Files
linuxcncWebWASM/web/worker/test_xyzac_source_widget_gates.mjs
wangdequan bade560372 Align AXIS control flow and fix pause and program rendering
Document source UI gates, explicit native live-plot clearing, and remaining parity boundaries. Fix pause/resume transport continuity, repeated stepping, coordinate previews, and spindle override state. Optimize large program snapshots and rendering, and cover the control flows with native Tcl, WASM, and browser checks.

Validation: 22 native tests and source/browser checks pass. Worker/App regression: 113 of 123 pass; 10 pre-existing failures remain documented with no new failures.
2026-09-08 10:46:27 +08:00

50 lines
3.3 KiB
JavaScript

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 bundle = await loadSimulationCase({
path: "linuxcnc/configs/sim/axis/vismach/5axis/table-rotary-tilting/xyzac-trt.ini",
fetchImpl: async (url) => {
try { const text = await readFile(new URL(`../../${String(url).replace(/^\//, "")}`, import.meta.url), "utf8"); return { ok: true, text: async () => text }; }
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 session = new XyzacSession(core, { sessionId: "source-widget-gates" });
let seq = 0;
const send = (kind, payload = {}) => session.accept({ schema_version: 1, context_id: CONTEXT_ID, session_id: session.sessionId, seq: ++seq, operation_id: `source-widget-${seq}`, kind, payload });
const snapshot = () => send("SNAPSHOT_REQUEST").payload.panel_snapshot;
send("HELLO"); send("SESSION_ATTACH");
assert.equal(send("LOAD_WORKSPACE", { root_path: "/workspace", configuration: toWorkerConfiguration(bundle) }).kind, "COMMAND_RESULT");
assert.equal(send("PROGRAM_LOAD", { source: "G21 G90\nG1 X100 F60\nM2\n", path: "source-widget.ngc" }).kind, "COMMAND_RESULT");
for (const estop of [false, true]) {
send("ESTOP", { active: estop });
for (const [kind, payload] of [["SET_OVERRIDE", { feed: 0.8 }], ["SET_JOG_SCALE", { percent: 50 }], ["SET_MAX_VELOCITY", { percent: 60 }], ["SET_SPINDLE_OVERRIDE", { scale: 0.7 }]]) {
const response = send(kind, payload);
assert.equal(response.kind, "COMMAND_RESULT", `${kind} in ${estop ? "ESTOP" : "OFF"}: ${response.payload.gate_reason ?? response.payload.message_key}`);
}
assert.equal(snapshot().io.state.spindles[0].enabled, 0);
assert.equal(snapshot().io.state.spindles[0].command_rpm, 0);
assert.equal(snapshot().ui_gates.abort.enabled, false, "Stop widget must be disabled at IDLE");
}
send("ESTOP", { active: false }); send("POWER", { active: true }); send("HOME", { all: true });
send("SET_MODE", { mode: "MDI" });
assert.equal(snapshot().gates.spindle.enabled, true);
assert.equal(snapshot().gates.touchOff.enabled, true);
assert.equal(send("SPINDLE_COMMAND", { direction: 1, rpm: 100, enabled: true }).kind, "COMMAND_RESULT");
assert.equal(snapshot().task.mode, "MANUAL", "source spindle radio handler ensures MANUAL");
send("SPINDLE_COMMAND", { direction: 0, rpm: 0, enabled: false });
send("PROGRAM_RUN"); send("SIM_STEP", { cycles: 2 });
assert.equal(snapshot().ui_gates.abort.enabled, true);
assert.equal(snapshot().ui_gates.coolant.enabled, false, "source manual checkbox group requires IDLE");
assert.equal(snapshot().gates.load.enabled, false);
send("PROGRAM_PAUSE");
assert.equal(snapshot().gates.load.enabled, false);
assert.equal(snapshot().ui_gates.abort.enabled, true);
send("PROGRAM_ABORT");
assert.equal(snapshot().ui_gates.abort.enabled, false);
assert.equal(snapshot().ui_gates.coolant.enabled, true);
console.log(JSON.stringify({ schema: "xyzac-source-widget-gates.v1", status: "verified", cases: ["OFF", "ESTOP", "MDI_IDLE", "AUTO_RUNNING", "PAUSED", "ABORTED_IDLE"] }));