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
72 lines
3.2 KiB
C#
72 lines
3.2 KiB
C#
using System.Globalization;
|
|
using Xunit;
|
|
|
|
namespace FinalToken.App.Tests;
|
|
|
|
public sealed class FormattingTests
|
|
{
|
|
[Fact]
|
|
public void DailyChartLabelAndTooltipUseTheBucketsLocalDate()
|
|
{
|
|
var zone = TimeZoneInfo.CreateCustomTimeZone("Fixture+02", TimeSpan.FromHours(2), "Fixture", "Fixture");
|
|
var day = FinalToken.Core.CalendarDays.Start(new DateTimeOffset(2026, 10, 14, 12, 0, 0, TimeSpan.Zero), zone);
|
|
Assert.Equal("10-14", Display.ChartDateLabel(day, TimeSpan.FromDays(1)));
|
|
Assert.Equal(day.DateTime.ToString("g"), Display.ChartTimestamp(day, TimeSpan.FromDays(1)));
|
|
}
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData("custom-config")]
|
|
public void LinuxAutostartHonorsConfigHome(string? configHome)
|
|
{
|
|
var home = Path.Combine(Path.GetTempPath(), "fixture-home");
|
|
var config = string.IsNullOrEmpty(configHome) ? null : Path.Combine(Path.GetTempPath(), configHome);
|
|
Assert.Equal(Path.Combine(config ?? Path.Combine(home, ".config"), "autostart", "finaltoken.desktop"), OsStartup.LinuxAutostartPath(config, home));
|
|
}
|
|
[Theory]
|
|
[InlineData("de-DE")]
|
|
[InlineData("en-US")]
|
|
public void FutureProjectionIncludesLocalDateInUsersCulture(string culture)
|
|
{
|
|
var clock = new FixedClock();
|
|
var projection = new DateTimeOffset(2026, 10, 16, 6, 24, 0, TimeSpan.Zero);
|
|
var userCulture = CultureInfo.GetCultureInfo(culture);
|
|
Assert.Equal(new DateTime(2026, 10, 16, 8, 24, 0).ToString("g", userCulture), Display.Projection(projection, clock, userCulture));
|
|
}
|
|
[Fact]
|
|
public void TodaysProjectionUsesLocalTimeOnly()
|
|
{
|
|
Assert.Equal("23:24", Display.Projection(new(2026, 10, 14, 21, 24, 0, TimeSpan.Zero), new FixedClock(), CultureInfo.GetCultureInfo("de-DE")));
|
|
}
|
|
[Fact]
|
|
public void ProjectionDateChangesAtLocalMidnight()
|
|
{
|
|
Assert.Equal("15.10.2026 00:24", Display.Projection(new(2026, 10, 14, 22, 24, 0, TimeSpan.Zero), new FixedClock(), CultureInfo.GetCultureInfo("de-DE")));
|
|
}
|
|
[Theory]
|
|
[InlineData(0, new double[] { 0 })]
|
|
[InlineData(1, new double[] { 0, 1 })]
|
|
[InlineData(2, new double[] { 0, 1, 2 })]
|
|
[InlineData(3, new double[] { 0, 1, 2, 3 })]
|
|
public void SmallChartTicksAreDistinctIntegers(double maximum, double[] expected)
|
|
=> Assert.Equal(expected, UsageChart.AxisTicks(maximum));
|
|
[Theory]
|
|
[InlineData(5, new double[] { 0, 2, 4, 6 })]
|
|
[InlineData(17, new double[] { 0, 5, 10, 15, 20 })]
|
|
[InlineData(123456, new double[] { 0, 50000, 100000, 150000 })]
|
|
public void LargerChartTicksUseRoundedStepsAndCoverMaximum(double maximum, double[] expected)
|
|
=> Assert.Equal(expected, UsageChart.AxisTicks(maximum));
|
|
[Fact]
|
|
public void PercentTicksKeepQuarterMarksAndEmptyPercentChartHasOnlyZero()
|
|
{
|
|
Assert.Equal([0d, 25, 50, 75, 100], UsageChart.AxisTicks(3, true));
|
|
Assert.Equal([0d], UsageChart.AxisTicks(0, true));
|
|
}
|
|
|
|
private sealed class FixedClock : TimeProvider
|
|
{
|
|
public override DateTimeOffset GetUtcNow() => new(2026, 10, 14, 18, 0, 0, TimeSpan.Zero);
|
|
public override TimeZoneInfo LocalTimeZone { get; } = TimeZoneInfo.CreateCustomTimeZone("Fixture+02", TimeSpan.FromHours(2), "Fixture", "Fixture");
|
|
}
|
|
}
|