Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(control-api): report optional-chained and cast pool ends in the teardown guard (J2)
Alfredo Lopez7cd93fccb818
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex d6950f128..b8901b3f7 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.689",+ "version": "0.1.690","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.689",+ "version": "0.1.690","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 ce9314f8f..52f72d6a5 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.689",+ "version": "0.1.690","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/realPostgresTeardown.guard.test.ts b/control-api/test/realPostgresTeardown.guard.test.tsindex e3d70bd72..40533af20 100644--- a/control-api/test/realPostgresTeardown.guard.test.ts+++ b/control-api/test/realPostgresTeardown.guard.test.ts@@ -33,6 +33,15 @@ function lineOf(source: string, index: number): number {return source.slice(0, index).split('\n').length}+function scanSource(file: string, source: string): ScannedSuite {+ const terminators = [...new Set([...source.matchAll(TERMINATE_QUERY)].map(match => match[1]))]+ 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, plainEnds: plainEnds.length, violations }+}+function scanSuites(): ScannedSuite[] {return readdirSync(testDir).filter(file => REAL_POSTGRES_SUITE.test(file))@@ -40,12 +49,7 @@ function scanSuites(): ScannedSuite[] {.flatMap(file => {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 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, plainEnds: plainEnds.length, violations }]+ return [scanSource(file, source)]})}@@ -65,4 +69,27 @@ describe('real-Postgres teardown guard (R4-L11)', () => {expect(suites.flatMap(suite => suite.violations)).toEqual([])})++ it('reports optional-chained, cast and chained ends, and allows the terminating pool (J2)', () => {+ const source = [+ 'await adminPool.query(`SELECT pg_terminate_backend(pid) FROM pg_stat_activity`)',+ 'await dbPool.end()',+ 'await pool?.end()',+ 'await (dbPool as Pool).end()',+ 'await corePool?.end().catch(() => undefined)',+ 'await adminPool?.end()',+ 'await adminPool.end()',+ ].join('\n')++ const suite = scanSource('fixture.realPostgres.test.ts', source)++ // Witness: the terminate query named the pool that is allowed a plain end.+ expect(suite.terminators).toEqual(['adminPool'])+ expect(suite.violations).toEqual([+ 'fixture.realPostgres.test.ts:2 dbPool.end(',+ 'fixture.realPostgres.test.ts:3 pool?.end(',+ 'fixture.realPostgres.test.ts:4 Pool).end(',+ 'fixture.realPostgres.test.ts:5 corePool?.end(',+ ])+ })})