72 lines
5.4 KiB
JavaScript
72 lines
5.4 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-editor-inventory.py");
|
|
const expectedPath = path.join(root, "tests/golden/M15-01E/blender-editor-inventory.json");
|
|
const reportPath = path.join(root, "tests/golden/M15-01E/editor-inventory-check-report.json");
|
|
const manifestPath = path.join(root, "tests/golden/M15-01E/manifest.json");
|
|
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "blender-editor-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 editor inventory is not deterministic");
|
|
const inventory = JSON.parse(expectedBytes);
|
|
assert.equal(inventory.schemaVersion, 1);
|
|
assert.equal(inventory.task, "M15-01E");
|
|
assert.equal(inventory.operation, "BLENDER_EDITOR_INVENTORY");
|
|
assert.deepEqual(inventory.runtime.versionTuple, [5, 2, 0]);
|
|
assert.equal(inventory.runtime.blenderVersion, "5.2.0 LTS");
|
|
assert.ok(inventory.summary.areaTypeCount >= 15);
|
|
assert.ok(inventory.summary.regionTypeCount >= 15);
|
|
assert.ok(inventory.summary.spaceTypeCount >= 15);
|
|
assert.ok(inventory.summary.spaceClassCount >= 10);
|
|
assert.ok(inventory.summary.workspaceModeCount >= 10);
|
|
assert.ok(inventory.summary.keymapCount >= 250);
|
|
assert.ok(inventory.summary.keymapItemCount >= 3000);
|
|
assert.equal(inventory.keymaps.length, inventory.summary.keymapCount);
|
|
assert.equal(inventory.keymaps.reduce((count, keymap) => count + keymap.items.length, 0), inventory.summary.keymapItemCount);
|
|
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`);
|
|
};
|
|
for (const [name, values] of [["area types", inventory.areaTypes], ["region types", inventory.regionTypes], ["space types", inventory.spaceTypes], ["workspace modes", inventory.workspaceModes]]) sortedUnique(values.map((entry) => entry.identifier), name);
|
|
sortedUnique(inventory.spaceClasses.map((entry) => entry.rnaIdentifier), "space classes");
|
|
sortedUnique(inventory.keymaps.map((entry) => `${entry.name}:${entry.spaceType}:${entry.regionType}`), "keymaps");
|
|
for (const keymap of inventory.keymaps) {
|
|
assert.ok(Array.isArray(keymap.items));
|
|
for (const item of keymap.items) {
|
|
if (item.idname) assert.match(item.idname, /^[a-z0-9_]+\.[a-z0-9_]+$/);
|
|
else assert.equal(keymap.modal, true, `${keymap.name} has an empty operator id outside a modal map`);
|
|
assert.match(item.mapType, /^[A-Z]+$/);
|
|
assert.equal(typeof item.active, "boolean");
|
|
}
|
|
}
|
|
const report = { schemaVersion: 1, task: "M15-01E", operation: "BLENDER_EDITOR_INVENTORY_CHECK", runtime: inventory.runtime, summary: inventory.summary, firstArea: inventory.areaTypes[0].identifier, lastKeymap: inventory.keymaps.at(-1).name, inventorySha256: sha256(expectedBytes), nextTask: inventory.nextTask };
|
|
if (process.env.UPDATE_M15_01E_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-01D/manifest.json"), generator, checker: path.join(root, "tools/web/check-blender-editor-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-01E", parentTask: "M15-01D", enablingTask: false, parityStateChange: false, runtime: "BLENDER_5_2_EDITOR", operation: "BLENDER_EDITOR_INVENTORY", artifacts, nextTask: "M15-01F" }, null, 2)}\n`);
|
|
}
|
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
assert.deepEqual({ task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { task: "M15-01E", parentTask: "M15-01D", nextTask: "M15-01F" });
|
|
for (const artifact of Object.values(manifest.artifacts)) assert.equal(fileSha256(path.join(root, artifact.path)), artifact.sha256, artifact.path);
|
|
process.stdout.write(`blender-editor-inventory-ok areas=${inventory.summary.areaTypeCount} regions=${inventory.summary.regionTypeCount} keymaps=${inventory.summary.keymapCount} items=${inventory.summary.keymapItemCount} inventory=${sha256(expectedBytes)} next=${manifest.nextTask}\n`);
|
|
} finally {
|
|
fs.rmSync(temporary, { recursive: true, force: true });
|
|
}
|