结论:已新增 Chromium headless 浏览器 smoke,验证 INI WASM SDK 可在真实浏览器运行并完成 OPFS 文本文件往返,继续保持 OPFS 在 host-side、LinuxCNC INI 解析来自 vendored inifile.cc。
60 lines
1.8 KiB
HTML
60 lines
1.8 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";
|
|
|
|
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 = "linuxcnc/browser-smoke.ini";
|
|
await saveTextFile(opfsPath, iniText);
|
|
assertEqual(await loadTextFile(opfsPath), iniText, "opfs roundtrip");
|
|
|
|
status.textContent = "browser_ini_opfs_smoke=ok";
|
|
} catch (error) {
|
|
status.textContent = `browser_ini_opfs_smoke=fail ${error.stack || error.message}`;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|