pi-mono/packages/durable/test/storage-runtime-boundary.test.ts
Mario Zechner 5901c9b9e5 feat: add durable SQLite storage backend
Add the portable SQLite storage core, Node adapter, versioned migrations, conformance coverage, and storage benchmarks.
2026-09-22 17:46:42 +02:00

34 lines
1.3 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const sourceRoot = fileURLToPath(new URL("../src", import.meta.url));
async function sourceGraph(entry: string): Promise<Set<string>> {
const visited = new Set<string>();
const pending = [resolve(sourceRoot, entry)];
while (pending.length > 0) {
const path = pending.pop()!;
if (visited.has(path)) continue;
visited.add(path);
const source = await readFile(path, "utf8");
expect(source, `${path} imports a Node built-in`).not.toMatch(/(?:from\s+|import\s*)["']node:/);
for (const match of source.matchAll(/(?:from\s+|import\s*)["'](\.[^"']+)["']/g)) {
pending.push(resolve(dirname(path), match[1]));
}
}
return visited;
}
describe("durable storage runtime boundaries", () => {
it("keeps the package root free of SQLite and Node imports", async () => {
const graph = await sourceGraph("index.ts");
expect([...graph].some((path) => path.includes("/storage/sqlite/"))).toBe(false);
});
it("keeps the portable SQLite subpath free of Node imports", async () => {
const graph = await sourceGraph("storage/sqlite/index.ts");
expect([...graph].some((path) => path.endsWith("/storage/sqlite/node.ts"))).toBe(false);
});
});