import assert from "node:assert/strict"; import { AXIS_BOUNDARIES, AXIS_COMMANDS, axisGate, axisGateMatrix, normalizeAxisState } from "./axis-contract.mjs"; const ready = { task: { state: "ON", interp_state: "IDLE", mode: "MANUAL" }, taskfile: "main.ngc", motion: { mode: "COORD", homed: [true, true, true] }, devices: { tool: { current: 1 } } }; assert.equal(normalizeAxisState(ready).taskState, "ON"); assert.equal(axisGate("run", ready).enabled, true); assert.equal(axisGate("jogStart", ready).enabled, true); assert.equal(axisGate("touchOff", ready).enabled, true); assert.equal(axisGate("toolTouchOff", ready).enabled, true); const running = { ...ready, task: { ...ready.task, interp_state: "READING" } }; assert.equal(axisGate("run", running).enabled, false); assert.equal(axisGate("pause", running).enabled, true); assert.equal(axisGate("stop", running).enabled, true); assert.equal(axisGate("jogStart", running).reason, "axis_manual_state_gate"); const paused = { ...ready, task: { ...ready.task, interp_state: "PAUSED" } }; assert.equal(axisGate("resume", paused).enabled, true); assert.equal(axisGate("pause", paused).enabled, false); const estop = { ...ready, task: { ...ready.task, state: "ESTOP" } }; assert.equal(axisGate("estop", estop).enabled, true); assert.equal(axisGate("jogStart", estop).reason, "axis_estop_active"); const queueFull = { ...ready, task: { ...ready.task, mode: "MDI", queued_mdi_commands: 10, max_queued_mdi_commands: 10 } }; assert.equal(axisGate("mdi", queueFull).enabled, false); assert.equal(axisGate("mdi", queueFull).reason, "axis_mdi_queue_full"); const limit = { ...ready, motion: { ...ready.motion, on_any_limit: true } }; assert.equal(axisGate("overrideLimits", limit).enabled, true); assert.equal(axisGateMatrix(ready).run.reason, "axis_run_available"); assert.equal(AXIS_COMMANDS.run, "PROGRAM_RUN"); assert.equal(AXIS_BOUNDARIES.physicalHardware, "REAL-EXCLUDED"); for (const action of ["tool", "toolPrepare", "toolChange"]) { assert.equal(axisGate(action, ready).enabled, true); assert.equal(axisGate(action, running).enabled, false); assert.equal(axisGate(action, paused).enabled, false); assert.equal(axisGate(action, estop).enabled, false); assert.equal(axisGate(action, { ...ready, task: { ...ready.task, state: "OFF" } }).enabled, false); assert.equal(axisGate(action, { ...ready, motion: { ...ready.motion, queue_depth: 1 } }).reason, "axis_motion_active"); assert.equal(axisGate(action, { ...ready, devices: { fault: true } }).reason, "axis_fault_active"); assert.equal(axisGate(action, { ...ready, task: { ...ready.task, mode: "AUTO" } }).enabled, false); } console.log(JSON.stringify({ schema: "axis-contract-sample.v1", status: "verified", commands: Object.keys(AXIS_COMMANDS).length, matrix: Object.keys(axisGateMatrix(ready)).length, blocked_reasons: [axisGate("mdi", queueFull).reason, axisGate("jogStart", estop).reason] }));