import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { TABLES } from "../protocol/index.mjs"; import { CLOUD_CORE_MIGRATIONS, FROZEN_CLOUD_CORE_TABLES, assertFrozenCloudCoreTables } from "./schema.mjs"; const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); test("cloud core schema keeps the frozen L0 table names", () => { assert.deepEqual(FROZEN_CLOUD_CORE_TABLES, TABLES); assertFrozenCloudCoreTables(); assert.equal(CLOUD_CORE_MIGRATIONS[0].connectsToDatabase, false); }); test("initial migration skeleton declares every frozen table", async () => { const sql = await readFile(path.join(repoRoot, "internal/db/migrations/0001_cloud_core_skeleton.sql"), "utf8"); for (const table of TABLES) { assert.match(sql, new RegExp(`CREATE TABLE IF NOT EXISTS ${table}\\b`), `missing ${table}`); } assert.match(sql, /\brequest_id\b/); assert.match(sql, /\bactor\b/); assert.match(sql, /\bsource\b/); assert.match(sql, /\boperation\b/); assert.match(sql, /\btarget\b/); assert.match(sql, /\bresult\b/); assert.match(sql, /\btimestamp\b/); });