From 5864710e4f8e5de40b2bcd900b5cee1e9f94e6c5 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 25 Feb 2026 13:12:02 -0500 Subject: [PATCH] Add test library cleanup by name and documentation Problem: - Libraries are universal (not user-owned) and persist in database - Tests create libraries via API but don't clean them up - Libraries accumulate between test runs Solution: - Delete test libraries (names containing "test") during cleanup - Uses case-insensitive matching to catch "Test", "TEST", "test", etc. - Preserves user-created libraries without "test" in name Changes: 1. cmd/server/tests/test_helpers.go: - Added library cleanup in setupTestServer() after user cleanup - Lists all libraries and deletes those with "test" in name - Includes warning comment about naming convention 2. docs/contributing/development.md: - Added "Test Library Naming Convention" section - Documents that "test" in library names triggers deletion - Recommends alternative names for persistent test libraries Note: Users should NOT use "test" in library names if they want to keep them. --- cmd/server/tests/test_helpers.go | 10 ++++++++++ docs/contributing/development.md | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/cmd/server/tests/test_helpers.go b/cmd/server/tests/test_helpers.go index 4f41ff3..4c86779 100644 --- a/cmd/server/tests/test_helpers.go +++ b/cmd/server/tests/test_helpers.go @@ -529,6 +529,16 @@ func setupTestServer(t *testing.T) *TestServerSetup { } } + // Delete test libraries (names containing "test" - case insensitive) + // This cleans up libraries created by tests while preserving user-created libraries + // NOTE: Do not use "test" in library names if you want to keep them! + allLibs, _ := queries.ListLibraries(ctx) + for _, lib := range allLibs { + if strings.Contains(strings.ToLower(lib.Name), "test") { + queries.DeleteLibrary(ctx, lib.ID) + } + } + // Create fresh admin test user passwordHash := "$2a$10$JjAtK7PPa1WexQC3AUGe8OXLeuseZ/haN1Mz7emMo6CfOvMiTVXWq" adminUser, err := queries.CreateUser(ctx, database.CreateUserParams{ diff --git a/docs/contributing/development.md b/docs/contributing/development.md index 2c4ca19..33113aa 100644 --- a/docs/contributing/development.md +++ b/docs/contributing/development.md @@ -279,6 +279,15 @@ Environment variables for testing: **⚠️ WARNING**: Never enable these in production! +### Test Library Naming Convention + +Integration tests automatically clean up libraries with "test" in the name (case-insensitive). + +**⚠️ IMPORTANT**: Do not use "test" in library names if you want to keep them! +- Libraries containing "test" (e.g., "My Test Library", "Test Library 1") will be deleted by test cleanup +- Use names like "Development Library", "Staging Books", or "Personal" for libraries you want to keep +- This ensures your manual test data persists between test runs + ## 📝 Code Style Guidelines ### Go Code