agent-review agent review: fail
The budget was the rest of the week over the time left, so each use today lowered it and a partial first day was held to a full day. Now each day of the instance has its share, its even pace and its budget. Today's budget starts from the use at the day start and does not move with today's use (D7). Forecasts start at 2 % of a window, so an early reset no longer hides them for most of a day. Limit tiles of one kind show the same rows, with placeholders that say why a value is missing. The week chart draws per-day steps and marks the instance start and reset (D8). Week token totals follow the provider's limit week and say since when, with the calendar week as fallback (D9). Refs #13
141 lines
7.3 KiB
C#
141 lines
7.3 KiB
C#
using FinalToken.Cli;
|
|
using FinalToken.Core;
|
|
using Xunit;
|
|
|
|
namespace FinalToken.Cli.Tests;
|
|
|
|
public class CliTests
|
|
{
|
|
[Fact]
|
|
public async Task UnexpectedRefreshFailureReturnsOneWithoutExceptionText()
|
|
{
|
|
var directory = Path.Combine(Path.GetTempPath(), "finaltoken-cli-" + Guid.NewGuid().ToString("N"));
|
|
try
|
|
{
|
|
using var output = new StringWriter(); using var error = new StringWriter();
|
|
Assert.Equal(1, await CliApplication.RunAsync(["status"], output, error, directory,
|
|
_ => throw new System.Text.Json.JsonException("synthetic private input"), TestContext.Current.CancellationToken));
|
|
Assert.Contains("could not complete", error.ToString()); Assert.DoesNotContain("synthetic private", error.ToString());
|
|
}
|
|
finally { if (Directory.Exists(directory)) Directory.Delete(directory, true); }
|
|
}
|
|
[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.Contains("Calendar week: since ", output.ToString());
|
|
Assert.NotNull(SnapshotFile.Read(directory).Snapshot);
|
|
}
|
|
finally { Directory.Delete(directory, true); }
|
|
}
|
|
[Fact]
|
|
public async Task TextNamesLimitWeekAndItsStart()
|
|
{
|
|
var directory = Path.Combine(Path.GetTempPath(), "finaltoken-cli-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(directory);
|
|
try
|
|
{
|
|
using var storeLock = StoreLock.TryAcquire(directory);
|
|
var start = new DateTimeOffset(2026, 10, 10, 22, 40, 0, TimeSpan.Zero);
|
|
await SnapshotFile.WriteAsync(directory, new Snapshot { MadeAt = DateTimeOffset.UtcNow, RefreshInterval = TimeSpan.FromMinutes(1),
|
|
Providers = [new(Provider.Codex, ProviderStatus.Available, null, [], new(), null, new(Total: 30), start, "week")] }, TestContext.Current.CancellationToken);
|
|
using var output = new StringWriter(); using var error = new StringWriter();
|
|
Assert.Equal(0, await CliApplication.RunAsync(["status"], output, error, directory, cancellationToken: TestContext.Current.CancellationToken));
|
|
Assert.Contains($"Limit week: since {start:O} (week)", output.ToString());
|
|
}
|
|
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); }
|
|
}
|
|
}
|