Files
FinalToken/tests/FinalToken.Core.Tests/ProcessTests.cs
T
Florian Schmidt 14223b05df 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
2026-10-14 19:09:54 +02:00

40 lines
1.7 KiB
C#

using FinalToken.Core.Processes;
using Xunit;
namespace FinalToken.Core.Tests;
public class ProcessTests
{
private static ProcessRequest LongProcess(string directory) => OperatingSystem.IsWindows()
? new(new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "ping.exe"), []), ["-n", "30", "127.0.0.1"], directory, TimeSpan.FromSeconds(60))
: new(new("sleep", []), ["30"], directory, TimeSpan.FromSeconds(60));
[Fact]
public async Task FakeClockTimeoutTerminatesChild()
{
using var directory = new TestDirectory();
var clock = new TestClock();
var task = new ProcessRunner(clock).RunAsync(LongProcess(directory.Path), TestContext.Current.CancellationToken);
clock.Advance(TimeSpan.FromSeconds(61));
Assert.True((await task).TimedOut);
}
[Fact]
public async Task CancellationTerminatesAndWaitsForChild()
{
using var directory = new TestDirectory();
using var cancelled = CancellationTokenSource.CreateLinkedTokenSource(TestContext.Current.CancellationToken);
var task = new ProcessRunner().RunAsync(LongProcess(directory.Path), cancelled.Token);
await cancelled.CancelAsync();
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => task);
}
[Fact]
public async Task CaptureIsBoundedWithoutBlockingTheChild()
{
using var directory = new TestDirectory();
var result = await new ProcessRunner().RunAsync(new(new("dotnet", []), ["--info"], directory.Path,
TimeSpan.FromSeconds(10), OutputLimit: 50), TestContext.Current.CancellationToken);
Assert.Equal(0, result.ExitCode);
Assert.Equal(50, result.Output.Length);
Assert.True(result.OutputTruncated);
}
}