Files
workinf_Blender_Wasm/tools/web/check-fuzz-regression.mjs
mes123456 380cbed4ff
Some checks are pending
M6 deployable RC / quick (push) Waiting to run
M6 deployable RC / chromium (push) Blocked by required conditions
M6 deployable RC / release (push) Blocked by required conditions
Checkpoint web parity through Chromium input tasks
2026-08-19 10:39:03 -04:00

46 lines
3.5 KiB
JavaScript

import assert from "node:assert/strict";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const runner = path.join(root, "tools/web/fuzz-case-runner.mjs");
const corpusRoot = path.join(root, "tests/files/web/fuzz-regressions");
const reportPath = path.join(root, "tests/golden/M13-05G/fuzz-report.json");
const manifestPath = path.join(root, "tests/golden/M13-05G/manifest.json");
const seed = 0x5a17c0de;
const iterationsPerDomain = 16;
const domains = ["blend", "image", "font", "node", "manifest"];
const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
const fileSha256 = (file) => sha256(fs.readFileSync(file));
fs.mkdirSync(corpusRoot, { recursive: true });
const outcomes = [];
for (const domain of domains) {
for (let iteration = 0; iteration < iterationsPerDomain; iteration++) {
const run = spawnSync(process.execPath, [runner, domain, String(seed), String(iteration)], { cwd: root, encoding: "utf8", maxBuffer: 2 * 1024 * 1024 });
if (run.status !== 0 || run.signal) {
const replay = { schemaVersion: 1, domain, seed, iteration, status: run.status, signal: run.signal, stdout: run.stdout, stderr: run.stderr };
const bytes = Buffer.from(`${JSON.stringify(replay, null, 2)}\n`);
const file = path.join(corpusRoot, `${sha256(bytes)}.json`);
fs.writeFileSync(file, bytes);
throw new Error(`FUZZ_CRASH_SAVED: ${path.relative(root, file)}`);
}
const lines = run.stdout.trim().split(/\r?\n/u).filter(Boolean);
assert.equal(lines.length, 1, `${domain}:${iteration} returned an invalid receipt`);
const receipt = JSON.parse(lines[0]);
assert.ok(["ACCEPTED", "REJECTED"].includes(receipt.status));
outcomes.push(receipt);
}
}
const corpus = fs.readdirSync(corpusRoot).filter((name) => name.endsWith(".json")).sort().map((name) => ({ path: `tests/files/web/fuzz-regressions/${name}`, sha256: fileSha256(path.join(corpusRoot, name)) }));
const counts = Object.fromEntries(domains.map((domain) => [domain, { accepted: outcomes.filter((item) => item.domain === domain && item.status === "ACCEPTED").length, rejected: outcomes.filter((item) => item.domain === domain && item.status === "REJECTED").length }]));
const report = { schemaVersion: 1, task: "M13-05G", operation: "DETERMINISTIC_FUZZ_REGRESSION", seed, domains, iterationsPerDomain, totalCases: outcomes.length, counts, crashes: 0, minimizedCorpus: corpus, crashPolicy: "SAVE_REPLAY_BEFORE_FIX_AND_ADD_TO_REGRESSION", execution: "DISABLED", nextTask: "M13-05H" };
if (process.env.UPDATE_M13_05G_REPORT === "1") { fs.mkdirSync(path.dirname(reportPath), { recursive: true }); fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`); }
assert.deepEqual(JSON.parse(fs.readFileSync(reportPath, "utf8")), report);
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
assert.deepEqual({ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { schemaVersion: 1, task: "M13-05G", parentTask: "M13-05F", nextTask: "M13-05H" });
for (const artifact of Object.values(manifest.artifacts)) assert.equal(fileSha256(path.join(root, artifact.path)), artifact.sha256, artifact.path);
process.stdout.write(`fuzz-regression-ok seed=${seed} cases=${outcomes.length} crashes=0 corpus=${corpus.length} execution=DISABLED next=M13-05H\n`);