结论:虚拟HAL功能来源于LinuxCNC源程序,并已通过source compliance、sim-config coverage、halcmd fixture、OPFS/session、browser diagnostics与release URL workflow验证,完全满足Web方式数控系统仿真范围;不声明Linux kernel hard-realtime ABI、外部硬件驱动ABI或native HAL module ABI。
1060 lines
40 KiB
HTML
1060 lines
40 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>LinuxCNC INI Browser Smoke</title>
|
|
</head>
|
|
<body>
|
|
<pre id="status">running</pre>
|
|
<div id="control-view"></div>
|
|
<script type="module">
|
|
import { createLinuxCncIniSdk } from "../../runtime/sdk/src/index.js";
|
|
import { renderMachineSessionControlView } from "../../runtime/ui/ini-panel/control-view-renderer.js";
|
|
import { loadTextFile, saveTextFile } from "../../runtime/opfs/file-service.js";
|
|
import {
|
|
gcodeProgramPath,
|
|
machineIniPath,
|
|
sessionSnapshotPath,
|
|
} from "../../runtime/opfs/path-model.js";
|
|
import {
|
|
createMachineSessionSnapshotPayload,
|
|
createVirtualHalSessionPayload,
|
|
loadMachineSessionSnapshot,
|
|
loadSessionSnapshot,
|
|
restoreVirtualHalStateFromSessionSnapshot,
|
|
saveMachineSessionSnapshot,
|
|
saveSessionSnapshot,
|
|
} from "../../runtime/opfs/snapshot-store.js";
|
|
import {
|
|
createVirtualHalState,
|
|
executeVirtualHalCommand,
|
|
} from "../../runtime/sdk/src/linuxcnc-hal.js";
|
|
import {
|
|
gcodeFilenameFromProgramPath,
|
|
loadGcodeProgram,
|
|
loadMachineTextFiles,
|
|
saveGcodeProgram,
|
|
saveMachineTextFiles,
|
|
} from "../../runtime/opfs/machine-file-store.js";
|
|
|
|
const status = document.getElementById("status");
|
|
|
|
function assertEqual(actual, expected, label) {
|
|
if (actual !== expected) {
|
|
throw new Error(`${label}: expected ${expected}, got ${actual}`);
|
|
}
|
|
}
|
|
|
|
async function assertRejects(label, operation, expectedPattern) {
|
|
try {
|
|
await operation();
|
|
} catch (error) {
|
|
if (!expectedPattern.test(error.message)) {
|
|
throw new Error(`${label}: unexpected error ${error.message}`);
|
|
}
|
|
return;
|
|
}
|
|
throw new Error(`${label}: expected rejection`);
|
|
}
|
|
|
|
function delay(ms) {
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
}
|
|
|
|
async function waitFor(predicate, label) {
|
|
const deadline = performance.now() + 8000;
|
|
while (performance.now() < deadline) {
|
|
const value = predicate();
|
|
if (value) {
|
|
return value;
|
|
}
|
|
await delay(50);
|
|
}
|
|
throw new Error(`Timed out waiting for ${label}`);
|
|
}
|
|
|
|
async function loadUiFrame() {
|
|
const frame = document.createElement("iframe");
|
|
frame.src = "../../runtime/ui/ini-panel/index.html";
|
|
document.body.appendChild(frame);
|
|
await new Promise((resolve, reject) => {
|
|
frame.addEventListener("load", resolve, { once: true });
|
|
frame.addEventListener("error", reject, { once: true });
|
|
});
|
|
return frame.contentDocument;
|
|
}
|
|
|
|
try {
|
|
const ini = await createLinuxCncIniSdk();
|
|
const wasmPath = "/work/browser-smoke.ini";
|
|
const iniText = `[EMC]
|
|
MACHINE = browser-smoke
|
|
|
|
[TRAJ]
|
|
LINEAR_UNITS = mm
|
|
COORDINATES = X Y Z
|
|
|
|
[KINS]
|
|
KINEMATICS = trivkins
|
|
JOINTS = 3
|
|
|
|
[RS274NGC]
|
|
PARAMETER_FILE = browser-linuxcnc.var
|
|
|
|
[EMCIO]
|
|
TOOL_TABLE = browser-tool.tbl
|
|
`;
|
|
|
|
ini.writeTextFile(wasmPath, iniText);
|
|
assertEqual(ini.getString(wasmPath, "EMC", "MACHINE"), "browser-smoke", "machine");
|
|
assertEqual(ini.getString(wasmPath, "TRAJ", "LINEAR_UNITS"), "mm", "units");
|
|
assertEqual(ini.getString(wasmPath, "KINS", "KINEMATICS"), "trivkins", "kinematics");
|
|
assertEqual(
|
|
ini.getString(wasmPath, "RS274NGC", "PARAMETER_FILE"),
|
|
"browser-linuxcnc.var",
|
|
"parameter file",
|
|
);
|
|
assertEqual(
|
|
ini.getString(wasmPath, "EMCIO", "TOOL_TABLE"),
|
|
"browser-tool.tbl",
|
|
"tool table",
|
|
);
|
|
assertEqual(ini.getString(wasmPath, "TRAJ", "MISSING"), null, "missing tag");
|
|
|
|
const fields = ini.getFields(wasmPath, {
|
|
machine: { section: "EMC", tag: "MACHINE" },
|
|
joints: { section: "KINS", tag: "JOINTS" },
|
|
parameterFile: { section: "RS274NGC", tag: "PARAMETER_FILE" },
|
|
toolTable: { section: "EMCIO", tag: "TOOL_TABLE" },
|
|
});
|
|
assertEqual(fields.machine, "browser-smoke", "field machine");
|
|
assertEqual(fields.joints, "3", "field joints");
|
|
assertEqual(fields.parameterFile, "browser-linuxcnc.var", "field parameter file");
|
|
assertEqual(fields.toolTable, "browser-tool.tbl", "field tool table");
|
|
|
|
const opfsPath = machineIniPath("browser-smoke");
|
|
await saveTextFile(opfsPath, iniText);
|
|
assertEqual(await loadTextFile(opfsPath), iniText, "opfs roundtrip");
|
|
|
|
const snapshotPayload = createMachineSessionSnapshotPayload("browser-smoke", {
|
|
gcodeFilename: "browser-smoke.ngc",
|
|
});
|
|
assertEqual(snapshotPayload.machineId, "browser-smoke", "snapshot machine");
|
|
assertEqual(snapshotPayload.files.ini, opfsPath, "snapshot payload INI");
|
|
assertEqual(
|
|
snapshotPayload.files.parameters,
|
|
"linuxcnc/machines/browser-smoke/linuxcnc.var",
|
|
"snapshot payload parameter file",
|
|
);
|
|
assertEqual(
|
|
snapshotPayload.files.toolTable,
|
|
"linuxcnc/machines/browser-smoke/tool.tbl",
|
|
"snapshot payload tool table",
|
|
);
|
|
assertEqual(
|
|
snapshotPayload.files.gcode,
|
|
"linuxcnc/gcode/browser-smoke.ngc",
|
|
"snapshot payload G-code",
|
|
);
|
|
const savedSnapshot = await saveSessionSnapshot(
|
|
"browser-session",
|
|
snapshotPayload,
|
|
{
|
|
createdAt: "2026-06-08T00:00:00.000Z",
|
|
metadata: { source: "browser-smoke" },
|
|
},
|
|
);
|
|
const loadedSnapshot = await loadSessionSnapshot("browser-session");
|
|
assertEqual(loadedSnapshot.format, "linuxcnc-wasm-session-snapshot", "snapshot format");
|
|
assertEqual(loadedSnapshot.version, 1, "snapshot version");
|
|
assertEqual(loadedSnapshot.sessionId, "browser-session", "snapshot session");
|
|
assertEqual(loadedSnapshot.createdAt, savedSnapshot.createdAt, "snapshot timestamp");
|
|
assertEqual(loadedSnapshot.payload.files.ini, opfsPath, "snapshot payload");
|
|
assertEqual(loadedSnapshot.payload.files.gcode, snapshotPayload.files.gcode, "snapshot G-code payload");
|
|
assertEqual(loadedSnapshot.metadata.source, "browser-smoke", "snapshot metadata");
|
|
const virtualHalState = executeVirtualHalCommand(
|
|
createVirtualHalState(),
|
|
"newsig x-pos HAL_FLOAT\nsetp axis.x.pos-cmd 4.5\nsets x-pos 3.25\nnet x-pos axis.x.pos-cmd joint.0.pos-fb\nloadrt trivkins\nloadusr halui\naddf motion-controller servo-thread\nstart servo-thread",
|
|
).state;
|
|
const virtualHalSnapshotPayload = createMachineSessionSnapshotPayload("browser-smoke", {
|
|
gcodeFilename: "browser-smoke.ngc",
|
|
virtualHal: createVirtualHalSessionPayload(virtualHalState),
|
|
});
|
|
assertEqual(
|
|
virtualHalSnapshotPayload.virtualHal.state.hal.signals["x-pos"].value,
|
|
3.25,
|
|
"browser virtual HAL signal snapshot",
|
|
);
|
|
const savedVirtualHalSnapshot = await saveSessionSnapshot(
|
|
"browser-virtual-hal-session",
|
|
virtualHalSnapshotPayload,
|
|
{
|
|
createdAt: "2026-06-08T00:00:00.000Z",
|
|
metadata: { source: "browser-virtual-hal-smoke" },
|
|
},
|
|
);
|
|
const restoredVirtualHalState = restoreVirtualHalStateFromSessionSnapshot(savedVirtualHalSnapshot);
|
|
assertEqual(
|
|
restoredVirtualHalState.hal.nets["x-pos"].includes("joint.0.pos-fb"),
|
|
true,
|
|
"browser virtual HAL restored net",
|
|
);
|
|
assertEqual(
|
|
restoredVirtualHalState.hal.loadedComponents.some(({ component }) => component === "halui"),
|
|
true,
|
|
"browser virtual HAL restored loadusr",
|
|
);
|
|
const customMachineSnapshotPayload = createMachineSessionSnapshotPayload("browser-smoke", {
|
|
parameterFilename: "browser-linuxcnc.var",
|
|
toolTableFilename: "browser-tool.tbl",
|
|
gcodeOpfsPath: "linuxcnc/gcode/browser-custom.ngc",
|
|
});
|
|
assertEqual(
|
|
customMachineSnapshotPayload.files.parameters,
|
|
"linuxcnc/machines/browser-smoke/browser-linuxcnc.var",
|
|
"custom snapshot parameter file",
|
|
);
|
|
assertEqual(
|
|
customMachineSnapshotPayload.files.toolTable,
|
|
"linuxcnc/machines/browser-smoke/browser-tool.tbl",
|
|
"custom snapshot tool table",
|
|
);
|
|
assertEqual(
|
|
customMachineSnapshotPayload.files.gcode,
|
|
"linuxcnc/gcode/browser-custom.ngc",
|
|
"custom snapshot G-code",
|
|
);
|
|
assertEqual(
|
|
sessionSnapshotPath("browser-session", "browser-custom-snapshot.json"),
|
|
"linuxcnc/sessions/browser-session/browser-custom-snapshot.json",
|
|
"snapshot custom path",
|
|
);
|
|
const customSnapshot = await saveSessionSnapshot(
|
|
"browser-session",
|
|
snapshotPayload,
|
|
{
|
|
filename: "browser-custom-snapshot.json",
|
|
createdAt: "2026-06-08T00:00:00.000Z",
|
|
metadata: { source: "browser-smoke-custom" },
|
|
},
|
|
);
|
|
const loadedCustomSnapshot = await loadSessionSnapshot(
|
|
"browser-session",
|
|
{ filename: "browser-custom-snapshot.json" },
|
|
);
|
|
assertEqual(
|
|
loadedCustomSnapshot.metadata.source,
|
|
customSnapshot.metadata.source,
|
|
"custom snapshot metadata",
|
|
);
|
|
const machineSessionSnapshot = await saveMachineSessionSnapshot(
|
|
"browser-machine-session",
|
|
"browser-smoke",
|
|
{
|
|
filename: "browser-machine-snapshot.json",
|
|
parameterFilename: "browser-linuxcnc.var",
|
|
toolTableFilename: "browser-tool.tbl",
|
|
gcodeFilename: "browser-smoke.ngc",
|
|
createdAt: "2026-06-08T00:00:00.000Z",
|
|
metadata: { source: "browser-machine-session" },
|
|
},
|
|
);
|
|
const loadedMachineSessionSnapshot = await loadSessionSnapshot(
|
|
"browser-machine-session",
|
|
{ filename: "browser-machine-snapshot.json" },
|
|
);
|
|
const loadedCheckedMachineSessionSnapshot = await loadMachineSessionSnapshot(
|
|
"browser-machine-session",
|
|
"browser-smoke",
|
|
{ filename: "browser-machine-snapshot.json" },
|
|
);
|
|
assertEqual(
|
|
machineSessionSnapshot.payload.files.parameters,
|
|
"linuxcnc/machines/browser-smoke/browser-linuxcnc.var",
|
|
"machine session snapshot parameter file",
|
|
);
|
|
assertEqual(
|
|
machineSessionSnapshot.payload.files.toolTable,
|
|
"linuxcnc/machines/browser-smoke/browser-tool.tbl",
|
|
"machine session snapshot tool table",
|
|
);
|
|
assertEqual(
|
|
loadedMachineSessionSnapshot.payload.files.gcode,
|
|
"linuxcnc/gcode/browser-smoke.ngc",
|
|
"machine session snapshot G-code",
|
|
);
|
|
assertEqual(
|
|
loadedMachineSessionSnapshot.metadata.source,
|
|
"browser-machine-session",
|
|
"machine session snapshot metadata",
|
|
);
|
|
assertEqual(
|
|
loadedCheckedMachineSessionSnapshot.payload.machineId,
|
|
"browser-smoke",
|
|
"checked machine session snapshot id",
|
|
);
|
|
await assertRejects(
|
|
"browser machine snapshot wrong machine",
|
|
() => loadMachineSessionSnapshot(
|
|
"browser-machine-session",
|
|
"other-browser-machine",
|
|
{ filename: "browser-machine-snapshot.json" },
|
|
),
|
|
/Machine session snapshot id mismatch/,
|
|
);
|
|
await assertRejects(
|
|
"browser snapshot invalid filename save",
|
|
() => saveSessionSnapshot("browser-session", {}, {
|
|
filename: "nested/snapshot.json",
|
|
}),
|
|
/Invalid session snapshot filename/,
|
|
);
|
|
await assertRejects(
|
|
"browser snapshot invalid filename load",
|
|
() => loadSessionSnapshot("browser-session", {
|
|
filename: "../snapshot.json",
|
|
}),
|
|
/Invalid session snapshot filename/,
|
|
);
|
|
await saveTextFile(
|
|
sessionSnapshotPath("browser-bad-format"),
|
|
JSON.stringify({
|
|
...loadedSnapshot,
|
|
format: "other-format",
|
|
sessionId: "browser-bad-format",
|
|
}),
|
|
);
|
|
await assertRejects(
|
|
"browser snapshot bad format",
|
|
() => loadSessionSnapshot("browser-bad-format"),
|
|
/Unsupported session snapshot format/,
|
|
);
|
|
await saveTextFile(
|
|
sessionSnapshotPath("browser-bad-version"),
|
|
JSON.stringify({
|
|
...loadedSnapshot,
|
|
version: 99,
|
|
sessionId: "browser-bad-version",
|
|
}),
|
|
);
|
|
await assertRejects(
|
|
"browser snapshot bad version",
|
|
() => loadSessionSnapshot("browser-bad-version"),
|
|
/Unsupported session snapshot version/,
|
|
);
|
|
await saveTextFile(
|
|
sessionSnapshotPath("browser-bad-session-id"),
|
|
JSON.stringify({
|
|
...loadedSnapshot,
|
|
sessionId: "other-browser-session",
|
|
}),
|
|
);
|
|
await assertRejects(
|
|
"browser snapshot id mismatch",
|
|
() => loadSessionSnapshot("browser-bad-session-id"),
|
|
/Session snapshot id mismatch/,
|
|
);
|
|
|
|
await saveMachineTextFiles("browser-smoke", {
|
|
ini: iniText,
|
|
toolTable: "T0 P0 ; no tool\n",
|
|
parameters: "5161 0.0\n",
|
|
});
|
|
const machineFiles = await loadMachineTextFiles("browser-smoke");
|
|
assertEqual(machineFiles.ini, iniText, "machine ini text");
|
|
assertEqual(machineFiles.toolTable, "T0 P0 ; no tool\n", "tool table text");
|
|
assertEqual(machineFiles.parameters, "5161 0.0\n", "parameter text");
|
|
assertEqual(
|
|
gcodeProgramPath("browser-custom.ngc"),
|
|
"linuxcnc/gcode/browser-custom.ngc",
|
|
"custom G-code path",
|
|
);
|
|
assertEqual(
|
|
gcodeFilenameFromProgramPath("linuxcnc/gcode/browser-custom.ngc"),
|
|
"browser-custom.ngc",
|
|
"custom G-code filename from OPFS path",
|
|
);
|
|
await assertRejects(
|
|
"browser G-code invalid program OPFS path",
|
|
() => Promise.resolve(gcodeFilenameFromProgramPath("linuxcnc/machines/browser-custom.ngc")),
|
|
/Invalid G-code program OPFS path/,
|
|
);
|
|
await saveGcodeProgram("browser-smoke.ngc", "G0 X0 Y0\nM2\n");
|
|
assertEqual(await loadGcodeProgram("browser-smoke.ngc"), "G0 X0 Y0\nM2\n", "gcode text");
|
|
await saveGcodeProgram("browser-custom.ngc", "G1 X1 F10\nM2\n");
|
|
assertEqual(await loadGcodeProgram("browser-custom.ngc"), "G1 X1 F10\nM2\n", "custom gcode text");
|
|
await assertRejects(
|
|
"browser G-code invalid filename save",
|
|
() => saveGcodeProgram("nested/browser.ngc", ""),
|
|
/Invalid G-code filename/,
|
|
);
|
|
await assertRejects(
|
|
"browser G-code invalid filename load",
|
|
() => loadGcodeProgram("../escape.ngc"),
|
|
/Invalid G-code filename/,
|
|
);
|
|
|
|
const uiDocument = await loadUiFrame();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("wasm-badge")?.textContent.includes("ready"),
|
|
"INI panel INI WASM readiness",
|
|
);
|
|
await waitFor(
|
|
() => uiDocument.getElementById("interp-badge")?.textContent.includes("ready"),
|
|
"INI panel interpreter WASM readiness",
|
|
);
|
|
await waitFor(
|
|
() => uiDocument.getElementById("opfs-badge")?.textContent.includes("ready"),
|
|
"INI panel OPFS readiness",
|
|
);
|
|
const uiApi = uiDocument.defaultView.linuxCncIniPanelApi;
|
|
if (
|
|
!uiApi?.getMachineSessionControlView ||
|
|
!uiApi?.getMachineSessionStateBundle ||
|
|
!uiApi?.getMachineSessionStateReport ||
|
|
!uiApi?.getMachineSessionStateReportExport ||
|
|
!uiApi?.getMachineSessionWorkflowStatus ||
|
|
!uiApi?.getMachineSessionPersistenceSummary ||
|
|
!uiApi?.getMachineSessionPersistenceDisplayViewModel ||
|
|
!uiApi?.getMachineSessionPersistenceRenderState ||
|
|
!uiApi?.renderMachineSessionControlView
|
|
) {
|
|
throw new Error("INI panel API namespace did not expose state getters");
|
|
}
|
|
|
|
uiDocument.getElementById("ini-editor").value = iniText;
|
|
uiDocument.getElementById("query").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Queried LinuxCNC INI fields"),
|
|
"INI field query",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-parameter-file").textContent,
|
|
"browser-linuxcnc.var",
|
|
"UI queried parameter file",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-tool-table").textContent,
|
|
"browser-tool.tbl",
|
|
"UI queried tool table",
|
|
);
|
|
|
|
uiDocument.getElementById("save-machine-files").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Saved machine text files"),
|
|
"machine file save",
|
|
);
|
|
uiDocument.getElementById("load-session").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Loaded machine session"),
|
|
"fallback machine session load",
|
|
);
|
|
uiDocument.getElementById("run-gcode").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Ran G-code"),
|
|
"fallback G-code run",
|
|
);
|
|
const fallbackRunLog = uiDocument.getElementById("log").textContent;
|
|
if (
|
|
!fallbackRunLog.includes("Program: linuxcnc/gcode/ui-session.ngc -> /work/ui-session.ngc") ||
|
|
!fallbackRunLog.includes("Program source: default") ||
|
|
!fallbackRunLog.includes("Snapshot: -") ||
|
|
!fallbackRunLog.includes("Workflow: -") ||
|
|
!fallbackRunLog.includes("Default G-code: -") ||
|
|
!fallbackRunLog.includes("canon_event=STRAIGHT_FEED")
|
|
) {
|
|
throw new Error(`UI fallback G-code run did not use default OPFS program path: ${fallbackRunLog}`);
|
|
}
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-source").textContent,
|
|
"default",
|
|
"UI fallback run source field",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-snapshot").textContent,
|
|
"-",
|
|
"UI fallback run snapshot field",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-workflow").textContent,
|
|
"-",
|
|
"UI fallback run workflow field",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-opfs-path").textContent,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI fallback run OPFS field",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-wasm-path").textContent,
|
|
"/work/ui-session.ngc",
|
|
"UI fallback run WASM field",
|
|
);
|
|
const fallbackRunSummary = uiDocument.defaultView.linuxCncIniPanelLastRunSummary;
|
|
assertEqual(fallbackRunSummary.runStatus, "ok", "UI fallback run summary status");
|
|
assertEqual(fallbackRunSummary.programSource, "default", "UI fallback run summary source");
|
|
assertEqual(fallbackRunSummary.snapshotLabel, null, "UI fallback run summary snapshot");
|
|
assertEqual(fallbackRunSummary.workflow, null, "UI fallback run summary workflow");
|
|
assertEqual(
|
|
fallbackRunSummary.programOpfsPath,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI fallback run summary OPFS path",
|
|
);
|
|
assertEqual(
|
|
fallbackRunSummary.programWasmPath,
|
|
"/work/ui-session.ngc",
|
|
"UI fallback run summary WASM path",
|
|
);
|
|
assertEqual(
|
|
fallbackRunSummary.iniWasmPath,
|
|
"/work/session-machine.ini",
|
|
"UI fallback run summary INI WASM path",
|
|
);
|
|
assertEqual(
|
|
fallbackRunSummary.canonicalEventCount,
|
|
2,
|
|
"UI fallback run summary canonical event count",
|
|
);
|
|
assertEqual(
|
|
fallbackRunSummary.motionSnapshotCount,
|
|
2,
|
|
"UI fallback run summary motion snapshot count",
|
|
);
|
|
uiDocument.getElementById("save-session-snapshot").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Saved machine session snapshot"),
|
|
"machine session snapshot save",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-session-snapshot").textContent,
|
|
"ui-machine-session/ui-machine-session.json",
|
|
"UI session snapshot path",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-session-ini").textContent,
|
|
"linuxcnc/machines/xyzab-tdr/machine.ini",
|
|
"UI snapshot INI OPFS path",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-session-gcode").textContent,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI snapshot G-code OPFS path",
|
|
);
|
|
const savedSnapshotLog = uiDocument.getElementById("log").textContent;
|
|
if (
|
|
!savedSnapshotLog.includes("Workflow: save-session-snapshot") ||
|
|
!savedSnapshotLog.includes("Default G-code: linuxcnc/gcode/ui-session.ngc")
|
|
) {
|
|
throw new Error(`UI saved snapshot log missing metadata summary: ${savedSnapshotLog}`);
|
|
}
|
|
const savedMachineSessionStateReport = uiApi.getMachineSessionStateReport();
|
|
assertEqual(
|
|
savedMachineSessionStateReport.session.snapshotLabel,
|
|
"ui-machine-session/ui-machine-session.json",
|
|
"UI saved machine session state report snapshot label",
|
|
);
|
|
assertEqual(
|
|
savedMachineSessionStateReport.session.gcode,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI saved machine session state report G-code path",
|
|
);
|
|
assertEqual(
|
|
savedMachineSessionStateReport.status.lastAction,
|
|
"save-session-snapshot",
|
|
"UI saved machine session state report last action",
|
|
);
|
|
const savedUiSnapshot = await loadMachineSessionSnapshot(
|
|
"ui-machine-session",
|
|
"xyzab-tdr",
|
|
{ filename: "ui-machine-session.json" },
|
|
);
|
|
assertEqual(savedUiSnapshot.metadata.source, "ini-panel", "UI snapshot metadata source");
|
|
assertEqual(
|
|
savedUiSnapshot.metadata.workflow,
|
|
"save-session-snapshot",
|
|
"UI snapshot metadata workflow",
|
|
);
|
|
assertEqual(
|
|
savedUiSnapshot.metadata.snapshotLabel,
|
|
"ui-machine-session/ui-machine-session.json",
|
|
"UI snapshot metadata label",
|
|
);
|
|
assertEqual(
|
|
savedUiSnapshot.metadata.defaultGcodeOpfsPath,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI snapshot metadata default G-code path",
|
|
);
|
|
uiDocument.getElementById("ini-editor").value = "";
|
|
uiDocument.getElementById("restore-session-snapshot").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Restored machine session snapshot"),
|
|
"machine session snapshot restore",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-session-snapshot").textContent,
|
|
"ui-machine-session/ui-machine-session.json",
|
|
"UI restored session snapshot path",
|
|
);
|
|
const restoredSnapshotLog = uiDocument.getElementById("log").textContent;
|
|
if (
|
|
!restoredSnapshotLog.includes("Workflow: save-session-snapshot") ||
|
|
!restoredSnapshotLog.includes("Default G-code: linuxcnc/gcode/ui-session.ngc")
|
|
) {
|
|
throw new Error(`UI restored snapshot log missing metadata summary: ${restoredSnapshotLog}`);
|
|
}
|
|
if (!uiDocument.getElementById("ini-editor").value.includes("MACHINE = browser-smoke")) {
|
|
throw new Error("UI restored session snapshot did not reload INI text");
|
|
}
|
|
uiDocument.getElementById("restore-load-session").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Restored and loaded machine session"),
|
|
"restore and load machine session",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-session-ini").textContent,
|
|
"/work/session-machine.ini",
|
|
"UI session INI path",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-session-parameters").textContent,
|
|
"/work/session-linuxcnc.var",
|
|
"UI session parameter path",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-session-tool-table").textContent,
|
|
"/work/session-tool.tbl",
|
|
"UI session tool table path",
|
|
);
|
|
const uiLog = uiDocument.getElementById("log").textContent;
|
|
if (!uiLog.includes("restore_parameters=0") || !uiLog.includes("tooldata_load=0")) {
|
|
throw new Error(`UI restore/load session log missing LinuxCNC load result: ${uiLog}`);
|
|
}
|
|
if (
|
|
!uiLog.includes("Snapshot: ui-machine-session/ui-machine-session.json") ||
|
|
!uiLog.includes("Workflow: save-session-snapshot") ||
|
|
!uiLog.includes("Default G-code: linuxcnc/gcode/ui-session.ngc") ||
|
|
!uiLog.includes(
|
|
"Parameter file: linuxcnc/machines/xyzab-tdr/linuxcnc.var -> /work/session-linuxcnc.var",
|
|
) ||
|
|
!uiLog.includes(
|
|
"Tool table file: linuxcnc/machines/xyzab-tdr/tool.tbl -> /work/session-tool.tbl",
|
|
)
|
|
) {
|
|
throw new Error(`UI restore/load session log missing OPFS default file mapping: ${uiLog}`);
|
|
}
|
|
const restoredLoadedMachineSessionStateReport = uiApi.getMachineSessionStateReport();
|
|
assertEqual(
|
|
restoredLoadedMachineSessionStateReport.session.snapshotLabel,
|
|
"ui-machine-session/ui-machine-session.json",
|
|
"UI restored loaded machine session state report snapshot label",
|
|
);
|
|
assertEqual(
|
|
restoredLoadedMachineSessionStateReport.loaded.iniWasmPath,
|
|
"/work/session-machine.ini",
|
|
"UI restored loaded machine session state report loaded INI WASM path",
|
|
);
|
|
assertEqual(
|
|
restoredLoadedMachineSessionStateReport.loaded.parameterWasmPath,
|
|
"/work/session-linuxcnc.var",
|
|
"UI restored loaded machine session state report loaded parameter WASM path",
|
|
);
|
|
assertEqual(
|
|
restoredLoadedMachineSessionStateReport.status.lastAction,
|
|
"restore-load-session",
|
|
"UI restored loaded machine session state report last action",
|
|
);
|
|
uiDocument.getElementById("run-gcode").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Ran G-code"),
|
|
"G-code run",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-session-gcode").textContent,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI session snapshot G-code path",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-status").textContent,
|
|
"ok",
|
|
"UI G-code run status",
|
|
);
|
|
const runLog = uiDocument.getElementById("log").textContent;
|
|
if (
|
|
!runLog.includes("Program: linuxcnc/gcode/ui-session.ngc -> /work/ui-session.ngc") ||
|
|
!runLog.includes("Program source: snapshot") ||
|
|
!runLog.includes("Snapshot: ui-machine-session/ui-machine-session.json") ||
|
|
!runLog.includes("Workflow: save-session-snapshot") ||
|
|
!runLog.includes("Default G-code: linuxcnc/gcode/ui-session.ngc")
|
|
) {
|
|
throw new Error(`UI G-code run missing snapshot session context: ${runLog}`);
|
|
}
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-source").textContent,
|
|
"snapshot",
|
|
"UI snapshot run source field",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-snapshot").textContent,
|
|
"ui-machine-session/ui-machine-session.json",
|
|
"UI snapshot run snapshot field",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-workflow").textContent,
|
|
"save-session-snapshot",
|
|
"UI snapshot run workflow field",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-opfs-path").textContent,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI snapshot run OPFS field",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-run-wasm-path").textContent,
|
|
"/work/ui-session.ngc",
|
|
"UI snapshot run WASM field",
|
|
);
|
|
const snapshotRunSummary = uiDocument.defaultView.linuxCncIniPanelLastRunSummary;
|
|
assertEqual(snapshotRunSummary.runStatus, "ok", "UI snapshot run summary status");
|
|
assertEqual(snapshotRunSummary.programSource, "snapshot", "UI snapshot run summary source");
|
|
assertEqual(
|
|
snapshotRunSummary.snapshotLabel,
|
|
"ui-machine-session/ui-machine-session.json",
|
|
"UI snapshot run summary snapshot",
|
|
);
|
|
assertEqual(
|
|
snapshotRunSummary.workflow,
|
|
"save-session-snapshot",
|
|
"UI snapshot run summary workflow",
|
|
);
|
|
assertEqual(
|
|
snapshotRunSummary.programOpfsPath,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI snapshot run summary OPFS path",
|
|
);
|
|
assertEqual(
|
|
snapshotRunSummary.programWasmPath,
|
|
"/work/ui-session.ngc",
|
|
"UI snapshot run summary WASM path",
|
|
);
|
|
assertEqual(
|
|
snapshotRunSummary.iniWasmPath,
|
|
"/work/session-machine.ini",
|
|
"UI snapshot run summary INI WASM path",
|
|
);
|
|
assertEqual(
|
|
snapshotRunSummary.canonicalEventCount,
|
|
2,
|
|
"UI snapshot run summary canonical event count",
|
|
);
|
|
assertEqual(
|
|
snapshotRunSummary.motionSnapshotCount,
|
|
2,
|
|
"UI snapshot run summary motion snapshot count",
|
|
);
|
|
const machineSessionStateReport = uiApi.getMachineSessionStateReport();
|
|
assertEqual(
|
|
machineSessionStateReport.status.lastAction,
|
|
"run-gcode",
|
|
"UI machine session state report last action",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReport.program.opfsPath,
|
|
"linuxcnc/gcode/ui-session.ngc",
|
|
"UI machine session state report selected program OPFS path",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReport.loaded.iniWasmPath,
|
|
"/work/session-machine.ini",
|
|
"UI machine session state report loaded INI WASM path",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReport.program.source,
|
|
"snapshot",
|
|
"UI machine session state report run source",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReport.session.workflow,
|
|
"save-session-snapshot",
|
|
"UI machine session state report workflow",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReport.status.error,
|
|
null,
|
|
"UI machine session state report error",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReport.run.status,
|
|
"ok",
|
|
"UI machine session state report run status",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReport.run.canonicalEventCount,
|
|
2,
|
|
"UI machine session state report canonical event count",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReport.run.motionSnapshotCount,
|
|
2,
|
|
"UI machine session state report motion snapshot count",
|
|
);
|
|
const machineSessionStateReportExport = uiApi.getMachineSessionStateReportExport();
|
|
assertEqual(
|
|
machineSessionStateReportExport.filename,
|
|
"machine-session-state-report.json",
|
|
"UI machine session state report export filename",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReportExport.mediaType,
|
|
"application/json",
|
|
"UI machine session state report export media type",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateReportExport.text.endsWith("\n"),
|
|
true,
|
|
"UI machine session state report export newline",
|
|
);
|
|
assertEqual(
|
|
JSON.parse(machineSessionStateReportExport.text).run.canonicalEventCount,
|
|
2,
|
|
"UI machine session state report export canonical event count",
|
|
);
|
|
assertEqual(
|
|
JSON.parse(machineSessionStateReportExport.text).program.source,
|
|
"snapshot",
|
|
"UI machine session state report export program source",
|
|
);
|
|
const machineSessionWorkflowStatus = uiApi.getMachineSessionWorkflowStatus();
|
|
assertEqual(
|
|
machineSessionWorkflowStatus.lastAction,
|
|
"run-gcode",
|
|
"UI machine session workflow status last action",
|
|
);
|
|
assertEqual(
|
|
machineSessionWorkflowStatus.error,
|
|
null,
|
|
"UI machine session workflow status error",
|
|
);
|
|
assertEqual(
|
|
machineSessionWorkflowStatus.readiness.opfs,
|
|
"OPFS: ready",
|
|
"UI machine session workflow status OPFS readiness",
|
|
);
|
|
assertEqual(
|
|
machineSessionWorkflowStatus.session.workflow,
|
|
"save-session-snapshot",
|
|
"UI machine session workflow status session workflow",
|
|
);
|
|
assertEqual(
|
|
machineSessionWorkflowStatus.run.status,
|
|
"ok",
|
|
"UI machine session workflow status run status",
|
|
);
|
|
assertEqual(
|
|
machineSessionWorkflowStatus.run.canonicalEventCount,
|
|
2,
|
|
"UI machine session workflow status canonical event count",
|
|
);
|
|
const machineSessionPersistenceSummary = uiApi.getMachineSessionPersistenceSummary();
|
|
assertEqual(
|
|
machineSessionPersistenceSummary.apiName,
|
|
"machine-session-persistence-summary",
|
|
"UI machine session persistence summary API name",
|
|
);
|
|
assertEqual(
|
|
machineSessionPersistenceSummary.ready,
|
|
true,
|
|
"UI machine session persistence summary readiness",
|
|
);
|
|
assertEqual(
|
|
machineSessionPersistenceSummary.rows.find((row) => row.id === "machine-files")?.value,
|
|
"ini, parameters, tool-table, g-code",
|
|
"UI machine session persistence summary machine files",
|
|
);
|
|
assertEqual(
|
|
machineSessionPersistenceSummary.rows.find((row) => row.id === "session-load")?.value,
|
|
"loaded: /work/session-machine.ini",
|
|
"UI machine session persistence summary session load",
|
|
);
|
|
const machineSessionPersistenceDisplay = uiApi.getMachineSessionPersistenceDisplayViewModel();
|
|
assertEqual(
|
|
machineSessionPersistenceDisplay.statusText,
|
|
"Ready",
|
|
"UI machine session persistence display status",
|
|
);
|
|
const machineSessionPersistenceRenderState = uiApi.getMachineSessionPersistenceRenderState();
|
|
assertEqual(
|
|
machineSessionPersistenceRenderState.statusLine,
|
|
"Ready: No missing persistence requirements",
|
|
"UI machine session persistence render-state status",
|
|
);
|
|
assertEqual(
|
|
machineSessionPersistenceRenderState.dataset.persistenceScope,
|
|
"opfs-session",
|
|
"UI machine session persistence render-state scope",
|
|
);
|
|
const machineSessionStateBundle = uiApi.getMachineSessionStateBundle();
|
|
assertEqual(
|
|
machineSessionStateBundle.report.status.lastAction,
|
|
machineSessionStateReport.status.lastAction,
|
|
"UI machine session state bundle report last action",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateBundle.export.text,
|
|
machineSessionStateReportExport.text,
|
|
"UI machine session state bundle export text",
|
|
);
|
|
assertEqual(
|
|
machineSessionStateBundle.workflowStatus.run.canonicalEventCount,
|
|
machineSessionWorkflowStatus.run.canonicalEventCount,
|
|
"UI machine session state bundle workflow status canonical event count",
|
|
);
|
|
assertEqual(
|
|
uiDocument.defaultView.getMachineSessionStateBundle().workflowStatus.lastAction,
|
|
machineSessionStateBundle.workflowStatus.lastAction,
|
|
"UI legacy machine session state bundle getter matches API namespace",
|
|
);
|
|
const machineSessionControlView = uiApi.getMachineSessionControlView();
|
|
const renderedControlView = renderMachineSessionControlView(
|
|
document.getElementById("control-view"),
|
|
machineSessionControlView,
|
|
);
|
|
assertEqual(
|
|
machineSessionControlView.status.runStatus,
|
|
"ok",
|
|
"UI machine session control view run status",
|
|
);
|
|
assertEqual(
|
|
machineSessionControlView.sections[0].id,
|
|
"readiness",
|
|
"UI machine session control view readiness section",
|
|
);
|
|
assertEqual(
|
|
machineSessionControlView.sections[1].rows[1].value,
|
|
"save-session-snapshot",
|
|
"UI machine session control view session workflow row",
|
|
);
|
|
assertEqual(
|
|
machineSessionControlView.sections[2].rows[1].value,
|
|
2,
|
|
"UI machine session control view canonical event row",
|
|
);
|
|
assertEqual(
|
|
renderedControlView.statusNode.textContent,
|
|
"run-gcode | ok | -",
|
|
"UI machine session control view DOM status",
|
|
);
|
|
assertEqual(
|
|
renderedControlView.sectionsNode.querySelectorAll("section").length,
|
|
3,
|
|
"UI machine session control view DOM section count",
|
|
);
|
|
assertEqual(
|
|
renderedControlView.sectionsNode.querySelector('section[data-section-id=\"run\"] dd:nth-of-type(2)').textContent,
|
|
"2",
|
|
"UI machine session control view DOM canonical event row",
|
|
);
|
|
const uiRenderedControlView = uiApi.renderMachineSessionControlView(
|
|
uiDocument.getElementById("machine-session-control-view"),
|
|
);
|
|
assertEqual(
|
|
uiRenderedControlView.statusNode.textContent,
|
|
"run-gcode | ok | -",
|
|
"UI machine session built-in control view DOM status",
|
|
);
|
|
assertEqual(
|
|
uiRenderedControlView.sectionsNode.querySelector('section[data-section-id=\"run\"] dd:nth-of-type(2)').textContent,
|
|
"2",
|
|
"UI machine session built-in control view canonical event row",
|
|
);
|
|
assertEqual(
|
|
uiDocument.defaultView.getMachineSessionControlView().status.lastAction,
|
|
machineSessionControlView.status.lastAction,
|
|
"UI legacy machine session control view getter matches API namespace",
|
|
);
|
|
assertEqual(
|
|
uiDocument.defaultView.getMachineSessionStateReport().status.lastAction,
|
|
machineSessionStateReport.status.lastAction,
|
|
"UI legacy machine session state report getter matches API namespace",
|
|
);
|
|
assertEqual(
|
|
uiDocument.defaultView.getMachineSessionStateReportExport().text,
|
|
machineSessionStateReportExport.text,
|
|
"UI legacy machine session state report export getter matches API namespace",
|
|
);
|
|
if (
|
|
!runLog.includes("canon_event=STRAIGHT_TRAVERSE") ||
|
|
!runLog.includes("canon_event=STRAIGHT_FEED")
|
|
) {
|
|
throw new Error(`UI G-code run missing LinuxCNC canonical events: ${runLog}`);
|
|
}
|
|
const eventText = uiDocument.getElementById("canon-events").textContent;
|
|
if (
|
|
!eventText.includes("canon_event=STRAIGHT_TRAVERSE") ||
|
|
!eventText.includes("canon_event=STRAIGHT_FEED")
|
|
) {
|
|
throw new Error(`UI canonical event panel missing LinuxCNC events: ${eventText}`);
|
|
}
|
|
await waitFor(
|
|
() => uiDocument.getElementById("run-motion")?.textContent.includes("STRAIGHT_FEED"),
|
|
"G-code run motion playback",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("run-progress-label").textContent,
|
|
"100%",
|
|
"UI G-code run progress",
|
|
);
|
|
assertEqual(uiDocument.getElementById("axis-x").textContent, "3.000", "UI G-code X axis");
|
|
assertEqual(uiDocument.getElementById("axis-y").textContent, "4.000", "UI G-code Y axis");
|
|
assertEqual(uiDocument.getElementById("axis-z").textContent, "0.000", "UI G-code Z axis");
|
|
assertEqual(uiDocument.getElementById("run-line").textContent, "line 2", "UI G-code line");
|
|
assertEqual(
|
|
uiDocument.getElementById("run-statement").textContent,
|
|
"G1 X3.0 Y4.0 F120.0",
|
|
"UI G-code statement",
|
|
);
|
|
const eventFilter = uiDocument.getElementById("event-filter");
|
|
eventFilter.value = "STRAIGHT_FEED";
|
|
eventFilter.dispatchEvent(new Event("input", { bubbles: true }));
|
|
const filteredEventText = uiDocument.getElementById("canon-events").textContent;
|
|
if (
|
|
filteredEventText.includes("canon_event=STRAIGHT_TRAVERSE") ||
|
|
!filteredEventText.includes("canon_event=STRAIGHT_FEED")
|
|
) {
|
|
throw new Error(`UI canonical event filter did not preserve raw LinuxCNC lines: ${filteredEventText}`);
|
|
}
|
|
assertEqual(
|
|
uiDocument.getElementById("event-count").textContent,
|
|
"1 / 4",
|
|
"UI canonical event count",
|
|
);
|
|
|
|
uiDocument.getElementById("run-fiveaxis-remap").click();
|
|
await waitFor(
|
|
() => uiDocument.getElementById("log")?.textContent.includes("Ran LinuxCNC 5-axis"),
|
|
"5-axis remap run",
|
|
);
|
|
assertEqual(
|
|
uiDocument.getElementById("field-fiveaxis-remap").textContent,
|
|
"ok",
|
|
"UI 5-axis remap status",
|
|
);
|
|
const remapLog = uiDocument.getElementById("log").textContent;
|
|
if (
|
|
!remapLog.includes("fiveaxis_ini_open=1") ||
|
|
!remapLog.includes("fiveaxis_tool_table_load=0") ||
|
|
!remapLog.includes("fiveaxis_file_read_count=4558") ||
|
|
!remapLog.includes("fiveaxis_file_finish_count=2") ||
|
|
!remapLog.includes("fiveaxis_hal_switchkins: rc=0 found=1 value=0") ||
|
|
!remapLog.includes("fiveaxis_linuxcnc_remap_file_execute=1")
|
|
) {
|
|
throw new Error(`UI 5-axis remap run missing LinuxCNC result: ${remapLog}`);
|
|
}
|
|
|
|
status.textContent = "browser_ini_opfs_smoke=ok";
|
|
} catch (error) {
|
|
status.textContent = `browser_ini_opfs_smoke=fail ${error.stack || error.message}`;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|