Repository navigation
Fix #999: CRLF-safe shebang writes in three sibling test fixtures - #1068
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 defaultnewline=Noneapplies universal-newline translation on write, turning\ninto\r\non 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 intest_lazy_mode_failure_returns_instead_of_exiting, same file/mechanism),tests/test_stdin_source_top_level_wins_344.pyandtests/test_session_start_compact_recap_339.py.test_detect_tools_cache_668.pycarries 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 usingopen(path, "w", newline="\n", encoding="utf-8")(matching this repo's existing_write_shell_scriptconvention intests/test_autonomous_log_retention_487.py), every shim-writing call site rewired to use it, and a new regression testtest_write_shell_script_never_uses_path_write_textper file that mocksPath.write_textto 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
\nmeant 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 mockedAssertionError); 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]