Repository navigation
feat(tools): emit patch advisor decisions as JSON - #12769
Conversation
|
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.
|
rooklz
left a comment
There was a problem hiding this comment.
Checked on macOS arm64 at a0e63ff (merge-tree against main ba5b533 is clean; conventions and git diff --check pass).
test_patch_advisor_json2/2 andtest_suggest_patchesOK on Homebrew Python 3.12, 3.13 and 3.15. Both new tests fail against main'ssuggest_patches.pybecause main has no--json, as expected.- Relinker-only build: the full ctest run passes 486/486.
patch_advisor_json_integrationpasses in 0.20 s against a real macOS relinker, so the integration fixture also works on a third host.
Test gap. I made 15 single-line mutants of the JSON reporting in main(). Only 3 are caught by the unit test (list status, entry number, default record status), and the integration test adds exit_code. These 11 pass both tests:
reason dropped (hash mismatch / validate_entry error / timeout), duplicate-id demotion leaving the record verified, no recommended_entry, no_match → rejected, relinker-error status → rejected, top-level error dropped, verification.stdout/stderr emptied, metadata dropped, patch → None.
The test below pins every record kind with one 6-entry catalog (verified, stale hash, invalid metadata, two duplicate ids, timeout) and adds the three failure statuses. It kills all 15 mutants, passes on this head with 3.12, 3.13 and 3.15, and fails on main. Each run takes a few ms:
diff --git a/tools/tests/test_patch_advisor_json.py b/tools/tests/test_patch_advisor_json.py
index 76173a8717..c0cf18f2bc 100644
--- a/tools/tests/test_patch_advisor_json.py
+++ b/tools/tests/test_patch_advisor_json.py
@@ -43,6 +43,43 @@ class PatchAdvisorJsonTests(unittest.TestCase):
self.assertEqual(self.advise("--json"), 2)
self.assertEqual(json.loads(output.getvalue())["status"], "error")
+ def run_json(self, *extra, **run):
+ output = io.StringIO()
+ with patch.object(suggest_patches.subprocess, "run", **run), contextlib.redirect_stdout(output):
+ code = self.advise("--json", *extra)
+ return code, json.loads(output.getvalue())
+
+ def test_json_records_every_decision(self):
+ verified = subprocess.CompletedProcess([], 0, VERIFIED, "warn")
+ self.entry["id"] = "fix"
+ other = dict(self.entry, id="other")
+ stale = dict(self.entry, targets={"Media/Modules/module.prx": "0" * 64})
+ invalid = dict(self.entry, category="unknown")
+ self.write_index([self.entry, stale, invalid, other, other, dict(self.entry, id="slow")])
+ code, data = self.run_json(side_effect=[verified, verified, verified, subprocess.TimeoutExpired([], 7)])
+ self.assertEqual(code, 0)
+ self.assertEqual(data["status"], "recommended")
+ self.assertEqual(data["recommended_entry"], 1)
+ first, second, third, fourth, fifth, sixth = data["entries"]
+ self.assertEqual(first, {"number": 1, "patch": "patch.toml", "status": "verified",
+ "targets": self.entry["targets"], "metadata": {"id": "fix"},
+ "verification": {"exit_code": 0, "summary": [1, 1, 0, 0],
+ "stdout": VERIFIED, "stderr": "warn"}})
+ self.assertEqual((second["status"], second["reason"].startswith("Media/Modules/module.prx")), ("rejected", True))
+ self.assertEqual((third["status"], third["reason"]), ("rejected", "invalid category"))
+ for record in (fourth, fifth):
+ self.assertEqual((record["status"], record["reason"]), ("rejected", "duplicate verified id 'other'"))
+ self.assertEqual((sixth["status"], sixth["reason"]), ("rejected", "verification_timeout"))
+
+ def test_json_failure_statuses(self):
+ self.write_index([dict(self.entry, contentVersion="02.000.000")])
+ self.assertEqual(self.run_json(), (1, {"status": "no_match", "entries": []}))
+ self.write_index()
+ code, data = self.run_json(return_value=subprocess.CompletedProcess([], 2, "", "FAIL: invalid patch"))
+ self.assertEqual((code, data["status"], data["error"]), (2, "error", "relinker errors occurred"))
+ self.param.write_text("[]")
+ self.assertEqual(self.run_json(), (2, {"status": "error", "entries": [], "error": "param.json must be an object"}))
+
if __name__ == "__main__":
unittest.main()Non-blocking.
- When the relinker rejects an entry (exit 1 with a mismatch, exit 2, or "did not confirm every patch"), the record is
rejectedwith noreason. Readers have to parseverificationto tell these apart from the other rejections.reasonvalues are also mixed:verification_timeoutis a code, while every other reason is free text. Picking one style now would keep the JSON contract simple. - Argparse errors (for example a missing
--catalog) still exit 2 with no JSON on stdout. That is probably fine, but the help text could say so. - The overlap bot's #12787 conflict is real: both PRs edit the top-level
exceptin the same block. Whichever lands second needs to addRecursionErrornext to the newfinish(2, "error", error).
(AI-assisted review)
# Conflicts: # tools/suggest_patches.py
|
One suggestion for a future web or GUI consumer: could the JSON include a schema version (for example, The text mode already prints This could also be a follow-up if you want to keep this PR focused on reporting decisions. |
WhiteAssassins
left a comment
There was a problem hiding this comment.
Reviewed head ec81a35. The optional JSON path preserves text behavior and exit statuses, records per-entry verification decisions, and has unit and native relinker integration coverage. Hosted relinker checks pass. The schema-version and conversion-argument suggestion can be handled in a follow-up.
malekaifa
left a comment
There was a problem hiding this comment.
Blocking JSON-validity edge on exact head ec81a35.
Python's json.loads accepts NaN/Infinity by default. A matching catalog entry whose raw patch field is NaN reaches the per-entry rejection path, but the report record captures entry.get("patch") before validation; json.dumps then emits that raw float as the non-standard token NaN.
Repro: use a catalog index entry with titleId TEST00001, contentVersion 01.000.000, patch: NaN, and a syntactically valid targets object; provide valid param/input/relinker files and run with --json. The tool exits 1 with stdout equivalent to:
{"entries":[{"number":1,"patch":NaN,"reason":"invalid relative path: nan","status":"rejected"}],"status":"rejected"}
Python's permissive parser accepts that output, but a strict JSON parser rejects NaN, so a malformed catalog can make the machine-readable mode stop being JSON while the tool reports a handled rejection. I reproduced the same behavior on stacked #12911.
Please reject non-finite constants on JSON input (for example via parse_constant raising ValueError) or otherwise ensure only validated/JSON-safe values are reflected, and add a strict-output regression. The ordinary valid-JSON paths and text behavior otherwise look unaffected.
|
Follow-up on the review fixes at head Addressed the strict-JSON review: advisor catalog/parameter input now rejects NaN, Infinity, -Infinity and floating-point overflow before raw fields can enter the report. Serialization also disallows non-finite values. Errors return status 2 with standard JSON. The shared reader opts into strict numeric parsing for the advisor, preserving other callers' existing validation policy. #12787 remains integrated. Validation at this exact head: built the native relinker on Windows/Linux and passed all four patch-advisor CTest groups, including both native integrations, 37 existing unit tests and 5 JSON tests. Windows has two existing filesystem skips; Linux has none. The new method covers 10 invalid-number input cases and strictly parses stdout; it fails against the pre-fix production code. Temporary integrations with #12911 (6 JSON + 37 unit tests and native JSON integration) and #12875 (2 JSON + 15 validator tests) also pass on both OSes. Those peer branches are not embedded in this PR. Hosted-check snapshot checked on 2026-10-30 for this head: 5 passed, 3 pending, 4 skipped; no failures. Current checks. Pending and skipped checks are not counted as passes. The PR description contains the detailed validation scope and limitations. Please re-review the updated head when convenient. AI-assisted: yes. |
malekaifa
left a comment
There was a problem hiding this comment.
Re-reviewed exact head be1fa52. The strict-JSON blocker from my previous review is fixed: the focused JSON suite passes on Windows Python 3.12 and WSL Python 3.12.3, non-finite catalog/parameter numbers are rejected before verification, and allow_nan=False protects serialization. I found no remaining defect in that fix itself. The remaining blocker is integration order with the older approved #12340 through this PR's prerequisite #12787. Exact current-head merge checks: #12787 + #12769 is clean; #12340 + #12787 conflicts in tools/suggest_patches.py; #12340 + #12769 also conflicts in tools/suggest_patches.py. #12787's body already acknowledges the #12340 conflict, but there is no resolved landing order yet. Please coordinate and record the stack order before merge; the lowest-risk sequence is #12340 first, then rebase/resolve #12787 keeping both symlink-loop and RecursionError handling, then rebase #12769 onto that integrated result (and #12911 after it). Once the overlap is resolved/restacked, I can re-check the exact integrated head; the JSON-validity issue itself is resolved.
…advisor-prerequisites-20261030
|
@malekaifa I have resolved and tested the combined stack at Proposed landing order: #12340 → #12787 → #12769 → #12911. Both #12340 and #12787 are now explicit prerequisites in this PR's checklist. @rooklz @xXPBSXx could you confirm this order and restack #12787 after #12340? The tested prerequisite resolution keeps Validation on Windows/MinGW and Linux:
The final main refresh, conventions, whitespace, script registration and test-retention checks pass. The prior non-finite JSON fix remains covered. The PR description records exact commits, commands and scope. Hosted-check snapshot at 2026-10-30T01:09:09+00:00 (UTC): 2 pending; no failures. Current checks. New-head CI and prerequisite-author confirmation remain pending; previous-head CI is not substituted for them. Please re-check this exact integrated head once the stack order is confirmed. AI-assisted: yes. |
|
CI follow-up for unchanged integrated head
This completes the hosted-CI result that was pending in my previous repair comment. The proposed #12340 → #12787 → #12769 → #12911 order still awaits prerequisite-author coordination; green CI does not establish that agreement. No source changes in this follow-up. AI-assisted: yes. |
|
Any updates? |
|
Status: #12769 is in review and lands in the stack order @StoneDC set out, after #12340 and #12787. #12787 still needs a restack onto current main before that chain can move. Separately, all merges are paused right now while we fix a test failure on main; we'll pick the stack up again once main is green. |
|
@WhiteAssassins @oneandonlydean Status checked at 2026-11-01T17:59:27.100922+00:00 UTC:
The next external action is the #12787 restack; the stack can then be refreshed/verified in that order. This PR is not being presented as independently ready to land. The description now records this status. Current-head checks. AI-assisted: yes. |
|
CI status update: the newer main Build for The remaining stack action is unchanged: #12340 -> #12787 -> #12769 -> #12911, with public #12787 still at AI-assisted: yes. |
|
Updated to Fresh Windows/MinGW and Linux validation builds the real relinker and passes all 4 registered advisor CTest groups on each OS, including both native integrations, 40 advisor unit tests and 6 JSON tests. There are no skipped CTest groups; Windows retains four existing filesystem/symlink unittest skips, Linux none. The 15 validator tests also pass (one existing Windows unittest skip). Both behavior controls catch removal of the exception catches / directory-error conversion on each OS. The clean temporary composition The description now declares Depends on: #12787. The remaining order is #12787 -> #12769 -> #12911; the prerequisite restack has been published and only its merge remains external. Please re-review this exact integrated head. The account has READ permission upstream, so a maintainer/reviewer must perform any formal re-request required by the review queue. New-head CI is pending until it completes: checks. Fresh repository overlap checking identifies #12911 as the intended downstream reporting change, covered by the clean composition above. It could not automatically compare four older peers sharing AI-assisted: yes. GitHub now reports this exact head mergeable. The existing |
|
Hi malekaifa, Your review of
Could you re-check the integrated head when you have time? Thank you. |
|
Hosted CI completion for unchanged head The maintainer has already asked for re-review of this integrated head; this adds the final CI links for that review. The remaining landing order is still #12787 -> #12769 -> #12911, with #12787 open at |
✅ AMD GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (4, not counted against this PR)Passed on retry (2, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validation IDs already present on main (4 IDs in 445 tests)Skipped (6)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Rechecked the integrated head
I found no remaining source blocker on this exact head. The remaining GitHub review state is historical ( |
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.
AI-assisted: yes. |
|
Windows check of head Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release,
AI-assisted: yes. |
|
Thanks @JJenkx and @gabichuuuuu for the Windows results. I rechecked unchanged head |
|
Tested
AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports. |
|
Updated to Integrated current main after #12787 merged, and removed the obsolete prerequisite from the PR body. The strict-number/serialization safeguards, both RecursionError handlers and path/symlink validation remain intact. Both real-relinker advisor integration tests were rebuilt and rerun on Windows and Linux. I also checked the uploaded artifacts behind the new external Windows report: across both ARM repeats, all 16 distinct failing names in this PR are included in the 17-name main baseline set; the Windows Server 2022 PR runs have no failures. Those historical ARM runs are not claimed passing, and no additional PR-only ARM failure was found in that comparison. Contributor run. Exact-head validation: Python 3.12 and 3.14 on Windows and Linux, 6/6 focused registered CTest groups passed in all four configurations, 62 unittest methods per configuration, slowest group 1.43 s. Windows retains five existing unittest filesystem/symlink skips (four advisor, one validator); Linux has none. All six CTest groups, including both real native integrations, execute on both platforms. Current-main conventions, whitespace, Python 3.9 grammar and script registration pass. Final hosted results for this exact updated head are recorded below. This PR has now merged. AI-assisted: yes. Final hosted CI completion (verified 2026-11-13) for
Skipped jobs (not counted as passes): The verified head was merged at |
malekaifa
left a comment
There was a problem hiding this comment.
Re-reviewed exact head fa07033 after the prerequisite stack was resolved. #12340 and #12787 are both merged, current main is integrated, and this PR is now CLEAN with the prerequisite overlap removed from the diff while retaining the strict-number, RecursionError, and path/symlink handling. Local Windows Python 3.12 validation passed test_patch_advisor_json.py (6/6) and test_suggest_patches.py (40 tests, 4 existing filesystem skips); git diff --check is clean. Hosted checks have no failures. Approved.
What
Add optional
suggest_patches.py --jsonwith final decision status, per-entry verification output/summary, targets, validated metadata and the recommended entry number. Preserve text output and verification policy. Reject non-finite input numbers before they enter reports, and serialize withallow_nan=False.Integrate current main now that #12340 and #12787 are merged. Keep both RecursionError handlers, path/symlink error handling, current metadata validation and the complete JSON/native integration regressions. Remove the obsolete open prerequisite from the checklist; the merged #12787 head remains an ancestor. Schema-version/conversion-option additions are outside this change.
Tested
Exact tested head:
fa07033d2427f9a69174d0864a5edbf39fbfebfc, including mainac94ac850371e12cde7048c3db59135e19a869c3.Windows 11 / MinGW GCC 15.2 / CMake 4.3.1 / Python 3.14.3 and 3.12.14; WSL Ubuntu 26.04 / GCC 15.2 / CMake 4.2.3 / Python 3.14.4 and 3.12.16. Real CMake/Ninja Release configurations use
ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ONand each selected interpreter.ctest --test-dir BUILD -R '^(patch_advisor.*|validate_patch_catalog|test_script_registration)$' -V --output-on-failure --no-tests=error: all 6 registered groups pass in each of the four configurations; 62 unittest methods per configuration. Slowest selected group: 1.43 s. No CTest group is skipped.allow_nan=False, both RecursionError catches and main path validation are retained.No full system-library build, new ARM64 runtime, local macOS runtime, PS5/title run or GPU validation is claimed. Hosted results for the new head are reported separately after publication; earlier-head checks are not substituted.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)