Files
workinf_Blender_Wasm/web/tests/unit/nanovdb-render-golden.test.mjs
mes123456 0fe8d2bb56
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
Advance M8-M11 parity workflows
2026-08-17 04:37:07 -04:00

53 lines
2.3 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import test from "node:test";
import ts from "typescript";
const repoRoot = path.resolve(import.meta.dirname, "../../..");
const sourcePath = path.join(repoRoot, "web/protocol/nanovdb-render-golden.ts");
const source = fs.readFileSync(sourcePath, "utf8").replace('import type { ErrorCode } from "./error";\n', "");
const transpiled = ts.transpileModule(source, {
compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 },
fileName: sourcePath,
reportDiagnostics: true,
});
assert.deepEqual(transpiled.diagnostics, []);
const golden = await import("data:text/javascript;base64," + Buffer.from(transpiled.outputText).toString("base64"));
const thresholds = { maxChannelError: 2, meanAbsoluteError: 0.5, rmsError: 1, alphaCoverageDeltaRatio: 0.25 };
test("M8-19 accepts a bounded RGBA8 desktop/WebGPU difference", () => {
const reference = Uint8Array.from([0, 10, 20, 0, 100, 110, 120, 255]);
const actual = Uint8Array.from([0, 11, 18, 0, 101, 110, 120, 255]);
assert.deepEqual(golden.compareNanoVDBRenderGolden(reference, actual, thresholds), {
schemaVersion: 1,
status: "READY",
pixelCount: 2,
comparedChannels: 8,
maxChannelError: 2,
meanAbsoluteError: 0.5,
rmsError: Math.sqrt(6 / 8),
referenceAlphaPixels: 1,
actualAlphaPixels: 1,
alphaCoverageDeltaRatio: 0,
thresholds,
errorCode: null,
});
});
test("M8-19 blocks channel and alpha coverage drift with a stable code", () => {
const reference = Uint8Array.from([0, 0, 0, 0, 10, 10, 10, 255]);
const actual = Uint8Array.from([9, 0, 0, 255, 10, 10, 10, 255]);
const result = golden.compareNanoVDBRenderGolden(reference, actual, thresholds);
assert.equal(result.status, "BLOCKED");
assert.equal(result.errorCode, "NANOVDB_GOLDEN_MISMATCH");
assert.equal(result.maxChannelError, 255);
assert.equal(result.alphaCoverageDeltaRatio, 0.5);
for (const args of [
[new Uint8Array(), new Uint8Array(), thresholds],
[new Uint8Array(4), new Uint8Array(8), thresholds],
[new Uint8Array(3), new Uint8Array(3), thresholds],
[new Uint8Array(4), new Uint8Array(4), { ...thresholds, rmsError: -1 }],
]) assert.throws(() => golden.compareNanoVDBRenderGolden(...args), /NANOVDB_INVALID_ARGUMENT/);
});