Skip to content

test(api): fail when api startup or bootstrap configuration read process.env - #3116

Merged
freeqaz merged 3 commits into
mainfrom
test/api-startup-env-guard
Oct 21, 2026
Merged

freeqaz merged 3 commits into
mainfrom
test/api-startup-env-guard

Conversation

@freeqaz

@freeqaz freeqaz commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Problem

#3111 moved API startup into apps/controller/src/api-startup.mjs (startApi(env)). It also moved the initialization Job's settings into scripts/lib/bootstrap-configuration.mjs. Both take their environment as a parameter, so sign-in-chart-parity.test.mjs can run them in process with its own environment. Open PRs that edit server.mjs (#3048, #2980, #2518 and #1619) have to move those edits into api-startup.mjs. If a ported edit reads process.env (for example a new OCC_CONSOLE_THEME_DIR read), the in-process tests check the test runner's environment instead of the one they pass, and nothing fails.

Change

Add tests/conformance/startup-environment-boundary.test.mjs and map it to checks-baseline-2, next to the other source-boundary checks. The test parses both files with the same parser as scripts/verify-repository-credentials-boundary.mjs and fails on any of these:

  • process.env in member, computed or optional form
  • process used as a value, such as a destructuring or alias
  • process reached through globalThis or global
  • a static or dynamic import or re-export of node:process

process.exitCode, process.once, and properties that are only named process are still allowed. Comments that mention process.env are ignored.

For each file, the test also appends every forbidden form to the real source and checks that each one is caught. It also checks that the allowed forms pass.

Verification

  • node --test tests/conformance/startup-environment-boundary.test.mjs passes in about 0.1 s.
  • Mutants on the real files all fail the test:
    • configuration(process.env) in startApi
    • a process.env.OCC_CONSOLE_THEME_DIR spread into the settings
    • an env[name] ?? process.env[name] fallback in bootstrap-configuration.mjs
  • On a remote test VM, the checks-baseline-2 and static lanes (no cache) passed on c826dfd.
  • run-tests.mjs audit passes. eslint and prettier are clean.

Risks

Test-only. Its scope is limited to these two files. Their dependencies still read a few process-wide settings from process.env (such as OCC_DATABASE_AUTH), as #3111 documents.

…ess.env

#3111 moved API startup into api-startup.mjs and the Job's settings into
scripts/lib/bootstrap-configuration.mjs, both taking their environment as a
parameter so the sign-in parity tests can run them in process. Open PRs that
edit server.mjs must port their edits there, and a ported process.env read
would make those in-process tests check the runner's environment instead.

Add a conformance test that parses both files and fails on process.env
(member, computed, destructured or via globalThis) or an import from
node:process, with appended-read cases proving each form is caught. It runs
in checks-baseline-2 beside the other source-boundary checks.
Review follow-up: the member rule flagged any property named process (such
as options.process) yet missed `const { process } = globalThis`. Treat
globalThis/global like process itself, catch import()/re-exports of
node:process, and pin that a plain property named process stays allowed.
@freeqaz
freeqaz requested a review from a team as a code owner October 21, 2026 08:22
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds a source-boundary test that rejects ambient process-environment access in API startup and bootstrap configuration, and registers it in CI.

Example: A future startup edit reads process.env.OCC_CONSOLE_THEME_DIR instead of the supplied env parameter.

  • Before: The edit can bypass the environment supplied by the in-process parity tests.
  • After: The new conformance test rejects the ambient environment read.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, useful architecture coverage with passing selected-lane evidence; validation is static and the separate required-check failure remains unclassified.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored, test-only change adds no shipped runtime behavior; its selected CI lane passed, and the inspected screenshots show unrelated console theming rather than this guard.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: Future startup changes could undermine configuration parity checks by reading the test runner's environment.
Reason: The maintainer-authored direction protects the established parameterized startup design without adding runtime machinery or configuration.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it adds a useful, focused guard for an existing startup contract, with no concrete introduced defect found; the failing required CI check still needs classification.

Priority: P3
Reviewed head: c826dfd12530d895269a8c11a0f2d495ad2a1ca4

Before merge

None.

Findings

None.

Agent review details

How this fits together

Production entrypoints pass process.env into parameterized startup functions, while parity tests pass isolated environment objects; the new guard parses those function owners and reports forbidden ambient access.

flowchart LR
  A[Startup source files] --> B[Existing TypeScript parser]
  B --> C[Environment boundary assertions]
  C --> D[Checks and Conformance 2]
  D --> E[CI result]
Loading

Technical review

Best possible solution:

Retain the focused source guard alongside the existing runtime parity coverage.

Do we have a high-confidence way to reproduce the issue?

This is preventive coverage, not a report of a current runtime defect; source inspection verifies the explicit-environment contract and the guard's intended regression inputs.

Is this the best way to solve the issue?

The AST-based check is proportional to the existing contract, reuses an established parser, and leaves real startup behavior covered by the existing parity tests.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c9cfa7a84dde.

Provenance checked

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Free Wortley: Raw commit 4655a74 adds apps/controller/src/api-startup.mjs:325 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4655a74559ea; files: apps/controller/src/api-startup.mjs)

Review metrics

Metric Value Why it matters
Change scope Production +0; test +110; CI manifest +4 The growth is limited to enforcing an existing source contract and scheduling its check.

Labels

Label changes:

  • add P3: Preventive test coverage with no current user-facing runtime failure established.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: Preventive test coverage with no current user-facing runtime failure established.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 21, 2026, 4:39 AM ET / 08:39 UTC.

@freeqaz
freeqaz merged commit 2b992e4 into main Oct 21, 2026
42 checks passed
@freeqaz
freeqaz deleted the test/api-startup-env-guard branch October 21, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant