fix(tools): normalize pad input output encoding and validate target path #11312

Merged
xXPBSXx merged 2 commits from upstream-pr/11312 into main 2026-10-27 01:07:03 +00:00
xXPBSXx commented 2026-10-26 02:57:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-26T02:57:20Z.


What

Carries #6531 (Laronza, head be8b84b43c; the first commit keeps its authorship), rebased on main. The first commit makes tools/pad_input.py write the command file as UTF-8 with LF line endings on every host and report a directory target or a missing parent directory as a command line error instead of a traceback. In main() its two checks now sit after the button_mask handling from #9079.
The second commit answers the changes requested in the reviews of #6531 (adriadam10, 19 October; THEMANnt, 25 October): previous_sequence catches only FileNotFoundError again, so an unreadable command file fails instead of being overwritten with a restarted sequence, and a test covers that case with a mocked PermissionError that checks the existing command is left unchanged, so it does not depend on file modes (no chmod) and runs the same for a privileged writer. This is the coverage the review of 25 October asks for; that review also withdraws its earlier remark about a POSIX test.
Overlap: #10206 (emirplus) also changes main() and the tests of tools/pad_input.py; the two heads conflict in tools/tests/test_pad_input.py (both add tests at the same place), so whichever lands second rebases and keeps both sets of tests. #10578 (xTRACKGOD) changes the same file and tools/tests/test_pad_timeline.py; it merges with this PR without a conflict. git merge-tree of this head with current main 14eb2cda22 is clean.

Fixes: none

Tested

One base for all arms: main 5b85225ef3, head 10781b738d (these two commits), tree d8a21e955ccac6f8070362603fcdd77117fcd8bb identical on Windows and Linux (on Linux the same two patches applied with git am); no build step (Python only). python -I tools/tests/test_pad_input.py, 18 tests, only pad_input.py swapped between arms, the tests of the head kept:

  • Windows 10 Pro 19045 (Python 3.12.10): head OK (2 skipped, POSIX-only); with pad_input.py of the first commit alone 1 failure (test_unreadable_command_file_is_not_replaced); with pad_input.py of main 2 errors (the directory and missing-parent tests) and 1 failure (the LF test).
  • Linux (WSL2 Ubuntu 24.04: a virtualised kernel, not bare-metal; Python 3.12.3): head OK (1 skipped, the privileged-writer test, which needs root); first commit alone 1 failure (the same test); main 2 errors (directory and missing-parent tests); the LF test passes on Linux with main already, as the review of 19 October notes, so it only guards Windows.
  • The unreadable-file test patches Path.open to raise PermissionError, so it behaves the same for an unprivileged and a privileged run (no chmod 000, which a privileged writer bypasses).
  • tools/check_conventions.py --base upstream/main passes on Windows and Linux.
    Not tested: macOS, a real unreadable file on disk, the CI.

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

Co-authored by the original author of #6531.
AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5011328268 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11312). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-26T02:57:20Z. --- ### What Carries #6531 (Laronza, head `be8b84b43c`; the first commit keeps its authorship), rebased on `main`. The first commit makes `tools/pad_input.py` write the command file as UTF-8 with LF line endings on every host and report a directory target or a missing parent directory as a command line error instead of a traceback. In `main()` its two checks now sit after the `button_mask` handling from #9079. The second commit answers the changes requested in the reviews of #6531 (adriadam10, 19 October; THEMANnt, 25 October): `previous_sequence` catches only `FileNotFoundError` again, so an unreadable command file fails instead of being overwritten with a restarted sequence, and a test covers that case with a mocked `PermissionError` that checks the existing command is left unchanged, so it does not depend on file modes (no `chmod`) and runs the same for a privileged writer. This is the coverage the review of 25 October asks for; that review also withdraws its earlier remark about a POSIX test. Overlap: #10206 (emirplus) also changes `main()` and the tests of `tools/pad_input.py`; the two heads conflict in `tools/tests/test_pad_input.py` (both add tests at the same place), so whichever lands second rebases and keeps both sets of tests. #10578 (xTRACKGOD) changes the same file and `tools/tests/test_pad_timeline.py`; it merges with this PR without a conflict. `git merge-tree` of this head with current `main` `14eb2cda22` is clean. Fixes: none ### Tested One base for all arms: `main` `5b85225ef3`, head `10781b738d` (these two commits), tree `d8a21e955ccac6f8070362603fcdd77117fcd8bb` identical on Windows and Linux (on Linux the same two patches applied with `git am`); no build step (Python only). `python -I tools/tests/test_pad_input.py`, 18 tests, only `pad_input.py` swapped between arms, the tests of the head kept: - Windows 10 Pro 19045 (Python 3.12.10): head OK (2 skipped, POSIX-only); with `pad_input.py` of the first commit alone 1 failure (`test_unreadable_command_file_is_not_replaced`); with `pad_input.py` of `main` 2 errors (the directory and missing-parent tests) and 1 failure (the LF test). - Linux (WSL2 Ubuntu 24.04: a virtualised kernel, not bare-metal; Python 3.12.3): head OK (1 skipped, the privileged-writer test, which needs root); first commit alone 1 failure (the same test); `main` 2 errors (directory and missing-parent tests); the LF test passes on Linux with `main` already, as the review of 19 October notes, so it only guards Windows. - The unreadable-file test patches `Path.open` to raise `PermissionError`, so it behaves the same for an unprivileged and a privileged run (no `chmod 000`, which a privileged writer bypasses). - `tools/check_conventions.py --base upstream/main` passes on Windows and Linux. Not tested: macOS, a real unreadable file on disk, the CI. ### 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 Co-authored by the original author of #6531. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-26 04:35:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T04:35:22Z.

