core: add the solution, Core engine, CLI and tests
Core implements the CLI-only collectors for Claude and Codex (D2 to D4), the history store (D5), the refresh engine (D6), pace and popup decisions (D7, D8), the snapshot contract (D9) and the Stream Deck installer contract (D11). finaltoken status runs one refresh and prints the snapshot. The app and plugin projects are placeholders so the solution file is complete before they are built in parallel. Refs #1
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# Cli tests
|
||||
Hand-written fixtures only. xUnit v3 AOT with Microsoft.Testing.Platform.
|
||||
Run `dotnet test --project tests/FinalToken.Cli.Tests -c Release` from the root.
|
||||
Cover behavior and failure boundaries, not implementation details.
|
||||
@@ -0,0 +1 @@
|
||||
@AGENTS.md
|
||||
@@ -0,0 +1,69 @@
|
||||
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:", 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); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
|
||||
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="xunit.v3.aot.mtp-v2" />
|
||||
<ProjectReference Include="../../src/FinalToken.Cli/FinalToken.Cli.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user