The reach date, the dotted forecast and the popup warning showed only for Claude. Codex had reset its week ten hours before and stood at 39 %, ahead by 33 points, but every forecast shared a gate that opened only after 10 % of the window. Nothing in the forecast paths was provider-specific; Codex was just the window early in its week. The gate now also opens as soon as the window is ahead, with the configured threshold, so it never disagrees with the chip. Average, recent and popup forecasts all use it. Until forecasts start, the tile and the window chart say when they will. Refs #5
This commit is contained in:
@@ -145,6 +145,35 @@ public sealed class HeadlessTests
|
||||
model.Snapshot = model.Snapshot! with { MadeAt = DateTimeOffset.UtcNow }; Dispatcher.UIThread.RunJobs();
|
||||
Assert.Equal(prior, viewport.Offset);
|
||||
}
|
||||
var forecastModel = FakeData.ForecastModel();
|
||||
var forecastPanel = new PanelWindow(forecastModel, () => { }, () => { }, () => { }, () => { });
|
||||
forecastPanel.Show(); Dispatcher.UIThread.RunJobs();
|
||||
var aheadTile = forecastPanel.GetVisualDescendants().OfType<Border>().Single(b => b.Name == "LimitTile-Codex-primary");
|
||||
Assert.Contains(aheadTile.GetVisualDescendants().OfType<TextBlock>(), t => t.Text?.StartsWith("100 % on ") == true);
|
||||
Assert.Contains(aheadTile.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == "⚠ ");
|
||||
Assert.NotNull(forecastModel.History.Limits.Single(l => l.Window!.Window.Id == "primary").Forecast);
|
||||
var waitingTile = forecastPanel.GetVisualDescendants().OfType<Border>().Single(b => b.Name == "LimitTile-Codex-secondary");
|
||||
var note = Assert.Single(waitingTile.GetVisualDescendants().OfType<TextBlock>(), t => t.Text?.StartsWith("Forecast from ") == true).Text;
|
||||
Assert.Contains(forecastPanel.GetVisualDescendants().OfType<BurnUpChart>(), c => c.GetVisualDescendants().OfType<TextBlock>().Any(t => t.Text == note));
|
||||
var aheadWindow = forecastModel.Snapshot!.Providers[0].Windows[0];
|
||||
var earlyAlert = new PopupDecider().Observe(aheadWindow.Window, aheadWindow.Pace, new Settings());
|
||||
Assert.NotNull(earlyAlert);
|
||||
var earlyPopup = PopupWindow.Pace(earlyAlert, () => { }); earlyPopup.Show();
|
||||
Assert.Contains(earlyPopup.GetVisualDescendants().OfType<TextBlock>(), t => t.Text?.Contains("⚠ 100 % on ") == true);
|
||||
earlyPopup.Close();
|
||||
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
|
||||
{
|
||||
forecastPanel.Width = 1280; forecastPanel.Height = 900; forecastPanel.RequestedThemeVariant = theme;
|
||||
var viewport = forecastPanel.GetVisualDescendants().OfType<ScrollViewer>().First(); viewport.Offset = default;
|
||||
Save(forecastPanel, $"forecast-1280x900-{theme}-limits.png");
|
||||
var heading = forecastPanel.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(forecastPanel, $"forecast-1280x900-{theme}-windows.png");
|
||||
var charts = forecastPanel.GetVisualDescendants().OfType<BurnUpChart>().ToArray();
|
||||
Assert.Equal(2, charts.Length);
|
||||
Assert.True(DrawsForecast(charts[0])); Assert.False(DrawsForecast(charts[1]));
|
||||
}
|
||||
forecastPanel.Close();
|
||||
var earlyModel = FakeData.EarlyResetModel();
|
||||
var earlyPanel = new PanelWindow(earlyModel, () => { }, () => { }, () => { }, () => { });
|
||||
earlyPanel.Show();
|
||||
@@ -323,6 +352,15 @@ public sealed class HeadlessTests
|
||||
foreach (var theme in new[] { ThemeVariant.Dark, ThemeVariant.Light })
|
||||
{ window.RequestedThemeVariant = theme; Save(window, stem + "-" + theme + ".png"); }
|
||||
}
|
||||
bool DrawsForecast(BurnUpChart chart)
|
||||
{
|
||||
var drawing = new Avalonia.Media.DrawingGroup();
|
||||
using (var context = drawing.Open()) chart.Render(context);
|
||||
return HasForecast(drawing);
|
||||
static bool HasForecast(Avalonia.Media.DrawingGroup group) => group.Children.Any(d =>
|
||||
d is Avalonia.Media.GeometryDrawing { Pen.DashStyle.Dashes: { } dashes } && dashes.SequenceEqual(new double[] { 1, 3 }) ||
|
||||
d is Avalonia.Media.DrawingGroup nested && HasForecast(nested));
|
||||
}
|
||||
void Save(Window window, string name, string? destination = null)
|
||||
{
|
||||
Dispatcher.UIThread.RunJobs();
|
||||
|
||||
@@ -5,6 +5,15 @@ namespace FinalToken.App.Tests;
|
||||
|
||||
public sealed class ViewModelTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(10, true)]
|
||||
[InlineData(40, false)]
|
||||
public void HistoryForecastsUseTheSnapshotsConfiguredPace(double threshold, bool eligible)
|
||||
{
|
||||
var model = FakeData.ForecastModel(threshold);
|
||||
Assert.Equal(eligible, model.History.Limits.Single(l => l.Window!.Window.Id == "primary").Forecast is not null);
|
||||
Assert.Equal(eligible, model.History.Details.Single(d => d.Id == "primary").Recent is not null);
|
||||
}
|
||||
[Fact] public async Task RefreshIgnoresConcurrentRequestsAndClearsGuardAfterFailure()
|
||||
{
|
||||
var model = new PanelViewModel(); var completion = new TaskCompletionSource(); var calls = 0;
|
||||
@@ -157,6 +166,19 @@ public sealed class ViewModelTests
|
||||
|
||||
internal static class FakeData
|
||||
{
|
||||
public static PanelViewModel ForecastModel(double threshold = 10)
|
||||
{
|
||||
var now = new DateTimeOffset(2026, 10, 15, 16, 45, 0, TimeSpan.Zero);
|
||||
var ahead = new LimitWindow(Provider.Codex, "primary", "Week", 39,
|
||||
new(2026, 10, 22, 6, 18, 0, TimeSpan.Zero), TimeSpan.FromDays(7), now, "fixture");
|
||||
var early = ahead with { Id = "secondary", Label = "Week · early on track", UsedPercent = 1, ResetsAt = now.AddDays(7).AddHours(-1) };
|
||||
var store = new HistoryStore(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")), new DiagnosticLog());
|
||||
store.AddLimits([ahead with { SampleTime = now.AddHours(-4), UsedPercent = 20 }, ahead,
|
||||
early with { SampleTime = now.AddHours(-1), UsedPercent = 0 }, early]);
|
||||
var snapshot = Snapshot(now) with { Providers = [Snapshot(now).Providers[1] with
|
||||
{ Windows = [new(ahead, Pace.Calculate(ahead, now, threshold)), new(early, Pace.Calculate(early, now, threshold))] }] };
|
||||
return new() { Snapshot = snapshot, History = PanelViewModel.QueryHistory(store, snapshot, HistoryRange.Days7, null, now) };
|
||||
}
|
||||
public static Snapshot Snapshot(DateTimeOffset now, bool unavailable = false) => new()
|
||||
{
|
||||
MadeAt = now, RefreshInterval = TimeSpan.FromSeconds(60), Providers =
|
||||
|
||||
Reference in New Issue
Block a user