Enforce LinuxCNC WASM authority for XYZAC frontend

This commit is contained in:
2026-09-02 07:43:47 +08:00
parent c60e3a1e8f
commit 6b689fd69e
36 changed files with 514 additions and 210 deletions

View File

@@ -9,7 +9,7 @@ const fetchImpl = async (url) => { try { const body = await readFile(new URL(`..
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)) });
function setup(id) {
function setup(id, { homeAll = true } = {}) {
const session = new XyzacSession(core, { sessionId: id });
const base = { schema_version: 1, context_id: CONTEXT_ID, session_id: id };
let seq = 0;
@@ -17,10 +17,17 @@ function setup(id) {
send("HELLO", "hello"); send("SESSION_ATTACH", "attach");
assert.equal(send("LOAD_WORKSPACE", "workspace", { root_path: "/workspace", configuration: toWorkerConfiguration(bundle) }).payload.status, "verified");
assert.equal(send("POWER", "power-on", { active: true }).payload.status, "verified");
assert.equal(send("HOME", "home-all", { all: true }).payload.wasm_home_limit.state.homed, true);
if (homeAll) assert.equal(send("HOME", "home-all", { all: true }).payload.wasm_home_limit.state.homed, true);
return { session, send };
}
const partialHome = setup("xyzac-manual-partial-home", { homeAll: false });
for (const [index, axis] of ["x", "y", "z", "a", "c"].entries()) {
const response = partialHome.send("HOME", `home-${axis}`, { axis });
assert.equal(response.payload.wasm_home_limit.state.homed_mask, (1 << (index + 1)) - 1);
assert.equal(response.payload.wasm_home_limit.state.homed, index === 4);
}
const jogCase = setup("xyzac-manual-jog");
const home = jogCase.send("HOME", "home-all");
assert.equal(home.payload.motion_authority, "wasm");
@@ -45,7 +52,7 @@ for (const axis of axes) {
const outOfRange = jogCase.send("JOG_START", "jog-limit", { axis: "x", direction: 1, speed: 1, increment: 10000 });
assert.equal(outOfRange.kind, "ERROR");
assert.equal(outOfRange.payload.message_key, "motion_limit_range");
const nonFinite = jogCase.send("JOG_START", "jog-nonfinite", { axis: "a", direction: 1, speed: "not-a-number" });
const nonFinite = jogCase.send("JOG_START", "jog-nonfinite", { axis: "a", direction: 1, increment: "not-a-number" });
assert.equal(nonFinite.kind, "ERROR");
assert.equal(nonFinite.payload.message_key, "motion_jog_nonfinite");
const ferror = jogCase.send("FOLLOWING_ERROR", "ferror", { value: 1 });