fix: add WAL checkpoint on test cleanup to prevent SQLITE_IOERR_SHMSIZE

When 88 integration test files run sequentially in a single-fork
Vitest process, the SQLite WAL file grows unbounded. Adding a
TRUNCATE checkpoint after each test app cleanup prevents the SHM
mapping from exceeding its size limit.
This commit is contained in:
SnapOtter
2026-05-14 10:46:24 +08:00
parent cd24bb92b6
commit 42d1a62ea2
2 changed files with 8 additions and 7 deletions
+8 -3
View File
@@ -184,9 +184,14 @@ export async function buildTestApp(): Promise<TestApp> {
const cleanup = async () => {
await app.close();
// Don't delete the temp DB directory here — other test files in the same
// vitest run share it. The directory lives under /tmp with a random UUID
// and is cleaned up by the OS.
// Checkpoint WAL to prevent unbounded growth across sequential test files.
// Without this, the WAL/SHM files grow until SQLite hits SQLITE_IOERR_SHMSIZE.
try {
const { sqlite } = await import("../../apps/api/src/db/index.js");
sqlite.pragma("wal_checkpoint(TRUNCATE)");
} catch {
// best-effort
}
};
return { app, cleanup };
-4
View File
@@ -23,8 +23,6 @@ export default defineConfig({
globals: true,
testTimeout: 30_000,
hookTimeout: 30_000,
// Run all test files in a single forked process so integration tests share
// the same SQLite connection and avoid SQLITE_BUSY races on WAL setup.
pool: "forks",
poolOptions: {
forks: {
@@ -44,8 +42,6 @@ export default defineConfig({
".worktrees/**",
".claude/**",
],
// These env vars are injected into process.env BEFORE test files are
// imported, ensuring apps/api/src/config.ts picks them up correctly.
env: {
AUTH_ENABLED: "true",
DEFAULT_USERNAME: "admin",