Skip to content

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

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
WhiteAssassins:feat/patch-catalog-validator
Oct 29, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
WhiteAssassins:feat/patch-catalog-validator

Conversation

@WhiteAssassins

@WhiteAssassins WhiteAssassins commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

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

@JJenkx

JJenkx commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

A Windows run, since the description lists none. Head 1d7bdd81ca was merged onto main 0cd07dc4ab with no conflicts. Setup: Windows 11 Enterprise 10.0.22621, Python 3.15.

python -m unittest tools/tests/test_validate_patch_catalog.py: 11 tests, OK, in each of 3 runs.

AI-assisted: yes (Claude Code).

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 674 CMakeLists.txt
PR 1835 CMakeLists.txt
PR 3786 CMakeLists.txt
docs/user/USAGE.md
PR 5021 CMakeLists.txt
docs/user/USAGE.md
PR 5925 docs/user/USAGE.md
PR 6924 docs/user/USAGE.md
PR 7642 docs/user/USAGE.md
PR 9345 docs/user/USAGE.md
PR 9508 CMakeLists.txt
docs/user/USAGE.md
PR 9539 CMakeLists.txt
PR 10193 docs/user/USAGE.md
PR 10861 docs/user/USAGE.md

@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.

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.

@WhiteAssassins

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review, Marc. I appreciate you checking the current head, the duplicate-ID behavior, and the cross-platform checks.

@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026

@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 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.

@rooklz

rooklz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Reviewed 1d7bdd81ca, independently reproducing THEMANnt's P2 and adding one more case.

Reproduction (macOS arm64, head file run directly):

index.json / --catalog 3.12 3.13 3.14 3.15
{"format":1,"entries":<2,500 nested arrays>} rc2 rc2 rc2 rc2
same, 200,000 nested arrays rc1 RecursionError rc1 rc1 (Stack overflow) rc1
--catalog = self-looping symlink rc1 RuntimeError (Path.resolve()) rc2 rc2 rc2
{"format":1,"entries":[]} rc0 rc0 rc0 rc0

On this host, 2,500 levels decodes on every version (each entry is reported as invalid). 200,000 levels escapes on all four. The script's floor is 3.11 (tomllib). On 3.11 and 3.12 a looping --catalog also exits through Path.resolve() with a traceback, the same pattern as #12340 in suggest_patches.

Suggested fix (source):

Tests (two added to test_validate_patch_catalog.py):

    def test_deeply_nested_index_is_reported_as_invalid(self):
        depth = 200000
        (self.catalog / "index.json").write_text('{"format": 1, "entries": ' + "[" * depth + "]" * depth + "}")
        output, errors = io.StringIO(), io.StringIO()
        with contextlib.redirect_stdout(output), contextlib.redirect_stderr(errors):
            result = validate_patch_catalog.main(["--catalog", str(self.catalog)])
        self.assertEqual(result, 2)
        self.assertIn("Catalog validation: index.json is nested too deeply", errors.getvalue())

    def test_catalog_symlink_loop_is_reported_as_invalid(self):
        loop = self.root / "loop"
        loop.symlink_to(loop)
        output, errors = io.StringIO(), io.StringIO()
        with contextlib.redirect_stdout(output), contextlib.redirect_stderr(errors):
            result = validate_patch_catalog.main(["--catalog", str(loop)])
        self.assertEqual(result, 2)
        self.assertIn("Catalog validation:", errors.getvalue())

Verified:

  • Head plus the fix: 13 tests OK on 3.12, 3.13, 3.14 and 3.15 (about 0.01 s).
  • Source reverted with the new tests kept: 3.12 has 2 errors (deep and loop) and 3.14 has 1 (deep). So each test fails without its arm.
  • Merged onto main 2227f13661: no conflicts. test_validate_patch_catalog + test_suggest_patches give 48 OK. Relinker-only build 270/270, ctest 379/379.
  • check_conventions --base origin/main is clean.

The 200,000 depth is deliberate: 20,000 decodes fine on 3.14+, so a smaller fixture would not test the new arm there.

AI-assisted: yes (Claude Code).

@WhiteAssassins

Copy link
Copy Markdown
Contributor Author

@THEMANnt Thanks for the P2 report. Fixed on the current head, c6c35d1a53: decoder-depth failures in index.json now produce Catalog validation: index.json is nested too deeply and exit 2. A CLI subprocess regression uses 200,000 nested arrays and checks exit 2, no traceback, and an unchanged input file.

I also handled looping --catalog paths, as rooklz noted. A follow-up review found the same uncontrolled depth failure in patch TOML and silent duplicate JSON keys; both now have CLI regressions too. The validator reports those as invalid catalogs without modifying the files.

On this head, the validator and advisor suites pass all 50 tests on Python 3.11 and 3.14. The synthetic real-relinker integration, conventions, test registration, and diff check also pass. Please re-review when convenient.

@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.

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.

@oneandonlydean
oneandonlydean merged commit 59d7cff into boykopovar:main Oct 29, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants