feat(tools): validate complete patch catalogs offline #12263

Merged
WhiteAssassins merged 4 commits from upstream-pr/12263 into main 2026-10-29 10:52:35 +00:00
WhiteAssassins commented 2026-10-28 05:54:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by WhiteAssassins on 2026-10-28T05:54:18Z.


What

Add tools/validate_patch_catalog.py --catalog DIR to check every format-1 catalog entry offline before sharing it or running a catalog CI job. It reuses the advisor's index and entry validation, checks relative target paths, duplicate JSON keys and patch-file format, and reports all invalid entries with their catalog numbers. It also rejects duplicate IDs that could match one title build while allowing the same ID for mutually exclusive target hashes or another content version.

The command needs no game files or relinker and does not download or apply patches. It performs structural checks; the relinker's stricter TOML parser and --verify-patches remain necessary to establish applicability. The advisor's recommendation behavior is unchanged. This follows #8900, #10719 and #11489 and supports the external catalog proposal in #8893.

Malformed deeply nested index.json data, deeply nested patch TOML, and a looping --catalog symlink are reported as catalog errors with exit code 2, without a traceback.

Tested

  • CachyOS Linux, Python 3.14.8 and Python 3.11: python3 -m unittest tools.tests.test_validate_patch_catalog tools.tests.test_suggest_patches and the same command with /usr/bin/python3.11 (50 passed on each version). The CLI regressions check exit code 2, no traceback, and preserved input for deeply nested JSON/TOML, looping catalog paths, and duplicate JSON keys.
  • Synthetic ELF: python3 core/relinker/relinker/tests/test_patch_advisor.py <relinker> passed with the real relinker.
  • python3 tools/check_conventions.py --base origin/main, python3 tools/check_test_registration.py --scripts, and git diff --check origin/main...HEAD passed.
  • python3 tools/validate_patch_catalog.py --help passed. No game files were used.
  • The new CTest registration is gated on Python 3.11+, matching the advisor's tomllib requirement. Python 3.9/3.10 was not available for a local CMake run.
  • python3 tools/pr_overlap.py --branch feat/patch-catalog-validator completed. I reviewed the shared CMakeLists.txt and USAGE.md hunks it could not compare automatically; they concern other features.

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 (n/a: Python tool only)
  • 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 (n/a: no third-party code)
  • 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:5045912829 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12263). Originally posted by [WhiteAssassins](https://github.com/WhiteAssassins) on 2026-10-28T05:54:18Z. --- ### What Add `tools/validate_patch_catalog.py --catalog DIR` to check every format-1 catalog entry offline before sharing it or running a catalog CI job. It reuses the advisor's index and entry validation, checks relative target paths, duplicate JSON keys and patch-file format, and reports all invalid entries with their catalog numbers. It also rejects duplicate IDs that could match one title build while allowing the same ID for mutually exclusive target hashes or another content version. The command needs no game files or relinker and does not download or apply patches. It performs structural checks; the relinker's stricter TOML parser and `--verify-patches` remain necessary to establish applicability. The advisor's recommendation behavior is unchanged. This follows #8900, #10719 and #11489 and supports the external catalog proposal in #8893. Malformed deeply nested `index.json` data, deeply nested patch TOML, and a looping `--catalog` symlink are reported as catalog errors with exit code `2`, without a traceback. ### 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. --> - CachyOS Linux, Python 3.14.8 and Python 3.11: `python3 -m unittest tools.tests.test_validate_patch_catalog tools.tests.test_suggest_patches` and the same command with `/usr/bin/python3.11` (50 passed on each version). The CLI regressions check exit code `2`, no traceback, and preserved input for deeply nested JSON/TOML, looping catalog paths, and duplicate JSON keys. - Synthetic ELF: `python3 core/relinker/relinker/tests/test_patch_advisor.py <relinker>` passed with the real relinker. - `python3 tools/check_conventions.py --base origin/main`, `python3 tools/check_test_registration.py --scripts`, and `git diff --check origin/main...HEAD` passed. - `python3 tools/validate_patch_catalog.py --help` passed. No game files were used. - The new CTest registration is gated on Python 3.11+, matching the advisor's `tomllib` requirement. Python 3.9/3.10 was not available for a local CMake run. - `python3 tools/pr_overlap.py --branch feat/patch-catalog-validator` completed. I reviewed the shared `CMakeLists.txt` and `USAGE.md` hunks it could not compare automatically; they concern other features. ### 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 (n/a: Python tool only) - [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 (n/a: no third-party code) - [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 08:58:12 +00:00 (Migrated from github.com)

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

Review: APPROVED


The validator reuses the advisor’s catalog and entry validation, then checks every entry independent of local title files, verifies patch format/target coverage, confines paths, and reports duplicate IDs only when entries could match the same title/version. The tests cover malformed entries, escaping and Windows-drive target paths, duplicate IDs, mutually exclusive hashes, and valid empty catalogs. I checked the PR head’s validate_entry return shape and metadata validation; the validator uses them consistently. The reported Python 3.14 tests and current cross-platform relinker/ASan, Windows, conventions and eligibility checks pass. No blocking issue found.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5680069461 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12263#pullrequestreview-5680069461). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T08:58:12Z. **Review:** APPROVED --- The validator reuses the advisor’s catalog and entry validation, then checks every entry independent of local title files, verifies patch format/target coverage, confines paths, and reports duplicate IDs only when entries could match the same title/version. The tests cover malformed entries, escaping and Windows-drive target paths, duplicate IDs, mutually exclusive hashes, and valid empty catalogs. I checked the PR head’s `validate_entry` return shape and metadata validation; the validator uses them consistently. The reported Python 3.14 tests and current cross-platform relinker/ASan, Windows, conventions and eligibility checks pass. No blocking issue found.
THEMANnt commented 2026-10-28 11:36:38 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Reviewed 1d7bdd81caac641370b5404feb45c26362e30359 — request changes.

[P2] Report decoder-depth failures as invalid catalogs — tools/validate_patch_catalog.py:52–55. The new command documents exit 2 for invalid catalogs, but a valid JSON index whose entries contains 2,500 nested arrays escapes as RecursionError, prints a traceback and exits 1. The same CLI returns the intended exit 2 for entries: [null] and exit 0 for an empty catalog. A generated or malformed deep index therefore bypasses the validator's controlled failure contract. Catch the decoder-depth failure at the catalog boundary and add a real CLI regression that checks exit 2, no traceback and input preservation.

Windows/Python 3.11: all 11 supplied validator tests passed; the existing advisor suite passed 33 cases with 2 symlink-privilege skips (35 total). The independent probe uses the exact submitted CLI and preserves each input. This is a new command, so missing old helper APIs are not behavioral regression proof. No game files or relinker-applicability claim is involved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5681972344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12263#pullrequestreview-5681972344). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T11:36:38Z. **Review:** CHANGES_REQUESTED --- Reviewed `1d7bdd81caac641370b5404feb45c26362e30359` — request changes. **[P2] Report decoder-depth failures as invalid catalogs — `tools/validate_patch_catalog.py:52–55`.** The new command documents exit 2 for invalid catalogs, but a valid JSON index whose `entries` contains 2,500 nested arrays escapes as `RecursionError`, prints a traceback and exits 1. The same CLI returns the intended exit 2 for `entries: [null]` and exit 0 for an empty catalog. A generated or malformed deep index therefore bypasses the validator's controlled failure contract. Catch the decoder-depth failure at the catalog boundary and add a real CLI regression that checks exit 2, no traceback and input preservation. Windows/Python 3.11: all 11 supplied validator tests passed; the existing advisor suite passed 33 cases with 2 symlink-privilege skips (35 total). The independent probe uses the exact submitted CLI and preserves each input. This is a new command, so missing old helper APIs are not behavioral regression proof. No game files or relinker-applicability claim is involved.
THEMANnt commented 2026-10-28 17:25:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T17:25:14Z.

Review: APPROVED


Re-reviewed c6c35d1a538929fdbcf11b428daa979af3dee1f7 — approve. My decoder-depth change request is addressed: deeply nested index JSON and patch TOML now exit 2 without a traceback. Duplicate JSON keys and looping catalog paths are also rejected without modifying the input files. The default advisor path remains compatible.

Windows/Python 3.11: the validator/advisor suites run 50 tests, with 47 passed and 3 symlink-privilege skips; the baseline advisor runs 35, with 33 passed and 2 skips. Independent CLI controls cover the original 2,500-level index, a 200,000-array index, nested patch TOML, duplicate top-level and entry keys, and an actual Windows junction loop, plus valid controls. All fixed-head invalid cases return 2 without a traceback and preserve every fixture file. The previously reviewed head still crashes on the depth/loop cases and silently accepts the duplicate-key controls.

A fresh Windows/GCC 15.3 Release relinker build passes the synthetic real-relinker advisor integration, and the registered validator CTest passes (14 passed, 1 symlink skip internally). Conventions, script registration and whitespace checks pass. The current Windows/Ubuntu relinker and ASan CI jobs pass; the macOS matrix remains pending. This approval closes the reviewed code defect; no console/title or game-file validation is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5686896283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12263#pullrequestreview-5686896283). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T17:25:14Z. **Review:** APPROVED --- Re-reviewed `c6c35d1a538929fdbcf11b428daa979af3dee1f7` — approve. My decoder-depth change request is addressed: deeply nested index JSON and patch TOML now exit 2 without a traceback. Duplicate JSON keys and looping catalog paths are also rejected without modifying the input files. The default advisor path remains compatible. Windows/Python 3.11: the validator/advisor suites run 50 tests, with 47 passed and 3 symlink-privilege skips; the baseline advisor runs 35, with 33 passed and 2 skips. Independent CLI controls cover the original 2,500-level index, a 200,000-array index, nested patch TOML, duplicate top-level and entry keys, and an actual Windows junction loop, plus valid controls. All fixed-head invalid cases return 2 without a traceback and preserve every fixture file. The previously reviewed head still crashes on the depth/loop cases and silently accepts the duplicate-key controls. A fresh Windows/GCC 15.3 Release relinker build passes the synthetic real-relinker advisor integration, and the registered validator CTest passes (14 passed, 1 symlink skip internally). Conventions, script registration and whitespace checks pass. The current Windows/Ubuntu relinker and ASan CI jobs pass; the macOS matrix remains pending. This approval closes the reviewed code defect; no console/title or game-file validation 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!12263
No description provided.