using ClaudeDo.Data.Models; using ClaudeDo.Data.Repositories; using Microsoft.EntityFrameworkCore; namespace ClaudeDo.Data.Tests; public sealed class MissionControlSessionRepositoryTests : IDisposable { private readonly string _dbPath; private readonly ClaudeDoDbContext _ctx; private readonly MissionControlSessionRepository _repo; public MissionControlSessionRepositoryTests() { _dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_mcs_{Guid.NewGuid():N}.db"); var options = new DbContextOptionsBuilder() .UseSqlite($"Data Source={_dbPath}") .Options; _ctx = new ClaudeDoDbContext(options); _ctx.Database.EnsureCreated(); _repo = new MissionControlSessionRepository(_ctx); } public void Dispose() { _ctx.Dispose(); foreach (var suffix in new[] { "", "-wal", "-shm" }) try { File.Delete(_dbPath + suffix); } catch { } } private static MissionControlSessionEntity Session(string title) => new() { SessionId = "s1", Cwd = "c", Title = title, StartedAt = DateTime.UtcNow }; [Fact] public async Task RenameAsync_updates_the_title_and_a_later_RecordAsync_does_not_revert_it() { await _repo.RecordAsync(Session("mika.kuns")); await _repo.RenameAsync("s1", "Fix login"); await _repo.RecordAsync(Session("mika.kuns")); Assert.Equal("Fix login", (await _repo.GetAsync("s1"))!.Title); } [Fact] public async Task RenameAsync_is_a_noop_for_an_unknown_session() { await _repo.RenameAsync("missing", "x"); Assert.Null(await _repo.GetAsync("missing")); } }