Skip to content

feat(config): lint .env files and enforce no cross-layer key conflicts - #3478

Draft
stalniy wants to merge 4 commits into
mainfrom
feat/config-lint-env-files
Draft

feat(config): lint .env files and enforce no cross-layer key conflicts#3478
stalniy wants to merge 4 commits into
mainfrom
feat/config-lint-env-files

Conversation

@stalniy

@stalniy stalniy commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Why

Closes #1019

What

Add a dotenv-linter based check (script/lint-env.mjs) wired into the per-app CI matrix (reusable-validate-app.yml). For each app it verifies:

  • file hygiene via dotenv-linter (duplicate keys, syntax, blank lines), ignoring checks that conflict with intentional conventions (UnorderedKey, SubstitutionKey, QuoteCharacter, LowercaseKey)
  • no key is shared across files that layer together at runtime (.env, .env.${DEPLOYMENT_ENV}, .env.${NETWORK}), detected by merging each layered pair and reusing dotenv-linter's DuplicatedKey check
  • .env.production and .env.staging declare the same key set
  • .env.sandbox and .env.mainnet declare the same key set

Fix the pre-existing violations the check surfaced:

  • api: add PORT and PROVIDER_PROXY_URL to .env.staging
  • deploy-web: add TRIAL_CREDITS_AMOUNT and the blocked GPU models list to .env.staging; drop the optional GTM id from .env.production
  • stats-web: add GA measurement id to .env.staging
  • hygiene fixes (trailing/extra blank lines, missing values, quoting) across several apps

provider-console is temporarily excluded from the layering checks: its base .env holds mainnet defaults duplicated in the overlays and its .env.production is empty, so restructuring its env layering is left to a dedicated follow-up owned by that team.

Summary by CodeRabbit

  • New Features

    • Added environment configuration linting for consistency, duplicate keys, and matching settings across environment variants.
    • Added an npm run lint:env command for validating all apps or selected apps.
    • Added staging configuration for trial credits, managed-wallet GPU restrictions, and analytics tracking.
    • Added missing staging API and provider settings.
  • Documentation

    • Documented environment-file validation and available linting commands.

Add a dotenv-linter based check (script/lint-env.mjs) wired into the
per-app CI matrix (reusable-validate-app.yml). For each app it verifies:

- file hygiene via dotenv-linter (duplicate keys, syntax, blank lines),
  ignoring checks that conflict with intentional conventions
  (UnorderedKey, SubstitutionKey, QuoteCharacter, LowercaseKey)
- no key is shared across files that layer together at runtime
  (.env, .env.${DEPLOYMENT_ENV}, .env.${NETWORK}), detected by merging
  each layered pair and reusing dotenv-linter's DuplicatedKey check
- .env.production and .env.staging declare the same key set
- .env.sandbox and .env.mainnet declare the same key set

Fix the pre-existing violations the check surfaced:
- api: add PORT and PROVIDER_PROXY_URL to .env.staging
- deploy-web: add TRIAL_CREDITS_AMOUNT and the blocked GPU models list to
  .env.staging; drop the optional GTM id from .env.production
- stats-web: add GA measurement id to .env.staging
- hygiene fixes (trailing/extra blank lines, missing values, quoting)
  across several apps

provider-console is temporarily excluded from the layering checks: its
base .env holds mainnet defaults duplicated in the overlays and its
.env.production is empty, so restructuring its env layering is left to a
dedicated follow-up owned by that team.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 856ecd15-0598-4ac6-9ec0-7e3e5cc994fe

📥 Commits

Reviewing files that changed from the base of the PR and between 0f4d47f and 8ff0483.

📒 Files selected for processing (12)
  • CLAUDE.md
  • apps/api/env/.env
  • apps/api/env/.env.functional.test
  • apps/api/env/.env.production
  • apps/api/env/.env.sample
  • apps/api/env/.env.staging
  • apps/api/env/.env.unit.test
  • apps/deploy-web/env/.env.production
  • apps/deploy-web/env/.env.sample
  • apps/deploy-web/env/.env.staging
  • apps/deploy-web/env/.env.staging-testnet
  • script/lint-env.mjs
📝 Walkthrough

Walkthrough

Adds a Node.js environment-file linter with dotenv-linter checks, integrates it into npm and reusable CI validation, documents usage, and updates application environment files.

Changes

Environment linting

