| 1 | using System.IO; |
| 2 | using System.Text.Json; |
| 3 | using CascadeIDE.Features.Chat; |
| 4 | using CascadeIDE.Models.AgentChat; |
| 5 | using CascadeIDE.Services; |
| 6 | using Xunit; |
| 7 | |
| 8 | namespace CascadeIDE.Tests; |
| 9 | |
| 10 | public sealed class ChatClarificationIntegrationTests |
| 11 | { |
| 12 | [Fact] |
| 13 | public void SubmitClarificationResponseFromJson_StoresStructuredDraftWithoutLegacyPrefix() |
| 14 | { |
| 15 | var workspace = Path.Combine(Path.GetTempPath(), "cascade-ide-chat-tests", Guid.NewGuid().ToString("N")); |
| 16 | Directory.CreateDirectory(workspace); |
| 17 | |
| 18 | var vm = CreateViewModel(workspace); |
| 19 | var batch = new ClarificationBatch( |
| 20 | Guid.NewGuid(), |
| 21 | [ |
| 22 | new ClarificationItem("scope", "Какой surface делаем первым?"), |
| 23 | new ClarificationItem("fallback", "Нужен ли fallback?") |
| 24 | ], |
| 25 | "Уточнения по ADR 0031"); |
| 26 | |
| 27 | var openResult = vm.OpenClarificationBatchFromJson(JsonSerializer.Serialize(batch)); |
| 28 | Assert.Equal("OK", openResult); |
| 29 | Assert.True(vm.HasActiveClarificationBatch); |
| 30 | |
| 31 | var response = new ClarificationResponse(batch.Id, new Dictionary<string, string> |
| 32 | { |
| 33 | ["scope"] = "Skia-centered surface", |
| 34 | ["fallback"] = "Avalonia baseline можно удалить" |
| 35 | }); |
| 36 | |
| 37 | var submitResult = vm.SubmitClarificationResponseFromJson(JsonSerializer.Serialize(response)); |
| 38 | Assert.Equal("OK", submitResult); |
| 39 | |
| 40 | var message = Assert.Single(vm.ChatMessages); |
| 41 | Assert.Equal("user", message.Role); |
| 42 | Assert.DoesNotContain("[clarification]", message.Content, StringComparison.Ordinal); |
| 43 | Assert.Contains("Уточнения по ADR 0031", message.Content); |
| 44 | Assert.Contains("scope: Skia-centered surface", message.Content); |
| 45 | Assert.False(vm.HasActiveClarificationBatch); |
| 46 | Assert.Empty(vm.ChatSurfaceSnapshot.State.Confirmations); |
| 47 | Assert.Contains(vm.ChatSurfaceSnapshot.Layout.Lanes.SelectMany(lane => lane.Entries), entry => entry.MessageIndex == 0); |
| 48 | } |
| 49 | |
| 50 | private static ChatPanelViewModel CreateViewModel(string workspace) |
| 51 | { |
| 52 | var minimizer = new ContextMinimizer(new CSharpLanguageService()); |
| 53 | var aiProviderManager = new AiProviderManager(minimizer, _ => (null, "")); |
| 54 | return new ChatPanelViewModel( |
| 55 | aiProviderManager, |
| 56 | getActiveAiProvider: () => "CursorACP", |
| 57 | getSelectedOllamaModel: () => null, |
| 58 | getChatMcpOnly: () => true, |
| 59 | getShowThinkingInHistory: () => true, |
| 60 | getUseMinimizedContext: () => false, |
| 61 | getCurrentFilePath: () => null, |
| 62 | getEditorText: () => "", |
| 63 | getWorkspaceRoot: () => workspace, |
| 64 | getCursorAcpAgentPath: () => "", |
| 65 | getExternalMcpServersJson: () => "", |
| 66 | getAcpAutoInjectIdeMcp: () => false, |
| 67 | getCursorAcpPreferredModelId: () => null); |
| 68 | } |
| 69 | } |
| 70 | |