Skip to content

test(regression): #812 pin suite TMPDIR under a space-free scratch anchor - #864

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/812
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/812

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #812 (residual face; the ${THIS_SH} half landed in #820).

What was still live on master

#820 pinned ${THIS_SH} to a space-free engine copy, but the errors-family snapshot machine dependence had a second machine-absolute input the CI lane could never see: the runner forwards ambient TEMP/TMP (the machine-infrastructure whitelist), the engine self-injects a Windows TMPDIR default from that process temp dir (executor/init.rs, the /tmp mapping fixture), and the upstream assets expand /c/Users/cmx/AppData/Local/Temp UNQUOTED for real faces in three slices:

slice face
heredoc.tests:115-124 cat > ${TMPDIR}/bash-zzz-$$ << EOF heredoc round-trip (abc/def ghi/jkl mno)
quote.tests:136-141 printf 'echo escape\' > $TMPDIR/quote-$$ re-sourced through ${THIS_SH} $TMPDIR/quote-$$
redir.tests:35-119 the $TMPDIR file battery, incl. > $TMPDIR/null-redir-a + testf's oops -- $1 not found branch

Under a spaced ambient TEMP every one of those paths word-splits: the faces go silent or fall to the oops branch. Verified on master HEAD (45f537e) with TEMP='D:\temp-812\rub temp':

  • heredoc 1483 -> 1463 bytes (three lines vanish, absent not misspelled — no normalizer can repair that);
  • quote drops the escape\ line;
  • redir prints oops -- /d/temp-812/rub not found (the spaced path, split);

while a space-free TEMP stays green — CI (windows-latest systemprofile TEMP) can never reproduce it. Same degenerate shape as the THIS_SH face, one layer over: a space in a machine-absolute path met by unquoted upstream expansion.

Fix — the #820/true-baseline contractual move

Same direction as the THIS_SH pin and as the GNU side's own contract (TMPDIR="$w/tmp" in scripts/true-baseline.sh):

  1. space_free_temp_root() anchors the per-suite scratch at a space-free root — ambient temp when it is space-free, else %SystemRoot%\Temp, neither -> loud panic. HOME, the .thissh pin and TMPDIR then share one machine-independent shape on every host.
  2. The lane exports TMPDIR=<scratch>/tmp to the suite child, created eagerly (the assets redirect into $TMPDIR with no mkdir).

No re-record. $TMPDIR's value never prints on a success face in any of the 13 slices (file targets and PATH=$TMPDIR assignments only), so bytes on a space-free host are unchanged; a spaced-TEMP host converges onto the committed bytes. Being under the scratch, even a hypothetical leak renders as the normalized <T> shape. Bonus: the spaced-host junk side effect is gone — errors10.sub's unquoted mkdir $TDIR used to create a word-split directory outside the scratch and rm -rf it afterwards.

No GNU source touched; runner-side determinism only, normalizer untouched.

Verification

  • Pre-fix divergence reproduced (master HEAD, spaced TEMP): 3/13 slices diverge from committed bytes, byte diffs captured (heredoc 1483->1463; quote escape\; redir oops lines); space-free host green 13/13.
  • Post-fix: spaced TEMP green 13/13 byte-identical to committed snapshots; space-free host green 13/13 with snapshots byte-identical (no re-record); no scratch leftovers in either anchor; no junk dirs.
  • Full lane: cargo test --test regression -- --test-threads=1 -> 76 passed / 0 failed.
  • fmt: cargo fmt --check clean repo-wide. Warnings: cargo check --tests — zero warnings touch tests/regression.rs (pre-existing warnings elsewhere untouched).
  • CI leg: this branch's windows regression job records with the same code; the recorded-snapshots artifact should be byte-identical to the committed files (same check as test(infra): #767 single helper implementation + #746 fixed-issue catalogue wave + #812 space-free THIS_SH pin #820).

…chor

The #820 space-free THIS_SH pin closed the ${THIS_SH} face, but the
errors-family machine dependence had a second live input the CI lane
could never see: the runner forwards ambient TEMP/TMP, the engine
self-injects a Windows TMPDIR default from that process temp dir
(executor/init.rs, the /tmp mapping fixture), and the upstream assets
expand $TMPDIR UNQUOTED for real faces in three slices:

