fix(tools): refuse a progress output set whose reports are the same file #12301

Merged
MarcZX10 merged 2 commits from upstream-pr/12301 into main 2026-10-28 12:31:54 +00:00
MarcZX10 commented 2026-10-28 08:28:05 +00:00 (Migrated from github.com)

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


What

tools/progress.py::write_site writes progress.json, the two badges, progress.svg and progress.html one after another. When two of those names already refer to the same file (a hardlink, for example), the later write replaces the earlier report through the alias: progress.json ends up holding the HTML page. The existing reports are now compared with samefile before anything is written, and the run fails naming the two aliased files and leaving every report unchanged (main reports it with parser.error, exit 2, no traceback).

tools/progress_history.py has the same problem and is covered by #12195, so this PR touches only progress.py. The existing progress_history --cache guard is not involved.

Two commits: the fix, then the test (test_aliased_reports_are_refused_and_left_unchanged, real hardlinks: exit 2, both names in the message, no traceback, and all five reports keep their bytes).

Fixes #12055 for the progress.py half.

Tested

python3 -m unittest test_progress in tools/tests: 46 tests pass. The new test fails (error) against main's tools/progress.py. tools/check_conventions.py --base upstream/main and git diff --check pass. Linux only; the test skips where hard links are unavailable.

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: #12055 (the progress.py half; progress_history.py is #12195)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5047474313 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12301). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T08:28:05Z. --- ### What `tools/progress.py::write_site` writes `progress.json`, the two badges, `progress.svg` and `progress.html` one after another. When two of those names already refer to the same file (a hardlink, for example), the later write replaces the earlier report through the alias: `progress.json` ends up holding the HTML page. The existing reports are now compared with `samefile` before anything is written, and the run fails naming the two aliased files and leaving every report unchanged (`main` reports it with `parser.error`, exit 2, no traceback). `tools/progress_history.py` has the same problem and is covered by #12195, so this PR touches only `progress.py`. The existing `progress_history --cache` guard is not involved. Two commits: the fix, then the test (`test_aliased_reports_are_refused_and_left_unchanged`, real hardlinks: exit 2, both names in the message, no traceback, and all five reports keep their bytes). Fixes #12055 for the `progress.py` half. ### Tested `python3 -m unittest test_progress` in `tools/tests`: 46 tests pass. The new test fails (error) against `main`'s `tools/progress.py`. `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. Linux only; the test skips where hard links are unavailable. ### 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: #12055 (the `progress.py` half; `progress_history.py` is #12195) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
rooklz commented 2026-10-28 11:18:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T11:18:10Z.

Review: COMMENTED


Reviewed head 8076937960 on macOS (APFS), merged onto current main 3a40945e62 (merge-tree clean). check_conventions --base upstream/main passes.

1. The new test errors on Python 3.9, the documented floor (docs/dev/BUILD.md: "Python 3.9 or newer enables the Python regression tests"). Path.hardlink_to was added in 3.10:

$ /usr/bin/python3 --version     # 3.9.6
$ python3 -m unittest test_progress
ERROR: test_aliased_reports_are_refused_and_left_unchanged
AttributeError: 'PosixPath' object has no attribute 'hardlink_to'
Ran 46 tests  FAILED (errors=1)

The rest of tools/tests uses os.link(source, link) (test_pad_timeline, test_stubgen, test_import_audit, test_configure_seed and others). CI didn't catch this because ctest runs a newer interpreter.

2. Two links to one missing target still alias. exists() follows symlinks, so a pair of dangling symlinks to the same name gets skipped by both checks:

site/progress.json -> shared   (shared does not exist)
site/progress.html -> shared
$ progress.py site   -> rc 0, site/shared now holds the HTML page; the JSON report is lost

That is the clobber described in #12055, through a symlink instead of a hardlink. Comparing os.path.realpath targets as well as samefile catches it. A loop (progress.json -> progress.json) still reaches the existing OSError path unchanged.

