Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): r6-h11 keep migrations monotonic after sync
Josué0b9345fffced
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 817e575a9..9c880649c 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.680",+ "version": "0.1.681","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.680",+ "version": "0.1.681","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex ab5a7cfd6..2e64e8220 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.680",+ "version": "0.1.681","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/db.ts b/control-api/src/db.tsindex 39fcadb8c..f090bcc96 100644--- a/control-api/src/db.ts+++ b/control-api/src/db.ts@@ -6279,14 +6279,6 @@ export const CONTROL_API_MIGRATIONS: DbMigration[] = [legacyVersions: ['0116_dynamic_clients_table', '0117_dynamic_clients_table'],apply: applyDynamicClientsTable,},- {- version: '0119_durable_entity_change_feed',- // This feature was deployed both before the two replace-inviter migrations- // and at its original 0117 slot. Preserve both identities so the sync does- // not rerun entity-change DDL in either previously deployed environment.- legacyVersions: ['0116_durable_entity_change_feed', '0117_durable_entity_change_feed'],- apply: applyEntityChangeSchema,- },{// Renumbered twice while syncing onto dev (0117 -> 0118 -> 0120), moving in// lockstep with the table migration above. Same legacyVersions rationale:@@ -6295,10 +6287,6 @@ export const CONTROL_API_MIGRATIONS: DbMigration[] = [legacyVersions: ['0117_dynamic_clients_runtime_access', '0118_dynamic_clients_runtime_access'],apply: applyDynamicClientsRuntimeAccess,},- {- version: '0120_entity_change_checkpoint_cursor_convergence',- apply: applyEntityChangeCheckpointSchema,- },{// Install-identity columns for the DCR/OAuth state (install_id + cr_uid on// dynamic_clients, cr_uid on oauth_grants). Renumbered 0119 -> 0121 while@@ -6309,6 +6297,28 @@ export const CONTROL_API_MIGRATIONS: DbMigration[] = [legacyVersions: ['0119_oauth_install_identity'],apply: applyOAuthInstallIdentity,},+ {+ version: '0122_durable_entity_change_feed',+ // This feature was deployed both before the two replace-inviter migrations+ // and at its original 0117 slot; it also shipped at 0119 before current dev+ // claimed that numeric slot for dynamic clients. Preserve all identities so+ // an upgrade records 0122 without rerunning entity-change DDL.+ legacyVersions: [+ '0116_durable_entity_change_feed',+ '0117_durable_entity_change_feed',+ '0119_durable_entity_change_feed',+ ],+ apply: applyEntityChangeSchema,+ },+ {+ version: '0123_entity_change_checkpoint_cursor_convergence',+ // The checkpoint fix shipped at 0120 before current dev assigned that slot+ // to dynamic-client runtime grants. This migration only replaces the+ // checkpoint function; retain the old identity so deployed databases skip+ // duplicate DDL while recording the new monotonic version.+ legacyVersions: ['0120_entity_change_checkpoint_cursor_convergence'],+ apply: applyEntityChangeCheckpointSchema,+ },]async function consolidateWorkflowAllowedUsersToTriggers(db: DbClient): Promise<void> {diff --git a/control-api/test/db.migrationsOrder.test.ts b/control-api/test/db.migrationsOrder.test.tsindex 9c0643a56..cae62b0ad 100644--- a/control-api/test/db.migrationsOrder.test.ts+++ b/control-api/test/db.migrationsOrder.test.ts@@ -48,6 +48,14 @@ describe('CONTROL_API_MIGRATIONS ordering invariant', () => {expect(duplicates, `duplicate version-string(s):\n${duplicates.join('\n')}`).toEqual([])})+ it('assigns each migration a unique numeric slot', async () => {+ const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')+ const slots = CONTROL_API_MIGRATIONS.map(migration => migration.version.slice(0, 4))+ const duplicates = slots.filter((slot, index) => slots.indexOf(slot) !== index)++ expect(duplicates, `duplicate migration slot(s):\n${duplicates.join('\n')}`).toEqual([])+ })+it('keeps legacy aliases unique and distinct from current versions', async () => {const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')const current = new Set(CONTROL_API_MIGRATIONS.map(migration => migration.version))@@ -59,14 +67,15 @@ describe('CONTROL_API_MIGRATIONS ordering invariant', () => {expect(currentCollisions).toEqual([])})- it('recognizes both previously deployed entity-change migration versions without reapplying DDL', async () => {+ it('recognizes all previously deployed feed migration versions without reapplying DDL', async () => {const { CONTROL_API_MIGRATIONS, initDb } = await import('../src/db.js')const migration = CONTROL_API_MIGRATIONS.find(- candidate => candidate.version === '0119_durable_entity_change_feed'+ candidate => candidate.version === '0122_durable_entity_change_feed')expect(migration?.legacyVersions).toEqual(['0116_durable_entity_change_feed','0117_durable_entity_change_feed',+ '0119_durable_entity_change_feed',])for (const legacyVersion of migration?.legacyVersions ?? []) {@@ -89,16 +98,47 @@ describe('CONTROL_API_MIGRATIONS ordering invariant', () => {)expect(query).toHaveBeenCalledWith(expect.stringContaining('INSERT INTO schema_migrations(version)'),- ['0119_durable_entity_change_feed']+ ['0122_durable_entity_change_feed'])expect(release).toHaveBeenCalledOnce()}})+ it('recognizes the deployed checkpoint version without reapplying its function DDL', async () => {+ const { CONTROL_API_MIGRATIONS, initDb } = await import('../src/db.js')+ const migration = CONTROL_API_MIGRATIONS.find(+ candidate => candidate.version === '0123_entity_change_checkpoint_cursor_convergence'+ )+ expect(migration?.legacyVersions).toEqual(['0120_entity_change_checkpoint_cursor_convergence'])++ const appliedVersions = CONTROL_API_MIGRATIONS.filter(+ candidate => candidate.version !== migration?.version+ ).map(candidate => ({ version: candidate.version }))+ appliedVersions.push({ version: '0120_entity_change_checkpoint_cursor_convergence' })+ const query = vi.fn(async (sql: string) =>+ sql.includes('SELECT version FROM schema_migrations')+ ? { rows: appliedVersions, rowCount: appliedVersions.length }+ : { rows: [], rowCount: 0 }+ )+ const release = vi.fn()++ await initDb({ connect: vi.fn().mockResolvedValue({ query, release }) } as never)++ const statements = query.mock.calls.map(([sql]) => String(sql))+ expect(statements).not.toContainEqual(+ expect.stringContaining('CREATE OR REPLACE FUNCTION entity_change_read_checkpoint')+ )+ expect(query).toHaveBeenCalledWith(+ expect.stringContaining('INSERT INTO schema_migrations(version)'),+ ['0123_entity_change_checkpoint_cursor_convergence']+ )+ expect(release).toHaveBeenCalledOnce()+ })+it('registers an additive migration for expired entity-change cursor convergence', async () => {const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')const migration = CONTROL_API_MIGRATIONS.find(- candidate => candidate.version === '0120_entity_change_checkpoint_cursor_convergence'+ candidate => candidate.version === '0123_entity_change_checkpoint_cursor_convergence')expect(migration).toBeDefined()if (!migration) returndiff --git a/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts b/control-api/test/db.oauthGrantsOwnerGeneralization.test.tsindex 7cb24dce4..c2c02200c 100644--- a/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts+++ b/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts@@ -46,9 +46,9 @@ describe('0101 oauth_grants owner generalization migration', () => {expect(versions.indexOf('0119_dynamic_clients_table')).toBeLessThan(versions.indexOf('0120_dynamic_clients_runtime_access'))- expect(versions).toContain('0119_durable_entity_change_feed')+ expect(versions).toContain('0122_durable_entity_change_feed')expect(versions.indexOf('0116_mcp_secret_rollback_permits')).toBeLessThan(- versions.indexOf('0119_durable_entity_change_feed')+ versions.indexOf('0122_durable_entity_change_feed'))expect(versions.indexOf('0100_seed_minimax_allowed_model')).toBeLessThan(versions.indexOf('0106_oauth_grants_owner_generalization')