Layer / File(s) Summary
Lint engine and validation flow
script/lint-env.mjs
Discovers app environment files, runs hygiene checks, detects cross-layer duplicate keys, compares overlay key sets, and exits nonzero on failures.
CLI and CI integration
package.json, .github/workflows/reusable-validate-app.yml, CLAUDE.md
Adds the lint:env command, installs and verifies a pinned dotenv-linter binary in CI, runs linting per app, and documents the checks.
Environment-file corrections
apps/*/env/*
Adds or normalizes environment variables and adjusts layered environment files to satisfy the new validation rules.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Assessment against linked issues

Objective Addressed Explanation
Use dotenv-linter for environment-file hygiene and run it in GitHub Actions for every project [#1019]
Prevent conflicting keys across base, deployment, and network environment layers [#1019]
Require matching production/staging and sandbox/mainnet key sets [#1019]
Keep .env.sample current and verify declared variables are used by applications [#1019] The script does not compare .env.sample files or validate variables against env.config.ts declarations.

Out-of-scope changes

Code Change Explanation
Adds standalone numeric lines 35 and 36 to the production environment block (apps/deploy-web/env/.env.production:35-37) These lines are not environment assignments and do not implement any stated issue objective; they may also be invalid dotenv-linter input.

Possibly related PRs

Suggested reviewers: ygrishajev

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/config-lint-env-files

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.88%. Comparing base (0cd230d) to head (8ff0483).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3478   +/-   ##
=======================================
  Coverage   72.87%   72.88%           
=======================================
  Files        1133     1133           
  Lines       29484    29484           
  Branches     7389     7393    +4     
=======================================
+ Hits        21487    21489    +2     
- Misses       7042     7046    +4     
+ Partials      955      949    -6     
Flag Coverage Δ
api 85.84% <ø> (+0.02%) ⬆️
deploy-web 62.34% <ø> (ø)
log-collector 85.85% <ø> (ø)
notifications 91.44% <ø> (ø)
provider-console 81.38% <ø> (ø)
provider-inventory 85.00% <ø> (ø)
provider-proxy 86.42% <ø> (ø)
tx-signer 86.72% <ø> (ø)
see 4 files with indirect coverage changes
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

stalniy and others added 3 commits July 20, 2026 22:21
Extend script/lint-env.mjs with a usage check: every key declared in an
app's committed .env files must be referenced somewhere in the codebase.
A key counts as used when it appears as a word in any tracked file
outside the env directories (source, Docker, CI, deploy manifests) or is
interpolated by another env value ($VAR / ${VAR} / %{VAR}). Keys that are
consumed only by external SDKs/tooling can be exempted via
EXTERNAL_ENV_KEYS.

Remove the dead keys this surfaced (verified unreferenced across the repo;
api has no dynamic process.env access):
- api: AUTH0_ISSUER, WEBSITE_URL (superseded by CORS_WEBSITE_URLS),
  DEPLOYMENT_ALLOWANCE_REFILL_THRESHOLD, HEALTHCHECKS_ENABLED
- deploy-web: NEXT_PUBLIC_AUTH0_LOGIN, NEXT_PUBLIC_AUTO_TOP_UP_ENABLED,
  NEXT_PUBLIC_BILLING_ENABLED, NEXT_PUBLIC_UNLEASH_FRONTEND_API_URL/TOKEN,
  UI_TESTS_TOKEN
- stats-web: NEXT_PUBLIC_UNLEASH_FRONTEND_API_URL/TOKEN

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Follow-up to the unused-key check based on review:

- Restore NEXT_PUBLIC_UNLEASH_FRONTEND_API_URL/TOKEN (deploy-web,
  stats-web) and NEXT_PUBLIC_AUTH0_LOGIN (deploy-web): these are read by
  @unleash/nextjs and @auth0/nextjs-auth0 via process.env convention, so
  they never appear as identifiers in source. They are now exempted through
  EXTERNAL_ENV_KEYS instead of being deleted.
- deploy-web: keep NEXT_PUBLIC_GTM_ID in production and add it as an empty
  value in staging/staging-testnet (rather than dropping it from
  production) so the pair still declares matching keys.
- deploy-web .env.sample: drop the stale UI_TESTS_TOKEN in favour of the
  already-present E2E_TESTING_CLIENT_TOKEN.
- api: remove PORT from the env files; the listen port is provided by the
  Helm chart (PORT=3000) and the schema still supplies a local default.

Still removed as genuinely dead (unreferenced anywhere in the repo):
api AUTH0_ISSUER, WEBSITE_URL, DEPLOYMENT_ALLOWANCE_REFILL_THRESHOLD,
HEALTHCHECKS_ENABLED; deploy-web NEXT_PUBLIC_AUTO_TOP_UP_ENABLED,
NEXT_PUBLIC_BILLING_ENABLED.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PORT is provided by the Helm chart at runtime, so it stays out of the
deployment env files but remains in .env.sample to document the accepted
variable.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@stalniy
stalniy marked this pull request as draft July 21, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use dotenv-linter to ensure that our configs are OK

2 participants