fix(tools): reconfigure streams with backslashreplace in progress_history #10218

Open
emirplus wants to merge 1 commit from upstream-pr/10218 into main
emirplus commented 2026-10-23 14:22:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by emirplus on 2026-10-23T14:22:04Z.


What

Reconfigure sys.stdout and sys.stderr with encoding="utf-8" and errors="backslashreplace" at the entrypoint of main() in tools/progress_history.py. This prevents UnicodeEncodeError when writing summaries or diagnostics on Windows consoles configured with legacy code pages.

Tested

Unit test test_main_reconfigures_streams verifies both standard streams are reconfigured with the expected encoding and error handler. Reported by @THEMANnt on Windows, Python 3.11.9, including a negative control.

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 (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4984231887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10218). Originally posted by [emirplus](https://github.com/emirplus) on 2026-10-23T14:22:04Z. --- ### What Reconfigure `sys.stdout` and `sys.stderr` with `encoding="utf-8"` and `errors="backslashreplace"` at the entrypoint of `main()` in `tools/progress_history.py`. This prevents `UnicodeEncodeError` when writing summaries or diagnostics on Windows consoles configured with legacy code pages. ### Tested Unit test `test_main_reconfigures_streams` verifies both standard streams are reconfigured with the expected encoding and error handler. Reported by @THEMANnt on Windows, Python 3.11.9, including a negative control. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
THEMANnt commented 2026-10-23 16:46:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-23T16:46:06Z.

Review: CHANGES_REQUESTED


Review: PR #10218

Head: 6da812a2346a2277605388fdc3cd174d1ae00c0a
Environment: Windows (win32), Python 3.11.9, Git 2.52.0.windows.1

Code Review

The implementation is correct. The stream reconfiguration loop in main() properly guards with hasattr and applies UTF-8 encoding with backslashreplace errors before any output. The new test test_main_reconfigures_streams correctly verifies this behavior, and the negative control confirms it exercises the new code path.

Blocking Issue

The conventions check fails because the PR body is missing required template sections:

  • What: missing or empty
  • Tested: missing or empty
  • Checklist: missing or empty

Please update the PR description to include these sections before requesting re-review.

Test Results

  • Baseline: 9/9 passed
  • Pristine PR: 10/10 passed
  • Candidate: 10/10 passed
  • Negative control: 1 failure (expected, confirms test validity)
  • Whitespace: OK
  • Conventions: FAILED (3 template errors)
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5631582295 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10218#pullrequestreview-5631582295). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-23T16:46:06Z. **Review:** CHANGES_REQUESTED --- ## Review: PR #10218 **Head:** `6da812a2346a2277605388fdc3cd174d1ae00c0a` **Environment:** Windows (win32), Python 3.11.9, Git 2.52.0.windows.1 ### Code Review The implementation is correct. The stream reconfiguration loop in `main()` properly guards with `hasattr` and applies UTF-8 encoding with `backslashreplace` errors before any output. The new test `test_main_reconfigures_streams` correctly verifies this behavior, and the negative control confirms it exercises the new code path. ### Blocking Issue The conventions check fails because the PR body is missing required template sections: - **What**: missing or empty - **Tested**: missing or empty - **Checklist**: missing or empty Please update the PR description to include these sections before requesting re-review. ### Test Results - Baseline: 9/9 passed - Pristine PR: 10/10 passed - Candidate: 10/10 passed - Negative control: 1 failure (expected, confirms test validity) - Whitespace: OK - Conventions: **FAILED** (3 template errors)
THEMANnt commented 2026-11-16 09:26:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-11-16T09:26:23Z.

Review: COMMENTED


Reviewed 6da812a234 merged with main at dcf3d15978. I found one merge blocker: the PR description still leaves AI-assisted blank. The What, Tested, and Checklist sections now pass. Please fill in AI-assisted with yes or no so the conventions check can pass. Conventions log

I found no code issues. On Windows with Python 3.11.9, 36 progress-history tests passed and 5 were skipped. With strict CP1252 stderr, the PR printed a Unicode diagnostic in UTF-8 and exited with the expected status. The same probe raised UnicodeEncodeError on main, and the new regression test failed when I restored the main implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5917671590 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10218#pullrequestreview-5917671590). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-11-16T09:26:23Z. **Review:** COMMENTED --- Reviewed `6da812a234` merged with `main` at `dcf3d15978`. I found one merge blocker: the PR description still leaves `AI-assisted` blank. The **What**, **Tested**, and **Checklist** sections now pass. Please fill in `AI-assisted` with `yes` or `no` so the conventions check can pass. [Conventions log](https://github.com/boykopovar/AnyPS5/actions/runs/40352389032/job/121675658999) I found no code issues. On Windows with Python 3.11.9, 36 progress-history tests passed and 5 were skipped. With strict CP1252 stderr, the PR printed a Unicode diagnostic in UTF-8 and exited with the expected status. The same probe raised `UnicodeEncodeError` on `main`, and the new regression test failed when I restored the `main` implementation.
catminou4 commented 2026-11-25 05:21:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by catminou4 on 2026-11-25T05:21:51Z.

Review: COMMENTED


Reviewed 6da812a234 merged onto main 7df43031f4 (clean merge), Ubuntu 22.04, Python 3.12.16.

  • python3 tools/tests/test_progress_history.py: 49 tests OK (1 skipped).
  • Control: with tools/progress_history.py from main, test_main_reconfigures_streams fails; restoring the PR source passes again.
  • The guard matches the stream setup main already uses in check_skips.py and library_oracle.py.
  • Overlap: #26736 and #26737 touch the same two files; each merges cleanly with this one.

Code is mergeable; the only remaining blocker is the AI-assisted line of the PR body, which the conventions check still flags.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6052246424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10218#pullrequestreview-6052246424). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T05:21:51Z. **Review:** COMMENTED --- Reviewed `6da812a234` merged onto `main` `7df43031f4` (clean merge), Ubuntu 22.04, Python 3.12.16. - `python3 tools/tests/test_progress_history.py`: 49 tests OK (1 skipped). - Control: with `tools/progress_history.py` from `main`, `test_main_reconfigures_streams` fails; restoring the PR source passes again. - The guard matches the stream setup `main` already uses in `check_skips.py` and `library_oracle.py`. - Overlap: #26736 and #26737 touch the same two files; each merges cleanly with this one. Code is mergeable; the only remaining blocker is the `AI-assisted` line of the PR body, which the conventions check still flags.
MarcZX10 commented 2026-11-25 05:35:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T05:35:54Z.

Review: APPROVED


Reviewed — looks good

The stream reconfiguration is guarded for streams without reconfigure, and the test checks both streams receive UTF-8 with backslashreplace.

What I ran

Reviewed head 6da812a2346a2277605388fdc3cd174d1ae00c0a. No test command or merged-preview check was run.

Results

Check Result Note
Changed code review passed Both changed files read
Automated tests not run No command run
Merged-preview check not run Not performed

Findings

Blocking

None.

Non-blocking

None.

Not verified

Runtime behavior on Windows consoles and the author-reported unit test were not independently verified. Both files listed as reviewed were read: tools/progress_history.py and tools/tests/test_progress_history.py. No files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6052364552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10218#pullrequestreview-6052364552). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T05:35:54Z. **Review:** APPROVED --- # Reviewed — looks good The stream reconfiguration is guarded for streams without `reconfigure`, and the test checks both streams receive UTF-8 with `backslashreplace`. ## What I ran Reviewed head `6da812a2346a2277605388fdc3cd174d1ae00c0a`. No test command or merged-preview check was run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Both changed files read | | Automated tests | not run | No command run | | Merged-preview check | not run | Not performed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Runtime behavior on Windows consoles and the author-reported unit test were not independently verified. Both files listed as reviewed were read: `tools/progress_history.py` and `tools/tests/test_progress_history.py`. No files were excluded. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 11:21:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T11:21:15Z.

Review: COMMENTED


Ran the submitted progress-history suite on Linux. All 10 tests passed. The added case checks that the command configures its output streams with backslashreplace.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6168739447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10218#pullrequestreview-6168739447). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T11:21:15Z. **Review:** COMMENTED --- Ran the submitted progress-history suite on Linux. All 10 tests passed. The added case checks that the command configures its output streams with `backslashreplace`. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/10218:upstream-pr/10218'
git switch 'upstream-pr/10218'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/10218'
git switch 'upstream-pr/10218'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/10218'
git switch 'upstream-pr/10218'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/10218'
git switch 'main'
git merge --squash 'upstream-pr/10218'
git switch 'main'
git merge --ff-only 'upstream-pr/10218'
git switch 'main'
git merge 'upstream-pr/10218'
git push origin 'main'
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!10218
No description provided.