/** * Task #242 (B1) — data-foundation interface test. */ import { test } from "node:test"; import assert from "node:assert/strict"; import { writeRow, readRows } from "../data-foundation/index.ts"; const SKIP_DB = !process.env["DATABASE_URL"]; test( "data-foundation: writeRow then readRows returns the row", { skip: SKIP_DB && "DATABASE_URL not set" }, async () => { const capabilityId = `cap_b1test_${Math.random().toString(16).slice(2, 8)}`; const w = await writeRow({ capabilityId, kind: "param_fingerprint", payload: { hash: "abc123", value: 42 }, sourceRunId: "src-1", }); assert.ok(w.id); const rows = await readRows({ capabilityId, kind: "param_fingerprint" }); assert.equal(rows.length, 1); assert.equal(rows[0]!.id, w.id); assert.equal(rows[0]!.kind, "param_fingerprint"); assert.equal((rows[0]!.payload as { hash: string }).hash, "abc123"); // cleanup const { db, capabilityDataFoundation } = await import("@workspace/db"); const { eq } = await import("drizzle-orm"); await db .delete(capabilityDataFoundation) .where(eq(capabilityDataFoundation.id, w.id)); }, ); test("data-foundation: readRows excludeSelf is reserved (throws)", async () => { await assert.rejects( () => readRows({ capabilityId: "x", excludeSelf: true }), /reserved for B7/, ); }); test("data-foundation: writeRow validates required fields", async () => { await assert.rejects( () => writeRow({ capabilityId: "", kind: "x", payload: {}, }), /capabilityId required/, ); await assert.rejects( () => writeRow({ capabilityId: "cap_x", kind: "", payload: {}, }), /kind required/, ); });