feat(tools): emit read-only PR label plans as JSON #12768

Merged
StoneDC merged 6 commits from upstream-pr/12768 into main 2026-11-02 13:39:50 +00:00
StoneDC commented 2026-10-29 08:39:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by StoneDC on 2026-10-29T08:39:52Z.


What

Add read-only --dry-run --json PR label plans; preserve normal text mode and reject JSON without dry-run before accessing a repository.

Pin whole JSON reports for --all and --pr: repository, success/error PR numbers, add/remove labels, posted-comment suppression, markers and failed items. Use deliberately descending set iteration so removing a sort fails independently of hash seed. The test's GitHub adapter is mocked and dry-run remains mandatory; it sends no live label edits or comments. Production behavior is unchanged by this test hardening.

Tested

Exact tested head: 29dd548a18be4156364094598d384e42d923d2fd; observed main snapshot: ba5b5330b37724bca4b99f30faab504653635a04. Upstream may advance after that recorded snapshot.

Windows 11 / Python 3.14.3 / MinGW GCC 15.2 / CMake 4.3.1 and non-root WSL Ubuntu 26.04 / Python 3.14.4 / GCC 15.2 / CMake 4.2.3. Ninja Release relinker-only configurations with BUILD_TESTING=ON; Linux uses exact source archives on its native filesystem.

  • Registered focused CTest ^pr_labels$ with --parallel 4 -V: 23 Python cases on each OS, all relevant groups passed. Slowest group 0.23 s Windows / 0.13 s Linux. No CTest group is skipped.
  • No Python test skips. All original test methods remain available in unique test classes.
  • Targeted shadow-module controls on both OSes: Dropping removed labels, zeroing success PR numbers or always posting a marker each fails the complete JSON plan assertion. These are assertion failures, not missing imports. The full reviewer mutation campaign is not claimed as rerun.
  • Production script-registration and CTest skip-policy checks pass on both OSes. These are fixture/tool tests, not a full product, GPU, console, title or browser deployment run. No local macOS/older-Python run is claimed.

