#!/usr/bin/env node /** * Validate a headed Outliner receipt. * * node tools/web/check-outliner-headed.mjs [--dir ] [--report ] [--allow-headless] * * Without arguments the newest tests/golden/OUTLINER-HEADED-* directory that * contains a report.json is validated. Prints {status, cases, artifacts} on * PASS, {status:"FAIL", errors} on stderr and exits 1 otherwise. * * Batch scope: the engine feature probes (display modes, native filter, * restriction columns) are recorded as soft evidence by the runner; this * checker only hard-gates what the baseline cases already exercise. The * probes become gates together with the engine batches that make them true. */ 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 = ["outliner-tree-baseline-web", "outliner-tools-baseline-web", "outliner-mirror-baseline-web", "outliner-metrics-web", "outliner-display-mode-web", "outliner-filter-web"]; /* Desktop Layout geometry the metrics case must reproduce (batch 2: UI sizes). */ const GEOMETRY_GOLDEN = path.join(REPO_ROOT, "tests/golden/OUTLINER-DESKTOP-METRICS/outliner-metrics.json"); 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("OUTLINER-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; } 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/OUTLINER-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"); /* The fixture ships with the repository, so the receipt binds the bytes on * disk rather than a copy that could drift. */ const fixture = report.fixtures?.basicScene; if (typeof fixture?.path !== "string" || !path.isAbsolute(fixture.path)) errors.push(`fixtures.basicScene.path is not an absolute path: ${fixture?.path}`); else if (!fs.existsSync(fixture.path)) errors.push(`fixture is missing: ${fixture.path}`); else if (sha256(fixture.path) !== fixture.sha256) errors.push("fixture basic_scene.blend sha256 does not match the receipt"); 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}`); } } const release = report.release ?? {}; if (release.bundleHasOutlinerSearch !== true) errors.push("release.bundleHasOutlinerSearch is not true (bundle lacks the outliner search box)"); 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 === "json") { try { JSON.parse(bytes.toString("utf8")); } catch { errors.push(`artifact is not valid JSON: ${artifact.path}`); } } } } /* The metrics case attaches its measured boxes; compare them with the desktop * golden the workbench layout is built from (±1 px at 1920x1080). */ const geometryCase = cases.find((item) => item.caseId === "outliner-metrics-web"); if (geometryCase) { const artifact = (geometryCase.artifacts ?? []).find((entry) => entry.name === "outliner-metrics-web"); if (!artifact) errors.push("outliner-metrics-web attached no geometry artifact"); else if (!fs.existsSync(GEOMETRY_GOLDEN)) errors.push(`desktop metrics golden is missing: ${GEOMETRY_GOLDEN}`); else { try { const body = JSON.parse(fs.readFileSync(path.resolve(reportDir, artifact.path ?? ""), "utf8")); const golden = JSON.parse(fs.readFileSync(GEOMETRY_GOLDEN, "utf8")).outliner; const near = (value, expected) => Number.isFinite(value) && Math.abs(value - expected) <= 1; const measured = body.measured ?? {}; if (measured.viewport?.width !== 1920 || measured.viewport?.height !== 1080) errors.push(`outliner-metrics-web ran at ${JSON.stringify(measured.viewport)}, expected 1920x1080`); for (const [name, actual, expected] of [ ["outliner width", measured.outliner?.width, golden.width], ["outliner height", measured.outliner?.height, golden.height], ["outliner header height", measured.header?.height, golden.headerHeight], ["indent per level", measured.indentPerLevel, golden.indentPerLevel], ]) { if (!near(actual, expected)) errors.push(`outliner-metrics-web ${name} ${actual} is outside ±1 of desktop ${expected}`); } const heights = Array.isArray(measured.rowHeights) ? measured.rowHeights : []; if (heights.length === 0) errors.push("outliner-metrics-web measured no rows"); for (const height of heights) if (!near(height, golden.rowHeight)) errors.push(`outliner-metrics-web row height ${height} is outside ±1 of desktop ${golden.rowHeight}`); } catch (error) { errors.push(`outliner-metrics-web artifact is unreadable: ${error.message}`); } } } 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, featureProbes: { engineHasDisplayMode: release.engineHasDisplayMode, engineHasOutlinerFilter: release.engineHasOutlinerFilter, engineHasRestrictionColumns: release.engineHasRestrictionColumns, bundleHasOutlinerSearch: release.bundleHasOutlinerSearch } }, null, 2));