Skip to content

fix(setup): preserve overridden runner variables and test isolation on Windows - #3639

Closed
Swatantra-66 wants to merge 0 commit into
morluto:mainfrom
Swatantra-66:fix/windows-runner-env-isolation
Closed

Swatantra-66 wants to merge 0 commit into
morluto:mainfrom
Swatantra-66:fix/windows-runner-env-isolation

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Fixes package runner identity resolution when ambient uppercase environment variables exist on Windows, isolates USERPROFILE in CLI setup tests, and hardens PTY JSON extraction against Windows ConPTY escape sequences.

Fixes #3635

Problem and expected behavior

  1. When callers construct child environments like { ...process.env, npm_command: "exec" } on Windows, npm's ambient NPM_COMMAND="run" precedes the lowercase entry in Object.keys(). environmentValue picked the first match, ignoring the override.
  2. In tests/boundary/cli/cliSetup.test.ts, runJourney only set HOME: isolatedHome, leaving USERPROFILE pointed at the host home directory.
  3. Windows ConPTY emits terminal restore sequences (\x1b[?25h) trailing stdout lines, breaking .split(/\r?\n/u, 1)[0] JSON parsing.

Change and scope

  • In src/application/ClientRegistrationIdentity.ts, updated environmentValue on Windows to use findLast() with case-normalized target comparison (candidate.toLowerCase() === target).
  • In src/setupEnvironment.test.ts, added unit regression coverage for Windows ambient case collisions.
  • In tests/boundary/cli/cliSetup.test.ts, set USERPROFILE: isolatedHome, bounded JSON parsing between { and }, sequenced multiselect prompt steps deterministically, and filtered ambient runner variables case-insensitively.

Contract and boundary impact

  • Semantic owner and earliest changed stage: src/application/ClientRegistrationIdentity.ts (invokingPackageRunner)

  • Contribution scope fit and linked maintainer decision: not applicable (bug fix within existing contracts)

  • CLI and MCP/tool-catalog contract: none

  • Provider, bridge, target-format, or platform compatibility: Windows win32

  • Evidence, artifact, provenance, or reconstruction contract: none

  • Target selection, authority, upstream behavior, and cleanup details: none

  • Generated metadata: none

  • Read existing files or captured data.

  • Launch or attach to a process.

  • Inject instrumentation or run scripts/code.

  • Change process memory, registers, files, or configuration.

  • Contact network services.

  • Recover protected code or work around protections.

  • Documentation or usability only; no target interaction.

  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:

    • src/setupEnvironment.test.ts ("prioritizes overridden package runner environment variables over ambient keys with differing case on Windows")
    • tests/boundary/cli/cliSetup.test.ts (14 tests passed on Windows ConPTY)
  • Base reproduction or other evidence: On Windows, invokingPackageRunner({ NPM_COMMAND: "run", npm_command: "exec", NPM_CONFIG_USER_AGENT: "npm/..." }, "win32") returned undefined.

  • Remaining proof gaps: none for Windows environment variable resolution and ConPTY journey parsing.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/setupEnvironment.test.ts — 7 tests passed
  • npm run test:focused -- tests/boundary/cli/cliSetup.test.ts — 14 tests passed
  • npm run check:fast — passed (turbo typecheck and lint)
  • npm run docs:check — passed (documentation and product catalog consistency)

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: Windows 11 x64 verified
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: Ensures test processes do not leak into host USERPROFILE.

Author readiness

Human owner: @Swatantra-66

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous Windows override issue is fixed.

Summary

The PR preserves caller overrides when Windows environment keys differ only in case.

  • Windows setup uses the latest value for case-matched runner variables.
  • Windows setup tests keep child homes and runner variables isolated.
  • The setup journey reads its decision when ConPTY adds trailing terminal codes.

Reviews (2) · Last reviewed commit: "fix(process): preserve Windows environme..." · Reviewed by Greptile

@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @Swatantra-66 for investigating Windows runner-variable overrides and ConPTY output in the setup tests. Main includes the setup and test-isolation corrections, with the environment normalization refined in a follow-up.

@morluto morluto added area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Windows package runner identity shadowed by ambient variables & ConPTY test failures

2 participants