Skip to content

fix(130): decode what git prints as a path so a non-ASCII repository path survives an ASCII locale - #135

Merged
cogc-factory[bot] merged 1 commit into
mainfrom
fix/130-nonascii-path
Oct 13, 2026
Merged

cogc-factory[bot] merged 1 commit into
mainfrom
fix/130-nonascii-path

Conversation

@cogc-factory

@cogc-factory cogc-factory Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #130

What changes

The shared helper git() decoded git's output with the locale's encoding and errors="replace". Under an ASCII locale the path .../dé came back as .../d??, which the process could neither open nor encode: doctor, init and run ended in a UnicodeEncodeError traceback. It now decodes the way the operating system decodes a path (file system encoding, surrogateescape), so the path round-trips. repo_config.repository_root goes through the helper instead of its own subprocess call. No spec change (triaged on the issue).

Proof

Acceptance

  • doctor works in a repository whose path has a non-ASCII character under an ASCII locale: test_doctor_reports_a_repository_whose_path_has_a_non_ascii_character_under_an_ascii_locale
  • init does too, and writes the config: test_init_sets_up_a_repository_whose_path_has_a_non_ascii_character_under_an_ascii_locale
  • run (and with it the hooks, which load the config through the same helper): test_run_works_in_a_repository_whose_path_has_a_non_ascii_character_under_an_ascii_locale

Demo (scratch repository /tmp/rep130/dé, the environment of the issue)

$ cd /tmp/rep130/dé   # LC_ALL=C PYTHONUTF8=0 PYTHONCOERCECLOCALE=0
$ prepush-ci init --non-interactive --check true --hooks none --ci none
skipped: hooks (--hooks none)
written: .claude/hooks/session-start.sh
written: .claude/settings.json
set up
exit 0
$ prepush-ci doctor --hooks none
ok config: loaded from .prepush-ci.toml
ok commit-msg: no local hooks wanted (`--hooks none`)
ok pre-push: no local hooks wanted (`--hooks none`)
ok preflight: nothing to verify: no `preflight` and no `require_env`

Check: CI on 0ff7ef2: 1211 passed (Linux; 1188 passed, 23 skipped on Windows, as on main), specs valid 12/12 (run).

Details for the reviewer

All three specs failed with the traceback before the fix. Not covered, and filed as #134: install --hooks native writes hook scripts that embed such a path; the write still fails under an ASCII locale (before this change it failed earlier, in the same way). On Windows the helper now decodes git's UTF-8 output as UTF-8 instead of the ANSI code page.

— chuck-norris

… path survives an ASCII locale

`git()` decoded git's output with the locale's encoding and `errors="replace"`:
under an ASCII locale `.../dé` came back as `.../d??` (U+FFFD), a path the
process could neither open nor encode, so `doctor`, `init` and `run` failed with
a UnicodeEncodeError traceback. Output is now decoded with the file system
encoding and `surrogateescape`, which is what `os.fsdecode` does, so the path
round-trips to the same bytes.

Decisions: the fix is in the one helper every command uses, and
`repo_config.repository_root` now goes through it instead of its own
subprocess call. Writing hook scripts that embed such a path (`install --hooks
native`) still fails under an ASCII locale; that is a separate bug and
unchanged by this commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Loop: chuck-norris
@cogc-factory
cogc-factory Bot requested a review from k-sok as a code owner October 13, 2026 15:18
@cogc-factory cogc-factory Bot added the turn:build chuck-norris's move: implement or fix label Oct 13, 2026
@cogc-factory cogc-factory Bot mentioned this pull request Oct 13, 2026
@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/prepush_ci
  git.py
  repo_config.py
Project Total  

This report was generated by python-coverage-comment-action

@cogc-factory cogc-factory Bot added turn:review robocop's move: review the implementation and removed turn:build chuck-norris's move: implement or fix labels Oct 13, 2026
@cogc-factory

cogc-factory Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Factory ledger

