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:
@@ -350,4 +350,54 @@ public class MergeHelperSelectionModalViewModelTests : IDisposable
|
||||
Assert.False(vm.HasTasks);
|
||||
Assert.False(vm.CanConfirm);
|
||||
}
|
||||
|
||||
// The tick reloads by rebuilding every row, so it remembers and replays the user's ticks.
|
||||
// A second tick entering while the first is between its reload and its restore would snapshot
|
||||
// rows that are back at IsTickedByDefault and write that default back — silently re-ticking
|
||||
// whatever the user had deliberately unticked. Only one tick may be in flight.
|
||||
[Fact]
|
||||
public async Task ReconcileTick_ignores_a_second_tick_while_one_is_still_in_flight()
|
||||
{
|
||||
await SeedAllStatusesAsync();
|
||||
|
||||
var factory = new CountingDbFactory(NewContext);
|
||||
var vm = new MergeHelperSelectionModalViewModel(factory);
|
||||
vm.Configure("L1", "Work");
|
||||
await vm.LoadAsync();
|
||||
|
||||
var unticked = vm.Tasks.Single(t => t.Id == "t-idle");
|
||||
unticked.IsSelected = false;
|
||||
|
||||
var reached = new TaskCompletionSource();
|
||||
var proceed = new TaskCompletionSource();
|
||||
vm.ReconcileTickTestBarrier = async () =>
|
||||
{
|
||||
reached.TrySetResult();
|
||||
await proceed.Task;
|
||||
};
|
||||
|
||||
var first = vm.ReconcileTickAsync();
|
||||
await reached.Task;
|
||||
|
||||
var loadsBefore = factory.CreateCalls;
|
||||
await vm.ReconcileTickAsync();
|
||||
Assert.Equal(loadsBefore, factory.CreateCalls); // the overlapping tick did not reload
|
||||
|
||||
proceed.TrySetResult();
|
||||
await first;
|
||||
|
||||
Assert.False(vm.Tasks.Single(t => t.Id == "t-idle").IsSelected);
|
||||
}
|
||||
|
||||
private sealed class CountingDbFactory : IDbContextFactory<ClaudeDoDbContext>
|
||||
{
|
||||
private readonly Func<ClaudeDoDbContext> _create;
|
||||
public int CreateCalls { get; private set; }
|
||||
public CountingDbFactory(Func<ClaudeDoDbContext> create) => _create = create;
|
||||
public ClaudeDoDbContext CreateDbContext()
|
||||
{
|
||||
CreateCalls++;
|
||||
return _create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user