尽快推进:加强OPFS参数备份目录边界验证

结论:真实浏览器app smoke继续使用LinuxCNC rs274ngc_pre.cc save_parameters() 语义,验证OPFS下备份link失败非致命时主参数仍持久化且目录不被误删;未扩展smoke parser功能。
This commit is contained in:
cnc
2026-06-05 07:39:12 +08:00
parent bc80d74d1f
commit 6a2f63c894

View File

@@ -39,6 +39,26 @@ export async function runBrowserAppOpfsSections(context) {
const updatedParameterFile = new TextDecoder().decode(await appSimulator.fs.opfs.readFile("parameters/rs274ngc.var"));
expectIncludes(updatedParameterFile, "5161\t2.000000",
"app frame did not replace LinuxCNC parameter state after second parse");
const savedParameterBackup = new TextDecoder().decode(await appSimulator.fs.opfs.readFile("parameters/rs274ngc.var.bak"));
expectIncludes(savedParameterBackup, "5161\t1.000000",
"app frame did not persist LinuxCNC parameter backup into OPFS");
await appSimulator.fs.opfs.removeFile("parameters/rs274ngc.var.bak");
const backupDirectory = appSimulator.fs.opfs.resolvePath("parameters/rs274ngc.var.bak");
appSimulator.fs.module.FS.mkdir(backupDirectory);
await appSimulator.fs.opfs.persistDirectory("parameters/rs274ngc.var.bak");
parseAppFrameProgram(appFrame, "G21 G90\nG0 X3\nG28.1\nM30\n");
await waitFor(
() => appFrame.contentDocument?.querySelector("#axisX")?.value === "3.000",
"app frame did not parse third program for backup-directory coverage",
);
const directoryBackupParameterFile = new TextDecoder().decode(await appSimulator.fs.opfs.readFile("parameters/rs274ngc.var"));
expectIncludes(directoryBackupParameterFile, "5161\t3.000000",
"app frame did not save LinuxCNC parameter state when backup link failed");
await context.expectOpfsDirectoryStat(
appSimulator,
"parameters/rs274ngc.var.bak",
"app frame removed an existing OPFS backup directory after LinuxCNC non-fatal backup failure",
);
// LinuxCNC source basis: rs274ngc_pre.cc save_parameters()
// renames filename + ".new" over filename after a successful save.
await context.expectOpfsMissing(
@@ -46,9 +66,6 @@ export async function runBrowserAppOpfsSections(context) {
"parameters/rs274ngc.var.new",
"app frame did not clean up LinuxCNC temporary parameter file in OPFS",
);
const savedParameterBackup = new TextDecoder().decode(await appSimulator.fs.opfs.readFile("parameters/rs274ngc.var.bak"));
expectIncludes(savedParameterBackup, "5161\t1.000000",
"app frame did not persist LinuxCNC parameter backup into OPFS");
} finally {
await disposeAppFrame(appFrame);
}
@@ -59,7 +76,7 @@ export async function runBrowserAppOpfsSections(context) {
await waitForAppControls(restoredAppFrame, "restored app frame did not load CNC controls");
await waitFor(() => {
const restoredInput = restoredAppFrame.contentDocument?.querySelector("#programInput");
return restoredInput?.value === "G21 G90\nG0 X2\nG28.1\nM30\n";
return restoredInput?.value === "G21 G90\nG0 X3\nG28.1\nM30\n";
}, "app frame did not restore current program from OPFS after reload");
await waitForAppAlarm(
restoredAppFrame,
@@ -69,7 +86,7 @@ export async function runBrowserAppOpfsSections(context) {
await getAppFrameSimulator(restoredAppFrame, "restored app frame did not create OPFS simulator workspace");
parseAppFrameProgram(
restoredAppFrame,
"G21 G90\nF100\nO10 if [#5161 EQ 2]\nG1 X12\nO10 endif\nM30\n",
"G21 G90\nF100\nO10 if [#5161 EQ 3]\nG1 X13\nO10 endif\nM30\n",
);
await waitForAppAlarm(
restoredAppFrame,
@@ -77,7 +94,7 @@ export async function runBrowserAppOpfsSections(context) {
"restored app frame did not parse program with reloaded parameter state",
);
await waitFor(
() => restoredAppFrame.contentDocument?.querySelector("#axisX")?.value === "12.000",
() => restoredAppFrame.contentDocument?.querySelector("#axisX")?.value === "13.000",
"app frame did not reload LinuxCNC parameter state from OPFS after reload",
);
} finally {