app: burn-up window charts, estimated days, full breakdown, one tooltip
agent-review agent review: fail

From developer feedback on the redesign:
- Week use per day draws estimated days hatched beside measured ones.
- Limit history becomes a burn-up chart per window instance: even-pace
  diagonal, used line without point markers, forecast to the reset,
  the previous instance faintly, and a strip of past peaks with their
  real start and end.
- The breakdown has its detail columns back, sorts by any column and
  expands "Other" to every row.
- One tooltip component, a title and a label/value grid, for every
  chart and table.
Also the review notes of #7: dated forecasts, the real span of the
recent rate, keyboard focus, distinct settings names, a wheel that no
longer changes selections, and version 1.1.0.

Refs #5, #7
This commit is contained in:
Florian Schmidt
2026-10-15 09:38:11 +02:00
parent e687a40346
commit ab8d245df8
14 changed files with 592 additions and 101 deletions
+98 -2
View File
@@ -59,6 +59,22 @@ public sealed class HeadlessTests
Dispatcher.UIThread.RunJobs();
panel.GetVisualDescendants().OfType<ComboBox>().Single().SelectedIndex = 1;
Assert.Contains(panel.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == "Claude · Week · Fable");
var wheelSelector = panel.GetVisualDescendants().OfType<ComboBox>().Single();
wheelSelector.BringIntoView(); Dispatcher.UIThread.RunJobs(); using (panel.CaptureRenderedFrame()) { }
wheelSelector.Focus();
var wheelViewport = panel.GetVisualDescendants().OfType<ScrollViewer>().First();
var beforeWheel = wheelViewport.Offset.Y;
panel.MouseWheel(wheelSelector.TranslatePoint(new Point(20, 16), panel)!.Value, new Vector(0, 1));
Dispatcher.UIThread.RunJobs();
Assert.Equal(1, wheelSelector.SelectedIndex);
Assert.True(wheelViewport.Offset.Y < beforeWheel);
foreach (var segment in panel.GetVisualDescendants().OfType<ToggleButton>().Where(b => b.Classes.Contains("segment")))
{
segment.Focus(); var rangeBefore = model.Range; var providerBefore = model.ProviderFilter;
panel.MouseWheel(segment.TranslatePoint(new Point(8, 8), panel)!.Value, new Vector(0, -1));
Assert.Equal(rangeBefore, model.Range); Assert.Equal(providerBefore, model.ProviderFilter);
}
wheelViewport.Offset = default;
model.History = originalHistory;
model.Snapshot = originalSnapshot with { Providers = originalSnapshot.Providers.Select(p => p.Provider == Provider.Claude ? p with { Windows = [] } : p).ToArray() };
Dispatcher.UIThread.RunJobs();
@@ -79,6 +95,12 @@ public sealed class HeadlessTests
var selected = panel.GetVisualDescendants().OfType<ToggleButton>().First(b => b.Classes.Contains("segment") && b.IsChecked == true);
Assert.Equal(theme == ThemeVariant.Dark ? "#ff383835" : "#ffe1e0d9", selected.Background?.ToString());
Assert.Equal(Avalonia.Media.FontWeight.SemiBold, selected.FontWeight);
selected.Focus(Avalonia.Input.NavigationMethod.Tab); Dispatcher.UIThread.RunJobs();
Assert.Equal(theme == ThemeVariant.Dark ? "#fff0efec" : "#ff0b0b0b", selected.BorderBrush?.ToString());
var neutralCheck = panel.GetVisualDescendants().OfType<NeutralCheckBox>().Single();
neutralCheck.Focus(Avalonia.Input.NavigationMethod.Tab); Dispatcher.UIThread.RunJobs();
Assert.Equal(theme == ThemeVariant.Dark ? "#fff0efec" : "#ff0b0b0b", neutralCheck.BorderBrush?.ToString());
Assert.True(neutralCheck.MarkVisible);
var glyph = panel.GetVisualDescendants().OfType<TextBlock>().Single(t => t.Name == "NeutralCheckGlyph");
Assert.Equal(theme == ThemeVariant.Dark ? "#fff0efec" : "#ff0b0b0b", glyph.Foreground?.ToString());
Assert.Equal(56, panel.GetVisualDescendants().OfType<Grid>().Single(g => g.Name == "PanelHeader").Bounds.Height);
@@ -90,17 +112,42 @@ public sealed class HeadlessTests
Assert.Equal(sessionTile.Bounds.Y, weekTile.Bounds.Y); Assert.Equal(weekTile.Bounds.Y, codexLimit.Bounds.Y);
Assert.True(sessionTile.Bounds.Height < weekTile.Bounds.Height);
}
foreach (var (name, target) in new[] { ("week", "Week use per day"), ("tokens", "Tokens"), ("history", "Limit history"), ("breakdown", "Breakdown") })
foreach (var (name, target) in new[] { ("week", "Week use per day"), ("tokens", "Tokens"), ("windows", "Window charts"), ("breakdown", "Breakdown") })
{
var text = panel.GetVisualDescendants().OfType<TextBlock>().First(t => t.Text == target);
var position = text.TranslatePoint(default, viewport)!.Value;
viewport.Offset = new Vector(0, viewport.Offset.Y + position.Y - 16);
Save(panel, stem + "-" + name + ".png");
if (name == "breakdown")
{
panel.GetVisualDescendants().OfType<Button>().Single(b => b.Content as string == "Show all 110").RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
Save(panel, stem + "-breakdown-expanded.png");
Assert.Contains(panel.GetVisualDescendants().OfType<Button>(), b => b.Content as string == "Show top 8");
panel.GetVisualDescendants().OfType<Button>().Single(b => b.Content as string == "Show top 8").RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
}
}
var prior = viewport.Offset;
model.Snapshot = model.Snapshot! with { MadeAt = DateTimeOffset.UtcNow }; Dispatcher.UIThread.RunJobs();
Assert.Equal(prior, viewport.Offset);
}
var earlyModel = FakeData.EarlyResetModel();
var earlyPanel = new PanelWindow(earlyModel, () => { }, () => { }, () => { }, () => { });
earlyPanel.Show();
var earlyTile = earlyPanel.GetVisualDescendants().OfType<Border>().Single(b => b.Name == "LimitTile-Codex-secondary");
Assert.DoesNotContain(earlyTile.GetVisualDescendants().OfType<TextBlock>(), t => t.Text?.Contains("at reset") == true || t.Text?.Contains("100 % on") == true || t.Text?.StartsWith("Last ") == true);
Assert.Null(Assert.Single(earlyModel.History.Limits).Forecast);
Assert.All(Assert.Single(earlyModel.History.Limits).Analysis!.Past, instance => Assert.True(instance.End <= earlyModel.Snapshot!.MadeAt));
foreach (var (width, height) in new[] { (1280, 900), (1500, 1000) })
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
{
earlyPanel.Width = width; earlyPanel.Height = height; earlyPanel.RequestedThemeVariant = theme;
var viewport = earlyPanel.GetVisualDescendants().OfType<ScrollViewer>().First(); viewport.Offset = default;
Save(earlyPanel, $"panel-{width}x{height}-{theme}-early-limits.png");
var heading = earlyPanel.GetVisualDescendants().OfType<TextBlock>().First(t => t.Text == "Window charts");
viewport.Offset = new Vector(0, viewport.Offset.Y + heading.TranslatePoint(default, viewport)!.Value.Y - 16);
Save(earlyPanel, $"panel-{width}x{height}-{theme}-early-windows.png");
}
earlyPanel.Close();
panel.Width = 1000; panel.Height = 900;
panel.GetVisualDescendants().OfType<ScrollViewer>().First().Offset = default; Save(panel, "panel-1000x900-light.png");
panel.Width = 1500; panel.Height = 1000;
@@ -117,6 +164,46 @@ public sealed class HeadlessTests
Save(panel, $"panel-{width}x{height}-{theme}-collecting-days.png");
}
model.History = originalHistory;
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
{
var weekData = originalHistory.Details.Single(d => d.Provider == Provider.Claude && d.Id == "week").Days!;
Assert.Contains(weekData.Current, d => d.Origin == UseOrigin.Estimated);
var future = DataTooltip.Day(new(DateTimeOffset.Now.AddDays(1), DateTimeOffset.Now.AddDays(2), null, 42, false, true));
Assert.DoesNotContain(future.Rows, row => row.Label == "Cumulative");
var types = new (string Name, DataTooltip Tip)[]
{
("day-estimated", DataTooltip.Day(weekData.Current.First(d => d.Origin == UseOrigin.Estimated))),
("day-measured", DataTooltip.Day(weekData.Current.Last(d => d.Used is not null && d.Origin == UseOrigin.Measured))),
("future-day", future),
("project", DataTooltip.Tokens("D:/Projects/Customer/Workspace/Project-with-a-long-name", new(100000000, 1900000000, 10000000, 53670717, 1234567, 2063670717))),
("tile", (DataTooltip)ToolTip.GetTip(panel.GetVisualDescendants().OfType<Border>().First(b => b.Name == "LimitTile-Claude-week"))!),
("tokens", DataTooltip.Tokens("Claude - This week", originalSnapshot.Providers[0].Week)),
};
var limit = originalHistory.Limits.Single(l => l.Provider == Provider.Claude && l.Window!.Window.Id == "week");
CaptureChartTip("burnup", new BurnUpChart(limit), new Point(240, 100));
CaptureChartTip("past-instance", new InstancePeaks(limit.Analysis!.Past, Provider.Claude), new Point(30, 30));
CaptureChartTip("past-limit-reached", new InstancePeaks(limit.Analysis!.Past, Provider.Claude), new Point(600, 30));
CaptureChartTip("hourly", new UsageChart { Values = originalHistory.Hourly }, new Point(60, 170));
CaptureChartTip("daily", new UsageChart { Values = originalHistory.Daily, Interval = TimeSpan.FromDays(1) }, new Point(60, 170));
CaptureChartTip("composition", new CompositionBar(originalSnapshot.Providers[0].Week, Provider.Claude, true) { Height = 8 }, new Point(100, 4));
void CaptureChartTip(string name, Control chartControl, Point hover)
{
var window = new Window { Width = 740, Height = 600, RequestedThemeVariant = theme }; Ui.Theme(window);
var content = Ui.Stack(Ui.Text(name, 20), chartControl); content.Margin = new Thickness(24); window.Content = content;
window.Show(); Dispatcher.UIThread.RunJobs(); using (window.CaptureRenderedFrame()) { }
window.MouseMove(chartControl.TranslatePoint(hover, window)!.Value);
var actualTip = Assert.IsType<DataTooltip>(ToolTip.GetTip(chartControl));
window.MouseMove(new Point(0, 0)); ToolTip.SetIsOpen(chartControl, false);
content.Children.Add(new DataTooltip(actualTip.Title, actualTip.Rows.ToArray()));
Save(window, $"tooltip-{name}-{theme}.png"); window.Close();
}
foreach (var (name, tip) in types)
{
var tooltipWindow = new Window { Width = 620, Height = 300, RequestedThemeVariant = theme };
Ui.Theme(tooltipWindow); tooltipWindow.Content = new Border { Child = tip, Padding = new Thickness(24), VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center };
tooltipWindow.Show(); Save(tooltipWindow, $"tooltip-{name}-{theme}.png"); tooltipWindow.Close();
}
}
model.Snapshot = FakeData.Snapshot(DateTimeOffset.UtcNow, true);
Dispatcher.UIThread.RunJobs(); panel.GetVisualDescendants().OfType<ScrollViewer>().First().Offset = default;
Save(panel, "panel-unavailable.png");
@@ -133,10 +220,19 @@ public sealed class HeadlessTests
expander.IsExpanded = true; panel.UpdateLayout();
panel.GetVisualDescendants().OfType<ScrollViewer>().First().Offset = new Vector(0, 100000);
Save(panel, "panel-diagnostics-expanded.png"); panel.Close();
string? folder = null; var quitCalls = 0; var saveCalls = 0;
var actions = new SettingsWindow(new(), new(PluginInstallState.NoHostFound), _ => { saveCalls++; return Task.CompletedTask; }, () => quitCalls++, path => folder = path);
actions.Show();
void ClickSettings(string text) => actions.GetVisualDescendants().OfType<Button>().Single(b => b.Content as string == text).RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
ClickSettings("Open folder"); Assert.Equal(DataPaths.DataDirectory, folder);
ClickSettings("Quit FinalToken"); Assert.Equal(1, quitCalls);
ClickSettings("Cancel"); Assert.False(actions.IsVisible); Assert.Equal(0, saveCalls);
Settings? saved = null;
var initial = new Settings { StartWithOs = true, StreamDeckInstallMode = InstallMode.Automatic, DismissedPluginVersion = "0.9" };
var settings = new SettingsWindow(initial, new(PluginInstallState.Outdated, "1.0", "0.9"), value => { saved = value; return Task.CompletedTask; }, () => { });
settings.Show(); Save(settings, "settings.png");
var providerNames = settings.GetVisualDescendants().OfType<CheckBox>().Select(c => c.Name).ToArray();
Assert.Equal(providerNames.Length, providerNames.Distinct().Count());
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
{
settings.RequestedThemeVariant = theme;
@@ -184,7 +280,7 @@ public sealed class HeadlessTests
var chartWindow = new Window { Content = chart, Width = 400, Height = 180 };
chartWindow.Show();
using (chartWindow.CaptureRenderedFrame()) { }
chartWindow.MouseMove(new Point(65, 80));
chartWindow.MouseMove(new Point(200, 100));
Assert.Contains(123456.ToString("N0"), ToolTip.GetTip(chart)?.ToString()); chartWindow.Close();
var polishShots = shots;
Directory.CreateDirectory(polishShots);
+54 -7
View File
@@ -5,6 +5,37 @@ namespace FinalToken.App.Tests;
public sealed class ViewModelTests
{
[Fact] public async Task RefreshIgnoresConcurrentRequestsAndClearsGuardAfterFailure()
{
var model = new PanelViewModel(); var completion = new TaskCompletionSource(); var calls = 0;
var first = model.RefreshAsync(() => { calls++; return completion.Task; });
Assert.True(model.Refreshing);
await model.RefreshAsync(() => { calls++; return Task.CompletedTask; });
Assert.Equal(1, calls); completion.SetResult(); await first; Assert.False(model.Refreshing);
await Assert.ThrowsAsync<IOException>(() => model.RefreshAsync(() => throw new IOException("fixture")));
Assert.False(model.Refreshing);
}
[Theory]
[InlineData(-1, "now")]
[InlineData(0, "now")]
[InlineData(59, "1 min")]
[InlineData(3600, "1 h 0 min")]
[InlineData(90061, "1 d 1 h")]
public void DurationUsesDaysHoursAndRoundedMinutes(int seconds, string expected)
=> Assert.Equal(expected, Display.Duration(TimeSpan.FromSeconds(seconds)));
[Theory]
[InlineData(PaceState.Ahead, "\u25b2 Ahead")]
[InlineData(PaceState.Behind, "\u25bc Behind")]
[InlineData(PaceState.OnTrack, "\u2713 On track")]
[InlineData(PaceState.Unknown, "? Pace unknown")]
public void StatusChipsAlwaysNameTheirState(PaceState state, string expected) => Assert.Equal(expected, Display.State(state));
[Fact] public void BreakdownSortingUsesTheSelectedNumericColumn()
{
BreakdownRow[] rows = [new("a", new(Input: 30, Output: 2, Total: 32), .4), new("b", new(Input: 10, Output: 40, Total: 50), .6)];
Assert.Equal("b", BreakdownTable.SortRows(rows, BreakdownColumn.Total, true).First().Name);
Assert.Equal("a", BreakdownTable.SortRows(rows, BreakdownColumn.Input, true).First().Name);
Assert.Equal("a", BreakdownTable.SortRows(rows, BreakdownColumn.Output, false).First().Name);
}
[Theory]
[InlineData(-1)]
[InlineData(1)]
@@ -129,7 +160,7 @@ internal static class FakeData
public static Snapshot Snapshot(DateTimeOffset now, bool unavailable = false) => new()
{
MadeAt = now, RefreshInterval = TimeSpan.FromSeconds(60), Providers =
[new(Provider.Claude, ProviderStatus.Available, null, [Window(Provider.Claude, "session", "Session · 5 h", 12, now, 5, 1), Window(Provider.Claude, "week", "Week · all models", 70, now, 168, 84)],
[new(Provider.Claude, ProviderStatus.Available, null, [Window(Provider.Claude, "session", "Session · 5 h", 12, now, 5, 1), Window(Provider.Claude, "week", "Week · all models", 98, now, 168, 24)],
new(12000000, 218000000, 2000000, 47000000, 0, 279000000), new(4000000, 6000000, 1000000, 1600000, 0, 12600000), new(85000000, 1920000000, 16000000, 259000000, 0, 2280000000)),
new(Provider.Codex, unavailable ? ProviderStatus.Unavailable : ProviderStatus.Available, unavailable ? "CLI is not installed. Token history remains available." : null,
[Window(Provider.Codex, "secondary", "Week", 86, now, 168, 24)],
@@ -137,6 +168,22 @@ internal static class FakeData
};
private static WindowSnapshot Window(Provider provider, string id, string label, double percent, DateTimeOffset now, int hours, int resetHours)
{ var w = new LimitWindow(provider, id, label, percent, now.AddHours(resetHours), TimeSpan.FromHours(hours), now.AddMinutes(-3), "fixture"); return new(w, Pace.Calculate(w, now)); }
public static PanelViewModel EarlyResetModel()
{
var now = DateTimeOffset.UtcNow;
var transition = now.AddHours(-1);
var store = new HistoryStore(Path.Combine(Path.GetTempPath(), "finaltoken-early", Guid.NewGuid().ToString("N")), new DiagnosticLog());
var snapshot = Snapshot(now);
var codex = snapshot.Providers.Single(p => p.Provider == Provider.Codex);
var window = codex.Windows[0].Window with { UsedPercent = 2, ResetsAt = transition.AddDays(7), SampleTime = now };
var previous = window with { ResetsAt = transition.AddDays(5), SampleTime = transition.AddDays(-1), UsedPercent = 40 };
store.AddLimits([previous, window with { SampleTime = transition, UsedPercent = 1 }, window]);
var start = previous.ResetsAt!.Value - previous.Length!.Value;
void Add(DateTimeOffset time, long input, string id) => store.Add(new(Provider.Codex, time, "gpt-6.1-sol", "Fixture/Project", new(Input: input, Total: input), id));
Add(start, 1000000, "a"); Add(previous.SampleTime.AddHours(1), 5000000, "b"); Add(transition, 100000, "c");
snapshot = snapshot with { Providers = [codex with { Windows = [new(window, Pace.Calculate(window, now))] }] };
return new() { Snapshot = snapshot, History = PanelViewModel.QueryHistory(store, snapshot, HistoryRange.Days7, null, now) };
}
public static PanelViewModel Model(bool unavailable = false)
{
var now = DateTimeOffset.UtcNow;
@@ -144,20 +191,20 @@ internal static class FakeData
var snapshot = Snapshot(now, unavailable);
foreach (var provider in snapshot.Providers)
{
for (var i = 0; i < 168; i++)
for (var i = 0; i < 336; i++)
{
var input = 1000000 + i * 10000; var cache = input * 8;
store.Add(new(provider.Provider, now.AddHours(-168 + i), provider.Provider == Provider.Claude ? "claude-fable" : "gpt-6.1-sol",
store.Add(new(provider.Provider, now.AddHours(-336 + i), provider.Provider == Provider.Claude ? "claude-fable" : "gpt-6.1-sol",
$"D:/Projects/Customer-{i % 110}/Workspace/Project-{i % 110}",
provider.Provider == Provider.Claude ? new(input, cache, 200000, 500000, 0, input + cache + 700000) : new(input + cache, cache, 0, 500000, 100000, input + cache + 500000), $"{provider.Provider}-{i}"));
}
foreach (var ws in provider.Windows.Where(w => w.Window.Length > TimeSpan.FromDays(1)))
foreach (var ws in provider.Windows)
{
var w = ws.Window; var start = w.ResetsAt!.Value - w.Length!.Value;
for (var i = 0; i <= (int)(now - start).TotalHours; i += 3)
for (var i = provider.Provider == Provider.Claude && w.Length > TimeSpan.FromDays(1) ? (int)(now - start).TotalHours - 24 : 0; i <= (int)(now - start).TotalHours; i += w.Length > TimeSpan.FromDays(1) ? 3 : 1)
store.AddLimits([w with { SampleTime = start.AddHours(i), UsedPercent = w.UsedPercent * i / (now - start).TotalHours }]);
for (var i = 0; i < 168; i += 6)
store.AddLimits([w with { ResetsAt = w.ResetsAt.Value.AddDays(-7), SampleTime = start.AddDays(-7).AddHours(i), UsedPercent = i * .5 }]);
for (var i = 0; i < (int)w.Length!.Value.TotalHours; i += w.Length > TimeSpan.FromDays(1) ? 6 : 1)
store.AddLimits([w with { ResetsAt = w.ResetsAt.Value - w.Length.Value, SampleTime = start - w.Length.Value + TimeSpan.FromHours(i), UsedPercent = 100.0 * i / w.Length.Value.TotalHours }]);
}
}
return new() { Snapshot = snapshot, Message = "Updated just now", History = PanelViewModel.QueryHistory(store, snapshot, HistoryRange.Days7, null, now) };