fix(tools): preserve main sync reports on limited encodings #5818

Merged
NumberGuan merged 2 commits from upstream-pr/5818 into main 2026-10-15 13:32:39 +00:00
NumberGuan commented 2026-10-14 12:17:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NumberGuan on 2026-10-14T12:17:33Z.


What

check_main_sync.py crashes while printing a report if a changed path contains characters stdout cannot encode. With a clean merge involving sp ace é 測 🚀.txt, ASCII or CP1252 output raises UnicodeEncodeError, leaves stdout empty and returns 1 instead of the normal success status. Conflict reports also disappear.

Set stdout's error handler to backslashreplace before printing. Keep its selected encoding: CP1252 still prints é, unencodable characters appear as \x/\u/\U escapes, and UTF-8 keeps the complete filename. Python's TextIOWrapper.reconfigure documentation specifies that omitted settings stay unchanged. Git inspection and merge/strict exit rules remain the same.

Add two regressions using real temporary Git repositories, Unicode filenames and merge commits. Nine CLI scenarios cover ASCII, CP1252 and UTF-8, clean merges in normal and strict mode, and conflicts. Each checks the expected exit status, file listing and merged PR reference, with no traceback. No other open PR covers this utility; no dependency.

Tested

Windows x64, Python 3.12.14 and Git; CMake 4.3.1/Ninja relinker-only configuration for test registration. Based on upstream e736e5bdb; contribution b5007fb7c.

python tools/tests/test_check_main_sync.py
ctest --test-dir build-relinker -R '^(check_main_sync|pr_overlap_own_branch|pr_overlap_encoding|test_registration)$' --output-on-failure --no-tests=error --parallel 2
python tools/check_test_registration.py build-relinker
python tools/check_conventions.py --base origin/main
git diff origin/main --check

Before the fix, the new CLI regressions fail with UnicodeEncodeError on both ASCII and CP1252. After the two-line fix, all nine unit tests pass. The four registered CTest groups passed in 12.94 seconds; check_main_sync took 12.39 seconds. After rebasing on main at c8e3039, all nine unit tests passed in 11.94 seconds and the four CTest groups passed in 11.97 seconds. After rebasing on main at 96dd647, the four CTest groups passed again in 10.68 seconds, including check_main_sync. Registration, conventions (including this title and body) and whitespace checks pass. git range-diff confirms the patch is unchanged after rebasing over upstream changes.

Hosted relinker CI passed on Windows, Linux and macOS for 090b8e0a1, including the registered Python regression. Hosted conventions and intake also passed. The full system-library builds and unrelated register-context/write-watch jobs were skipped by the workflow.

C++ targets and system libraries were not built locally for this Python-only change. No game or PS5 hardware test; the console cases use redirected stdout with explicit encodings.

Revalidated on current main

