// The module's migration is its own file and exactly `schemaStatements()` over the agent runtime's // two entities (decision AT-D20). import { readFileSync } from "node:fs" import { AGENT_ENTITIES } from "@conusai-kit/agent" import { schemaStatements } from "@conusai-kit/data-kysely" import { describe, expect, it } from "vitest" import { agentModule } from "../index.js" function tablesOf(entities: Parameters[0]): string { const kernel = schemaStatements([]).length return `${schemaStatements(entities) .slice(kernel) .map((statement) => `${statement};`) .join("\n\n")}\n` } describe("the migration of the agent module", () => { it("is its own file, exactly its two tables", async () => { await expect( `-- SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0\n${tablesOf(AGENT_ENTITIES)}`, ).toMatchFileSnapshot("../migrations/0001_agent.sql") }) it("is declared by the manifest, and every table is row-level secured", () => { expect(agentModule.migrations).toEqual({ postgres: "migrations" }) const sql = readFileSync(new URL("../migrations/0001_agent.sql", import.meta.url), "utf8") for (const table of ["agent_run", "agent_step"]) { expect(sql).toContain(`create table "${table}"`) expect(sql).toContain(`alter table "${table}" force row level security`) } }) })