Files
ClaudeDo/tests/ClaudeDo.Worker.Tests/Usage/TokenTracker/TokenTrackerArgsTests.cs
T
mika kuns 3003cfa561 feat(usage): open the TokenTracker dashboard from the usage monitor
The modal deliberately shows only a slice of the analytics; this hands off
to TokenTracker's own local dashboard for the rest. The worker starts
`tokentracker serve` on demand and returns the URL, the UI opens the browser.

Three things the spawn has to get right: port 7680 is not free on Windows
(Delivery Optimization holds [::]:7680) and serve does not fall back, so we
scan 7680-7689 with a dual-stack bind probe; --no-open because the CLI would
open the browser before the server answers; and the child is a cmd.exe shim,
so shutdown kills the process tree. --no-sync keeps our no-cloud-sync rule.
2026-08-24 16:51:00 +02:00

51 lines
1.5 KiB
C#

using ClaudeDo.Worker.Usage.TokenTracker;
namespace ClaudeDo.Worker.Tests.Usage.TokenTracker;
public sealed class TokenTrackerArgsTests
{
[Fact]
public void Export_UsesIsoDatesAndDisablesGitAttribution()
{
var args = TokenTrackerArgs.Export(new DateOnly(2026, 5, 26), new DateOnly(2026, 8, 24));
Assert.Equal(
new[] { "sessions", "--from", "2026-05-26", "--to", "2026-08-24", "--no-git", "--format", "json" },
args);
}
[Fact]
public void Export_IsCultureInvariant()
{
var previous = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
try
{
var args = TokenTrackerArgs.Export(new DateOnly(2026, 1, 2), new DateOnly(2026, 1, 3));
Assert.Equal("2026-01-02", args[2]);
Assert.Equal("2026-01-03", args[4]);
}
finally { Thread.CurrentThread.CurrentCulture = previous; }
}
[Fact]
public void Version_AsksTheCliForItsVersion()
{
Assert.Equal(new[] { "-v" }, TokenTrackerArgs.Version());
}
[Fact]
public void Install_InstallsTheCliPackageGlobally()
{
Assert.Equal(new[] { "i", "-g", "tokentracker-cli" }, TokenTrackerArgs.Install());
}
[Fact]
public void Serve_PinsThePortAndOptsOutOfBrowserAndCloudSync()
{
Assert.Equal(
new[] { "serve", "--port", "7681", "--no-open", "--no-sync" },
TokenTrackerArgs.Serve(7681));
}
}