Complete XYZAC LinuxCNC WASM parity and smooth 3D preview

This commit is contained in:
2026-08-28 06:24:50 +08:00
parent e8fe323aab
commit 1a7995fa9b
181 changed files with 36854 additions and 215 deletions

View File

@@ -0,0 +1,44 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import createModule from "../../build-wasm/linuxcnc-sim-core.js";
import { loadSimulationCase, toWorkerConfiguration } from "../workspace/sim-case-loader.mjs";
import { XyzacSession, CONTEXT_ID } from "./xyzac-session.mjs";
const CASE = "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.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 });
const core = await createModule({ wasmBinary: await readFile(new URL("../../build-wasm/linuxcnc-sim-core.wasm", import.meta.url)) });
const session = new XyzacSession(core, { sessionId: "xyzac-preview" });
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: session.sessionId };
let seq = 0;
const send = (kind, operation_id, payload = {}) => session.accept({ ...base, kind, seq: ++seq, operation_id, payload });
send("HELLO", "hello");
send("SESSION_ATTACH", "attach");
assert.equal(send("LOAD_WORKSPACE", "workspace", { root_path: "/workspace", configuration: toWorkerConfiguration(bundle) }).payload.status, "verified");
const source = "G21 G90\nG0 X10 Y5 Z200 A30 C45\nG1 X20 Y10 Z180 A35 C50 F100\nM2\n";
const loaded = send("PROGRAM_LOAD", "program-load", { source, path: "demos/preview.ngc" });
assert.equal(loaded.kind, "COMMAND_RESULT");
assert.equal(loaded.payload.program.source, "linuxcnc-wasm-sim_program");
assert.equal(loaded.payload.program.path, "demos/preview.ngc");
assert.equal(loaded.payload.program.source_hash, "fnv1a64:b7f4678312207b31");
assert.equal(loaded.payload.preview.status, "verified");
assert.equal(loaded.payload.preview.source, "linuxcnc-wasm-sim_program");
assert.equal(loaded.payload.preview.path, "demos/preview.ngc");
assert.equal(loaded.payload.preview.line_count, 4);
assert.ok(loaded.payload.preview.segments.length >= 2);
assert.ok(loaded.payload.preview.segments.every((segment) => Number.isSafeInteger(segment.id) && Number.isSafeInteger(segment.source_line)));
assert.ok(loaded.payload.preview.segments.every((segment) => ["x", "y", "z", "a", "b", "c"].every((axis) => Number.isFinite(segment.start[axis]) && Number.isFinite(segment.end[axis]))));
const previewHash = loaded.payload.preview.preview_hash;
const snapshot = send("SNAPSHOT_REQUEST", "snapshot");
assert.equal(snapshot.payload.panel_snapshot.program.path, "demos/preview.ngc");
assert.equal(snapshot.payload.panel_snapshot.program.source_hash, loaded.payload.program.source_hash);
const replay = send("PROGRAM_LOAD", "program-load", { source: "G999\n", path: "bad.ngc" });
assert.equal(replay.replayed, true);
assert.equal(replay.payload.preview.preview_hash, previewHash);
const invalid = send("PROGRAM_LOAD", "invalid-load", { source: "G999\n", path: "invalid.ngc" });
assert.equal(invalid.kind, "ERROR");
assert.equal(invalid.payload.preview.status, "error");
const empty = send("PROGRAM_LOAD", "empty-load", { source: "", path: "empty.ngc" });
assert.equal(empty.kind, "ERROR");
assert.equal(empty.payload.code, "program_source_invalid");
console.log(JSON.stringify({ schema: "xyzac-program-preview-rtcp-04.v1", status: "verified", case: CASE, source_hash: loaded.payload.program.source_hash, line_count: loaded.payload.preview.line_count, segment_count: loaded.payload.preview.segments.length, preview_hash: previewHash, invalid_gcode: invalid.payload.preview.status, empty_code: empty.payload.code, state_hash: snapshot.payload.panel_snapshot.state_hash }));