What the loops spent on this so far, summed from the loop runtime's records. Cost is at API prices; the loops run on a subscription, so it measures plan usage, not a bill.

Loop Model Wakes Time Output tokens Cost at API prices
chuck-norris sonnet-5-5 2 13 min 15k $0.53
robocop opus-5-5 1 14 min 18k $1.15
terminator sonnet-5-5 2 4 min 22k $0.58
Total 5 31 min 55k $2.26

Updated automatically.

@cogc-factory

cogc-factory Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Verdict: APPROVE

Reviewed head 0ff7ef2 (round 1, one commit on 977b5ff). It merges cleanly, and every required check on the head is green: check (3.11) and check (3.14) 1211 passed, check-windows 1188 passed with 23 skipped, specs 12/12, coverage, ci-passed, proof.

Findings

None that block.

Notes:

Evidence

Local full check at 0ff7ef2 (sh scripts/ci, no CI): ==> full check passed, unit tests 505 passed with 100% of core, all tests 1208 passed with 95% overall, specs 12/12. The local count is 1208 because that many tests are collected here; CI collected 1211.

Mutants, running the three new specs:

git.py back to errors="replace" (locale encoding)  -> 3 failed (doctor, init, run)
repo_config.py back to its own subprocess call     -> 2 failed (doctor, run)

The proof's environment (LC_ALL=C PYTHONUTF8=0 PYTHONCOERCECLOCALE=0), repository at /tmp/rc135/<side>/dé with a bare remote. Head on the left, main (977b5ff) on the right:

init --non-interactive --check 'echo check' --hooks none --ci none
  head: written ... / set up                 main: UnicodeEncodeError (pathlib open)
doctor
  head: ok commit-msg/pre-push/preflight     main: UnicodeEncodeError in resolve()
PREPUSH_CI=full git commit -m "dritté Nachricht"   (hooks native)
  head: trailer `Prepush-CI: full` written   main: UnicodeDecodeError ('ANSI_X3.4-1968')
git push origin main
  head: check / To ../remote.git             main: UnicodeEncodeError, push refused
verify HEAD (ASCII and UTF-8 locale)
  head: verified: 26395c5… carries the trailer `Prepush-CI: full`
prepush-ci run
  head: check, rc 0                          main: UnicodeEncodeError

Looking for regressions under a UTF-8 locale, where surrogateescape now replaces replace: verify, doctor and push on the same repository all still work. A commit message in Latin-1 bytes fails in the commit-msg hook (read_text(encoding="utf-8")), on head and on main alike. That is the Bug above, not this change.

Next: turn:attack.

— robocop

@cogc-factory

cogc-factory Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Attack: PASS

Head: 0ff7ef2 · 11 hypotheses · 0 broken

# Hypothesis Result
1 UTF-8 path dé, ASCII locale: doctor, run, verify, strip ok (all four traceback on main for doctor/run)
2 Latin-1 (invalid UTF-8) path, UTF-8 locale ok (FileNotFoundError on main)
3 Latin-1 path, ASCII locale ok
4 Path with a space, a newline and é ok
5 Linked worktree at a non-ASCII path ok
6 Submodule in a non-ASCII directory ok
7 Non-ASCII branch name, strip main (surrogate-escaped branch handed back to update-ref) ok
8 Non-ASCII committer name/email, verify ok
9 Unreachable remote with a non-ASCII path, require_up_to_date: the git error is quoted ok, no traceback (stderr shows \udcc3\udcb6 for ö under ASCII; ? before; cosmetic)
10 Full cycle: hooks installed under a UTF-8 locale, then commit with trailer, push and verify under an ASCII locale ok, check ran once, trailer verified
11 UTF-8 locale, é path: unchanged ok

Found while attacking, both on main too (so not held against this PR): #145 (commit-msg hook traceback on a non-UTF-8 .prepush-ci.toml), #146 (non-ASCII remote name never matches require_up_to_date under an ASCII locale). Known and out of scope: #134 (install), #144 (message).

Reproduction scripts

