From eefc0457be8f0c71b388a20a19053787b286ea53 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Sivakumar Date: Thu, 13 Aug 2026 22:09:33 +0530 Subject: [PATCH] fix(test): use a fresh random user per ai_credits_reaper.rs run The fixed UUID (33333333-...) meant every re-run against the same persistent test database reused the same wallet - any earlier partial run that panicked before its own capture/release step left reserved_credits permanently stuck above zero, so this run's fresh reserve (expected to bring it to exactly 4) actually reads 8, 12, etc. depending on how many times the suite had previously failed midway. Matches ai_credits.rs's make_user() pattern (Uuid::new_v4()) instead. Co-Authored-By: Claude Sonnet 5 --- crates/db/tests/ai_credits_reaper.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/db/tests/ai_credits_reaper.rs b/crates/db/tests/ai_credits_reaper.rs index 4afdcd4..406e2b3 100644 --- a/crates/db/tests/ai_credits_reaper.rs +++ b/crates/db/tests/ai_credits_reaper.rs @@ -21,12 +21,15 @@ async fn pool() -> PgPool { #[tokio::test] 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(); + // A fresh random user/wallet every run (matching ai_credits.rs's + // make_user() pattern) rather than the fixed UUID this test used to + // hardcode - against a persistent test database re-run many times over + // a session, reusing one fixed user let earlier partial runs' stuck + // reserved_credits (left over whenever the test panicked before its own + // capture/release step) silently accumulate onto every subsequent run. + let user_id = Uuid::new_v4(); - // 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. + // user_ai_subscriptions.user_id has a FK to users(id). 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"))