146 lines
9.2 KiB
JavaScript
146 lines
9.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Validate a headed armature / ABB IRB120 receipt.
|
|
*
|
|
* node tools/web/check-armature-robot-headed.mjs [--dir <abs report dir>] [--report <abs report.json>] [--allow-headless]
|
|
*
|
|
* Without arguments the newest tests/golden/ARMATURE-ROBOT-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 armature feature probes (bone parenting, pose evaluation,
|
|
* rig entry) are still recorded as soft evidence by the runner; this checker
|
|
* only hard-gates what the robot 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 = ["robot-sample-web", "robot-assemble-check-web", "robot-pose-web", "robot-rig-web", "armature-bones-web", "armature-bind-web", "armature-pose-web", "armature-viewport-web", "armature-decimal-input-web", "armature-ui-readback-web", "armature-reopen-web"];
|
|
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("ARMATURE-ROBOT-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/ARMATURE-ROBOT-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 robot sample ships with the candidate, so the receipt binds its
|
|
* provenance file and every hashed member to the bytes on disk now. */
|
|
const sample = report.fixtures?.robotSample;
|
|
if (typeof sample?.dir !== "string" || !path.isAbsolute(sample.dir)) errors.push(`fixtures.robotSample.dir is not an absolute path: ${sample?.dir}`);
|
|
else {
|
|
for (const [relative, key] of [["provenance.json", "provenance"], ["abb_irb120.urdf", "urdf"], ["start-scene.blend", "starter"]]) {
|
|
const file = path.join(sample.dir, relative);
|
|
if (!fs.existsSync(file)) { errors.push(`robot sample is missing ${relative}`); continue; }
|
|
if (sha256(file) !== sample[key]) errors.push(`robot sample ${relative} sha256 does not match the receipt`);
|
|
}
|
|
const files = Array.isArray(sample.files) ? sample.files : [];
|
|
if (files.length === 0) errors.push("fixtures.robotSample.files is empty");
|
|
for (const entry of files) {
|
|
if (!entry || typeof entry.path !== "string") { errors.push(`robot sample entry is malformed: ${JSON.stringify(entry)}`); continue; }
|
|
if (entry.match !== true || entry.expected !== entry.actual) errors.push(`robot sample preflight bytes did not match provenance: ${entry.path}`);
|
|
const file = path.join(sample.dir, entry.path);
|
|
if (!fs.existsSync(file)) { errors.push(`robot sample file is missing: ${entry.path}`); continue; }
|
|
if (sha256(file) !== entry.actual) errors.push(`robot sample file changed after preflight: ${entry.path}`);
|
|
}
|
|
}
|
|
|
|
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.bundleHasRobotTool !== true) errors.push("release.bundleHasRobotTool is not true (bundle lacks the ABB IRB120 sample entry)");
|
|
if (release.matchesSyncedRuntime === false) errors.push("release.matchesSyncedRuntime is false (candidate wasm differs from the synced runtime)");
|
|
if (release.engineHasArmatureCommands !== true) errors.push("release.engineHasArmatureCommands is not true (wasm lacks the armature command strings)");
|
|
if (release.engineHasBoneParent !== true) errors.push("release.engineHasBoneParent is not true (wasm lacks bone parenting)");
|
|
if (release.enginePoseEvaluated !== true) errors.push("release.enginePoseEvaluated is not true (wasm lacks pose evaluation)");
|
|
if (release.bundleHasArmatureReadback !== true) errors.push("release.bundleHasArmatureReadback is not true (bundle lacks the pose readback form)");
|
|
|
|
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}`); }
|
|
}
|
|
}
|
|
}
|
|
|
|
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: { engineHasArmatureCommands: release.engineHasArmatureCommands, engineHasBoneParent: release.engineHasBoneParent, enginePoseEvaluated: release.enginePoseEvaluated, bundleHasArmatureReadback: release.bundleHasArmatureReadback } }, null, 2));
|