using System.Text.Json; using System.IO; using AxCopilot.Models; using AxCopilot.Services; using FluentAssertions; using Xunit; namespace AxCopilot.Tests.Services; public class ChatStorageServiceTests { [Fact] public void Load_ShouldRestoreMissingToolResultPreviewFromLegacyStoredConversation() { var conversationId = "legacy-preview-" + Guid.NewGuid().ToString("N"); var storagePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "AxCopilot", "conversations", conversationId + ".axchat"); Directory.CreateDirectory(Path.GetDirectoryName(storagePath)!); var conversation = new ChatConversation { Id = conversationId, Title = "Legacy conversation", Messages = new() { new ChatMessage { MsgId = "tool-result-1", Role = "user", Content = $$"""{"type":"tool_result","tool_use_id":"call-legacy","tool_name":"file_read","content":"{{new string('L', 900)}}" }""", QueryPreviewContent = null, } } }; var json = JsonSerializer.Serialize(conversation); CryptoService.EncryptToFile(storagePath, json); try { var storage = new ChatStorageService(); var loaded = storage.Load(conversationId); loaded.Should().NotBeNull(); loaded!.Messages.Should().ContainSingle(); loaded.Messages[0].QueryPreviewContent.Should().NotBeNullOrWhiteSpace(); loaded.Messages[0].QueryPreviewContent.Should().Contain("call-legacy"); } finally { try { var storage = new ChatStorageService(); storage.Delete(conversationId); } catch { } } } }