From f498c0ebfdf621ae8c209fc4f6b381b947db9f7e Mon Sep 17 00:00:00 2001 From: FENG <223868679+MakerFlyFly@users.noreply.github.com> Date: Sun, 11 Oct 2026 11:04:01 +0000 Subject: [PATCH 1/2] fix(pr-management-stats): keep the parity tests from publishing a gist Why: the JSON parity tests call dashboard.main() with publishing enabled, and their stubs cover only data fetching. An authenticated gh can PATCH a real dashboard gist or create a new secret gist while both tests pass. Pass --no-publish to the dashboard invocation only, since reference.main() does not accept it. Replace both publishing entry points with stubs that fail the test if reached, so removing the flag cannot silently regress. Generated-by: Codex (GPT-6) --- tools/pr-management/tests/stats/test_json_parity.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/pr-management/tests/stats/test_json_parity.py b/tools/pr-management/tests/stats/test_json_parity.py index cb72dc574..afc1cbbeb 100644 --- a/tools/pr-management/tests/stats/test_json_parity.py +++ b/tools/pr-management/tests/stats/test_json_parity.py @@ -78,6 +78,14 @@ def fake_paginated_search(query, search_q, *args, status=None, **kwargs): monkeypatch.setattr(module, "paginated_search", fake_paginated_search) monkeypatch.setattr(module, "fetch_codeowners", lambda repo: "") monkeypatch.setattr(module, "fetch_ready_pr_files", lambda repo, nums: {}) + if module is dashboard: + # dashboard.main() ends by publishing to a secret gist through `gh`. + # A unit test must never reach GitHub, so fail loudly if it gets there. + def refuse_publish(*args, **kwargs): + raise AssertionError("unit test reached the dashboard gist publish step") + + monkeypatch.setattr(module, "gist_scope_available", refuse_publish) + monkeypatch.setattr(module, "publish_gist", refuse_publish) def _run(monkeypatch, module, out_path): @@ -93,6 +101,8 @@ def _run(monkeypatch, module, out_path): "--out", str(out_path), ] + if module is dashboard: + argv.append("--no-publish") # reference.py has no publish step and no such flag monkeypatch.setattr(module.sys, "argv", argv) module.main() return json.loads(out_path.with_suffix(".json").read_text()) From c8fdbc05f14a51379ae39173660437043e005358 Mon Sep 17 00:00:00 2001 From: FENG <223868679+MakerFlyFly@users.noreply.github.com> Date: Sun, 11 Oct 2026 16:40:31 +0000 Subject: [PATCH 2/2] fix(pr-management-stats): harden the parity test gist guards Why: AssertionError can be caught by an ordinary Exception handler, and the parity test stubs did not cover session-state reads or writes. Use pytest.fail so a reached guard escapes ordinary exception handling. Protect all four gist entry points independently of their current order. Keep the dashboard-only --no-publish flag and the existing JSON assertions. Generated-by: Codex (GPT-6) --- tools/pr-management/tests/stats/test_json_parity.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/pr-management/tests/stats/test_json_parity.py b/tools/pr-management/tests/stats/test_json_parity.py index afc1cbbeb..e3a1bbf04 100644 --- a/tools/pr-management/tests/stats/test_json_parity.py +++ b/tools/pr-management/tests/stats/test_json_parity.py @@ -28,6 +28,8 @@ import json +import pytest + from pr_management.stats import dashboard, reference from .helpers import comment, make_pr @@ -82,10 +84,13 @@ def fake_paginated_search(query, search_q, *args, status=None, **kwargs): # dashboard.main() ends by publishing to a secret gist through `gh`. # A unit test must never reach GitHub, so fail loudly if it gets there. def refuse_publish(*args, **kwargs): - raise AssertionError("unit test reached the dashboard gist publish step") + pytest.fail("unit test reached the dashboard gist publish step") + # Guard each entry point independently of main()'s current call order. monkeypatch.setattr(module, "gist_scope_available", refuse_publish) monkeypatch.setattr(module, "publish_gist", refuse_publish) + monkeypatch.setattr(module, "read_stats_gist_id", refuse_publish) + monkeypatch.setattr(module, "store_stats_gist_id", refuse_publish) def _run(monkeypatch, module, out_path):