| 1 | using System.Net.Http.Json; |
| 2 | using System.Text.Json; |
| 3 | using AgentForge.Abstractions; |
| 4 | |
| 5 | namespace AgentForge.Tests; |
| 6 | |
| 7 | public sealed class ForgeLensPluginTests |
| 8 | { |
| 9 | private static readonly JsonSerializerOptions JsonOptions = new() { PropertyNameCaseInsensitive = true }; |
| 10 | |
| 11 | [Fact] |
| 12 | public async Task Standard_bundle_excludes_lens_feature_and_mcp_tool() |
| 13 | { |
| 14 | using var factory = new ForgeWebApplicationFactory(); |
| 15 | var caps = await factory.CreateClient().GetFromJsonAsync<JsonElement>("/api/v1/capabilities", JsonOptions); |
| 16 | |
| 17 | var features = caps.GetProperty("features").EnumerateArray().Select(f => f.GetString()).ToList(); |
| 18 | var mcpTools = caps.GetProperty("mcpTools").EnumerateArray().Select(t => t.GetString()).ToList(); |
| 19 | |
| 20 | Assert.DoesNotContain("forge_lens", features); |
| 21 | Assert.DoesNotContain(ForgeMcpToolNames.LensQuery, mcpTools); |
| 22 | |
| 23 | var lensResponse = await factory.CreateClient().GetAsync("/api/v1/repos/any/lens"); |
| 24 | Assert.Equal(System.Net.HttpStatusCode.NotFound, lensResponse.StatusCode); |
| 25 | } |
| 26 | |
| 27 | [Fact] |
| 28 | public async Task Cide_companion_bundle_includes_lens() |
| 29 | { |
| 30 | using var factory = new ForgeWebApplicationFactory { PluginBundle = "cide-companion" }; |
| 31 | var client = factory.CreateClient(); |
| 32 | var caps = await client.GetFromJsonAsync<JsonElement>("/api/v1/capabilities", JsonOptions); |
| 33 | |
| 34 | Assert.Equal("cide-companion", caps.GetProperty("bundle").GetString()); |
| 35 | |
| 36 | var features = caps.GetProperty("features").EnumerateArray().Select(f => f.GetString()).ToList(); |
| 37 | var mcpTools = caps.GetProperty("mcpTools").EnumerateArray().Select(t => t.GetString()).ToList(); |
| 38 | var lensPlugin = caps.GetProperty("plugins").EnumerateArray() |
| 39 | .Single(p => p.GetProperty("id").GetString() == "lens"); |
| 40 | |
| 41 | Assert.Contains("forge_lens", features); |
| 42 | Assert.Contains(ForgeMcpToolNames.LensQuery, mcpTools); |
| 43 | Assert.Equal("extended", lensPlugin.GetProperty("tier").GetString()); |
| 44 | Assert.Equal(0, lensPlugin.GetProperty("commandCount").GetInt32()); |
| 45 | |
| 46 | await client.PostAsJsonAsync("/api/v1/repos", new { name = "lens-repo" }); |
| 47 | var create = await client.PostAsJsonAsync("/api/v1/repos/lens-repo/issues", new |
| 48 | { |
| 49 | title = "Anchor test", |
| 50 | anchors = new[] { new { file = "src/Foo.cs", line = 10 } }, |
| 51 | }); |
| 52 | create.EnsureSuccessStatusCode(); |
| 53 | |
| 54 | var lens = await client.GetFromJsonAsync<JsonElement>( |
| 55 | "/api/v1/repos/lens-repo/lens?file=src/Foo.cs", |
| 56 | JsonOptions); |
| 57 | Assert.Equal("lens-repo", lens.GetProperty("repo").GetString()); |
| 58 | Assert.Equal(1, lens.GetProperty("issues").GetArrayLength()); |
| 59 | } |
| 60 | } |
| 61 | |