- A GUI-subsystem host has no console code page, so .NET decoded the probes' UTF-8 output with code page 0 and Claude's /usage separators never matched: Claude showed as unavailable in the app but not in the CLI. Probe output is now decoded as UTF-8 and every probe gets valid standard handles, with stdin closed unless it is the Codex RPC. A GUI-subsystem test host reproduces it. - The /usage parser stops at the contributing section and only reports lines that start like a limit line. - snapshot.json no longer defaults appPath to the reader's own path. The app passes its path to the engine and a CLI refresh keeps it, so a Stream Deck key always starts the app (D9, D10). - The CLI is finaltoken-cli on every platform: FinalToken.exe and finaltoken.exe cannot share a folder on Windows. - Day series follow the local calendar day, as Today does. - The dev-only migration from the first store format is gone. - README.md is a short user guide. Refs #1
110 lines
5.4 KiB
C#
110 lines
5.4 KiB
C#
using FinalToken.Cli;
|
|
using FinalToken.Core;
|
|
using Xunit;
|
|
|
|
namespace FinalToken.Cli.Tests;
|
|
|
|
public class CliTests
|
|
{
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("unknown")]
|
|
[InlineData("status --unknown")]
|
|
[InlineData("status --json --json")]
|
|
public async Task InvalidUsageExitsTwo(string command)
|
|
{
|
|
using var output = new StringWriter();
|
|
using var error = new StringWriter();
|
|
Assert.Equal(2, await CliApplication.RunAsync(command.Split(' ', StringSplitOptions.RemoveEmptyEntries), output, error, cancellationToken: TestContext.Current.CancellationToken));
|
|
Assert.Contains("Usage: finaltoken-cli status", error.ToString());
|
|
}
|
|
[Fact]
|
|
public async Task BusyStoreReadsExistingSnapshotAndDoesNotRefresh()
|
|
{
|
|
var directory = Path.Combine(Path.GetTempPath(), "finaltoken-cli-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(directory);
|
|
try
|
|
{
|
|
using var storeLock = StoreLock.TryAcquire(directory);
|
|
await SnapshotFile.WriteAsync(directory, new Snapshot { MadeAt = DateTimeOffset.UtcNow, RefreshInterval = TimeSpan.FromSeconds(60), Providers = [] }, TestContext.Current.CancellationToken);
|
|
using var output = new StringWriter();
|
|
using var error = new StringWriter();
|
|
Assert.Equal(0, await CliApplication.RunAsync(["status", "--json"], output, error, directory,
|
|
_ => throw new InvalidOperationException("Must not create a writing engine."), TestContext.Current.CancellationToken));
|
|
Assert.Contains("\"v\":1", output.ToString());
|
|
Assert.Contains("Store is in use", error.ToString());
|
|
}
|
|
finally { Directory.Delete(directory, true); }
|
|
}
|
|
[Fact]
|
|
public async Task StatusNoProbeWritesSnapshotAndText()
|
|
{
|
|
var directory = Path.Combine(Path.GetTempPath(), "finaltoken-cli-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(directory);
|
|
try
|
|
{
|
|
using var output = new StringWriter();
|
|
using var error = new StringWriter();
|
|
Assert.Equal(0, await CliApplication.RunAsync(["status", "--no-probe"], output, error, directory,
|
|
path => new(path, claudeDirectory: path, codexDirectory: path, cliDiscovery: (_, _) => new(null, "Fixture CLI missing.")), TestContext.Current.CancellationToken));
|
|
Assert.Contains("Tokens today: 0", output.ToString());
|
|
Assert.NotNull(SnapshotFile.Read(directory).Snapshot);
|
|
}
|
|
finally { Directory.Delete(directory, true); }
|
|
}
|
|
[Fact]
|
|
public async Task BusyStoreWithoutSnapshotExitsOne()
|
|
{
|
|
var directory = Path.Combine(Path.GetTempPath(), "finaltoken-cli-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(directory);
|
|
try
|
|
{
|
|
using var storeLock = StoreLock.TryAcquire(directory);
|
|
using var output = new StringWriter();
|
|
using var error = new StringWriter();
|
|
Assert.Equal(1, await CliApplication.RunAsync(["status"], output, error, directory, cancellationToken: TestContext.Current.CancellationToken));
|
|
}
|
|
finally { Directory.Delete(directory, true); }
|
|
}
|
|
[Fact]
|
|
public async Task PrintsFoldedDiagnosticCountAndLastTime()
|
|
{
|
|
var directory = Path.Combine(Path.GetTempPath(), "finaltoken-cli-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(directory);
|
|
try
|
|
{
|
|
using var output = new StringWriter();
|
|
using var error = new StringWriter();
|
|
var result = await CliApplication.RunAsync(["status", "--no-probe"], output, error, directory, path =>
|
|
{
|
|
var engine = new RefreshEngine(path, claudeDirectory: path, codexDirectory: path,
|
|
cliDiscovery: (_, _) => new(null, "Fixture CLI missing."));
|
|
for (var i = 0; i < 20; i++) engine.Diagnostics.Add(Provider.Claude, "fixture-parse", "Malformed usage.");
|
|
return engine;
|
|
}, TestContext.Current.CancellationToken);
|
|
Assert.Equal(0, result);
|
|
Assert.Contains("fixture-parse (x20, last ", error.ToString());
|
|
Assert.Equal(1, error.ToString().Split('\n').Count(line => line.StartsWith("fixture-parse", StringComparison.Ordinal)));
|
|
}
|
|
finally { Directory.Delete(directory, true); }
|
|
}
|
|
[Fact]
|
|
public async Task StatusKeepsExistingDesktopPath()
|
|
{
|
|
var directory = Path.Combine(Path.GetTempPath(), "finaltoken-cli-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(directory);
|
|
try
|
|
{
|
|
await SnapshotFile.WriteAsync(directory, new Snapshot { MadeAt = DateTimeOffset.UtcNow,
|
|
RefreshInterval = TimeSpan.FromMinutes(1), Providers = [], AppPath = "desktop.exe" }, TestContext.Current.CancellationToken);
|
|
using var output = new StringWriter();
|
|
using var error = new StringWriter();
|
|
Assert.Equal(0, await CliApplication.RunAsync(["status", "--no-probe"], output, error, directory,
|
|
path => new(path, claudeDirectory: path, codexDirectory: path, cliDiscovery: (_, _) => new(null, "Fixture CLI missing.")),
|
|
TestContext.Current.CancellationToken));
|
|
Assert.Equal("desktop.exe", SnapshotFile.Read(directory).Snapshot!.AppPath);
|
|
}
|
|
finally { Directory.Delete(directory, true); }
|
|
}
|
|
}
|