3. Test strength. On head these mutants of require_distinct_reports pass all 46 tests: if not path.exists(): continue → if False:, and paths[index + 1:] → paths[index + 2:]. The fixture's only pair is json/html (not adjacent) and all five files exist. A test with an adjacent pair and the other reports missing kills both. With the diff below, the realpath arm's index + 2 mutant and the other.exists() drop survive. Both are redundant with the samefile arm for the shapes tested, so I'd call them equivalent.

Suggested diff (48 tests in the module: 46 + 2 new), green on 3.9.6 / 3.13 / 3.14, and on the merge with main on 3.9.6 and 3.13. On main's progress.py the new missing-target test fails. With the realpath arm reverted to str(path), the missing-target test fails:

diff --git a/tools/progress.py b/tools/progress.py
index b2acd14921..69ee1145b3 100644
--- a/tools/progress.py
+++ b/tools/progress.py
@@ -514,6 +514,11 @@ def require_distinct_reports(output):
         for other in paths[index + 1:]:
             if other.exists() and path.samefile(other):
                 raise ValueError(f"{path.name} and {other.name} in {output} are the same file")
+    targets = [os.path.normcase(os.path.realpath(path)) for path in paths]
+    for index, target in enumerate(targets):
+        for other in range(index + 1, len(targets)):
+            if targets[other] == target:
+                raise ValueError(f"{paths[index].name} and {paths[other].name} in {output} are the same file")
 
 
 def write_site(output, libraries, shaders):
diff --git a/tools/tests/test_progress.py b/tools/tests/test_progress.py
index 96bcc273c6..75872daecd 100644
--- a/tools/tests/test_progress.py
+++ b/tools/tests/test_progress.py
@@ -1,5 +1,6 @@
 import io
 import json
+import os
 import sys
 import tempfile
 import unittest
@@ -685,7 +686,7 @@ class ProgressTests(unittest.TestCase):
             first, second = output / "progress.json", output / "progress.html"
             first.write_text("json report", encoding="utf-8")
             try:
-                second.hardlink_to(first)
+                os.link(first, second)
             except OSError:
                 self.skipTest("hard links are not available")
             others = {name: output / name for name in ("badge-libraries.svg", "badge-shaders.svg", "progress.svg")}
@@ -702,6 +703,42 @@ class ProgressTests(unittest.TestCase):
             for name, path in others.items():
                 self.assertEqual(path.read_text(encoding="utf-8"), name)
 
+    def test_adjacent_aliased_reports_are_refused_when_others_are_missing(self):
+        libraries, shaders = self.library_snapshot()
+        with tempfile.TemporaryDirectory() as directory:
+            output = Path(directory) / "site"
+            output.mkdir()
+            first, second = output / "badge-libraries.svg", output / "badge-shaders.svg"
+            first.write_text("badge", encoding="utf-8")
+            try:
+                os.link(first, second)
+            except OSError:
+                self.skipTest("hard links are not available")
+            stderr = io.StringIO()
+            with patch("sys.stderr", stderr), self.assertRaises(SystemExit) as raised:
+                self.run_main([str(output)], libraries, shaders)
+            self.assertEqual(raised.exception.code, 2)
+            self.assertIn("badge-libraries.svg and badge-shaders.svg", stderr.getvalue())
+            self.assertEqual(first.read_text(encoding="utf-8"), "badge")
+            self.assertFalse((output / "progress.json").exists())
+
+    def test_reports_linked_to_one_missing_target_are_refused(self):
+        libraries, shaders = self.library_snapshot()
+        with tempfile.TemporaryDirectory() as directory:
+            output = Path(directory) / "site"
+            output.mkdir()
+            try:
+                os.symlink("shared", output / "progress.json")
+                os.symlink("shared", output / "progress.html")
+            except OSError:
+                self.skipTest("symbolic links are not available")
+            stderr = io.StringIO()
+            with patch("sys.stderr", stderr), self.assertRaises(SystemExit) as raised:
+                self.run_main([str(output)], libraries, shaders)
+            self.assertEqual(raised.exception.code, 2)
+            self.assertIn("progress.json and progress.html", stderr.getvalue())
+            self.assertFalse((output / "shared").exists())
+
     def test_root_must_be_a_source_tree(self):
         with tempfile.TemporaryDirectory() as directory:
             empty = Path(directory) / "empty tree"

