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 { execFileSync } from "node:child_process"; import { fileURLToPath } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); const fixtureRoot = path.join(root, "tests/files/web/m12_library_override_v1"); const generator = path.join(root, "tools/web/generate-library-override-fixture.py"); const blender = process.env.BLENDER_BIN ?? path.join(root, "build_blender_5.2.0/bin/blender"); const read = (relativePath) => fs.readFileSync(path.join(root, relativePath)); const sha256 = (value) => crypto.createHash("sha256").update(value).digest("hex"); const manifest = JSON.parse(read("tests/golden/M12-03J/manifest.json")); const report = JSON.parse(read("tests/golden/M12-03J/desktop-override-report.json")); assert.equal(manifest.task, "M12-03J"); assert.equal(manifest.parentTask, "M12-03I"); assert.equal(manifest.nextTask, "M12-03K"); assert.equal(report.schemaVersion, 1); assert.equal(report.task, "M12-03J"); assert.equal(report.operation, "LIBRARY_OVERRIDE"); assert.equal(report.blenderVersion, "5.2.0"); assert.deepEqual(report.selectedRoots, ["Object/M12 Override Object"]); assert.deepEqual(report.overrideGraph.reference, { dataBlockId: "Object/M12 Override Object", idType: "OBJECT", library: "m12_override_source.blend", owner: "SOURCE_LIBRARY", readOnly: true, isLibraryOverride: false, }); assert.deepEqual(report.overrideGraph.local, { dataBlockId: "Object/M12 Override Object", idType: "OBJECT", library: null, owner: "LOCAL_OVERRIDE", projectId: "m12-03j-project", readOnly: false, referenceSourceDataBlockId: "Object/M12 Override Object", hierarchyRootDataBlockId: "Object/M12 Override Object", isLibraryOverride: true, }); assert.deepEqual(report.overrideGraph.propertyOverride, { index: 0, operationCount: 1, propertyCount: 1, rnaPath: "[\"m12_override_value\"]", value: 2.5, }); assert.equal(report.overrideGraph.sourceMarker, "M12-03J"); for (const artifact of Object.values(manifest.artifacts)) assert.equal(sha256(read(artifact.path)), artifact.sha256, artifact.path); assert.equal(sha256(fs.readFileSync(path.join(fixtureRoot, report.source.file))), report.source.sha256); assert.equal(sha256(fs.readFileSync(path.join(fixtureRoot, report.target.file))), report.target.sha256); const normalize = (value) => ({ ...value, source: { ...value.source, sha256: "" }, target: { ...value.target, sha256: "" }, }); const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "m12-library-override-")); try { const generatedRoot = path.join(temporary, "files"); const generatedReportPath = path.join(temporary, "report.json"); const output = execFileSync(blender, ["--background", "--factory-startup", "--python", generator, "--", generatedRoot, generatedReportPath], { cwd: root, encoding: "utf8" }); assert.match(output, /library-override-fixture-ok roots=1/); assert.match(output, /owner=LOCAL_OVERRIDE/); const generated = JSON.parse(fs.readFileSync(generatedReportPath, "utf8")); assert.deepEqual(normalize(generated), normalize(report)); assert.equal(sha256(fs.readFileSync(path.join(generatedRoot, generated.source.file))), generated.source.sha256); assert.equal(sha256(fs.readFileSync(path.join(generatedRoot, generated.target.file))), generated.target.sha256); } finally { fs.rmSync(temporary, { recursive: true, force: true }); } process.stdout.write( `library-override-fixture-check-ok roots=${report.selectedRoots.length} ` + `reference=${report.overrideGraph.reference.library} owner=${report.overrideGraph.local.owner} ` + `path=${report.overrideGraph.propertyOverride.rnaPath} next=${report.nextTask}\n`, );