From 199d82c613f44524405e9d477f010266c5cda30f Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 14 Oct 2026 13:53:51 -0400 Subject: [PATCH] fix(tests): sync-integration cleanup wiped the shared reading_history table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sync_integration_test's cleanup ran DELETE FROM reading_history WHERE true — harmless for years while the table sat empty, and a silent stats-data destroyer the moment session capture started feeding it: every suite run erased the shared dev accounts' captured reading (the user's manual flip-through test data included). The cleanup is now scoped: the sync tests' sessions belong to their test-sync users, and deleting those users cascades their rows. Any future table-wide cleanup DELETE is off the table (AGENTS.md test rules updated). --- AGENTS.md | 5 ++++- cmd/server/tests/sync_integration_test.go | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 747a9dc5..60819108 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -53,7 +53,10 @@ were name-only across ALL libraries. Fixed; do not regress. broke on 2026-10-14 within hours of session capture shipping). Tests that need deterministic data use `setup.RegularToken` + `getRegularUserID` (the fresh per-test user), or assert ranges - instead of equals. + instead of equals. Related: **no table-wide DELETEs in test + cleanups** — sync_integration's `DELETE FROM reading_history WHERE + true` destroyed the live reader's stats data on every suite run + until scoped to the test-sync users (cascade via user delete). ## Timezones diff --git a/cmd/server/tests/sync_integration_test.go b/cmd/server/tests/sync_integration_test.go index 9b49c8a0..6b90f661 100644 --- a/cmd/server/tests/sync_integration_test.go +++ b/cmd/server/tests/sync_integration_test.go @@ -32,12 +32,16 @@ func setupSyncTestDB(t *testing.T) *database.Queries { db := database.New(dbPool) t.Cleanup(func() { + // Scoped wipes ONLY: reading_history now carries real captured + // sessions for the shared dev accounts, so a table-wide DELETE + // here silently destroyed a live reader's stats data on every + // suite run (2026-10-14). Sync-test sessions belong to the + // test-sync users; deleting those users cascades their rows. _, _ = dbPool.Exec(ctx, "DELETE FROM sync_queue WHERE true") - _, _ = dbPool.Exec(ctx, "DELETE FROM reading_history WHERE true") + _, _ = dbPool.Exec(ctx, "DELETE FROM users WHERE email LIKE 'test-sync%'") _, _ = dbPool.Exec(ctx, "DELETE FROM media_items WHERE title LIKE 'Test %'") _, _ = dbPool.Exec(ctx, "DELETE FROM libraries WHERE name LIKE 'Test %'") _, _ = dbPool.Exec(ctx, "DELETE FROM devices WHERE device_name LIKE 'Test %'") - _, _ = dbPool.Exec(ctx, "DELETE FROM users WHERE email LIKE 'test-sync%'") dbPool.Close() })