结论:浏览器 interpreter smoke 和 INI panel UI 已接入 vendored LinuxCNC 五轴 switchkins remap 执行路径,只复制 LinuxCNC sample machine 文件到 WASM FS 并调用 SDK C ABI;host 聚合 smoke 通过,未新增 JavaScript M428/M429/M430 或运动学语义。
390 lines
14 KiB
HTML
390 lines
14 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>
|
|
<script type="module">
|
|
import { createLinuxCncIniSdk } from "../../runtime/sdk/src/index.js";
|
|
import { loadTextFile, saveTextFile } from "../../runtime/opfs/file-service.js";
|
|
import {
|
|
gcodeProgramPath,
|
|
machineIniPath,
|
|
sessionSnapshotPath,
|
|
} from "../../runtime/opfs/path-model.js";
|
|
import {
|
|
loadSessionSnapshot,
|
|
saveSessionSnapshot,
|
|
} from "../../runtime/opfs/snapshot-store.js";
|
|
import {
|
|
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 = { files: { ini: opfsPath } };
|
|
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.metadata.source, "browser-smoke", "snapshot metadata");
|
|
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",
|
|
);
|
|
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",
|
|
);
|
|
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",
|
|
);
|
|
|
|
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"),
|
|
"machine session load",
|
|
);
|
|
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 session log missing LinuxCNC load result: ${uiLog}`);
|
|
}
|
|
if (
|
|
!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 session log missing OPFS default file mapping: ${uiLog}`);
|
|
}
|
|
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,
|
|
"/work/ui-session.ngc",
|
|
"UI session 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("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}`);
|
|
}
|
|
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_file_read_count=620") ||
|
|
!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>
|