49 lines
2.9 KiB
JavaScript
49 lines
2.9 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
import test from "node:test";
|
|
import ts from "typescript";
|
|
|
|
const root = path.resolve(import.meta.dirname, "../../..");
|
|
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "io-format-runtime-receipt-unit-"));
|
|
const sourcePath = path.join(root, "web/protocol/io-format-runtime-receipt.ts");
|
|
const transpiled = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: sourcePath, reportDiagnostics: true });
|
|
assert.deepEqual(transpiled.diagnostics, []);
|
|
fs.writeFileSync(path.join(temporary, "protocol.mjs"), transpiled.outputText);
|
|
const protocol = await import(pathToFileURL(path.join(temporary, "protocol.mjs")));
|
|
const receiptSet = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M12-05D/runtime-receipts.json"), "utf8"));
|
|
const inventorySha256 = receiptSet.inventorySha256;
|
|
|
|
test("M12-05D resolves capability from the runtime operator receipt", () => {
|
|
const parsed = protocol.validateIOFormatRuntimeReceiptSet(receiptSet, inventorySha256);
|
|
assert.equal(protocol.resolveIOFormatRuntimeRoute(parsed, { format: "GLB", operation: "EXPORT" }).status, "READY");
|
|
assert.equal(protocol.resolveIOFormatRuntimeRoute(parsed, { format: "USD", operation: "EXPORT" }).status, "BLOCKED");
|
|
});
|
|
|
|
test("M12-05D does not infer capability from a filename extension", () => {
|
|
const mutated = structuredClone(receiptSet);
|
|
const receipt = mutated.receipts.find((candidate) => candidate.format === "GLB" && candidate.operation === "EXPORT");
|
|
receipt.extensions = [".usd"];
|
|
const parsed = protocol.validateIOFormatRuntimeReceiptSet(mutated, inventorySha256);
|
|
assert.deepEqual(protocol.resolveIOFormatRuntimeRoute(parsed, { format: "GLB", operation: "EXPORT" }).status, "READY");
|
|
assert.deepEqual(protocol.resolveIOFormatRuntimeRoute(parsed, { format: "USD", operation: "EXPORT" }).status, "BLOCKED");
|
|
});
|
|
|
|
test("M12-05D rejects receipt identity drift and consumes explicit receipt status", () => {
|
|
const stale = structuredClone(receiptSet);
|
|
stale.inventorySha256 = "0".repeat(64);
|
|
assert.throws(() => protocol.validateIOFormatRuntimeReceiptSet(stale, inventorySha256), { code: "IO_FORMAT_UNSUPPORTED" });
|
|
const forged = structuredClone(receiptSet);
|
|
const usd = forged.receipts.find((candidate) => candidate.format === "USD" && candidate.operation === "EXPORT");
|
|
usd.runtimeStatus = "AVAILABLE";
|
|
usd.registered = true;
|
|
usd.rnaIdentifier = "WM_OT_usd_export";
|
|
usd.buildOptionEnabled = true;
|
|
assert.doesNotThrow(() => protocol.parseIOFormatRuntimeReceiptSet(forged));
|
|
assert.equal(protocol.resolveIOFormatRuntimeRoute(protocol.parseIOFormatRuntimeReceiptSet(forged), { format: "USD", operation: "EXPORT" }).status, "READY");
|
|
});
|
|
|
|
test.after(() => fs.rmSync(temporary, { recursive: true, force: true }));
|