fix(tools): reject aliased report output paths in progress_history #12195

Merged
pushkarreddyy merged 2 commits from upstream-pr/12195 into main 2026-10-28 09:51:34 +00:00
pushkarreddyy commented 2026-10-28 03:06:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-28T03:06:27Z.


What

tools/progress_history.py writes three generated reports (history.json, history.svg, history.html) into the specified output directory. If any of those report paths already reference the same filesystem object (such as hardlinks or symlinks to the same file), writing them in sequence causes subsequent report formats to silently overwrite earlier outputs through the alias.

Before collecting or writing reports:

  • Validate that all generated report paths (history.json, history.svg, history.html) are distinct and do not alias existing files (samefile()) or resolve to identical filesystem paths.
  • If an alias is detected, exit with code 2 and a clean diagnostic before collecting history or modifying any output files, preserving existing file contents untouched.

Tested

  • Ran unit test suite via python -m unittest tools.tests.test_progress_history: all 12 tests passed cleanly.
  • Added test_main_rejects_aliased_output_reports in tools/tests/test_progress_history.py verifying that hardlinked output files are rejected with exit code 2 and leave existing file contents untouched.
  • Ran conventions preflight via python tools/check_conventions.py --base origin/main 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5044528166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12195). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-28T03:06:27Z. --- ### What `tools/progress_history.py` writes three generated reports (`history.json`, `history.svg`, `history.html`) into the specified output directory. If any of those report paths already reference the same filesystem object (such as hardlinks or symlinks to the same file), writing them in sequence causes subsequent report formats to silently overwrite earlier outputs through the alias. Before collecting or writing reports: - Validate that all generated report paths (`history.json`, `history.svg`, `history.html`) are distinct and do not alias existing files (`samefile()`) or resolve to identical filesystem paths. - If an alias is detected, exit with code 2 and a clean diagnostic before collecting history or modifying any output files, preserving existing file contents untouched. ### Tested - Ran unit test suite via `python -m unittest tools.tests.test_progress_history`: all 12 tests passed cleanly. - Added `test_main_rejects_aliased_output_reports` in `tools/tests/test_progress_history.py` verifying that hardlinked output files are rejected with exit code 2 and leave existing file contents untouched. - Ran conventions preflight via `python tools/check_conventions.py --base origin/main` 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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-28 03:10:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T03:10:19Z.

Review: APPROVED


I reviewed the exact head f3a612cd5e962ffbf6273905fe87c33e9e81222e. The output paths are validated before collect() or writes; canonical resolved paths catch symlink/path aliases, and samefile() catches existing hardlinks. The error follows the existing argparse diagnostic path. The regression exercises hardlinked output files and confirms exit code 2 with contents preserved. I ran python3 -m unittest tools.tests.test_progress_history on the PR head (12 tests passed), python3 tools/check_conventions.py --base refs/review/main (passed), and git diff --check refs/review/main...HEAD (clean). Hosted conventions, eligibility, intake, labels, and ASan relinker checks pass. The other relinker jobs are still running; full builds are skipped by workflow filters.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5677314134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12195#pullrequestreview-5677314134). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T03:10:19Z. **Review:** APPROVED --- I reviewed the exact head `f3a612cd5e962ffbf6273905fe87c33e9e81222e`. The output paths are validated before `collect()` or writes; canonical resolved paths catch symlink/path aliases, and `samefile()` catches existing hardlinks. The error follows the existing argparse diagnostic path. The regression exercises hardlinked output files and confirms exit code 2 with contents preserved. I ran `python3 -m unittest tools.tests.test_progress_history` on the PR head (12 tests passed), `python3 tools/check_conventions.py --base refs/review/main` (passed), and `git diff --check refs/review/main...HEAD` (clean). Hosted conventions, eligibility, intake, labels, and ASan relinker checks pass. The other relinker jobs are still running; full builds are skipped by workflow filters.
THEMANnt commented 2026-10-28 04:27:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T04:27:45Z.

Review: APPROVED


Reviewed f3a612cd5e962ffbf6273905fe87c33e9e81222e — approve. Generated history reports must be distinct files before collection and writing starts, including hardlink aliases.

Windows/Python 3.11: head 12 passed (12 total); author base 11 passed (11 total). The current alias-preservation test fails against old production. Existing history-cache separation remains in place. No repository history or existing user report was modified by this review.

The inspected hosted Windows relinker job merged this exact head and completed successfully. This is not a full product or game build.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5677789864 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12195#pullrequestreview-5677789864). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T04:27:45Z. **Review:** APPROVED --- Reviewed `f3a612cd5e962ffbf6273905fe87c33e9e81222e` — approve. Generated history reports must be distinct files before collection and writing starts, including hardlink aliases. Windows/Python 3.11: head 12 passed (12 total); author base 11 passed (11 total). The current alias-preservation test fails against old production. Existing history-cache separation remains in place. No repository history or existing user report was modified by this review. The inspected hosted Windows relinker job merged this exact head and completed successfully. This is not a full product or game build.
rooklz commented 2026-10-28 04:43:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T04:43:35Z.

