fix(inbound-api): ScriptLog durable write before the Live sink; prove the central write (Task 8 review)
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user