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

48 lines
3.0 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 { execFileSync } from "node:child_process";
import { fileURLToPath, pathToFileURL } from "node:url";
import ts from "../../web/node_modules/typescript/lib/typescript.js";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const inventoryPath = path.join(repoRoot, "tests/golden/M12-05A/format-inventory.json");
const receiptPath = path.join(repoRoot, "tests/golden/M12-05D/runtime-receipts.json");
const protocolPath = path.join(repoRoot, "web/protocol/io-format-runtime-receipt.ts");
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "io-format-runtime-receipts-"));
const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
try {
const inventoryBytes = fs.readFileSync(inventoryPath);
const inventory = JSON.parse(inventoryBytes);
const receiptBytes = fs.readFileSync(receiptPath);
const receipts = JSON.parse(receiptBytes);
const transpiled = ts.transpileModule(fs.readFileSync(protocolPath, "utf8"), { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: protocolPath, reportDiagnostics: true });
assert.deepEqual(transpiled.diagnostics, []);
const modulePath = path.join(temporary, "protocol.mjs");
fs.writeFileSync(modulePath, transpiled.outputText);
const protocol = await import(pathToFileURL(modulePath));
const parsed = protocol.validateIOFormatRuntimeReceiptSet(receipts, sha256(inventoryBytes));
assert.equal(parsed.receipts.length, 14);
const byIdentity = new Map(inventory.formats.flatMap((entry) => ["IMPORT", "EXPORT"].map((operation) => [`${entry.format}:${operation}`, entry[operation.toLowerCase()]])));
for (const receipt of parsed.receipts) {
const source = byIdentity.get(`${receipt.format}:${receipt.operation}`);
assert.ok(source);
assert.equal(receipt.operator, source.operator);
assert.equal(receipt.registered, source.registered);
assert.equal(receipt.rnaIdentifier, source.rnaIdentifier);
assert.equal(receipt.runtimeStatus, source.runtimeStatus);
assert.equal(receipt.extensions.length > 0, true);
}
assert.equal(protocol.resolveIOFormatRuntimeRoute(parsed, { format: "GLB", operation: "EXPORT" }).status, "READY");
assert.equal(protocol.resolveIOFormatRuntimeRoute(parsed, { format: "USD", operation: "EXPORT" }).status, "BLOCKED");
const regenerated = path.join(temporary, "runtime-receipts.json");
execFileSync(process.execPath, [path.join(repoRoot, "tools/web/generate-io-format-runtime-receipts.mjs"), "--output", regenerated], { cwd: repoRoot });
assert.deepEqual(fs.readFileSync(regenerated), receiptBytes, "runtime receipt set is not deterministic");
process.stdout.write("io-format-runtime-receipts-ok formats=7 receipts=14 glb-export=READY usd-export=BLOCKED extension-independent=true\n");
}
finally {
fs.rmSync(temporary, { recursive: true, force: true });
}