Skip to content

Commit 0b959a8

Browse files
Keep reuse self-test notices out of CI logs (#1634)
The fallback tests for ci-reuse-merge-group.py and ci-reuse-pr-head.py let the scripts print their real "::notice::Could not verify merge-queue CI (...)" lines to stdout. lint-ecosystems runs those tests in a GitHub job, so every run on PRs, the merge queue and main gained ten fake annotations claiming the reuse check had failed. They fill the step's ten-notice cap and send anyone debugging a reuse decision down the wrong path. Capture stdout in those cases and assert that the notice is printed. The fallback path is now checked, not just silenced. Claude-Session: https://claude.ai/code/session_01SeHhBxEvePf8ERTaTTenMK Co-authored-by: Claude <noreply@anthropic.com>
1 parent a54753a commit 0b959a8

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

‎scripts/tests/test_ci_reuse_merge_group.py‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""A reused CI verdict must belong to this workflow, repository and exact SHA."""
22

3+
import contextlib
34
import importlib.util
5+
import io
46
import json
57
import subprocess
68
import unittest
@@ -60,15 +62,22 @@ def test_non_main_pushes_and_other_events_never_query_or_skip(self):
6062
self.assertIsNone(reuse.reusable_run(dict(self.env, **change)))
6163
call.assert_not_called()
6264

65+
def assert_falls_back(self, env):
66+
# Capture the fallback notice: printed to the job log it becomes a
67+
# real (misleading) annotation on every lint-ecosystems run.
68+
with contextlib.redirect_stdout(io.StringIO()) as out:
69+
self.assertIsNone(reuse.reusable_run(env))
70+
self.assertTrue(out.getvalue().startswith("::notice::"), out.getvalue())
71+
6372
def test_api_failure_timeout_and_bad_payload_keep_all_checks(self):
6473
for error in (FileNotFoundError(), subprocess.CalledProcessError(1, "gh"),
6574
subprocess.TimeoutExpired("gh", 15)):
6675
with self.subTest(error=error), patch.object(reuse.subprocess, "run", side_effect=error):
67-
self.assertIsNone(reuse.reusable_run(self.env))
76+
self.assert_falls_back(self.env)
6877
for text in ("not json", "{}", '{"workflow_runs": null}', '{"workflow_runs": [null]}'):
6978
with self.subTest(text=text), patch.object(reuse.subprocess, "run", return_value=
7079
subprocess.CompletedProcess([], 0, stdout=text)):
71-
self.assertIsNone(reuse.reusable_run(self.env))
80+
self.assert_falls_back(self.env)
7281

7382

7483
if __name__ == "__main__":

‎scripts/tests/test_ci_reuse_pr_head.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Only a clean base-branch merge onto a head that passed CI may skip tests."""
22

3+
import contextlib
34
import importlib.util
5+
import io
46
import json
57
import subprocess
68
import tempfile
@@ -118,18 +120,24 @@ def test_other_events_and_bases_never_query_or_skip(self):
118120
self.assertIsNone(reuse.reusable_run(dict(self.env, **change)))
119121
call.assert_not_called()
120122

123+
def assert_falls_back(self, env):
124+
# Capture the fallback notice: printed to the job log it becomes a
125+
# real (misleading) annotation on every lint-ecosystems run.
126+
with contextlib.redirect_stdout(io.StringIO()) as out:
127+
self.assertIsNone(reuse.reusable_run(env))
128+
self.assertTrue(out.getvalue().startswith("::notice::"), out.getvalue())
129+
121130
def test_api_failure_timeout_and_bad_payload_run_everything(self):
122131
for error in (FileNotFoundError(), subprocess.CalledProcessError(1, "gh"),
123132
subprocess.TimeoutExpired("gh", 15)):
124133
with self.subTest(error=error), patch.object(reuse.subprocess, "run", side_effect=error):
125-
self.assertIsNone(reuse.reusable_run(self.env))
134+
self.assert_falls_back(self.env)
126135
for text in ("not json", "{}", '{"parents": null}', '{"parents": [null, null]}'):
127136
with self.subTest(text=text), patch.object(reuse.subprocess, "run", return_value=
128137
subprocess.CompletedProcess([], 0, stdout=text)):
129-
self.assertIsNone(reuse.reusable_run(self.env))
138+
self.assert_falls_back(self.env)
130139
with self.subTest("missing env"), patch.object(reuse.subprocess, "run") as call:
131-
self.assertIsNone(reuse.reusable_run({"GITHUB_EVENT_NAME": "pull_request",
132-
"PR_BASE_REF": "main"}))
140+
self.assert_falls_back({"GITHUB_EVENT_NAME": "pull_request", "PR_BASE_REF": "main"})
133141
call.assert_not_called()
134142

135143
def test_main_writes_the_output(self):

0 commit comments

Comments
 (0)