fix(ui): stop the reconcile ticks from destroying user state
The 4s reconcile tick was added to three long-lived surfaces. On two of them it reloads by rebuilding every row instance, which silently threw away whatever the user had built up since the overlay opened; on the third it healed a row's data but left it in the wrong section. - WorktreesOverview: LoadAsync clears Rows, SelectedCount, ConflictRows and BatchProgress, so batch-merge ticks, the highlighted row and a finished batch's outcome badges were wiped every four seconds -- assembling a multi-worktree selection was impossible. Carry that state across the reload, keyed by task id, and re-point SelectedRow at the fresh instance (or clear it when the worktree is gone). - MergeHelperSelection: the remember/restore had no re-entrancy guard, so a second tick entering between the first one's reload and its restore snapshotted rows already back at IsTickedByDefault and wrote that default back, re-ticking what the user had unticked. One tick at a time, and hold the row instances instead of a value snapshot so a tick landed during the await survives. - TasksIsland: the tick deliberately never called Regroup because Phase 2b owned Rows in parallel. 2b has landed, so a healed task that went Done stayed in the Open section under a stale count, and a healed depends-on link never pulled its dependent under the chain head. Regroup when a patch moved a grouping input, gated on a cheap key so an idle tick stays free.
This commit is contained in:
@@ -7,9 +7,11 @@ using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
namespace ClaudeDo.Ui.Tests.ViewModels;
|
||||
|
||||
// Phase 3 reconcile tick: a periodic, awaitable-for-tests diff of the flat `Items` master
|
||||
// collection against SQLite that patches properties in place. It must never rebuild a row,
|
||||
// never call Regroup(), and never fall back to LoadForList — see
|
||||
// collection against SQLite that patches properties in place. It must never rebuild a row and
|
||||
// never fall back to LoadForList — see
|
||||
// docs/superpowers/specs/2026-08-07-ui-reaktivitaet-und-listen-performance-design.md.
|
||||
// It DOES Regroup, but only when a patch changed a grouping input: healing a row's data while
|
||||
// leaving it in the wrong section would fix nothing the user can see.
|
||||
public class TasksIslandReconcileTickTests : IDisposable
|
||||
{
|
||||
private readonly string _dbPath;
|
||||
@@ -216,4 +218,64 @@ public class TasksIslandReconcileTickTests : IDisposable
|
||||
var lastRow = vm.Items.Single(r => r.Id == $"T{total - 1}");
|
||||
Assert.Equal(TaskStatus.Queued, lastRow.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Tick_moves_a_healed_done_task_into_the_completed_section()
|
||||
{
|
||||
await SeedListAsync();
|
||||
await SeedTaskAsync("T1", "Task one", TaskStatus.Idle, 0);
|
||||
await SeedTaskAsync("T2", "Task two", TaskStatus.Idle, 1);
|
||||
|
||||
var vm = new TasksIslandViewModel(new CountingDbFactory(NewContext), worker: null);
|
||||
await LoadAndWaitAsync(vm, UserList("L1", "Work"), expectedCount: 2);
|
||||
vm.IsShowingCompleted = true;
|
||||
Assert.False(vm.HasCompleted);
|
||||
|
||||
// The TaskUpdated broadcast goes missing: SQLite says Done, the row still reads open.
|
||||
await using (var db = NewContext())
|
||||
{
|
||||
var t = await db.Tasks.FirstAsync(x => x.Id == "T1");
|
||||
t.Status = TaskStatus.Done;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await vm.ReconcileTickAsync();
|
||||
|
||||
Assert.True(vm.HasCompleted);
|
||||
|
||||
// Rows is the rendered order, so the healed row has to sit *under* the completed header
|
||||
// (the only one carrying an action command), not still be interleaved with the open rows.
|
||||
var rows = vm.Rows.ToList();
|
||||
var headerIndex = rows.FindIndex(r => r is HeaderRow { HasAction: true });
|
||||
var healedIndex = rows.FindIndex(r => r is TaskRowViewModel { Id: "T1" });
|
||||
Assert.True(headerIndex >= 0, "completed header was never emitted");
|
||||
Assert.True(healedIndex > headerIndex, $"healed row at {healedIndex}, completed header at {headerIndex}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Tick_reorders_the_chain_when_a_depends_on_link_is_healed()
|
||||
{
|
||||
await SeedListAsync();
|
||||
await SeedTaskAsync("HEAD", "Chain head", TaskStatus.Idle, 0);
|
||||
await SeedTaskAsync("MID", "Unrelated", TaskStatus.Idle, 1);
|
||||
await SeedTaskAsync("DEP", "Dependent", TaskStatus.Idle, 2);
|
||||
|
||||
var vm = new TasksIslandViewModel(new CountingDbFactory(NewContext), worker: null);
|
||||
await LoadAndWaitAsync(vm, UserList("L1", "Work"), expectedCount: 3);
|
||||
Assert.Equal(new[] { "HEAD", "MID", "DEP" }, vm.Rows.OfType<TaskRowViewModel>().Select(r => r.Id));
|
||||
|
||||
await using (var db = NewContext())
|
||||
{
|
||||
var t = await db.Tasks.FirstAsync(x => x.Id == "DEP");
|
||||
t.DependsOnTaskId = "HEAD";
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await vm.ReconcileTickAsync();
|
||||
|
||||
// The dependent is pulled directly under its head and gets the rail, not just the data.
|
||||
Assert.Equal(new[] { "HEAD", "DEP", "MID" }, vm.Rows.OfType<TaskRowViewModel>().Select(r => r.Id));
|
||||
Assert.True(vm.Items.Single(r => r.Id == "DEP").ShowAsChainMember);
|
||||
Assert.Equal(1, vm.Items.Single(r => r.Id == "DEP").ChainStep);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user