Repository navigation
fix(billing): take a hand-set Enterprise AI budget only at the plan's $50 or more - #1675
Merged
gkhngyk merged 2 commits intoOct 28, 2026
Merged
Conversation
… $50 or more Follow-up from ansvisor#1598 (item 1). The comment said "$50 or more", but any finite number was taken: 0 or a negative number made every AI call answer "budget used up" (reserveAiBudget), and -1 read as unlimited. applyPlanOverrides now takes plan_overrides.improveMonthlyBudgetUsd only when it's a number at or above the plan's budget (Enterprise's $50, the floor the billing cards and the AI usage tiers name); anything else keeps the plan's. Unlimited AI isn't something a customer is given by hand. Tests: 0, -5, -1 and just under the plan's keep the plan's; the AI usage meter reads an override of 0 on the plan's $50. The meter's own test of a $0 budget (still read as used up) now mocks a plan with 0 instead of setting one by hand. Item 2 (ansvisor#1604's dialog reusing aiUsageCustom) is ansvisor#1604's to take when it's rebased. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n't leak it Review follow-up. The "budget of nothing" test undid its plans.js mock at the end of its own body, so a failure there left the next tests reading a $0 budget. The unmock is in afterEach now, beside the supabase one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 28, 2026
gkhngyk
approved these changes
Oct 28, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Looks good.
Item 1 of the #1598 review: Done.
What I checked:
- Own change. Two commits (da52281, 97b38be) on 3f6a4d4. It merges cleanly on main (b591947), including with #1629's rework of
getAiUsageand its tests: the merged "budget of nothing" test keeps this PR's mocked plan and main'sfeaturesexpectation ([]). It merges cleanly with #1670, #1671 and #1674 too. - The floor.
applyPlanOverridestakesplan_overrides.improveMonthlyBudgetUsdonly as a finite number at or above the plan's own budget.0,-5,-1,4.98(against a mocked $4.99) and anything that isn't a number now keep the plan's. A missing key still leaves the plan's budget alone.- Only Enterprise organizations reach this branch, and every reader of the budget (
reserveAiBudget, the usage reads, the Improve and task-writer checks) goes throughresolveOrgPlanByOrgId. The migrations and the web never read the override themselves.
- Tests.
- At the head, the five
plan-guard*files pass (58). On the tree merged with main, they pass too (60). - With main's
plan-guard.jsand this PR's tests, the new floor test and the new meter test fail. - The
doUnmockinafterEach, after theresetModulesinbeforeEach, keeps the mocked plan from reaching the next test.
- At the head, the five
Before the API deploy: no visible change. The floor applies once the API is deployed.
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up from #1598 (item 1): a hand-set Enterprise AI budget is taken only at the plan's $50 or more.
The comment said "$50 or more", but any finite number was taken:
reserveAiBudget);applyPlanOverridesnow takesplan_overrides.improveMonthlyBudgetUsdonly when it's a number at or above the plan's budget: Enterprise's $50, the floor that the billing cards and the AI usage tiers name. Anything else keeps the plan's budget. Unlimited AI isn't something a customer gets by hand.The web only merges overrides raw (no consumer reads the budget there). The meter and the SQL take the budget from the server.
Tests:
Review fix (97b38be): that mock is undone in
afterEach, so a failing test can't leak it.Item 2 (#1604's dialog reusing
aiUsageCustom) belongs to #1604.No visible change; this is a guard.
Related issue
Follow-up from #1598's review.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
cd server && npx vitest run src/lib/plan-guard.test.js src/lib/plan-guard-ai-usage.test.jsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Full checks were run in one tree with this batch's ten follow-up branches merged, and again after the review fixes:
npm test: 246 files, 3,343 tests passed;vitest: 447 files, 4,352 tests passed (after the review fixes).A pre-push review was run on all ten branches.
🤖 Generated with Claude Code