feat(usage): pin the TokenTracker CLI invocations
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace ClaudeDo.Worker.Usage.TokenTracker;
|
||||
|
||||
/// <summary>
|
||||
/// The exact CLI invocations we rely on. <c>--no-git</c> matters: without it TokenTracker runs
|
||||
/// <c>git log</c> inside every session's working directory, which is both slower and touches
|
||||
/// repositories we have no business touching. We never invoke <c>init</c> — that would write
|
||||
/// hooks into the user's global <c>~/.claude/settings.json</c> and switch on cloud sync.
|
||||
/// The date range is passed for correctness, not economy: v0.88.4 accepts it but returns the
|
||||
/// full history regardless, so <see cref="TokenTrackerAggregator"/> does the real filtering.
|
||||
/// </summary>
|
||||
public static class TokenTrackerArgs
|
||||
{
|
||||
public const string Command = "tokentracker";
|
||||
public const string NpmCommand = "npm";
|
||||
public const string PackageName = "tokentracker-cli";
|
||||
|
||||
public static string[] Export(DateOnly from, DateOnly to) =>
|
||||
[
|
||||
"sessions",
|
||||
"--from", from.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
|
||||
"--to", to.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
|
||||
"--no-git",
|
||||
"--format", "json",
|
||||
];
|
||||
|
||||
public static string[] Version() => ["-v"];
|
||||
|
||||
public static string[] Install() => ["i", "-g", PackageName];
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user