app: burn-up window charts, estimated days, full breakdown, one tooltip
agent-review agent review: fail
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:
@@ -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) };
|
||||
|
||||
Reference in New Issue
Block a user