fix(inbound,security): bound the sync prefix of inbound scripts by the method timeout; persist a role refresh done on a passive request (INB-1, SEC-1, WP7 task 7.6)

This commit is contained in:
Joseph Doherty
2026-12-03 09:49:51 -05:00
parent 76c50a29c2
commit f7d3c69071
6 changed files with 84 additions and 7 deletions
@@ -1106,6 +1106,40 @@ public class InboundScriptExecutorTests
Assert.Equal(0, _executor.AbandonedExecutionCount); // ...and DECREMENTED
}
/// <summary>
/// INB-1: a script that blocks BEFORE its first await (CPU loop, <c>.Result</c> on a helper) used to
/// run inline on the request thread, so the method timeout could not fire until it returned. The
/// request must come back with TIMEOUT at the deadline and the orphan must be counted.
/// </summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task ScriptBlockingBeforeFirstAwait_StillTimesOutAtTheDeadline()
{
var release = new ManualResetEventSlim();
_executor.RegisterHandler("spin", _ =>
{
release.Wait(TimeSpan.FromSeconds(30)); // synchronous block: no await has happened yet
return Task.FromResult<object?>(1);
});
var method = new ApiMethod("spin", "unused") { Id = 10, TimeoutSeconds = 1 };
var started = System.Diagnostics.Stopwatch.StartNew();
var execution = _executor.ExecuteAsync(
method, new Dictionary<string, object?>(), _route, TimeSpan.FromMilliseconds(200));
var finished = await Task.WhenAny(execution, Task.Delay(TimeSpan.FromSeconds(10)));
Assert.Same(execution, finished); // pre-fix: the call itself never returned until released
var result = await execution;
Assert.False(result.Success);
Assert.Equal("TIMEOUT", result.ErrorCode);
Assert.True(started.Elapsed < TimeSpan.FromSeconds(5), $"took {started.Elapsed}");
Assert.Equal(1, _executor.AbandonedExecutionCount);
release.Set(); // the orphan finishes; its continuation cleans up
await Task.Delay(300);
Assert.Equal(0, _executor.AbandonedExecutionCount);
}
// --- Flow Debugger step logs (design 2026-09-09 D4/D5/D7): the Log global ---
/// <summary>Verifies that a traced run emits one ScriptLog row on the trace sink.</summary>