Skip to content

fix(tests): stop PATH-mirror helpers from deep-copying under Git Bash - #6491

Merged
kyle-sexton merged 4 commits into
mainfrom
fix/test-fs-leaks
Oct 7, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
fix/test-fs-leaks

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Incident

scripts/check-script-contract.test.sh hid a tool by running ln -sf "$entry"/* "$dir"/ for every PATH entry. Under Git Bash, ln -s deep-copies by default (MSYS winsymlinks unset), and the glob matched subdirectories, so each run copied C:\WINDOWS and the WindowsApps PowerShell dirs recursively into %TEMP%\tmp.* (about 35 GB per hidden tool, 4 tools per run). The mirror dir was registered for cleanup only after the loop, so an interrupt left it behind, and 2>/dev/null || true hid disk-full. Agent worktrees ran the suite repeatedly and filled C:.

Fixes

  • check-script-contract.test.sh hidden_path: PATH entries without the tool pass through unchanged. Each entry that holds the tool is replaced in place by a dir of symlinks to its regular files minus the tool, made with MSYS=winsymlinks:nativestrict so a link fails instead of becoming a copy. One labeled root (hidden-path.XXXXXX) is created and registered before any mirror is filled, and the EXIT trap removes it.
  • check-detector-eval-coverage.test.sh, testing/test-judge-bg.test.sh, work-item-tracker.test.sh: these linked every file of every PATH entry into one dir (test-judge-bg and work-item-tracker also matched subdirectories). They now use the same filtered-PATH shape. This also removes thousands of process spawns per run on Windows.
  • actionlint, bash-format, biome-format, markdown-format, powershell-format, ruff-format, typos-format probes; guardrails run-guards and block-hook-bypass; code-metrics tool-free-path.sh: force native symlinks on the existing ln -s so a link never turns into a copy of /usr/bin or a PATH dir.
  • Temp dirs that were never removed:
    • lib/mermaid-gate.test.mjs: after(rmSync).
    • course-digest cli-entry.test.js and cli-browser-artifacts.test.js: tracked tempDirs plus afterEach(rmSync). cli-entry also unlinks its junction into the source extraction/ dir before cleanup.
    • test_compare_reports.py and speech test_assets.py: addCleanup(shutil.rmtree, ...).
    • index-drift.test.sh: EXIT trap.
    • lib/exec-bash.gates.test.mjs: exit hook, so a failed assert no longer leaks its dir.
  • test_kill_switch_probe.py: the copytree ignore list now covers .venv, node_modules, .*_cache and .work.

Verification

Run on Windows Git Bash with TMPDIR on D:, because C: is full:

  • check-script-contract.test.sh: every environment-dimension row passes. The 3 remaining FAILs are in fixture recipes this PR does not touch: htmlhint is not installed (no npm ci) and the exec-form-windows-probe fixture lacks lib/exec-bash.mjs.
  • check-detector-eval-coverage: 172/0. run-guards: 652/0. work-item-tracker: pass.
  • mermaid-gate, exec-bash.gates, the three Python suites and index-drift ran with the same results as on main.
  • The course-digest vitest suites pass 27/27 on Linux (WSL). On Windows they fail on main and on this branch alike, because of a URL.pathname drive-letter issue.
  • No new tmp.* or cli-* dirs were left in the temp dir after the runs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BNvS11TdNcvQcurygMK7sW

Git Bash's default `ln -s` deep-copies its target, so test helpers that
hide a tool by mirroring PATH copied whole system directories (C:\WINDOWS,
WindowsApps) into %TEMP% and filled the C: drive.

- check-script-contract.test.sh hidden_path: keep PATH entries that lack
  the tool, mirror only regular files of the entries that hold it, force
  native symlinks, and register a labeled root before filling it.
- check-detector-eval-coverage, test-judge-bg, work-item-tracker: same
  filtered-PATH shape instead of linking every file on PATH.
- Format-hook probes, run-guards, block-hook-bypass, tool-free-path: force
  native symlinks so a link never becomes a copy.
- Remove temp dirs that were never cleaned: mermaid-gate, course-digest
  cli-entry (unlink its junction first) and cli-browser-artifacts,
  test_compare_reports, test_assets, index-drift (EXIT trap),
  exec-bash.gates (exit hook); bound test_kill_switch_probe's copytree.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BNvS11TdNcvQcurygMK7sW
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

PR body contract — issue linkage

This PR body does not yet satisfy the issue-linkage contract:

  • Missing a "## Summary" section. Describe what this PR changes and why, in a sentence or two.
  • Missing a "## Fix" section. State the concrete change and how it addresses the problem.
  • Missing a "## Related" section. List related PRs, ADRs, or decision-log entries this PR does not close.
  • Missing a native closing keyword (Closes/Fixes/Resolves #N). If this PR references an issue it must not close, put "Refs: #N" (or "Relates to: #N") on its own line. If it relates to no GitHub issue at all, state "No linked issue" (or "No related issue:") in the body instead.

Edit the body and this comment updates itself on the next run.

@kyle-sexton
kyle-sexton marked this pull request as ready for review October 7, 2026 12:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 7, 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-07T13:09:30.129931Z 00a1d81 Draft marked ready
ℹ️ 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.

@claude

claude Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 11s —— View job


Code review (/review:code-review)

Reviewed all 22 changed files (git diff origin/main...HEAD against head 00a1d81) against the code-review lane's correctness/maintainability criteria.

Summary: This is a well-scoped bug fix. The core change — hidden_path() in scripts/check-script-contract.test.sh — correctly addresses both bugs described in the incident:

  • It now filters on -f (regular file) before linking, so the glob no longer walks into subdirectories (the actual cause of the recursive C:\WINDOWS copy).
  • It forces MSYS=winsymlinks:nativestrict so ln -s fails loudly instead of deep-copying under Git Bash.
  • It replaces only the PATH entries that actually contain the hidden tool (keeping the rest untouched), which also fixes the precedence bug in the original backward-iteration ln -sf loop — a single merged mirror directory could never represent "entry A overrides entry B" correctly once more than one entry provided the same name.
  • The mirror root is created lazily under a single HIDDEN_ROOT, and cleanup_hidden_paths (installed via trap ... EXIT once, at file scope) removes it unconditionally; a no-op mktemp/mkdir/ln failure path returns 2 so callers detect it rather than silently continuing with the original noisy fallback.

The same filtered-PATH shape is applied consistently across check-detector-eval-coverage.test.sh, test-judge-bg.test.sh, and work-item-tracker.test.sh, and each of those nests its mirror directories under a mktemp/TEST_TMPDIR root that already has its own trap ... EXIT rm -rf, so no new leak is introduced. The one-line ln -s → MSYS=winsymlinks:nativestrict ln -s swaps in the format/lint-hook probes and tool-free-path.sh are low-risk and consistent with the same fix. The course-digest vitest temp-dir tracking (including unlinking the junction in cli-entry.test.js before the recursive afterEach cleanup, so the cleanup can't follow the junction back into the source extraction/ dir) and the Python addCleanup(shutil.rmtree, ...) additions are correct and match the stated intent.

I did not find a correctness issue a careful reviewer would block on. Minor, sub-threshold observations (not blocking, no inline comments posted since none meet the high-signal bar for this lane):

  • A few of the rewritten loops (e.g. test-judge-bg.test.sh#L177-L179) dropped the old -x executable filter in favor of -f only; this is harmless (symlinks to non-executable targets still don't resolve via command -v) but is a slight widening of what gets mirrored.
  • plugins/speech/scripts/test_assets.py adds import shutil after import sys, breaking alphabetical import order — cosmetic, and something an isort/ruff import-sort rule would catch if enabled.

Security scope note: no security lane findings identified; this repo runs a separate /review:security-review lane and none of these changes touch trust boundaries.

Verification: The PR body's Windows Git Bash test runs (check-script-contract environment-dimension rows, check-detector-eval-coverage 172/0, run-guards 652/0, work-item-tracker, mermaid-gate, exec-bash.gates, the Python suites, index-drift) are author-claimed and not independently re-run by me in this CI sandbox.

@claude

claude Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 21s —— View job


Security review

  • Gather context (PR diff, changed files)
  • Review for security-relevant issues (logic flaws, injection, trust boundaries, instruction-surface deletions)
  • Post findings

No security issues found.

This PR is entirely test-infrastructure plumbing: it changes how 22 test scripts build a "PATH without tool X" fixture (replacing a deep-copying ln -s with native symlinks via MSYS=winsymlinks:nativestrict, filtering to regular files only) and fixes several test temp-directory leaks (missing rmSync/shutil.rmtree/EXIT traps). None of the changed files are production hooks or shipped scripts — they are all *.test.sh / *.test.{js,mjs} / test_*.py files that construct symlink mirrors of the local PATH inside mktemp-created directories for use within the test run itself.

Reviewed for:

  • Injection/trust-boundary issues: the hidden_path/path_without/NOGH_BIN/NOTO helpers operate only on the local $PATH and hardcoded tool names (jq, gh, shfmt, timeout, etc.) passed by the test author — no untrusted input flows into these paths.
  • Symlink/race-condition risk: all mirror directories are created with mktemp -d, and the switch to MSYS=winsymlinks:nativestrict tightens behavior (a failed native-link attempt now errors instead of silently falling back to a deep copy of system directories like C:\WINDOWS, which was the actual incident this PR fixes).
  • Instruction-surface deletions: no CLAUDE.md/AGENTS.md/rules files/hook allow/block lists were touched. The guardrails files changed (block-hook-bypass.test.sh, run-guards.test.sh) are the tests for those hooks, not the hooks' own logic, and the diff there is the same native-symlink one-liner as the other format-hook test probes — no guard logic was weakened.
  • Cleanup fixes (mermaid-gate.test.mjs, exec-bash.gates.test.mjs, cli-entry.test.js, cli-browser-artifacts.test.js, test_compare_reports.py, test_assets.py, index-drift.test.sh, test_kill_switch_probe.py): these add/move cleanup (afterEach/after/addCleanup/EXIT trap) and, in cli-entry.test.js, explicitly unlinkSync the junction link before the recursive rmSync so a cleanup pass can't follow the junction into the source extraction/ directory — a good defensive detail, not a gap.

Scope note: per this lane's brief, GitHub Actions workflow hardening (triggers, permissions:, pinning) is zizmor's lane and out of scope here; none of the changed files are workflow files in any case.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review has reviewed this pull request through 489218d; a later push is reviewed from there.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

claude-review has reviewed this pull request through 489218d; a later push is reviewed from there.

kyle-sexton and others added 2 commits October 7, 2026 09:04
Patch-bump the eleven per-PR-versioned plugins whose test files changed,
add none fragments for the five fragment-mode plugins, and build the
no-timeout PATH mirrors in test-judge-bg under the suite's own trapped
$TMP without mktemp, which the test-tmp-cleanup gate reads lexically.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BNvS11TdNcvQcurygMK7sW
@kyle-sexton

Copy link
Copy Markdown
Member Author

Re the code-review lane's two sub-threshold notes:

Finding Classification Evidence / action
-x filter dropped for -f in the PATH mirrors INCORRECT (not a defect) -f is deliberate: it excludes subdirectories, the cause of the deep copy. Non-executable targets stay unresolvable by command -v, as the lane notes. No change.
import shutil out of order in plugins/speech/scripts/test_assets.py VALID (fix now) Sorted in 489218d.

Also pushed eeffeab: patch bumps and changelog entries for the 11 per-PR-versioned plugins, none fragments for the 5 fragment-mode plugins, and test-judge-bg's mirror dirs made without mktemp under the suite's trapped $TMP (check-test-tmp-cleanup gate).

@claude

claude Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 28s —— View job


Security review (/review:security-review) — incremental

  • Gather context: read .claude-lane/incremental.diff (changes since 00a1d81) and the listed files
  • Review the incremental diff for security-relevant issues
  • Post findings

Scope: incremental re-review for commit 489218d. Only the files changed since 00a1d81 (per the lane's diff) were reviewed; every other file in this PR was already reviewed at that commit.

What changed in this increment:

  • Plugin version bumps + CHANGELOG entries (actionlint, bash-format, biome-format, code-metrics, knowledge, markdown-format, powershell-format, ruff-format, speech, typos-format, work-items) and new .changes/*.md fragments — metadata only.
  • plugins/speech/scripts/test_assets.py: reordered import shutil above import sys — cosmetic, no behavior change.
  • plugins/testing/hooks/test-judge-bg.test.sh#L169-L183: the mktemp -d "$TMP/no-timeout-bin.XXXXXX" call was replaced with a counter-based mkdir "$TMP/no-timeout-bin.$((n++))".

No security issues found.

Looked specifically at whether the move from mktemp -d to a predictable, counter-named directory under $TMP opens a symlink-preplant race (an attacker pre-creating $TMP/no-timeout-bin.0 as a symlink before this script's mkdir runs, so the later ln -s "$x" "$m/$b" writes through it into an attacker-controlled location). This isn't exploitable here: $TMP itself is a single-use mktemp -d directory created fresh per test run (private to the invoking user, not guessable in advance), so nothing outside this process can pre-plant an entry at a path under it before the directory exists. mkdir also fails closed on a pre-existing path rather than following a symlink, so even within the same principal there's no silent redirection. No trust boundary, input handling, or credential path is touched by this increment.

The rest of the increment (version/changelog metadata, one import reorder) has no security surface.

No instruction-surface deletions in this increment (no CLAUDE.md/AGENTS.md/rules/hook allow-or-block-list changes).

@claude

claude Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 34s —— View job


Code review (/review:code-review) — incremental

  • Gather context (incremental diff since 00a1d81, PR body, prior review state)
  • Review changed files since 00a1d81 (scoped to the file list in the lane instructions)
  • Post findings
  • Final update

Summary: Reviewed the incremental diff in .claude-lane/incremental.diff (28 files) against the previous review point 00a1d81. No correctness issues found; no inline comments posted.

  • Version bumps + changelogs (actionlint, bash-format, biome-format, code-metrics, knowledge, markdown-format, powershell-format, ruff-format, speech, typos-format, work-items): mechanical patch bumps with matching CHANGELOG.md entries, consistent with the test-only fixes already reviewed at 00a1d81.
  • Changelog fragments (.changes/{disk-hygiene,guardrails,harness-ops,instruction-placement,testing}/fix-test-fs-leaks-*.md, bump: none): correct — all five are listed in scripts/fragment-plugins.txt (ADR 0048 fragment-mode plugins), so they get a fragment instead of a version bump.
  • plugins/speech/scripts/test_assets.py: reorders import shutil before import sys, fixing the alphabetical-order nit the prior review round flagged as cosmetic. Correct, no behavior change.
  • plugins/testing/hooks/test-judge-bg.test.sh#L169-L180: replaces mktemp -d "$TMP/no-timeout-bin.XXXXXX" with a counter-based m="$TMP/no-timeout-bin.$((n++))"; mkdir "$m". Verified this is safe: n is scoped to this block only (no collision elsewhere in the file), each generated name is unique since n increments on every directory created, and the directories are still removed by the enclosing $TMP EXIT trap in judge-test-helpers.sh (no new leak). This avoids spawning an external mktemp process per hidden PATH entry, consistent with the PR's stated goal of cutting process spawns on Windows.
    • Permalink:
      NOTO="" n=0
      IFS=: read -ra dirs <<<"$PATH"
      for d in "${dirs[@]}"; do
      if [[ ! -e "$d/timeout" && ! -e "$d/timeout.exe" && ! -e "$d/gtimeout" ]]; then
      NOTO+="${NOTO:+:}$d"
      continue
      fi
      m="$TMP/no-timeout-bin.$((n++))"
      mkdir "$m"
      for x in "$d"/*; do
      b="${x##*/}"
      [[ -f "$x" && "$b" != timeout && "$b" != timeout.exe && "$b" != gtimeout ]] && MSYS=winsymlinks:nativestrict ln -s "$x" "$m/$b"

Verification: Static review only; did not re-run the test suites (author-claimed results in the PR body were already noted as not independently re-run in the prior review round, and nothing in this incremental diff changes that).

@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 7, 2026
Merged via the queue into main with commit 498148c Oct 7, 2026
26 checks passed
@kyle-sexton
kyle-sexton deleted the fix/test-fs-leaks branch October 7, 2026 13:22
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.

1 participant