fix(tests): sync-integration cleanup wiped the shared reading_history table

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).
This commit is contained in:
John O'Keefe committed 2026-10-14 13:53:51 -04:00
1 parent 0914c935d9
commit 199d82c613
2 files changed
+10 -3

No files matched your search

+6 -2
View File
@@ -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()
})