- heredoc.tests:115-124: cat > ${TMPDIR}/bash-zzz-$$ heredoc round-trip
- quote.tests:136-141: printf ... > $TMPDIR/quote-$$, re-sourced via
  ${THIS_SH} $TMPDIR/...
- redir.tests:35-119: the $TMPDIR file battery incl. the
  testf/'oops -- $1 not found' branch

Verified on master HEAD (45f537e): with TEMP='D:\temp-812\rub temp'
the snapshot lane diverges from the committed bytes in exactly those
three slices (heredoc 1483 -> 1463 bytes; quote drops the 'escape\'
line; redir prints 'oops -- /d/temp-812/rub not found') while a
space-free TEMP stays green — machine-dependent bytes across Windows
hosts, invisible to CI, the same degenerate shape as the THIS_SH face
one layer over (a space in a machine-absolute path met by unquoted
upstream expansion).

Same contractual move as #820 and as true-baseline.sh's GNU side
(TMPDIR="$w/tmp" in scripts/true-baseline.sh): the lane now

1. anchors the per-suite scratch at a space-free root (ambient temp
   when it is space-free, else %SystemRoot%\Temp; neither -> loud
   panic), so HOME/.thissh/TMPDIR share one machine-independent shape,
2. exports TMPDIR=<scratch>/tmp to the suite child, created eagerly
   (the assets redirect into $TMPDIR with no mkdir).

No re-record: $TMPDIR's value never prints on a success face in any of
the 13 slices (file targets and PATH assignments only), so bytes on a
space-free host are unchanged — the committed snapshots diff clean; a
spaced-TEMP host converges onto them. Bonus: the spaced-host junk side
effect is gone (errors10.sub's unquoted 'mkdir $TDIR' used to create a
word-split directory OUTSIDE the scratch and 'rm -rf' it afterwards).

Verification, both at HEAD:
- space-free host: snapshot lane green 13/13, snapshots byte-identical;
- spaced TEMP: pre-fix 3 slices diverged (reproduced above), post-fix
  green 13/13 byte-identical, no scratch leftovers, no junk dirs;
- cargo test --test regression -- --test-threads=1: 76 passed / 0 failed;
- cargo fmt --check clean; cargo check --tests: no warning touches
  tests/regression.rs.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Independent code review — verdict: APPROVE-WITH-NITS

Reviewed independently from a fresh detached worktree at b287e5a with a separate detached baseline tree at 45f537e (own builds, own scratch under D:\temp-cr812\rub temp; nothing recorded was pushed — record-mode writes were reverted in-tree, committed snapshots untouched).

