Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(control-api): require a changed catalog name and window to replace the stored one (#739)

Alfredo Lopez2c2aeaf1a615
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 35192d916..4085715ec 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.622",
+ "version": "0.1.623",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.622",
+ "version": "0.1.623",
"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.json
index 45567e876..712b64b13 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.622",
+ "version": "0.1.623",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/services.codexSubscriptionCatalog.realPostgres.integration.test.ts b/control-api/test/services.codexSubscriptionCatalog.realPostgres.integration.test.ts
index 3b710050e..79b9b0c6f 100644
--- a/control-api/test/services.codexSubscriptionCatalog.realPostgres.integration.test.ts
+++ b/control-api/test/services.codexSubscriptionCatalog.realPostgres.integration.test.ts
@@ -181,4 +181,48 @@ describeRealPostgres('Codex subscription catalog on real PostgreSQL', () => {
expect(silent.refreshed).toBe(1)
expect(await names()).toEqual({ connection: ['GPT-5.6-Sol'], union: ['GPT-5.6-Sol'] })
})
+
+ it('R9-20 a catalog that changes a stored name and window replaces both in both tables', async () => {
+ const model = 'gpt-r9-20-replace'
+ const sync = (models: CodexDiscoveredModel[]) =>
+ syncCodexSubscriptionCatalog(
+ pool,
+ {
+ async listModels() {
+ return { outcome: 'ready', models }
+ },
+ },
+ 'access-token'
+ )
+ const stored = async () => {
+ const connection = await pool.query<{
+ display_name: string | null
+ context_window_tokens: number | null
+ }>(`SELECT display_name, context_window_tokens FROM codex_catalog_models WHERE model = $1`, [
+ model,
+ ])
+ const union = await pool.query<{
+ display_name: string | null
+ context_window_tokens: number | null
+ }>(
+ `SELECT display_name, context_window_tokens FROM llm_allowed_models
+ WHERE provider = 'codex-subscription' AND model = $1`,
+ [model]
+ )
+ return { connection: connection.rows, union: union.rows }
+ }
+
+ // Catalog A: both values non-null, inserted on first sight.
+ const first = await sync([{ model, displayName: 'Model A', contextWindowTokens: 200_000 }])
+ expect(first.added).toBe(1)
+ const a = { display_name: 'Model A', context_window_tokens: 200_000 }
+ expect(await stored()).toEqual({ connection: [a], union: [a] })
+
+ // Catalog B: different non-null values; the existing rows take the refresh
+ // path and must store what the catalog now says, not keep A.
+ const second = await sync([{ model, displayName: 'Model B', contextWindowTokens: 400_000 }])
+ expect(second.refreshed).toBe(1)
+ const b = { display_name: 'Model B', context_window_tokens: 400_000 }
+ expect(await stored()).toEqual({ connection: [b], union: [b] })
+ })
})
diff --git a/control-api/test/services.grokSubscriptionConnection.realPostgres.integration.test.ts b/control-api/test/services.grokSubscriptionConnection.realPostgres.integration.test.ts
index 23770ebd0..02df77e63 100644
--- a/control-api/test/services.grokSubscriptionConnection.realPostgres.integration.test.ts
+++ b/control-api/test/services.grokSubscriptionConnection.realPostgres.integration.test.ts
@@ -649,4 +649,55 @@ describeRealPostgres('Grok subscription connection on real PostgreSQL', () => {
union: ['Grok Display R52'],
})
})
+
+ it('R9-20-grok a catalog that changes a stored name and window replaces both in both tables', async () => {
+ const key = 'team-grok-r9-20-replace'
+ const model = 'grok-r9-20-replace'
+ const created = await insertInitialGrokSubscriptionConnection(
+ pool,
+ KEY,
+ { refreshToken: 'refresh-r920', accessToken: 'access', accountFingerprint: 'fp-r920' },
+ key
+ )
+ const sync = (models: GrokDiscoveredModel[]) =>
+ syncGrokSubscriptionCatalog(
+ pool,
+ { listModels: async () => ({ outcome: 'ready', models }) },
+ 'access',
+ { connectionKey: key },
+ { withTransaction: poolTransaction }
+ )
+ const stored = async () => {
+ const connection = await pool.query<{
+ display_name: string | null
+ context_window_tokens: number | null
+ }>(
+ `SELECT display_name, context_window_tokens FROM grok_catalog_models
+ WHERE connection_id = $1 AND model = $2`,
+ [created.id, model]
+ )
+ const union = await pool.query<{
+ display_name: string | null
+ context_window_tokens: number | null
+ }>(
+ `SELECT display_name, context_window_tokens FROM llm_allowed_models
+ WHERE provider = 'grok-subscription' AND model = $1`,
+ [model]
+ )
+ return { connection: connection.rows, union: union.rows }
+ }
+
+ // Catalog A: both values non-null, inserted on first sight.
+ const first = await sync([{ model, displayName: 'Grok A', contextWindowTokens: 131_072 }])
+ expect(first.added).toBe(1)
+ const a = { display_name: 'Grok A', context_window_tokens: 131_072 }
+ expect(await stored()).toEqual({ connection: [a], union: [a] })
+
+ // Catalog B: different non-null values; the existing rows take the refresh
+ // path and must store what the catalog now says, not keep A.
+ const second = await sync([{ model, displayName: 'Grok B', contextWindowTokens: 262_144 }])
+ expect(second.refreshed).toBe(1)
+ const b = { display_name: 'Grok B', context_window_tokens: 262_144 }
+ expect(await stored()).toEqual({ connection: [b], union: [b] })
+ })
})