fix(ui): Log Visualizer shows every footer-log message
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
c956ab102e
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Ui.Services;
|
||||
using ClaudeDo.Ui.ViewModels;
|
||||
using ClaudeDo.Ui.ViewModels.Modals;
|
||||
using Xunit;
|
||||
|
||||
namespace ClaudeDo.Ui.Tests;
|
||||
@@ -55,4 +59,49 @@ public class IslandsShellViewModelWorkerLogTests
|
||||
|
||||
Assert.StartsWith(expectedLocalHhmm + " · ", vm.WorkerLogText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Visualizer_shows_flashed_and_received_footer_lines_with_their_levels()
|
||||
{
|
||||
var shell = new IslandsShellViewModel();
|
||||
shell.FlashFooterInfo("claude 2.0 updating");
|
||||
shell.OnWorkerLogReceived(new WorkerLogEntry("task merged", WorkerLogLevel.Success, DateTime.UtcNow.AddSeconds(1)));
|
||||
var vm = new LogVisualizerViewModel(new BufferClient(), shell.FooterHistorySnapshot);
|
||||
|
||||
await vm.RefreshAsync();
|
||||
|
||||
Assert.Equal(new[] { ("task merged", WorkerLogLevel.Success), ("claude 2.0 updating", WorkerLogLevel.Info) },
|
||||
vm.Rows.Select(r => (r.Message, r.Level)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Footer_line_arriving_while_visualizer_is_open_shows_on_next_refresh()
|
||||
{
|
||||
var shell = new IslandsShellViewModel();
|
||||
var vm = new LogVisualizerViewModel(new BufferClient(), shell.FooterHistorySnapshot);
|
||||
await vm.RefreshAsync();
|
||||
|
||||
shell.FlashFooterError("boom");
|
||||
await vm.RefreshAsync();
|
||||
|
||||
Assert.Equal(("boom", WorkerLogLevel.Error), (vm.Rows.Single().Message, vm.Rows.Single().Level));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Worker_warn_in_both_footer_history_and_buffer_appears_once()
|
||||
{
|
||||
var shell = new IslandsShellViewModel();
|
||||
var warn = new WorkerLogEntry("disk low", WorkerLogLevel.Warn, DateTime.UtcNow);
|
||||
shell.OnWorkerLogReceived(warn);
|
||||
var vm = new LogVisualizerViewModel(new BufferClient(warn), shell.FooterHistorySnapshot);
|
||||
|
||||
await vm.RefreshAsync();
|
||||
|
||||
Assert.Single(vm.Rows);
|
||||
}
|
||||
|
||||
private sealed class BufferClient(params WorkerLogEntry[] logs) : StubWorkerClient
|
||||
{
|
||||
public override Task<IReadOnlyList<WorkerLogEntry>> GetRecentLogsAsync() => Task.FromResult<IReadOnlyList<WorkerLogEntry>>(logs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ public class LogVisualizerViewModelTests
|
||||
public override Task<IReadOnlyList<WorkerLogEntry>> GetRecentLogsAsync() => Task.FromResult(Logs);
|
||||
}
|
||||
|
||||
private static LogVisualizerViewModel Vm(IWorkerClient client,
|
||||
Func<string, Task<bool>>? copy = null, Func<IReadOnlyList<WorkerLogEntry>>? footer = null)
|
||||
=> new(client, footer ?? (() => Array.Empty<WorkerLogEntry>()), copy ?? (_ => Task.FromResult(true)));
|
||||
|
||||
private static WorkerLogEntry E(WorkerLogLevel lvl, string msg)
|
||||
=> new(msg, lvl, new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc));
|
||||
|
||||
@@ -30,7 +34,7 @@ public class LogVisualizerViewModelTests
|
||||
[Fact]
|
||||
public async Task Refresh_populates_rows_from_worker_newest_first()
|
||||
{
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(new[] { E(WorkerLogLevel.Info, "a"), E(WorkerLogLevel.Error, "b") }));
|
||||
var vm = Vm(new FakeClient(new[] { E(WorkerLogLevel.Info, "a"), E(WorkerLogLevel.Error, "b") }));
|
||||
|
||||
await vm.RefreshAsync();
|
||||
|
||||
@@ -40,7 +44,7 @@ public class LogVisualizerViewModelTests
|
||||
[Fact]
|
||||
public async Task WarnErrorOnly_filters_out_info()
|
||||
{
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(new[]
|
||||
var vm = Vm(new FakeClient(new[]
|
||||
{ E(WorkerLogLevel.Info, "a"), E(WorkerLogLevel.Warn, "w"), E(WorkerLogLevel.Error, "e") }));
|
||||
await vm.RefreshAsync();
|
||||
|
||||
@@ -52,7 +56,7 @@ public class LogVisualizerViewModelTests
|
||||
[Fact]
|
||||
public async Task Empty_logs_yield_no_rows_and_a_status()
|
||||
{
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(Array.Empty<WorkerLogEntry>()));
|
||||
var vm = Vm(new FakeClient(Array.Empty<WorkerLogEntry>()));
|
||||
|
||||
await vm.RefreshAsync();
|
||||
|
||||
@@ -64,7 +68,7 @@ public class LogVisualizerViewModelTests
|
||||
public async Task Refresh_orders_newest_entry_first()
|
||||
{
|
||||
var t0 = new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc);
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(new[]
|
||||
var vm = Vm(new FakeClient(new[]
|
||||
{
|
||||
E(WorkerLogLevel.Info, "oldest", t0),
|
||||
E(WorkerLogLevel.Info, "middle", t0.AddMinutes(1)),
|
||||
@@ -80,7 +84,7 @@ public class LogVisualizerViewModelTests
|
||||
public async Task Refresh_orders_newest_entry_first_with_warn_error_only()
|
||||
{
|
||||
var t0 = new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc);
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(new[]
|
||||
var vm = Vm(new FakeClient(new[]
|
||||
{
|
||||
E(WorkerLogLevel.Warn, "oldest", t0),
|
||||
E(WorkerLogLevel.Info, "skipped", t0.AddMinutes(1)),
|
||||
@@ -98,7 +102,7 @@ public class LogVisualizerViewModelTests
|
||||
public async Task CopyLast_orders_chronologically_oldest_first()
|
||||
{
|
||||
var t0 = new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc);
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(new[]
|
||||
var vm = Vm(new FakeClient(new[]
|
||||
{
|
||||
E(WorkerLogLevel.Info, "oldest", t0),
|
||||
E(WorkerLogLevel.Warn, "middle", t0.AddMinutes(1)),
|
||||
@@ -122,7 +126,7 @@ public class LogVisualizerViewModelTests
|
||||
var entries = Enumerable.Range(0, 50)
|
||||
.Select(i => E(WorkerLogLevel.Info, $"line{i}", t0.AddMinutes(i)))
|
||||
.ToArray();
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(entries));
|
||||
var vm = Vm(new FakeClient(entries));
|
||||
await vm.RefreshAsync();
|
||||
|
||||
var lines = vm.BuildCopyText().Split('\n');
|
||||
@@ -136,7 +140,7 @@ public class LogVisualizerViewModelTests
|
||||
public async Task CopyLast_respects_active_warn_error_filter()
|
||||
{
|
||||
var t0 = new DateTime(2026, 6, 23, 8, 0, 0, DateTimeKind.Utc);
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(new[]
|
||||
var vm = Vm(new FakeClient(new[]
|
||||
{
|
||||
E(WorkerLogLevel.Info, "skipped", t0),
|
||||
E(WorkerLogLevel.Warn, "kept", t0.AddMinutes(1)),
|
||||
@@ -153,7 +157,7 @@ public class LogVisualizerViewModelTests
|
||||
[Fact]
|
||||
public async Task CopyLastCommand_disabled_when_no_rows()
|
||||
{
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(Array.Empty<WorkerLogEntry>()));
|
||||
var vm = Vm(new FakeClient(Array.Empty<WorkerLogEntry>()));
|
||||
await vm.RefreshAsync();
|
||||
|
||||
Assert.False(vm.CopyLastCommand.CanExecute(null));
|
||||
@@ -163,7 +167,7 @@ public class LogVisualizerViewModelTests
|
||||
public async Task CopyLastCommand_copies_and_reports_count_on_success()
|
||||
{
|
||||
string? copied = null;
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(new[] { E(WorkerLogLevel.Info, "a") }),
|
||||
var vm = Vm(new FakeClient(new[] { E(WorkerLogLevel.Info, "a") }),
|
||||
text => { copied = text; return Task.FromResult(true); });
|
||||
await vm.RefreshAsync();
|
||||
|
||||
@@ -176,7 +180,7 @@ public class LogVisualizerViewModelTests
|
||||
[Fact]
|
||||
public async Task CopyLastCommand_reports_failure_when_clipboard_unavailable()
|
||||
{
|
||||
var vm = new LogVisualizerViewModel(new FakeClient(new[] { E(WorkerLogLevel.Info, "a") }),
|
||||
var vm = Vm(new FakeClient(new[] { E(WorkerLogLevel.Info, "a") }),
|
||||
_ => Task.FromResult(false));
|
||||
await vm.RefreshAsync();
|
||||
|
||||
@@ -190,7 +194,7 @@ public class LogVisualizerViewModelTests
|
||||
{
|
||||
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);
|
||||
var vm = Vm(client);
|
||||
await vm.RefreshAsync();
|
||||
var row = vm.Rows.Single();
|
||||
|
||||
@@ -207,7 +211,7 @@ public class LogVisualizerViewModelTests
|
||||
{
|
||||
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);
|
||||
var vm = Vm(client);
|
||||
await vm.RefreshAsync();
|
||||
var existingRow = vm.Rows.Single();
|
||||
|
||||
@@ -226,7 +230,7 @@ public class LogVisualizerViewModelTests
|
||||
{
|
||||
Logs = new[] { E(WorkerLogLevel.Info, "a", t0), E(WorkerLogLevel.Info, "b", t0.AddMinutes(1)) },
|
||||
};
|
||||
var vm = new LogVisualizerViewModel(client);
|
||||
var vm = Vm(client);
|
||||
await vm.RefreshAsync();
|
||||
Assert.Equal(new[] { "b", "a" }, vm.Rows.Select(r => r.Message));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user