fix: full verification against the brief — 137 confirmed findings fixed over six passes #4

Merged
Alby96 merged 169 commits from claude/keen-knuth-uhxv8w into main 2026-10-13 12:10:04 +02:00
Showing only changes of commit 59605168b2 - Show all commits
@@ -162,7 +162,7 @@ public sealed class ProjectFilesTests(TestContext context)
Assert.Null(SingleInstance.TryAcquire(data));
// The next launch waits (the mutex belongs to a thread, so it waits on its own) and gets its turn once the first exits.
var next = Task.Run(() =>
var next = OnOwnThread(() =>
{
using var instance = SingleInstance.WaitForTurn(data, TimeSpan.FromSeconds(20));
return instance is not null;
@@ -175,7 +175,7 @@ public sealed class ProjectFilesTests(TestContext context)
var holder = Assert.NotNull(SingleInstance.TryAcquire(data));
try
{
Assert.False(Task.Run(() => SingleInstance.WaitForTurn(data, TimeSpan.FromMilliseconds(200)) is { } got && Dispose(got)).Result);
Assert.False(OnOwnThread(() => SingleInstance.WaitForTurn(data, TimeSpan.FromMilliseconds(200)) is { } got && Dispose(got)).Result);
}
finally
{
@@ -187,6 +187,26 @@ public sealed class ProjectFilesTests(TestContext context)
instance.Dispose();
return true;
}
// A thread of its own, never this one: a mutex this thread owns would let it in at once, and a task waited on
// before it started may run inline on the waiting thread.
static Task<bool> OnOwnThread(Func<bool> launch)
{
var done = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
new Thread(() =>
{
try
{
done.SetResult(launch());
}
catch (Exception ex)
{
done.SetException(ex);
}
})
{ IsBackground = true }.Start();
return done.Task;
}
}
/// <summary>Dialogs that pick one folder and cancel everything else.</summary>