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 { spawnSync } from "node:child_process"; import { fileURLToPath } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const manifestPath = path.join(root, "tests/golden/M12-07G/manifest.json"); const reportPath = path.join(root, "tests/golden/M12-07G/capability-report.json"); const fixtureRoot = path.join(root, "tests/files/web/m12_ply_capability_v1"); const generator = path.join(root, "tools/web/generate-ply-capability-fixtures.py"); const blender = process.env.BLENDER_BIN ?? path.join(root, "build_blender_5.2.0/bin/blender"); const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex"); const fileHash = (file) => sha256(fs.readFileSync(file)); const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8")); const manifest = readJson(manifestPath); const report = readJson(reportPath); assert.deepEqual({ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { schemaVersion: 1, task: "M12-07G", parentTask: "M12-07F", nextTask: "M12-07H" }); assert.deepEqual({ schemaVersion: report.schemaVersion, task: report.task, operation: report.operation, nextTask: report.nextTask }, { schemaVersion: 1, task: "M12-07G", operation: "DESKTOP_PLY_ASCII_BINARY_LE_CAPABILITY", nextTask: "M12-07H" }); for (const artifact of Object.values(manifest.artifacts)) { if (artifact.path === manifestPath) continue; const absolute = path.join(root, artifact.path); assert.ok(fs.existsSync(absolute), `missing artifact ${artifact.path}`); assert.equal(fileHash(absolute), artifact.sha256, `hash mismatch ${artifact.path}`); } const inventory = readJson(path.join(root, "tests/golden/M12-05A/format-inventory.json")); for (const key of ["blenderVersion", "versionTuple", "buildDate", "buildTime", "buildHash", "buildBranch", "buildPlatform", "buildType", "binarySha256"]) assert.deepEqual(report.runtime[key], inventory.runtime[key], `runtime drift in ${key}`); assert.equal(report.sourceAnchor, "blender-5.2.0/source/blender/io/ply"); assert.equal(report.operator, "wm.ply_export"); assert.deepEqual(report.variants.map((variant) => variant.id), ["PLY_ASCII", "PLY_BINARY_LITTLE_ENDIAN"]); assert.equal(report.variants[0].semantic.format, "ascii"); assert.equal(report.variants[1].semantic.format, "binary_little_endian"); for (const variant of report.variants) { assert.deepEqual(variant.semantic.elements, [{ name: "vertex", count: 4 }, { name: "face", count: 2 }]); const file = path.join(fixtureRoot, variant.file); assert.equal(fileHash(file), report.files.find((candidate) => candidate.name === variant.file).sha256); } const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "m12-07g-ply-")); try { const regeneratedReport = path.join(temporary, "capability-report.json"); const result = spawnSync(blender, ["-b", "--factory-startup", "--python", generator, "--", temporary, regeneratedReport], { cwd: root, encoding: "utf8", maxBuffer: 20 * 1024 * 1024 }); assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`); assert.deepEqual(readJson(regeneratedReport), report, "PLY capability report is not deterministic"); for (const file of report.files) assert.deepEqual(fs.readFileSync(path.join(temporary, file.name)), fs.readFileSync(path.join(fixtureRoot, file.name)), `${file.name} bytes are not deterministic`); } finally { fs.rmSync(temporary, { recursive: true, force: true }); } process.stdout.write(`ply-capability-fixtures-ok ascii=ascii binary=binary_little_endian vertices=4 faces=2 deterministic=true next=${manifest.nextTask}\n`);