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"))