feat(diagnostics): VM emits trace events + CallScriptDispatches stat

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-07 15:21:28 -04:00
parent 10cf79a41b
commit e010393b8a
6 changed files with 99 additions and 16 deletions

View File

@@ -58,12 +58,13 @@ public class CallScriptTests
OP_MOV, 3, 0x11, 3, 0x10,
OP_EXIT);
var host = new NullHost();
var vm = new VirtualMachine(caller, t, host, null, new MapProvider(new() { [5] = callee }));
var sink = new RecordingTraceSink();
var vm = new VirtualMachine(caller, t, host, null, new MapProvider(new() { [5] = callee }), sink);
vm.Run();
Assert.Equal(7, vm.Globals[0x10]); // callee wrote a shared global
Assert.Equal(7, vm.Globals[0x11]); // caller read it AFTER the call returned
Assert.Equal("exit", vm.HaltReason); // top-level exit
Assert.Contains(5L, host.Calls); // host notified
Assert.Contains(5L, sink.CallScriptIds); // dispatch observed via the trace sink
}
[Fact]
@@ -72,10 +73,11 @@ public class CallScriptTests
var t = Table();
var caller = Asm(t, "CALLER", OP_CALLSCRIPT, 0, 5, OP_EXIT);
var host = new NullHost();
var vm = new VirtualMachine(caller, t, host, null, null); // no provider
var sink = new RecordingTraceSink();
var vm = new VirtualMachine(caller, t, host, null, null, sink); // no provider
vm.Run();
Assert.Equal("exit", vm.HaltReason); // did not halt on the call; stub + continue
Assert.Contains(5L, host.Calls);
Assert.Contains(5L, sink.CallScriptIds);
}
[Fact]