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
91 lines
4.2 KiB
C#
91 lines
4.2 KiB
C#
using Xunit;
|
|
|
|
namespace FinalToken.Core.Tests;
|
|
|
|
public class EarlyForecastTests
|
|
{
|
|
private static readonly DateTimeOffset Now = new(2026, 10, 15, 16, 45, 0, TimeSpan.Zero);
|
|
private static LimitWindow Week(double used = 39) => new(Provider.Codex, "primary", "Week", used,
|
|
new(2026, 10, 22, 6, 18, 0, TimeSpan.Zero), TimeSpan.FromDays(7), Now, "fixture");
|
|
|
|
[Fact] public void AheadCodexWeekProjectsEarly()
|
|
{
|
|
var window = Week(); var pace = Pace.Calculate(window, Now);
|
|
Assert.Equal(PaceState.Ahead, pace.State);
|
|
Assert.InRange(pace.ElapsedFraction!.Value, .061, .063);
|
|
Assert.NotNull(pace.Projection);
|
|
Assert.InRange(pace.Projection.Value, Now, window.ResetsAt!.Value);
|
|
}
|
|
|
|
[Fact] public void AheadCodexWeekHasAverageForecast() => Assert.NotNull(LimitAnalysis.AverageUseAtReset(Week(), Now));
|
|
|
|
[Fact] public void AheadCodexWeekHasRecentForecast()
|
|
{
|
|
var window = Week();
|
|
var recent = LimitAnalysis.Recent(window, [window with { SampleTime = Now.AddHours(-4), UsedPercent = 20 }], Now);
|
|
Assert.NotNull(recent); Assert.NotNull(recent.ReachesLimit);
|
|
Assert.Equal(TimeSpan.FromHours(4), recent.Span);
|
|
}
|
|
|
|
[Fact] public void AheadCodexPopupIncludesProjection()
|
|
{
|
|
var window = Week();
|
|
var popup = new PopupDecider().Observe(window, Pace.Calculate(window, Now), new Settings());
|
|
Assert.NotNull(popup); Assert.NotNull(popup.Projection);
|
|
}
|
|
|
|
[Fact] public void OnePercentOneHourIntoWeekDoesNotForecast()
|
|
{
|
|
var window = Week(1) with { ResetsAt = Now.AddDays(7).AddHours(-1) };
|
|
Assert.Equal(PaceState.OnTrack, Pace.Calculate(window, Now).State);
|
|
Assert.Null(Pace.Calculate(window, Now).Projection);
|
|
Assert.Null(LimitAnalysis.AverageUseAtReset(window, Now));
|
|
Assert.Null(LimitAnalysis.Recent(window, [], Now));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(10, true)]
|
|
[InlineData(40, false)]
|
|
public void AllForecastsFollowConfiguredThreshold(double threshold, bool eligible)
|
|
{
|
|
var window = Week() with { Length = TimeSpan.FromDays(28), ResetsAt = Now.AddDays(28).AddHours(-4) }; var pace = Pace.Calculate(window, Now, threshold);
|
|
Assert.Equal(eligible, pace.State == PaceState.Ahead);
|
|
Assert.Equal(eligible, Pace.CanForecast(window, Now, threshold));
|
|
Assert.Equal(eligible, pace.Projection is not null);
|
|
Assert.Equal(eligible, LimitAnalysis.AverageUseAtReset(window, Now, pace) is not null);
|
|
Assert.Equal(eligible, LimitAnalysis.Recent(window,
|
|
[window with { SampleTime = Now.AddHours(-4), UsedPercent = 20 }], Now, pace) is not null);
|
|
}
|
|
|
|
[Fact] public void ExactlyAheadThresholdEnablesEarlyForecasts()
|
|
{
|
|
var window = Week(); var threshold = Pace.Calculate(window, Now).Delta!.Value;
|
|
var pace = Pace.Calculate(window, Now, threshold);
|
|
Assert.Equal(PaceState.Ahead, pace.State);
|
|
Assert.NotNull(pace.Projection);
|
|
Assert.NotNull(LimitAnalysis.AverageUseAtReset(window, Now, pace));
|
|
Assert.NotNull(LimitAnalysis.Recent(window, [window with { SampleTime = Now.AddHours(-4), UsedPercent = 20 }], Now, pace));
|
|
}
|
|
|
|
[Fact] public void UnderPaceCodexAtSixPointFourPercentShowsUseAtReset()
|
|
{
|
|
var window = Week(4) with { ResetsAt = Now + TimeSpan.FromTicks(TimeSpan.FromDays(7).Ticks * 936 / 1000) };
|
|
var pace = Pace.Calculate(window, Now);
|
|
Assert.Equal(PaceState.OnTrack, pace.State);
|
|
Assert.Null(pace.Projection);
|
|
Assert.Equal(62.5, LimitAnalysis.AverageUseAtReset(window, Now)!.Value, 8);
|
|
}
|
|
|
|
[Fact] public void ForecastStartIsTwoPercentIntoWindow()
|
|
{
|
|
var window = Week(1);
|
|
Assert.Equal(window.ResetsAt - TimeSpan.FromTicks(TimeSpan.FromDays(7).Ticks * 49 / 50), Pace.ForecastStartsAt(window));
|
|
Assert.Null(Pace.ForecastStartsAt(window with { Length = null }));
|
|
Assert.Null(Pace.ForecastStartsAt(window with { ResetsAt = null }));
|
|
Assert.Null(Pace.ForecastStartsAt(window with { Length = TimeSpan.Zero }));
|
|
var start = Pace.ForecastStartsAt(window)!.Value;
|
|
Assert.False(Pace.CanForecast(window, start.AddTicks(-1), 40));
|
|
Assert.True(Pace.CanForecast(window, start, 40));
|
|
}
|
|
}
|