Skip to content

Fix #999: CRLF-safe shebang writes in three sibling test fixtures - #1068

Merged
fdaviddpt merged 2 commits into
mainfrom
recon-999-20261031T202236Z
Oct 31, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
recon-999-20261031T202236Z

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Follow-up from #994/PR #998. Recon during that lane found three sibling test files with the same unguarded Path.write_text("#!/bin/sh...") shape #994 fixed: write_text()'s default newline=None applies universal-newline translation on write, turning \n into \r\n on Windows and corrupting the shebang line into a "bad interpreter" exec failure.

Fixed in tests/test_detect_tools_cache_668.py (two sites -- the one the issue named, plus a second unnamed one in test_lazy_mode_failure_returns_instead_of_exiting, same file/mechanism), tests/test_stdin_source_top_level_wins_344.py and tests/test_session_start_compact_recap_339.py. test_detect_tools_cache_668.py carries no win32 skip marker, so this one is live on windows-latest CI today; the other two carry an existing win32 skip and are currently inert, fixed anyway per the issue's own stated rationale.

Each file gains a local _write_shell_script(path, text) helper using open(path, "w", newline="\n", encoding="utf-8") (matching this repo's existing _write_shell_script convention in tests/test_autonomous_log_retention_487.py), every shim-writing call site rewired to use it, and a new regression test test_write_shell_script_never_uses_path_write_text per file that mocks Path.write_text to raise if called, confirming the helper never falls back to it.

A follow-up commit fixes a self-review finding: six string literals (two helper docstrings, one regression-test docstring per file, one assertion message per file) were written as plain strings containing literal-looking \n meant as prose, which Python's parser silently turned into real embedded newlines at compile time. All six are now raw strings.

TDD: red confirmed by reverting the helper to a plain write_text() call and re-running the new regression test alone (failed with the mocked AssertionError); green after restoring the fix. Targeted run after both commits: python3 -m pytest tests/test_detect_tools_cache_668.py tests/test_stdin_source_top_level_wins_344.py tests/test_session_start_compact_recap_339.py -q --no-cov -> 32 passed. Full suite not run locally, per this repo's own policy (CI is the matrix gate).

Self-reviewed in two rounds (Explore + oss:auditor concurrently on the main fix; one more Explore pass on the follow-up fix alone, triggered by fix_commit_scope.py's own second-pass rule since the main commit touches 3 files). One finding (the raw-string issue above), fixed. Zero findings refused, argued-down, or left below-bar.

Closes #999

[AI-generated]

fdaviddpt and others added 2 commits October 31, 2026 21:28
tests/test_detect_tools_cache_668.py (two sites), tests/test_stdin_source_top_level_wins_344.py
and tests/test_session_start_compact_recap_339.py each wrote a `#!/bin/sh` shim via
`Path.write_text()`, whose default `newline=None` applies universal-newline translation
on write and corrupts the shebang into a "bad interpreter" exec failure on Windows -- the
same shape #994/#998 fixed. test_detect_tools_cache_668.py carries no win32 skip, so this
one is live on windows-latest CI today; the other two are currently inert behind an
existing skip, same as #994's own file, but are fixed anyway rather than left as a trap.

Each file gains a local _write_shell_script helper (open(..., newline="\n")) and a
regression test pinning that the helper never falls back to Path.write_text().

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…rtion message

Self-review (Explore) caught that the new `_write_shell_script` helper's and its
regression test's docstrings, plus the mocked AssertionError message, used plain
(non-raw) triple/double-quoted strings containing literal-looking `\n`/`\r\n`
sequences meant as prose about escape characters. Without `r"""`/`r"..."`, Python's
parser turns those into real embedded newlines at compile time, garbling the
rendered docstring text (confirmed via __doc__ repr before/after). All three
files are now consistently raw-stringed for these literals.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 8aa456b into main Oct 31, 2026
19 checks passed
@fdaviddpt
fdaviddpt deleted the recon-999-20261031T202236Z branch October 31, 2026 21:14
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.

Unguarded write_text shebang writes in 3 sibling test files share #994's CRLF-on-Windows shape

1 participant