Files
workinf_Blender_Wasm/web/tests/unit/nanovdb-progressive-redraw.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

48 lines
1.9 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-progressive-redraw.ts");
const transpiled = ts.transpileModule(fs.readFileSync(sourcePath, "utf8"), {
compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 },
fileName: sourcePath,
reportDiagnostics: true,
});
assert.deepEqual(transpiled.diagnostics, []);
const moduleUrl = "data:text/javascript;base64," + Buffer.from(transpiled.outputText).toString("base64");
const redraw = await import(moduleUrl);
test("M8-10 validates a bounded progressive redraw budget", () => {
assert.equal(redraw.NANOVDB_PROGRESSIVE_REDRAW_MAX_FRAMES, 32);
assert.equal(redraw.validateNanoVDBProgressiveRedrawLimit(1), 1);
assert.equal(redraw.validateNanoVDBProgressiveRedrawLimit(1024), 1024);
for (const value of [0, 1.5, 1025, Number.POSITIVE_INFINITY]) {
assert.throws(() => redraw.validateNanoVDBProgressiveRedrawLimit(value), /NANOVDB_INVALID_ARGUMENT/);
}
});
test("M8-10 caps repeated successful uploads with a stable error code", () => {
assert.deepEqual(redraw.consumeNanoVDBProgressiveRedrawBudget(0, 2), {
allowed: true,
redrawCount: 1,
capped: false,
errorCode: null,
});
assert.deepEqual(redraw.consumeNanoVDBProgressiveRedrawBudget(1, 2), {
allowed: true,
redrawCount: 2,
capped: true,
errorCode: "NANOVDB_PROGRESSIVE_REDRAW_LIMIT",
});
assert.deepEqual(redraw.consumeNanoVDBProgressiveRedrawBudget(2, 2), {
allowed: false,
redrawCount: 2,
capped: true,
errorCode: "NANOVDB_PROGRESSIVE_REDRAW_LIMIT",
});
assert.throws(() => redraw.consumeNanoVDBProgressiveRedrawBudget(-1, 2), /NANOVDB_INVALID_ARGUMENT/);
});