Skip to content

Conversation

@brandonkachen
Copy link
Collaborator

No description provided.

@brandonkachen brandonkachen changed the title [refactor] Billing di refactor [refactor] Billing DI refactor Dec 16, 2025
- Add typed mock helpers in common/src/testing/fixtures/:
  - billing.ts: createGrantCreditsDbMock, createOrgBillingDbMock, etc.
  - fetch.ts: createMockFetch, wrapMockAsFetch, etc.
  - database.ts: createVersionQueryDbMock, createExistsQueryDbMock
  - agent-runtime.ts: mockAnalytics, mockBigQuery, mockRandomUUID
  - index.ts: barrel exports

- Refactor billing package to use DI:
  - Add optional conn parameter to grant-credits, org-billing, credit-delegation
  - Add injectable function parameters to usage-service
  - Update all 4 test files to use typed mock helpers

- Refactor agent-runtime tests to use shared mock helpers:
  - Replace inline spyOn calls with mockAnalytics/mockBigQuery/mockRandomUUID
  - Update 8 test files

- Refactor SDK code-search to use DI:
  - Export SpawnFn type and codeSearchWithSpawn function
  - Update tests to use typed mock spawn

- Refactor CLI tests to use wrapMockAsFetch:
  - Update codebuff-api, use-usage-query, and integration tests

- Add SDK build step to init-worktree.ts for fresh worktree setup

- Add barrel export for testing/fixtures in common/package.json

Eliminates ~30 mockModule calls and ~50 "as unknown as" type casts.
All 100+ affected tests pass.
The 2000 credit cap was a temporary migration safeguard that is no longer needed.
Update imports to use @codebuff/common/testing/fixtures barrel file instead of individual module paths.
- Remove .optional() from NEXT_PUBLIC_POSTHOG_API_KEY
- Remove .optional() from NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL
- Remove conditional check in usage-section.tsx since portal URL is now required
- All required vars have dummy values in .env.example
- Remove .default() from NEXT_PUBLIC_CB_ENVIRONMENT
- Remove .default() from NEXT_PUBLIC_CODEBUFF_APP_URL
- Remove .default() from NEXT_PUBLIC_WEB_PORT
- Keep defaults only for SUPPORT_EMAIL and POSTHOG_HOST_URL
- Add NEXT_PUBLIC_WEB_PORT to .env.example
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.

2 participants