fix(tools): report symlink-looping suggest_patches directories as usage errors #12340

Merged
rooklz merged 2 commits from upstream-pr/12340 into main 2026-11-02 13:37:15 +00:00
rooklz commented 2026-10-28 10:16:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T10:16:57Z.


What

suggest_patches printed a traceback when --catalog or --sce-module-path (or the input's parent directory) was a symbolic link loop (ln -s loop loop). It does not give its usage error in that case.

Both directories go through Path.resolve() in main. On Python 3.11–3.12 (the tool needs tomllib, so 3.11 is the minimum), that raises RuntimeError("Symlink loop ..."). The handler is except (OSError, ValueError, ...), so the error goes uncaught and the exit code is 1. On 3.13+ resolve() doesn't raise, and the run ends with the existing Patch advisor: error, exit 2.

Both directories now use os.path.realpath, which doesn't raise for a loop on any version. The catalog directory is resolved once and reused by load_catalog and validate_entry, so behaviour is unchanged for normal paths. A looping catalog now reaches confined(), which already turns the loop into invalid relative path: 'index.json': Symlink loop .... A looping module parent hits the existing module parent must be a directory check. Both exit 2 before the relinker runs, the same as on 3.13+.

Tested

macOS arm64. New test_directory_symlink_loop_is_a_usage_error puts the loop at --catalog and at --sce-module-path. For each it checks exit 2, a Patch advisor: message and that the relinker was never run.

  • main source, 3.12: both subtests ERROR (RuntimeError: Symlink loop)
  • main source, 3.13: OK (resolve() doesn't raise there)
  • this branch: test_suggest_patches 36 OK on 3.12, 3.13, 3.14 and 3.15
  • CLI probe on 3.12: main traceback, exit 1 → branch exit 2 for both options. A normal catalog still gives no catalog entry, exit 1
  • relinker-only build, ctest 378/378 on main 3a40945e62
  • check_conventions --base upstream/main and pr_overlap clean

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:5048796090 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12340). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T10:16:57Z. --- ### What `suggest_patches` printed a traceback when `--catalog` or `--sce-module-path` (or the input's parent directory) was a symbolic link loop (`ln -s loop loop`). It does not give its usage error in that case. Both directories go through `Path.resolve()` in `main`. On Python 3.11–3.12 (the tool needs `tomllib`, so 3.11 is the minimum), that raises `RuntimeError("Symlink loop ...")`. The handler is `except (OSError, ValueError, ...)`, so the error goes uncaught and the exit code is 1. On 3.13+ `resolve()` doesn't raise, and the run ends with the existing `Patch advisor:` error, exit 2. Both directories now use `os.path.realpath`, which doesn't raise for a loop on any version. The catalog directory is resolved once and reused by `load_catalog` and `validate_entry`, so behaviour is unchanged for normal paths. A looping catalog now reaches `confined()`, which already turns the loop into `invalid relative path: 'index.json': Symlink loop ...`. A looping module parent hits the existing `module parent must be a directory` check. Both exit 2 before the relinker runs, the same as on 3.13+. ### Tested macOS arm64. New `test_directory_symlink_loop_is_a_usage_error` puts the loop at `--catalog` and at `--sce-module-path`. For each it checks exit 2, a `Patch advisor:` message and that the relinker was never run. - main source, 3.12: both subtests ERROR (`RuntimeError: Symlink loop`) - main source, 3.13: OK (`resolve()` doesn't raise there) - this branch: `test_suggest_patches` 36 OK on 3.12, 3.13, 3.14 and 3.15 - CLI probe on 3.12: main traceback, exit 1 → branch exit 2 for both options. A normal catalog still gives `no catalog entry`, exit 1 - relinker-only build, `ctest` 378/378 on main 3a40945e62 - `check_conventions --base upstream/main` and `pr_overlap` clean ### 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
MarcZX10 commented 2026-10-28 10:52:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T10:52:07Z.

Review: APPROVED


Reviewed the path normalization change and the symlink-loop regression. The exact-head focused suite passed 36 tests locally; the loop case is checked for both --catalog and --sce-module-path and confirms the relinker is not invoked. Hosted Ubuntu and Windows relinker checks pass. macOS relinker jobs are still pending, so no macOS run is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681458154 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12340#pullrequestreview-5681458154). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T10:52:07Z. **Review:** APPROVED --- Reviewed the path normalization change and the symlink-loop regression. The exact-head focused suite passed 36 tests locally; the loop case is checked for both `--catalog` and `--sce-module-path` and confirms the relinker is not invoked. Hosted Ubuntu and Windows relinker checks pass. macOS relinker jobs are still pending, so no macOS run is claimed.
THEMANnt commented 2026-10-28 11:53:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T11:53:06Z.

Review: APPROVED


Reviewed 800599a8465b207ba175203f9ab24f8143436d6a — approve. Patch-advisor catalog/module directory loops are converted into usage errors rather than escaping through Path.resolve. The resolved catalog path is reused for validation.

Windows/Python 3.11: head test_suggest_patches.py: 33 passed, 3 skipped (36 total); base test_suggest_patches.py: 33 passed, 2 skipped (35 total). The independent real-junction fixture returns exit 2 without a traceback on head and exit 1 with a traceback on base. Neither the metadata nor the existing independent output is modified. No title conversion or patch applicability is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5682152652 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12340#pullrequestreview-5682152652). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T11:53:06Z. **Review:** APPROVED --- Reviewed `800599a8465b207ba175203f9ab24f8143436d6a` — approve. Patch-advisor catalog/module directory loops are converted into usage errors rather than escaping through Path.resolve. The resolved catalog path is reused for validation. Windows/Python 3.11: head test_suggest_patches.py: 33 passed, 3 skipped (36 total); base test_suggest_patches.py: 33 passed, 2 skipped (35 total). The independent real-junction fixture returns exit 2 without a traceback on head and exit 1 with a traceback on base. Neither the metadata nor the existing independent output is modified. No title conversion or patch applicability is claimed.
malekaifa commented 2026-10-30 10:16:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-30T10:16:54Z.

Review: APPROVED


Reviewed exact current head e8bb5b47ccf315591d97aa48582bc740ef083efc. tools/tests/test_suggest_patches.py passes 38 tests on Windows Python 3.12 with 4 expected filesystem/symlink skips and 38/38 on WSL Python 3.12. Current-main merge-tree is clean and git diff --check is clean; the hosted Build is fully green across Ubuntu/Windows/macOS relinker, ASan and eligibility. I also verified that this head's two touched blobs are byte-identical to the #12340 snapshot already integrated and tested in #12769's proposed prerequisite stack, so approving this live head does not introduce a divergence from that integration. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5710870570 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12340#pullrequestreview-5710870570). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-10-30T10:16:54Z. **Review:** APPROVED --- Reviewed exact current head e8bb5b47ccf315591d97aa48582bc740ef083efc. tools/tests/test_suggest_patches.py passes 38 tests on Windows Python 3.12 with 4 expected filesystem/symlink skips and 38/38 on WSL Python 3.12. Current-main merge-tree is clean and git diff --check is clean; the hosted Build is fully green across Ubuntu/Windows/macOS relinker, ASan and eligibility. I also verified that this head's two touched blobs are byte-identical to the #12340 snapshot already integrated and tested in #12769's proposed prerequisite stack, so approving this live head does not introduce a divergence from that integration. No blocking issue found.
malekaifa commented 2026-10-30 11:29:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by malekaifa on 2026-10-30T11:29:57Z.

Review: APPROVED


Re-checked exact current head 55868bca499c14fcf2a3aa3a607785d4fba4b183. The two touched blobs are byte-identical to the exact head I previously tested and approved (suggest_patches.py dc4f9cf41b; test_suggest_patches.py 20bdd49e9c). Current-main merge-tree is clean and git diff --check passes. The refreshed hosted run has eligibility green and the platform relinker jobs queued; no implementation/test change was introduced by this rebase. My prior Windows/WSL exact-behavior validation still applies. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5711585447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12340#pullrequestreview-5711585447). Originally posted by [malekaifa](https://github.com/malekaifa) on 2026-10-30T11:29:57Z. **Review:** APPROVED --- Re-checked exact current head 55868bca499c14fcf2a3aa3a607785d4fba4b183. The two touched blobs are byte-identical to the exact head I previously tested and approved (suggest_patches.py dc4f9cf41b631d897b27e5dafaf2bbd36ba2290c; test_suggest_patches.py 20bdd49e9c0b477ec4f4f6a29887824c305766be). Current-main merge-tree is clean and git diff --check passes. The refreshed hosted run has eligibility green and the platform relinker jobs queued; no implementation/test change was introduced by this rebase. My prior Windows/WSL exact-behavior validation still applies. No blocking issue found.
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!12340
No description provided.