Files
workinf_Blender_Wasm/tools/web/check-stl-capability-fixtures.mjs
mes123456 380cbed4ff
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
Checkpoint web parity through Chromium input tasks
2026-08-19 10:39:03 -04:00

76 lines
4.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 { 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-07D/manifest.json");
const reportPath = path.join(root, "tests/golden/M12-07D/capability-report.json");
const fixtureRoot = path.join(root, "tests/files/web/m12_stl_capability_v1");
const generator = path.join(root, "tools/web/generate-stl-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-07D", parentTask: "M12-07C", nextTask: "M12-07E" },
);
assert.deepEqual(
{ schemaVersion: report.schemaVersion, task: report.task, operation: report.operation, nextTask: report.nextTask },
{ schemaVersion: 1, task: "M12-07D", operation: "DESKTOP_STL_BINARY_ASCII_CAPABILITY", nextTask: "M12-07E" },
);
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/stl");
assert.equal(report.operator, "wm.stl_export");
assert.deepEqual(report.variants.map((variant) => variant.id), ["STL_BINARY", "STL_ASCII"]);
assert.equal(report.variants[0].asciiFormat, false);
assert.equal(report.variants[0].semantic.format, "STL_BINARY");
assert.equal(report.variants[0].semantic.triangleCount, 2);
assert.equal(report.variants[0].semantic.byteLength, 84 + 2 * 50);
assert.equal(report.variants[1].asciiFormat, true);
assert.equal(report.variants[1].semantic.format, "STL_ASCII");
assert.equal(report.variants[1].semantic.facetCount, 2);
assert.equal(report.variants[1].semantic.vertexCount, 6);
for (const file of report.files) {
const absolute = path.join(fixtureRoot, file.name);
assert.equal(fileHash(absolute), file.sha256, `${file.name} hash`);
assert.equal(fs.statSync(absolute).size, file.byteLength, `${file.name} byte length`);
}
const binary = fs.readFileSync(path.join(fixtureRoot, "capability-binary.stl"));
assert.equal(binary.readUInt32LE(80), 2);
assert.equal(binary.length, 184);
const ascii = fs.readFileSync(path.join(fixtureRoot, "capability-ascii.stl"), "utf8");
assert.match(ascii, /^solid /);
assert.equal((ascii.match(/^facet normal/gm) ?? []).length, 2);
assert.equal((ascii.match(/^ vertex /gm) ?? []).length, 6);
assert.match(ascii, /\nendsolid /);
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "m12-07d-stl-"));
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, "STL 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(`stl-capability-fixtures-ok binaryTriangles=${report.variants[0].semantic.triangleCount} asciiFacets=${report.variants[1].semantic.facetCount} deterministic=true next=${manifest.nextTask}\n`);