35 lines
2.8 KiB
JavaScript
35 lines
2.8 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import createModule from "../../build-wasm/linuxcnc-sim-core.js";
|
|
import { loadXyzacTrtCase, XYZAC_TRT_CASE, XYZAC_TRT_STARTUP_STATES } from "../workspace/xyzac-trt-case-loader.mjs";
|
|
import { XyzacSession, CONTEXT_ID } from "./xyzac-session.mjs";
|
|
|
|
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 core = await createModule({ wasmBinary: await readFile(new URL("../../build-wasm/linuxcnc-sim-core.wasm", import.meta.url)) });
|
|
const loaded = await loadXyzacTrtCase({ fetchImpl, core });
|
|
assert.equal(loaded.status, "ready");
|
|
assert.equal(loaded.case, XYZAC_TRT_CASE);
|
|
assert.equal(loaded.startup.status, "ready");
|
|
assert.equal(loaded.startup.state, "TASK_READY");
|
|
assert.deepEqual(loaded.startup.transitions.map((row) => row.to), XYZAC_TRT_STARTUP_STATES);
|
|
assert.deepEqual(loaded.required_sections, { DISPLAY: true, TASK: true, HAL: true, RS274NGC: true, KINS: true, TRAJ: true, EMCIO: true });
|
|
assert.equal(loaded.machine.coordinates, "XYZAC");
|
|
assert.equal(loaded.machine.joint_count, 5);
|
|
assert.equal(loaded.machine.rotary_units, "degrees");
|
|
assert.equal(loaded.machine.kinematics, "xyzac-trt");
|
|
const roles = new Map(loaded.exact_resources.map((row) => [row.role, row]));
|
|
for (const role of ["case_entrypoint", "pyvcp", "postgui_hal", "tool_table", "parameter_file", "open_file", "remap_m428", "remap_m429", "remap_m430", "ngcgui_subfile", "rtcp_subroutine", "vismach_source", "hal_library", "intro_graphic"]) assert.equal(roles.get(role)?.status, "resolved", role);
|
|
assert.ok(loaded.exact_resources.every((row) => row.data_hash));
|
|
assert.ok(loaded.startup.hal.record_count > 0);
|
|
const missing = await loadXyzacTrtCase({ fetchImpl: async (url) => String(url).endsWith("xyzac-trt.xml") ? { ok: false, text: async () => "" } : fetchImpl(url), core });
|
|
assert.equal(missing.status, "blocked");
|
|
assert.ok(missing.missing.includes("linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.xml"));
|
|
const session = new XyzacSession(core, { sessionId: "startup-session" });
|
|
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: session.sessionId };
|
|
const attach = session.accept({ ...base, kind: "HELLO", seq: 1, operation_id: "hello", payload: {} });
|
|
assert.equal(attach.payload.xyzac_session.machine.coordinates, "XYZAC");
|
|
console.log(JSON.stringify({ schema: "xyzac-trt-startup-rtcp-02.v1", status: "verified", case: XYZAC_TRT_CASE, startup: loaded.startup, exact_resource_count: loaded.exact_resources.length, fetched_count: loaded.fetched.length, missing_case_status: missing.status, state_hash: loaded.state_hash }));
|