Verified (all re-executed, not taken from the description)

  1. Root cause chain confirmed statically. The suite lane .env_clear()s then whitelists machine infra including ambient TEMP/TMP (tests/regression.rs:682-693 post-diff); the engine self-injects a Windows TMPDIR default from that process temp dir when TMPDIR is absent (src/executor/init.rs:599-606, or_insert_with(|| shell_pwd_display(safe_temp_dir_string()...)); safe_temp_dir_string reads TMPDIR→TEMP→TMP, local_helpers.rs:172); and the upstream assets expand ${TMPDIR} unquoted in exactly 3 of the 13 slices (grep: heredoc 6, quote 4, redir 37, all other 10 slices 0), incl. the redir testf/oops -- $1 not found battery and errors10.sub's unquoted TDIR=$TMPDIR/errors-$$ + mkdir $TDIR + rm -rf $TDIR. A spaced ambient TEMP therefore reaches real faces through injected $TMPDIR — CI (space-free runneradmin TEMP) can never see it. test(infra): #767 single helper implementation + #746 fixed-issue catalogue wave + #812 space-free THIS_SH pin #820's THIS_SH pin is indeed in the base; this is the second face of the same shape.
  2. Reproduction, baseline 45f537e + TEMP='D:\temp-cr812\rub temp' (record mode for per-suite byte forensics): exactly the three TMPDIR-touching snapshots diverge from committed bytes, all other 10 byte-identical. heredoc −20 bytes (abc/def ghi/jkl mno heredoc round-trip goes silent — 1483→1463, exactly as claimed); quote drops one escape\ line (the ${THIS_SH} $TMPDIR/quote-$$ re-source); redir collapses to repeated oops -- /d/temp-cr812/rub not found — the unquoted $1 echo of the word-split POSIX-form injected TMPDIR, byte-for-byte the described shape.
  3. Fix matrix, all four cells + the panic leg:
    • head + space-free ambient: snapshot lane green, snapshots untouched.
    • head + spaced TEMP: record-mode output diffs EMPTY against committed snapshots; normal mode green. The %SystemRoot%\Temp fallback leg was genuinely exercised (scratch landed at C:\Windows\Temp).
    • baseline + space-free: green, snapshots untouched — the divergence is specifically the spaced-TEMP host, CI was never broken.
    • head + spaced TEMP + spaced SystemRoot (controlled injection): fails in 0.00s with panic at tests\regression.rs:458: rubash#812: no space-free temp root available... — the loud-fail path is real, not silent divergence.
  4. "No re-record" proven the strong way: the two states produce different TMPDIR values (ambient C:\Users\cmx\AppData\Local\Temp scratch vs C:\Windows\Temp scratch) and both reproduce the committed bytes exactly — so the value demonstrably never reaches output bytes; spaced hosts converge onto the committed snapshots.
  5. Junk side effect observed live: my two baseline spaced runs leaked engine-internal temps (comsub24-*, foo-*, bash-redir-*, process-subst *.tmp; two distinct PIDs matching those runs) directly into the spaced ambient dir, outside the per-suite scratch — the engine's internal temp machinery follows the forwarded ambient TEMP when TMPDIR is unpinned. The head runs left nothing anywhere (spaced dir untouched, C:\Windows\Temp clean after runs). The fix removes the whole junk surface, not just the errors10.sub face.
  6. TMPDIR blast radius is the lane only: run_suite_snapshot has exactly one caller (upstream_suite_slice_snapshots); the golden lane (run_rubash_in) env-clears without TMPDIR and is untouched; the [bug] nvm 链路 File name too long ×5(根因未定)+ 诊断族四项(compopt 静默 / command-not-found 前缀 / 顶层 line N 丢失 / source 链归属错位) #162 TMPDIR child-boundary test is a separate binary over an unchanged engine; no other tests/*.rs reads TMPDIR through this path.
  7. Contract alignment: scripts/true-baseline.sh:338,342 pins TMPDIR="$w/tmp" on the GNU side; the Windows snapshot side now mirrors it, and quote.tests' : ${TMPDIR:=/tmp} no-ops against the pinned value exactly as it does against the GNU-side pin.
  8. Gates re-run: cargo test --test regression -- --test-threads=1 → 76 passed / 0 failed (57s); cargo fmt --check clean; cargo check --tests warnings exist only in pre-existing unrelated test files — zero touch tests/regression.rs (note: cargo clippy -D warnings does not pass on the lib, identically on baseline — pre-existing debt, not this PR's gate).
  9. Hitchhiking / GPL scan: single commit b287e5a, parent exactly 45f537e; 1 file, tests/regression.rs +63/−1; no submodule pointer change, no binaries, no workflow edits; diff contains no license text (comments quote only small factual asset fragments; true-baseline.sh is an in-repo script, comparison is clean).

Nits (non-blocking)

  1. Space-freeness checks only ' '. contains(' ') misses a tab/newline, which IFS also splits on. Unproducible through normal Windows UIs and consistent with the pre-existing space_free_this_sh check, so the residual hole is at least uniform — but contains([' ', '\t', '\n']) would close it for free.
  2. Spaced-ambient + space-free-but-unwritable %SystemRoot%\Temp degrades to a generic panic. The root candidates are checked for spaces but not writability, so that host dies on expect("create snapshot scratch dir") instead of the errors slice snapshot is machine-dependent across Windows hosts: 'after exit:'/'after shift:' status lines diverge both directions vs golden (errors10.sub ${THIS_SH} suspect) #812 host-shape message — still loud (test fails, no divergent bytes), just less diagnosable. Eager create_dir_all on the chosen root (or extending that expect's message) would make triage one-glance. Same mechanics for hard-kill leftovers under C:\Windows\Temp — pre-existing scheme, unchanged by this PR.
  3. Stale sibling comment worth a follow-up deletion: tests/regression.rs:272 still says "(Suite snapshots deliberately keep the ambient env: their bytes were recorded with it.)" — it has contradicted the lane since it went airtight (predates this PR), and this PR's own comments now document the opposite. One-line cleanup, does not belong in this commit.

Merging is safe from my side: the lane is machine-independent in both verified host shapes, fails loudly on a third, and the committed bytes are provably the fixed point of both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant