82 lines
4.7 KiB
JavaScript
82 lines
4.7 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 root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const generator = path.join(root, "tools/web/generate-blender-rna-datablock-inventory.py");
|
|
const expectedPath = path.join(root, "tests/golden/M15-01A/blender-rna-datablock-inventory.json");
|
|
const manifestPath = path.join(root, "tests/golden/M15-01A/manifest.json");
|
|
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "blender-rna-datablock-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: 8 * 1024 * 1024,
|
|
});
|
|
assert.equal(run.status, 0, `${run.stdout ?? ""}\n${run.stderr ?? ""}`);
|
|
const expectedBytes = fs.readFileSync(expectedPath);
|
|
assert.deepEqual(fs.readFileSync(regeneratedPath), expectedBytes, "Blender RNA inventory is not deterministic");
|
|
const inventory = JSON.parse(expectedBytes);
|
|
assert.deepEqual(inventory, JSON.parse(fs.readFileSync(regeneratedPath, "utf8")));
|
|
assert.equal(inventory.schemaVersion, 1);
|
|
assert.equal(inventory.task, "M15-01A");
|
|
assert.equal(inventory.operation, "BLENDER_RNA_DATABLOCK_INVENTORY");
|
|
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.summary.baseType, "ID");
|
|
assert.ok(inventory.summary.count >= 20, `unexpectedly small ID inventory: ${inventory.summary.count}`);
|
|
assert.equal(inventory.dataBlockTypes.length, inventory.summary.count);
|
|
const identifiers = inventory.dataBlockTypes.map((entry) => entry.rnaIdentifier);
|
|
assert.deepEqual(identifiers, [...identifiers].sort(), "RNA identifiers are not sorted");
|
|
assert.equal(new Set(identifiers).size, identifiers.length, "RNA identifiers are not unique");
|
|
for (const entry of inventory.dataBlockTypes) {
|
|
assert.match(entry.parityId, /^BLENDER52_RNA_ID_[A-Z0-9_]+$/);
|
|
assert.equal(entry.baseType, "ID");
|
|
assert.match(entry.sourceAnchor, /blender-5\.2\.0\/source\/blender\/makesrna/);
|
|
}
|
|
assert.equal(inventory.nextTask, "M15-01B");
|
|
const report = {
|
|
schemaVersion: 1,
|
|
task: "M15-01A",
|
|
operation: "BLENDER_RNA_DATABLOCK_INVENTORY_CHECK",
|
|
runtime: inventory.runtime,
|
|
count: inventory.summary.count,
|
|
first: identifiers[0],
|
|
last: identifiers.at(-1),
|
|
inventorySha256: sha256(expectedBytes),
|
|
nextTask: inventory.nextTask,
|
|
};
|
|
if (process.env.UPDATE_M15_01A_MANIFEST === "1") {
|
|
fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
|
|
const artifactPaths = {
|
|
parentManifest: path.join(root, "tests/golden/M14-04H/manifest.json"),
|
|
generator,
|
|
checker: path.join(root, "tools/web/check-blender-rna-datablock-inventory.mjs"),
|
|
inventory: expectedPath,
|
|
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-01A", parentTask: "M14-04H", enablingTask: false, parityStateChange: false, runtime: "BLENDER_5_2_RNA", operation: "BLENDER_RNA_DATABLOCK_INVENTORY", artifacts, nextTask: "M15-01B" }, null, 2)}\n`);
|
|
fs.writeFileSync(path.join(root, "tests/golden/M15-01A/inventory-check-report.json"), `${JSON.stringify(report, null, 2)}\n`);
|
|
}
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
assert.deepEqual({ task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { task: "M15-01A", parentTask: "M14-04H", nextTask: "M15-01B" });
|
|
for (const artifact of Object.values(manifest.artifacts)) assert.equal(fileSha256(path.join(root, artifact.path)), artifact.sha256, artifact.path);
|
|
process.stdout.write(`blender-rna-datablock-inventory-ok count=${inventory.summary.count} blender=${inventory.runtime.blenderVersion} inventory=${sha256(expectedBytes)} next=${manifest.nextTask}\n`);
|
|
}
|
|
finally {
|
|
fs.rmSync(temporary, { recursive: true, force: true });
|
|
}
|