Files
workinf_Blender_Wasm/tools/web/check-mesh-decimate-headed.mjs
mes123456 390d487eb8
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
fix(web): decimate ratio writes refresh the evaluated modifier stack
The modifier merge ran after refresh_scene_from_main round-tripped Main
through the blend format, which dropped the DEG tag issued by the setter,
so DEG_get_evaluated kept publishing the previous COW copy: Ratio 0.1 was
visible in Main and in the snapshot parameters while triangleCount and
python to_mesh() stayed at the add-time 968 until an external
update_tag()+view_layer.update().

- engine: tag every modifier owner with DEG_id_tag_update_ex(state->main,
  ID_RECALC_ALL) before merge evaluation and update through
  BKE_scene_graph_update_tagged (same call ViewLayer.update uses).
- tests: mode menu items are menuitemcheckbox; select-all lives in the
  header 选择 ▸ 全部 menu, not 网格 ▸ 选择工具.
- runner: archive per-case evidence JSON under artifacts/evidence;
  checker reads fixtures.desktopOracle instead of a missing top-level key.
- docs: record the root cause, fix and receipt MESH-DECIMATE-HEADED-20261129-012441.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-29 01:51:25 +08:00

142 lines
8.2 KiB
JavaScript

#!/usr/bin/env node
/**
* Validate a headed Decimate (triangle simplification) receipt.
*
* node tools/web/check-mesh-decimate-headed.mjs [--dir <abs report dir>] [--report <abs report.json>] [--allow-headless]
*
* Without arguments the newest tests/golden/MESH-DECIMATE-HEADED-* directory that
* contains a report.json is validated. Prints {status, cases, artifacts} on PASS,
* {status:"FAIL", errors} on stderr and exits 1 otherwise.
*/
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const EXPECTED_CASES = ["dec-monkey-modifier-web", "dec-monkey-modifier-native", "dec-monkey-edit-web", "dec-monkey-edit-native"];
const errors = [];
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
function parseArgs(argv) {
const take = (name) => { const index = argv.indexOf(`--${name}`); return index >= 0 && argv[index + 1] ? argv[index + 1] : null; };
return { dir: take("dir"), report: take("report"), allowHeadless: argv.includes("--allow-headless") };
}
function newestReportDir(root) {
if (!fs.existsSync(root)) return null;
return fs.readdirSync(root)
.filter((name) => name.startsWith("MESH-DECIMATE-HEADED-"))
.map((name) => path.join(root, name))
.filter((dir) => fs.existsSync(path.join(dir, "report.json")))
.sort((a, b) => fs.statSync(path.join(b, "report.json")).mtimeMs - fs.statSync(path.join(a, "report.json")).mtimeMs)[0] ?? null;
}
function pngSize(file) {
const bytes = fs.readFileSync(file);
if (bytes.length < 24 || bytes.toString("latin1", 1, 4) !== "PNG") return null;
return { width: bytes.readUInt32BE(16), height: bytes.readUInt32BE(20) };
}
const args = parseArgs(process.argv.slice(2));
const reportDir = args.report ? path.dirname(path.resolve(args.report)) : args.dir ? path.resolve(args.dir) : newestReportDir(path.join(REPO_ROOT, "tests/golden"));
const reportFile = args.report ? path.resolve(args.report) : reportDir ? path.join(reportDir, "report.json") : null;
if (!reportFile || !fs.existsSync(reportFile)) {
console.error(`no headed receipt found${reportDir ? `: ${reportFile ?? reportDir}` : " under tests/golden/MESH-DECIMATE-HEADED-*"}`);
process.exit(1);
}
let report;
try { report = JSON.parse(fs.readFileSync(reportFile, "utf8")); }
catch (error) { console.error(`report.json is not valid JSON: ${error.message}`); process.exit(1); }
if (report.schemaVersion !== 1) errors.push(`schemaVersion is ${report.schemaVersion}, expected 1`);
if (report.status !== "PASS") errors.push(`status is ${report.status}, expected PASS`);
if (report.acceptance !== "NOT_CLAIMED") errors.push(`acceptance is ${report.acceptance}, expected NOT_CLAIMED`);
if (!Array.isArray(report.errors) || report.errors.length > 0) errors.push(`errors is not empty: ${JSON.stringify(report.errors)}`);
const environment = report.environment ?? {};
if (environment.browser !== "chromium-headed" && !args.allowHeadless) errors.push(`environment.browser is ${environment.browser}, expected chromium-headed`);
if (environment.gpuMode !== "hardware" && !args.allowHeadless) errors.push(`environment.gpuMode is ${environment.gpuMode}, expected hardware`);
if (!environment.display && !args.allowHeadless) errors.push("environment.display is empty (headed runs need X11)");
if (typeof environment.chrome !== "string" || environment.chrome.length === 0) errors.push("environment.chrome is missing");
/* Fixtures are the user's desktop assets, not build output: the receipt must
* name them absolutely and bind their bytes so a run cannot be mistaken for
* one on a different monkey head or base blend. */
const fixtures = report.fixtures ?? {};
for (const key of ["monkey", "base"]) {
const fixture = fixtures[key];
const file = typeof fixture === "string" ? fixture : fixture?.path;
if (typeof file !== "string" || !path.isAbsolute(file)) { errors.push(`fixtures.${key} is not an absolute path: ${file}`); continue; }
if (!fs.existsSync(file)) { errors.push(`fixtures.${key} is missing: ${file}`); continue; }
if (typeof fixture === "object" && fixture.sha256 !== undefined && fixture.sha256 !== sha256(file)) errors.push(`fixtures.${key} sha256 ${sha256(file)} does not match receipt ${fixture.sha256}`);
}
const candidate = report.candidate;
if (typeof candidate !== "string" || !path.isAbsolute(candidate)) errors.push(`candidate is not an absolute path: ${candidate}`);
else {
if (!fs.existsSync(candidate)) errors.push(`candidate directory is missing: ${candidate}`);
const checks = [
["index.html", "indexSha256"],
["wasm-module-manifest.json", "moduleManifestSha256"],
["vendor/blender/web_engine.wasm", "wasmSha256"],
];
for (const [relative, key] of checks) {
const file = path.join(candidate, relative);
if (!fs.existsSync(file)) { errors.push(`candidate is missing ${relative}`); continue; }
const actual = sha256(file);
const expected = report.release?.[key];
if (actual !== expected) errors.push(`${relative} sha256 ${actual} does not match receipt ${expected}`);
}
}
/* The freshness probes are the point of this suite: a candidate whose engine
* lacks the evaluated-stack publication or whose bundle lacks the two desktop
* entries must not be reported as a Decimate pass. */
const release = report.release ?? {};
if (release.engineHasDecimateMesh !== true) errors.push("release.engineHasDecimateMesh is not true (wasm lacks the decimate entry point)");
if (release.bundleHasDecimateEntries !== true) errors.push("release.bundleHasDecimateEntries is not true (bundle lacks 添加修改器 / 简化几何)");
if (release.matchesSyncedRuntime === false) errors.push("release.matchesSyncedRuntime is false (candidate wasm differs from the synced runtime)");
const summary = report.summary ?? {};
if (summary.fail !== 0) errors.push(`summary.fail is ${summary.fail}`);
if (summary.blocked !== 0) errors.push(`summary.blocked is ${summary.blocked}`);
if (!Number.isSafeInteger(summary.total) || summary.total < 1) errors.push(`summary.total is ${summary.total}`);
const cases = Array.isArray(report.cases) ? report.cases : [];
if (cases.length !== summary.total) errors.push(`cases length ${cases.length} does not match summary.total ${summary.total}`);
const expected = Array.isArray(summary.expectedCaseIds) && summary.expectedCaseIds.length > 0 ? summary.expectedCaseIds : EXPECTED_CASES;
for (const id of EXPECTED_CASES) {
if (!expected.includes(id)) errors.push(`expected case ${id} is not in summary.expectedCaseIds`);
}
for (const id of expected) {
const found = cases.find((item) => item.caseId === id);
if (!found) errors.push(`expected case ${id} is missing`);
else if (found.status !== "PASS") errors.push(`expected case ${id} is ${found.status}`);
}
if ((summary.missingCaseIds ?? []).length > 0) errors.push(`missingCaseIds: ${summary.missingCaseIds.join(", ")}`);
let artifactCount = 0;
for (const item of cases) {
for (const artifact of item.artifacts ?? []) {
artifactCount++;
const file = path.resolve(reportDir, artifact.path ?? "");
if (!file.startsWith(reportDir + path.sep)) { errors.push(`artifact escapes the receipt directory: ${artifact.path}`); continue; }
if (!fs.existsSync(file)) { errors.push(`artifact is missing: ${artifact.path}`); continue; }
const bytes = fs.readFileSync(file);
if (crypto.createHash("sha256").update(bytes).digest("hex") !== artifact.sha256) errors.push(`artifact sha256 mismatch: ${artifact.path}`);
if (artifact.kind === "png") {
const size = pngSize(file);
if (!size || size.width <= 0 || size.height <= 0) errors.push(`artifact is not a decodable PNG: ${artifact.path}`);
}
else if (artifact.kind === "json") {
try { JSON.parse(bytes.toString("utf8")); }
catch { errors.push(`artifact is not valid JSON: ${artifact.path}`); }
}
}
}
if (errors.length > 0) {
console.error(JSON.stringify({ status: "FAIL", errors }, null, 2));
process.exit(1);
}
console.log(JSON.stringify({ status: "PASS", report: reportFile, cases: cases.length, artifacts: artifactCount, candidate, wasmSha256: report.release?.wasmSha256, desktopOracle: report.fixtures?.desktopOracle ?? "missing" }, null, 2));