Advance M8-M11 parity workflows
This commit is contained in:
29
web/tests/unit/storage-budget.test.mjs
Normal file
29
web/tests/unit/storage-budget.test.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
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/storage-budget.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 { createStorageBudget, formatStorageBytes } = await import(moduleUrl);
|
||||
|
||||
test("M7-11 storage budget reports stable category totals", () => {
|
||||
const budget = createStorageBudget("budget", { projectBytes: 10, snapshotBytes: 20, lodBytes: 30, mediaBytes: 40, vdbBytes: 50 });
|
||||
assert.deepEqual(budget, { schemaVersion: 1, projectId: "budget", projectBytes: 10, snapshotBytes: 20, lodBytes: 30, mediaBytes: 40, vdbBytes: 50, totalBytes: 150 });
|
||||
assert.equal(formatStorageBytes(1024), "1.0 KiB");
|
||||
assert.equal(formatStorageBytes(1024 * 1024), "1.0 MiB");
|
||||
});
|
||||
|
||||
test("M7-11 storage budget rejects invalid or overflowing categories", () => {
|
||||
assert.throws(() => createStorageBudget("budget", { mediaBytes: -1 }), /STORAGE_BUDGET_INVALID/);
|
||||
assert.throws(() => createStorageBudget("budget", { projectBytes: Number.MAX_SAFE_INTEGER, mediaBytes: Number.MAX_SAFE_INTEGER }), /STORAGE_BUDGET_INVALID/);
|
||||
assert.throws(() => formatStorageBytes(-1), /STORAGE_BUDGET_INVALID/);
|
||||
});
|
||||
Reference in New Issue
Block a user