app: render the panel with an injected clock so tests do not depend on the date #12

Merged
schmidt.florian merged 2 commits from 11-panel-clock into master 2026-10-17 09:28:16 +02:00
3 changed files with 9 additions and 9 deletions
Showing only changes of commit 0549e862c5 - Show all commits
@@ -156,7 +156,7 @@ public sealed class LimitAnalysisTests
[Fact] public void ModelSeriesGroupsInOnePassAndMatchesTotals() [Fact] public void ModelSeriesGroupsInOnePassAndMatchesTotals()
{ {
using var directory = new TestDirectory(); using var directory = new TestDirectory();
var store = new HistoryStore(directory.Path, new DiagnosticLog()); var store = new HistoryStore(directory.Path, new DiagnosticLog(), new TestClock());
store.Add(new(Provider.Claude, Now.AddHours(-2), "a", "p", new(Total: 20), "a")); store.Add(new(Provider.Claude, Now.AddHours(-2), "a", "p", new(Total: 20), "a"));
store.Add(new(Provider.Claude, Now.AddHours(-2), "b", "p", new(Total: 30), "b")); store.Add(new(Provider.Claude, Now.AddHours(-2), "b", "p", new(Total: 30), "b"));
store.Add(new(Provider.Claude, Now.AddHours(-1), "a", "p", new(Total: 40), "c")); store.Add(new(Provider.Claude, Now.AddHours(-1), "a", "p", new(Total: 40), "c"));
+2 -2
View File
@@ -90,11 +90,11 @@ public class ReworkTests
using var directory = new TestDirectory(); using var directory = new TestDirectory();
var source = directory.Write("claude/projects/p/a.jsonl", Fixtures.Claude()); var source = directory.Write("claude/projects/p/a.jsonl", Fixtures.Claude());
var log = new DiagnosticLog(); var log = new DiagnosticLog();
var store = new HistoryStore(directory.Path, log); var store = new HistoryStore(directory.Path, log, new TestClock());
var scanner = new IncrementalScanner(store, log, Path.Combine(directory.Path, "claude"), directory.Path); var scanner = new IncrementalScanner(store, log, Path.Combine(directory.Path, "claude"), directory.Path);
Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
await store.SaveAsync(TestContext.Current.CancellationToken); await store.SaveAsync(TestContext.Current.CancellationToken);
store = new(directory.Path, log); store = new(directory.Path, log, new TestClock());
scanner = new(store, log, Path.Combine(directory.Path, "claude"), directory.Path); scanner = new(store, log, Path.Combine(directory.Path, "claude"), directory.Path);
using var exclusive = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.None); using var exclusive = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.None);
Assert.Equal(0, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(0, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
+6 -6
View File
@@ -10,14 +10,14 @@ public class StorageTests
{ {
using var directory = new TestDirectory(); using var directory = new TestDirectory();
var source = directory.Write("claude/projects/p/session.jsonl", Fixtures.Claude()); var source = directory.Write("claude/projects/p/session.jsonl", Fixtures.Claude());
var history = new HistoryStore(directory.Path, new()); var history = new HistoryStore(directory.Path, new(), new TestClock());
var scanner = new IncrementalScanner(history, new(), Path.Combine(directory.Path, "claude"), Path.Combine(directory.Path, "codex")); var scanner = new IncrementalScanner(history, new(), Path.Combine(directory.Path, "claude"), Path.Combine(directory.Path, "codex"));
Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
Assert.Equal(0, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(0, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
await File.AppendAllTextAsync(source, Fixtures.Claude("b"), cancellationToken: TestContext.Current.CancellationToken); await File.AppendAllTextAsync(source, Fixtures.Claude("b"), cancellationToken: TestContext.Current.CancellationToken);
Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
await history.SaveAsync(TestContext.Current.CancellationToken); await history.SaveAsync(TestContext.Current.CancellationToken);
history = new(directory.Path, new()); history = new(directory.Path, new(), new TestClock());
scanner = new(history, new(), Path.Combine(directory.Path, "claude"), Path.Combine(directory.Path, "codex")); scanner = new(history, new(), Path.Combine(directory.Path, "claude"), Path.Combine(directory.Path, "codex"));
Assert.Equal(0, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(0, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
await File.WriteAllTextAsync(source, Fixtures.Claude(), cancellationToken: TestContext.Current.CancellationToken); await File.WriteAllTextAsync(source, Fixtures.Claude(), cancellationToken: TestContext.Current.CancellationToken);
@@ -36,7 +36,7 @@ public class StorageTests
using var directory = new TestDirectory(); using var directory = new TestDirectory();
var fixture = Fixtures.Claude(); var fixture = Fixtures.Claude();
var source = directory.Write("claude/projects/p/session.jsonl", fixture[..30]); var source = directory.Write("claude/projects/p/session.jsonl", fixture[..30]);
var history = new HistoryStore(directory.Path, new()); var history = new HistoryStore(directory.Path, new(), new TestClock());
var scanner = new IncrementalScanner(history, new(), Path.Combine(directory.Path, "claude"), directory.Path); var scanner = new IncrementalScanner(history, new(), Path.Combine(directory.Path, "claude"), directory.Path);
Assert.Equal(0, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(0, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
await File.AppendAllTextAsync(source, fixture[30..], cancellationToken: TestContext.Current.CancellationToken); await File.AppendAllTextAsync(source, fixture[30..], cancellationToken: TestContext.Current.CancellationToken);
@@ -79,7 +79,7 @@ public class StorageTests
using var directory = new TestDirectory(); using var directory = new TestDirectory();
directory.Write("claude/projects/p/a.jsonl", "{\n" + Fixtures.Claude()); directory.Write("claude/projects/p/a.jsonl", "{\n" + Fixtures.Claude());
var log = new DiagnosticLog(); var log = new DiagnosticLog();
var scanner = new IncrementalScanner(new(directory.Path, log), log, Path.Combine(directory.Path, "claude"), directory.Path); var scanner = new IncrementalScanner(new(directory.Path, log, new TestClock()), log, Path.Combine(directory.Path, "claude"), directory.Path);
Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
Assert.Single(log.Recent); Assert.Single(log.Recent);
} }
@@ -89,7 +89,7 @@ public class StorageTests
using var directory = new TestDirectory(); using var directory = new TestDirectory();
var line = Fixtures.Claude().Replace("{\"type\"", "{\"padding\":\"" + new string('x', 4 * 1024 * 1024) + "\",\"type\""); var line = Fixtures.Claude().Replace("{\"type\"", "{\"padding\":\"" + new string('x', 4 * 1024 * 1024) + "\",\"type\"");
directory.Write("claude/projects/p/large.jsonl", line); directory.Write("claude/projects/p/large.jsonl", line);
var scanner = new IncrementalScanner(new(directory.Path, new()), new(), Path.Combine(directory.Path, "claude"), directory.Path); var scanner = new IncrementalScanner(new(directory.Path, new(), new TestClock()), new(), Path.Combine(directory.Path, "claude"), directory.Path);
Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents); Assert.Equal(1, (await scanner.ScanAsync(TestContext.Current.CancellationToken)).AddedEvents);
} }
[Fact] [Fact]
@@ -159,7 +159,7 @@ public class StorageTests
public void QueriesAggregateByHourDayModelProjectAndLimitWindow() public void QueriesAggregateByHourDayModelProjectAndLimitWindow()
{ {
using var directory = new TestDirectory(); using var directory = new TestDirectory();
var history = new HistoryStore(directory.Path, new()); var history = new HistoryStore(directory.Path, new(), new TestClock());
var now = new DateTimeOffset(2026, 10, 14, 16, 30, 0, TimeSpan.Zero); var now = new DateTimeOffset(2026, 10, 14, 16, 30, 0, TimeSpan.Zero);
history.Add(new(Provider.Claude, now.AddHours(-1), "a", "/one", new(Total: 10), "a")); history.Add(new(Provider.Claude, now.AddHours(-1), "a", "/one", new(Total: 10), "a"));
history.Add(new(Provider.Claude, now, "b", "/two", new(Total: 20), "b")); history.Add(new(Provider.Claude, now, "b", "/two", new(Total: 20), "b"));