55 lines
3.3 KiB
JavaScript
55 lines
3.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
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-06D/manifest.json"), "utf8"));
|
|
const report = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M12-06D/web-loss-report.json"), "utf8"));
|
|
const parent = JSON.parse(fs.readFileSync(path.join(root, "tests/golden/M12-06C/desktop-main-report.json"), "utf8"));
|
|
const sha256 = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
|
|
const fileHash = (file) => sha256(fs.readFileSync(file));
|
|
|
|
assert.deepEqual(
|
|
{ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask },
|
|
{ schemaVersion: 1, task: "M12-06D", parentTask: "M12-06C", nextTask: "M12-06E" },
|
|
);
|
|
assert.deepEqual(
|
|
{ schemaVersion: report.schemaVersion, task: report.task, operation: report.operation, fixtureCount: report.fixtureCount, nextTask: report.nextTask },
|
|
{ schemaVersion: 1, task: "M12-06D", operation: "WEB_GLB_EXPORT_LOSS_REPORT", fixtureCount: 5, nextTask: "M12-06E" },
|
|
);
|
|
assert.equal(fileHash(path.join(root, "tests/golden/M12-06C/manifest.json")), manifest.artifacts.parentManifest.sha256);
|
|
for (const artifact of Object.values(manifest.artifacts)) {
|
|
const file = path.join(root, artifact.path);
|
|
assert.ok(fs.existsSync(file), `missing artifact ${artifact.path}`);
|
|
assert.equal(fileHash(file), artifact.sha256, `hash mismatch ${artifact.path}`);
|
|
}
|
|
|
|
const expectedIds = ["mesh", "pbr", "uv", "skin", "animation"];
|
|
assert.deepEqual(report.fixtures.map((fixture) => fixture.fixtureId), expectedIds);
|
|
for (const fixture of report.fixtures) {
|
|
const source = parent.fixtures.find((candidate) => candidate.id === fixture.fixtureId);
|
|
assert.ok(source, `${fixture.fixtureId} is absent from M12-06C`);
|
|
assert.equal(fixture.sourceBlendSha256, source.blend.sha256, `${fixture.fixtureId} source blend drift`);
|
|
const losses = fixture.lossReport.losses;
|
|
assert.deepEqual(losses, [...losses].sort((left, right) =>
|
|
left.code.localeCompare(right.code) || left.severity.localeCompare(right.severity) ||
|
|
(left.id ?? "").localeCompare(right.id ?? "") || left.message.localeCompare(right.message)));
|
|
assert.equal(fixture.lossReport.errorCount, losses.filter((loss) => loss.severity === "error").length);
|
|
assert.equal(fixture.lossReport.warningCount, losses.filter((loss) => loss.severity === "warning").length);
|
|
if (fixture.fixtureId === "mesh") {
|
|
assert.equal(fixture.lossReport.canExport, false);
|
|
assert.deepEqual(losses.map((loss) => loss.code), ["LINKED_MATERIAL_INPUT_UNEVALUATED", "SHADER_GRAPH_UNMAPPABLE"]);
|
|
assert.equal(fixture.output, null);
|
|
}
|
|
else {
|
|
assert.equal(fixture.lossReport.canExport, true);
|
|
assert.equal(fixture.lossReport.errorCount, 0);
|
|
assert.ok(fixture.output?.byteLength > 128);
|
|
assert.match(fixture.output.sha256, /^[0-9a-f]{64}$/);
|
|
}
|
|
}
|
|
|
|
process.stdout.write(`glb-loss-report-ok fixtures=${report.fixtureCount} blocked=mesh warnings=${report.fixtures.reduce((sum, fixture) => sum + fixture.lossReport.warningCount, 0)} deterministic=true next=${manifest.nextTask}\n`);
|