test: cover the AI_REQUEST entitlement gate (AI cost control) - #42
Merged
Conversation
checkEntitlement('AI_REQUEST') is the monthly cost-control gate every AI
endpoint passes through (FREE=50/mo, STARTER=500, ...), but the branch
had no direct test — only getSubscriptionUsage was covered. New tests:
- allows below quota (49/50)
- blocks at the exact boundary (50/50) and above with 403 + the
monthly-limit message
- counts only this month (createdAt >= start of month), org-scoped
- scales with plan (STARTER 499 ok / 500 blocked)
No production code changed.
✅ Deploy Preview for teamsynch-ai canceled.
|
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.
Problem
checkEntitlement('AI_REQUEST')is the monthly cost-control gate every AI endpoint passes through (FREE = 50 requests/mo, STARTER = 500, PRO = 5000, BUSINESS = 50000). It blocks AI calls with a 403 once the org's monthlyAIUsageLogcount reaches the plan quota. The branch had no direct test — onlygetSubscriptionUsagewas covered — so the most important cost-protection boundary in the AI path was unpinned.Solution
New tests in
entitlement.service.test.ts(mocked prisma, deterministic, DB-free):createdAt >= start of month), org-scopedValidation results
npm run typecheck: cleannpm run build: cleanRisk
LOW. Tests only — no production code touched.
Rollback
Revert the PR (delete the added tests). No production impact either way.
Production behavior
Not changed. Entitlement logic, quotas, and all AI behavior are untouched. Only coverage was added.