fix(tools): stage web release manifests before replacement #12488

Closed
StoneDC wants to merge 17 commits from upstream-pr/12488 into main
StoneDC commented 2026-10-28 15:53:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by StoneDC on 2026-10-28T15:53:17Z.


What

Stage release manifests next to their destination and replace them only after successful JSON serialization, preserving existing files on serialization/write failures.

Resolve current-main integration conflicts while keeping the archive metadata stream context-managed and retaining main's release-layout validation and invalid-layout assertions. All current-main methods are preserved; one old test's context-manager nesting is aligned with main without removing its checks. The prior #12446 and #12788 prerequisites have both merged, so the checklist now declares no open prerequisite.

Tested

Exact tested head ae8ca3f7786f5070b8fa91912b536805fcac4258; recorded main 9f748f4d8e36ce3714f3b95f3386316e110a9b22; previous published head 29a0e474d99880c7d6e532272ce5cec66c5cbd95. Recorded main and the previous published head are ancestors. All current-main and previous unique test methods are retained; the documented #12488 context nesting and #12766 identical-shadow cleanup preserve the effective assertions.

Windows 11: Python 3.14.3 and 3.12.14, CMake 4.3.1 / MinGW GCC 15.2. Non-root Ubuntu 26.04 / WSL: Python 3.14.4 and isolated Python 3.12.16, CMake 4.2.3 / GCC 15.2. Linux runs exact source archives on its native filesystem; a temporary Git snapshot supplies the release tests' current-tree revision lookup.

For both interpreters on each OS, configure Ninja Release with BUILD_TESTING=ON and ANYPS5_RELINKER_ONLY=ON, then run ctest --test-dir <build> -R '^(web_library_assets|web_release)$' -V and the CTest skip-policy audit. All four configurations pass.

Registered web_library_assets and web_release: 2 CTest groups / 39 build-web methods + 33 release methods pass per configuration. Windows has one existing permissions skip in build-web; Linux has none. No CTest group skips. Existing atomic-write, malformed metadata, nested JSON, archive-layout and no-partial-publication regressions remain present.

