chore(config): adding zod schemas to manage envs - #45
Open
ArtuArtaza wants to merge 1 commit into
Open
ArtuArtaza wants to merge 1 commit into
ArtuArtaza wants to merge 1 commit into
Conversation
Replace inline process.env reads in the server and browser entrypoints with typed, per-feature zod schemas under src/config/env/. Each feature module (core, parallel, browser, voice, slack, computer) owns its slice and the aggregator composes a ServerEnv. PlatformConfig keeps its runtime shape and is now derived from the parsed env via platformConfigFromEnv(), with runtimeUrl computed once in the entrypoint. - Defaults preserved (HOST/PORT/DATABASE_PATH/OWNER_ID/OPENAI_BASE_URL/VOICE_NAME) - Same boot-time guards: BROWSER_SECRET min 24 chars; OWNER_TOKEN required for external bindings; WEB_SEARCH_PROVIDER enum (parallel|browser|disabled) - Slack user list parsing, port coercion, URL validation all moved into schemas - Removed the webSearchProvider() helper (deprecated-leftover cutover complete); test exercises parallelEnvSchema directly - Added tests/env.test.ts (14 cases) covering defaults, classification, and validation failures
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
Centralizes environment-variable parsing for the server and browser entrypoints using per-feature zod schemas under
src/config/env/. Each feature module (core, parallel, browser, voice, slack, computer) owns its own slice, and the aggregator composes a typedServerEnv. The downstreamPlatformConfigruntime shape is preserved and now derived from the parsed env viaplatformConfigFromEnv(), withruntimeUrlcomputed once in the entrypoint.Why
Previously, both entrypoints read
process.envinline, scattering default values, string transforms (SLACK_USER_IDS), enum coercion (WEB_SEARCH_PROVIDER), URL coercion, and boot-time guards (BROWSER_SECRETlength,OWNER_TOKENfor external binding) across multiple files. Per-feature zod schemas give:z.infer, nostring | undefinedhandling at every call site.Invalid <feature> environment: ...error per process).Changes
src/config/env/{core,parallel,browser,voice,slack,computer}.ts— zod schemas + inferredEnvtypes per feature.src/config/env/index.ts— aggregator (parseServerEnv,parseBrowserEnv) and sharedServerEnvtype.src/config/env.ts— re-export barrel so call sites keep using../config/env.js.src/server/index.ts— noprocess.envreads; buildsPlatformConfigviaplatformConfigFromEnv().src/browser/index.ts— usesparseBrowserEnv();BROWSER_SECRETlength enforced by the schema.src/server/platform-config.ts—PlatformConfiginterface kept identical; addsplatformConfigFromEnv()projection;setupStatus()unchanged.src/server/parallel.ts— re-exportsWebSearchProvidertype from config;webSearchProvider()helper removed (deprecated-leftover cutover complete; test now exercisesparallelEnvSchemadirectly).tests/env.test.ts— 14 cases covering defaults, host classification, external-bindingOWNER_TOKENguard,BROWSER_SECRETlength, slack list parsing, computer namespace, parallel enum, and theHOSTpost-parse guard.Behavior preserved
BROWSER_SECRETis missing or shorter than 24 chars.HOSTis not local andOWNER_TOKENis missing or shorter than 24 chars.WEB_SEARCH_PROVIDERis anything other thanparallel,browser, ordisabled.SLACK_USER_IDSis split/trimmed the same way (a, b ,,c→['a','b','c']).runtimeUrlderived exactly as before in the entrypoint.Verification
npm run typecheck: clean.npm run lint: clean.npx vitest run: 36 files / 178 tests passing (including the new env schema tests).