87 lines
4.8 KiB
JavaScript
87 lines
4.8 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-07A/manifest.json");
|
|
const reportPath = path.join(root, "tests/golden/M12-07A/desktop-fixture.json");
|
|
const fixtureRoot = path.join(root, "tests/files/web/m12_obj_desktop_v1");
|
|
const generator = path.join(root, "tools/web/generate-obj-single-mesh-fixture.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-07A", parentTask: "M12-06G", nextTask: "M12-07B" },
|
|
);
|
|
assert.deepEqual(
|
|
{ schemaVersion: report.schemaVersion, task: report.task, operation: report.operation, nextTask: report.nextTask },
|
|
{ schemaVersion: 1, task: "M12-07A", operation: "DESKTOP_OBJ_SINGLE_MESH_FIXTURE", nextTask: "M12-07B" },
|
|
);
|
|
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/wavefront_obj");
|
|
assert.equal(report.operator, "wm.obj_export");
|
|
assert.deepEqual(report.settings, {
|
|
forwardAxis: "NEGATIVE_Z",
|
|
upAxis: "Y",
|
|
globalScale: 1,
|
|
exportUV: true,
|
|
exportNormals: true,
|
|
exportMaterials: true,
|
|
exportMaterialGroups: true,
|
|
});
|
|
assert.deepEqual(report.semantic.materialLibraries, ["single-mesh.mtl"]);
|
|
assert.deepEqual(report.semantic.objects, ["M12_OBJ_Single_Mesh"]);
|
|
assert.equal(report.semantic.positions.length, 4);
|
|
assert.equal(report.semantic.texcoords.length, 4);
|
|
assert.equal(report.semantic.normals.length, 1);
|
|
assert.equal(report.semantic.faces.length, 2);
|
|
assert.equal(report.semantic.materials.length, 2);
|
|
assert.deepEqual(report.semantic.faces.map((face) => face.vertices.length), [3, 3]);
|
|
assert.deepEqual(report.semantic.faces.map((face) => face.material), ["M12_OBJ_Red", "M12_OBJ_Blue"]);
|
|
assert.deepEqual(report.semantic.faces.map((face) => face.groups.length), [1, 1]);
|
|
assert.notEqual(report.semantic.faces[0].groups[0], report.semantic.faces[1].groups[0]);
|
|
assert.ok(report.semantic.faces.flatMap((face) => face.vertices).every((vertex) => vertex.position && vertex.texcoord && vertex.normal));
|
|
assert.deepEqual(report.semantic.materials.map((material) => material.name), ["M12_OBJ_Blue", "M12_OBJ_Red"]);
|
|
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 temporary = fs.mkdtempSync(path.join(os.tmpdir(), "m12-07a-obj-"));
|
|
try {
|
|
const regeneratedReport = path.join(temporary, "desktop-fixture.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, "OBJ semantic 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(`obj-single-mesh-fixture-ok vertices=${report.semantic.positions.length} normals=${report.semantic.normals.length} uv=${report.semantic.texcoords.length} faces=${report.semantic.faces.length} materials=${report.semantic.materials.length} deterministic=true next=${manifest.nextTask}\n`);
|