Skip to content

fix(env): treat empty-string env vars as unset across all apps#8

Merged
alextnetto merged 1 commit into
mainfrom
fix/env-empty-strings
May 10, 2026
Merged

fix(env): treat empty-string env vars as unset across all apps#8
alextnetto merged 1 commit into
mainfrom
fix/env-empty-strings

Conversation

@alextnetto
Copy link
Copy Markdown
Member

Summary

Follow-up to #3. Railway/Nixpacks (and several other PaaS / CI runners) pass unset env vars to Node as "" rather than omitting them. The strict env validation introduced in #3 rejected "" because .optional() on enum/url/coerce.number only accepts undefined. Result: every Railway boot since #6 merged crashed with:

Invalid environment: ZodError: NODE_ENV — Expected
'development' | 'production' | 'test', received ''

Fix

Wrap each app's schema in z.preprocess that maps ""undefined before the typed schema runs. Same pattern across all three apps so behaviour is consistent.

Tests

Added 4 regression tests in apps/api/schemas.test.ts covering NODE_ENV, LOG_LEVEL, PUBLIC_URL, and PORT under empty-string input. 162/162 tests pass locally.

Notes

  • Also pulls in the .gitignore update from vercel link (excludes apps/web/.vercel/)
  • The MCP bundle is rebuilt to include the preprocess wrapper

Test plan

  • CI green
  • Railway deploy after merge boots cleanly (no ZodError)
  • curl https://pagent.up.railway.app/health{"ok":true,"db":"ok"}

Railway/Nixpacks (and several other PaaS / CI runners) pass unset env
vars to Node as "" rather than omitting them. That made every Railway
boot since PR #3 crash with:

  Invalid environment: ZodError: NODE_ENV — Expected
  'development' | 'production' | 'test', received ''

The new validation introduced in #3 is correct in spirit (fail loud on
bad config) but `.optional()` on enum/url/coerce.number rejects "" —
exactly the value Railway ships in practice.

Wrap each app's schema in a `z.preprocess` step that maps "" → undefined
before the typed schema runs. Add regression tests covering NODE_ENV,
LOG_LEVEL, PUBLIC_URL, and PORT under empty-string input.

Also stage the apps/web/.gitignore update from `vercel link` so the
generated .vercel/ directory stays out of the repo.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pagent Error Error May 10, 2026 7:21pm

Request Review

@alextnetto alextnetto merged commit 3011a9e into main May 10, 2026
2 of 3 checks passed
@alextnetto alextnetto deleted the fix/env-empty-strings branch May 10, 2026 19:22
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