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

Closed
Laronza wants to merge 1 commit from upstream-pr/6531 into main
Laronza commented 2026-10-15 19:03:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Laronza on 2026-10-15T19:03:06Z.


What

  • Ensure tools/pad_input.py writes controller commands using explicit encoding="utf-8" and newline="\n" on temporary file creation, guaranteeing uniform LF line endings and UTF-8 encoding across Windows and POSIX hosts.
  • Validate that the specified command file path is not a directory and that its parent directory exists, reporting a clean CLI error instead of crashing with a Python traceback.
  • Add unit tests covering LF line ending retention, missing parent directory validation, and directory target rejection.

Tested

  • Windows 11:
    • python -m unittest tools.tests.test_pad_input (13 passed, 0 failed).
    • python -m unittest discover tools/tests (498 passed, 0 failed).
    • ctest --test-dir build-relinker -R pad_input --output-on-failure (1/1 passed).
    • python tools/check_conventions.py --base origin/main (passed with 0 findings).

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4878418252 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6531). Originally posted by [Laronza](https://github.com/Laronza) on 2026-10-15T19:03:06Z. --- ### What - Ensure `tools/pad_input.py` writes controller commands using explicit `encoding="utf-8"` and `newline="\n"` on temporary file creation, guaranteeing uniform LF line endings and UTF-8 encoding across Windows and POSIX hosts. - Validate that the specified command file path is not a directory and that its parent directory exists, reporting a clean CLI error instead of crashing with a Python traceback. - Add unit tests covering LF line ending retention, missing parent directory validation, and directory target rejection. ### Tested - Windows 11: - `python -m unittest tools.tests.test_pad_input` (13 passed, 0 failed). - `python -m unittest discover tools/tests` (498 passed, 0 failed). - `ctest --test-dir build-relinker -R pad_input --output-on-failure` (1/1 passed). - `python tools/check_conventions.py --base origin/main` (passed with 0 findings). ### 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] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
adriadam10 commented 2026-10-19 03:49:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T03:49:18Z.

Review: CHANGES_REQUESTED


Thanks, the directory / missing-parent errors and the explicit newline="\n" look right. One thing to change:

  • tools/pad_input.py:24: the new except (FileNotFoundError, IsADirectoryError, PermissionError) is out of scope and not tested. IsADirectoryError can't happen any more (main() rejects directories first). PermissionError now silently resets the sequence for an unreadable command file and then overwrites it, where before it failed loudly. Please revert this line to except FileNotFoundError:, or keep PermissionError only with a test and a note in the PR body on why it is wanted.

Minor: test_output_has_consistent_lf_newlines_and_utf8 also passes on main on Linux (text mode already writes \n there), so it only guards Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5566689340 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6531#pullrequestreview-5566689340). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T03:49:18Z. **Review:** CHANGES_REQUESTED --- Thanks, the directory / missing-parent errors and the explicit `newline="\n"` look right. One thing to change: - `tools/pad_input.py:24`: the new `except (FileNotFoundError, IsADirectoryError, PermissionError)` is out of scope and not tested. `IsADirectoryError` can't happen any more (`main()` rejects directories first). `PermissionError` now silently resets the sequence for an unreadable command file and then overwrites it, where before it failed loudly. Please revert this line to `except FileNotFoundError:`, or keep `PermissionError` only with a test and a note in the PR body on why it is wanted. Minor: `test_output_has_consistent_lf_newlines_and_utf8` also passes on `main` on Linux (text mode already writes `\n` there), so it only guards Windows.
THEMANnt commented 2026-10-24 12:27:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-24T12:27:37Z.

Review: CHANGES_REQUESTED


Reviewed head be8b84b43caba2a3257ed99ec9445e2aab08d0fb against pinned base 44df21632125dbe3113a19173e7ebb879da53003, including the local candidate amendments. main() now rejects directory targets and missing parents through CLI errors and writes explicit UTF-8/LF output. newline="\n" correctly preserves LF. The candidate also restores propagation of unreadable-file errors from previous_sequence(), addressing the pristine PR's sequence-reset risk. Existing clock-reset, malformed-command, stick-schema, and exhaustion assertions remain intact.

Changes are required in the candidate's added POSIX test at tools/tests/test_pad_input.py:133. After expecting PermissionError, it reads the file while its mode remains 000; restoring permissions through cleanup happens too late. An unprivileged run therefore errors despite correct production behavior, while a privileged writer can bypass the expected denial. Restore readability before verifying contents and account for privileged execution.

The controller executed tools/tests/test_pad_input.py on Windows AMD64 with Python 3.11.9: baseline reported 10 tests with 2 skipped, pristine PR 13 with 2 skipped, and candidate 14 with 3 skipped. Candidate tests against baseline code produced the required old-code LF assertion failure plus two path-validation errors. The unreadable-file test was skipped, so this control provides no execution evidence for that case. Local whitespace and conventions checks succeeded.

GitHub-reported effective eligibility, conventions, and intake checks succeeded; relinker, windows, linux, register-context, and write-watch were skipped. The earlier cancelled conventions run was superseded by the successful same-workflow execution. These results do not establish passing product builds. Broader discovery and CTest results remain author-reported; no game or GPU validation is established.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638234107 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6531#pullrequestreview-5638234107). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-24T12:27:37Z. **Review:** CHANGES_REQUESTED --- Reviewed head `be8b84b43caba2a3257ed99ec9445e2aab08d0fb` against pinned base `44df21632125dbe3113a19173e7ebb879da53003`, including the local candidate amendments. `main()` now rejects directory targets and missing parents through CLI errors and writes explicit UTF-8/LF output. `newline="\n"` correctly preserves LF. The candidate also restores propagation of unreadable-file errors from `previous_sequence()`, addressing the pristine PR's sequence-reset risk. Existing clock-reset, malformed-command, stick-schema, and exhaustion assertions remain intact. Changes are required in the candidate's added POSIX test at `tools/tests/test_pad_input.py:133`. After expecting `PermissionError`, it reads the file while its mode remains `000`; restoring permissions through cleanup happens too late. An unprivileged run therefore errors despite correct production behavior, while a privileged writer can bypass the expected denial. Restore readability before verifying contents and account for privileged execution. The controller executed `tools/tests/test_pad_input.py` on Windows AMD64 with Python 3.11.9: baseline reported 10 tests with 2 skipped, pristine PR 13 with 2 skipped, and candidate 14 with 3 skipped. Candidate tests against baseline code produced the required old-code LF assertion failure plus two path-validation errors. The unreadable-file test was skipped, so this control provides no execution evidence for that case. Local whitespace and conventions checks succeeded. GitHub-reported effective `eligibility`, `conventions`, and `intake` checks succeeded; `relinker`, `windows`, `linux`, `register-context`, and `write-watch` were skipped. The earlier cancelled conventions run was superseded by the successful same-workflow execution. These results do not establish passing product builds. Broader discovery and CTest results remain author-reported; no game or GPU validation is established. <!-- qwen-review-desk:59a92345e98138b79c04dfa8d3c79f86bf62d357116876f16522e9f6b02d4b8f -->
THEMANnt commented 2026-10-25 23:09:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-25T23:09:31Z.

Review: CHANGES_REQUESTED


Re-reviewed be8b84b43caba2a3257ed99ec9445e2aab08d0fb. Changes requested for a reproduced regression in the submitted production code.

Correction to my earlier review: the POSIX test criticized there existed only in the reviewer's local candidate, not in this PR. That test is not a valid author-facing finding, and I retract that part of the feedback. The candidate's production fix also was not part of the submitted PR.

tools/pad_input.py:23 — Preserve read errors instead of resetting an existing command's sequence

The submitted change catches PermissionError in previous_sequence and returns zero. If an existing command cannot be read but its directory permits replacement, main can then overwrite it using the current clock value rather than advancing the existing sequence. After a clock reset this goes backwards, so a consumer that already observed the old sequence can ignore the newly queued pulse. Abort and preserve the command when reading fails; only an absent command should take the missing-file path.

Validation: A controlled read-denial reproduction executes the exact current main with an existing 1000 16384 300 command and clock value 100. Current head silently replaces it with 100 16384 300; the original baseline propagates PermissionError and retains the original bytes. This uses a mocked read denial on Windows, not a real POSIX chmod test. The exact submitted suite also passes 11 tests with 2 POSIX skips (13 total), demonstrating that its present coverage misses this case.

Scope: The reproduction tests the actual submitted code, with no production edits or candidate tests attributed to the author. Add coverage that rejects unreadable existing commands and verifies they remain unchanged. No game/runtime execution was performed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645816589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6531#pullrequestreview-5645816589). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-25T23:09:31Z. **Review:** CHANGES_REQUESTED --- Re-reviewed `be8b84b43caba2a3257ed99ec9445e2aab08d0fb`. Changes requested for a reproduced regression in the submitted production code. **Correction to my earlier review:** the POSIX test criticized there existed only in the reviewer's local candidate, not in this PR. That test is not a valid author-facing finding, and I retract that part of the feedback. The candidate's production fix also was not part of the submitted PR. **`tools/pad_input.py:23` — Preserve read errors instead of resetting an existing command's sequence** The submitted change catches PermissionError in previous_sequence and returns zero. If an existing command cannot be read but its directory permits replacement, main can then overwrite it using the current clock value rather than advancing the existing sequence. After a clock reset this goes backwards, so a consumer that already observed the old sequence can ignore the newly queued pulse. Abort and preserve the command when reading fails; only an absent command should take the missing-file path. **Validation:** A controlled read-denial reproduction executes the exact current main with an existing `1000 16384 300` command and clock value 100. Current head silently replaces it with `100 16384 300`; the original baseline propagates PermissionError and retains the original bytes. This uses a mocked read denial on Windows, not a real POSIX chmod test. The exact submitted suite also passes 11 tests with 2 POSIX skips (13 total), demonstrating that its present coverage misses this case. **Scope:** The reproduction tests the actual submitted code, with no production edits or candidate tests attributed to the author. Add coverage that rejects unreadable existing commands and verifies they remain unchanged. No game/runtime execution was performed.

Pull request closed

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!6531
No description provided.