Skip to content

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

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
rooklz:fix/suggest-patches-symlink-loop
Nov 2, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
rooklz:fix/suggest-patches-symlink-loop

Conversation

@rooklz

@rooklz rooklz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

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 3a40945
  • 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

@MarcZX10

Copy link
Copy Markdown
Contributor

I fetched the current PR head (800599a8465b) and ran python3 tools/tests/test_suggest_patches.py with Linux Python 3.11.2: 36 tests passed, including the catalog and module-parent symlink-loop cases. This verifies the focused Python suite on the submitted head; I have not run the full relinker/build matrix. Hosted Ubuntu/Windows/macOS relinker and conventions checks are still pending at this point.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 THEMANnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 12787 tools/suggest_patches.py L221-222

@rooklz

rooklz commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

windows-latest patch_advisor_unit failure (run 40897440132): Windows already handled the loop without a traceback. Path.resolve() raises [WinError 1921] The name of the file cannot be resolved by the system, and the tool exits 2. The new tests' regex only matched POSIX wording, though. 0f76911 labels ELOOP and winerror 1921 as "Symlink loop from ..." with the OS text kept, and adds a mocked-resolve row covering winerror 1921 (fails on 601c0dc) and an ENOENT control that must not say loop (fails if every OSError gets the loop label). macOS arm64: test_suggest_patches 38 OK on py3.12/3.13; relinker-only ctest 494/494; check_conventions + diff --check clean.

@rooklz
rooklz force-pushed the fix/suggest-patches-symlink-loop branch 2 times, most recently from 7e3c2a5 to 42ea885 Compare October 29, 2026 22:44
@rooklz
rooklz force-pushed the fix/suggest-patches-symlink-loop branch 4 times, most recently from 4c11f31 to e8bb5b4 Compare October 30, 2026 02:16

@malekaifa malekaifa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact current head e8bb5b4. 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.

@rooklz
rooklz force-pushed the fix/suggest-patches-symlink-loop branch 4 times, most recently from a8e4680 to 55868bc Compare October 30, 2026 11:26

@malekaifa malekaifa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked exact current head 55868bc. 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.

@rooklz
rooklz force-pushed the fix/suggest-patches-symlink-loop branch 2 times, most recently from 166229d to bb66f41 Compare October 30, 2026 15:55
@rooklz
rooklz force-pushed the fix/suggest-patches-symlink-loop branch from bb66f41 to d8081ef Compare October 30, 2026 16:51
@oneandonlydean
oneandonlydean merged commit 131b868 into boykopovar:main Nov 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants