Files
Ekklesia/packages/module-database/tests/architecture.test.ts
T
ekklesia 49b4d4165d
CI / verify (pull_request) Successful in 1m0s
CI / infrastructure-smoke (pull_request) Successful in 36s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / image-build (pull_request) Successful in 23s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m30s
feat: deliver module database ABI by manifest
2026-10-07 17:29:32 -05:00

49 lines
2.1 KiB
TypeScript

import { readFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const workspaceRoot = path.resolve(packageRoot, "..", "..");
async function text(relative: string): Promise<string> {
return readFile(path.resolve(workspaceRoot, relative), "utf8");
}
describe("the module-side database architecture", () => {
it("keeps the Drizzle adapter free of Core, pg, and Core-owned Drizzle types", async () => {
const source = await text("packages/module-database/src/drizzle.ts");
expect(source).not.toMatch(/@ekklesia\/core|from ["']pg["']|node-postgres/u);
expect(source).not.toMatch(/NodePgDatabase|NodePgTransaction/u);
expect(source).toContain("@ekklesia/contracts");
expect(source).toContain("drizzle-orm/pg-proxy");
});
it("keeps ABI v1 contracts free of ORM imports", async () => {
for (const file of ["module-database-abi.ts", "module-schema-metadata.ts"]) {
const source = await text(`packages/contracts/src/${file}`);
expect(source).not.toMatch(/(?:import|export).*drizzle-orm/u);
expect(source).not.toMatch(/(?:import|export).*kysely/u);
expect(source).not.toMatch(/(?:import|export).*\bpg\b/u);
}
});
it("makes Drizzle an optional ranged peer and keeps raw SQL independent from it", async () => {
const manifest = JSON.parse(await text("packages/module-database/package.json")) as Record<
string,
Record<string, string>
>;
expect(manifest.dependencies).not.toHaveProperty("drizzle-orm");
expect(manifest.peerDependencies?.["drizzle-orm"]).toBe(">=0.45.2 <0.46.0");
expect(manifest.peerDependenciesMeta?.["drizzle-orm"]).toEqual({ optional: true });
const rawSource = await text("packages/module-database/src/index.ts");
expect(rawSource).not.toContain("drizzle-orm");
});
it("does not introduce an adapter dependency into Core", async () => {
const manifest = await text("core/package.json");
expect(manifest).not.toContain("@ekklesia/module-database");
});
});