Rebased onto 63fb0cd92. The registered check_main_sync CTest passed in 11.05 s. Test registration, conventions and whitespace checks passed. Hosted relinker CI passed on Windows, Linux and macOS; hosted conventions also passed. This is a Python-only change; no title or PS5 hardware test was run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source; none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4857731932 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5818). Originally posted by [NumberGuan](https://github.com/NumberGuan) on 2026-10-14T12:17:33Z. --- ### What `check_main_sync.py` crashes while printing a report if a changed path contains characters stdout cannot encode. With a clean merge involving `sp ace é 測 🚀.txt`, ASCII or CP1252 output raises `UnicodeEncodeError`, leaves stdout empty and returns 1 instead of the normal success status. Conflict reports also disappear. Set stdout's error handler to `backslashreplace` before printing. Keep its selected encoding: CP1252 still prints `é`, unencodable characters appear as `\x`/`\u`/`\U` escapes, and UTF-8 keeps the complete filename. Python's [TextIOWrapper.reconfigure documentation](https://docs.python.org/3.12/library/io.html#io.TextIOWrapper.reconfigure) specifies that omitted settings stay unchanged. Git inspection and merge/strict exit rules remain the same. Add two regressions using real temporary Git repositories, Unicode filenames and merge commits. Nine CLI scenarios cover ASCII, CP1252 and UTF-8, clean merges in normal and strict mode, and conflicts. Each checks the expected exit status, file listing and merged PR reference, with no traceback. No other open PR covers this utility; no dependency. ### Tested Windows x64, Python 3.12.14 and Git; CMake 4.3.1/Ninja relinker-only configuration for test registration. Based on upstream `e736e5bdb`; contribution `b5007fb7c`. ```text python tools/tests/test_check_main_sync.py ctest --test-dir build-relinker -R '^(check_main_sync|pr_overlap_own_branch|pr_overlap_encoding|test_registration)$' --output-on-failure --no-tests=error --parallel 2 python tools/check_test_registration.py build-relinker python tools/check_conventions.py --base origin/main git diff origin/main --check ``` Before the fix, the new CLI regressions fail with `UnicodeEncodeError` on both ASCII and CP1252. After the two-line fix, all nine unit tests pass. The four registered CTest groups passed in 12.94 seconds; `check_main_sync` took 12.39 seconds. After rebasing on `main` at `c8e3039`, all nine unit tests passed in 11.94 seconds and the four CTest groups passed in 11.97 seconds. After rebasing on `main` at `96dd647`, the four CTest groups passed again in 10.68 seconds, including `check_main_sync`. Registration, conventions (including this title and body) and whitespace checks pass. `git range-diff` confirms the patch is unchanged after rebasing over upstream changes. Hosted [relinker CI](https://github.com/boykopovar/AnyPS5/actions/runs/38567457311) passed on Windows, Linux and macOS for `090b8e0a1`, including the registered Python regression. Hosted [conventions](https://github.com/boykopovar/AnyPS5/actions/runs/38567452865) and intake also passed. The full system-library builds and unrelated register-context/write-watch jobs were skipped by the workflow. C++ targets and system libraries were not built locally for this Python-only change. No game or PS5 hardware test; the console cases use redirected stdout with explicit encodings. ### Revalidated on current main Rebased onto `63fb0cd92`. The registered `check_main_sync` CTest passed in 11.05 s. Test registration, conventions and whitespace checks passed. Hosted [relinker CI](https://github.com/boykopovar/AnyPS5/actions/runs/38570378445) passed on Windows, Linux and macOS; hosted [conventions](https://github.com/boykopovar/AnyPS5/actions/runs/38570373619) also passed. This is a Python-only change; no title or PS5 hardware test was run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source; none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes, Codex
ideabsassistenza commented 2026-10-14 12:45:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ideabsassistenza on 2026-10-14T12:45:13Z.


Independent Windows validation of head b5007fb7cb693ffc66846d0ae833430843098c14, CPython 3.12.14 on Windows 11 Pro, i7-8700.

  • All nine test_check_main_sync.py tests pass, no skips. The two new methods exercise nine CLI scenarios: ASCII, CP1252 and UTF-8; clean normal/strict reports and conflict reports.
  • Running those same two methods with the unmodified tool from base e736e5bdb18e72ed717014c02c62c616701a7cf8 gives six failed subcases and no test errors. ASCII/CP1252 lose the report; the three UTF-8 controls pass. With this head, report contents and exit statuses pass, including the merged PR reference and CP1252's preserved accented character.
  • Local timing observation: the complete nine-test suite took 32.344 s, then 34.843 s in a separate run outside the Codex execution sandbox; both passed. These are direct Python runs, not CTest timeouts or hosted CI failures. They exceed the project's 30 s reference on this host, so the suite may merit splitting if slower CI runners also approach that bound. This does not contradict the faster run recorded in the PR description.

Only the exact tool and test files were extracted from Git into an isolated local directory. The contribution checkout and its branch remained unchanged. No CMake/CTest registration, native build/runtime, game, GPU or composition with current main was tested; windows_fixed_base remained excluded.

AI-assisted: yes (Codex); source diff, baseline failures and both passing Windows logs reviewed in this session.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6168645968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5818#issuecomment-6168645968). Originally posted by [ideabsassistenza](https://github.com/ideabsassistenza) on 2026-10-14T12:45:13Z. --- Independent Windows validation of head `b5007fb7cb693ffc66846d0ae833430843098c14`, CPython 3.12.14 on Windows 11 Pro, i7-8700. - All nine `test_check_main_sync.py` tests pass, no skips. The two new methods exercise nine CLI scenarios: ASCII, CP1252 and UTF-8; clean normal/strict reports and conflict reports. - Running those same two methods with the unmodified tool from base `e736e5bdb18e72ed717014c02c62c616701a7cf8` gives six failed subcases and no test errors. ASCII/CP1252 lose the report; the three UTF-8 controls pass. With this head, report contents and exit statuses pass, including the merged PR reference and CP1252's preserved accented character. - Local timing observation: the complete nine-test suite took 32.344 s, then 34.843 s in a separate run outside the Codex execution sandbox; both passed. These are direct Python runs, not CTest timeouts or hosted CI failures. They exceed the project's 30 s reference on this host, so the suite may merit splitting if slower CI runners also approach that bound. This does not contradict the faster run recorded in the PR description. Only the exact tool and test files were extracted from Git into an isolated local directory. The contribution checkout and its branch remained unchanged. No CMake/CTest registration, native build/runtime, game, GPU or composition with current main was tested; `windows_fixed_base` remained excluded. AI-assisted: yes (Codex); source diff, baseline failures and both passing Windows logs reviewed in this session.
thuanquang commented 2026-10-14 16:36:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-14T16:36:13Z.


With PYTHONIOENCODING=utf-8 set, the existing test_paths_with_spaces_and_unicode_are_reported_verbatim still fails with this change: the tool writes UTF-8, while run_tool decodes with the locale code page (text=True), so é arrives as é. The shell Claude Code starts on Windows has PYTHONIOENCODING=utf-8:surrogateescape set; the check_main_sync code-page failure mentioned in #5804 may be the same.

Windows 11 26200, Python 3.13.3, code page 1252, this head 969a8bfa7 merged into main e34c47921, python tools/tests/test_check_main_sync.py:

PYTHONIOENCODING Result
unset 9 tests OK
utf-8 1 failure: test_paths_with_spaces_and_unicode_are_reported_verbatim
utf-8:surrogateescape same failure

Pinning the encoding in run_tool, as your new tests do, fixes it:

def run_tool(path, *args):
    return subprocess.run([sys.executable, str(TOOL), "--repo", str(path), "--base", "main", *args], capture_output=True,
                          encoding="utf-8", env={**os.environ, "PYTHONIOENCODING": "utf-8"})

With that, the 9 tests pass with PYTHONIOENCODING unset, utf-8, utf-8:surrogateescape and cp1252. Not tested: Linux and macOS.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6173288242 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5818#issuecomment-6173288242). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-14T16:36:13Z. --- With `PYTHONIOENCODING=utf-8` set, the existing `test_paths_with_spaces_and_unicode_are_reported_verbatim` still fails with this change: the tool writes UTF-8, while `run_tool` decodes with the locale code page (`text=True`), so `é` arrives as `é`. The shell Claude Code starts on Windows has `PYTHONIOENCODING=utf-8:surrogateescape` set; the `check_main_sync` code-page failure mentioned in #5804 may be the same. Windows 11 26200, Python 3.13.3, code page 1252, this head `969a8bfa7` merged into `main` `e34c47921`, `python tools/tests/test_check_main_sync.py`: | `PYTHONIOENCODING` | Result | |---|---| | unset | 9 tests OK | | `utf-8` | 1 failure: `test_paths_with_spaces_and_unicode_are_reported_verbatim` | | `utf-8:surrogateescape` | same failure | Pinning the encoding in `run_tool`, as your new tests do, fixes it: ```python def run_tool(path, *args): return subprocess.run([sys.executable, str(TOOL), "--repo", str(path), "--base", "main", *args], capture_output=True, encoding="utf-8", env={**os.environ, "PYTHONIOENCODING": "utf-8"}) ``` With that, the 9 tests pass with `PYTHONIOENCODING` unset, `utf-8`, `utf-8:surrogateescape` and `cp1252`. Not tested: Linux and macOS. AI-assisted: yes (Claude Code).
simonbronk commented 2026-10-15 13:25:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-15T13:25:16Z.


Independent Windows recheck of the encoding follow-up at d4cce869eb12c4dc52537bf2a6cbb0b76e4f57f8 (AI-assisted). Thanks for carrying the suggested run_tool encoding fix.

  • Exact current tool/test files extracted to an isolated directory, Windows 11 22631, CPython 3.12.14.
  • Full nine-test suite with parent PYTHONIOENCODING=utf-8: 9/9 pass, no skips, 33.497 s.
  • test_paths_with_spaces_and_unicode_are_reported_verbatim also passes separately with parent PYTHONIOENCODING=utf-8:surrogateescape, cp1252, and unset (3.770 / 3.642 / 3.574 s). These are focused runs, not three more full-suite runs.
  • Control: the previous test harness from 969a8bfa7681f82700d55d4e1fed2e3f9ca5d01e, paired with the same current production tool and parent PYTHONIOENCODING=utf-8, fails that Unicode assertion (one failure, no errors; 3.403 s). This isolates the harness fix from a production-tool change.

The test now pins both ends to UTF-8, so the inherited parent encoding no longer corrupts the captured path in this case. The full suite still took over 30 s on this host; that is a direct Python run, not a CTest timeout or hosted CI failure. No current-main merge/composition, full repository/CTest/native build, Linux/macOS, game or GPU execution tested. No source edit, new patch or separate PR from me.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6193161539 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5818#issuecomment-6193161539). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-15T13:25:16Z. --- Independent Windows recheck of the encoding follow-up at `d4cce869eb12c4dc52537bf2a6cbb0b76e4f57f8` (AI-assisted). Thanks for carrying the suggested `run_tool` encoding fix. - Exact current tool/test files extracted to an isolated directory, Windows 11 22631, CPython 3.12.14. - Full nine-test suite with parent `PYTHONIOENCODING=utf-8`: **9/9 pass, no skips**, 33.497 s. - `test_paths_with_spaces_and_unicode_are_reported_verbatim` also passes separately with parent `PYTHONIOENCODING=utf-8:surrogateescape`, `cp1252`, and unset (3.770 / 3.642 / 3.574 s). These are focused runs, not three more full-suite runs. - Control: the previous test harness from `969a8bfa7681f82700d55d4e1fed2e3f9ca5d01e`, paired with the same current production tool and parent `PYTHONIOENCODING=utf-8`, fails that Unicode assertion (one failure, no errors; 3.403 s). This isolates the harness fix from a production-tool change. The test now pins both ends to UTF-8, so the inherited parent encoding no longer corrupts the captured path in this case. The full suite still took over 30 s on this host; that is a direct Python run, not a CTest timeout or hosted CI failure. No current-main merge/composition, full repository/CTest/native build, Linux/macOS, game or GPU execution tested. No source edit, new patch or separate PR from me.
adriadam10 commented 2026-10-15 13:32:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:32:26Z.


Checked on the PR merged onto main: build and ctest green (47 tests, including check_main_sync); without the check_main_sync.py change the new tests fail, with it they pass. Third-party Windows runs confirm 9/9. Relinker CI is green on all three OSes; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6193308444 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5818#issuecomment-6193308444). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T13:32:26Z. --- Checked on the PR merged onto main: build and ctest green (47 tests, including `check_main_sync`); without the `check_main_sync.py` change the new tests fail, with it they pass. Third-party Windows runs confirm 9/9. Relinker CI is green on all three OSes; merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!5818
No description provided.