Skip to content

fix(api): gate /api/_test/* routes to non-production (closes #116)#125

Open
themightychris wants to merge 1 commit into
mainfrom
fix/gate-test-routes-to-non-prod
Open

fix(api): gate /api/_test/* routes to non-production (closes #116)#125
themightychris wants to merge 1 commit into
mainfrom
fix/gate-test-routes-to-non-prod

Conversation

@themightychris
Copy link
Copy Markdown
Member

Summary

Closes #116. Three test-harness routes in `apps/api/src/routes/health.ts`:

  • `POST /api/_test/validation-error`
  • `POST /api/_test/internal-error`
  • `POST /api/_test/idempotency`

were always reachable in production. Any caller could hit `/api/_test/internal-error` and force a 500.

Fix: wrap the three route registrations in `if (fastify.config.NODE_ENV !== 'production')`. CI tests that depend on these routes already run in `NODE_ENV=test`, so nothing breaks.

New test asserts all three return 404 when the app is built with `NODE_ENV=production`, plus that `/api/health` still works (sanity check that prod-mode boot didn't regress anything else).

Test plan

  • `npm run -w apps/api type-check` clean
  • `npm run lint` clean
  • `npm run -w apps/api test -- tests/api-skeleton.test.ts` — 11/11

🤖 Generated with Claude Code

The three test-harness routes in health.ts:

  POST /api/_test/validation-error
  POST /api/_test/internal-error
  POST /api/_test/idempotency

exist purely to exercise the error-mapping + idempotency code paths
from CI. They were always reachable in production — meaning any caller
could hit /api/_test/internal-error and force a 500. Defense in depth:
wrap registration in `if (fastify.config.NODE_ENV !== 'production')`.

CI tests that depend on these routes already run in NODE_ENV=test, so
nothing breaks. New api-skeleton test asserts all three return 404
when the app is built with NODE_ENV=production.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

docs: gate /api/_test/* endpoints to non-prod OR document them in api/conventions.md

1 participant