Merge task: UI polish: ListBox Padding scroll clip, 4s log rebuild, ClassifyItems side effects
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Ui.ViewModels.Islands;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
||||
|
||||
namespace ClaudeDo.Ui.Tests.ViewModels;
|
||||
|
||||
// ClassifyItems (used by Regroup) additionally mutates every row's chain-display fields via
|
||||
// ApplyChainGrouping. ClearCompletedAsync only needs section membership/counts, so it goes
|
||||
// through the pure PartitionItems instead — this must not write ShowAsChainMember/ChainStep/
|
||||
// ChainAfterLabel as a side effect of counting completed rows.
|
||||
public class TasksIslandClassifyItemsTests : IDisposable
|
||||
{
|
||||
private readonly string _dbPath;
|
||||
|
||||
public TasksIslandClassifyItemsTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_ui_classify_{Guid.NewGuid():N}.db");
|
||||
using var ctx = NewContext();
|
||||
ctx.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
try { File.Delete(_dbPath); } catch { }
|
||||
try { File.Delete(_dbPath + "-wal"); } catch { }
|
||||
try { File.Delete(_dbPath + "-shm"); } catch { }
|
||||
}
|
||||
|
||||
private ClaudeDoDbContext NewContext()
|
||||
{
|
||||
var opts = new DbContextOptionsBuilder<ClaudeDoDbContext>()
|
||||
.UseSqlite($"Data Source={_dbPath}")
|
||||
.Options;
|
||||
return new ClaudeDoDbContext(opts);
|
||||
}
|
||||
|
||||
private sealed class TestDbFactory : IDbContextFactory<ClaudeDoDbContext>
|
||||
{
|
||||
private readonly Func<ClaudeDoDbContext> _create;
|
||||
public TestDbFactory(Func<ClaudeDoDbContext> create) => _create = create;
|
||||
public ClaudeDoDbContext CreateDbContext() => _create();
|
||||
}
|
||||
|
||||
private TasksIslandViewModel BuildViewModel()
|
||||
{
|
||||
var factory = new TestDbFactory(NewContext);
|
||||
return new TasksIslandViewModel(factory, worker: null);
|
||||
}
|
||||
|
||||
private static ListNavItemViewModel UserList(string listEntityId, string name) =>
|
||||
new() { Id = $"user:{listEntityId}", Kind = ListKind.User, Name = name };
|
||||
|
||||
private static async Task LoadAndWaitAsync(TasksIslandViewModel vm, ListNavItemViewModel list, int expectedCount = 1)
|
||||
{
|
||||
vm.LoadForList(list);
|
||||
var deadline = DateTime.UtcNow.AddSeconds(5);
|
||||
while (DateTime.UtcNow < deadline)
|
||||
{
|
||||
await Task.Delay(25);
|
||||
if (vm.Items.Count >= expectedCount) break;
|
||||
}
|
||||
await Task.Delay(50);
|
||||
}
|
||||
|
||||
private async Task SeedAsync(
|
||||
params (string Id, TaskStatus Status, string? DependsOnTaskId, int SortOrder)[] tasks)
|
||||
{
|
||||
await using var db = NewContext();
|
||||
db.Lists.Add(new ListEntity { Id = "list1", Name = "Default", CreatedAt = DateTime.UtcNow });
|
||||
foreach (var t in tasks)
|
||||
{
|
||||
db.Tasks.Add(new TaskEntity
|
||||
{
|
||||
Number = TestTaskNumbers.Next(),
|
||||
Id = t.Id,
|
||||
ListId = "list1",
|
||||
Title = t.Id,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
Status = t.Status,
|
||||
DependsOnTaskId = t.DependsOnTaskId,
|
||||
SortOrder = t.SortOrder,
|
||||
});
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClearCompleted_counting_path_leaves_chain_fields_untouched()
|
||||
{
|
||||
await SeedAsync(
|
||||
("head", TaskStatus.Idle, null, 0),
|
||||
("dep", TaskStatus.Idle, "head", 1));
|
||||
|
||||
var vm = BuildViewModel();
|
||||
await LoadAndWaitAsync(vm, UserList("list1", "Default"), expectedCount: 2);
|
||||
|
||||
var dep = vm.Items.Single(r => r.Id == "dep");
|
||||
// Sanity: the initial Regroup (during load) computed the chain correctly.
|
||||
Assert.True(dep.ShowAsChainMember);
|
||||
Assert.Equal(1, dep.ChainStep);
|
||||
|
||||
// Corrupt the row to a sentinel distinguishable from both the correct and default value.
|
||||
dep.ShowAsChainMember = false;
|
||||
dep.ChainStep = 99;
|
||||
dep.ChainAfterLabel = "SENTINEL";
|
||||
|
||||
// Nothing is completed, so ClearCompletedAsync does nothing but count via PartitionItems.
|
||||
await vm.ClearCompletedCommand.ExecuteAsync(null);
|
||||
|
||||
Assert.False(dep.ShowAsChainMember);
|
||||
Assert.Equal(99, dep.ChainStep);
|
||||
Assert.Equal("SENTINEL", dep.ChainAfterLabel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Regroup_still_recomputes_chain_fields()
|
||||
{
|
||||
await SeedAsync(
|
||||
("head", TaskStatus.Idle, null, 0),
|
||||
("dep", TaskStatus.Idle, "head", 1));
|
||||
|
||||
var vm = BuildViewModel();
|
||||
await LoadAndWaitAsync(vm, UserList("list1", "Default"), expectedCount: 2);
|
||||
|
||||
var dep = vm.Items.Single(r => r.Id == "dep");
|
||||
dep.ShowAsChainMember = false;
|
||||
dep.ChainStep = 99;
|
||||
dep.ChainAfterLabel = "SENTINEL";
|
||||
|
||||
vm.Regroup();
|
||||
|
||||
Assert.True(dep.ShowAsChainMember);
|
||||
Assert.Equal(1, dep.ChainStep);
|
||||
Assert.Null(dep.ChainAfterLabel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClearCompleted_still_deletes_completed_rows_and_reports_count()
|
||||
{
|
||||
await SeedAsync(
|
||||
("open1", TaskStatus.Idle, null, 0),
|
||||
("done1", TaskStatus.Done, null, 1),
|
||||
("done2", TaskStatus.Done, null, 2));
|
||||
|
||||
var vm = BuildViewModel();
|
||||
await LoadAndWaitAsync(vm, UserList("list1", "Default"), expectedCount: 3);
|
||||
vm.IsShowingCompleted = true;
|
||||
|
||||
await vm.ClearCompletedCommand.ExecuteAsync(null);
|
||||
|
||||
Assert.DoesNotContain(vm.Items, r => r.Id is "done1" or "done2");
|
||||
Assert.Contains(vm.Items, r => r.Id == "open1");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user