| 1 | #nullable enable |
| 2 | using CascadeIDE.Features.Chat; |
| 3 | using CascadeIDE.Services; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class SlashRouteSemanticsTests |
| 9 | { |
| 10 | [Theory] |
| 11 | [InlineData("/build run", "solution", "build", "run", SlashPathRole.Alias)] |
| 12 | [InlineData("/intercom topic list", "intercom", "topic", "list", SlashPathRole.Canonical)] |
| 13 | [InlineData("/editor select code", "editor", "code", "select", SlashPathRole.Canonical)] |
| 14 | [InlineData("/map type file", "map", "type", "set", SlashPathRole.Alias)] |
| 15 | [InlineData("/help", "help", "", "", SlashPathRole.Canonical)] |
| 16 | public void Resolve_matches_expected( |
| 17 | string path, |
| 18 | string domain, |
| 19 | string obj, |
| 20 | string intent, |
| 21 | SlashPathRole role) |
| 22 | { |
| 23 | var fields = SlashRouteSemantics.Resolve(path); |
| 24 | Assert.Equal(domain, fields.Domain, StringComparer.OrdinalIgnoreCase); |
| 25 | Assert.Equal(obj, fields.Object, StringComparer.OrdinalIgnoreCase); |
| 26 | Assert.Equal(intent, fields.Intent, StringComparer.OrdinalIgnoreCase); |
| 27 | Assert.Equal(role, fields.PathRole); |
| 28 | Assert.True(SlashRouteSemantics.PathMatchesSemantic(path, fields)); |
| 29 | } |
| 30 | |
| 31 | [Fact] |
| 32 | public void Bundled_catalog_semantics_match_inference() |
| 33 | { |
| 34 | foreach (var route in IntentSlashCatalog.SlashRoutes.Values) |
| 35 | { |
| 36 | var inferred = SlashRouteSemantics.Resolve(route.SlashPath, route.MapLevel); |
| 37 | Assert.True( |
| 38 | SlashRouteSemantics.PathMatchesSemantic(route.SlashPath, route.SemanticFields), |
| 39 | route.SlashPath); |
| 40 | Assert.Equal(inferred.Domain, route.Domain, StringComparer.OrdinalIgnoreCase); |
| 41 | Assert.Equal(inferred.Object, route.Object, StringComparer.OrdinalIgnoreCase); |
| 42 | Assert.Equal(inferred.Intent, route.Intent, StringComparer.OrdinalIgnoreCase); |
| 43 | Assert.Equal(inferred.PathRole, route.PathRole); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | [Fact] |
| 48 | public void GetHierarchyContext_BuildRun_AfterObjectToken_ShowsIntentStep() |
| 49 | { |
| 50 | var ctx = ChatSlashAutocomplete.GetHierarchyContext("/build "); |
| 51 | Assert.NotNull(ctx); |
| 52 | Assert.Equal("действие", ctx.NextStepLabel); |
| 53 | } |
| 54 | } |
| 55 | |