45 lines
3.0 KiB
JavaScript
45 lines
3.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile } from "node:fs/promises";
|
|
import { projectXyzacVisual, XYZAC_MACHINE_GROUPS } from "./xyzac-visual-adapter.ts";
|
|
|
|
const source = await readFile(new URL("./XyzacMachineView.tsx", import.meta.url), "utf8");
|
|
const adapter = await readFile(new URL("./xyzac-visual-adapter.ts", import.meta.url), "utf8");
|
|
const snapshot = {
|
|
schema: "axis-panel-snapshot.v1",
|
|
simulation_tick: 42,
|
|
state_hash: "fnv1a64:xyzac-authoritative",
|
|
kinematics: {
|
|
schema: "wasm-xyzac-kinematics.v1",
|
|
status: "verified",
|
|
active_type: 1,
|
|
native_type: "xyzac-trt-kins",
|
|
coordinates: "XYZAC",
|
|
joint_count: 5,
|
|
linear_units: "mm",
|
|
angular_units: "deg",
|
|
pose: { x: 12, y: -5, z: 20, a: 30, b: 0, c: 45, u: 0, v: 0, w: 0 },
|
|
joints: [12, -5, 20, 30, 45],
|
|
offsets: { x_rot_point: 0, y_offset: 20, z_offset: 10, tool_offset: 25 },
|
|
generation: 2,
|
|
switch_count: 2,
|
|
state_hash: "fnv1a64:kinematics",
|
|
wasm_state_hash: "fnv1a64:wasm-kinematics",
|
|
},
|
|
visual: { active_segment_id: 7, active_progress: 0.5, pose: { x: 12, y: -5, z: 20, a: 30, c: 45 }, joints: [12, -5, 20, 30, 45], toolpath: [{ id: 7, active: true, start: { x: 0, y: 0, z: 0 }, end: { x: 12, y: -5, z: 20 }, motion_type: 1 }] },
|
|
};
|
|
const visual = projectXyzacVisual(snapshot);
|
|
assert.equal(visual.schema, "xyzac-visual-state.v1");
|
|
assert.equal(visual.tick, 42);
|
|
assert.equal(visual.stateHash, snapshot.state_hash);
|
|
assert.deepEqual(visual.joints, [12, -5, 20, 30, 45]);
|
|
assert.deepEqual(visual.pose, snapshot.kinematics.pose);
|
|
assert.deepEqual(visual.offsets, snapshot.kinematics.offsets);
|
|
assert.equal(visual.activeSegmentId, 7);
|
|
assert.equal(visual.activeProgress, 0.5);
|
|
assert.equal(visual.source, "linuxcnc-wasm-worker");
|
|
assert.deepEqual(XYZAC_MACHINE_GROUPS, ["xyzac-machine", "table-x", "saddle-y", "spindle-z", "tilt-a", "rotate-c", "tool-offset", "xyzac-toolpath", "xyzac-live-toolpath"]);
|
|
for (const token of ["table-x", "saddle-y", "spindle-z", "tilt-a", "rotate-c", "tool-offset", "tableX.position.x = -tableXJoint * MM", "saddle.position.z = -saddleYJoint * MM", "zslide.position.y = (200 - spindleZJoint) * MM", "tilt.rotation.x = -tiltAJoint * DEG", "rotate.rotation.y = -rotateCJoint * DEG", "tool.position.y = -state.offsets.tool_offset * MM", "data-xyzac-tick", "data-xyzac-state-hash", "data-xyzac-active-segment", "data-xyzac-joints", "data-xyzac-offsets"]) assert.ok(source.includes(token), token);
|
|
for (const forbidden of [/accept\s*\(/, /postMessage\s*\(/, /_sim_/, /_malloc/, /navigator\.storage/, /HAL_SET/, /KINEMATICS_SELECT/]) assert.equal(forbidden.test(source), false, String(forbidden));
|
|
assert.ok(adapter.includes("source: \"linuxcnc-wasm-worker\""));
|
|
console.log(JSON.stringify({ schema: "xyzac-threejs-rtcp-10.v1", status: "verified", tick: visual.tick, state_hash: visual.stateHash, groups: XYZAC_MACHINE_GROUPS, active_segment: visual.activeSegmentId, direction: { table_x: -1, saddle_y: -1, spindle_z: -1, tilt_a: "x+", rotate_c: "z+", tool_offset: "z-" }, clear_visual_nonmutating: true, source: visual.source }));
|