Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/MandoCode.Tests/Acp/AcpClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,10 @@ public async Task HandlerErrors_ReachTheAgentAsJsonRpcErrors()

private static async Task WaitFor(Func<bool> 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 ─────────────
Expand Down
2 changes: 1 addition & 1 deletion tests/MandoCode.Tests/Acp/AcpHardeningTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private sealed class Releaser(Harness owner) : IDisposable
/// <summary>Answers the menu the way the VDOM component would, once it is shown.</summary>
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");
Expand Down
19 changes: 15 additions & 4 deletions tests/MandoCode.Tests/Acp/AcpTestKit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ public JsonRpcConnection CreateConnection(JsonRpcConnectionOptions? options = nu
/// <summary>Reads the next line the client wrote, parsed as JSON.</summary>
public async Task<JsonElement> 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!);
return doc.RootElement.Clone();
}

public async Task<string?> ReadRawLineAsync() =>
await _reader.ReadLineAsync().WaitAsync(TimeSpan.FromSeconds(5));
await _reader.ReadLineAsync().WaitAsync(AcpTestTimeouts.Guard);

public void SendLine(string json) => SendRaw(json + "\n");

Expand Down Expand Up @@ -123,11 +123,22 @@ public void Dispose()
}
}

/// <summary>
/// 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).
/// </summary>
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<T> Within<T>(this Task<T> task, int seconds = 5) =>
public static async Task<T> Within<T>(this Task<T> 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));
}
4 changes: 2 additions & 2 deletions tests/MandoCode.Tests/Acp/AcpToolsAndPermissionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
Loading