Guard OPFS path helper staging

This commit is contained in:
2026-06-13 18:10:10 +08:00
parent c699c7769d
commit 0b09c3c069
2 changed files with 83 additions and 6 deletions

View File

@@ -119,6 +119,18 @@ function assertPreviewCacheStoragePath(cacheKey, path, filename = "preview.json"
);
}
function assertMachineFileStoragePaths(machineId, paths) {
assert.deepEqual(
paths,
{
ini: `linuxcnc/machines/${machineId}/machine.ini`,
toolTable: `linuxcnc/machines/${machineId}/tool.tbl`,
parameters: `linuxcnc/machines/${machineId}/linuxcnc.var`,
},
`${machineId} machine file OPFS path drift`,
);
}
assert.equal(await getOpfsRoot(storage), root);
assert.equal(normalizeOpfsPath("linuxcnc/machines/xyzab.ini"), "linuxcnc/machines/xyzab.ini");
@@ -145,12 +157,8 @@ assertSessionSnapshotStoragePath(
sessionSnapshotPath("session-1", "custom-snapshot.json"),
"custom-snapshot.json",
);
assert.deepEqual(defaultMachinePaths("xyzab-tdr"), {
ini: "linuxcnc/machines/xyzab-tdr/machine.ini",
toolTable: "linuxcnc/machines/xyzab-tdr/tool.tbl",
parameters: "linuxcnc/machines/xyzab-tdr/linuxcnc.var",
});
assert.deepEqual(machineFilePaths("xyzab-tdr"), defaultMachinePaths("xyzab-tdr"));
assertMachineFileStoragePaths("xyzab-tdr", defaultMachinePaths("xyzab-tdr"));
assertMachineFileStoragePaths("xyzab-tdr", machineFilePaths("xyzab-tdr"));
const snapshotPayload = {
files: {
@@ -653,6 +661,10 @@ assert.throws(
() => sessionSnapshotPath("session-1", "nested/snapshot.json"),
/Invalid session snapshot filename/,
);
assert.throws(
() => previewCachePath("fixture", "nested/preview.json"),
/Invalid preview cache filename/,
);
assert.throws(
() => gcodeProgramPath("../escape.ngc"),
/Invalid G-code filename/,