按建议,继续完成后续工作
结论:已新增 OPFS machine file store,支持 INI、tool table、parameter file 和 G-code 的纯文本保存/读取,并在 Node mock 与 Chromium smoke 中验证往返,不引入 CNC 文件格式语义。
This commit is contained in:
@@ -14,6 +14,12 @@
|
||||
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");
|
||||
|
||||
@@ -72,6 +78,18 @@ JOINTS = 3
|
||||
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}`;
|
||||
|
||||
@@ -21,6 +21,13 @@ import {
|
||||
saveSessionSnapshot,
|
||||
validateSessionSnapshot,
|
||||
} from "../../../runtime/opfs/snapshot-store.js";
|
||||
import {
|
||||
loadGcodeProgram,
|
||||
loadMachineTextFiles,
|
||||
machineFilePaths,
|
||||
saveGcodeProgram,
|
||||
saveMachineTextFiles,
|
||||
} from "../../../runtime/opfs/machine-file-store.js";
|
||||
|
||||
class MockFileHandle {
|
||||
constructor(name) {
|
||||
@@ -91,6 +98,7 @@ assert.deepEqual(defaultMachinePaths("xyzab-tdr"), {
|
||||
toolTable: "linuxcnc/machines/xyzab-tdr/tool.tbl",
|
||||
parameters: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
|
||||
});
|
||||
assert.deepEqual(machineFilePaths("xyzab-tdr"), defaultMachinePaths("xyzab-tdr"));
|
||||
|
||||
const snapshotPayload = {
|
||||
files: {
|
||||
@@ -129,6 +137,22 @@ await saveSessionSnapshot("session-1", snapshotPayload, {
|
||||
});
|
||||
assert.deepEqual(await loadSessionSnapshot("session-1", { storage }), snapshot);
|
||||
|
||||
await saveMachineTextFiles("xyzab-tdr", {
|
||||
ini: "[EMC]\nMACHINE = xyzab-tdr\n",
|
||||
toolTable: "T0 P0 ; no tool\nT2 P2 Z1.25 D0.25\n",
|
||||
parameters: "5161 0.0\n5162 0.0\n",
|
||||
}, { storage });
|
||||
assert.deepEqual(await loadMachineTextFiles("xyzab-tdr", { storage }), {
|
||||
ini: "[EMC]\nMACHINE = xyzab-tdr\n",
|
||||
toolTable: "T0 P0 ; no tool\nT2 P2 Z1.25 D0.25\n",
|
||||
parameters: "5161 0.0\n5162 0.0\n",
|
||||
});
|
||||
assert.equal(
|
||||
await saveGcodeProgram("fixture.ngc", "G0 X0 Y0\nM2\n", { storage }),
|
||||
"linuxcnc/gcode/fixture.ngc",
|
||||
);
|
||||
assert.equal(await loadGcodeProgram("fixture.ngc", { storage }), "G0 X0 Y0\nM2\n");
|
||||
|
||||
await assert.rejects(
|
||||
() => loadTextFile("linuxcnc/machines/missing.ini", storage),
|
||||
/missing file/,
|
||||
@@ -141,6 +165,10 @@ assert.throws(
|
||||
() => machineIniPath("../escape"),
|
||||
/Invalid machine id/,
|
||||
);
|
||||
await assert.rejects(
|
||||
() => saveMachineTextFiles("xyzab-tdr", null, { storage }),
|
||||
/machine files must be a plain object/,
|
||||
);
|
||||
await saveTextFile(sessionSnapshotPath("bad-json"), "{", storage);
|
||||
await assert.rejects(
|
||||
() => loadSessionSnapshot("bad-json", { storage }),
|
||||
|
||||
Reference in New Issue
Block a user