fix(ui): reconcile the log visualizer tick instead of clearing Rows
The 4s reconcile tick called Apply(), which did Rows.Clear() + refill on every tick -- resetting the user's scroll position and selection while they're mid-read, exactly what the overlay exists to avoid. Reconcile granularly instead: find the overlap between the previous and latest snapshot (the ring buffer is append-mostly, evicting from the front as entries age out of the 30-min window), trim rows for evicted entries off the tail, and insert new entries at the head. A tick with no change now leaves Rows untouched. The WarnErrorOnly toggle still goes through the full Apply() rebuild, unchanged.
This commit is contained in:
@@ -13,6 +13,14 @@ public class LogVisualizerViewModelTests
|
||||
public override Task<IReadOnlyList<WorkerLogEntry>> GetRecentLogsAsync() => Task.FromResult(_logs);
|
||||
}
|
||||
|
||||
// Simulates the worker's append-mostly LogRingBuffer across successive ticks: each
|
||||
// RefreshAsync call returns whatever `Logs` currently holds.
|
||||
private sealed class MutableFakeClient : StubWorkerClient
|
||||
{
|
||||
public IReadOnlyList<WorkerLogEntry> Logs { get; set; } = Array.Empty<WorkerLogEntry>();
|
||||
public override Task<IReadOnlyList<WorkerLogEntry>> GetRecentLogsAsync() => Task.FromResult(Logs);
|
||||
}
|
||||
|
||||
private static WorkerLogEntry E(WorkerLogLevel lvl, string msg)
|
||||
=> new(msg, lvl, new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc));
|
||||
|
||||
@@ -176,4 +184,56 @@ public class LogVisualizerViewModelTests
|
||||
|
||||
Assert.False(string.IsNullOrEmpty(vm.StatusText));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Tick_with_no_new_data_does_not_touch_rows()
|
||||
{
|
||||
var t0 = new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc);
|
||||
var client = new MutableFakeClient { Logs = new[] { E(WorkerLogLevel.Info, "a", t0) } };
|
||||
var vm = new LogVisualizerViewModel(client);
|
||||
await vm.RefreshAsync();
|
||||
var row = vm.Rows.Single();
|
||||
|
||||
var changeCount = 0;
|
||||
vm.Rows.CollectionChanged += (_, _) => changeCount++;
|
||||
await vm.RefreshAsync(); // same snapshot on the next tick
|
||||
|
||||
Assert.Equal(0, changeCount);
|
||||
Assert.Same(row, vm.Rows.Single());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Tick_appends_a_new_entry_without_clearing_existing_rows()
|
||||
{
|
||||
var t0 = new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc);
|
||||
var client = new MutableFakeClient { Logs = new[] { E(WorkerLogLevel.Info, "a", t0) } };
|
||||
var vm = new LogVisualizerViewModel(client);
|
||||
await vm.RefreshAsync();
|
||||
var existingRow = vm.Rows.Single();
|
||||
|
||||
client.Logs = new[] { E(WorkerLogLevel.Info, "a", t0), E(WorkerLogLevel.Info, "b", t0.AddMinutes(1)) };
|
||||
await vm.RefreshAsync();
|
||||
|
||||
Assert.Equal(new[] { "b", "a" }, vm.Rows.Select(r => r.Message));
|
||||
Assert.Same(existingRow, vm.Rows[1]); // the pre-existing row instance survived the tick
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Tick_drops_the_row_for_an_entry_that_aged_out_of_the_window()
|
||||
{
|
||||
var t0 = new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc);
|
||||
var client = new MutableFakeClient
|
||||
{
|
||||
Logs = new[] { E(WorkerLogLevel.Info, "a", t0), E(WorkerLogLevel.Info, "b", t0.AddMinutes(1)) },
|
||||
};
|
||||
var vm = new LogVisualizerViewModel(client);
|
||||
await vm.RefreshAsync();
|
||||
Assert.Equal(new[] { "b", "a" }, vm.Rows.Select(r => r.Message));
|
||||
|
||||
// "a" fell out of the ring buffer's 30-min window; "c" is a new entry.
|
||||
client.Logs = new[] { E(WorkerLogLevel.Info, "b", t0.AddMinutes(1)), E(WorkerLogLevel.Info, "c", t0.AddMinutes(2)) };
|
||||
await vm.RefreshAsync();
|
||||
|
||||
Assert.Equal(new[] { "c", "b" }, vm.Rows.Select(r => r.Message));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user