Files
workinf_Blender_Wasm/tools/web/check-io-format-runtime-inventory.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

79 lines
4.6 KiB
JavaScript

import assert from "node:assert/strict";
import crypto from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { spawnSync } from "node:child_process";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const generator = path.join(repoRoot, "tools/web/generate-io-format-runtime-inventory.py");
const expectedInventory = path.join(repoRoot, "tests/golden/M12-05A/format-inventory.json");
const evidencePath = path.join(repoRoot, "tests/golden/M12-05A/manifest.json");
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "io-format-runtime-inventory-"));
const regenerated = path.join(temporary, "format-inventory.json");
const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
const fileSha256 = (file) => sha256(fs.readFileSync(file));
try {
const evidence = JSON.parse(fs.readFileSync(evidencePath, "utf8"));
assert.equal(evidence.schemaVersion, 1);
assert.equal(evidence.task, "M12-05A");
assert.equal(evidence.parentTask, "M12-04J");
assert.equal(evidence.nextTask, "M12-05B");
for (const artifact of Object.values(evidence.artifacts)) assert.equal(fileSha256(path.join(repoRoot, artifact.path)), artifact.sha256, artifact.path);
const blender = process.env.BLENDER_BIN ?? path.join(repoRoot, "build_blender_5.2.0/bin/blender");
const run = spawnSync(blender, ["-b", "--factory-startup", "--python", generator, "--", regenerated], {
cwd: repoRoot,
encoding: "utf8",
maxBuffer: 8 * 1024 * 1024,
});
assert.equal(run.status, 0, `${run.stdout ?? ""}\n${run.stderr ?? ""}`);
const expectedBytes = fs.readFileSync(expectedInventory);
assert.deepEqual(fs.readFileSync(regenerated), expectedBytes, "Blender runtime inventory is not deterministic");
const inventory = JSON.parse(expectedBytes);
assert.deepEqual(inventory, JSON.parse(fs.readFileSync(regenerated, "utf8")));
assert.equal(inventory.schemaVersion, 1);
assert.equal(inventory.task, "M12-05A");
assert.deepEqual(inventory.runtime.versionTuple, [5, 2, 0]);
assert.equal(inventory.runtime.blenderVersion, "5.2.0 LTS");
assert.match(inventory.runtime.binarySha256, /^[a-f0-9]{64}$/);
assert.equal(inventory.formats.length, 7);
assert.deepEqual(inventory.formats.map((entry) => entry.format), ["GLTF", "GLB", "OBJ", "STL", "PLY", "USD", "ALEMBIC"]);
const available = new Set(["GLTF", "GLB", "OBJ", "STL", "PLY"]);
const disabled = new Set(["USD", "ALEMBIC"]);
for (const entry of inventory.formats) {
assert.ok(Array.isArray(entry.extensions) && entry.extensions.length > 0, `${entry.format} extensions missing`);
assert.ok(Array.isArray(entry.variants) && entry.variants.length > 0, `${entry.format} variants missing`);
for (const operation of ["import", "export"]) {
const receipt = entry[operation];
assert.ok(typeof receipt.operator === "string" && receipt.operator.includes("."), `${entry.format} ${operation} operator missing`);
assert.ok(Array.isArray(receipt.properties), `${entry.format} ${operation} properties missing`);
assert.deepEqual(receipt.properties.map((property) => property.identifier), [...receipt.properties].map((property) => property.identifier).sort(), `${entry.format} ${operation} properties are not canonical`);
if (available.has(entry.format)) {
assert.equal(receipt.registered, true, `${entry.format} ${operation} is not registered`);
assert.equal(receipt.runtimeStatus, "AVAILABLE", `${entry.format} ${operation} is not available`);
assert.equal(receipt.buildOptionEnabled, true, `${entry.format} ${operation} build option is disabled`);
}
if (disabled.has(entry.format)) {
assert.equal(receipt.registered, false, `${entry.format} ${operation} unexpectedly registered`);
assert.equal(receipt.runtimeStatus, "OPERATOR_UNREGISTERED", `${entry.format} ${operation} did not fail closed`);
assert.equal(receipt.buildOptionEnabled, null, `${entry.format} ${operation} has an ambiguous build option`);
}
}
}
assert.equal(inventory.runtime.buildOptions.io_wavefront_obj, true);
assert.equal(inventory.runtime.buildOptions.io_stl, true);
assert.equal(inventory.runtime.buildOptions.io_ply, true);
assert.equal(inventory.runtime.buildOptions.usd, false);
assert.equal(inventory.runtime.buildOptions.alembic, false);
process.stdout.write(`io-format-runtime-inventory-ok formats=${inventory.formats.length} available=${available.size} build-disabled=${disabled.size} blender=${inventory.runtime.blenderVersion}\n`);
}
finally {
fs.rmSync(temporary, { recursive: true, force: true });
}