Where agent teams gather. Cross-platform team chat where AI agents are first-class teammates — with cloud or bring-your-own (Claude Code / Codex) brains.
TypeScript
test: batch integration cleanup to avoid CI timeouts
bingqilinweimaotai30cd8597bfd5
diff --git a/server/src/__integration__/_helpers.ts b/server/src/__integration__/_helpers.tsindex 6959adf..6b96586 100644--- a/server/src/__integration__/_helpers.ts+++ b/server/src/__integration__/_helpers.ts@@ -27,8 +27,7 @@ export function ensureSchemaOnce(): Promise<void> {return schemaReady}-/** Tables we wipe between tests. Order matters when there are FK- * constraints; CASCADE on the parents handles it but listing explicitly+/** Tables we wipe between tests. CASCADE handles FK constraints, but listing explicitly* keeps the intent visible + lets us spot-check leakage. */const TABLES_TO_WIPE: readonly string[] = ['workspace_cleanup_jobs',@@ -99,8 +98,16 @@ export async function resetAllTables(): Promise<void> {throw new Error(`refusing to TRUNCATE — DATABASE_URL doesn't look like a test DB: ${env.DATABASE_URL}`)}await ensureSchemaOnce()- for (const t of TABLES_TO_WIPE) {- await pool.query(`TRUNCATE TABLE ${t} CASCADE`).catch(() => { /* table may not exist on partial schemas */ })+ // Partial schemas may omit tables. Resolve the allowlist first instead of+ // swallowing every TRUNCATE error (which could leave stale test data).+ const { rows } = await pool.query<{ name: string }>(+ 'SELECT name FROM unnest($1::text[]) AS tables(name) WHERE to_regclass(name) IS NOT NULL',+ [TABLES_TO_WIPE],+ )+ if (rows.length > 0) {+ // One transaction avoids repeatedly truncating the same FK descendants+ // and syncing dozens of separate commits before every test.+ await pool.query(`TRUNCATE TABLE ${rows.map(({ name }) => name).join(', ')} CASCADE`)}}diff --git a/server/src/__integration__/harness-reset.test.ts b/server/src/__integration__/harness-reset.test.tsnew file mode 100644index 0000000..bf419d3--- /dev/null+++ b/server/src/__integration__/harness-reset.test.ts@@ -0,0 +1,43 @@+import { after, test } from 'node:test'+import assert from 'node:assert/strict'+import { pool } from '../db/pool.js'+import { resetAllTables, seedCompanyWithAgent, teardownAll } from './_helpers.js'++after(async () => { await teardownAll() })++test('[integration] reset clears related rows and preserves migration history', async () => {+ await resetAllTables()+ await seedCompanyWithAgent()+ const migrations = await pool.query('SELECT * FROM schema_migrations ORDER BY version')++ await resetAllTables()++ for (const table of ['companies', 'participants']) {+ const { rows } = await pool.query(`SELECT count(*)::int AS count FROM ${table}`)+ assert.equal(rows[0].count, 0)+ }+ assert.deepEqual((await pool.query('SELECT * FROM schema_migrations ORDER BY version')).rows, migrations.rows)+})++test('[integration] reset tolerates missing tables in partial schemas', async () => {+ await resetAllTables()+ await seedCompanyWithAgent()+ await pool.query('ALTER TABLE shipping_regressions RENAME TO harness_reset_saved_regressions')+ try {+ await resetAllTables()+ const { rows } = await pool.query('SELECT count(*)::int AS count FROM companies')+ assert.equal(rows[0].count, 0)+ } finally {+ await pool.query('ALTER TABLE harness_reset_saved_regressions RENAME TO shipping_regressions')+ }+})++test('[integration] reset propagates cleanup errors instead of leaving stale data silently', async (t) => {+ const originalQuery = pool.query.bind(pool)+ const failure = new Error('simulated cleanup failure')+ t.mock.method(pool, 'query', (...args: Parameters<typeof pool.query>) => {+ if (typeof args[0] === 'string' && args[0].startsWith('TRUNCATE TABLE')) throw failure+ return originalQuery(...args)+ })+ await assert.rejects(resetAllTables(), failure)+})