feat(mission-control): rename sessions inline in the Recent sessions flyout
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
d9355383a4
commit
5bf08873bd
@@ -0,0 +1,52 @@
|
||||
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<ClaudeDoDbContext>()
|
||||
.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"));
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,55 @@ public class MissionControlViewModelTests : IDisposable
|
||||
rows);
|
||||
}
|
||||
|
||||
private async Task<MissionControlViewModel> BuildVmWithSessionAsync(string title)
|
||||
{
|
||||
await using (var ctx = NewContext())
|
||||
{
|
||||
ctx.MissionControlSessions.Add(new MissionControlSessionEntity
|
||||
{
|
||||
SessionId = "s1", Cwd = "c", Title = title, StartedAt = DateTime.UtcNow,
|
||||
});
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
var vm = BuildVm(new FakeWorker());
|
||||
await vm.RefreshRecentSessionsAsync();
|
||||
return vm;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RenameSession_PersistsAndSurvivesRefresh()
|
||||
{
|
||||
using var vm = await BuildVmWithSessionAsync("mika.kuns");
|
||||
var row = vm.RecentSessions.Single();
|
||||
|
||||
row.BeginEdit();
|
||||
row.EditText = " Fix login ";
|
||||
await vm.RenameSessionAsync(row);
|
||||
|
||||
Assert.Equal("Fix login", row.Title);
|
||||
Assert.False(row.IsEditing);
|
||||
await vm.RefreshRecentSessionsAsync();
|
||||
Assert.Equal("Fix login", vm.RecentSessions.Single().Title);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("mika.kuns")]
|
||||
public async Task RenameSession_IgnoresEmptyOrUnchangedInput(string input)
|
||||
{
|
||||
using var vm = await BuildVmWithSessionAsync("mika.kuns");
|
||||
var row = vm.RecentSessions.Single();
|
||||
|
||||
row.BeginEdit();
|
||||
row.EditText = input;
|
||||
await vm.RenameSessionAsync(row);
|
||||
|
||||
Assert.Equal("mika.kuns", row.Title);
|
||||
await vm.RefreshRecentSessionsAsync();
|
||||
Assert.Equal("mika.kuns", vm.RecentSessions.Single().Title);
|
||||
}
|
||||
|
||||
// Gates the title/list-name DB lookup behind a manually-released TaskCompletionSource so two
|
||||
// overlapping Open*ConPtySessionAsync calls both run their synchronous dedupe-check prefix
|
||||
// to completion before either resumes past the DB await. This reproduces the open-path races
|
||||
|
||||
Reference in New Issue
Block a user