build: one version for the app and the plugin

D11 replaces an installed plugin only when the shipped manifest is
newer, but the manifest version was kept by hand and still said
1.0.0.1, the version of a test build installed before the snapshot
sharing and appPath fixes, so that stale plugin was never replaced.
Directory.Build.props now holds the only version, 1.0.1; publish.py
stamps it into the shipped manifest and the app shows it in its title.

Tests that waited on real time (file retry, popup expiry) use
controlled timers, and real process waits have wider margins.

Refs #1
This commit is contained in:
Florian Schmidt
2026-10-14 21:08:22 +02:00
parent 5c5973aa6c
commit 15c7e684bb
15 changed files with 126 additions and 18 deletions
+1
View File
@@ -4,3 +4,4 @@ Run `dotnet test --project tests/FinalToken.App.Tests -c Release` from the root.
View-model tests use public Core queries. Headless tests run on a dedicated UI thread with
Skia and HarfBuzz, exercise settings and popup actions, and save seven PNG screenshots outside
the repo at ../runs/shots/w2. FINALTOKEN_SCREENSHOT_DIR overrides that path.
Popup expiry uses an injected TimeProvider; fire timers and pump the dispatcher instead of sleeping.
+24 -2
View File
@@ -31,6 +31,7 @@ public sealed class HeadlessTests
var model = FakeData.Model();
var panel = new PanelWindow(model, () => { }, () => { }, () => { }, () => { }) { Height = 2450 };
panel.RequestedThemeVariant = ThemeVariant.Light; panel.Show(); Save(panel, "panel-light.png");
Assert.Equal($"FinalToken {typeof(Program).Assembly.GetName().Version!.ToString(3)}", panel.Title);
Assert.Contains(panel.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == "Claude");
Assert.Contains(panel.GetVisualDescendants().OfType<TextBlock>(), t => t.Text == "Tokens per day");
var filters = panel.GetVisualDescendants().OfType<ComboBox>().ToArray();
@@ -74,7 +75,8 @@ public sealed class HeadlessTests
var install = new PopupWindow("Stream Deck plugin", "Update ready", () => { }, "Update", () => installed++);
install.Show(); install.GetVisualDescendants().OfType<Button>().Single(b => b.Content as string == "Update").RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
Assert.Equal(1, installed);
using var stack = new PopupStack(() => { });
var popupClock = new PopupClock();
using var stack = new PopupStack(() => { }, popupClock);
var first = PopupWindow.Pace(new(Provider.Claude, "a", "Session", PaceState.Ahead, 20, null), () => { });
var second = PopupWindow.Pace(new(Provider.Codex, "b", "Week", PaceState.Behind, -20, null), () => { });
stack.Show(first); stack.Show(second); Assert.True(second.Position.Y < first.Position.Y);
@@ -94,8 +96,9 @@ public sealed class HeadlessTests
{ Values = [new(time, "Claude", 1), new(time.AddHours(1), "Claude", 2), new(time.AddHours(2), "Claude", 3)] })),
Width = 620, Height = 260, RequestedThemeVariant = ThemeVariant.Light };
smallChart.Show(); Save(smallChart, "chart-max-3.png", polishShots); smallChart.Close();
Thread.Sleep(8200); Dispatcher.UIThread.RunJobs();
popupClock.Fire(); Dispatcher.UIThread.RunJobs();
Assert.False(first.IsVisible); Assert.False(second.IsVisible);
Assert.All(popupClock.Timers, timer => Assert.True(timer.Disposed));
completion.SetResult();
void Save(Window window, string name, string? destination = null)
{
@@ -112,4 +115,23 @@ public sealed class HeadlessTests
}
public sealed class TestApplication : Application
{ public override void Initialize() => Styles.Add(new FluentTheme()); }
private sealed class PopupClock : TimeProvider
{
public List<PopupTimer> Timers { get; } = [];
public override ITimer CreateTimer(TimerCallback callback, object? state, TimeSpan dueTime, TimeSpan period)
{
Assert.Equal(TimeSpan.FromSeconds(8), dueTime);
Assert.Equal(Timeout.InfiniteTimeSpan, period);
var timer = new PopupTimer(callback, state); Timers.Add(timer); return timer;
}
public void Fire() { foreach (var timer in Timers.Where(t => !t.Disposed)) timer.Fire(); }
}
private sealed class PopupTimer(TimerCallback callback, object? state) : ITimer
{
public bool Disposed { get; private set; }
public void Fire() => callback(state);
public bool Change(TimeSpan dueTime, TimeSpan period) => throw new NotSupportedException();
public void Dispose() => Disposed = true;
public ValueTask DisposeAsync() { Dispose(); return ValueTask.CompletedTask; }
}
}
@@ -28,7 +28,7 @@ public class IntegrationTests
process.Start();
try
{
await process.WaitForExitAsync(TestContext.Current.CancellationToken);
await process.WaitForExitAsync(TestContext.Current.CancellationToken).WaitAsync(TimeSpan.FromSeconds(90), TestContext.Current.CancellationToken);
using var report = JsonDocument.Parse(File.ReadAllText(reportPath));
Assert.False(report.RootElement.GetProperty("HostHasConsole").GetBoolean());
Assert.False(report.RootElement.GetProperty("HostInputValid").GetBoolean());
+1 -1
View File
@@ -31,7 +31,7 @@ public class ProcessTests
{
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);
TimeSpan.FromSeconds(60), OutputLimit: 50), TestContext.Current.CancellationToken);
Assert.Equal(0, result.ExitCode);
Assert.Equal(50, result.Output.Length);
Assert.True(result.OutputTruncated);
+14 -6
View File
@@ -1,4 +1,3 @@
using System.Diagnostics;
using FinalToken.Core.Collectors;
using Xunit;
@@ -59,9 +58,15 @@ public class ReworkTests
using var directory = new TestDirectory();
var path = directory.Write("blocked.json", "old");
using var reader = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var watch = Stopwatch.StartNew();
await Assert.ThrowsAsync<IOException>(() => AtomicFile.WriteAsync(path, "new", TestContext.Current.CancellationToken));
Assert.InRange(watch.Elapsed.TotalMilliseconds, 400, 3000);
var clock = new TestClock();
var write = AtomicFile.WriteAsync(path, "new", TestContext.Current.CancellationToken, clock);
for (var attempt = 0; attempt < 10; attempt++)
{
Assert.Equal(TimeSpan.FromMilliseconds(50), await clock.NextTimerAsync(TestContext.Current.CancellationToken));
Assert.False(write.IsCompleted);
clock.Advance(TimeSpan.FromMilliseconds(50));
}
await Assert.ThrowsAsync<IOException>(() => write);
Assert.Equal("old", File.ReadAllText(path));
Assert.Empty(Directory.GetFiles(directory.Path, "*.tmp"));
}
@@ -196,9 +201,12 @@ public class ReworkTests
using var directory = new TestDirectory();
var path = directory.Write("briefly-blocked.json", "old");
using var reader = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var write = AtomicFile.WriteAsync(path, "new", TestContext.Current.CancellationToken);
await Task.Delay(TimeSpan.FromMilliseconds(120), TestContext.Current.CancellationToken);
var clock = new TestClock();
var write = AtomicFile.WriteAsync(path, "new", TestContext.Current.CancellationToken, clock);
Assert.Equal(TimeSpan.FromMilliseconds(50), await clock.NextTimerAsync(TestContext.Current.CancellationToken));
Assert.False(write.IsCompleted);
reader.Dispose();
clock.Advance(TimeSpan.FromMilliseconds(50));
await write;
Assert.Equal("new", File.ReadAllText(path));
}
@@ -11,6 +11,24 @@ public sealed class InstallerTests : IDisposable
private string Installed => Path.Combine(Plugins, PluginInstaller.FolderName);
public InstallerTests() => Write(Shipped, "1.0.0.0", "new");
[Fact]
public async Task ReleasePluginReportsOldDevelopmentCopyAsOutdated()
{
var shipped = Environment.GetEnvironmentVariable("FINALTOKEN_TEST_SHIPPED_PLUGIN");
if (shipped is null)
{
Write(Shipped, typeof(PluginInstaller).Assembly.GetName().Version!.ToString(), "new");
shipped = Shipped;
}
Write(Installed, "1.0.0.1", "old development copy");
var process = new FakeProcesses();
var installer = new PluginInstaller(shipped, new(Plugins, "fake", "fake"), process);
var status = await installer.GetStatusAsync(TestContext.Current.CancellationToken);
Assert.Equal(PluginInstallState.Outdated, status.State);
Assert.Equal(typeof(PluginInstaller).Assembly.GetName().Version!.ToString(), status.ShippedVersion);
Assert.Equal("1.0.0.1", status.InstalledVersion);
Assert.Equal(0, process.Stops); Assert.Equal(0, process.Starts);
}
[Fact]
public async Task FreshInstallDoesNotStartStoppedHost()
{
var process = new FakeProcesses();
@@ -1,4 +1,5 @@
using FinalToken.Core.Processes;
using System.Threading.Channels;
namespace FinalToken.Core.Tests;
@@ -18,6 +19,8 @@ public sealed class TestDirectory : IDisposable
public sealed class TestClock : TimeProvider
{
private readonly Channel<TimeSpan> scheduled = Channel.CreateUnbounded<TimeSpan>();
public ValueTask<TimeSpan> NextTimerAsync(CancellationToken cancellationToken) => scheduled.Reader.ReadAsync(cancellationToken);
private readonly Lock gate = new();
private DateTimeOffset now = new(2026, 10, 14, 16, 0, 0, TimeSpan.Zero);
private readonly List<TestTimer> timers = [];
@@ -40,6 +43,7 @@ public sealed class TestClock : TimeProvider
var timer = new TestTimer(this, callback, state, period);
timer.Change(dueTime, period);
timers.Add(timer);
scheduled.Writer.TryWrite(dueTime);
return timer;
}
}