Skip to content

test: cover the AI_REQUEST entitlement gate (AI cost control) - #42

Merged
akash4550 merged 1 commit into
mainfrom
feat/entitlement-ai-tests
Aug 11, 2026
Merged

test: cover the AI_REQUEST entitlement gate (AI cost control)#42
akash4550 merged 1 commit into
mainfrom
feat/entitlement-ai-tests

Conversation

@akash4550

Copy link
Copy Markdown
Owner

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 monthly AIUsageLog count reaches the plan quota. The branch had no direct test — only getSubscriptionUsage was 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):

  • allows an AI request below quota (49/50)
  • blocks at the exact boundary (50/50) and above (51) with 403 and the monthly-limit message
  • counts only the current month (createdAt >= start of month), org-scoped
  • scales with the plan (STARTER: 499 allowed, 500 blocked)

Validation results

  • API tests: 60 suites, 418 passed (413 pre-existing + 5 new)
  • Web tests: 29 files, 147 passed
  • npm run typecheck: clean
  • npm run build: clean
  • Diff: 1 file, 62 additions / 0 deletions; zero new dependencies; zero migrations; zero UI/deployment/CI changes; zero production code changed

Risk

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.

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.
@netlify

netlify Bot commented Aug 11, 2026

Copy link
Copy Markdown

Deploy Preview for teamsynch-ai canceled.

Name Link
🔨 Latest commit 0519718
🔍 Latest deploy log https://app.netlify.com/projects/teamsynch-ai/deploys/6a7afe8b3761a20008b995fc

@akash4550
akash4550 merged commit af48ade into main Aug 11, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant