test: establish storage adapter contracts

This commit is contained in:
vorotamoroz
2026-07-12 08:52:43 +00:00
parent a60932d9e4
commit dbb8d2be22
5 changed files with 186 additions and 10 deletions
@@ -2,9 +2,10 @@ import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { storageAdapterContractCases } from "@/apps/storageAdapterContract";
import { NodeStorageAdapter } from "./NodeStorageAdapter";
describe("NodeStorageAdapter binary I/O", () => {
describe("NodeStorageAdapter", () => {
const tempDirs: string[] = [];
async function createAdapter() {
@@ -17,6 +18,12 @@ describe("NodeStorageAdapter binary I/O", () => {
await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
});
for (const contractCase of storageAdapterContractCases) {
it(contractCase.name, async () => {
await contractCase.run(await createAdapter());
});
}
it("writes and reads binary data without corruption", async () => {
const adapter = await createAdapter();
const expected = Uint8Array.from([0x00, 0x7f, 0x80, 0xff, 0x42]);
@@ -37,4 +44,7 @@ describe("NodeStorageAdapter binary I/O", () => {
expect(result.byteLength).toBe(expected.byteLength);
expect(Array.from(new Uint8Array(result))).toEqual([0x10, 0x20, 0x30]);
});
it.todo("rejects paths that escape the configured root");
it.todo("rejects removing the configured root through an empty path");
});