Skip to content

[APPS-2945] Add: warn on process.env reads in backend functions - #565

Open
tyffical wants to merge 1 commit into
tiffany.trinh/apps-2945-follow-terrapin-flagfrom
tiffany.trinh/apps-2945-warn-env-reads-v2
Open

tyffical wants to merge 1 commit into
tiffany.trinh/apps-2945-follow-terrapin-flagfrom
tiffany.trinh/apps-2945-warn-env-reads-v2

Conversation

@tyffical

@tyffical tyffical commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Architecture

flowchart TD
    T[".backend.* transform"] --> R["runBackendStaticChecks (app-local modules only)"]
    L["local run (module-graph walk)"] --> R
    V["vite build (nested backend build)"] --> R
    R --> M["rejectGlobalsMissingFromNode"]
    R --> W["warnAboutEnvReads"]
    W -->|"process.env.X, a destructure, an env import, a const alias"| K["warn: process.env.X"]
    W -->|"process.env[key], a rest destructure"| A["warn: process.env"]
    W -->|"writes, deletes, indirect forms"| N["no warning"]
Loading
  • The check warns once per file and use, and never fails a build.

Changes

5 changes across warn-env-reads.ts, ambient-global-access.ts, run-backend-static-checks.ts, README.md and tests
What changed File
Add warnAboutEnvReads, which warns on direct process.env reads, naming static keys. warn-env-reads.ts
Export the static-name helpers it reuses. ambient-global-access.ts
Run the warning after the missing-global check. run-backend-static-checks.ts
Document the forms it catches and the modules it skips. README.md
Test must-warn and must-not-warn forms, dedup and module skips. warn-env-reads.test.ts, dev-server-module-graph.test.ts

QA Instructions

yarn typecheck:all && yarn lint && yarn cli integrity
# Expected: all exit 0, integrity leaves no file changes ✅ VERIFIED
yarn build:all && yarn test:unit packages/plugins/apps
# Expected: Test Suites: 42 total; Tests: 1071 total, all passed except 15 manifest-tags and parameters tests, which fail on macOS's /var TMPDIR ✅ VERIFIED
Fixtures and staging runs
  • src/useEnv.backend.ts:
export async function readStripeKey() { return process.env.STRIPE_KEY ?? null; }
  • src/useRestEnv.backend.ts:
export async function readRest() {
    const { env, ...rest } = process;
    return { region: env.REGION ?? null, restKey: rest.env?.STRIPE_KEY ?? null };
}
cd "$QA_DIR" && QA_APP=<vite 8 scaffold> ./install-plugin.sh 565 <build-plugins checkout of this branch>
QA_APP=<vite 8 scaffold> ./qa-run.sh development useEnv useRestEnv useFetch
# Output: one warning each, "useEnv.backend.ts uses process.env.STRIPE_KEY" and "useRestEnv.backend.ts uses process.env.REGION"; none for useFetch ✅ VERIFIED
# Expected with DD_API_KEY and DD_APP_KEY set: 3 "in a child process" lines; readStripeKey null, readRest {"region":null,"restKey":null}
for app in <vite 8 scaffold> <vite 5 app>; do for m in development dev-verify; do
  QA_APP=$app env STRIPE_KEY=qa-local-value ./qa-run.sh $m useEnv | grep -E "readStripeKey|uses process.env"
done; done
# Expected: Vite 5 development returns "qa-local-value"; Vite 8 development and both dev-verify runs return null; all four warn

Blast Radius

  • Apps whose backend modules read process.env directly (NODE_ENV included) get new warn-level log lines in builds and the dev server.
  • Warning only: builds never fail.
  • No feature flag.
  • Low risk.

Out of Scope / Follow-ups

1 item deferred
Item Status Next step
Indirect forms don't warn: parameters and defaults, let/var or second-level aliases, nested env destructures, namespace, default as and dynamic imports, re-exports, literal wrappers, .then callbacks, Object.assign/Reflect, globalThis.process, for-of bindings, spreads, Object.keys, in. NODE_ENV and keys the file assigns itself still warn; warnings show once per file per dev-server process Accepted None; exempt NODE_ENV if the runtime sets it

Documentation

🤖 Generated with Claude Code

