fix(inbound-api): ScriptLog durable write before the Live sink; prove the central write (Task 8 review)

This commit is contained in:
Joseph Doherty
2026-09-09 11:47:23 -04:00
parent 2eaaed559f
commit 7245c63c62
2 changed files with 61 additions and 14 deletions
@@ -937,6 +937,37 @@ public class InboundScriptExecutorTests
Assert.Null(extra.StepEventId);
}
[Fact]
public async Task Log_TracedRun_WritesTheScriptLogRowToTheCentralAuditStore()
{
// D5: the row must be DURABLE, not just inline — Replay reads it back from the central
// audit store, so the write happens even when no Live trace sink is attached, and it
// carries the emitting node exactly as the RouteCall row does.
var writer = Substitute.For<ICentralAuditWriter>();
writer.WriteAsync(Arg.Any<AuditEvent>(), Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
var nodeIdentity = Substitute.For<INodeIdentityProvider>();
nodeIdentity.NodeName.Returns("central-a");
var services = new ServiceCollection();
services.AddSingleton(writer);
services.AddSingleton(nodeIdentity);
using var provider = services.BuildServiceProvider();
var executor = new InboundScriptExecutor(NullLogger<InboundScriptExecutor>.Instance, provider);
var method = new ApiMethod("persisted", "Log.Info(\"persist\"); return 1;") { Id = 7, TimeoutSeconds = 10 };
var result = await executor.ExecuteAsync(
method, new Dictionary<string, object?>(), NewRoute(), TimeSpan.FromSeconds(10),
parentExecutionId: Guid.NewGuid(), trace: true);
Assert.True(result.Success, result.ErrorMessage);
await writer.Received(1).WriteAsync(
Arg.Is<AuditEvent>(e =>
AuditDetailsCodec.Deserialize(e.DetailsJson).Kind == nameof(AuditKind.ScriptLog)
&& e.SourceNode == "central-a"),
Arg.Any<CancellationToken>());
}
[Fact]
public async Task Log_UntracedRun_WritesOnlyToTheNodeLogger()
{