import assert from "node:assert/strict"; import { INITIAL_STATE, reduceFrontendState } from "./store.ts"; import { projectXyzacPanel } from "./xyzac-panel-contract.ts"; const envelope = (kind, seq, payload, tick) => ({ schema_version: 1, kind, context_id: INITIAL_STATE.contextId, session_id: "motion-projection", seq, simulation_tick: tick, payload }); const panel = { schema: "axis-panel-snapshot.v1", context_id: INITIAL_STATE.contextId, session_id: "motion-projection", simulation_tick: 1, state_hash: "fnv1a64:panel", task: { state: "RUNNING", mode: "AUTO", program_status: "running", current_line: 1 }, program: { program_status: "running", current_line: 1 }, motion: { axes: [10, 20, 30, 40, 50], joints: [10, 20, 30, 40, 50] }, coordinates: { machine: [10, 20, 30, 40, 50], relative: [10, 20, 30, 40, 50] }, overrides: { feed: 1, spindle: [1] }, wasm_motion: { status: "verified", state: { position: { x: 10, y: 20, z: 30, a: 40, c: 50 }, queue_depth: 1 } }, visual: { schema: "axis-visual.v1", pose: { x: 10, y: 20, z: 30, a: 40, c: 50 }, joints: [10, 20, 30, 40, 50], toolpath: [], active_segment_id: 1, active_progress: 0.1, source: "wasm_canonical_motion" }, kinematics: { coordinates: "XYZAC", joint_count: 5, pose: { x: 10, y: 20, z: 30, a: 40, c: 50 }, joints: [10, 20, 30, 40, 50], offsets: {} }, xyzac: { coordinates: "XYZAC", joint_count: 5 }, gates: {}, }; const initial = reduceFrontendState(INITIAL_STATE, envelope("STATE_SNAPSHOT", 1, { panel_snapshot: panel }, 1)); const next = reduceFrontendState(initial, envelope("COMMAND_RESULT", 2, { status: "verified", snapshot_mode: "motion_delta", motion_sample: { tick: 2, pose: { x: 11, y: 21, z: 31, a: 41, c: 51 }, joints: [11, 21, 31, 41, 51], active_segment_id: 1, active_progress: 0.2 }, motion_trace: [], wasm_motion: { status: "verified", state: { position: { x: 11, y: 21, z: 31, a: 41, c: 51 }, queue_depth: 1 } }, motion: { axes: [11, 21, 31, 41, 51], joints: [11, 21, 31, 41, 51] }, task: panel.task, program: panel.program, state_hash: "fnv1a64:delta", }, 2)); assert.deepEqual(next.snapshot.motion.axes, [11, 21, 31, 41, 51]); assert.equal(next.snapshot.visual.pose.a, 41); assert.equal(next.snapshot.visual.pose.c, 51); const xyzbcPanel = projectXyzacPanel({ simulation_tick: 3, state_hash: "bc", kinematics: { schema: "wasm-xyzac-kinematics.v1", status: "verified", active_type: 1, native_type: "xyzbc-trt-kins", coordinates: "XYZBC", joint_count: 5, linear_units: "mm", angular_units: "deg", pose: { x: 0, y: 0, z: 0, a: 0, b: 12, c: 20, u: 0, v: 0, w: 0 }, joints: [1, 2, 3, 12, 20], offsets: { x_rot_point: 0, y_rot_point: 0, z_rot_point: 0, x_offset: -20, y_offset: 0, z_offset: -15, tool_offset: 0 }, generation: 1, switch_count: 1, state_hash: "k", wasm_state_hash: "w" }, xyzac: { coordinates: "XYZBC", joint_count: 5, active_type: 1, hal_pin_vars: true, switchkins_net: true, finite_offsets: true, userk_capability: true }, visual: { pose: { x: 0, y: 0, z: 0, a: 0, b: 12, c: 20 }, joints: [1, 2, 3, 12, 20] } }); assert.equal(xyzbcPanel.machine.coordinates, "XYZBC"); assert.deepEqual(xyzbcPanel.machine.axes, ["x", "y", "z", "b", "c"]); assert.deepEqual(xyzbcPanel.joints, [1, 2, 3, 12, 20]); console.log(JSON.stringify({ schema: "xyzac-motion-projection.v1", status: "verified", axes: next.snapshot.motion.axes, pose: { a: next.snapshot.visual.pose.a, c: next.snapshot.visual.pose.c } }));