FinalToken v1: a NativeAOT tray app for Windows 11 and CachyOS that tracks Claude Code and Codex usage and limits through their CLIs only, with no provider sign-in and no tokens (R1-R7, D1-D11). - Core: incremental collectors for Claude transcripts and Codex rollouts, limit probes through `claude -p /usage` and `codex app-server`, a journaled history store, the refresh engine, pace and popup decisions, and the snapshot.json contract. - App (Avalonia): stats panel with limit bars, pace, projections, token totals, charts, limit history and breakdowns; tray, settings, non-activating pace popups, single-instance activation, start with the OS, and the Off/Ask/Automatic Stream Deck plugin install. - Stream Deck plugin (SDK v2, NativeAOT) for Elgato and OpenDeck. - finaltoken-cli, tools/publish.py, the documentation check and the agent review workflow. Closes #1
74 lines
4.3 KiB
C#
74 lines
4.3 KiB
C#
using Xunit;
|
|
|
|
namespace FinalToken.Core.Tests;
|
|
|
|
public class PaceTests
|
|
{
|
|
private static readonly DateTimeOffset Now = new(2026, 10, 14, 16, 0, 0, TimeSpan.Zero);
|
|
private static LimitWindow Window(double used, double elapsed = 0.5) => new(Provider.Claude, "session", "Session",
|
|
used, Now + TimeSpan.FromHours(5 * (1 - elapsed)), TimeSpan.FromHours(5), Now, "fixture");
|
|
|
|
[Theory]
|
|
[InlineData(0, 0, PaceState.OnTrack)]
|
|
[InlineData(0, 0.5, PaceState.Behind)]
|
|
[InlineData(60, 0.5, PaceState.Ahead)]
|
|
[InlineData(50, 0.5, PaceState.OnTrack)]
|
|
[InlineData(10, 0.4, PaceState.OnTrack)]
|
|
[InlineData(0, 1.2, PaceState.Behind)]
|
|
public void CalculatesStates(double used, double elapsed, PaceState expected) =>
|
|
Assert.Equal(expected, Pace.Calculate(Window(used, elapsed), Now).State);
|
|
[Fact] public void ClampsElapsedAfterReset() => Assert.Equal(1, Pace.Calculate(Window(50, 2), Now).ElapsedFraction);
|
|
[Fact] public void MissingLengthIsUnknown() => Assert.Equal(PaceState.Unknown, Pace.Calculate(Window(40) with { Length = null }, Now).State);
|
|
[Fact] public void MissingResetIsUnknown() => Assert.Equal(PaceState.Unknown, Pace.Calculate(Window(40) with { ResetsAt = null }, Now).State);
|
|
[Fact] public void AheadProjectionPrecedesReset()
|
|
{
|
|
var window = Window(80);
|
|
Assert.Equal(Now.AddMinutes(37.5), Pace.Calculate(window, Now).Projection);
|
|
Assert.True(Pace.Calculate(window, Now).Projection < window.ResetsAt);
|
|
}
|
|
[Fact] public void ProjectionAfterResetIsHidden() => Assert.Null(Pace.Calculate(Window(10), Now).Projection);
|
|
[Fact] public void ZeroElapsedDoesNotProject() => Assert.Null(Pace.Calculate(Window(50, 0), Now).Projection);
|
|
[Fact] public void ZeroUsageDoesNotProject() => Assert.Null(Pace.Calculate(Window(0), Now).Projection);
|
|
|
|
[Fact]
|
|
public void PopupHysteresisPreventsFlappingAndRearmsAfterClear()
|
|
{
|
|
var machine = new PopupDecider();
|
|
var settings = new Settings();
|
|
Assert.NotNull(machine.Observe(Window(60), Pace.Calculate(Window(60), Now), settings));
|
|
Assert.Null(machine.Observe(Window(59), Pace.Calculate(Window(59), Now), settings));
|
|
Assert.Null(machine.Observe(Window(60), Pace.Calculate(Window(60), Now), settings));
|
|
Assert.Null(machine.Observe(Window(57), Pace.Calculate(Window(57), Now), settings));
|
|
Assert.NotNull(machine.Observe(Window(60), Pace.Calculate(Window(60), Now), settings));
|
|
}
|
|
[Fact]
|
|
public void BehindHasHysteresisAndIndependentProviderState()
|
|
{
|
|
var machine = new PopupDecider();
|
|
var settings = new Settings();
|
|
Assert.NotNull(machine.Observe(Window(40), Pace.Calculate(Window(40), Now), settings));
|
|
Assert.Null(machine.Observe(Window(41), Pace.Calculate(Window(41), Now), settings));
|
|
Assert.NotNull(machine.Observe(Window(40) with { Provider = Provider.Codex }, Pace.Calculate(Window(40), Now), settings));
|
|
Assert.Null(machine.Observe(Window(43), Pace.Calculate(Window(43), Now), settings));
|
|
Assert.NotNull(machine.Observe(Window(40), Pace.Calculate(Window(40), Now), settings));
|
|
}
|
|
[Fact]
|
|
public void PopupHonorsProviderAndStateSettings()
|
|
{
|
|
var window = Window(60);
|
|
Assert.Null(new PopupDecider().Observe(window, Pace.Calculate(window, Now), new Settings { PopupAhead = false }));
|
|
Assert.Null(new PopupDecider().Observe(window, Pace.Calculate(window, Now), new Settings { Claude = new() { PopupsEnabled = false } }));
|
|
Assert.Null(new PopupDecider().Observe(window, Pace.Calculate(window, Now), new Settings { Claude = new() { Enabled = false } }));
|
|
Assert.Null(new PopupDecider().Observe(Window(40), Pace.Calculate(Window(40), Now), new Settings { PopupBehind = false }));
|
|
}
|
|
[Fact]
|
|
public void ProviderStateTogglesDoNotDisableOtherProviders()
|
|
{
|
|
var settings = new Settings { Claude = new() { PopupAhead = false, PopupBehind = false } };
|
|
var machine = new PopupDecider();
|
|
Assert.Null(machine.Observe(Window(60), Pace.Calculate(Window(60), Now), settings));
|
|
Assert.Null(machine.Observe(Window(40), Pace.Calculate(Window(40), Now), settings));
|
|
Assert.NotNull(machine.Observe(Window(60) with { Provider = Provider.Codex }, Pace.Calculate(Window(60), Now), settings));
|
|
}
|
|
}
|