perf(web): centralize batch handoff rotation
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled

This commit is contained in:
mes123456
2026-09-03 15:50:39 +08:00
parent d602a13e2b
commit 07e63efa25
6 changed files with 78 additions and 30 deletions

View File

@@ -22,7 +22,8 @@ const inputPaths = [
parentManifest,
`tests/golden/${task}/task-context.json`,
];
const inputHash = digest(inputPaths.map((file) => `${file}\0${digest(read(file))}\n`).join(""));
const inputHashFor = () => digest(inputPaths.map((file) => `${file}\0${fs.existsSync(abs(file)) ? digest(read(file)) : "MISSING"}\n`).join(""));
const inputHash = inputHashFor();
let cached = null;
try { cached = JSON.parse(fs.readFileSync(cachePath, "utf8")); }
catch { /* First use or an interrupted write. */ }
@@ -31,14 +32,15 @@ if (!process.argv.includes("--force") && cached?.status === "PASS" && cached.tas
process.exit(0);
}
const result = spawnSync(process.execPath, [abs("tools/web/print-task-context.mjs"), "--task", task], { cwd: root, encoding: "utf8", maxBuffer: 8 * 1024 * 1024 });
const check = spawnSync(process.execPath, [abs("tools/web/check-task-context.mjs"), "--task", task], { cwd: root, encoding: "utf8", maxBuffer: 8 * 1024 * 1024 });
const check = spawnSync(process.execPath, [abs("tools/web/check-task-context.mjs"), "--task", task, "--write"], { cwd: root, encoding: "utf8", maxBuffer: 8 * 1024 * 1024 });
if ((result.status ?? 1) !== 0 || (check.status ?? 1) !== 0) {
process.stderr.write(`${result.stdout ?? ""}${result.stderr ?? ""}${check.stdout ?? ""}${check.stderr ?? ""}`);
process.exit(Math.max(result.status ?? 1, check.status ?? 1));
}
fs.mkdirSync(path.dirname(cachePath), { recursive: true });
const payload = { schemaVersion: 1, status: "PASS", task, inputHash, refreshedAt: new Date().toISOString() };
const refreshedInputHash = inputHashFor();
const payload = { schemaVersion: 1, status: "PASS", task, inputHash: refreshedInputHash, refreshedAt: new Date().toISOString() };
const temporary = `${cachePath}.tmp-${process.pid}`;
fs.writeFileSync(temporary, `${JSON.stringify(payload, null, 2)}\n`);
fs.renameSync(temporary, cachePath);
process.stdout.write(`wbv2-context-cache-refresh task=${task} inputHash=${inputHash}\n`);
process.stdout.write(`wbv2-context-cache-refresh task=${task} inputHash=${refreshedInputHash}\n`);