Skip to content

test(isolation): start a spawned rtk from an empty environment - #4471

Closed
KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:fix/isolate-rtk-shell-settings
Closed

KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:fix/isolate-rtk-shell-settings

Conversation

@KuSh

@KuSh KuSh commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

A spawned rtk in the test suite now starts from an empty environment and keeps only the variables KEPT names in src/core/test_isolation/scratch.rs, instead of inheriting everything but a list of removed names.

Removing variables by name let everything else through. The fake tools tests put on PATH are shell scripts, so SHELLOPTS=xtrace exported in a contributor's shell makes silent_command_stays_silent and guard_fallback_emits_exactly_the_command_bytes fail on any host where /bin/sh is bash; BASHOPTS, BASH_ENV, POSIXLY_CORRECT, CDPATH and exported functions change them the same way. #4154 hits this with its new fake tools.

Changes

  • redirect_rtk_data is renamed isolate_rtk, next to isolate_git. It clears the environment and keeps what a child needs to run tools at all: PATH, the loader paths, TMPDIR, the locale and time zone with their data, rustup's toolchain, and on Windows the system variables in WINDOWS_KEPT. rtk's data, git configuration and HOME are pinned into the scratch directory as before; on Windows the profile variables are pinned there too.
  • The other side of a comparison gets the same environment, so a setting only the contributor's shell exports reaches neither side rather than one: common::native_command() for a native grep, rg, head or wc, and isolate_git() for git. With RIPGREP_CONFIG_PATH pointing at --max-columns=150, bulky_rg_yields_token_savings fails if only rtk's side is isolated.
  • Tests drop the env_remove and RTK_TELEMETRY_DISABLED lines the empty environment makes redundant, and the hook protocol test runs its bash hook through common::isolate_rtk instead of a hand-written list.
  • .claude/rules/cli-testing.md describes the new contract.

No change to the rtk binary: everything touched is test code.

Test plan

  • cargo fmt --all, cargo clippy --all-targets, cargo test --all: clean, 4267 tests.
  • The full suite also passes with SHELLOPTS=xtrace exported, with TMPDIR inside a git repository, with RTK_DB_PATH exported (never written to), and in a French locale.
  • tests/isolate_rtk_test.rs runs env (cmd /D /C set on Windows) directly, through rtk proxy, as a native tool and as an isolated git, and checks that nothing this process inherited and isolation dropped reaches the child, and that rtk's data path lies in the scratch directory. Removing env_clear(), bypassing isolation in rtk_command or native_command, reverting isolate_git, or keeping RTK_DB_PATH unpinned each fails it.
  • a_child_keeps_none_of_the_shell_settings fails if SHELLOPTS is added to KEPT; every_variable_rtk_reads_is_redirected_for_a_child fails if a variable rtk reads, such as CODEX_HOME, is.
  • Windows code type-checked against x86_64-pc-windows-gnu; CI runs it.

🤖 Generated with Claude Code

isolate_rtk, renamed from redirect_rtk_data next to isolate_git, clears the
environment and keeps only what KEPT names: PATH, what the loader needs to start
a tool installed outside the system directories, TMPDIR, the locale and the
time zone with the data they load, and what rustup needs to find cargo, plus the
system variables WINDOWS_KEPT names on Windows, where the profile variables are
pinned into the scratch directory alongside HOME.

Removing variables by name let everything else through. A test's fake tools are
shell scripts, so SHELLOPTS=xtrace exported in a contributor's shell made
silent_command_stays_silent fail on any host where /bin/sh is bash; BASHOPTS,
BASH_ENV, POSIXLY_CORRECT, CDPATH and exported functions change them the same
way.

A native tool or git a test compares rtk's output with gets the same
environment, through common::native_command and isolate_git, so a setting only
the contributor's shell exports, such as RIPGREP_CONFIG_PATH or COLUMNS,
reaches neither side. Tests drop the
removals and pins the empty environment makes redundant, and the hook protocol
test isolates the bash hook that runs rtk the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Rewrites the test suite's rtk isolation helper (renamed isolate_rtk) to start spawned rtk processes from a fully empty environment that keeps only an explicit allowlist, rather than removing a blocklist of names from the inherited environment. This prevents shell settings like SHELLOPTS, BASHOPTS, or RIPGREP_CONFIG_PATH from leaking into either side of test comparisons and causing flaky failures on contributors' machines.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@TaKO8Ki TaKO8Ki closed this in #4154 Oct 9, 2026
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Oct 9, 2026
@KuSh
KuSh deleted the fix/isolate-rtk-shell-settings branch October 9, 2026 17:53
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.

1 participant