Implement AXIS parity UI and execution baseline
This commit is contained in:
24
web/worker/test_trace_export.mjs
Normal file
24
web/worker/test_trace_export.mjs
Normal file
@@ -0,0 +1,24 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import createModule from "../../build-wasm/linuxcnc-sim-core.js";
|
||||
import { SimSession, CONTEXT_ID } from "./sim-session.mjs";
|
||||
import { validateTrace } from "./trace-export.mjs";
|
||||
|
||||
const wasmBinary = await readFile(new URL("../../build-wasm/linuxcnc-sim-core.wasm", import.meta.url));
|
||||
const core = await createModule({ wasmBinary });
|
||||
const session = new SimSession(core, { sessionId: "trace-a" });
|
||||
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: "trace-a" };
|
||||
const send = (kind, seq, operation_id, payload = {}) => session.accept({ ...base, kind, seq, operation_id, payload });
|
||||
send("HELLO", 1); send("SESSION_ATTACH", 2, "attach"); send("LOAD_WORKSPACE", 3, "workspace", { root_path: "/workspace" });
|
||||
send("HOME", 4, "home"); send("JOG_START", 5, "jog", { axis: "x", direction: 1, speed: 10 }); send("SIM_STEP", 6, "step", { cycles: 3 });
|
||||
const trace = session.exportTrace();
|
||||
assert.equal(trace.schema, "simulation-trace.v1");
|
||||
assert.equal(validateTrace(trace, { contextId: CONTEXT_ID }).trace.trace_hash, trace.trace_hash);
|
||||
const imported = structuredClone(trace);
|
||||
const secondCore = await createModule({ wasmBinary });
|
||||
const second = new SimSession(secondCore, { sessionId: "trace-a" });
|
||||
assert.equal(second.importTrace(imported).state_hash, trace.state_hash);
|
||||
assert.equal(second.exportTrace().trace_hash, trace.trace_hash);
|
||||
const invalid = structuredClone(trace); invalid.state.motion.axes.x += 1;
|
||||
assert.throws(() => validateTrace(invalid, { contextId: CONTEXT_ID }), /trace_state_hash/);
|
||||
console.log(`trace_export=passed seq=${trace.seq} tick=${trace.tick} hash=${trace.trace_hash}`);
|
||||
Reference in New Issue
Block a user