Guard SDK sim-config staging paths

This commit is contained in:
2026-06-13 20:12:15 +08:00
parent ea2537e4e3
commit 7fae830726
3 changed files with 133 additions and 2 deletions

View File

@@ -187,14 +187,16 @@ function simMachine(machineRel, iniFile, programFile, nativeToolTableRel) {
resolve(vendorRoot, `configs/sim/${machineRel}/${iniFile}`),
"utf8",
);
const expectedWasmDir = `/work/sim-inventory/${machineRel}`;
const plan = planSimConfigStaging({
manifestText,
machineRel,
iniFile,
iniText,
programFile,
wasmDir: `/work/sim-inventory/${machineRel}`,
wasmDir: expectedWasmDir,
});
assertSimConfigStagingPlan(machineRel, plan, expectedWasmDir);
const machine = {
...plan,
files: plan.files.map((file) => ({
@@ -207,6 +209,40 @@ function simMachine(machineRel, iniFile, programFile, nativeToolTableRel) {
return withNativeToolTableFallback(machine, iniText, nativeToolTableRel);
}
function assertSimConfigStagingPlan(machineRel, plan, expectedWasmDir) {
assert.equal(plan.wasmDir, expectedWasmDir, `${machineRel}: sim staging root drift`);
assert.ok(
plan.iniPath.startsWith(`${expectedWasmDir}/`),
`${machineRel}: sim INI staging path drift`,
);
if (plan.programPath !== null) {
assert.ok(
plan.programPath.startsWith(`${expectedWasmDir}/`),
`${machineRel}: sim program staging path drift`,
);
}
const paths = [];
for (const file of plan.files) {
assert.equal(file.path, file.wasmPath, `${file.sourceRel}: path/wasmPath drift`);
assert.ok(
file.wasmPath.startsWith(`${expectedWasmDir}/`),
`${file.sourceRel}: sim file staging root drift`,
);
assert.ok(
file.sourceRel.startsWith("configs/sim/"),
`${file.sourceRel}: sim source root drift`,
);
paths.push(file.wasmPath);
}
assert.deepEqual(
paths.filter((path, index) => paths.indexOf(path) !== index),
[],
`${machineRel}: duplicate sim staging paths`,
);
}
function firstIniValue(iniText, section, key) {
let activeSection = "";
for (const rawLine of iniText.split("\n")) {