Review: COMMENTED


Evidence review of f3a612cd5e (merged onto main ee5e24729c, macOS 15 arm64).

What I checked

  • RED/GREEN: putting main's tools/progress_history.py under this PR's tests fails only test_main_rejects_aliased_output_reports. The other 11 pass. The PR head passes 12/12 on 3.9.6 and on 3.13.
  • Gates: check_conventions --base upstream/main is clean. pr_overlap --branch reports no overlap (it merged the 3 PRs that share files with this one). git merge-tree against main is clean. CI: 5 pass / 4 skipping.
  • Real-CLI shape probe (collect patched, CLI run against a real output dir), main vs head:
shape main head (3.13/3.14) head (3.9.6/3.12)
clean dir rc 0 rc 0 rc 0
hardlink json==svg rc 0 (silently overwritten) rc 2 alias rc 2 alias
symlink html->json (existing) rc 0 rc 2 alias rc 2 alias
symlink svg->json (json missing) rc 0 rc 2 alias rc 2 alias
two links to the same outside file rc 0 rc 2 alias rc 2 alias
unrelated dangling symlink rc 0 rc 0 rc 0
self-loop history.json -> history.json rc 2 (ELOOP on write) rc 2 traceback RuntimeError
2-loop json<->svg rc 2 rc 2 traceback RuntimeError

Finding (regression on Python 3.9–3.12, below the 3.9+ floor in docs/dev/BUILD.md): before 3.13, Path.resolve() raises RuntimeError("Symlink loop ..."), not OSError. 3.13 changed this to OSError. On main, a looped output path fails at the write and becomes parser.error (rc 2). On this head, the new path.resolve() == other.resolve() runs first, and the except (OSError, ValueError) doesn't catch the RuntimeError, so the tool tracebacks with rc 1. Ubuntu's default python3 (3.12) is affected.

Minimal fix, probed: except (OSError, RuntimeError, ValueError). With it, 3.9.6 and 3.12 give rc 2 "Symlink loop from ..." for both loop shapes, 3.13/3.14 behave the same as before, and the other shapes don't change. A loop-shape test (os.symlink self-loop, skip on OSError) would kill the regression on 3.9–3.12 runners. Main's --cache resolve check already has the same exposure; this PR now hits it for the output path, which never touched --cache.

Everything else is sound. The pairwise check covers all 3 pairs, and the samefile guard only runs when both paths exist.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5677880090 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12195#pullrequestreview-5677880090). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T04:43:35Z. **Review:** COMMENTED --- Evidence review of f3a612cd5e (merged onto main ee5e24729c, macOS 15 arm64). **What I checked** - RED/GREEN: putting main's `tools/progress_history.py` under this PR's tests fails only `test_main_rejects_aliased_output_reports`. The other 11 pass. The PR head passes 12/12 on 3.9.6 and on 3.13. - Gates: `check_conventions --base upstream/main` is clean. `pr_overlap --branch` reports no overlap (it merged the 3 PRs that share files with this one). `git merge-tree` against main is clean. CI: 5 pass / 4 skipping. - Real-CLI shape probe (`collect` patched, CLI run against a real output dir), main vs head: | shape | main | head (3.13/3.14) | head (3.9.6/3.12) | |---|---|---|---| | clean dir | rc 0 | rc 0 | rc 0 | | hardlink json==svg | rc 0 (silently overwritten) | rc 2 alias | rc 2 alias | | symlink html->json (existing) | rc 0 | rc 2 alias | rc 2 alias | | symlink svg->json (json missing) | rc 0 | rc 2 alias | rc 2 alias | | two links to the same outside file | rc 0 | rc 2 alias | rc 2 alias | | unrelated dangling symlink | rc 0 | rc 0 | rc 0 | | self-loop `history.json -> history.json` | rc 2 (ELOOP on write) | rc 2 | **traceback RuntimeError** | | 2-loop json<->svg | rc 2 | rc 2 | **traceback RuntimeError** | **Finding (regression on Python 3.9–3.12, below the 3.9+ floor in docs/dev/BUILD.md):** before 3.13, `Path.resolve()` raises `RuntimeError("Symlink loop ...")`, not `OSError`. 3.13 changed this to OSError. On main, a looped output path fails at the write and becomes `parser.error` (rc 2). On this head, the new `path.resolve() == other.resolve()` runs first, and the `except (OSError, ValueError)` doesn't catch the RuntimeError, so the tool tracebacks with rc 1. Ubuntu's default python3 (3.12) is affected. Minimal fix, probed: `except (OSError, RuntimeError, ValueError)`. With it, 3.9.6 and 3.12 give `rc 2 "Symlink loop from ..."` for both loop shapes, 3.13/3.14 behave the same as before, and the other shapes don't change. A loop-shape test (os.symlink self-loop, skip on OSError) would kill the regression on 3.9–3.12 runners. Main's `--cache` resolve check already has the same exposure; this PR now hits it for the output path, which never touched `--cache`. Everything else is sound. The pairwise check covers all 3 pairs, and the samefile guard only runs when both paths exist.
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!12195
No description provided.