feat(config): add Zod-based startup env validation | ENG-193#294
Merged
feat(config): add Zod-based startup env validation | ENG-193#294
Conversation
Add environment variable validation at startup for backend, worker, and frontend services using Zod schemas. Misconfiguration is now caught immediately with clear, actionable error messages instead of causing silent failures or cryptic runtime errors. Shared schemas (packages/shared/src/env.ts): - databaseUrlSchema, temporalConfigSchema, minioConfigSchema - secretStoreKeySchema (exactly 32 chars), kafkaBrokersSchema - stringToBoolean helper (avoids JS coercion footgun) - formatEnvErrors for readable console output Backend (backend/src/config/env.schema.ts): - Conditional: DATABASE_URL/LOG_KAFKA_BROKERS optional when SKIP_INGEST_SERVICES=true - AUTH_PROVIDER normalized via transform+pipe+catch pattern - Clerk keys required conditionally when AUTH_PROVIDER=clerk Worker (worker/src/config/env.schema.ts): - Required: DATABASE_URL, SECRET_STORE_MASTER_KEY, LOG_KAFKA_BROKERS - MinIO and Temporal configs with sensible defaults Frontend (frontend/src/config/env.schema.ts): - VITE_API_URL defaults to localhost:3211 (test compatibility) - All VITE_* vars optional with defaults - Clerk key required conditionally Test setup provides SECRET_STORE_MASTER_KEY and SKIP_INGEST_SERVICES defaults so AppModule import doesn't fail in integration tests. Existing ad-hoc checks in database.module.ts and dev.worker.ts are preserved as defense-in-depth. Signed-off-by: Aseem Shrey <LuD1161@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d2634a55fd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…p forcing SKIP_INGEST_SERVICES in test setup Address PR review feedback: - superRefine now checks both ENABLE_INGEST_SERVICES and SKIP_INGEST_SERVICES, matching the runtime guard in node-io.module.ts / trace.module.ts - test/setup.ts provides dummy DATABASE_URL and LOG_KAFKA_BROKERS instead of setting SKIP_INGEST_SERVICES=true, so integration tests exercise real code paths Signed-off-by: Aseem Shrey <LuD1161@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
packages/shared/src/env.tsavoid duplication across servicesKey design decisions
true, DATABASE_URL and LOG_KAFKA_BROKERS become optional (backend)stringToBooleanhelper avoids JS footgun whereBoolean("false") === truetransform+pipe+catchpattern trims, lowercases, and defaults unknown values to'local''http://localhost:3211'preserving test compatibility'localhost'matching current behaviorFiles changed
New files (10):
packages/shared/src/env.ts— shared Zod schemas + helpersbackend/src/config/env.schema.ts— backend env schema with conditional validationbackend/src/config/env.validate.ts— validation function for NestJS ConfigModuleworker/src/config/env.schema.ts— worker env schemaworker/src/config/env.validate.ts— worker validation functionfrontend/src/config/env.schema.ts— frontend env schemaModified files (5):
packages/shared/src/index.ts— export env modulebackend/src/app.module.ts— addvalidate: validateBackendEnvto ConfigModuleworker/src/temporal/workers/dev.worker.ts— add validation call after dotenvfrontend/src/config/env.ts— replace manual fallback pattern with Zod validationtest/setup.ts— provide test defaults for SECRET_STORE_MASTER_KEY and SKIP_INGEST_SERVICESManual Verification (SHIPSEC_INSTANCE=1)
Tested by creating
.instances/instance-1/backend.envwith each config and runningSHIPSEC_INSTANCE=1 bun src/main.tsfrombackend/:DATABASE_URLfrom envDATABASE_URL is required (set SKIP_INGEST_SERVICES=true or ENABLE_INGEST_SERVICES=false to skip)SKIP_INGEST_SERVICES=truewithoutDATABASE_URLSECRET_STORE_MASTER_KEY="short"SECRET_STORE_MASTER_KEY must be exactly 32 charactersAUTH_PROVIDER=clerkwithoutCLERK_SECRET_KEYCLERK_SECRET_KEYandCLERK_PUBLISHABLE_KEYreported missing.envwith all required fieldsTest plan