From b48a1dd2049ff3e1b0ddb5cf81df14393ac638b2 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Sivakumar Date: Thu, 13 Aug 2026 21:52:54 +0530 Subject: [PATCH] fix(test): self-provision the fixture user in ai_credits_reaper.rs expired_hold_is_swept_and_credits_return_to_available used a hardcoded UUID assuming a matching users row already existed in whatever database it ran against, but user_ai_subscriptions.user_id has a FK to users(id) - against a fresh database (like CI's nxtgauge_test) this failed with a foreign key violation before the actual sweep/release logic under test ever ran. Provision it inline instead, matching ai_credits.rs's make_user() pattern. Co-Authored-By: Claude Sonnet 5 --- crates/db/tests/ai_credits_reaper.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/db/tests/ai_credits_reaper.rs b/crates/db/tests/ai_credits_reaper.rs index 44a8d05..deb6ed3 100644 --- a/crates/db/tests/ai_credits_reaper.rs +++ b/crates/db/tests/ai_credits_reaper.rs @@ -23,6 +23,17 @@ async fn expired_hold_is_swept_and_credits_return_to_available() { let pool = pool().await; let user_id = Uuid::parse_str("33333333-3333-3333-3333-333333333333").unwrap(); + // user_ai_subscriptions.user_id has a FK to users(id) - this fixed UUID + // isn't a real seeded user in every environment this test might run + // against (e.g. a fresh CI database), so provision it here rather than + // assuming it pre-exists. Matches ai_credits.rs's make_user() pattern. + sqlx::query("INSERT INTO users (id, email, password_hash) VALUES ($1, $2, 'x') ON CONFLICT (id) DO NOTHING") + .bind(user_id) + .bind(format!("{user_id}@test.local")) + .execute(&pool) + .await + .unwrap(); + AiCreditsRepository::ensure_wallet(&pool, user_id).await.unwrap(); let hold = AiCreditsRepository::try_reserve_credits(&pool, user_id, "help_answer", 4, None, None)