Current-main conventions with this complete description, whitespace, Python 3.9 grammar, AST test-retention and production-script registration checks pass. No timeout was raised. These are interpreter/tool tests, not native product builds. No actual Python 3.9/3.11, local macOS, PS5/title/GPU or live sampler/browser run is claimed. New-head hosted CI starts after publication; old-head approvals/checks are not fresh results for this head.

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:5053488060 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12488). Originally posted by [StoneDC](https://github.com/StoneDC) on 2026-10-28T15:53:17Z. --- ### What Stage release manifests next to their destination and replace them only after successful JSON serialization, preserving existing files on serialization/write failures. Resolve current-main integration conflicts while keeping the archive metadata stream context-managed and retaining main's release-layout validation and invalid-layout assertions. All current-main methods are preserved; one old test's context-manager nesting is aligned with main without removing its checks. The prior #12446 and #12788 prerequisites have both merged, so the checklist now declares no open prerequisite. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Exact tested head `ae8ca3f7786f5070b8fa91912b536805fcac4258`; recorded main `9f748f4d8e36ce3714f3b95f3386316e110a9b22`; previous published head `29a0e474d99880c7d6e532272ce5cec66c5cbd95`. Recorded main and the previous published head are ancestors. All current-main and previous unique test methods are retained; the documented #12488 context nesting and #12766 identical-shadow cleanup preserve the effective assertions. Windows 11: Python 3.14.3 and 3.12.14, CMake 4.3.1 / MinGW GCC 15.2. Non-root Ubuntu 26.04 / WSL: Python 3.14.4 and isolated Python 3.12.16, CMake 4.2.3 / GCC 15.2. Linux runs exact source archives on its native filesystem; a temporary Git snapshot supplies the release tests' current-tree revision lookup. For both interpreters on each OS, configure Ninja Release with BUILD_TESTING=ON and ANYPS5_RELINKER_ONLY=ON, then run `ctest --test-dir <build> -R '^(web_library_assets|web_release)$' -V` and the CTest skip-policy audit. All four configurations pass. Registered `web_library_assets` and `web_release`: 2 CTest groups / 39 build-web methods + 33 release methods pass per configuration. Windows has one existing permissions skip in build-web; Linux has none. No CTest group skips. Existing atomic-write, malformed metadata, nested JSON, archive-layout and no-partial-publication regressions remain present. Current-main conventions with this complete description, whitespace, Python 3.9 grammar, AST test-retention and production-script registration checks pass. No timeout was raised. These are interpreter/tool tests, not native product builds. No actual Python 3.9/3.11, local macOS, PS5/title/GPU or live sampler/browser run is claimed. New-head hosted CI starts after publication; old-head approvals/checks are not fresh results for this head. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-28 15:59:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T15:59:46Z.

Review: COMMENTED


I reviewed head ac3c05ab53ca and ran the focused web release tests from a clean detached worktree on Linux/Python 3.11: relinker-only CMake configure succeeded and web_release plus web_library_assets passed (2/2). tools/check_conventions.py --base upstream/main and tools/check_test_registration.py --scripts also passed. The tests cover interrupted partial writes, failed replacement and retry, permissions, and symlink write-through; the implementation stages beside the resolved target and replaces only after the complete content has been written. The stated per-manifest atomicity and no-crash-durability limits match the implementation. I found no blocking issue in this focused review. I’m not treating the author’s Windows and Linux test report as hosted CI evidence; the hosted checks have their own status in the PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5685711882 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12488#pullrequestreview-5685711882). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T15:59:46Z. **Review:** COMMENTED --- I reviewed head `ac3c05ab53ca` and ran the focused web release tests from a clean detached worktree on Linux/Python 3.11: relinker-only CMake configure succeeded and `web_release` plus `web_library_assets` passed (2/2). `tools/check_conventions.py --base upstream/main` and `tools/check_test_registration.py --scripts` also passed. The tests cover interrupted partial writes, failed replacement and retry, permissions, and symlink write-through; the implementation stages beside the resolved target and replaces only after the complete content has been written. The stated per-manifest atomicity and no-crash-durability limits match the implementation. I found no blocking issue in this focused review. I’m not treating the author’s Windows and Linux test report as hosted CI evidence; the hosted checks have their own status in the PR.
MarcZX10 commented 2026-10-28 16:19:35 +00:00 (Migrated from github.com)

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

Review: COMMENTED


I reviewed the new exact head 8055acbbaa58 and the one-line replacement-test adjustment. The production implementation resolves the destination before Path.replace, so comparing the injected destination against self.manifest.resolve() now matches the actual call and should reach the intended OSError path even when the temporary directory is accessed through an alias.

I independently ran python3 -m unittest tools.tests.test_build_web on Linux/Python 3.11: 19 tests passed, 1 platform-dependent test skipped. python3 tools/check_conventions.py --base upstream/main, python3 tools/check_test_registration.py --scripts (212 scripts), and git diff --check upstream/main...HEAD pass. Hosted relinker and conventions checks for this new head are still pending, so I am not treating them as completed or changing my review to approval yet.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5686005907 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12488#pullrequestreview-5686005907). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T16:19:35Z. **Review:** COMMENTED --- I reviewed the new exact head `8055acbbaa58` and the one-line replacement-test adjustment. The production implementation resolves the destination before `Path.replace`, so comparing the injected destination against `self.manifest.resolve()` now matches the actual call and should reach the intended `OSError` path even when the temporary directory is accessed through an alias. I independently ran `python3 -m unittest tools.tests.test_build_web` on Linux/Python 3.11: 19 tests passed, 1 platform-dependent test skipped. `python3 tools/check_conventions.py --base upstream/main`, `python3 tools/check_test_registration.py --scripts` (212 scripts), and `git diff --check upstream/main...HEAD` pass. Hosted relinker and conventions checks for this new head are still pending, so I am not treating them as completed or changing my review to approval yet.
rooklz commented 2026-10-28 17:52:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T17:52:13Z.

Review: APPROVED


Independent macOS run of exact head ef9d0a4d05 (prior runs here were Linux only).

  • python -m unittest tools.tests.test_build_web: 22 OK on Python 3.13 and 3.14 (Homebrew), and on 3.9.6 (Apple; 1 skip, the existing zipfile Unicode-extra test). check_conventions --base upstream/main and check_test_registration --scripts (212) pass. The branch merges cleanly with current main e4da19aff0. #12446 418cd0d37e is an ancestor, matching Depends on.
  • RED/GREEN: putting back #12446's build_web.py under the new tests makes the 3 manifest tests fail (2F+1E), and the 3 deep-JSON tests still pass because they come from #12446.
  • Mutants of write_manifest: drop resolve() → killed, drop chmod → killed, write in place instead of replace → killed. Two survive:
    1. Removing the read-only PermissionError guard. No test covers it, and without the guard replace() quietly overwrites a 0444 manifest.
    2. TemporaryDirectory(dir=None), i.e. staging outside the destination directory. The tests still pass, but in real use the rename becomes cross-device (EXDEV), so the replace is no longer atomic or can fail.

The test-only diff below kills both (re-verified on 3.13/3.14/3.9). 0o222 → 0o200 stays equivalent, which is fine.

diff --git a/tools/tests/test_build_web.py b/tools/tests/test_build_web.py
index 53a8f03e2c..910498222c 100644
--- a/tools/tests/test_build_web.py
+++ b/tools/tests/test_build_web.py
@@ -189,6 +189,7 @@ class LibraryPublicationTests(unittest.TestCase):
         def fail_manifest(source, destination):
             if destination == self.manifest.resolve():
                 self.assertNotEqual(source, destination)
+                self.assertEqual(source.parent.parent, destination.parent)
                 self.assertIn("platforms", json.loads(source.read_text(encoding="utf-8")))
                 raise OSError("manifest is busy")
             return original(source, destination)
@@ -199,6 +200,15 @@ class LibraryPublicationTests(unittest.TestCase):
         self.publish(valid, valid)
         self.assertEqual(json.loads(self.manifest.read_text(encoding="utf-8"))["tag"], "v1")
 
+    @unittest.skipUnless(os.name == "posix" and os.geteuid() != 0, "POSIX permission bits")
+    def test_read_only_manifest_is_rejected_without_replacement(self):
+        self.manifest.chmod(0o444)
+        with self.assertRaises(PermissionError):
+            build_web.write_manifest(self.manifest, "replacement\n")
+        self.assertEqual(self.manifest.read_bytes(), self.previous)
+        self.assertEqual(self.manifest.stat().st_mode & 0o777, 0o444)
+        self.assertFalse(list(self.output.glob(".release-*")))
+
     def test_partial_manifest_write_preserves_the_previous_file(self):
         original = Path.write_text
         def interrupted(path, text, *args, **kwargs):

No defects in the production change. The two gaps above are coverage only.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5687254549 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12488#pullrequestreview-5687254549). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T17:52:13Z. **Review:** APPROVED --- Independent macOS run of exact head `ef9d0a4d05` (prior runs here were Linux only). - `python -m unittest tools.tests.test_build_web`: 22 OK on Python 3.13 and 3.14 (Homebrew), and on 3.9.6 (Apple; 1 skip, the existing zipfile Unicode-extra test). `check_conventions --base upstream/main` and `check_test_registration --scripts` (212) pass. The branch merges cleanly with current main `e4da19aff0`. #12446 `418cd0d37e` is an ancestor, matching **Depends on**. - RED/GREEN: putting back #12446's `build_web.py` under the new tests makes the 3 manifest tests fail (2F+1E), and the 3 deep-JSON tests still pass because they come from #12446. - Mutants of `write_manifest`: drop `resolve()` → killed, drop `chmod` → killed, write in place instead of replace → killed. **Two survive:** 1. Removing the read-only `PermissionError` guard. No test covers it, and without the guard `replace()` quietly overwrites a 0444 manifest. 2. `TemporaryDirectory(dir=None)`, i.e. staging outside the destination directory. The tests still pass, but in real use the rename becomes cross-device (`EXDEV`), so the replace is no longer atomic or can fail. The test-only diff below kills both (re-verified on 3.13/3.14/3.9). `0o222` → `0o200` stays equivalent, which is fine. ```diff diff --git a/tools/tests/test_build_web.py b/tools/tests/test_build_web.py index 53a8f03e2c..910498222c 100644 --- a/tools/tests/test_build_web.py +++ b/tools/tests/test_build_web.py @@ -189,6 +189,7 @@ class LibraryPublicationTests(unittest.TestCase): def fail_manifest(source, destination): if destination == self.manifest.resolve(): self.assertNotEqual(source, destination) + self.assertEqual(source.parent.parent, destination.parent) self.assertIn("platforms", json.loads(source.read_text(encoding="utf-8"))) raise OSError("manifest is busy") return original(source, destination) @@ -199,6 +200,15 @@ class LibraryPublicationTests(unittest.TestCase): self.publish(valid, valid) self.assertEqual(json.loads(self.manifest.read_text(encoding="utf-8"))["tag"], "v1") + @unittest.skipUnless(os.name == "posix" and os.geteuid() != 0, "POSIX permission bits") + def test_read_only_manifest_is_rejected_without_replacement(self): + self.manifest.chmod(0o444) + with self.assertRaises(PermissionError): + build_web.write_manifest(self.manifest, "replacement\n") + self.assertEqual(self.manifest.read_bytes(), self.previous) + self.assertEqual(self.manifest.stat().st_mode & 0o777, 0o444) + self.assertFalse(list(self.output.glob(".release-*"))) + def test_partial_manifest_write_preserves_the_previous_file(self): original = Path.write_text def interrupted(path, text, *args, **kwargs): ``` No defects in the production change. The two gaps above are coverage only.
THEMANnt commented 2026-10-29 06:44:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-29T06:44:37Z.

Review: APPROVED


Reviewed f69d829d2a3ec16c76fbdb17c55260c3ccd432bc against 52c09d567d2fa453494dd720fcf53a98149468e4. Release library manifests are staged in a temporary directory beside the resolved destination and replaced only after a successful write. Existing mode/read-only checks are retained; the three JSON depth-error entry points are included in this branch. No actionable finding in this scoped review.

Windows/Python 3.11 validation: head 23 passed, 2 skipped; baseline 17 passed, 1 skipped. The write-failure controls preserve the prior manifest on the head and fail on old production. Two platform filesystem cases are skipped. This establishes manifest replacement behavior, not a transaction across all downloaded asset files. Responses/archives are fixtures; no site was published.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5693839784 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12488#pullrequestreview-5693839784). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-29T06:44:37Z. **Review:** APPROVED --- Reviewed `f69d829d2a3ec16c76fbdb17c55260c3ccd432bc` against `52c09d567d2fa453494dd720fcf53a98149468e4`. Release library manifests are staged in a temporary directory beside the resolved destination and replaced only after a successful write. Existing mode/read-only checks are retained; the three JSON depth-error entry points are included in this branch. No actionable finding in this scoped review. Windows/Python 3.11 validation: head 23 passed, 2 skipped; baseline 17 passed, 1 skipped. The write-failure controls preserve the prior manifest on the head and fail on old production. Two platform filesystem cases are skipped. This establishes manifest replacement behavior, not a transaction across all downloaded asset files. Responses/archives are fixtures; no site was published.

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