Govern task context and advance execution pointer
This commit is contained in:
71
tools/web/check-blender-format-inventory.mjs
Normal file
71
tools/web/check-blender-format-inventory.mjs
Normal file
@@ -0,0 +1,71 @@
|
||||
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 root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const generator = path.join(root, "tools/web/generate-blender-format-inventory.py");
|
||||
const expectedPath = path.join(root, "tests/golden/M15-01D/blender-format-inventory.json");
|
||||
const reportPath = path.join(root, "tests/golden/M15-01D/format-inventory-check-report.json");
|
||||
const manifestPath = path.join(root, "tests/golden/M15-01D/manifest.json");
|
||||
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "blender-format-inventory-"));
|
||||
const regeneratedPath = path.join(temporary, "inventory.json");
|
||||
const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
|
||||
const fileSha256 = (file) => sha256(fs.readFileSync(file));
|
||||
const relative = (file) => path.relative(root, file).replaceAll(path.sep, "/");
|
||||
|
||||
try {
|
||||
const blender = process.env.BLENDER_BIN ?? path.join(root, "build_blender_5.2.0/bin/blender");
|
||||
const run = spawnSync(blender, ["-b", "--factory-startup", "--python", generator, "--", regeneratedPath], { cwd: root, encoding: "utf8", maxBuffer: 32 * 1024 * 1024 });
|
||||
assert.equal(run.status, 0, `${run.stdout ?? ""}\n${run.stderr ?? ""}`);
|
||||
const expectedBytes = fs.readFileSync(expectedPath);
|
||||
assert.deepEqual(fs.readFileSync(regeneratedPath), expectedBytes, "Blender format inventory is not deterministic");
|
||||
const inventory = JSON.parse(expectedBytes);
|
||||
assert.equal(inventory.schemaVersion, 1);
|
||||
assert.equal(inventory.task, "M15-01D");
|
||||
assert.equal(inventory.operation, "BLENDER_FORMAT_INVENTORY");
|
||||
assert.deepEqual(inventory.runtime.versionTuple, [5, 2, 0]);
|
||||
assert.equal(inventory.runtime.blenderVersion, "5.2.0 LTS");
|
||||
assert.ok(inventory.summary.stripTypeCount >= 20);
|
||||
assert.ok(inventory.summary.physicsTypeCount >= 40);
|
||||
assert.ok(inventory.summary.ioOperatorCount >= 25);
|
||||
assert.equal(inventory.stripTypes.length, inventory.summary.stripTypeCount);
|
||||
assert.equal(inventory.physicsTypes.length, inventory.summary.physicsTypeCount);
|
||||
assert.equal(inventory.ioOperators.length, inventory.summary.ioOperatorCount);
|
||||
const sortedUnique = (values, label) => {
|
||||
assert.deepEqual(values, [...values].sort(), `${label} are not sorted`);
|
||||
assert.equal(new Set(values).size, values.length, `${label} are not unique`);
|
||||
};
|
||||
sortedUnique(inventory.stripTypes.map((entry) => entry.identifier), "strip types");
|
||||
sortedUnique(inventory.physicsTypes.map((entry) => entry.rnaIdentifier), "physics types");
|
||||
sortedUnique(inventory.ioOperators.map((entry) => entry.operator), "I/O operators");
|
||||
for (const entry of inventory.stripTypes) assert.match(entry.identifier, /^[A-Z0-9_]+$/);
|
||||
for (const entry of inventory.physicsTypes) {
|
||||
assert.match(entry.className, /^[A-Za-z0-9_]+$/);
|
||||
assert.ok(Array.isArray(entry.properties));
|
||||
sortedUnique(entry.properties.map((property) => property.identifier), `${entry.className} properties`);
|
||||
}
|
||||
for (const entry of inventory.ioOperators) {
|
||||
assert.match(entry.operator, /^[a-z0-9_]+\.[a-z0-9_]+$/);
|
||||
assert.match(entry.operator, /import|export/i);
|
||||
assert.match(entry.rnaIdentifier, /^[A-Za-z0-9_]+$/);
|
||||
assert.ok(Array.isArray(entry.properties));
|
||||
}
|
||||
const report = { schemaVersion: 1, task: "M15-01D", operation: "BLENDER_FORMAT_INVENTORY_CHECK", runtime: inventory.runtime, summary: inventory.summary, firstStrip: inventory.stripTypes[0].identifier, lastOperator: inventory.ioOperators.at(-1).operator, inventorySha256: sha256(expectedBytes), nextTask: inventory.nextTask };
|
||||
if (process.env.UPDATE_M15_01D_MANIFEST === "1") {
|
||||
fs.mkdirSync(path.dirname(reportPath), { recursive: true });
|
||||
fs.writeFileSync(reportPath, `${JSON.stringify(report, null, 2)}\n`);
|
||||
const artifactPaths = { parentManifest: path.join(root, "tests/golden/M15-01C/manifest.json"), generator, checker: path.join(root, "tools/web/check-blender-format-inventory.mjs"), inventory: expectedPath, report: reportPath, runtime: blender, package: path.join(root, "web/package.json") };
|
||||
const artifacts = Object.fromEntries(Object.entries(artifactPaths).map(([name, file]) => [name, { path: relative(file), sha256: fileSha256(file) }]));
|
||||
fs.writeFileSync(manifestPath, `${JSON.stringify({ schemaVersion: 1, task: "M15-01D", parentTask: "M15-01C", enablingTask: false, parityStateChange: false, runtime: "BLENDER_5_2_FORMAT", operation: "BLENDER_FORMAT_INVENTORY", artifacts, nextTask: "M15-01E" }, null, 2)}\n`);
|
||||
}
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
assert.deepEqual({ task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { task: "M15-01D", parentTask: "M15-01C", nextTask: "M15-01E" });
|
||||
for (const artifact of Object.values(manifest.artifacts)) assert.equal(fileSha256(path.join(root, artifact.path)), artifact.sha256, artifact.path);
|
||||
process.stdout.write(`blender-format-inventory-ok strips=${inventory.summary.stripTypeCount} physics=${inventory.summary.physicsTypeCount} io=${inventory.summary.ioOperatorCount} inventory=${sha256(expectedBytes)} next=${manifest.nextTask}\n`);
|
||||
} finally {
|
||||
fs.rmSync(temporary, { recursive: true, force: true });
|
||||
}
|
||||
Reference in New Issue
Block a user