core: plan the daily budget per day, start forecasts at 2 % and follow the limit week
agent-review agent review: fail
agent-review agent review: fail
The budget was the rest of the week over the time left, so each use today lowered it and a partial first day was held to a full day. Now each day of the instance has its share, its even pace and its budget. Today's budget starts from the use at the day start and does not move with today's use (D7). Forecasts start at 2 % of a window, so an early reset no longer hides them for most of a day. Limit tiles of one kind show the same rows, with placeholders that say why a value is missing. The week chart draws per-day steps and marks the instance start and reset (D8). Week token totals follow the provider's limit week and say since when, with the calendar week as fallback (D9). Refs #13
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using System.Text.Json;
|
||||
using Xunit;
|
||||
|
||||
namespace FinalToken.Core.Tests;
|
||||
|
||||
public sealed class WeekTotalsTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("limit", true)]
|
||||
[InlineData("family", false)]
|
||||
[InlineData("expired", false)]
|
||||
[InlineData("missing", false)]
|
||||
[InlineData("mixed", true)]
|
||||
public async Task EngineSelectsProviderWeekOrCalendarFallback(string kind, bool limit)
|
||||
{
|
||||
using var directory = new TestDirectory();
|
||||
var clock = new WeekClock(); var now = clock.GetUtcNow();
|
||||
await using var engine = new RefreshEngine(directory.Path, clock, claudeDirectory: directory.Path, codexDirectory: directory.Path,
|
||||
cliDiscovery: (_, _) => new(null, "Fixture CLI missing."));
|
||||
var start = new DateTimeOffset(2026, 10, 10, 22, 40, 0, TimeSpan.Zero);
|
||||
var week = new LimitWindow(Provider.Codex, "week", "Week", 30, start.AddDays(7), TimeSpan.FromDays(7), now, "fixture");
|
||||
var family = week with { Id = "family", Label = "Week (Fable)", Length = TimeSpan.FromDays(8) };
|
||||
engine.History.AddLimits(kind switch
|
||||
{
|
||||
"limit" => [week], "family" => [family], "expired" => [week with { ResetsAt = now.AddHours(-1) }],
|
||||
"mixed" => [family, week, week with { Id = "short", Length = TimeSpan.FromDays(2) }], _ => []
|
||||
});
|
||||
foreach (var (time, count) in new[] { (now.AddDays(-5), 10), (now.AddDays(-3), 20), (now.AddDays(-1), 30) })
|
||||
engine.History.Add(new(Provider.Codex, time, "fixture", "fixture", new(Total: count), count.ToString()));
|
||||
var snapshot = await engine.RefreshNowAsync(true, TestContext.Current.CancellationToken);
|
||||
var provider = snapshot.Providers.Single(p => p.Provider == Provider.Codex);
|
||||
Assert.Equal(limit ? 50 : 30, provider.Week.Total);
|
||||
Assert.Equal(limit ? start : new DateTimeOffset(2026, 10, 12, 0, 0, 0, TimeSpan.Zero), provider.WeekStart);
|
||||
Assert.Equal(limit ? "week" : null, provider.WeekWindow);
|
||||
}
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void SourceGeneratedJsonReadsNewAndLegacyWeekFields(bool limit)
|
||||
{
|
||||
var start = new DateTimeOffset(2026, 10, 10, 22, 40, 0, TimeSpan.Zero);
|
||||
var snapshot = new Snapshot { MadeAt = start.AddDays(2), RefreshInterval = TimeSpan.FromMinutes(1),
|
||||
Providers = [new(Provider.Codex, ProviderStatus.Available, null, [], new(), null, new(Total: 30), start, limit ? "week" : null)] };
|
||||
var json = JsonSerializer.Serialize(snapshot, CoreJsonContext.Default.Snapshot);
|
||||
Assert.Contains("\"weekStart\"", json);
|
||||
Assert.Equal(limit, json.Contains("\"weekWindow\"", StringComparison.Ordinal));
|
||||
var provider = Assert.Single(JsonSerializer.Deserialize(json, CoreJsonContext.Default.Snapshot)!.Providers);
|
||||
Assert.Equal(start, provider.WeekStart); Assert.Equal(limit ? "week" : null, provider.WeekWindow);
|
||||
const string old = """{"v":1,"madeAt":"2026-10-14T16:00:00Z","refreshInterval":"00:01:00","providers":[{"provider":1,"status":0,"windows":[],"today":{},"session":null,"week":{"total":30}}]}""";
|
||||
var legacy = JsonSerializer.Deserialize(old, CoreJsonContext.Default.Snapshot)!;
|
||||
Assert.Equal(1, legacy.V); Assert.Equal(30, legacy.Providers[0].Week.Total);
|
||||
Assert.Equal(default, legacy.Providers[0].WeekStart); Assert.Null(legacy.Providers[0].WeekWindow);
|
||||
}
|
||||
private sealed class WeekClock : TimeProvider
|
||||
{
|
||||
public override DateTimeOffset GetUtcNow() => new(2026, 10, 14, 16, 0, 0, TimeSpan.Zero);
|
||||
public override TimeZoneInfo LocalTimeZone => TimeZoneInfo.Utc;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user