Guard restore-parameter negative staging

This commit is contained in:
2026-06-13 15:54:56 +08:00
parent 24a8f92fb0
commit bfb5655f28
3 changed files with 116 additions and 10 deletions

View File

@@ -4446,6 +4446,19 @@
return { disabledIniPath, iniPath, parameterPath, programPath };
}
function generatedParameterPath(wasmPath, expectedWasmPath) {
if (wasmPath !== expectedWasmPath) {
throw new Error(`browser_parameter_fixture_${expectedWasmPath}_staging: path drift`);
}
return wasmPath;
}
function writeGeneratedParameterFixture(interp, wasmPath, expectedWasmPath, text) {
const checkedPath = generatedParameterPath(wasmPath, expectedWasmPath);
interp.writeTextFile(checkedPath, text);
return checkedPath;
}
async function loadSimMachineFiles(machineRel, iniFile, programFile = null) {
const iniText = await fetchText(
`../../vendor/linuxcnc/configs/sim/${machineRel}/${iniFile}`,
@@ -8718,11 +8731,17 @@
verifyExpectedOutput(
"restore_parameters_missing_file",
interp.restoreParameters("/work/browser-missing.var"),
interp.restoreParameters(
generatedParameterPath("/work/browser-missing.var", "/work/browser-missing.var"),
),
"restore_parameters=0",
);
const outOfOrderParameterFilePath = "/work/browser-out-of-order.var";
interp.writeTextFile(outOfOrderParameterFilePath, "5220 1\n5161 2\n");
const outOfOrderParameterFilePath = writeGeneratedParameterFixture(
interp,
"/work/browser-out-of-order.var",
"/work/browser-out-of-order.var",
"5220 1\n5161 2\n",
);
verifyExpectedOutput(
"restore_parameters_out_of_order",
interp.restoreParameters(outOfOrderParameterFilePath),
@@ -8732,8 +8751,12 @@
].join("\n"),
);
const missingRequiredParameterFilePath = "/work/browser-missing-required.var";
interp.writeTextFile(missingRequiredParameterFilePath, "5161 3.5\n5220 1\n");
const missingRequiredParameterFilePath = writeGeneratedParameterFixture(
interp,
"/work/browser-missing-required.var",
"/work/browser-missing-required.var",
"5161 3.5\n5220 1\n",
);
verifyExpectedOutput(
"restore_parameters_missing_required",
interp.restoreParameters(missingRequiredParameterFilePath),

View File

@@ -208,6 +208,17 @@ function writeG92PersistenceStaging(wasmDir, expectedWasmDir, targetInterp = int
return { disabledIniPath, iniPath, parameterPath, programPath };
}
function generatedParameterPath(wasmPath, expectedWasmPath) {
assert.equal(wasmPath, expectedWasmPath, `parameter fixture ${expectedWasmPath} staging path drift`);
return wasmPath;
}
function writeGeneratedParameterFixture(wasmPath, expectedWasmPath, text, targetInterp = interp) {
const checkedPath = generatedParameterPath(wasmPath, expectedWasmPath);
targetInterp.writeTextFile(checkedPath, text);
return checkedPath;
}
function stageInterpIniContext(name, programFile = "test.ngc") {
const sourceRootRel = `tests/interp/${name}`;
const iniText = readFileSync(
@@ -3724,12 +3735,15 @@ verifyExpectedOutput(
);
verifyExpectedOutput(
"restore_parameters_missing_file",
interp.restoreParameters("/work/missing.var"),
interp.restoreParameters(generatedParameterPath("/work/missing.var", "/work/missing.var")),
"restore_parameters=0",
);
const outOfOrderParameterFilePath = "/work/out-of-order.var";
interp.writeTextFile(outOfOrderParameterFilePath, "5220 1\n5161 2\n");
const outOfOrderParameterFilePath = writeGeneratedParameterFixture(
"/work/out-of-order.var",
"/work/out-of-order.var",
"5220 1\n5161 2\n",
);
verifyExpectedOutput(
"restore_parameters_out_of_order",
interp.restoreParameters(outOfOrderParameterFilePath),
@@ -3739,8 +3753,11 @@ verifyExpectedOutput(
].join("\n"),
);
const missingRequiredParameterFilePath = "/work/missing-required.var";
interp.writeTextFile(missingRequiredParameterFilePath, "5161 3.5\n5220 1\n");
const missingRequiredParameterFilePath = writeGeneratedParameterFixture(
"/work/missing-required.var",
"/work/missing-required.var",
"5161 3.5\n5220 1\n",
);
verifyExpectedOutput(
"restore_parameters_missing_required",
interp.restoreParameters(missingRequiredParameterFilePath),