| 1 | using System.Net.Http.Json; |
| 2 | using AgentForge.Abstractions; |
| 3 | using System.Text.Json; |
| 4 | |
| 5 | namespace AgentForge.Tests; |
| 6 | |
| 7 | public sealed class ForgeCapabilitiesTests(ForgeWebApplicationFactory factory) : IClassFixture<ForgeWebApplicationFactory> |
| 8 | { |
| 9 | private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true }; |
| 10 | |
| 11 | [Fact] |
| 12 | public async Task Capabilities_lists_kernel_mcp_tools_and_human_view() |
| 13 | { |
| 14 | var response = await factory.CreateClient().GetAsync("/api/v1/capabilities"); |
| 15 | response.EnsureSuccessStatusCode(); |
| 16 | |
| 17 | var caps = await response.Content.ReadFromJsonAsync<JsonElement>(JsonOptions); |
| 18 | Assert.Equal("agent-forge", caps.GetProperty("service").GetString()); |
| 19 | Assert.Equal("standard", caps.GetProperty("bundle").GetString()); |
| 20 | |
| 21 | var plugins = caps.GetProperty("plugins").EnumerateArray().ToList(); |
| 22 | Assert.Contains(plugins, p => p.GetProperty("id").GetString() == "view-shell"); |
| 23 | Assert.Contains(plugins, p => p.GetProperty("id").GetString() == "issue"); |
| 24 | Assert.Contains(plugins, p => p.GetProperty("id").GetString() == "merge-request"); |
| 25 | |
| 26 | var features = caps.GetProperty("features").EnumerateArray().Select(e => e.GetString()).ToList(); |
| 27 | Assert.Contains("human_view", features); |
| 28 | Assert.Contains("issues", features); |
| 29 | |
| 30 | var mcpTools = caps.GetProperty("mcpTools").EnumerateArray().Select(e => e.GetString()).ToList(); |
| 31 | Assert.Contains(ForgeMcpToolNames.Capabilities, mcpTools); |
| 32 | Assert.Contains(ForgeMcpToolNames.IssueCreate, mcpTools); |
| 33 | Assert.Contains(ForgeMcpToolNames.ViewUrl, mcpTools); |
| 34 | |
| 35 | var commands = caps.GetProperty("commands").EnumerateArray().ToList(); |
| 36 | Assert.Contains(commands, c => c.GetProperty("commandId").GetString() == "forge.issue.open"); |
| 37 | Assert.Contains(commands, c => c.GetProperty("commandId").GetString() == "forge.artifact.goto"); |
| 38 | |
| 39 | var contributors = caps.GetProperty("viewContributors").EnumerateArray().ToList(); |
| 40 | Assert.Equal(2, contributors.Count); |
| 41 | Assert.Contains(contributors, c => c.GetProperty("tabId").GetString() == "issues"); |
| 42 | Assert.Contains(contributors, c => c.GetProperty("tabId").GetString() == "merge-requests"); |
| 43 | |
| 44 | var tools = caps.GetProperty("tools").EnumerateArray().ToList(); |
| 45 | Assert.Contains(tools, t => t.GetProperty("name").GetString() == ForgeMcpToolNames.IssueCreate); |
| 46 | Assert.Contains(tools, t => t.GetProperty("name").GetString() == ForgeMcpToolNames.ViewUrl); |
| 47 | Assert.True(tools[0].TryGetProperty("inputSchema", out _)); |
| 48 | } |
| 49 | |
| 50 | [Fact] |
| 51 | public async Task Minimal_bundle_has_no_human_view_feature() |
| 52 | { |
| 53 | await using var localFactory = new ForgeWebApplicationFactory { PluginBundle = "minimal" }; |
| 54 | var response = await localFactory.CreateClient().GetAsync("/api/v1/capabilities"); |
| 55 | response.EnsureSuccessStatusCode(); |
| 56 | |
| 57 | var caps = await response.Content.ReadFromJsonAsync<JsonElement>(JsonOptions); |
| 58 | Assert.Equal("minimal", caps.GetProperty("bundle").GetString()); |
| 59 | Assert.Empty(caps.GetProperty("plugins").EnumerateArray()); |
| 60 | |
| 61 | var features = caps.GetProperty("features").EnumerateArray().ToList(); |
| 62 | Assert.DoesNotContain(features, e => e.GetString() == "human_view"); |
| 63 | Assert.DoesNotContain(features, e => e.GetString() == "issues"); |
| 64 | |
| 65 | var mcpTools = caps.GetProperty("mcpTools").EnumerateArray().Select(e => e.GetString()).ToList(); |
| 66 | Assert.DoesNotContain(ForgeMcpToolNames.ViewUrl, mcpTools); |
| 67 | Assert.DoesNotContain(ForgeMcpToolNames.IssueCreate, mcpTools); |
| 68 | Assert.DoesNotContain(ForgeMcpToolNames.MergeRequestList, mcpTools); |
| 69 | } |
| 70 | } |
| 71 | |