Skip to content

P1: Validate config at startup + fix boolean env parsing (#174, #74)#193

Open
dkijania wants to merge 1 commit into
mainfrom
feat/config-validation
Open

P1: Validate config at startup + fix boolean env parsing (#174, #74)#193
dkijania wants to merge 1 commit into
mainfrom
feat/config-validation

Conversation

@dkijania

Copy link
Copy Markdown
Contributor

What & why

Part of the production-readiness epic (#163). Closes #174, closes #74.

Two problems:

  1. Boolean env bug (Fix Boolean env vars parsing #74): booleans were read with ad-hoc truthiness — if (process.env.ENABLE_LOGGING), if (!process.env.ENABLE_INTROSPECTION), if (!process.env.ENABLE_JAEGER ...). The string "false" is truthy, so ENABLE_LOGGING=false enabled logging, ENABLE_JAEGER=false enabled tracing, etc.
  2. No startup validation: typos (missing PG_CONN, non-numeric PORT) surfaced as confusing runtime behaviour instead of failing fast.

Changes

  • New src/config.ts:
    • parseBoolean — understands true/false, 1/0, yes/no, on/off (case-insensitive); unrecognised/empty → fallback.
    • validateConfig / assertValidConfig — aggregate problems (missing PG_CONN, non-positive-integer PORT/BLOCK_RANGE_SIZE, mistyped booleans) and throw one clear message.
  • Every boolean env read now goes through parseBoolean (plugins.ts, server.ts, jaeger-tracing.ts) — fixes Fix Boolean env vars parsing #74 and makes the previously-strict === 'true' checks accept the same spellings.
  • assertValidConfig() runs first thing at startup, so misconfig fails fast.

Testing

  • npm run build — clean
  • npm run test:unit — all pass; 11 new assertions covering boolean spellings (incl. the "false" case), each validation rule, error aggregation, and the throw
  • npm run lint / npx prettier --debug-check . — clean

🤖 Generated with Claude Code

…ing (#74)

Booleans were read with ad-hoc truthiness — `if (process.env.ENABLE_LOGGING)`,
`if (!process.env.ENABLE_INTROSPECTION)`, `if (!process.env.ENABLE_JAEGER ...)`
— so the string "false" was truthy and *enabled* the feature. There was also no
startup validation, so typos surfaced as confusing runtime behaviour.

- Add `src/config.ts`: a `parseBoolean` that understands true/false, 1/0,
  yes/no, on/off (case-insensitive), plus `validateConfig`/`assertValidConfig`
  that aggregate problems (missing PG_CONN, non-numeric PORT/BLOCK_RANGE_SIZE,
  mistyped booleans) and fail fast with one clear message.
- Route every boolean env read through `parseBoolean` (plugins, server, jaeger
  tracing), fixing the "false enables it" bug (#74) and making all the strict
  `=== 'true'` checks accept the same spellings.
- Call `assertValidConfig()` first thing at startup.

Unit tests cover boolean spellings (incl. the "false" case), each validation
rule, error aggregation, and the throwing behaviour.

Closes #174. Closes #74.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QSuak9smCHbp4N17xjjLF6
@dkijania dkijania added bug Something isn't working production-readiness Work toward making the API production-ready / publicly available P1 Strongly recommended before GA labels Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working P1 Strongly recommended before GA production-readiness Work toward making the API production-ready / publicly available

Projects

None yet

Development

Successfully merging this pull request may close these issues.

P1: Validate config at boot (fail-fast) + fix boolean env parsing (#74) Fix Boolean env vars parsing

1 participant