Skip to content

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

TypeScript

fix(control-api): end the remaining pools through the teardown helper (R4-L11)

Alfredo Lopez2b8ce209b148
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index f0f315c32..d6950f128 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.688",
+ "version": "0.1.689",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.688",
+ "version": "0.1.689",
"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 bf10b20e9..ce9314f8f 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.688",
+ "version": "0.1.689",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/gfsReaderRole.realPostgres.integration.test.ts b/control-api/test/gfsReaderRole.realPostgres.integration.test.ts
index af24695ed..48c12186f 100644
--- a/control-api/test/gfsReaderRole.realPostgres.integration.test.ts
+++ b/control-api/test/gfsReaderRole.realPostgres.integration.test.ts
@@ -181,7 +181,10 @@ describeRealPostgres('GFS reader and writer login isolation', () => {
rows: [{ current_user: 'gfs_controller_reader' }],
})
} finally {
- await Promise.all([freshWriter.end(), freshReader.end()])
+ await Promise.all([
+ endPoolAndWaitForClients(freshWriter),
+ endPoolAndWaitForClients(freshReader),
+ ])
}
})
diff --git a/control-api/test/realPostgresTeardown.guard.test.ts b/control-api/test/realPostgresTeardown.guard.test.ts
index e3f6016bf..e3d70bd72 100644
--- a/control-api/test/realPostgresTeardown.guard.test.ts
+++ b/control-api/test/realPostgresTeardown.guard.test.ts
@@ -25,6 +25,7 @@ const PLAIN_END = /\b(\w+)\.end\(\)/g
interface ScannedSuite {
file: string
terminators: string[]
+ plainEnds: number
violations: string[]
}
@@ -40,10 +41,11 @@ function scanSuites(): ScannedSuite[] {
const source = readFileSync(join(testDir, file), 'utf8')
if (!source.includes('pg_terminate_backend')) return []
const terminators = [...new Set([...source.matchAll(TERMINATE_QUERY)].map(match => match[1]))]
- const violations = [...source.matchAll(PLAIN_END)]
+ const plainEnds = [...source.matchAll(PLAIN_END)]
+ const violations = plainEnds
.filter(match => !terminators.includes(match[1]))
.map(match => `${file}:${lineOf(source, match.index)} ${match[0]}`)
- return [{ file, terminators, violations }]
+ return [{ file, terminators, plainEnds: plainEnds.length, violations }]
})
}
@@ -51,13 +53,15 @@ describe('real-Postgres teardown guard (R4-L11)', () => {
it('ends every pool other than the terminating one through endPoolAndWaitForClients', () => {
const suites = scanSuites()
- // Witnesses: the scan reached suites that terminate backends, and in each
- // one it identified the pool that runs the terminate. Without both, an
+ // Witnesses: the scan reached suites that terminate backends, in each one
+ // it identified the pool that runs the terminate, and it matched plain
+ // `.end()` calls at all (the terminating pools' own). Without them, an
// empty violation list would say nothing.
expect(suites.length).toBeGreaterThan(0)
expect(suites.filter(suite => suite.terminators.length === 0).map(suite => suite.file)).toEqual(
[]
)
+ expect(suites.reduce((sum, suite) => sum + suite.plainEnds, 0)).toBeGreaterThan(0)
expect(suites.flatMap(suite => suite.violations)).toEqual([])
})
diff --git a/control-api/test/routes.externalGfsRateLimitFailClosed.realPostgres.integration.test.ts b/control-api/test/routes.externalGfsRateLimitFailClosed.realPostgres.integration.test.ts
index b4e6c9bcd..b230fa9e0 100644
--- a/control-api/test/routes.externalGfsRateLimitFailClosed.realPostgres.integration.test.ts
+++ b/control-api/test/routes.externalGfsRateLimitFailClosed.realPostgres.integration.test.ts
@@ -99,7 +99,7 @@ describeRealPostgres('external GFS rate limiter backend (real PostgreSQL)', () =
limiterPool.on('error', () => {})
const migratePool = new Pool({ connectionString })
await dbMod.initDb({ connect: () => migratePool.connect() })
- await migratePool.end()
+ await endPoolAndWaitForClients(migratePool)
const appMod = await import('../src/app.js')
const configMod = await import('../src/config.js')
diff --git a/control-api/test/routes.externalGfsRateLimitStress.realPostgres.integration.test.ts b/control-api/test/routes.externalGfsRateLimitStress.realPostgres.integration.test.ts
index 79a59d167..3d0669558 100644
--- a/control-api/test/routes.externalGfsRateLimitStress.realPostgres.integration.test.ts
+++ b/control-api/test/routes.externalGfsRateLimitStress.realPostgres.integration.test.ts
@@ -181,7 +181,7 @@ describeRealPostgres('external GFS rate limits under concurrent load (real Postg
limiterPool.on('error', () => {})
const migratePool = new Pool({ connectionString })
await dbMod.initDb({ connect: () => migratePool.connect() })
- await migratePool.end()
+ await endPoolAndWaitForClients(migratePool)
const appMod = await import('../src/app.js')
const configMod = await import('../src/config.js')
diff --git a/control-api/test/routes.llmModelGrantRace.realPostgres.integration.test.ts b/control-api/test/routes.llmModelGrantRace.realPostgres.integration.test.ts
index 0a319eb20..44fbfd4f9 100644
--- a/control-api/test/routes.llmModelGrantRace.realPostgres.integration.test.ts
+++ b/control-api/test/routes.llmModelGrantRace.realPostgres.integration.test.ts
@@ -138,7 +138,7 @@ describeRealPostgres('llm-model reductor ↔ grant upsert serialization (R1-H3 f
limiterPool.on('error', () => {})
const migratePool = new Pool({ connectionString })
await dbMod.initDb({ connect: () => migratePool.connect() })
- await migratePool.end()
+ await endPoolAndWaitForClients(migratePool)
racePool = new Pool({ connectionString })
racePool.on('error', () => {})
diff --git a/control-api/test/routes.llmModelHostRace.realPostgres.integration.test.ts b/control-api/test/routes.llmModelHostRace.realPostgres.integration.test.ts
index 8e7df1231..313266df2 100644
--- a/control-api/test/routes.llmModelHostRace.realPostgres.integration.test.ts
+++ b/control-api/test/routes.llmModelHostRace.realPostgres.integration.test.ts
@@ -121,7 +121,7 @@ describeRealPostgres('llm-model reductor ↔ host referencer serialization (R1-H
limiterPool.on('error', () => {})
const migratePool = new Pool({ connectionString })
await dbMod.initDb({ connect: () => migratePool.connect() })
- await migratePool.end()
+ await endPoolAndWaitForClients(migratePool)
const appMod = await import('../src/app.js')
const configMod = await import('../src/config.js')
diff --git a/control-api/test/routes.rateLimitProcessMemory.realPostgres.integration.test.ts b/control-api/test/routes.rateLimitProcessMemory.realPostgres.integration.test.ts
index 6041980ae..c2fcc04b5 100644
--- a/control-api/test/routes.rateLimitProcessMemory.realPostgres.integration.test.ts
+++ b/control-api/test/routes.rateLimitProcessMemory.realPostgres.integration.test.ts
@@ -96,7 +96,7 @@ describeRealPostgres('rateLimitMiddleware process-memory mode (real PostgreSQL)'
limiterPool.on('error', () => {})
const migratePool = new Pool({ connectionString })
await dbMod.initDb({ connect: () => migratePool.connect() })
- await migratePool.end()
+ await endPoolAndWaitForClients(migratePool)
const appMod = await import('../src/app.js')
const configMod = await import('../src/config.js')
diff --git a/control-api/test/services.rateLimiterPoolSaturation.realPostgres.integration.test.ts b/control-api/test/services.rateLimiterPoolSaturation.realPostgres.integration.test.ts
index 4ce70fc79..b0d699132 100644
--- a/control-api/test/services.rateLimiterPoolSaturation.realPostgres.integration.test.ts
+++ b/control-api/test/services.rateLimiterPoolSaturation.realPostgres.integration.test.ts
@@ -115,7 +115,7 @@ describeRealPostgres('rate limiter under pool saturation', () => {
limiterPool.on('error', () => {})
const migratePool = new Pool({ connectionString })
await dbMod.initDb({ connect: () => migratePool.connect() })
- await migratePool.end()
+ await endPoolAndWaitForClients(migratePool)
const appMod = await import('../src/app.js')
const configMod = await import('../src/config.js')