Review: APPROVED


Reviewed the path validation and output handling. The directory/missing-parent checks prevent the reported traceback paths before creating a temp file; explicit UTF-8 plus newline="\n" makes serialization stable on Windows, and the test checks raw bytes. Restoring the narrow FileNotFoundError catch means a read/permission error is no longer mistaken for a missing sequence, preserving the existing command file; the mocked permission failure avoids chmod/root dependence. The stated overlap with #10206 is a same-file test conflict with a clear keep-both resolution, and #10578 was checked as clean. Hosted conventions, eligibility, intake, labels and the Linux/macOS/Windows relinker matrix plus ASan pass; product jobs are skipped by path policy. The author reports 18 focused tests on Windows and WSL Linux; I did not rerun them locally. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5647449332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11312#pullrequestreview-5647449332). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T04:35:22Z. **Review:** APPROVED --- Reviewed the path validation and output handling. The directory/missing-parent checks prevent the reported traceback paths before creating a temp file; explicit UTF-8 plus `newline="\n"` makes serialization stable on Windows, and the test checks raw bytes. Restoring the narrow `FileNotFoundError` catch means a read/permission error is no longer mistaken for a missing sequence, preserving the existing command file; the mocked permission failure avoids chmod/root dependence. The stated overlap with #10206 is a same-file test conflict with a clear keep-both resolution, and #10578 was checked as clean. Hosted conventions, eligibility, intake, labels and the Linux/macOS/Windows relinker matrix plus ASan pass; product jobs are skipped by path policy. The author reports 18 focused tests on Windows and WSL Linux; I did not rerun them locally. No blocking issue found.
THEMANnt commented 2026-10-26 18:45:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T18:45:57Z.

Review: APPROVED


Reviewed 10781b738d7c08b5c91b66eb688d38099832706d. Approve; no actionable finding in this focused review.

The writer rejects directory destinations and missing parents before staging output, and explicitly writes UTF-8 with LF endings. The submitted unreadable-file check also confirms that read denial propagates without replacing an existing command.

Validation: Windows, Python 3.11: 16 passed, 2 skipped; base 12 passed, 2 skipped. Old production fails the newline assertion and errors in the two new path-diagnostic cases. Exact-head hosted Build and Conventions are checked again before submission; skipped product jobs are not counted as native execution.

Scope: The two skips concern POSIX permission/ownership behavior. No controller or title session was run.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5657284405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11312#pullrequestreview-5657284405). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T18:45:57Z. **Review:** APPROVED --- Reviewed `10781b738d7c08b5c91b66eb688d38099832706d`. Approve; no actionable finding in this focused review. The writer rejects directory destinations and missing parents before staging output, and explicitly writes UTF-8 with LF endings. The submitted unreadable-file check also confirms that read denial propagates without replacing an existing command. **Validation:** Windows, Python 3.11: 16 passed, 2 skipped; base 12 passed, 2 skipped. Old production fails the newline assertion and errors in the two new path-diagnostic cases. Exact-head hosted Build and Conventions are checked again before submission; skipped product jobs are not counted as native execution. **Scope:** The two skips concern POSIX permission/ownership behavior. No controller or title session was run.
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!11312
No description provided.