Files
cnc_wams/wasm-port/tests/browser/ini_panel_smoke.html
wangdequan 72215f8400 按建议,继续完成后续工作
结论:已将 session snapshot store 纳入 Chromium 浏览器 smoke,验证真实浏览器 OPFS 中的 INI 文本和通用 session snapshot 均可往返保存读取。
2026-06-08 03:31:28 +08:00

82 lines
2.9 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/linuxcnc-ini.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";
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");
status.textContent = "browser_ini_opfs_smoke=ok";
} catch (error) {
status.textContent = `browser_ini_opfs_smoke=fail ${error.stack || error.message}`;
}
</script>
</body>
</html>