@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch 2 times, most recently from 481364f to e574841 Compare October 8, 2026 03:44
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 1139d7b to 1c99e18 Compare October 8, 2026 04:29
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from e574841 to 34a9189 Compare October 13, 2026 00:52
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 1c99e18 to f47f7f2 Compare October 13, 2026 01:33
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from 34a9189 to abf34ad Compare October 13, 2026 20:08
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch 3 times, most recently from cd6a25a to cf3c8c3 Compare October 14, 2026 22:40
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from abf34ad to 892bda9 Compare October 15, 2026 01:04
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from cf3c8c3 to 47069c8 Compare October 15, 2026 02:18
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch 2 times, most recently from bd21790 to 2352fe9 Compare October 15, 2026 15:37
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 47069c8 to 7c4b7c7 Compare October 15, 2026 17:08
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch 2 times, most recently from e7d5434 to 1fa97d9 Compare October 15, 2026 22:20
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 7c4b7c7 to 2f3af66 Compare October 15, 2026 23:51
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch 2 times, most recently from e44fe4a to 141d960 Compare October 16, 2026 00:47
@tyffical
tyffical marked this pull request as ready for review October 16, 2026 01:26
@tyffical
tyffical requested a review from a team as a code owner October 16, 2026 01:26
@tyffical
tyffical requested review from Chau-DDOG and removed request for a team October 16, 2026 01:26
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 2f3af66 to 10e3990 Compare October 16, 2026 02:55
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from 141d960 to 04671dd Compare October 16, 2026 04:18
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 10e3990 to 6941e61 Compare October 16, 2026 04:45
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from 04671dd to 696d422 Compare October 16, 2026 16:37
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 6941e61 to 7c83f70 Compare October 16, 2026 16:37
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from a64a6ad to 31ea49f Compare October 18, 2026 05:41
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 94528a9 to 4f06e53 Compare October 18, 2026 05:41
@tyffical tyffical changed the title [APPS-2945] Add: warn on process.env reads under the v2 runtime [APPS-2945] Add: warn on process.env reads in backend functions Oct 18, 2026
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from 31ea49f to ea71187 Compare October 20, 2026 19:49
@tyffical
tyffical requested a review from a team as a code owner October 20, 2026 19:49
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 4f06e53 to 6d4a47e Compare October 20, 2026 22:40
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from ea71187 to e59b683 Compare October 20, 2026 23:58
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 6d4a47e to 79afef1 Compare October 20, 2026 23:59
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from e59b683 to c499254 Compare October 22, 2026 16:46
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 79afef1 to c721652 Compare October 22, 2026 16:47
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from c499254 to 06018e9 Compare October 23, 2026 07:29
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from c721652 to d867e12 Compare October 23, 2026 07:33
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9e703c8 | Docs | View more details | Give us feedback!

@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch 2 times, most recently from 7509268 to eb7a6fb Compare October 23, 2026 13:41
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from d867e12 to 102e6e7 Compare October 23, 2026 13:45
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from eb7a6fb to 92afaf2 Compare October 23, 2026 14:30
@tyffical
tyffical requested a review from ksun154 October 23, 2026 14:57
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from 102e6e7 to cd32453 Compare October 23, 2026 15:56
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-follow-terrapin-flag branch from 92afaf2 to b71e121 Compare October 23, 2026 16:19
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from cd32453 to a779bfd Compare October 23, 2026 16:23
@tyffical
tyffical requested a balanced review from Copilot October 23, 2026 16:44
@tyffical

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T16:49:04.250227Z a779bfd Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Optional-chain deletes incorrectly emit environment-read warnings instead of being excluded like plain deletes.

1 open issue
What changed in this PR

Adds warning-only checks for backend process.env reads, extending the apps plugin’s Node runtime checks to flag values unavailable in production.

Changes:

  • Detects direct reads, destructuring, supported imports, and first-level const aliases, with per-file warning deduplication.
  • Integrates warnings into shared backend static checks.
  • Documents supported forms and adds unit and module-graph coverage.
File Description
packages/​plugins/​apps/​src/​vite/​dev-server-module-graph.test.ts Tests local-run warnings, deduplication, and dependency skips.
packages/​plugins/​apps/​src/​backend/​ast-parsing/​warn-env-reads.ts Implements environment-read detection and warning reporting.
packages/​plugins/​apps/​src/​backend/​ast-parsing/​warn-env-reads.test.ts Tests detection, exclusions, deduplication, and failure handling.
packages/​plugins/​apps/​src/​backend/​ast-parsing/​run-backend-static-checks.ts Invokes the new warning check.
packages/​plugins/​apps/​src/​backend/​ast-parsing/​run-backend-static-checks.test.ts Tests shared-check warning integration.
packages/​plugins/​apps/​src/​backend/​ast-parsing/​ambient-global-access.ts Exports helpers reused by the detector.
packages/​plugins/​apps/​README.md Documents warnings, supported forms, and module exclusions.

Review effort: Balanced

},
UnaryExpression(node) {
if (node.operator === 'delete') {
writtenMembers.add(node.argument);
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: a779bfd271

ℹ️ 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".

The Node backend runtime doesn't pass the developer's environment
variables or Custom Credentials to backend functions, so a
process.env.X read finds nothing in production, and nothing flagged it
before upload.

The static checks now warn, never fail, on direct process.env reads in
app-local backend modules, once per file and use, naming the variable
when the key is static: process.env.X and process.env[key],
destructures of process.env, env or default process imports from
process or node:process, and a const bound to process.env or to an env
destructured from process. Writes, including destructuring and
for...in/of targets, and deletes don't warn. Modules a backend file
imports from node_modules or from outside the Vite root are skipped,
so an SDK's own env reads don't warn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tyffical
tyffical force-pushed the tiffany.trinh/apps-2945-warn-env-reads-v2 branch from a779bfd to 9e703c8 Compare October 23, 2026 21:34
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.

2 participants