From cbed193e4e9031aeb276664455e28da992ff3a29 Mon Sep 17 00:00:00 2001 From: Jim Meyer Date: Fri, 13 Nov 2026 17:29:40 -0800 Subject: [PATCH 1/3] fix(review): validate reviewer roster collaborator membership Signed-off-by: Jim Meyer --- .agents/skills/watch-github-actions/SKILL.md | 4 + .github/CODEOWNERS | 2 + .github/workflows/branch-checks.yml | 17 ++++ CONTRIBUTING.md | 2 + REVIEWERS.md | 21 ----- tasks/scripts/check_reviewer_collaborators.py | 47 +++++++++++ .../check_reviewer_collaborators_test.py | 82 +++++++++++++++++++ tasks/test.toml | 2 +- 8 files changed, 155 insertions(+), 22 deletions(-) create mode 100644 tasks/scripts/check_reviewer_collaborators.py create mode 100644 tasks/scripts/check_reviewer_collaborators_test.py diff --git a/.agents/skills/watch-github-actions/SKILL.md b/.agents/skills/watch-github-actions/SKILL.md index 6435a119ea..f5668f2038 100644 --- a/.agents/skills/watch-github-actions/SKILL.md +++ b/.agents/skills/watch-github-actions/SKILL.md @@ -125,6 +125,10 @@ gh run list --json databaseId,status,headBranch,url --jq '.[] | {id: .databaseId ## View Job Logs +For Branch Checks `Reviewer Roster` failures, the log lists non-collaborators in +`REVIEWERS.md`. Remove those entries or arrange repository access before rerunning. +Lookup errors fail the check rather than treating missing results as eligibility. + For Kubernetes app-listener E2E failures during kind setup, inspect the uploaded `results/app-listener/cni-setup/` evidence. It includes node and Calico pod descriptions, events, and current/previous container logs. A CNI rollout timeout diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 78f5034728..c5e9ae20c5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -35,6 +35,8 @@ /REVIEWERS.md @NVIDIA/openshell-codeowners @mrunalp @sjenning @derekwaynecarr /tasks/scripts/check_review_readiness.py @NVIDIA/openshell-codeowners @mrunalp @sjenning @derekwaynecarr /tasks/scripts/check_review_readiness_test.py @NVIDIA/openshell-codeowners @mrunalp @sjenning @derekwaynecarr +/tasks/scripts/check_reviewer_collaborators.py @NVIDIA/openshell-codeowners @mrunalp @sjenning @derekwaynecarr +/tasks/scripts/check_reviewer_collaborators_test.py @NVIDIA/openshell-codeowners @mrunalp @sjenning @derekwaynecarr # PR issue acceptance checks /tasks/scripts/check_issue_acceptance.cjs @NVIDIA/openshell-codeowners @mrunalp @sjenning @derekwaynecarr diff --git a/.github/workflows/branch-checks.yml b/.github/workflows/branch-checks.yml index 834dc5fb4a..4d5ce75dfa 100644 --- a/.github/workflows/branch-checks.yml +++ b/.github/workflows/branch-checks.yml @@ -50,6 +50,23 @@ jobs: echo "number=0" >> "$GITHUB_OUTPUT" fi + reviewer-roster: + name: Reviewer Roster + needs: pr_metadata + if: needs.pr_metadata.outputs.should_run == 'true' + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Validate reviewer collaborator membership + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + run: python3 tasks/scripts/check_reviewer_collaborators.py --repo "$GH_REPO" + compatibility-review: name: Compatibility Review (advisory) needs: pr_metadata diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65ba634845..225fec7b20 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,6 +74,8 @@ Pull requests that touch the enforcement machinery or reviewer routing — anyth Once your pull request represents [accepted work](#accepted-work), apply exactly one `area:` label and any relevant `topic:` labels. Follow [Labeling and Notifications](#labeling-and-notifications) before applying classification labels. The [reviewer routing workflow](.github/workflows/review-readiness.yml) requests all matching members of [REVIEWERS.md](REVIEWERS.md), excluding the author, when a PR opens ready for review, leaves draft status, or gains or loses an area/topic label. Reviewers do not need repository write access to receive requests or review PRs. Manual reviewer choices and people who have commented or reviewed are preserved. Propose roster membership changes through a reviewed PR. +Branch Checks rejects accounts in `REVIEWERS.md` that are not repository collaborators. Public read access alone does not qualify; read and triage collaborators are eligible. + If your pull request has been idle, ask for a reviewer in the pull request or in the CNCF Slack channel rather than waiting. ## Agent Skills diff --git a/REVIEWERS.md b/REVIEWERS.md index 874aaa7944..dc0df9beff 100644 --- a/REVIEWERS.md +++ b/REVIEWERS.md @@ -46,7 +46,6 @@ Authentication, multitenancy, gateway interceptors, FIPS compliance, and other e | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Akram Ben Aissi | [@akram](https://github.com/akram) | Red Hat | | Derek Carr | [@derekwaynecarr](https://github.com/derekwaynecarr) | Red Hat | | Seth Jennings | [@sjenning](https://github.com/sjenning) | Red Hat | @@ -88,7 +87,6 @@ Authentication, authorization, credential protection, policy integrity/signed po | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Gordon Sim | [@grs](https://github.com/grs) | Red Hat | | Kris Hicks | [@krishicks](https://github.com/krishicks) | NVIDIA | | Seth Jennings | [@sjenning](https://github.com/sjenning) | Red Hat | @@ -129,7 +127,6 @@ Extension APIs and integration points, including consistency, general-purpose de | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Artem Lytvyn | [@letv1nnn](https://github.com/letv1nnn) | Independent | | Drew Newberry | [@drew](https://github.com/drew) | NVIDIA | | Matthew Grossman | [@matthewgrossman](https://github.com/matthewgrossman) | NVIDIA | | Piotr Mlocek | [@pimlock](https://github.com/pimlock) | NVIDIA | @@ -151,11 +148,7 @@ Kubernetes operator development, custom resource definitions (CRDs), deployment | --- | --- | --- | | Divesh Chowdary | [@FrostGod](https://github.com/FrostGod) | NVIDIA | | Drew Newberry | [@drew](https://github.com/drew) | NVIDIA | -| Ignas Baranauskas | [@Ygnas](https://github.com/Ygnas) | Red Hat | -| Jorge Garcia Oncins | [@jgarciao](https://github.com/jgarciao) | Red Hat | | Kris Hicks | [@krishicks](https://github.com/krishicks) | NVIDIA | -| Krzysztof Malczuk | [@2000krysztof](https://github.com/2000krysztof) | Red Hat | -| Mark Campbell | [@Bobbins228](https://github.com/Bobbins228) | Red Hat | | Mrunal Patel | [@mrunalp](https://github.com/mrunalp) | Red Hat | | Taylor Mutch | [@TaylorMutch](https://github.com/TaylorMutch) | NVIDIA | @@ -186,11 +179,8 @@ Logging, metrics, tracing, telemetry, dashboards, event correlation, and the col | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Artem Lytvyn | [@letv1nnn](https://github.com/letv1nnn) | Independent | -| Gaizka Menendez | [@gmenher](https://github.com/gmenher) | Red Hat | | Kris Hicks | [@krishicks](https://github.com/krishicks) | NVIDIA | | Matthew Grossman | [@matthewgrossman](https://github.com/matthewgrossman) | NVIDIA | -| Roland Huss | [@rhuss](https://github.com/rhuss) | Red Hat | | Taylor Mutch | [@TaylorMutch](https://github.com/TaylorMutch) | NVIDIA | ### topic:operability @@ -242,7 +232,6 @@ Go SDK implementation, maintenance, interfaces, and distribution. | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Krzysztof Malczuk | [@2000krysztof](https://github.com/2000krysztof) | Red Hat | | Max Dubrinsky | [@maxdubrinsky](https://github.com/maxdubrinsky) | Gretel | | Simon Scatton | [@SDAChess](https://github.com/SDAChess) | NVIDIA | | Taylor Mutch | [@TaylorMutch](https://github.com/TaylorMutch) | NVIDIA | @@ -253,7 +242,6 @@ Python SDK implementation, maintenance, interfaces, and distribution. | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Krzysztof Malczuk | [@2000krysztof](https://github.com/2000krysztof) | Red Hat | | Max Dubrinsky | [@maxdubrinsky](https://github.com/maxdubrinsky) | Gretel | | Simon Scatton | [@SDAChess](https://github.com/SDAChess) | NVIDIA | | Taylor Mutch | [@TaylorMutch](https://github.com/TaylorMutch) | NVIDIA | @@ -264,7 +252,6 @@ Rust SDK implementation, maintenance, interfaces, and distribution. | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Krzysztof Malczuk | [@2000krysztof](https://github.com/2000krysztof) | Red Hat | | Max Dubrinsky | [@maxdubrinsky](https://github.com/maxdubrinsky) | Gretel | | Simon Scatton | [@SDAChess](https://github.com/SDAChess) | NVIDIA | | Taylor Mutch | [@TaylorMutch](https://github.com/TaylorMutch) | NVIDIA | @@ -275,7 +262,6 @@ TypeScript SDK implementation, maintenance, interfaces, and distribution. | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Krzysztof Malczuk | [@2000krysztof](https://github.com/2000krysztof) | Red Hat | | Max Dubrinsky | [@maxdubrinsky](https://github.com/maxdubrinsky) | Gretel | | Simon Scatton | [@SDAChess](https://github.com/SDAChess) | NVIDIA | | Taylor Mutch | [@TaylorMutch](https://github.com/TaylorMutch) | NVIDIA | @@ -287,10 +273,8 @@ Vulnerability management, static/dynamic analysis, FSR (Functional Security Requ | Name | GitHub ID | Company/Organization | | --- | --- | --- | | Adrien Langou | [@alangou](https://github.com/alangou) | NVIDIA | -| Christian Zaccaria | [@ChristianZaccaria](https://github.com/ChristianZaccaria) | Red Hat | | Jim Meyer | [@purp](https://github.com/purp) | NVIDIA | | John T. Myers | [@johntmyers](https://github.com/johntmyers) | NVIDIA | -| Krzysztof Malczuk | [@2000krysztof](https://github.com/2000krysztof) | Red Hat | | Russell Bryant | [@russellb](https://github.com/russellb) | Red Hat | | Simon Scatton | [@SDAChess](https://github.com/SDAChess) | NVIDIA | @@ -301,9 +285,6 @@ Unit, integration, regression, conformance, and end-to-end testing, including te | Name | GitHub ID | Company/Organization | | --- | --- | --- | | Evan Lezar | [@elezar](https://github.com/elezar) | NVIDIA | -| Gaizka Menendez | [@gmenher](https://github.com/gmenher) | Red Hat | -| Jorge Garcia Oncins | [@jgarciao](https://github.com/jgarciao) | Red Hat | -| Mark Campbell | [@Bobbins228](https://github.com/Bobbins228) | Red Hat | | Matthew Grossman | [@matthewgrossman](https://github.com/matthewgrossman) | NVIDIA | | Simon Scatton | [@SDAChess](https://github.com/SDAChess) | NVIDIA | @@ -313,5 +294,3 @@ CLI command interface and flags, help text, error messages and exit codes, human | Name | GitHub ID | Company/Organization | | --- | --- | --- | -| Artem Lytvyn | [@letv1nnn](https://github.com/letv1nnn) | Independent | -| Roland Huss | [@rhuss](https://github.com/rhuss) | Red Hat | diff --git a/tasks/scripts/check_reviewer_collaborators.py b/tasks/scripts/check_reviewer_collaborators.py new file mode 100644 index 0000000000..a20c88158a --- /dev/null +++ b/tasks/scripts/check_reviewer_collaborators.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Reject reviewer roster entries without repository collaborator membership.""" + +import argparse +import subprocess +import sys +from pathlib import Path + +from check_review_readiness import _api, parse_reviewers + + +def main(argv: list[str] | None = None) -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--repo", required=True) + parser.add_argument("--reviewers", type=Path, default=Path("REVIEWERS.md")) + args = parser.parse_args(argv) + try: + categories = parse_reviewers(args.reviewers.read_text(encoding="utf-8")) + members = set().union(*categories.values()) + collaborators = { + member["login"].lower() + for member in _api( + f"repos/{args.repo}/collaborators?per_page=100&affiliation=all", + pages=True, + ) + } + invalid = sorted(members - collaborators) + if invalid: + raise ValueError("non-collaborators in REVIEWERS.md: " + ", ".join(invalid)) + except subprocess.CalledProcessError as exc: + print( + "Cannot list repository collaborators: " + (exc.stderr or str(exc)).strip(), + file=sys.stderr, + ) + return 1 + except (OSError, ValueError, KeyError, TypeError) as exc: + print(f"Reviewer roster: {exc}", file=sys.stderr) + return 1 + print(f"All {len(members)} reviewer roster accounts are repository collaborators.") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/scripts/check_reviewer_collaborators_test.py b/tasks/scripts/check_reviewer_collaborators_test.py new file mode 100644 index 0000000000..951234a339 --- /dev/null +++ b/tasks/scripts/check_reviewer_collaborators_test.py @@ -0,0 +1,82 @@ +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Offline tests for reviewer roster eligibility.""" + +import contextlib +import io +import json +import subprocess +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +import check_reviewer_collaborators as check + +ROSTER = """### area:build + +| Name | GitHub ID | Company/Organization | +| --- | --- | --- | +| Alice | [@Alice](https://github.com/Alice) | Example | +| Bob | [@bob](https://github.com/bob) | Example | +""" + + +class CollaboratorTests(unittest.TestCase): + def run_check(self, response): + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "REVIEWERS.md" + path.write_text(ROSTER) + with ( + mock.patch.object(check.subprocess, "run", side_effect=response) as api, + contextlib.redirect_stdout(io.StringIO()) as output, + contextlib.redirect_stderr(io.StringIO()) as errors, + ): + result = check.main(["--repo", "owner/repo", "--reviewers", str(path)]) + return result, api, output.getvalue(), errors.getvalue() + + def test_accepts_collaborators_on_all_pages_without_write_access(self): + pages = [ + [{"login": "ALICE", "role_name": "read"}], + [{"login": "bob", "role_name": "triage"}], + ] + result, api, _, _ = self.run_check( + [subprocess.CompletedProcess([], 0, stdout=json.dumps(pages))] + ) + self.assertEqual(result, 0) + command = api.call_args.args[0] + self.assertIn( + "repos/owner/repo/collaborators?per_page=100&affiliation=all", command + ) + self.assertIn("--paginate", command) + self.assertIn("--slurp", command) + + def test_reports_all_non_collaborators_in_sorted_order(self): + result, _, _, errors = self.run_check( + [subprocess.CompletedProcess([], 0, stdout="[[]]")] + ) + self.assertEqual(result, 1) + self.assertIn("alice, bob", errors) + self.assertIn("REVIEWERS.md", errors) + + def test_lookup_failure_fails_closed(self): + result, _, output, errors = self.run_check( + subprocess.CalledProcessError(1, "gh", stderr="Forbidden (HTTP 403)") + ) + self.assertEqual(result, 1) + self.assertEqual(output, "") + self.assertIn("403", errors) + + def test_invalid_roster_fails_before_lookup(self): + with mock.patch.object( + check, "parse_reviewers", side_effect=ValueError("bad roster") + ): + result, api, _, errors = self.run_check([]) + self.assertEqual(result, 1) + api.assert_not_called() + self.assertIn("bad roster", errors) + + +if __name__ == "__main__": + unittest.main() diff --git a/tasks/test.toml b/tasks/test.toml index 4f1d6892c7..4fdd377f95 100644 --- a/tasks/test.toml +++ b/tasks/test.toml @@ -106,7 +106,7 @@ hide = true ["test:review-readiness"] description = "Test PR review readiness and reviewer reconciliation" -run = "uv run --no-project python -m unittest discover -s tasks/scripts -p check_review_readiness_test.py" +run = "uv run --no-project python -m unittest discover -s tasks/scripts -p 'check_review*_test.py'" hide = true ["test:accepted-work"] From 715a6f7fe85379e854b8028c5adb60c3d8e24970 Mon Sep 17 00:00:00 2001 From: Jim Meyer Date: Fri, 13 Nov 2026 20:54:08 -0800 Subject: [PATCH 2/3] test(review): name reviewer test files explicitly Signed-off-by: Jim Meyer --- tasks/test.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tasks/test.toml b/tasks/test.toml index 4fdd377f95..7626135c41 100644 --- a/tasks/test.toml +++ b/tasks/test.toml @@ -106,7 +106,10 @@ hide = true ["test:review-readiness"] description = "Test PR review readiness and reviewer reconciliation" -run = "uv run --no-project python -m unittest discover -s tasks/scripts -p 'check_review*_test.py'" +run = [ + "uv run --no-project python -m unittest discover -s tasks/scripts -p check_review_readiness_test.py", + "uv run --no-project python -m unittest discover -s tasks/scripts -p check_reviewer_collaborators_test.py", +] hide = true ["test:accepted-work"] From d6d57f0dc02cdd9750cf243f09778dae29f15081 Mon Sep 17 00:00:00 2001 From: Adrien Langou Date: Tue, 17 Nov 2026 15:30:34 +0100 Subject: [PATCH 3/3] fix(review): verify effective access for unlisted reviewers Check effective write or admin access before rejecting an account omitted from the collaborator list. Keep public read access and lookup errors rejected, with regression tests and matching contributor guidance. Signed-off-by: Adrien Langou --- CONTRIBUTING.md | 2 +- tasks/scripts/check_reviewer_collaborators.py | 22 +++- .../check_reviewer_collaborators_test.py | 124 +++++++++++++++++- 3 files changed, 136 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 225fec7b20..88f6434afa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,7 +74,7 @@ Pull requests that touch the enforcement machinery or reviewer routing — anyth Once your pull request represents [accepted work](#accepted-work), apply exactly one `area:` label and any relevant `topic:` labels. Follow [Labeling and Notifications](#labeling-and-notifications) before applying classification labels. The [reviewer routing workflow](.github/workflows/review-readiness.yml) requests all matching members of [REVIEWERS.md](REVIEWERS.md), excluding the author, when a PR opens ready for review, leaves draft status, or gains or loses an area/topic label. Reviewers do not need repository write access to receive requests or review PRs. Manual reviewer choices and people who have commented or reviewed are preserved. Propose roster membership changes through a reviewed PR. -Branch Checks rejects accounts in `REVIEWERS.md` that are not repository collaborators. Public read access alone does not qualify; read and triage collaborators are eligible. +Branch Checks requires accounts in `REVIEWERS.md` to appear in the repository collaborator list or have confirmed write or admin permission. Public read access alone does not qualify; read and triage accounts must appear in the collaborator list. If your pull request has been idle, ask for a reviewer in the pull request or in the CNCF Slack channel rather than waiting. diff --git a/tasks/scripts/check_reviewer_collaborators.py b/tasks/scripts/check_reviewer_collaborators.py index a20c88158a..d3b8a1d86b 100644 --- a/tasks/scripts/check_reviewer_collaborators.py +++ b/tasks/scripts/check_reviewer_collaborators.py @@ -2,7 +2,7 @@ # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -"""Reject reviewer roster entries without repository collaborator membership.""" +"""Validate reviewer roster accounts against repository membership and permissions.""" import argparse import subprocess @@ -27,19 +27,31 @@ def main(argv: list[str] | None = None) -> int: pages=True, ) } - invalid = sorted(members - collaborators) + invalid = [] + for login in sorted(members - collaborators): + permission = _api(f"repos/{args.repo}/collaborators/{login}/permission")[ + "permission" + ] + if permission in ("read", "none"): + invalid.append(login) + elif permission not in ("write", "admin"): + raise ValueError(f"unexpected repository permission for {login}") if invalid: - raise ValueError("non-collaborators in REVIEWERS.md: " + ", ".join(invalid)) + raise ValueError( + "ineligible accounts in REVIEWERS.md: " + ", ".join(invalid) + ) except subprocess.CalledProcessError as exc: print( - "Cannot list repository collaborators: " + (exc.stderr or str(exc)).strip(), + "Cannot verify reviewer access: " + (exc.stderr or str(exc)).strip(), file=sys.stderr, ) return 1 except (OSError, ValueError, KeyError, TypeError) as exc: print(f"Reviewer roster: {exc}", file=sys.stderr) return 1 - print(f"All {len(members)} reviewer roster accounts are repository collaborators.") + print( + f"All {len(members)} reviewer roster accounts are eligible for review requests." + ) return 0 diff --git a/tasks/scripts/check_reviewer_collaborators_test.py b/tasks/scripts/check_reviewer_collaborators_test.py index 951234a339..a8faf7eba3 100644 --- a/tasks/scripts/check_reviewer_collaborators_test.py +++ b/tasks/scripts/check_reviewer_collaborators_test.py @@ -24,10 +24,10 @@ class CollaboratorTests(unittest.TestCase): - def run_check(self, response): + def run_check(self, response, roster=ROSTER): with tempfile.TemporaryDirectory() as directory: path = Path(directory) / "REVIEWERS.md" - path.write_text(ROSTER) + path.write_text(roster) with ( mock.patch.object(check.subprocess, "run", side_effect=response) as api, contextlib.redirect_stdout(io.StringIO()) as output, @@ -40,11 +40,14 @@ def test_accepts_collaborators_on_all_pages_without_write_access(self): pages = [ [{"login": "ALICE", "role_name": "read"}], [{"login": "bob", "role_name": "triage"}], + [{"login": "outside", "role_name": "read"}], ] result, api, _, _ = self.run_check( - [subprocess.CompletedProcess([], 0, stdout=json.dumps(pages))] + [subprocess.CompletedProcess([], 0, stdout=json.dumps(pages))], + ROSTER + "| Outside | [@outside](https://github.com/outside) | Other |\n", ) self.assertEqual(result, 0) + self.assertEqual(api.call_count, 1) command = api.call_args.args[0] self.assertIn( "repos/owner/repo/collaborators?per_page=100&affiliation=all", command @@ -52,13 +55,122 @@ def test_accepts_collaborators_on_all_pages_without_write_access(self): self.assertIn("--paginate", command) self.assertIn("--slurp", command) - def test_reports_all_non_collaborators_in_sorted_order(self): - result, _, _, errors = self.run_check( - [subprocess.CompletedProcess([], 0, stdout="[[]]")] + def test_reports_unlisted_read_and_none_in_sorted_order(self): + result, api, output, errors = self.run_check( + [ + subprocess.CompletedProcess([], 0, stdout="[[]]"), + subprocess.CompletedProcess( + [], 0, stdout='{"permission": "read", "role_name": "admin"}' + ), + subprocess.CompletedProcess( + [], 0, stdout='{"permission": "none", "role_name": "custom-role"}' + ), + ] ) self.assertEqual(result, 1) + self.assertEqual(output, "") self.assertIn("alice, bob", errors) self.assertIn("REVIEWERS.md", errors) + self.assertEqual(api.call_count, 3) + self.assertIn( + "repos/owner/repo/collaborators/alice/permission", + api.call_args_list[1].args[0], + ) + self.assertIn( + "repos/owner/repo/collaborators/bob/permission", + api.call_args_list[2].args[0], + ) + + def test_accepts_unlisted_writer_with_custom_role(self): + result, api, output, errors = self.run_check( + [ + subprocess.CompletedProcess([], 0, stdout='[[{"login": "bob"}]]'), + subprocess.CompletedProcess( + [], 0, stdout='{"permission": "write", "role_name": "custom-role"}' + ), + ] + ) + self.assertEqual(result, 0, errors) + self.assertIn("All 2 reviewer roster accounts", output) + self.assertEqual(api.call_count, 2) + command = api.call_args.args[0] + self.assertEqual( + command, + [ + "gh", + "api", + "repos/owner/repo/collaborators/alice/permission", + "--method", + "GET", + ], + ) + + def test_accepts_unlisted_administrator(self): + result, _, output, errors = self.run_check( + [ + subprocess.CompletedProcess([], 0, stdout='[[{"login": "bob"}]]'), + subprocess.CompletedProcess( + [], 0, stdout='{"permission": "admin", "role_name": "admin"}' + ), + ] + ) + self.assertEqual(result, 0, errors) + self.assertIn("All 2 reviewer roster accounts", output) + + def test_permission_lookup_errors_fail_closed(self): + for status in (403, 404, 500): + with self.subTest(status=status): + result, _, output, errors = self.run_check( + [ + subprocess.CompletedProcess([], 0, stdout="[[]]"), + subprocess.CalledProcessError( + 1, "gh", stderr=f"lookup failed (HTTP {status})" + ), + ] + ) + self.assertEqual(result, 1) + self.assertEqual(output, "") + self.assertIn(f"HTTP {status}", errors) + self.assertNotIn("ineligible accounts", errors) + + def test_malformed_permission_responses_fail_closed(self): + responses = ["invalid JSON", "", "null", "[]", "{}", '{"role_name": "admin"}'] + responses.extend( + json.dumps({"permission": permission, "role_name": "admin"}) + for permission in ( + None, + [], + {}, + True, + 1, + "maintain", + "triage", + "custom-role", + ) + ) + for response in responses: + with self.subTest(response=response): + result, _, output, errors = self.run_check( + [ + subprocess.CompletedProcess([], 0, stdout="[[]]"), + subprocess.CompletedProcess([], 0, stdout=response), + ] + ) + self.assertEqual(result, 1) + self.assertEqual(output, "") + self.assertIn("Reviewer roster:", errors) + self.assertNotIn("ineligible accounts", errors) + + def test_permission_process_error_fails_closed(self): + result, _, output, errors = self.run_check( + [ + subprocess.CompletedProcess([], 0, stdout="[[]]"), + OSError("connection failed"), + ] + ) + self.assertEqual(result, 1) + self.assertEqual(output, "") + self.assertIn("connection failed", errors) def test_lookup_failure_fails_closed(self): result, _, output, errors = self.run_check(