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

44 lines
2.8 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 registryPath = path.join(repoRoot, "web/app/src/capabilities/io-format-ui-registry.json");
const matrixPath = path.join(repoRoot, "tests/golden/M12-05B/capability-matrix.json");
const matrixProtocolPath = path.join(repoRoot, "web/protocol/io-format-capability-matrix.ts");
const gateProtocolPath = path.join(repoRoot, "web/protocol/io-format-ui-gate.ts");
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "io-format-ui-gate-check-"));
const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
try {
const registry = JSON.parse(fs.readFileSync(registryPath, "utf8"));
const matrixBytes = fs.readFileSync(matrixPath);
const transpile = (sourcePath, fileName) => {
const result = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: sourcePath, reportDiagnostics: true });
assert.deepEqual(result.diagnostics, []);
const target = path.join(temporary, fileName);
fs.writeFileSync(target, result.outputText);
return target;
};
const matrixProtocol = await import(pathToFileURL(transpile(matrixProtocolPath, "matrix.mjs")));
const gateProtocol = await import(pathToFileURL(transpile(gateProtocolPath, "gate.mjs")));
const matrix = matrixProtocol.parseIOFormatCapabilityMatrix(JSON.parse(matrixBytes));
gateProtocol.validateIOFormatUIRegistry(registry, matrix, sha256(matrixBytes));
assert.equal(registry.task, "M12-05C");
assert.equal(registry.parentMatrixSha256, sha256(matrixBytes));
assert.equal(registry.projectFileAccept, ".blend,application/octet-stream");
assert.deepEqual(registry.importRoutes, [], "no blocked import route may reach the file selector");
assert.deepEqual(registry.exportRoutes, [{ format: "GLB", operation: "EXPORT", execution: "LOCAL", extensions: [".glb"] }]);
const regenerated = path.join(temporary, "registry.json");
execFileSync(process.execPath, [path.join(repoRoot, "tools/web/generate-io-format-ui-gate.mjs"), "--output", regenerated], { cwd: repoRoot });
assert.deepEqual(fs.readFileSync(regenerated), fs.readFileSync(registryPath), "UI registry is not deterministic");
process.stdout.write("io-format-ui-gate-ok import-routes=0 export-routes=1 file-accept=.blend,application/octet-stream fail-closed=true\n");
}
finally {
fs.rmSync(temporary, { recursive: true, force: true });
}