Files
linuxcncWebWASM/web/app/test_axis_operation_controller.mjs

18 lines
1.4 KiB
JavaScript

import assert from "node:assert/strict";
import { AxisOperationController } from "./axis-operation-controller.mjs";
const calls = [];
const client = { send: async (kind, payload, operationId) => { calls.push({ kind, payload, operationId }); return { kind: "COMMAND_RESULT", payload: { status: "verified" } }; } };
const controller = new AxisOperationController(client);
const ready = { task: { state: "READY", mode: "MANUAL" }, program: { path: "main.ngc", program_status: "loaded" } };
const run = await controller.execute("PROGRAM_RUN", {}, { state: ready });
assert.equal(run.operationId, "axis-program-run-000001");
assert.equal(run.gate.reason, "linuxcnc_wasm_worker_authority");
assert.equal(calls[0].operationId, run.operationId);
const jog = await controller.execute("JOG_START", { axis: "x" }, { state: { task: { state: "ESTOP" } } });
assert.equal(jog.operationId, "axis-jog-start-000002");
const tick = await controller.execute("SIM_STEP", { cycles: 1 }, { state: ready, gate: false });
assert.equal(tick.operationId, "axis-sim-step-000003");
assert.deepEqual(controller.exportTrace().map((entry) => entry.phase), ["pending", "result", "pending", "result", "pending", "result"]);
console.log(JSON.stringify({ schema: "axis-operation-controller-sample.v1", status: "verified", calls: calls.length, phases: controller.exportTrace().map((entry) => entry.phase), last_operation: tick.operationId }));