Files
cnc_wams/web-rtcp-5axis-sim-plan/tests/browser/gmoccapy_shell_smoke.html

630 lines
33 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>gmoccapy shell browser smoke</title>
</head>
<body>
<pre id="result">gmoccapy_shell_smoke=pending</pre>
<iframe id="app-frame" title="gmoccapy shell"></iframe>
<script type="module">
const result = document.querySelector("#result");
const frame = document.querySelector("#app-frame");
const appSrc = new URLSearchParams(window.location.search).get("app") || "../../app/index.html";
frame.src = appSrc;
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function waitForInterpreterExecution(win) {
for (let attempt = 0; attempt < 40; attempt += 1) {
const state = win.webRtcp5AxisSimulation.getState();
if (!state.interpreterExecutionPending && state.programExecutionSourceMode === "linuxcnc-interpreter-wasm") {
return state;
}
await wait(25);
}
return win.webRtcp5AxisSimulation.getState();
}
async function waitForMachineFileExecution(win) {
for (let attempt = 0; attempt < 60; attempt += 1) {
const state = win.webRtcp5AxisSimulation.getState();
if (!state.interpreterExecutionPending && state.machineFileExecution) {
return state;
}
await wait(25);
}
return win.webRtcp5AxisSimulation.getState();
}
async function runSmoke() {
await new Promise((resolve, reject) => {
frame.addEventListener("load", resolve, { once: true });
frame.addEventListener("error", reject, { once: true });
});
await wait(250);
const doc = frame.contentDocument;
const win = frame.contentWindow;
const regions = [
"titlebar",
"preview",
"dro",
"gcode",
"status-sidebar",
"info-tabs",
"override",
"spindle-coolant",
"bottom-controls",
];
for (const region of regions) {
const element = doc.querySelector(`[data-region="${region}"]`);
if (!element) {
throw new Error(`missing region: ${region}`);
}
if (!element.textContent.trim() && region !== "preview") {
throw new Error(`empty region: ${region}`);
}
}
if (!doc.querySelector(".machine-preview")) {
throw new Error("missing machine preview");
}
let canvas = doc.querySelector("[data-five-axis-canvas]");
if (!canvas) {
throw new Error("missing Three.js preview canvas");
}
if (
canvas.dataset.threeReady !== "true" ||
canvas.dataset.threeFrameApi !== "web-rtcp-5axis-motion-frame" ||
Number(canvas.dataset.threePathPoints ?? 0) < 64 ||
Number(canvas.dataset.threeSceneObjects ?? 0) < 12 ||
!canvas.dataset.threeToolhead ||
!canvas.dataset.threeToolAxis ||
!canvas.dataset.threeTcpPose
) {
throw new Error(`Three.js preview did not expose ready render state: ${JSON.stringify(canvas.dataset)}`);
}
assertCanvasNonblank(canvas, "initial Three.js preview");
if (!doc.querySelector(".dro-row")) {
throw new Error("missing DRO rows");
}
if (!doc.querySelector(".gcode-row.active")) {
throw new Error("missing active gcode row");
}
if (!win.webRtcp5AxisSimulation) {
throw new Error("missing public simulation API");
}
if (win.React || win.Vue || win.angular || win.Svelte) {
throw new Error("forbidden frontend framework global detected");
}
if (doc.querySelector("[data-reactroot], [data-v-app], [ng-version], [svelte]")) {
throw new Error("forbidden frontend framework DOM marker detected");
}
const packageJson = await fetch("../../app/package.json").then((response) => response.json());
const dependencyNames = [
...Object.keys(packageJson.dependencies || {}),
...Object.keys(packageJson.devDependencies || {}),
];
const forbiddenDependencies = ["react", "vue", "@angular/core", "svelte"];
const forbidden = dependencyNames.filter((name) => forbiddenDependencies.includes(name));
if (forbidden.length > 0) {
throw new Error(`forbidden frontend framework dependency detected: ${forbidden.join(", ")}`);
}
const runtimeReadiness = await win.webRtcp5AxisSimulation.kinematicsRuntimeReady;
if (runtimeReadiness.loaded !== true || runtimeReadiness.moduleId !== "xyzac-trt") {
throw new Error(`LinuxCNC kinematics runtime did not load in browser: ${JSON.stringify(runtimeReadiness)}`);
}
if (runtimeReadiness.executionContext !== "worker") {
throw new Error(`LinuxCNC kinematics runtime should run in worker: ${JSON.stringify(runtimeReadiness)}`);
}
const interpreterReadiness = await win.webRtcp5AxisSimulation.interpreterRuntimeReady;
if (interpreterReadiness.loaded !== true || interpreterReadiness.runProgramReady !== true) {
throw new Error(`LinuxCNC interpreter runtime did not load in browser: ${JSON.stringify(interpreterReadiness)}`);
}
if (interpreterReadiness.executionContext !== "worker") {
throw new Error(`LinuxCNC interpreter runtime should run in worker: ${JSON.stringify(interpreterReadiness)}`);
}
if (
interpreterReadiness.plannerRuntimeReady !== true ||
interpreterReadiness.plannerSemanticBoundary !== "linuxcnc_tp_queue_runtime_timing_from_canonical_motion"
) {
throw new Error(`LinuxCNC TP planner runtime did not load in browser worker: ${JSON.stringify(interpreterReadiness)}`);
}
const taskHalReadiness = await win.webRtcp5AxisSimulation.taskHalRuntimeReady;
if (
taskHalReadiness.loaded !== true ||
taskHalReadiness.taskRuntimeReady !== true ||
taskHalReadiness.motionRuntimeReady !== true ||
taskHalReadiness.halRuntimeReady !== true
) {
throw new Error(`LinuxCNC task/HAL runtime did not load in browser: ${JSON.stringify(taskHalReadiness)}`);
}
if (taskHalReadiness.executionContext !== "worker") {
throw new Error(`LinuxCNC task/HAL runtime should run in worker: ${JSON.stringify(taskHalReadiness)}`);
}
const state = win.webRtcp5AxisSimulation.getState();
if (state.sourceMode !== "source-derived-kinematics-wasm") {
throw new Error(`unexpected source mode: ${state.sourceMode}`);
}
if (state.kinematicsExecutionContext !== "worker") {
throw new Error(`unexpected kinematics execution context: ${state.kinematicsExecutionContext}`);
}
const profileSelector = doc.querySelector('[data-action="select-profile"]');
if (!profileSelector || profileSelector.options.length < 2) {
throw new Error("missing five-axis profile selector");
}
profileSelector.value = "xyzbc-trt";
profileSelector.dispatchEvent(new Event("change", { bubbles: true }));
await wait(500);
await win.webRtcp5AxisSimulation.refreshKinematicsFrame({ operatorMessage: "browser smoke refreshed xyzbc frame" });
const xyzbcState = win.webRtcp5AxisSimulation.getState();
if (xyzbcState.machineProfile !== "xyzbc-trt" || xyzbcState.profile.traj.coordinates !== "XYZBC") {
throw new Error("profile selector did not switch to XYZBC");
}
if (xyzbcState.kinematicsRuntimeReadiness?.moduleId !== "xyzbc-trt") {
throw new Error(`XYZBC kinematics runtime did not load: ${JSON.stringify(xyzbcState.kinematicsRuntimeReadiness)}`);
}
const restoredProfileSelector = doc.querySelector('[data-action="select-profile"]');
restoredProfileSelector.value = "xyzac-trt";
restoredProfileSelector.dispatchEvent(new Event("change", { bubbles: true }));
await wait(500);
await win.webRtcp5AxisSimulation.refreshKinematicsFrame({ operatorMessage: "browser smoke restored xyzac frame" });
const restoredProfileState = win.webRtcp5AxisSimulation.getState();
if (restoredProfileState.machineProfile !== "xyzac-trt") {
throw new Error(`unexpected profile: ${restoredProfileState.machineProfile}`);
}
if (state.rtcpFrame?.apiName !== "web-rtcp-5axis-motion-frame") {
throw new Error("missing RTCP frame state");
}
if (state.rtcpFrame?.readiness?.linuxCncKinematicsReady !== true) {
throw new Error("browser RTCP frame must use LinuxCNC kinematics readiness");
}
if (!doc.querySelector('[data-rtcp-value="tcp"]')?.textContent.includes("TCP")) {
throw new Error("missing TCP DRO strip");
}
if (!doc.querySelector('[data-rtcp-diagnostic="boundary"]')?.textContent.includes("linuxcnc_kinematics_wasm_c_abi")) {
throw new Error("missing RTCP boundary diagnostic");
}
if (!doc.querySelector('[data-linuxcnc-ini="status"]')?.textContent.includes("xyzac-trt.ini")) {
throw new Error("missing LinuxCNC INI status diagnostic");
}
if (!doc.querySelector('[data-linuxcnc-ini="kins"]')?.textContent.includes("xyzac-trt-kins")) {
throw new Error("missing LinuxCNC INI kinematics diagnostic");
}
if (!doc.querySelector('[data-linuxcnc-ini="limits"]')?.textContent.includes("X[-200,200]")) {
throw new Error("missing LinuxCNC INI axis limits diagnostic");
}
if (!doc.querySelector('[data-linuxcnc-task-policy="boundary"]')?.textContent.includes("linuxcnc_task_state_mode_command_gate")) {
throw new Error("missing LinuxCNC task policy boundary diagnostic");
}
if (!doc.querySelector('[data-linuxcnc-task-policy="source"]')?.textContent.includes("linuxcnc/src/emc/task/emctaskmain.cc")) {
throw new Error("missing LinuxCNC emctaskmain source diagnostic");
}
if (!doc.querySelector('[data-tool-preview="summary"]')?.textContent.includes("T1")) {
throw new Error("missing tool preview summary");
}
if (!doc.querySelector('[data-action="OPEN_FILE"]')) {
throw new Error("missing G-code file input");
}
if (!doc.querySelector('[data-machine-state="summary"]')?.textContent.includes("power off")) {
throw new Error("initial machine state should show power off");
}
win.webRtcp5AxisSimulation.dispatch({ type: "RUN" });
await wait(50);
if (!win.webRtcp5AxisSimulation.getState().operatorMessage.includes("blocked")) {
throw new Error("RUN should be blocked before power on");
}
doc.querySelector('[data-action="power"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().machine.powerOn !== true) {
throw new Error("POWER action did not turn machine on");
}
if (!doc.querySelector('[data-machine-state="summary"]')?.textContent.includes("power on")) {
throw new Error("machine state did not render power on");
}
doc.querySelector('[data-action="HOME"]').click();
await wait(50);
doc.querySelector('[data-action="mode-auto"]').click();
await wait(50);
if (!doc.querySelector('[data-linuxcnc-task-policy="gates"]')?.textContent.includes("auto")) {
throw new Error("LinuxCNC task policy did not expose auto run gate");
}
win.webRtcp5AxisSimulation.dispatch({
type: "LOAD_PROGRAM",
filename: "operator-demo.ngc",
content: [
"G90 G17",
"G0 X0 Y0 Z0",
"G1 X10 F100",
"G1 Y10",
"G1 X0",
"G1 Y0",
"G0 Z5",
"M5",
"M2",
].join("\n"),
});
await waitForInterpreterExecution(win);
if (win.webRtcp5AxisSimulation.getState().activeProgram !== "operator-demo.ngc") {
throw new Error("LOAD_PROGRAM did not update active program");
}
if (win.webRtcp5AxisSimulation.getState().programExecutionSourceMode !== "linuxcnc-interpreter-wasm") {
throw new Error("LOAD_PROGRAM did not execute through LinuxCNC interpreter WASM");
}
if (win.webRtcp5AxisSimulation.getState().programExecution?.summary?.motionEventCount < 5) {
throw new Error("LinuxCNC interpreter execution did not produce motion events");
}
if (win.webRtcp5AxisSimulation.getState().programExecution?.summary?.plannerRuntimeReady !== true) {
throw new Error("LinuxCNC TP planner timing was not ready for operator program");
}
if (win.webRtcp5AxisSimulation.getState().programExecutionTiming?.semanticBoundary !== "linuxcnc_tp_queue_runtime_timing_from_canonical_motion") {
throw new Error(`program timing did not use LinuxCNC TP queue runtime: ${JSON.stringify(win.webRtcp5AxisSimulation.getState().programExecutionTiming)}`);
}
if (win.webRtcp5AxisSimulation.getState().programExecutionTiming?.sampleCount < 2) {
throw new Error("LinuxCNC TP runtime feedback samples were not exposed");
}
if (win.webRtcp5AxisSimulation.getState().programRuntimeFeedback?.semanticBoundary !== "linuxcnc_tp_run_cycle_feedback_without_hardware") {
throw new Error(`initial runtime feedback did not use LinuxCNC TP sample: ${JSON.stringify(win.webRtcp5AxisSimulation.getState().programRuntimeFeedback)}`);
}
if (!doc.querySelector('[data-program-execution-source]')?.textContent.includes("linuxcnc-interpreter-wasm")) {
throw new Error("program execution source DOM did not render interpreter source");
}
if (!doc.querySelector('[data-program-execution-summary]')?.textContent.includes("motion")) {
throw new Error("program execution summary DOM did not render motion count");
}
if (!doc.querySelector('[data-program-timing="summary"]')?.textContent.match(/\\d+:\\d/)) {
throw new Error("program timing summary DOM did not render estimated execution time");
}
if (!doc.querySelector('[data-program-timing="segment"]')?.textContent.includes("mm/min")) {
throw new Error("program timing segment DOM did not render segment velocity");
}
if (!doc.querySelector('[data-program-runtime-feedback="source"]')?.textContent.includes("linuxcnc-tp-runtime-sample")) {
throw new Error("program runtime feedback DOM did not render LinuxCNC TP sample source");
}
if (!doc.querySelector('[data-program-runtime-feedback="dtg"]')?.textContent.includes("DTG")) {
throw new Error("program runtime feedback DOM did not render DTG");
}
if (!doc.querySelector('[data-program-switchkins-summary]')?.textContent.includes("0 events")) {
throw new Error("program switchkins summary DOM did not render zero-event state");
}
win.webRtcp5AxisSimulation.dispatch({
type: "LOAD_PROGRAM",
filename: "operator-arc-demo.ngc",
content: [
"G90 G17",
"G0 X1 Y0 Z0",
"G2 X0 Y1 I-1 J0 F60",
"M2",
].join("\n"),
});
await waitForInterpreterExecution(win);
const arcState = win.webRtcp5AxisSimulation.getState();
if (!arcState.programExecution?.summary?.motionTypes?.includes("ARC_FEED")) {
throw new Error("LinuxCNC interpreter did not produce ARC_FEED for browser arc program");
}
if (arcState.programExecution?.summary?.plannerRuntimeReady !== true) {
throw new Error("LinuxCNC TP planner timing was not ready for browser arc program");
}
const arcSegment = arcState.programExecutionTiming?.segments?.find((segment) => segment.type === "ARC_FEED");
if (!arcSegment || arcSegment.durationSeconds <= 1.4) {
throw new Error(`LinuxCNC TP arc timing segment missing or too short: ${JSON.stringify(arcState.programExecutionTiming)}`);
}
const stagedMachineFiles = await win.webRtcp5AxisSimulation.stageMachineFiles();
await wait(50);
if (stagedMachineFiles.save.status !== "saved" || stagedMachineFiles.save.fileCount < 5) {
throw new Error(`machine file staging did not save files: ${JSON.stringify(stagedMachineFiles.save)}`);
}
if (!stagedMachineFiles.save.files.some((file) => file.sourceRel.endsWith("remap_subs/428remap.ngc"))) {
throw new Error("machine file staging did not include M428 remap");
}
if (!doc.querySelector('[data-machine-file-staging="status"]')?.textContent.includes("staged")) {
throw new Error("machine file staging status did not render");
}
const sourceSelect = doc.querySelector('[data-action="select-linuxcnc-gcode-source"]');
if (!sourceSelect || sourceSelect.options.length < 4) {
throw new Error("LinuxCNC 5-axis G-code source selector did not render staged demos");
}
const impellerSource = "configs/sim/axis/vismach/5axis/table-rotary-tilting/demos/impeller-7bl-xyzac.ngc";
sourceSelect.value = impellerSource;
sourceSelect.dispatchEvent(new Event("change", { bubbles: true }));
await waitForInterpreterExecution(win);
const linuxCncSourceState = win.webRtcp5AxisSimulation.getState();
if (linuxCncSourceState.programSource !== "linuxcnc-vendored-5axis-gcode") {
throw new Error(`LinuxCNC source program was not loaded: ${linuxCncSourceState.programSource}`);
}
if (!linuxCncSourceState.activeProgram.endsWith("impeller-7bl-xyzac.ngc")) {
throw new Error(`unexpected LinuxCNC source program: ${linuxCncSourceState.activeProgram}`);
}
if (!doc.querySelector('[data-linuxcnc-gcode-source="selected"]')?.textContent.includes("impeller-7bl-xyzac.ngc")) {
throw new Error("selected LinuxCNC G-code source did not render");
}
if (!doc.querySelector('[data-program-source]')?.textContent.includes("linuxcnc-vendored-5axis-gcode")) {
throw new Error("program source DOM did not show LinuxCNC vendored source");
}
win.webRtcp5AxisSimulation.dispatch({ type: "RUN_MACHINE_FILE_PROGRAM" });
const machineFileRunState = await waitForMachineFileExecution(win);
if (machineFileRunState.machineFileExecution?.summary?.machineFileExecutionReady !== true) {
throw new Error(`machine-file backed remap run did not complete: ${JSON.stringify(machineFileRunState.machineFileExecution?.summary)}`);
}
if (!machineFileRunState.machineFileExecution.resultText.includes("fiveaxis_file_reached_exit=1")) {
throw new Error("machine-file backed remap run did not reach exit");
}
if (!machineFileRunState.machineFileExecution.machineFilePlan?.selectedProgramFilename?.includes("impeller-7bl-xyzac.ngc")) {
throw new Error("machine-file backed remap run did not use selected LinuxCNC G-code source");
}
if (!doc.querySelector('[data-machine-file-execution="status"]')?.textContent.includes("ready")) {
throw new Error("machine-file execution status did not render");
}
if (machineFileRunState.fullExecutionBoundary?.machineFileBackedRemapReady !== true) {
throw new Error(`full execution boundary did not record remap readiness: ${JSON.stringify(machineFileRunState.fullExecutionBoundary)}`);
}
if (!doc.querySelector('[data-full-execution-boundary="status"]')?.textContent.includes("remap ready")) {
throw new Error("full execution boundary status did not render remap readiness");
}
const savedSession = await win.webRtcp5AxisSimulation.saveSession();
await wait(50);
if (savedSession.snapshot.format !== "web-rtcp-5axis-session-snapshot") {
throw new Error("saveSession did not write a five-axis session snapshot");
}
if (!doc.querySelector('[data-session-persistence="status"]')?.textContent.includes("saved")) {
throw new Error("session save status did not render");
}
if (doc.querySelector('[data-active-program-line]')?.textContent !== "Current line 2") {
throw new Error("loaded program did not render first LinuxCNC motion line");
}
if (doc.querySelector(".gcode-row.active")?.dataset.programLine !== "2") {
throw new Error("loaded program active row should be first LinuxCNC motion line");
}
win.webRtcp5AxisSimulation.dispatch({ type: "RUN" });
await wait(250);
if (win.webRtcp5AxisSimulation.getState().runState !== "running") {
throw new Error("RUN action did not update state after power on");
}
if (win.webRtcp5AxisSimulation.getState().programRuntimeFeedback?.sourceMode !== "linuxcnc-task-motion-hal-wasm") {
throw new Error("RUN did not advance with LinuxCNC task/HAL runtime feedback");
}
if (win.webRtcp5AxisSimulation.getState().feed.currentVelocity <= 0) {
throw new Error("RUN did not expose LinuxCNC task/HAL current velocity");
}
if (Number(doc.querySelector(".gcode-row.active")?.dataset.programLine || 0) < 2) {
throw new Error("RUN did not highlight a LinuxCNC task/HAL motion line");
}
const taskHalRunState = win.webRtcp5AxisSimulation.getState();
if (taskHalRunState.fullExecutionBoundary?.semanticBoundary !== "linuxcnc_task_motion_hal_wasm_simulation_runtime") {
throw new Error(`full execution boundary did not promote task/HAL simulation runtime: ${JSON.stringify(taskHalRunState.fullExecutionBoundary)}`);
}
if (taskHalRunState.fullExecutionBoundary?.fullLinuxCncProgramExecutionReady !== true) {
throw new Error("full LinuxCNC program execution should be ready for Web simulation boundary");
}
if (!doc.querySelector('[data-full-execution-boundary="status"]')?.textContent.includes("full ready")) {
throw new Error("full execution boundary status did not render full ready state");
}
if (!doc.querySelector('[data-task-hal-runtime="readiness"]')?.textContent.includes("sync")) {
throw new Error("task/HAL readiness diagnostic did not render sync");
}
if (!doc.querySelector('[data-task-hal-runtime="cycles"]')?.textContent.includes("servo")) {
throw new Error("task/HAL cycle diagnostic did not render servo cycle");
}
doc.querySelector('[data-action="PAUSE"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().runState !== "paused") {
throw new Error("PAUSE action did not update state");
}
doc.querySelector('[data-action="RUN"]').click();
await wait(50);
if (!win.webRtcp5AxisSimulation.getState().operatorMessage.includes("resume paused program")) {
throw new Error("RUN should be blocked while program is paused");
}
doc.querySelector('[data-action="RESUME"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().runState !== "running") {
throw new Error("RESUME action did not restore running state");
}
const tcpButton = doc.querySelector('[data-action="kins-tcp"]');
tcpButton.click();
await wait(50);
const rtcpState = win.webRtcp5AxisSimulation.getState();
if (rtcpState.rtcpState !== "on" || rtcpState.kinsType !== "tcp-xyzac") {
throw new Error(`TCP mode did not enable RTCP: ${rtcpState.rtcpState}/${rtcpState.kinsType}`);
}
if (!doc.querySelector('[data-rtcp-value="state"]')?.textContent.includes("RTCP on")) {
throw new Error("RTCP DRO strip did not render enabled state");
}
if (!doc.querySelector('[data-rtcp-diagnostic="frame"]')?.textContent.includes("on")) {
throw new Error("RTCP diagnostics did not render enabled frame");
}
if (canvas.dataset.threeRtcpState !== "on") {
throw new Error("Three.js preview did not consume RTCP enabled frame");
}
if (doc.querySelector('[data-rtcp-diagnostic="kinematics-ready"]')?.textContent !== "ready") {
throw new Error("RTCP diagnostics must show LinuxCNC kinematics ready");
}
if (doc.querySelector('[data-rtcp-diagnostic="execution-context"]')?.textContent !== "worker") {
throw new Error("RTCP diagnostics must show worker kinematics context");
}
if (!doc.querySelector('[data-linuxcnc-boundary="adapter"]')?.textContent.includes("linuxcnc-boundary-adapter")) {
throw new Error("missing LinuxCNC boundary adapter diagnostic");
}
if (!doc.querySelector('[data-linuxcnc-boundary="panel"]')?.textContent.includes("xyzac-trt-switchkins-pyvcp")) {
throw new Error("missing PyVCP panel schema diagnostic");
}
if (!doc.querySelector('[data-linuxcnc-boundary="profile-summary"]')?.textContent.includes("XYZAC / 5 joints / 10 tools")) {
throw new Error("missing LinuxCNC profile summary diagnostic");
}
if (!doc.querySelector('[data-linuxcnc-boundary="readiness"]')?.textContent.includes("ready")) {
throw new Error("LinuxCNC boundary readiness should show kinematics ready");
}
if (!doc.querySelector('[data-linuxcnc-boundary="interpreter"]')?.textContent.includes("linuxcnc_interpreter_wasm_canonical_events")) {
throw new Error("missing LinuxCNC interpreter boundary diagnostic");
}
if (doc.querySelector('[data-linuxcnc-boundary="interpreter-context"]')?.textContent !== "worker") {
throw new Error("LinuxCNC interpreter diagnostics must show worker context");
}
canvas = doc.querySelector("[data-five-axis-canvas]");
const tcpPoseBeforeStep = canvas.dataset.threeTcpPose;
win.webRtcp5AxisSimulation.dispatch({ type: "STEP" });
await win.webRtcp5AxisSimulation.refreshKinematicsFrame({ operatorMessage: "browser smoke refreshed worker frame" });
await wait(50);
if (win.webRtcp5AxisSimulation.getState().activeLine <= rtcpState.activeLine) {
throw new Error("STEP did not advance RTCP frame line");
}
canvas = doc.querySelector("[data-five-axis-canvas]");
if (canvas.dataset.threeTcpPose === tcpPoseBeforeStep) {
throw new Error("Three.js preview did not update TCP pose after STEP");
}
assertCanvasNonblank(canvas, "updated Three.js preview");
doc.querySelector('[data-action="STOP"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().machine.interpState !== "idle") {
throw new Error("STOP did not clear interpreter state");
}
doc.querySelector('[data-action="mode-manual"]').click();
await wait(50);
doc.querySelector('[data-action="mode-jog"]').click();
await wait(50);
const xBeforeJog = win.webRtcp5AxisSimulation.getState().axisPose.x;
doc.querySelector('[data-action="JOG_X_POS"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().axisPose.x <= xBeforeJog) {
throw new Error("JOG X+ did not move the axis");
}
await win.webRtcp5AxisSimulation.restoreSession();
await wait(50);
const restoredState = win.webRtcp5AxisSimulation.getState();
if (restoredState.axisPose.x !== xBeforeJog) {
throw new Error("restoreSession did not restore saved axis pose");
}
if (restoredState.programExecutionSourceMode !== "linuxcnc-interpreter-wasm") {
throw new Error("restoreSession did not restore LinuxCNC interpreter execution source");
}
if (!doc.querySelector('[data-session-persistence="status"]')?.textContent.includes("restored")) {
throw new Error("session restore status did not render");
}
if (win.webRtcp5AxisSimulation.getState().machine.allHomed !== true) {
doc.querySelector('[data-action="mode-manual"]').click();
await wait(50);
doc.querySelector('[data-action="HOME"]').click();
await wait(50);
}
doc.querySelector('[data-action="mode-mdi"]').click();
const mdiInput = doc.querySelector('[data-action="mdi-command"]');
if (!mdiInput) {
throw new Error("missing MDI command input");
}
mdiInput.value = "G90 X12.5 Y-4 Z1.25 F900";
doc.querySelector('[data-action="mdi-submit"]').click();
await wait(50);
let mdiState = win.webRtcp5AxisSimulation.getState();
if (mdiState.runState !== "mdi") {
throw new Error("MDI action did not update run state");
}
if (mdiState.axisPose.x !== 12.5 || mdiState.axisPose.y !== -4 || mdiState.axisPose.z !== 1.25) {
throw new Error(`MDI input did not move axes: ${JSON.stringify(mdiState.axisPose)}`);
}
if (!doc.querySelector(".mdi-history")?.textContent.includes("G90 X12.5")) {
throw new Error("MDI history did not render executed command");
}
doc.querySelector('[data-action="MDI_RUN"]').click();
await wait(50);
mdiState = win.webRtcp5AxisSimulation.getState();
if (mdiState.runState !== "mdi" || mdiState.machine.mdiCommand !== "G90 X12.5 Y-4 Z1.25 F900") {
throw new Error("bottom MDI button did not execute staged command");
}
doc.querySelector('[data-action="reset"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().runState !== "idle") {
throw new Error("RESET did not return to idle");
}
doc.querySelector('[data-action="feed-override-down"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().feed.feedOverride !== 90) {
throw new Error("feed override button did not update state");
}
if (doc.querySelector('[data-value="feed-override"]')?.textContent.trim() !== "90 %") {
throw new Error("feed override DOM did not update");
}
doc.querySelector('[data-action="rapid-override-up"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().feed.rapidOverride !== 110) {
throw new Error("rapid override button did not update state");
}
doc.querySelector('[data-action="spindle-override-up"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().spindle.override !== 110) {
throw new Error("spindle override button did not update state");
}
doc.querySelector('[data-action="toggle-flood"]').click();
doc.querySelector('[data-action="toggle-mist"]').click();
await wait(50);
const coolantState = win.webRtcp5AxisSimulation.getState().coolant;
if (coolantState.flood !== false || coolantState.mist !== true) {
throw new Error("coolant buttons did not update state");
}
doc.querySelector('[data-action="view-x"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().preview.selectedView !== "x") {
throw new Error("preview view button did not update state");
}
doc.querySelector('[data-action="clear-preview"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().preview.pathPoints !== 0) {
throw new Error("clear preview button did not update path points");
}
doc.querySelector('[data-action="RELOAD"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().preview.pathPoints !== 8) {
throw new Error("reload button did not restore path points");
}
doc.querySelector('[data-action="FULL"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().preview.fullscreen !== true) {
throw new Error("fullscreen button did not update state");
}
doc.querySelector('[data-action="mode-manual"]').click();
await wait(50);
doc.querySelector('[data-action="HOME"]').click();
await wait(50);
const homedState = win.webRtcp5AxisSimulation.getState();
if (homedState.axisPose.x !== 43) {
throw new Error("home button did not restore fixture origin");
}
doc.querySelector('[data-action="estop"]').click();
await wait(50);
if (win.webRtcp5AxisSimulation.getState().runState !== "estopped") {
throw new Error("E-STOP did not update run state");
}
result.textContent = "gmoccapy_shell_smoke=ok";
}
runSmoke().catch((error) => {
result.textContent = `gmoccapy_shell_smoke=fail ${error.message}`;
});
function assertCanvasNonblank(canvas, context) {
const gl = canvas.getContext("webgl2") || canvas.getContext("webgl");
if (!gl) {
throw new Error(`${context}: missing WebGL context`);
}
const pixel = new Uint8Array(4);
gl.readPixels(
Math.floor(canvas.width / 2),
Math.floor(canvas.height / 2),
1,
1,
gl.RGBA,
gl.UNSIGNED_BYTE,
pixel,
);
if (pixel[0] === 0 && pixel[1] === 0 && pixel[2] === 0 && pixel[3] === 0) {
throw new Error(`${context}: center pixel was blank`);
}
}
</script>
</body>
</html>