Query402 uses Vitest for deterministic, network-free unit and API integration tests.
From the repository root:
npm testCoverage report with baseline thresholds:
npm run test:coverageCoverage output is written to apps/api/coverage/.
- Shared Zod schemas and provider/category validation (
packages/shared) - Public health, catalog, usage, and analytics routes (
apps/api) - Protected query input validation for search, news, and scrape
- Dynamic provider pricing for all paid modes
- Demo-mode 402 challenge and paid retry semantics without live credentials
- Agent-client URL construction and error handling
- Provider registry, scrape URL safety, sponsorship, and idempotency behavior
- Tests inject fixed timestamps where responses include time-dependent fields.
- Analytics SQLite storage uses a temporary database per test via
ANALYTICS_DB_PATHand helpers inapps/api/src/test/storage-test-helpers.ts. - Sponsorship/idempotency SQLite storage uses a temporary database per test via
SPONSORSHIP_DB_PATH. - Live Stellar testnet spending is out of scope for normal CI runs. Quality-gate and CI workflow changes are handled separately from this test foundation.
The API Vitest coverage config enforces these minimum thresholds:
- Lines: 35%
- Functions: 35%
- Statements: 35%
- Branches: 30%
Adjust thresholds in apps/api/vitest.config.ts only after intentional coverage improvements.
Run the root test command twice and confirm identical passing results:
npm test
npm test