Skip to content

enhancement(api): API token auth: report-endpoint fallback, Valkey cache with immediate invalidation, and capacity test suite#199

Merged
therealbrad merged 2 commits intomainfrom
enhancement/api-token-auth-report-utils
Apr 15, 2026
Merged

enhancement(api): API token auth: report-endpoint fallback, Valkey cache with immediate invalidation, and capacity test suite#199
therealbrad merged 2 commits intomainfrom
enhancement/api-token-auth-report-utils

Conversation

@therealbrad
Copy link
Copy Markdown
Contributor

@therealbrad therealbrad commented Apr 15, 2026

Summary

  • Report endpoints accept Bearer tokens. handle{AutomationTrends,FlakyTests,TestCaseHealth,IssueTestCoverage}POST now fall back to authenticateRequest() alongside the existing getServerSession() check, closing a gap where cross-project reports rejected valid API tokens.
  • API token cache invalidates immediately on revoke. Extracted the Valkey cache helpers into lib/api-token-cache.ts and wired invalidateApiTokenCache() into the Prisma apiToken update / delete / updateMany / deleteMany extensions. A revoked or deleted token is now rejected on the next request instead of the next ~30 seconds.
  • Session-user cache. server/auth.ts now uses getCachedSessionUser() and touchLastActive() from the new lib/session-cache.ts module, eliminating a per-request user.findUnique on every session check.
  • Access manifest + create fast-path. lib/access-manifest.ts precomputes per-user project access; lib/access-fast-path.ts uses it to short-circuit selected create operations (see file header for the whitelist) without going through ZenStack policy evaluation. Wired into the central /api/model/[...path] router.
  • DISABLE_API_RATE_LIMIT env var. lib/api-rate-limit.ts now honors a short-circuit flag used exclusively for isolated load-test stacks.
  • Capacity test suite under testplanit/load-tests/capacity/ — 8 k6 scenarios (concurrent users, import rate, result ingestion, report generation, run creation, search, audit throughput, concurrent runs), a tier seeder, runner shell script, and JSON report generator. Results and generated charts are .gitignored; reference sizing data lives outside the repo.
  • Docs updates. api-reference.md now documents the global hourly rate-limit tiers and response headers; api-tokens.md clarifies that token-authenticated requests are subject to the same limits.
  • E2E coverage. Two new tests in e2e/tests/auth/api-tokens.spec.ts:
    • AUTH-08-8: admin Bearer token authenticates all 4 cross-project report endpoints.
    • AUTH-08-9: non-admin Bearer token is rejected (401) from a cross-project endpoint.

Test plan

  • pnpm type-check
  • pnpm vitest run lib/api-token-auth.test.ts — 25/25
  • pnpm vitest run app/api/api-tokens/route.test.ts — 17/17
  • E2E_PROD=on pnpm test:e2e e2e/tests/auth/api-tokens.spec.ts — 10/10 (includes AUTH-08-3 which was failing before the cache-invalidation fix, plus the two new tests AUTH-08-8/9)
  • CI runs the full test suite

Notes for reviewers

  • The dist/scheduler.js and dist/workers/syncWorker.js diffs are regenerated build artifacts, not source changes.
  • lib/api-token-auth.ts re-exports invalidateApiTokenCache so external callers of the old import path keep working.
  • Capacity test outputs (load-tests/capacity/results/*, load-tests/capacity/charts/*.png) are gitignored. The results/.gitkeep preserves the directory that run-capacity-tests.sh writes into.

therealbrad and others added 2 commits April 13, 2026 17:54
…lity handlers

Extends the authenticateRequest() pattern from the previous PR to 4 additional
report utility handlers that were still using getServerSession() only:
- testCaseHealthUtils (cross-project health report)
- flakyTestsUtils (cross-project flaky tests report)
- automationTrendsUtils (cross-project automation trends)
- issueTestCoverageUtils (cross-project issue-test coverage)

Also updates k6 load test scripts to use the correct report request schema
(reportType required, dimensions/metrics as string arrays) and fixes the
testRuns include relation name (testCases, not testRunCases).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…API token integration

- Expanded the API reference to include a comprehensive overview of global hourly rate limits, detailing tier limits and response headers.
- Updated the API tokens documentation to clarify that requests made with tokens are subject to the same rate limits.
- Enhanced the rate limiting functionality in the codebase, including the ability to disable rate limiting for load testing environments.
- Added tests to verify the behavior of admin and non-admin tokens in cross-project report endpoints.

This update aims to improve user understanding of rate limits and enhance the API's robustness in handling token-based authentication.
@therealbrad therealbrad changed the title API token auth: report-endpoint fallback, Valkey cache with immediate invalidation, and capacity test suite enhancement(api): API token auth: report-endpoint fallback, Valkey cache with immediate invalidation, and capacity test suite Apr 15, 2026
@therealbrad therealbrad merged commit cd82846 into main Apr 15, 2026
5 checks passed
@therealbrad therealbrad deleted the enhancement/api-token-auth-report-utils branch April 15, 2026 18:12
@therealbrad
Copy link
Copy Markdown
Contributor Author

🎉 This PR is included in version 0.21.13 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

therealbrad pushed a commit that referenced this pull request Apr 15, 2026
## [0.21.13](v0.21.12...v0.21.13) (2026-04-15)

### Enhancements

* **api:** API token auth: report-endpoint fallback, Valkey cache with immediate invalidation, and capacity test suite ([#199](#199)) ([cd82846](cd82846))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant