Skip to content

fix(api): treat empty optional env vars as unset - #159

Open
stringbitking wants to merge 1 commit into
theam:mainfrom
stringbitking:fix/empty-optional-env-vars
Open

fix(api): treat empty optional env vars as unset#159
stringbitking wants to merge 1 commit into
theam:mainfrom
stringbitking:fix/empty-optional-env-vars

Conversation

@stringbitking

Copy link
Copy Markdown

Fixes #158 — a fresh clone's pnpm dev crashes the API and worker because .env.example ships the VERCEL_* keys as blank assignments (KEY=), dotenv delivers those as empty strings, and the min(1).optional() declarations in services/api/src/config.ts reject empty-present values.

What this does

Implements Option A from the issue: extends the blank-to-undefined preprocess idiom the file already uses for OptionalUrl, OptionalGithubOrganization, and FACILITY_PREVIEW_SURFACE_TOKEN to the whole optional non-empty group — VERCEL_TOKEN, VERCEL_OIDC_TOKEN, VERCEL_TEAM_ID, VERCEL_PROJECT_ID, FACILITY_AWS_CODEBUILD_PROJECT, FACILITY_AWS_CODEBUILD_CACHE_BASE_LOCATION, and PACKAGE_REGISTRY_TOKEN.

A blank or whitespace-only value now parses as unset (matching how facility doctor already reasons about these values via truthiness), while a value that is actually set must still be non-empty after trimming. Existing generated .env files heal without edits.

Why this doesn't change an intentional guarantee

  • There is no cross-field validation requiring the tokens when FACILITY_SANDBOX_DRIVER=vercel — absent tokens already boot fine today, so the current min(1) only rejected one spelling of "not configured" while accepting the other.
  • No existing test pinned the empty-string rejection; the Vercel config test covers trimming and OIDC-over-token precedence, both preserved.
  • facility doctor remains the fail-fast surface for "driver selected but not configured".

Happy to rework toward Option B (comment the blank lines out of .env.example, keep the strict schema) if you prefer strict-presence semantics.

Tests

Two new cases in services/api/test/config.test.ts:

  • the exact .env-template shape (all seven keys blank) boots and resolves every value to undefined;
  • a whitespace-only value resolves identically to the key being absent.

vitest run test/config.test.ts: 16 passed. tsc --noEmit and biome check clean on the touched files.

🤖 Generated with Claude Code

.env.example ships VERCEL_TOKEN=, VERCEL_OIDC_TOKEN=, VERCEL_TEAM_ID= and
VERCEL_PROJECT_ID= as blank assignments, and pnpm dev copies them verbatim
into .env. dotenv delivers a blank assignment as an empty string, which the
min(1).optional() declarations reject — so a fresh clone's first boot
crashes the API and the worker while the rest of the stack comes up.

Extend the file's existing blank-to-undefined preprocess idiom (already
used by OptionalUrl, OptionalGithubOrganization and
FACILITY_PREVIEW_SURFACE_TOKEN) to the whole optional non-empty group:
VERCEL_*, FACILITY_AWS_CODEBUILD_* and PACKAGE_REGISTRY_TOKEN. A blank or
whitespace-only value now parses as unset, matching how facility doctor
already reasons about these values; a value that is actually set must
still be non-empty.

Fixes theam#158

Co-Authored-By: Claude Fable 5 <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.

Fresh pnpm dev crashes the API and worker: blank VERCEL_* lines in the generated .env fail config validation

1 participant