From 18a83f1a402324e63f30555451a0218120107b26 Mon Sep 17 00:00:00 2001 From: Armando Fernandez Date: Mon, 16 Nov 2026 22:07:26 -0800 Subject: [PATCH] test(acp): raise in-memory test hang-guard from 5s to 30s The ACP tests used a hard-coded 5s guard for every FakeAgentPeer read, Within() call and polling loop. On the loaded windows-latest/net8.0 runner the first handshake read exceeded it, failing main after #143 (FileSystemRequests_WithoutTheCapability_GetMethodNotFound and AgentDyingMidTurn_FailsTheTurn_AndEndsTheUpdateStream), while the same code had passed on the PR branch minutes earlier. Centralize the value in AcpTestTimeouts.Guard (30s). It only bounds a hung test, so passing tests never wait on it. Co-Authored-By: Claude Sonnet 5.5 --- tests/MandoCode.Tests/Acp/AcpClientTests.cs | 4 ++-- .../MandoCode.Tests/Acp/AcpHardeningTests.cs | 2 +- tests/MandoCode.Tests/Acp/AcpTestKit.cs | 19 +++++++++++++++---- .../Acp/AcpToolsAndPermissionsTests.cs | 4 ++-- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/MandoCode.Tests/Acp/AcpClientTests.cs b/tests/MandoCode.Tests/Acp/AcpClientTests.cs index 517679f..5e37b78 100644 --- a/tests/MandoCode.Tests/Acp/AcpClientTests.cs +++ b/tests/MandoCode.Tests/Acp/AcpClientTests.cs @@ -576,10 +576,10 @@ public async Task HandlerErrors_ReachTheAgentAsJsonRpcErrors() private static async Task WaitFor(Func condition) { - var deadline = DateTime.UtcNow.AddSeconds(5); + var deadline = DateTime.UtcNow.Add(AcpTestTimeouts.Guard); while (!condition() && DateTime.UtcNow < deadline) await Task.Delay(10); - Assert.True(condition(), "condition not met within 5s"); + Assert.True(condition(), $"condition not met within {AcpTestTimeouts.GuardSeconds}s"); } // ───────────── modes ───────────── diff --git a/tests/MandoCode.Tests/Acp/AcpHardeningTests.cs b/tests/MandoCode.Tests/Acp/AcpHardeningTests.cs index 220adbe..a7203c1 100644 --- a/tests/MandoCode.Tests/Acp/AcpHardeningTests.cs +++ b/tests/MandoCode.Tests/Acp/AcpHardeningTests.cs @@ -134,7 +134,7 @@ private sealed class Releaser(Harness owner) : IDisposable /// Answers the menu the way the VDOM component would, once it is shown. public async Task Answer(string choice) { - var deadline = DateTime.UtcNow.AddSeconds(5); + var deadline = DateTime.UtcNow.Add(AcpTestTimeouts.Guard); while (!Menu.IsActive && DateTime.UtcNow < deadline) await Task.Delay(5); Assert.True(Menu.IsActive, "the menu was never shown"); diff --git a/tests/MandoCode.Tests/Acp/AcpTestKit.cs b/tests/MandoCode.Tests/Acp/AcpTestKit.cs index 58273fe..c3a1ef2 100644 --- a/tests/MandoCode.Tests/Acp/AcpTestKit.cs +++ b/tests/MandoCode.Tests/Acp/AcpTestKit.cs @@ -78,7 +78,7 @@ public JsonRpcConnection CreateConnection(JsonRpcConnectionOptions? options = nu /// Reads the next line the client wrote, parsed as JSON. public async Task ReadMessageAsync() { - var line = await _reader.ReadLineAsync().WaitAsync(TimeSpan.FromSeconds(5)); + var line = await _reader.ReadLineAsync().WaitAsync(AcpTestTimeouts.Guard); Assert.NotNull(line); Assert.DoesNotContain('\n', line); using var doc = JsonDocument.Parse(line!); @@ -86,7 +86,7 @@ public async Task ReadMessageAsync() } public async Task ReadRawLineAsync() => - await _reader.ReadLineAsync().WaitAsync(TimeSpan.FromSeconds(5)); + await _reader.ReadLineAsync().WaitAsync(AcpTestTimeouts.Guard); public void SendLine(string json) => SendRaw(json + "\n"); @@ -123,11 +123,22 @@ public void Dispose() } } +/// +/// Hang-guard for the in-memory ACP tests. It only bounds a test that would otherwise never finish, so passing +/// tests never wait on it. It is deliberately generous: the full suite runs ~1,900 tests in parallel and a cold +/// Windows runner can take well over 5s to schedule the first handshake read (CI flake, 2026-11-13). +/// +internal static class AcpTestTimeouts +{ + public const int GuardSeconds = 30; + public static readonly TimeSpan Guard = TimeSpan.FromSeconds(GuardSeconds); +} + internal static class TaskExtensions { - public static async Task Within(this Task task, int seconds = 5) => + public static async Task Within(this Task task, int seconds = AcpTestTimeouts.GuardSeconds) => await task.WaitAsync(TimeSpan.FromSeconds(seconds)); - public static async Task Within(this Task task, int seconds = 5) => + public static async Task Within(this Task task, int seconds = AcpTestTimeouts.GuardSeconds) => await task.WaitAsync(TimeSpan.FromSeconds(seconds)); } diff --git a/tests/MandoCode.Tests/Acp/AcpToolsAndPermissionsTests.cs b/tests/MandoCode.Tests/Acp/AcpToolsAndPermissionsTests.cs index 2c3e3ee..9b904f0 100644 --- a/tests/MandoCode.Tests/Acp/AcpToolsAndPermissionsTests.cs +++ b/tests/MandoCode.Tests/Acp/AcpToolsAndPermissionsTests.cs @@ -418,7 +418,7 @@ public async Task CancellingTheTurn_ClosesTheMenu_AndAnswersCancelled() async Task AnswerShown() { - var deadline = DateTime.UtcNow.AddSeconds(5); + var deadline = DateTime.UtcNow.Add(AcpTestTimeouts.Guard); while (!_menu.IsActive && DateTime.UtcNow < deadline) await Task.Delay(5); Assert.True(_menu.IsActive); @@ -469,7 +469,7 @@ public async Task TheDiffOfTheProposedChange_IsThePreviewOfTheMenu() }; var answer = prompter.RequestAsync(request, CancellationToken.None).AsTask(); - var deadline = DateTime.UtcNow.AddSeconds(5); + var deadline = DateTime.UtcNow.Add(AcpTestTimeouts.Guard); while (!_menu.IsActive && DateTime.UtcNow < deadline) await Task.Delay(5);