Skip to content

test_git_backup_rotate_advice_974.py: pre_commit.write_text has no newline= guard against CRLF shebang on Windows #994

Closed

Description

@fdaviddpt

tests/test_git_backup_rotate_advice_974.py:154's test_could_not_untrack_also_logs_rotate_advice
forces the hook's "could not untrack" branch by writing a pre-commit git hook script:

pre_commit.write_text("#!/bin/sh\nexit 1\n")
pre_commit.chmod(0o755)

Path.write_text with no newline="" argument uses Python's default text-mode newline
translation, which on Windows rewrites every \n to \r\n on write. A CRLF-terminated shebang
line (#!/bin/sh\r\n) can make some shebang parsers read /bin/sh\r as the interpreter path and
fail to exec, rather than running and exiting 1 as intended -- the script would silently stop
doing what the test relies on it doing.

Why this is inert today: the whole test file carries
pytestmark = pytest.mark.skipif(sys.platform == "win32", ...) for an unrelated reason (#79,
bash hook subprocess + POSIX flock/git semantics), so this file never runs on the one platform
where write_text's CRLF translation would matter. CI's own matrix
(.github/workflows/tests.yml, os: [ubuntu-latest, macos-latest, windows-latest]) confirms
windows-latest is exactly the leg this skip exempts, so nothing in CI today exercises the CRLF
path either way.

What would make this live: if the #79 skip reason is ever narrowed or removed (e.g. if a
future change makes the bash-hook mechanism itself portable), this specific line needs
newline="\n" added, or the content written via open(path, "wb") with an explicit b"...\n"
payload, before the test could be trusted on Windows. Re-check at that point rather than
assuming this issue was already closed by that change.

Confirmed still true by reading tests/test_git_backup_rotate_advice_974.py:154 and
.github/workflows/tests.yml directly at HEAD; not independently run on a Windows box (none
available). Originally logged in trap.d/989.pre-commit-hook-script-crlf-write-text.md during
a curate pass, declined there as a one-off code observation rather than an agent-facing lesson,
with this issue filed as its tracking record per that pass's own rule (#1736).

[AI-generated]

Activity

  1. added
    priority:low
    filed-by-loop
    lane-other
    on Oct 8, 2026
  2. self-assigned this
    on Oct 8, 2026
  3. removed their assignment
    on Oct 8, 2026
  4. added 2 commits that reference this issue on Oct 9, 2026
  5. added a commit that references this issue on Oct 12, 2026
    112dcef
  6. added a commit that references this issue on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    filed-by-looplane-otherpriority:low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions