结论:解释器 WASM、SDK 统一入口、浏览器解释器 smoke 与兼容性文档已闭环,native 和 host/WASM/browser 验证全部通过。
100 lines
3.7 KiB
HTML
100 lines
3.7 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 { machineIniPath } 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}`);
|
|
}
|
|
}
|
|
|
|
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
|
|
`;
|
|
|
|
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, "TRAJ", "MISSING"), null, "missing tag");
|
|
|
|
const fields = ini.getFields(wasmPath, {
|
|
machine: { section: "EMC", tag: "MACHINE" },
|
|
joints: { section: "KINS", tag: "JOINTS" },
|
|
});
|
|
assertEqual(fields.machine, "browser-smoke", "field machine");
|
|
assertEqual(fields.joints, "3", "field joints");
|
|
|
|
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");
|
|
|
|
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");
|
|
await saveGcodeProgram("browser-smoke.ngc", "G0 X0 Y0\nM2\n");
|
|
assertEqual(await loadGcodeProgram("browser-smoke.ngc"), "G0 X0 Y0\nM2\n", "gcode text");
|
|
|
|
status.textContent = "browser_ini_opfs_smoke=ok";
|
|
} catch (error) {
|
|
status.textContent = `browser_ini_opfs_smoke=fail ${error.stack || error.message}`;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|