/tmp/atk135/h.sh and /tmp/atk135/h2.sh on the terminator workstation (SHA=<sha> bash h.sh); kept as scenario s_31 in the sweep. Every case ran against 0ff7ef2 and 04aab2d (main). Outcome on main: tracebacks in 1–6 and 9–10, as #130 says; none on 0ff7ef2.

— terminator

@cogc-factory
cogc-factory Bot enabled auto-merge (rebase) October 13, 2026 16:19
@cogc-factory cogc-factory Bot added turn:human Ready to merge: the human's move and removed turn:attack terminator's move: try to break the implementation labels Oct 13, 2026
@cogc-factory
cogc-factory Bot merged commit fdc4e1c into main Oct 13, 2026
12 checks passed
@cogc-factory
cogc-factory Bot deleted the fix/130-nonascii-path branch October 13, 2026 16:23
cogc-factory Bot added a commit that referenced this pull request Oct 13, 2026
… not UTF-8

The hook read the message with a strict UTF-8 decode, and decoded the output of its
own git calls with the locale, so a Latin-1 message (or comment character, or template
path) ended the commit with a UnicodeDecodeError traceback.

Decisions: the text is only classified (editor used, blank, untouched template), never
written back, so decoding with errors="replace" is enough; git interpret-trailers
rewrites the file and keeps its bytes. The same errors="replace" goes on the two git
calls of the hook, as git() in git.py has had since #135. The hook keeps its own
subprocess calls: it needs stdin for stripspace and check=True.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Loop: chuck-norris
cogc-factory Bot added a commit that referenced this pull request Oct 13, 2026
… not UTF-8

The hook read the message with a strict UTF-8 decode, and decoded the output of its
own git calls with the locale, so a Latin-1 message (or comment character, or template
path) ended the commit with a UnicodeDecodeError traceback.

Decisions: the text is only classified (editor used, blank, untouched template), never
written back, so it is decoded with errors="surrogateescape" (every byte stays distinct,
so a template path or content that is not UTF-8 is still found and compared equal); git interpret-trailers rewrites the file and keeps its bytes. The same decoding goes on the two git
calls of the hook, as git() in git.py has had since #135. The hook keeps its own
subprocess calls: it needs stdin for stripspace and check=True.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Loop: chuck-norris
cogc-factory Bot added a commit that referenced this pull request Oct 13, 2026
… not UTF-8

The hook read the message with a strict UTF-8 decode, and decoded the output of its
own git calls with the locale, so a Latin-1 message (or comment character, or template
path) ended the commit with a UnicodeDecodeError traceback.

Decisions: the text is only classified (editor used, blank, untouched template), never
written back, so it is decoded with errors="surrogateescape" (every byte stays distinct,
so a template path or content that is not UTF-8 is still found and compared equal); git interpret-trailers rewrites the file and keeps its bytes. The same decoding goes on the two git
calls of the hook, as git() in git.py has had since #135. The hook keeps its own
subprocess calls: it needs stdin for stripspace and check=True.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Loop: chuck-norris
cogc-factory Bot added a commit that referenced this pull request Oct 13, 2026
… not UTF-8

The hook read the message with a strict UTF-8 decode, and decoded the output of its
own git calls with the locale, so a Latin-1 message (or comment character, or template
path) ended the commit with a UnicodeDecodeError traceback.

Decisions: the text is only classified (editor used, blank, untouched template), never
written back, so it is decoded with errors="surrogateescape" (every byte stays distinct,
so a template path or content that is not UTF-8 is still found and compared equal); git interpret-trailers rewrites the file and keeps its bytes. The same decoding goes on the two git
calls of the hook, as git() in git.py has had since #135. The hook keeps its own
subprocess calls: it needs stdin for stripspace and check=True.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Loop: chuck-norris
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

turn:human Ready to merge: the human's move

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doctor, init: UnicodeEncodeError traceback in a repository whose path has a non-ASCII character, ASCII locale

1 participant