Everything else looks right. The guard runs before the first write, ValueError is mapped to parser.error before the OSError arm, and the original test checks all five reports keep their bytes.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681763860 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12301#pullrequestreview-5681763860). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T11:18:10Z. **Review:** COMMENTED --- Reviewed head 8076937960 on macOS (APFS), merged onto current `main` 3a40945e62 (merge-tree clean). `check_conventions --base upstream/main` passes. **1. The new test errors on Python 3.9, the documented floor** (`docs/dev/BUILD.md`: "Python 3.9 or newer enables the Python regression tests"). `Path.hardlink_to` was added in 3.10: ``` $ /usr/bin/python3 --version # 3.9.6 $ python3 -m unittest test_progress ERROR: test_aliased_reports_are_refused_and_left_unchanged AttributeError: 'PosixPath' object has no attribute 'hardlink_to' Ran 46 tests FAILED (errors=1) ``` The rest of `tools/tests` uses `os.link(source, link)` (test_pad_timeline, test_stubgen, test_import_audit, test_configure_seed and others). CI didn't catch this because ctest runs a newer interpreter. **2. Two links to one missing target still alias.** `exists()` follows symlinks, so a pair of dangling symlinks to the same name gets skipped by both checks: ``` site/progress.json -> shared (shared does not exist) site/progress.html -> shared $ progress.py site -> rc 0, site/shared now holds the HTML page; the JSON report is lost ``` That is the clobber described in #12055, through a symlink instead of a hardlink. Comparing `os.path.realpath` targets as well as `samefile` catches it. A loop (`progress.json -> progress.json`) still reaches the existing OSError path unchanged. **3. Test strength.** On head these mutants of `require_distinct_reports` pass all 46 tests: `if not path.exists(): continue` → `if False:`, and `paths[index + 1:]` → `paths[index + 2:]`. The fixture's only pair is json/html (not adjacent) and all five files exist. A test with an adjacent pair and the other reports missing kills both. With the diff below, the realpath arm's `index + 2` mutant and the `other.exists()` drop survive. Both are redundant with the samefile arm for the shapes tested, so I'd call them equivalent. Suggested diff (48 tests in the module: 46 + 2 new), green on 3.9.6 / 3.13 / 3.14, and on the merge with `main` on 3.9.6 and 3.13. On `main`'s `progress.py` the new missing-target test fails. With the realpath arm reverted to `str(path)`, the missing-target test fails: ```diff diff --git a/tools/progress.py b/tools/progress.py index b2acd14921..69ee1145b3 100644 --- a/tools/progress.py +++ b/tools/progress.py @@ -514,6 +514,11 @@ def require_distinct_reports(output): for other in paths[index + 1:]: if other.exists() and path.samefile(other): raise ValueError(f"{path.name} and {other.name} in {output} are the same file") + targets = [os.path.normcase(os.path.realpath(path)) for path in paths] + for index, target in enumerate(targets): + for other in range(index + 1, len(targets)): + if targets[other] == target: + raise ValueError(f"{paths[index].name} and {paths[other].name} in {output} are the same file") def write_site(output, libraries, shaders): diff --git a/tools/tests/test_progress.py b/tools/tests/test_progress.py index 96bcc273c6..75872daecd 100644 --- a/tools/tests/test_progress.py +++ b/tools/tests/test_progress.py @@ -1,5 +1,6 @@ import io import json +import os import sys import tempfile import unittest @@ -685,7 +686,7 @@ class ProgressTests(unittest.TestCase): first, second = output / "progress.json", output / "progress.html" first.write_text("json report", encoding="utf-8") try: - second.hardlink_to(first) + os.link(first, second) except OSError: self.skipTest("hard links are not available") others = {name: output / name for name in ("badge-libraries.svg", "badge-shaders.svg", "progress.svg")} @@ -702,6 +703,42 @@ class ProgressTests(unittest.TestCase): for name, path in others.items(): self.assertEqual(path.read_text(encoding="utf-8"), name) + def test_adjacent_aliased_reports_are_refused_when_others_are_missing(self): + libraries, shaders = self.library_snapshot() + with tempfile.TemporaryDirectory() as directory: + output = Path(directory) / "site" + output.mkdir() + first, second = output / "badge-libraries.svg", output / "badge-shaders.svg" + first.write_text("badge", encoding="utf-8") + try: + os.link(first, second) + except OSError: + self.skipTest("hard links are not available") + stderr = io.StringIO() + with patch("sys.stderr", stderr), self.assertRaises(SystemExit) as raised: + self.run_main([str(output)], libraries, shaders) + self.assertEqual(raised.exception.code, 2) + self.assertIn("badge-libraries.svg and badge-shaders.svg", stderr.getvalue()) + self.assertEqual(first.read_text(encoding="utf-8"), "badge") + self.assertFalse((output / "progress.json").exists()) + + def test_reports_linked_to_one_missing_target_are_refused(self): + libraries, shaders = self.library_snapshot() + with tempfile.TemporaryDirectory() as directory: + output = Path(directory) / "site" + output.mkdir() + try: + os.symlink("shared", output / "progress.json") + os.symlink("shared", output / "progress.html") + except OSError: + self.skipTest("symbolic links are not available") + stderr = io.StringIO() + with patch("sys.stderr", stderr), self.assertRaises(SystemExit) as raised: + self.run_main([str(output)], libraries, shaders) + self.assertEqual(raised.exception.code, 2) + self.assertIn("progress.json and progress.html", stderr.getvalue()) + self.assertFalse((output / "shared").exists()) + def test_root_must_be_a_source_tree(self): with tempfile.TemporaryDirectory() as directory: empty = Path(directory) / "empty tree" ``` Everything else looks right. The guard runs before the first write, `ValueError` is mapped to `parser.error` before the `OSError` arm, and the original test checks all five reports keep their bytes. AI-assisted: yes
THEMANnt commented 2026-10-28 11:28:19 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed 80769379600be119784ba001b4b83e76a69eac3d — approve. All five progress-site outputs are checked for existing file aliases before the first write, preventing hardlinked reports from overwriting each other.

Windows/Python 3.11: head test_progress.py: 46 passed, 0 skipped (46 total); base test_progress.py: 45 passed, 0 skipped (45 total). The CLI hardlink case preserves the reports and emits a usage error on head; the same case fails against old production. The change guards aliases, not general transactional recovery from later filesystem write failures. Full command/output evidence is retained locally. Hosted CI and mergeability are rechecked before publication. No game or full product execution is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681881896 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12301#pullrequestreview-5681881896). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T11:28:19Z. **Review:** APPROVED --- Reviewed `80769379600be119784ba001b4b83e76a69eac3d` — approve. All five progress-site outputs are checked for existing file aliases before the first write, preventing hardlinked reports from overwriting each other. Windows/Python 3.11: head test_progress.py: 46 passed, 0 skipped (46 total); base test_progress.py: 45 passed, 0 skipped (45 total). The CLI hardlink case preserves the reports and emits a usage error on head; the same case fails against old production. The change guards aliases, not general transactional recovery from later filesystem write failures. Full command/output evidence is retained locally. Hosted CI and mergeability are rechecked before publication. No game or full product execution is claimed.
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!12301
No description provided.