Current-main conventions with this complete description and whitespace checks pass. Python 3.9 grammar checks pass for changed Python files. Recorded main and the original published PR head are ancestors of this tested branch. New hosted jobs run after publication; old-head passes are not substituted for the new head's results.

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:5064921944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12768). Originally posted by [StoneDC](https://github.com/StoneDC) on 2026-10-29T08:39:52Z. --- ### What Add read-only `--dry-run --json` PR label plans; preserve normal text mode and reject JSON without dry-run before accessing a repository. Pin whole JSON reports for --all and --pr: repository, success/error PR numbers, add/remove labels, posted-comment suppression, markers and failed items. Use deliberately descending set iteration so removing a sort fails independently of hash seed. The test's GitHub adapter is mocked and dry-run remains mandatory; it sends no live label edits or comments. Production behavior is unchanged by this test hardening. ### 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: `29dd548a18be4156364094598d384e42d923d2fd`; observed main snapshot: `ba5b5330b37724bca4b99f30faab504653635a04`. Upstream may advance after that recorded snapshot. Windows 11 / Python 3.14.3 / MinGW GCC 15.2 / CMake 4.3.1 and non-root WSL Ubuntu 26.04 / Python 3.14.4 / GCC 15.2 / CMake 4.2.3. Ninja Release relinker-only configurations with BUILD_TESTING=ON; Linux uses exact source archives on its native filesystem. - Registered focused CTest `^pr_labels$` with --parallel 4 -V: 23 Python cases on each OS, all relevant groups passed. Slowest group 0.23 s Windows / 0.13 s Linux. No CTest group is skipped. - No Python test skips. All original test methods remain available in unique test classes. - Targeted shadow-module controls on both OSes: Dropping removed labels, zeroing success PR numbers or always posting a marker each fails the complete JSON plan assertion. These are assertion failures, not missing imports. The full reviewer mutation campaign is not claimed as rerun. - Production script-registration and CTest skip-policy checks pass on both OSes. These are fixture/tool tests, not a full product, GPU, console, title or browser deployment run. No local macOS/older-Python run is claimed. Current-main conventions with this complete description and whitespace checks pass. Python 3.9 grammar checks pass for changed Python files. Recorded main and the original published PR head are ancestors of this tested branch. New hosted jobs run after publication; old-head passes are not substituted for the new head's results. ### 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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
rooklz commented 2026-10-29 11:14:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T11:14:24Z.

Review: COMMENTED


Reviewed head ace7b9a6a1 on macOS arm64.

Result: the change is correct, but the new tests leave most of the JSON row contents unchecked.

  • tools/tests/test_pr_labels.py passes on Python 3.9.6, 3.13 and 3.15 (22/22). When the file runs against main's pr_labels.py, both JSON tests that touch the output fail as expected.
  • git merge-tree against current main ba5b5330b3 merges cleanly. check_conventions --head and git diff --check are clean. pr_overlap --branch probed 1392 PRs and found 2 that share files; both merge cleanly with no overlap.

Mutation check. I applied 15 single-line mutants to the new code in main() and ran the PR's tests on each. These 5 still pass:

  • "remove": []
  • comment_marker always set to MARKER, even when no comment would be posted
  • "number": 0 in success rows
  • "number": 0 in error rows
  • "repository": ""

A sixth, "add": list(add), passes or fails depending on PYTHONHASHSEED, because the test sets only have two elements. The only remaining survivor is sort_keys=True removed, which changes byte layout but not content.

The test below compares the whole JSON object for --all (a remove-only row, an add row whose comment is already posted so the marker is None, and an error row) and for --pr. It returns sets that iterate in descending order, so dropping sorted() fails on every hash seed. With it, 14/15 mutants fail under seeds 1–6. It passes on head (23/23, ×3 Pythons) and fails on main.

+    def test_plan_rows_match_the_text_plan(self):
+        import subprocess
+        body = "Unblocks: PPSA01325"
+        records = [
+            {"number": 11, "title": "fix(core): x", "body": "", "labels": [{"name": n} for n in ("perf numbers missing", "unblocks title", "perf", "bug")], "state": "open"},
+            {"number": 12, "title": "perf(core): x", "body": body, "labels": [], "state": "open"},
+            {"number": 13, "title": "fix(core): x", "body": "", "labels": [], "state": "open"},
+        ]
+        def gh(*args):
+            if args[:2] == ("api", "--paginate") and "pulls?" in args[2]:
+                return json.dumps(records)
+            if args[:2] == ("api", "--paginate") and args[2] == "repos/test/repo/issues/42/comments":
+                return "1"
+            if args == ("api", "repos/test/repo/pulls/42"):
+                return json.dumps(dict(records[1], number=42))
+            if args[:2] == ("api", "--paginate"):
+                raise subprocess.CalledProcessError(1, ["gh"], stderr="read failed")
+            raise AssertionError(args)
+        class Descending(set):
+            def __iter__(self):
+                return iter(sorted(set.__iter__(self), reverse=True))
+        original = pr_labels.process
+        def process(repo, pr, dry_run, comment):
+            if pr["number"] == 13:
+                raise subprocess.CalledProcessError(1, ["gh"], stderr="read failed")
+            add, remove, post = original(repo, pr, dry_run, comment)
+            return Descending(add), Descending(remove), post
+        for argv, expected, code in (
+            (["--all"], {"repository": "test/repo", "failed": [13], "plans": [
+                {"number": 11, "add": [], "remove": sorted(pr_labels.MANAGED), "comment_marker": None},
+                {"number": 12, "add": sorted(pr_labels.MANAGED), "remove": [], "comment_marker": None},
+                {"number": 13, "error": "read failed"}]}, 1),
+            (["--pr", "42"], {"repository": "test/repo", "failed": [], "plans": [
+                {"number": 42, "add": sorted(pr_labels.MANAGED), "remove": [], "comment_marker": None}]}, 0),
+        ):
+            with self.subTest(argv=argv):
+                output = io.StringIO()
+                with patch.object(pr_labels, "repository", return_value="test/repo"), patch.object(pr_labels, "gh", side_effect=gh), patch.object(pr_labels, "process", side_effect=process), contextlib.redirect_stdout(output), contextlib.redirect_stderr(io.StringIO()):
+                    self.assertEqual(pr_labels.main(argv + ["--dry-run", "--json"]), code)
+                self.assertEqual(json.loads(output.getvalue()), expected)
+

Non-blocking: in text mode a failed item ends with sys.exit(message), while JSON mode returns 1. Both exit with status 1, so that matches.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5696778777 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12768#pullrequestreview-5696778777). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T11:14:24Z. **Review:** COMMENTED --- Reviewed head `ace7b9a6a1` on macOS arm64. **Result: the change is correct, but the new tests leave most of the JSON row contents unchecked.** - `tools/tests/test_pr_labels.py` passes on Python 3.9.6, 3.13 and 3.15 (22/22). When the file runs against main's `pr_labels.py`, both JSON tests that touch the output fail as expected. - `git merge-tree` against current main `ba5b5330b3` merges cleanly. `check_conventions --head` and `git diff --check` are clean. `pr_overlap --branch` probed 1392 PRs and found 2 that share files; both merge cleanly with no overlap. **Mutation check.** I applied 15 single-line mutants to the new code in `main()` and ran the PR's tests on each. These 5 still pass: - `"remove": []` - `comment_marker` always set to `MARKER`, even when no comment would be posted - `"number": 0` in success rows - `"number": 0` in error rows - `"repository": ""` A sixth, `"add": list(add)`, passes or fails depending on `PYTHONHASHSEED`, because the test sets only have two elements. The only remaining survivor is `sort_keys=True` removed, which changes byte layout but not content. The test below compares the whole JSON object for `--all` (a remove-only row, an add row whose comment is already posted so the marker is `None`, and an error row) and for `--pr`. It returns sets that iterate in descending order, so dropping `sorted()` fails on every hash seed. With it, 14/15 mutants fail under seeds 1–6. It passes on head (23/23, ×3 Pythons) and fails on main. ```diff + def test_plan_rows_match_the_text_plan(self): + import subprocess + body = "Unblocks: PPSA01325" + records = [ + {"number": 11, "title": "fix(core): x", "body": "", "labels": [{"name": n} for n in ("perf numbers missing", "unblocks title", "perf", "bug")], "state": "open"}, + {"number": 12, "title": "perf(core): x", "body": body, "labels": [], "state": "open"}, + {"number": 13, "title": "fix(core): x", "body": "", "labels": [], "state": "open"}, + ] + def gh(*args): + if args[:2] == ("api", "--paginate") and "pulls?" in args[2]: + return json.dumps(records) + if args[:2] == ("api", "--paginate") and args[2] == "repos/test/repo/issues/42/comments": + return "1" + if args == ("api", "repos/test/repo/pulls/42"): + return json.dumps(dict(records[1], number=42)) + if args[:2] == ("api", "--paginate"): + raise subprocess.CalledProcessError(1, ["gh"], stderr="read failed") + raise AssertionError(args) + class Descending(set): + def __iter__(self): + return iter(sorted(set.__iter__(self), reverse=True)) + original = pr_labels.process + def process(repo, pr, dry_run, comment): + if pr["number"] == 13: + raise subprocess.CalledProcessError(1, ["gh"], stderr="read failed") + add, remove, post = original(repo, pr, dry_run, comment) + return Descending(add), Descending(remove), post + for argv, expected, code in ( + (["--all"], {"repository": "test/repo", "failed": [13], "plans": [ + {"number": 11, "add": [], "remove": sorted(pr_labels.MANAGED), "comment_marker": None}, + {"number": 12, "add": sorted(pr_labels.MANAGED), "remove": [], "comment_marker": None}, + {"number": 13, "error": "read failed"}]}, 1), + (["--pr", "42"], {"repository": "test/repo", "failed": [], "plans": [ + {"number": 42, "add": sorted(pr_labels.MANAGED), "remove": [], "comment_marker": None}]}, 0), + ): + with self.subTest(argv=argv): + output = io.StringIO() + with patch.object(pr_labels, "repository", return_value="test/repo"), patch.object(pr_labels, "gh", side_effect=gh), patch.object(pr_labels, "process", side_effect=process), contextlib.redirect_stdout(output), contextlib.redirect_stderr(io.StringIO()): + self.assertEqual(pr_labels.main(argv + ["--dry-run", "--json"]), code) + self.assertEqual(json.loads(output.getvalue()), expected) + ``` Non-blocking: in text mode a failed item ends with `sys.exit(message)`, while JSON mode returns 1. Both exit with status 1, so that matches.
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!12768
No description provided.