mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -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 };
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user