11/**
22 * Live-PG apply of the v3 baseline migration bundle.
33 *
4- * `installEqlV3IfNeeded` applies `readInstallSql()` — and this suite
5- * pins that those are byte-for-byte the SQL baked into the shipped
6- * migration's `ops.json` (`migrations/20260601T0100_install_eql_v3_bundle`),
7- * so a green run here IS a green apply of the customer-facing
4+ * `installEqlV3IfNeeded` applies `readInstallSql()` — and this suite pins that
5+ * those are byte-for-byte the SQL injected into the shipped control descriptor
6+ * at runtime, so a green run here IS a green apply of the customer-facing
87 * migration op. After install it verifies the observable contract: the
9- * `public.eql_v3_*` storage domains and the `eql_v3` operator schema
10- * exist, the op carries the `cipherstash:install-eql-v3-bundle-v1`
11- * invariant, the op's own postchecks hold against the live database,
12- * and no v2-style `add_search_config` was executed (v3 needs no
13- * per-column search configuration).
8+ * `public.eql_v3_*` storage domains and the `eql_v3` operator schema exist, the
9+ * op carries the `cipherstash:install-eql-v3-bundle-v1` invariant, the op's own
10+ * postchecks hold against the live database, and no v2-style
11+ * `add_search_config` was executed (v3 needs no per-column search configuration).
1412 */
1513
1614import 'dotenv/config'
17- import { readFileSync } from 'node:fs'
18- import { fileURLToPath } from 'node:url'
19- import { dirname , join } from 'pathe'
2015import type postgres from 'postgres'
2116import { afterAll , beforeAll , expect , it } from 'vitest'
22- import { CIPHERSTASH_V3_INVARIANTS } from '../../src/extension-metadata/constants-v3'
17+ import cipherstashDescriptor from '../../src/exports/control'
18+ import {
19+ CIPHERSTASH_V3_BASELINE_MIGRATION_NAME ,
20+ CIPHERSTASH_V3_INVARIANTS ,
21+ } from '../../src/extension-metadata/constants-v3'
2322import {
2423 readInstallSql ,
2524 releaseManifest ,
@@ -28,12 +27,6 @@ import { installEqlV3IfNeeded, uninstallEqlV3 } from './helpers/eql-v3'
2827import { liveConnection } from './helpers/harness'
2928import { describeLivePg } from './helpers/live-gate'
3029
31- const MIGRATION_DIR = join (
32- dirname ( dirname ( dirname ( fileURLToPath ( import . meta. url ) ) ) ) ,
33- 'migrations' ,
34- '20260601T0100_install_eql_v3_bundle' ,
35- )
36-
3730interface MigrationOp {
3831 readonly id : string
3932 readonly invariantId : string
@@ -48,14 +41,14 @@ interface MigrationOp {
4841 } >
4942}
5043
51- function readOpsFixture ( ) : MigrationOp {
52- const ops = JSON . parse (
53- readFileSync ( join ( MIGRATION_DIR , 'ops.json' ) , 'utf8' ) ,
54- ) as MigrationOp [ ]
55- const op = ops [ 0 ]
56- if ( ops . length !== 1 || ! op ) {
44+ function readRuntimeDescriptorOp ( ) : MigrationOp {
45+ const migration = cipherstashDescriptor . contractSpace ?. migrations . find (
46+ ( { dirName } ) => dirName === CIPHERSTASH_V3_BASELINE_MIGRATION_NAME ,
47+ )
48+ const op = migration ?. ops [ 0 ] as MigrationOp | undefined
49+ if ( migration ?. ops . length !== 1 || ! op ) {
5750 throw new Error (
58- `expected exactly one op in the v3 baseline migration, got ${ ops . length } ` ,
51+ `expected exactly one op in the v3 baseline migration, got ${ migration ?. ops . length ?? 0 } ` ,
5952 )
6053 }
6154 return op
@@ -79,14 +72,14 @@ describeLivePg('v3 baseline migration bundle against live Postgres', () => {
7972 if ( sql ) await sql . end ( )
8073 } )
8174
82- it ( 'the applied SQL is byte-for-byte the shipped migration op, carrying the v3 invariant' , ( ) => {
83- const op = readOpsFixture ( )
75+ it ( 'the applied SQL is byte-for-byte the runtime descriptor op, carrying the v3 invariant' , ( ) => {
76+ const op = readRuntimeDescriptorOp ( )
8477 expect ( op . id ) . toBe ( 'cipherstash.install-eql-v3-bundle' )
8578 expect ( op . invariantId ) . toBe ( CIPHERSTASH_V3_INVARIANTS . installBundle )
8679 expect ( op . operationClass ) . toBe ( 'data' )
8780 expect ( op . execute ) . toHaveLength ( 1 )
88- // Byte identity: what installEqlV3IfNeeded just applied IS the
89- // migration bundle a customer's `prisma-next migrate` applies .
81+ // Byte identity: what installEqlV3IfNeeded just applied IS the migration
82+ // bundle the control descriptor gives to `prisma-next migrate`.
9083 expect ( op . execute [ 0 ] ?. sql ) . toBe ( readInstallSql ( ) )
9184 } )
9285
@@ -117,7 +110,7 @@ describeLivePg('v3 baseline migration bundle against live Postgres', () => {
117110 } , 60_000 )
118111
119112 it ( "the migration op's own postchecks hold against the live database" , async ( ) => {
120- const op = readOpsFixture ( )
113+ const op = readRuntimeDescriptorOp ( )
121114 expect ( op . postcheck . length ) . toBeGreaterThan ( 0 )
122115 for ( const check of op . postcheck ) {
123116 const rows = ( await sql . unsafe ( check . sql ) ) as unknown as Array <
0 commit comments