Skip to content

Stop wiping the whole database between tests - #18

Merged
fajarhide merged 1 commit into
mainfrom
fix/scoped-test-cleanup
Aug 17, 2026
Merged

Stop wiping the whole database between tests#18
fajarhide merged 1 commit into
mainfrom
fix/scoped-test-cleanup

Conversation

@fajarhide

Copy link
Copy Markdown
Owner

startTestServer ran TRUNCATE workspaces CASCADE on every call, so two suite runs against one TEST_DATABASE_URL deleted each other's rows mid-test. The failures came out as expected 401 to be 200, because the credential row went away between the seed and the request, and nothing in the output suggested another process was involved.

Nothing needed the wipe. Every test already creates its own workspace, and credentials, grants, enablements and usage rows all cascade from it. One assertion did read the whole table, counting oauth_states to prove an expired row was swept; it now names the state it is about.

Before and after, both suites started at the same moment against the same database.

On main:

$ npx vitest run test/mcp.test.ts test/rest.test.ts
Tests  6 failed | 9 passed (15)

$ npx vitest run test/connections-http.test.ts test/isolation.test.ts test/admin-connections.test.ts
Tests  7 failed | 13 passed (20)

On this branch, same two commands, same overlap:

Tests  15 passed (15)
Tests  20 passed (20)

Full suite: 35 files, 351 tests, green. Typecheck clean.

Worth naming the tradeoff: rows now accumulate in the test database across runs instead of being cleared. Nothing reads across workspaces, so that is invisible to assertions, and a dropdb is the reset if it ever gets large.

Closes #15

Every startTestServer ran TRUNCATE workspaces CASCADE, so two suite runs
against one TEST_DATABASE_URL deleted each other's rows mid-test. The failures
read as auth bugs, since the credential row vanished between the seed and the
request, and nothing in the output pointed at the other process.

Nothing needed the wipe. Every test already creates its own workspace and
everything else cascades from it. One assertion counted oauth_states across the
whole table; it now names the state it is actually about.

Closes #15
@fajarhide
fajarhide force-pushed the fix/scoped-test-cleanup branch from f9e8092 to 134ebcc Compare August 17, 2026 04:16
@fajarhide
fajarhide merged commit 2ed5189 into main Aug 17, 2026
2 checks passed
@fajarhide
fajarhide deleted the fix/scoped-test-cleanup branch August 17, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two concurrent test runs share one database, and every startTestServer truncates it

1 participant