From b918fba3d90de9a965b8610b55a6b902022d80fb Mon Sep 17 00:00:00 2001 From: FENG <223868679+MakerFlyFly@users.noreply.github.com> Date: Mon, 12 Oct 2026 07:37:03 +0000 Subject: [PATCH] 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. Guard gist authentication, publication and session-state reads/writes with pytest.fail, so ordinary exception handlers cannot swallow a reached guard and the checks do not depend on main's current call order. Generated-by: Codex (GPT-6) --- .../pr-management/tests/stats/test_json_parity.py | 15 +++++++++++++++ 1 file changed, 15 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..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 @@ -78,6 +80,17 @@ 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): + 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): @@ -93,6 +106,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())