import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import { fnv1a64 } from "./replay.mjs"; import { loadSimulationCase, toWorkerConfiguration } from "../workspace/sim-case-loader.mjs"; import { WorkspaceRuntime } from "../workspace/runtime.mjs"; import { startConfiguration } from "../workspace/configuration-startup.mjs"; const CASE = "linuxcnc/configs/sim/axis/vismach/3axis-tutorial/3axis-tutorial.ini"; const fetchImpl = async (url) => { try { const body = await readFile(new URL(`../../${String(url).replace(/^\//, "")}`, import.meta.url)); return { ok: true, text: async () => body.toString("utf8") }; } catch { return { ok: false, text: async () => "" }; } }; const bundle = await loadSimulationCase({ path: CASE, fetchImpl }); assert.equal(bundle.status, "ready"); const firstWorkspace = new WorkspaceRuntime({ files: bundle.files }); const secondWorkspace = new WorkspaceRuntime({ files: bundle.files }); const core = { _sim_create() { return 0; }, _sim_load_workspace() { return 0; } }; const first = startConfiguration({ workspace: firstWorkspace, entrypoint: CASE, core, halManifest: bundle.halManifest }); const second = startConfiguration({ workspace: secondWorkspace, entrypoint: CASE, core, halManifest: bundle.halManifest }); assert.equal(first.status, "ready"); assert.equal(first.state, "TASK_READY"); assert.deepEqual(first.transitions.map((row) => row.to), ["NEW", "MOUNTED", "PARSED", "RESOLVED", "CORE_CREATED", "HAL_READY", "TASK_READY"]); assert.equal(first.state_hash, second.state_hash); assert.equal(firstWorkspace.read("/workspace/linuxcnc/configs/sim/axis/vismach/3axis-tutorial/3axis-tutorial_mm.var"), ""); assert.equal(bundle.catalog.coordinates, "X Y Z"); assert.equal(bundle.catalog.kinematics, "trivkins"); assert.equal(first.resources.resources.find((row) => row.type === "image").path, "linuxcnc/linuxcnc.gif"); assert.equal(first.hal.records.some((row) => row.program === "./3axis-tutorial" && row.capability === "WEB-EQUIV"), true); const configuration = toWorkerConfiguration(bundle); assert.equal(configuration.entrypoint, CASE); assert.equal(fnv1a64({ bundle: bundle.state_hash, startup: first.state_hash }), fnv1a64({ bundle: bundle.state_hash, startup: second.state_hash })); console.log(JSON.stringify({ schema: "axis3-tutorial-startup.v1", status: "verified", case: CASE, transitions: first.transitions.map((row) => row.to), loader_hash: bundle.state_hash, startup_hash: first.state_hash, deterministic: first.state_hash === second.state_hash, generated: bundle.runtime_fixtures.map((row) => row.resource_path), hal_blocked: first.hal.blocked_count }));