Files
workinf_Blender_Wasm/tools/web/check-library-append-fixture.mjs
mes123456 5a11045ca5
Some checks are pending
M6 deployable RC / quick (push) Waiting to run
M6 deployable RC / chromium (push) Blocked by required conditions
M6 deployable RC / release (push) Blocked by required conditions
Advance Blender 5.2 web parity through M12-03D
2026-08-17 17:30:27 -04:00

101 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 { execFileSync } from "node:child_process";
import { fileURLToPath } from "node:url";
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
const reportPath = path.join(root, "tests/golden/M12-03C/desktop-append-report.json");
const report = JSON.parse(fs.readFileSync(reportPath, "utf8"));
const manifest = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M12-03C/manifest.json"), "utf8"));
const fixtureRoot = path.join(root, "tests/files/web/m12_library_append_v1");
const generator = path.join(root, "tools/web/generate-library-append-fixture.py");
const blender = process.env.BLENDER_BIN ?? path.join(root, "build_blender_5.2.0/bin/blender");
const sha256 = (value) => crypto.createHash("sha256").update(value).digest("hex");
assert.equal(manifest.task, "M12-03C");
assert.equal(manifest.nextTask, "M12-03D");
for (const artifact of Object.values(manifest.artifacts)) {
assert.equal(sha256(fs.readFileSync(path.join(root, artifact.path))), artifact.sha256, artifact.path);
}
assert.equal(report.schemaVersion, 1);
assert.equal(report.task, "M12-03C");
assert.equal(report.operation, "APPEND");
assert.equal(report.blenderVersion, "5.2.0");
assert.equal(report.nextTask, "M12-03D");
assert.deepEqual(report.selectedRoots, ["Object/M12 Append Object"]);
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);
assert.deepEqual(report.sourceGraph, report.appendedGraph);
assert.deepEqual(report.appendedGraph.edges, [
{ from: "Object/M12 Append Object", relation: "OBJECT_DATA", to: "Mesh/M12 Append Mesh" },
{ from: "Mesh/M12 Append Mesh", relation: "MATERIAL_SLOT[0]", to: "Material/M12 Append Material" },
{ from: "Material/M12 Append Material", relation: "NODE_IMAGE[M12 Append Image Node]", to: "Image/M12 Append Image" },
]);
assert.deepEqual(Object.keys(report.appendedGraph.ids).sort(), ["IMAGE", "MATERIAL", "MESH", "OBJECT"]);
for (const value of Object.values(report.appendedGraph.ids)) {
assert.equal(value.library, null);
assert.equal(value.isLibraryOverride, false);
}
assert.deepEqual(report.appendedGraph.geometry, {
edges: 4,
loops: 4,
materialSlots: ["M12 Append Material"],
polygons: 1,
uvLayers: ["UVMap"],
vertices: 4,
});
assert.deepEqual(report.appendedGraph.image.size, [2, 2]);
assert.equal(report.appendedGraph.image.channels, 4);
assert.equal(report.appendedGraph.image.colorspace, "sRGB");
assert.equal(report.appendedGraph.image.packed, true);
assert.match(report.appendedGraph.image.pixelFloat32Sha256, /^[a-f0-9]{64}$/);
assert.deepEqual(report.stableMapping.map((item) => [item.owner, item.readOnly]), [
["LOCAL_MAIN", false],
["LOCAL_MAIN", false],
["LOCAL_MAIN", false],
["LOCAL_MAIN", false],
]);
assert.deepEqual(report.stableMapping.map((item) => item.source), [
"Object/M12 Append Object",
"Mesh/M12 Append Mesh",
"Material/M12 Append Material",
"Image/M12 Append Image",
]);
assert.deepEqual(report.stableMapping.map((item) => item.local), report.stableMapping.map((item) => item.source));
const normalizeContainerHashes = (value) => ({
...value,
source: { ...value.source, sha256: "<SESSION_BOUND_BLEND_CONTAINER>" },
target: { ...value.target, sha256: "<SESSION_BOUND_BLEND_CONTAINER>" },
});
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "m12-library-append-"));
try {
const generatedFixtureRoot = path.join(temporary, "files");
const generatedReportPath = path.join(temporary, "report.json");
const output = execFileSync(blender, [
"--background",
"--factory-startup",
"--python",
generator,
"--",
generatedFixtureRoot,
generatedReportPath,
], { cwd: root, encoding: "utf8" });
assert.match(output, /library-append-fixture-ok roots=1 mapping=4/);
assert.match(output, /next=M12-03D/);
const generated = JSON.parse(fs.readFileSync(generatedReportPath, "utf8"));
assert.deepEqual(normalizeContainerHashes(generated), normalizeContainerHashes(report));
assert.equal(sha256(fs.readFileSync(path.join(generatedFixtureRoot, generated.source.file))), generated.source.sha256);
assert.equal(sha256(fs.readFileSync(path.join(generatedFixtureRoot, generated.target.file))), generated.target.sha256);
}
finally {
fs.rmSync(temporary, { recursive: true, force: true });
}
process.stdout.write(
`library-append-fixture-check-ok roots=${report.selectedRoots.length} mapping=${report.stableMapping.length} edges=${report.appendedGraph.edges.length} pixels=${report.appendedGraph.image.pixelFloat32Sha256} next=${report.nextTask}\n`,
);