| 1 | using CascadeIDE.Features.Chat; |
| 2 | using CascadeIDE.Features.Forge.Infrastructure; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class ForgeSlashCatalogOverlayTests |
| 8 | { |
| 9 | public ForgeSlashCatalogOverlayTests() |
| 10 | { |
| 11 | ForgeSlashCatalogOverlay.Clear(); |
| 12 | } |
| 13 | |
| 14 | [Fact] |
| 15 | public void Overlay_resolves_forge_issue_open_path() |
| 16 | { |
| 17 | ForgeSlashCatalogOverlay.ApplyForTests( |
| 18 | [ |
| 19 | new ForgeCapabilitiesCommand |
| 20 | { |
| 21 | Domain = "forge", |
| 22 | Object = "issue", |
| 23 | Intent = "open", |
| 24 | CommandId = "forge.issue.open", |
| 25 | Path = "/issue open", |
| 26 | PathAliases = ["/forge issue open"], |
| 27 | Help = "Open issue by number.", |
| 28 | ArgTail = "required", |
| 29 | }, |
| 30 | ]); |
| 31 | |
| 32 | Assert.True(SlashLineResolver.TryResolveSlashLine("/forge issue open 3", out var resolution)); |
| 33 | Assert.Equal("/forge issue open", resolution.CanonicalPath); |
| 34 | Assert.Equal("3", resolution.ArgTail); |
| 35 | Assert.Equal(SlashArgTailKind.Required, resolution.ArgTailKind); |
| 36 | Assert.True(resolution.IsRunnable); |
| 37 | } |
| 38 | |
| 39 | [Fact] |
| 40 | public void Catalog_resolves_overlay_descriptor() |
| 41 | { |
| 42 | ForgeSlashCatalogOverlay.ApplyForTests( |
| 43 | [ |
| 44 | new ForgeCapabilitiesCommand |
| 45 | { |
| 46 | Object = "repo", |
| 47 | Intent = "open", |
| 48 | CommandId = "forge.repo.open", |
| 49 | Path = "/repo open", |
| 50 | PathAliases = ["/forge repo open"], |
| 51 | Help = "Open repo view.", |
| 52 | ArgTail = "optional", |
| 53 | }, |
| 54 | ]); |
| 55 | |
| 56 | Assert.True(ChatSlashCommandCatalog.TryResolveInput("/forge repo open", out var descriptor, out _)); |
| 57 | Assert.Equal("forge.repo.open", descriptor.CommandId); |
| 58 | Assert.Equal(ChatSlashCommandExecutionKind.ForgeCommand, descriptor.ExecutionKind); |
| 59 | } |
| 60 | |
| 61 | [Fact] |
| 62 | public void Clear_removes_overlay_paths() |
| 63 | { |
| 64 | ForgeSlashCatalogOverlay.ApplyForTests( |
| 65 | [ |
| 66 | new ForgeCapabilitiesCommand |
| 67 | { |
| 68 | Object = "issue", |
| 69 | Intent = "open", |
| 70 | CommandId = "forge.issue.open", |
| 71 | Path = "/issue open", |
| 72 | PathAliases = ["/forge issue open"], |
| 73 | Help = "Open issue.", |
| 74 | }, |
| 75 | ]); |
| 76 | |
| 77 | ForgeSlashCatalogOverlay.Clear(); |
| 78 | Assert.False(SlashLineResolver.TryResolveSlashLine("/forge issue open 1", out _)); |
| 79 | } |
| 80 | |
| 81 | [Fact] |
| 82 | public void Overlay_resolves_forge_artifact_goto() |
| 83 | { |
| 84 | ForgeSlashCatalogOverlay.ApplyForTests( |
| 85 | [ |
| 86 | new ForgeCapabilitiesCommand |
| 87 | { |
| 88 | Object = "artifact", |
| 89 | Intent = "goto", |
| 90 | CommandId = "forge.artifact.goto", |
| 91 | Path = "/artifact goto", |
| 92 | PathAliases = ["/forge artifact goto"], |
| 93 | Help = "Open [FRG:…] artifact.", |
| 94 | ArgTail = "required", |
| 95 | }, |
| 96 | ]); |
| 97 | |
| 98 | Assert.True(ChatSlashCommandCatalog.TryResolveInput("/forge artifact goto [FRG:pilot/issues/1]", out var descriptor, out _)); |
| 99 | Assert.Equal("forge.artifact.goto", descriptor.CommandId); |
| 100 | } |
| 101 | } |
| 102 | |