import assert from "node:assert/strict"; import test from "node:test"; import { ImageClient } from "../src/client"; import { parseValue } from "../src/values"; import { startImage } from "./server"; test( "execution inspection returns exact loaded code and mapped nested frames without mutations", { timeout: 10000 }, async (t) => { const image = await startImage(); let changes = 0; const client = await ImageClient.connect( image.address, (error) => assert.equal(error, undefined), () => changes++, ); t.after(async () => { await client.close(); await image.stop(); }); const source = "pub fn handle(ctx, state, sender, message) {\n nested()\n}\nfn nested() {\n loop {}\n}"; const file = await client.writeSource("actors/debug", null, source); const actor = await client.spawn(file.path, parseValue("null")); assert.equal((await client.inspectExecution(actor)).execution, null); await client.send(actor, parseValue("null")); await client.tick(1, 16); const before = await client.inspectActor(actor); const count = changes; const inspection = await client.inspectExecution(actor); assert.equal(changes, count, "read-only inspection does not broadcast image_changed"); assert.deepEqual(await client.inspectActor(actor), before); assert.equal(inspection.source_id, file.source_id); assert.equal(inspection.source, source); assert.equal(inspection.implementation_id, before.implementation_id); const execution = inspection.execution; assert.ok(execution); assert.equal(execution.vm_steps, before.execution?.vm_steps); assert.equal(execution.call_depth, 1n); assert.deepEqual( execution.frames.map((frame) => frame.function), ["nested", "handle"], ); assert.deepEqual( execution.frames.map((frame) => frame.range?.start.line), [4, 1], ); await client.writeSource( file.path, file.source_id, "pub fn handle(ctx, state, sender, message) { 42 }", ); await client.system(actor, { kind: "reload" }); assert.equal((await client.inspectExecution(actor)).source, source); await client.system(actor, { kind: "pause" }); await client.tick(1, 1); const paused = await client.inspectExecution(actor); await client.tick(1, 100); assert.deepEqual(await client.inspectExecution(actor), paused); await client.system(actor, { kind: "kill" }); await assert.rejects(client.inspectExecution(actor), /unknown actor/); }, );