42 lines
1.4 KiB
JavaScript
42 lines
1.4 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-device-recovery.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 recovery = await import(moduleUrl);
|
|
|
|
test("M8-15 deterministically bounds visible-page replay by resident capacity", () => {
|
|
assert.deepEqual(recovery.planNanoVDBDeviceLossReplay([3, 1, 3, 2], 4, 2), {
|
|
schemaVersion: 1,
|
|
visiblePageIds: [1, 2, 3],
|
|
replayedPageIds: [1, 2],
|
|
skippedPageIds: [3],
|
|
pageCount: 4,
|
|
residentPageCapacity: 2,
|
|
});
|
|
});
|
|
|
|
test("M8-15 rejects invalid replay bounds and visible page IDs", () => {
|
|
for (const args of [
|
|
[[0], 0, 1],
|
|
[[0], 8193, 1],
|
|
[[0], 2, 0],
|
|
[[0], 2, 3],
|
|
[[-1], 2, 1],
|
|
[[2], 2, 1],
|
|
[[0.5], 2, 1],
|
|
]) {
|
|
assert.throws(() => recovery.planNanoVDBDeviceLossReplay(...args), /NANOVDB_INVALID_ARGUMENT/);
|
|
}
|
|
});
|