36 lines
2.0 KiB
JavaScript
36 lines
2.0 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 "../../node_modules/typescript/lib/typescript.js";
|
|
|
|
const root = path.resolve(import.meta.dirname, "../../..");
|
|
const sourcePath = path.join(root, "web/protocol/device-budget.ts");
|
|
const source = fs.readFileSync(sourcePath, "utf8");
|
|
const output = ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.ES2022, target: ts.ScriptTarget.ES2022 }, fileName: sourcePath, reportDiagnostics: true });
|
|
assert.deepEqual(output.diagnostics, []);
|
|
const budget = await import(`data:text/javascript;base64,${Buffer.from(output.outputText).toString("base64")}`);
|
|
const base = { schemaVersion: 1, identitySha256: "a".repeat(64), webgl2: { status: "PASS", renderer: "ANGLE NVIDIA", vendor: "NVIDIA" }, webgpu: { status: "PASS", description: "NVIDIA RTX", isFallbackAdapter: false }, hardwareConcurrency: 16, deviceMemory: 16 };
|
|
|
|
test("M14-04A selects HIGH only from trusted observed capability", () => {
|
|
const result = budget.selectDeviceBudget(base);
|
|
assert.equal(result.tier, "HIGH");
|
|
assert.equal(result.reason, "HIGH_CAPABILITY");
|
|
assert.equal(result.limits.maxTextureGPUBytes, 1024 * 1024 * 1024);
|
|
});
|
|
|
|
test("M14-04A fails closed for missing WebGPU, SwiftShader, fallback and invalid identity", () => {
|
|
for (const observation of [
|
|
{ ...base, webgpu: { status: "BLOCKED" } },
|
|
{ ...base, webgl2: { ...base.webgl2, renderer: "ANGLE SwiftShader" } },
|
|
{ ...base, webgpu: { ...base.webgpu, isFallbackAdapter: true } },
|
|
{ ...base, deviceMemory: null },
|
|
]) assert.equal(budget.selectDeviceBudget(observation).tier, "CONSERVATIVE");
|
|
assert.throws(() => budget.selectDeviceBudget({ ...base, identitySha256: "bad" }), /DEVICE_BUDGET_IDENTITY_INVALID/);
|
|
});
|
|
|
|
test("M14-04A exposes fixed limits and never expands an unknown tier", () => {
|
|
assert.equal(budget.deviceBudgetLimits("CONSERVATIVE").maxLights, 8);
|
|
assert.throws(() => budget.deviceBudgetLimits("UNKNOWN"), /DEVICE_BUDGET_TIER_INVALID/);
|
|
});
|