Commit 6566a58
committed
fix(billing): fix critical bugs in consumeFromOrderedGrants
Fix three critical bugs in credit consumption:
1. Stale balance check - grant.balance not updated in memory after DB update
2. Debt not created when needed - condition checked stale balance
3. Silent credit loss - missing else branch when remainingToConsume > 0
Solution: Use effectiveBalances Map as single source of truth for all
grant balance modifications across both passes (debt repayment and
consumption).
Also adds comprehensive test coverage:
- 8 debt creation edge case tests
- 12 consumption code path tests
- Total: 81 billing tests, 196 assertions
All tests pass. Reviewed by 4 CLI agents (Codebuff, Codex, Claude Code, Gemini).1 parent 547ac88 commit 6566a58
File tree
2 files changed
+904
-25
lines changed- packages/billing/src
- __tests__
2 files changed
+904
-25
lines changed
0 commit comments