Files
workinf_Blender_Wasm/tools/web/check-asset-preview-display.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

49 lines
2.5 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 manifest = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M12-02H/manifest.json"), "utf8"));
const report = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M12-02H/desktop-report.json"), "utf8"));
const content = path.join(root, "tests/golden/M12-02B/preview.png");
const generator = path.join(root, "tools/web/generate-asset-preview-identity.py");
const source = path.join(root, "tests/files/web/media/sequencer-frame.png");
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");
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "asset-preview-display-"));
try {
const regenerated = path.join(temporary, "preview.png");
const raw = path.join(temporary, "preview.rgba8");
const output = execFileSync(blender, ["--background", "--factory-startup", "--python", generator, "--", source, regenerated], {
cwd: root,
encoding: "utf8",
});
assert.match(output, /asset-preview-generated width=8 height=8/);
assert.match(execFileSync(blender, ["--version"], { encoding: "utf8" }), /^Blender 5\.2\.0 LTS/m);
assert.equal(sha256(fs.readFileSync(regenerated)), report.contentSha256);
execFileSync("magick", [regenerated, "-depth", "8", `RGBA:${raw}`], { cwd: root, stdio: "pipe" });
const pixels = fs.readFileSync(raw);
assert.equal(pixels.byteLength, report.pixelCount * 4);
assert.equal(sha256(pixels), report.rgbaSha256);
const unique = new Set();
for (let offset = 0; offset < pixels.byteLength; offset += 4) {
const pixel = Array.from(pixels.subarray(offset, offset + 4));
unique.add(pixel.join(","));
assert.deepEqual(pixel, report.referencePixel);
}
assert.equal(unique.size, report.uniquePixelCount);
for (const artifact of Object.values(manifest.artifacts)) {
assert.equal(sha256(fs.readFileSync(path.join(root, artifact.path))), artifact.sha256, artifact.path);
}
}
finally {
fs.rmSync(temporary, { recursive: true, force: true });
}
process.stdout.write(`asset-preview-display-desktop-ok size=${report.width}x${report.height} rgba=${report.rgbaSha256} next=${manifest.nextTask}\n`);