From 248cce454cb771cd9d656efd47e3264f6b74f6b5 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Sun, 2 Nov 2025 16:04:36 -0800 Subject: [PATCH] Document and enforce private memory test isolation pattern (bd-2e80) - Update newTestStore to default to private memory mode - Add comprehensive documentation explaining test isolation - Prevents shared :memory: database interference between tests Amp-Thread-ID: https://ampcode.com/threads/T-97b59814-3d1a-4f32-bcd2-07a7b81c2b65 Co-authored-by: Amp --- internal/storage/sqlite/test_helpers.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/storage/sqlite/test_helpers.go b/internal/storage/sqlite/test_helpers.go index 0c3a0e12..c8542ee8 100644 --- a/internal/storage/sqlite/test_helpers.go +++ b/internal/storage/sqlite/test_helpers.go @@ -7,9 +7,24 @@ import ( // newTestStore creates a SQLiteStorage with issue_prefix configured (bd-166) // This prevents "database not initialized" errors in tests +// +// Test Isolation Pattern (bd-2e80): +// By default, uses "file::memory:?mode=memory&cache=private" for proper test isolation. +// The standard ":memory:" creates a SHARED database across all tests in the same process, +// which can cause test interference and flaky behavior. The private mode ensures each +// test gets its own isolated in-memory database. +// +// To override (e.g., for file-based tests), pass a custom dbPath: +// - For temp files: t.TempDir()+"/test.db" +// - For shared memory (not recommended): ":memory:" func newTestStore(t *testing.T, dbPath string) *SQLiteStorage { t.Helper() + // Default to private memory for test isolation + if dbPath == "" { + dbPath = "file::memory:?mode=memory&cache=private" + } + store, err := New(dbPath) if err != nil { t.Fatalf("Failed to create test database: %v", err)