Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Successful in 10m21s
Docker images / frontend-image (push) Successful in 2m8s
Docker images / updater-image (push) Successful in 38s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / backend-image (push) Successful in 1m59s
Docker images / publish-release (push) Successful in 12s
Docker images / notify-webhook (push) Successful in 2s
248 lines
24 KiB
TypeScript
248 lines
24 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { createHash } from "node:crypto"
|
|
import { readFile } from "node:fs/promises"
|
|
import { fileURLToPath } from "node:url"
|
|
import { MIGRATION_MANIFEST, CURRENT_REQUIRED_TABLES, analyzeMigration, assessLegacyMigrationBaseline, inventoryMigrationDirectory, migrationManifestDigest, MigrationManifestError, parseMigrationStatements, validateMigrationFileSet, type LegacyBaselineEvidence, type MigrationReview } from "./migration-manifest.js"
|
|
|
|
let cases = 0
|
|
async function test(name: string, work: () => Promise<void> | void) { await work(); cases++; console.log("ok", name) }
|
|
const directory = fileURLToPath(new URL("../../drizzle/", import.meta.url))
|
|
const inventory = await inventoryMigrationDirectory(directory)
|
|
const reviewed = (source: string, extra: Partial<MigrationReview> = {}) => {
|
|
const bytes = Buffer.from(source), file = "9000_fixture.sql"
|
|
return () => analyzeMigration(file, bytes, { file, sha256: createHash("sha256").update(bytes).digest("hex"), transaction: "owner-transaction", selfMarker: false, opaqueBodies: 0, bodyReview: [], effects: ["Explicit inert fixture review"], ...extra })
|
|
}
|
|
await test("all 59 exact file pins and every top-level schema operation are inventoried", () => {
|
|
assert.equal(inventory.length, 59); assert.equal(MIGRATION_MANIFEST.length, 59)
|
|
assert.equal(inventory.filter(file => file.transaction === "owner-transaction").length, 17)
|
|
assert.equal(inventory.filter(file => file.transaction === "self-managed-single-transaction").length, 42)
|
|
assert(inventory.every(file => file.operations.length === file.statementCount && file.effects.length > 0))
|
|
let tables = new Set<string>()
|
|
for (const file of inventory) {
|
|
if (file.publicTableReset) tables = new Set(["schema_migrations"])
|
|
for (const operation of file.operations) if (operation.command === "CREATE" && operation.objectKind === "TABLE" && operation.target) tables.add(operation.target.replace(/^public\./, ""))
|
|
}
|
|
assert.deepEqual([...tables].sort(), [...CURRENT_REQUIRED_TABLES]); assert(CURRENT_REQUIRED_TABLES.length > 80)
|
|
})
|
|
await test("DO BEGIN and stored function BEGIN are never transaction boundaries", () => {
|
|
const compact = inventory.find(file => file.id === "0002_compact_schema")!
|
|
assert.equal(compact.transaction, "owner-transaction"); assert.equal(compact.topLevelTransactionControls.length, 0); assert.equal(compact.opaqueBodies[0].kind, "executed-do-body"); assert.equal(compact.publicTableReset, true)
|
|
assert(compact.effects.some(effect => effect.includes("DESTRUCTIVE")))
|
|
const endpoint = inventory.find(file => file.id === "0029_mcp_routing_sources")!
|
|
assert.equal(endpoint.topLevelTransactionControls.length, 2); assert.equal(endpoint.opaqueBodies.length, 2)
|
|
assert.deepEqual(endpoint.opaqueBodies.map(body => body.kind), ["stored-function-body", "executed-do-body"])
|
|
})
|
|
await test("0035 through 0059 have exact atomic file-owned terminal markers", () => {
|
|
assert.deepEqual(inventory.filter(file => file.selfMarker).map(file => file.id), ["0035_server_probe_journal", "0036_diagnostic_cancellations", "0037_server_probe_storage_v2", "0038_server_poll_journal_and_writer_guards", "0039_server_poll_storage", "0040_mcp_routing_reservations", "0041_server_poll_terminal_archives", "0042_server_poll_settings_epoch", "0043_mcp_routing_forward_charges", "0044_mcp_routing_manual_inverse_charges", "0045_mcp_operation_replay_tombstones", "0046_server_poll_operation_retirement", "0047_server_poll_retirement_claims", "0048_mcp_ordinary_retirement_claims", "0049_mcp_ordinary_telemetry_retirement", "0050_server_probe_retired_sources", "0051_server_probe_retirement_claims", "0052_server_probe_retired_gc", "0053_server_probe_terminal_proofs", "0054_mcp_geoip_retirement", "0055_mcp_backup_schedule_retirement", "0056_mcp_manual_inverse_recovery_v8", "0057_mcp_routing_charge_audit_index", "0058_internet_exchange", "0059_server_poll_journal_limits"])
|
|
for (const file of inventory.filter(file => file.selfMarker)) { assert.equal(file.selfMarker!.atomicWithAllFileEffects, true); assert.equal(file.selfMarker!.statement, file.statementCount - 2); assert.equal(file.currentOuterMarkerGap, false) }
|
|
assert.equal(inventory.filter(file => file.currentOuterMarkerGap).length, 34)
|
|
})
|
|
await test("0041 preserves nonempty full journals and defines only fixed atomic lossless terminal archive transitions", async () => {
|
|
const source = await readFile(new URL("../../drizzle/0041_server_poll_terminal_archives.sql", import.meta.url), "utf8")
|
|
const migration = inventory.find(file => file.id === "0041_server_poll_terminal_archives")!
|
|
assert.equal(migration.opaqueBodies.length, 13)
|
|
assert.equal(migration.operations[1].command, "DO"); assert.equal(migration.operations[2].command, "LOCK")
|
|
assert(source.includes("existing poll accounting requires explicit reconciliation"))
|
|
assert(source.includes("pg_get_constraintdef(oid)='CHECK ((reserved_rows = (admissions * 4019)))'"))
|
|
assert(source.includes("DROP CONSTRAINT server_poll_storage_usage_check,")); assert(source.includes("DROP CONSTRAINT server_poll_storage_usage_check1,"))
|
|
assert(source.includes("pg_try_advisory_xact_lock(hashtextextended('mcp-operation:'")); assert(source.includes("FOR UPDATE NOWAIT"))
|
|
assert(source.includes("pg_try_advisory_xact_lock(hashtextextended('server-poll-execution-v1:mcp:'"))
|
|
assert(source.includes("pg_try_advisory_xact_lock(hashtextextended('server-poll-receipt-v1:'"))
|
|
assert(source.includes("o.error_code IS NOT NULL")); assert(source.includes("s.server_id IS NOT NULL"))
|
|
assert(source.includes("p.created_at>p.approved_at OR p.approved_at>o.created_at OR o.created_at>=LEAST(p.expires_at,a.authority_expires_at)"))
|
|
assert(source.includes("r.created_at<a.authority_expires_at")); assert(source.includes("created_at>=a.authority_expires_at"))
|
|
assert(!source.includes("o.finished_at>=a.authority_expires_at")); assert(!source.includes("s.finished_at>=a.authority_expires_at"))
|
|
assert(source.includes("s.state<>'verified'")); assert(source.includes("o.state<>'applied'")); assert(source.includes("p.approved_by IS NULL"))
|
|
assert(source.includes("outcome<>'confirmed'")); assert(source.includes("generate_series(0,pubs-1)"))
|
|
assert(source.includes("NEW.source_sha256<>encode(sha256(convert_to(payload::text,'UTF8')),'hex')"))
|
|
assert(source.includes("NEW.decoded_bytes<>octet_length(payload::text)")); assert(source.includes("compressed_bytes BETWEEN 1 AND 98048"))
|
|
assert(source.includes("compaction_xid=pg_current_xact_id()")); assert(!source.includes("mm.poll_storage_compact"))
|
|
assert(source.includes("ADD COLUMN compaction_claim uuid")); assert(source.includes("ADD COLUMN compaction_claimed_at timestamptz"))
|
|
assert(source.includes("ADD COLUMN compaction_claim_xid xid8"))
|
|
assert(source.includes("OLD.compaction_claim IS NULL AND OLD.compaction_claimed_at IS NULL"))
|
|
assert(source.includes("THEN NEW.compaction_claimed_at:=clock_timestamp(); NEW.compaction_claim_xid:=pg_current_xact_id(); RETURN NEW; END IF"))
|
|
assert(source.includes("a.compaction_claim IS NULL OR a.compaction_claimed_at IS NULL"))
|
|
assert(source.includes("a.compaction_claim_xid IS NULL OR a.compaction_claim_xid=pg_current_xact_id()"))
|
|
assert.equal((source.match(/DEFERRABLE INITIALLY DEFERRED/g) ?? []).length, 3)
|
|
assert(source.includes("reserved_rows=admissions*4019+compacted_admissions*2"))
|
|
assert(source.includes("reserved_bytes=admissions*8421376+compacted_admissions*32768+archive_bytes"))
|
|
assert(source.includes("GREATEST(a.retention_days,retention)")); assert(source.includes("activity:=GREATEST(a.original_activity_at"))
|
|
assert(CURRENT_REQUIRED_TABLES.includes("server_poll_archives"))
|
|
assert.equal(migration.operations.filter(operation => operation.command === "INSERT").length, 1)
|
|
assert(!migration.operations.some(operation => operation.command === "UPDATE" || operation.command === "DELETE"), "No compaction or source rewrite runs during DDL")
|
|
})
|
|
await test("0040 additive routing enrollment refuses legacy reserved/proposal collisions and never backfills authority", async () => {
|
|
const source = await readFile(new URL("../../drizzle/0040_mcp_routing_reservations.sql", import.meta.url), "utf8")
|
|
const migration = inventory.find(file => file.id === "0040_mcp_routing_reservations")!
|
|
assert.equal(migration.opaqueBodies.length, 1)
|
|
assert.equal(migration.operations[1].command, "LOCK"); assert.equal(migration.operations[2].command, "DO")
|
|
const guard = parseMigrationStatements(source)[2].tokens.find(token => token.kind === "dollar")!.value
|
|
assert(guard.includes("WHERE mode='reserved'")); assert(guard.includes("pg_catalog.pg_attribute")); assert(guard.includes("pg_catalog.pg_constraint"))
|
|
assert(source.includes("source_configuration_proof IS NOT NULL")); assert(source.includes("inverse_configuration_sealed IS NULL OR inverse_intent_sealed IS NOT NULL"))
|
|
assert.equal(migration.operations.filter(operation => operation.command === "INSERT").length, 1, "Only the atomic file marker is inserted")
|
|
assert(!migration.operations.some(operation => operation.command === "UPDATE" || operation.command === "DELETE"))
|
|
assert(CURRENT_REQUIRED_TABLES.includes("mcp_routing_reservations")); assert(CURRENT_REQUIRED_TABLES.includes("mcp_routing_reservation_slots"))
|
|
})
|
|
await test("fresh storage enrollment locks and refuses history before DDL without backfill", async () => {
|
|
const migration = inventory.find(file => file.id === "0037_server_probe_storage_v2")!
|
|
const source = await readFile(new URL("../../drizzle/0037_server_probe_storage_v2.sql", import.meta.url), "utf8")
|
|
const statements = parseMigrationStatements(source)
|
|
assert.equal(migration.statementCount, 27)
|
|
assert.equal(migration.operations[1].command, "LOCK"); assert.equal(migration.operations[2].command, "DO")
|
|
const lock = statements[1].tokens.map(token => token.value).join(" ")
|
|
assert(lock.includes("ACCESS EXCLUSIVE MODE"))
|
|
const guard = statements[2].tokens.find(token => token.kind === "dollar")!.value
|
|
for (const table of ["server_probe_executions", "server_probe_execution_stages", "server_probe_execution_quarantines", "mcp_diagnostic_cancellations"]) {
|
|
assert(lock.includes(table.toUpperCase())); assert(guard.includes(`EXISTS(SELECT 1 FROM ${table})`))
|
|
}
|
|
for (const table of ["server_probe_storage_usage", "server_probe_storage_admissions", "server_probe_execution_payloads"]) {
|
|
assert(guard.includes("'" + table + "'")); assert(CURRENT_REQUIRED_TABLES.includes(table))
|
|
}
|
|
assert.equal(migration.opaqueBodies.filter(body => body.kind === "executed-do-body").length, 1)
|
|
assert.equal(migration.opaqueBodies.filter(body => body.kind === "stored-function-body").length, 10)
|
|
assert.deepEqual(migration.operations.filter(operation => operation.command === "INSERT").map(operation => operation.target), ["server_probe_storage_usage", "schema_migrations"])
|
|
assert.deepEqual(migration.operations.filter(operation => operation.command === "UPDATE"), [])
|
|
const seed = statements.find(statement => statement.tokens[0].value === "INSERT" && statement.tokens[2].value === "SERVER_PROBE_STORAGE_USAGE")!
|
|
assert(!seed.tokens.some(token => token.kind === "word" && token.value === "SELECT"))
|
|
assert.deepEqual(seed.tokens.filter(token => token.kind === "number").map(token => token.value), ["0", "0", "0"])
|
|
})
|
|
await test("poll enrollment fences writers before inspecting unmarked schema and installs exact fixed guards", async () => {
|
|
const source = await readFile(new URL("../../drizzle/0038_server_poll_journal_and_writer_guards.sql", import.meta.url), "utf8")
|
|
const statements = parseMigrationStatements(source)
|
|
const migration = inventory.find(file => file.id === "0038_server_poll_journal_and_writer_guards")!
|
|
assert.equal(migration.operations[1].command, "DO")
|
|
const guard = statements[1].tokens.find(token => token.kind === "dollar")!.value
|
|
const lockAt = guard.indexOf("PERFORM pg_catalog.pg_advisory_xact_lock(8723110::bigint)")
|
|
assert(lockAt >= 0 && lockAt < guard.indexOf("IF EXISTS"))
|
|
for (const name of ["server_poll_executions", "server_poll_intents", "server_poll_acks", "server_poll_receipts", "server_poll_quarantines", "server_poll_journal_immutable", "server_partition_writer_guard"]) assert(guard.includes("'" + name + "'"))
|
|
const { SERVER_POLL_JOURNAL_DDL } = await import("../services/server-poll-journal.js")
|
|
const { SERVER_PARTITION_WRITER_DDL } = await import("../services/server-partition-maintenance-lease.js")
|
|
assert(source.includes(SERVER_POLL_JOURNAL_DDL.trim()))
|
|
assert(source.includes(SERVER_PARTITION_WRITER_DDL.trim()))
|
|
assert.equal((source.match(/ENABLE ALWAYS TRIGGER server_partition_writer_guard/g) ?? []).length, 12)
|
|
assert.deepEqual(migration.operations.filter(operation => operation.command === "INSERT").map(operation => operation.target), ["schema_migrations"])
|
|
assert.equal(migration.opaqueBodies.length, 3)
|
|
})
|
|
await test("poll storage enrollment refuses history before any change and preserves reviewed quota/GC bodies", async () => {
|
|
const source=await readFile(new URL("../../drizzle/0039_server_poll_storage.sql",import.meta.url),"utf8")
|
|
const proposal=await readFile(new URL("./proposals/server-poll-storage.sql",import.meta.url),"utf8")
|
|
const migration=inventory.find(file=>file.id==="0039_server_poll_storage")!
|
|
const statements=parseMigrationStatements(source),historical=parseMigrationStatements(proposal)
|
|
assert.equal(migration.statementCount,25);assert.equal(migration.opaqueBodies.length,6)
|
|
assert.equal(migration.operations[1].command,"LOCK");assert.equal(migration.operations[2].command,"DO")
|
|
const guard=statements[2].tokens.find(token=>token.kind==="dollar")!.value
|
|
for(const name of ["server_poll_executions","server_poll_intents","server_poll_acks","server_poll_receipts","server_poll_quarantines"])assert(guard.includes(`EXISTS(SELECT 1 FROM ${name})`))
|
|
for(const name of ["server_poll_storage_admissions","server_poll_storage_usage"])assert(guard.includes("'"+name+"'")&&CURRENT_REQUIRED_TABLES.includes(name))
|
|
const bodies=(list:ReturnType<typeof parseMigrationStatements>)=>list.filter(statement=>statement.tokens[0].value==="CREATE").flatMap(statement=>statement.tokens.filter(token=>token.kind==="dollar").map(token=>token.value))
|
|
const comparableBodies=(list:ReturnType<typeof parseMigrationStatements>)=>bodies(list).map(body=>body.replace(/\r\n/g,"\n"))
|
|
assert.deepEqual(comparableBodies(statements),comparableBodies(historical));assert.equal(bodies(statements).length,5)
|
|
assert(bodies(statements)[0].includes("mcp_settings.id=1 FOR SHARE"),"Predicate itself fences current retention, including direct guarded deletes")
|
|
assert.deepEqual(migration.operations.filter(operation=>operation.command==="INSERT").map(operation=>operation.target),["server_poll_storage_usage","schema_migrations"])
|
|
assert.equal(migration.operations.some(operation=>["UPDATE","DELETE","DROP"].includes(operation.command)),false)
|
|
})
|
|
await test("comment-only CONCURRENTLY is not an executed nontransactional effect", () => {
|
|
const index = inventory.find(file => file.id === "0013_scheduler_retention_index")!
|
|
assert.equal(index.statementCount, 1); assert.equal(index.transaction, "owner-transaction")
|
|
})
|
|
await test("nested comments, quoted identifiers, escaped strings and tagged bodies split correctly", () => {
|
|
const source = `/* BEGIN; /* COMMIT; */ still comment */ DO $tag$ BEGIN PERFORM ';COMMIT'; END; $tag$;
|
|
CREATE TABLE "semi;COMMIT"(value text DEFAULT 'it''s; BEGIN');
|
|
INSERT INTO "semi;COMMIT" VALUES(E'back\\slash; END', $$literal;COMMIT;$$); -- BEGIN;`
|
|
const statements = parseMigrationStatements(source)
|
|
assert.equal(statements.length, 3); assert.equal(statements[0].tokens[1].kind, "dollar")
|
|
assert.equal(statements[1].tokens.find(token => token.kind === "identifier")?.value, "semi;COMMIT")
|
|
assert.equal(statements[2].tokens.filter(token => token.kind === "dollar").length, 1)
|
|
})
|
|
await test("unterminated/unsupported source refuses rather than guessing", () => {
|
|
for (const source of ["DO $$ BEGIN;", "CREATE TABLE x(v text DEFAULT 'oops);", "/* never closes", 'CREATE TABLE "missing(v int);', "CREATE TABLE x(v int)", "\\i arbitrary.sql", "SELECT U&'unsupported';", "SELECT 1;\0"]) assert.throws(() => parseMigrationStatements(source), MigrationManifestError)
|
|
})
|
|
await test("split commits, statements after COMMIT and unsupported controls refuse", () => {
|
|
for (const source of ["BEGIN; CREATE TABLE x(v int); COMMIT; CREATE TABLE y(v int);", "BEGIN; COMMIT; BEGIN; COMMIT;", "SAVEPOINT x; CREATE TABLE x(v int);", "START TRANSACTION; COMMIT;", "BEGIN; ROLLBACK;", "BEGIN WORK; COMMIT;"]) assert.throws(reviewed(source, { transaction: "self-managed-single-transaction" }), MigrationManifestError)
|
|
})
|
|
await test("exact synthetic transaction contract and terminal selfmarker are checked", () => {
|
|
const source = "BEGIN; CREATE TABLE fixture(v int); INSERT INTO schema_migrations(id) VALUES('9000_fixture') ON CONFLICT(id) DO NOTHING; COMMIT;"
|
|
assert.equal(reviewed(source, { transaction: "self-managed-single-transaction", selfMarker: true })().selfMarker?.atomicWithAllFileEffects, true)
|
|
assert.throws(reviewed(source.replace("9000_fixture", "9000_foreign"), { transaction: "self-managed-single-transaction", selfMarker: true }), MigrationManifestError)
|
|
assert.throws(reviewed(source.replace("COMMIT;", "CREATE TABLE later(v int); COMMIT;"), { transaction: "self-managed-single-transaction", selfMarker: true }), MigrationManifestError)
|
|
})
|
|
await test("opaque body requires its exact declared semantic review", () => {
|
|
const source = "DO $$ BEGIN EXECUTE 'DROP TABLE x'; END $$;"
|
|
assert.throws(reviewed(source), MigrationManifestError)
|
|
assert.equal(reviewed(source, { opaqueBodies: 1, bodyReview: ["Reviewed inert dynamic destructive fixture"] })().opaqueBodies.length, 1)
|
|
assert.throws(reviewed("DO 'BEGIN NULL; END';"), MigrationManifestError)
|
|
})
|
|
await test("executed nontransactional/unclassified commands fail closed", () => {
|
|
for (const source of ["CREATE INDEX CONCURRENTLY ix ON t(x);", "SELECT setval('s',1);", "VACUUM x;", "ALTER SYSTEM SET x=1;", "CALL arbitrary();", "COPY x FROM PROGRAM 'x';"]) assert.throws(reviewed(source), MigrationManifestError)
|
|
})
|
|
await test("raw byte drift including newline changes refuses pinned inventory", async () => {
|
|
const pin = MIGRATION_MANIFEST[0], bytes = await readFile(new URL("../../drizzle/" + pin.file, import.meta.url))
|
|
assert.throws(() => analyzeMigration(pin.file, Buffer.concat([bytes, Buffer.from("\n")]), pin), MigrationManifestError)
|
|
assert.throws(() => analyzeMigration(pin.file, bytes, { ...pin, transaction: "self-managed-single-transaction" }), MigrationManifestError)
|
|
})
|
|
await test("new/missing/duplicate SQL files require an explicit classified pin", () => {
|
|
const files = MIGRATION_MANIFEST.map(pin => pin.file)
|
|
validateMigrationFileSet([...files].reverse())
|
|
for (const changed of [[...files, "0040_unclassified.sql"], files.slice(1), [...files, files[0]], [...files, "manual.sql"]]) assert.throws(() => validateMigrationFileSet(changed), MigrationManifestError)
|
|
assert(Object.isFrozen(MIGRATION_MANIFEST)); assert(Object.isFrozen(MIGRATION_MANIFEST[0].effects))
|
|
})
|
|
const empty: LegacyBaselineEvidence = { inventoryComplete: true, databaseGeneration: "owned-generation", unresolvedAttemptIds: [], markerTable: "absent", markerIds: [], applicationObjects: [] }
|
|
await test("absent markers never alone authorize fresh execution", () => {
|
|
assert.equal(assessLegacyMigrationBaseline(empty).state, "clean-database-candidate")
|
|
assert.equal(assessLegacyMigrationBaseline(empty).dispatchAuthorized, false)
|
|
assert.equal(assessLegacyMigrationBaseline({ ...empty, inventoryComplete: false }).state, "blocked")
|
|
assert.equal(assessLegacyMigrationBaseline({ ...empty, applicationObjects: [{ schema: "public", name: "servers", kind: "table" }] }).state, "blocked")
|
|
assert.equal(assessLegacyMigrationBaseline({ ...empty, unresolvedAttemptIds: ["uncertain0000"] }).state, "blocked")
|
|
})
|
|
const complete: LegacyBaselineEvidence = { ...empty, markerTable: "present", markerIds: MIGRATION_MANIFEST.map(pin => pin.file.slice(0, -4)), applicationObjects: CURRENT_REQUIRED_TABLES.map(name => ({ schema: "public", name, kind: "table" })), verifiedSchema: { manifestDigest: migrationManifestDigest(), databaseGeneration: "owned-generation", exactCurrentSchema: true, observedSchemaDigest: "a".repeat(64) } }
|
|
await test("existing current schema needs exact separately supplied comparator evidence", () => {
|
|
assert.equal(assessLegacyMigrationBaseline(complete).state, "legacy-current-enrollment-candidate")
|
|
assert.equal(assessLegacyMigrationBaseline(complete).dispatchAuthorized, false)
|
|
for (const changed of [{ ...complete, verifiedSchema: undefined }, { ...complete, markerIds: complete.markerIds.slice(0, 1) }, { ...complete, applicationObjects: complete.applicationObjects.slice(1) }, { ...complete, markerIds: [...complete.markerIds, "0001_unknown"] }, { ...complete, verifiedSchema: { ...complete.verifiedSchema!, databaseGeneration: "restored-foreign" } }, { ...complete, verifiedSchema: { ...complete.verifiedSchema!, manifestDigest: "0".repeat(64) } }]) assert.equal(assessLegacyMigrationBaseline(changed).state, "blocked")
|
|
})
|
|
|
|
|
|
await test("0043 adds a separate one-unit immutable forward ledger with an atomic marker", async () => {
|
|
const pin = inventory.find(file => file.id === "0043_mcp_routing_forward_charges")!
|
|
assert.equal(pin.opaqueBodies.length, 3); assert.equal(pin.selfMarker?.atomicWithAllFileEffects, true)
|
|
const source = await readFile(new URL("../../drizzle/0043_mcp_routing_forward_charges.sql", import.meta.url), "utf8")
|
|
assert(source.includes("CHECK(charge_units=1)")); assert(source.includes("source_operation_id uuid PRIMARY KEY"))
|
|
assert(!/REFERENCES|CASCADE|SECURITY DEFINER/.test(source.replace(/--[^\n]*/g, "")))
|
|
assert(source.includes("BEFORE UPDATE OR DELETE")); assert(source.includes("BEFORE TRUNCATE"))
|
|
})
|
|
|
|
await test("0044 adds only a fixed manual inverse ledger and current-version intent fence in one atomic file", async () => {
|
|
const pin = inventory.find(file => file.id === "0044_mcp_routing_manual_inverse_charges")!
|
|
assert.equal(pin.transaction, "self-managed-single-transaction")
|
|
assert.equal(pin.opaqueBodies.length, 4); assert.equal(pin.selfMarker?.atomicWithAllFileEffects, true)
|
|
const source = await readFile(new URL("../../drizzle/0044_mcp_routing_manual_inverse_charges.sql", import.meta.url), "utf8")
|
|
const executable = source.replace(/--[^\n]*/g, "")
|
|
assert(!/REFERENCES|CASCADE|SECURITY DEFINER/.test(executable), "Logical charge identity must not acquire family lifetime FKs or extra authority")
|
|
assert(source.includes("CHECK(charge_units=1)")); assert(source.includes("UNIQUE(source_operation_id,source_step_index)"))
|
|
assert(source.includes("BEFORE UPDATE OR DELETE")); assert(source.includes("BEFORE TRUNCATE"))
|
|
assert(source.includes("pg_try_advisory_xact_lock(hashtextextended('mcp-runner-admission',0))"))
|
|
assert(source.includes("p.operation_id='operations.recover' AND p.operation_version=7"))
|
|
assert(source.includes("sp.operation_id='routing.community.switch' AND sp.operation_version=7"))
|
|
assert(source.includes("manual inverse requires current exact running recovery"))
|
|
assert(source.includes("WHERE mode='manual'")); assert(CURRENT_REQUIRED_TABLES.includes("mcp_routing_manual_inverse_charges"))
|
|
assert.equal(pin.operations.filter(operation => operation.command === "INSERT").length, 1, "Only atomic file marker is inserted; no historical charge backfill")
|
|
assert(!pin.operations.some(operation => operation.command === "UPDATE" || operation.command === "DELETE"))
|
|
})
|
|
|
|
await test("0056 changes only live manual inverse recovery version guards", async () => {
|
|
const migration = inventory.find(file => file.id === "0056_mcp_manual_inverse_recovery_v8")!
|
|
assert.equal(migration.statementCount, 5)
|
|
assert.equal(migration.opaqueBodies.length, 2)
|
|
assert.equal(migration.selfMarker?.atomicWithAllFileEffects, true)
|
|
const oldSql = await readFile(new URL("../../drizzle/0044_mcp_routing_manual_inverse_charges.sql", import.meta.url), "utf8")
|
|
const newSql = await readFile(new URL("../../drizzle/0056_mcp_manual_inverse_recovery_v8.sql", import.meta.url), "utf8")
|
|
for (const name of ["mcp_routing_manual_inverse_charge_source", "mcp_scoped_recovery_manual_version"]) {
|
|
const definition = new RegExp(`CREATE(?: OR REPLACE)? FUNCTION public\\.${name}\\(\\)[\\s\\S]*?END \\$\\$;`)
|
|
const original = oldSql.match(definition)?.[0]?.replaceAll("\r\n", "\n")
|
|
assert.ok(original)
|
|
assert.equal(newSql.match(definition)?.[0]?.replaceAll("\r\n", "\n"), original.replace("CREATE FUNCTION", "CREATE OR REPLACE FUNCTION")
|
|
.replace("p.operation_id='operations.recover' AND p.operation_version=7", "p.operation_id='operations.recover' AND p.operation_version=8"))
|
|
}
|
|
})
|
|
|
|
console.log(`migration-manifest: ${cases} inert parser/inventory/baseline scenarios passed; ${inventory.length} exact files`)
|