Fix integration test cleanup to delete orphaned sources and flu* users
Problem
The integration test cleanup function (R__090_integration_test_cleanup.sql) leaves orphaned data in the database after tests run:
1. Orphaned "Test User" sources (56 found)
Source: user-tests.ts:9-10
const username = `tu${Date.now()}`;
const result = await api.createUser(username, 'Test', 'User', `${username}@test.com`);
The create_user function creates a source with creator_id = 0 (system), but the cleanup only deletes sources where creator_id = v_test_user_id. When the tu* users are deleted, their sources remain orphaned.
2. "flu*" users not cleaned up (6 found)
Source: feed-generator-execution-tests.ts:904-905
const followedUsername = `flu${Date.now()}`;
const userResult = await api.createUser(followedUsername, 'Followed', 'User', ...);
The cleanup regex only matches ^tu[0-9]+$ or ^del[0-9]+$ - the flu* pattern is missing entirely.
3. Orphaned "Delegate User" sources
Source: feed-generator-execution-tests.ts:442-448
const delegateUsername = `del${Date.now()}`;
const delegateResult = await api.createUser(delegateUsername, 'Delegate', 'User', ...);
Users are deleted (matches ^del[0-9]+$), but their sources (with creator_id = 0) remain orphaned.
Solution
Update R__090_integration_test_cleanup.sql to:
-
Delete sources linked to test users via
source_idbefore deleting the users:
-- Delete sources that are linked to test users being deleted
DELETE FROM sources s
USING users u
WHERE u.source_id = s.id
AND u.id != v_test_user_id
AND (u.username ~ '^tu[0-9]+$' OR u.username ~ '^del[0-9]+$' OR u.username ~ '^flu[0-9]+$');
-
Add
flu*pattern to the user cleanup regex:
DELETE FROM users
WHERE id != v_test_user_id
AND (username ~ '^tu[0-9]+$' OR username ~ '^del[0-9]+$' OR username ~ '^flu[0-9]+$');
- Update all related cleanup statements (follow_lists, user_active_follow_lists, etc.) to include the
flu*pattern.
Acceptance Criteria
- Running integration tests and cleanup leaves no orphaned sources
-
flu*users are cleaned up along withtu*anddel*users -
All sources linked to test users via
source_idare deleted