-
Notifications
You must be signed in to change notification settings - Fork 0
fix(scheduler): reject commented reviews before runner admission #1900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seonghobae
wants to merge
5
commits into
main
Choose a base branch
from
codex/filter-commented-review-admission-20260905
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e8302e2
fix(scheduler): reject commented reviews before runner admission
seonghobae 7a8c47f
Merge protected main into scheduler review-event admission repair
seonghobae 2ade00a
fix(scheduler): preserve actionable review run from comments
seonghobae ccd2fd7
Merge main into COMMENTED review admission repair
seonghobae 77569bf
Merge branch 'main' into codex/filter-commented-review-admission-2026…
opencode-agent[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
docs/doctoring/pr-review-merge-scheduler-trigger-audit-20260903.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """Executable admission contract for merge-scheduler review events.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import ast | ||
| import re | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
| WORKFLOW = ROOT / ".github" / "workflows" / "pr-review-merge-scheduler.yml" | ||
|
|
||
|
|
||
| def scan_job_condition() -> str: | ||
| """Return the normalized pre-runner condition for ``scan-pr-queue``.""" | ||
| workflow = WORKFLOW.read_text(encoding="utf-8") | ||
| scan_job = workflow.split("\n scan-pr-queue:\n", 1)[1] | ||
| condition = scan_job.split("\n runs-on:", 1)[0].split("\n if: >-\n", 1)[1] | ||
| return " ".join(line.strip() for line in condition.splitlines()) | ||
|
|
||
|
|
||
| def admits_review_event(*, action: str, state: str) -> bool: | ||
| """Evaluate the workflow's review-event condition for one trusted fixture.""" | ||
| expression = scan_job_condition().replace("&&", " and ").replace("||", " or ") | ||
| expression = re.sub(r"\btrue\b", "True", expression) | ||
| values = { | ||
| "github.event_name": "pull_request_review", | ||
| "github.event.action": action, | ||
| "github.event.review.state": state, | ||
| "github.event.client_payload.org_sweep": False, | ||
| } | ||
|
|
||
| def evaluate(node: ast.AST) -> object: | ||
| """Interpret only the boolean/comparison subset used by the job guard.""" | ||
| if isinstance(node, ast.Expression): | ||
| return evaluate(node.body) | ||
| if isinstance(node, ast.BoolOp): | ||
| operands = [bool(evaluate(value)) for value in node.values] | ||
| return all(operands) if isinstance(node.op, ast.And) else any(operands) | ||
| if isinstance(node, ast.Compare) and len(node.ops) == len(node.comparators) == 1: | ||
| left = evaluate(node.left) | ||
| right = evaluate(node.comparators[0]) | ||
| if isinstance(node.ops[0], ast.Eq): | ||
| return left == right | ||
| if isinstance(node.ops[0], ast.NotEq): | ||
| return left != right | ||
| if isinstance(node, ast.Constant): | ||
| return node.value | ||
| if isinstance(node, (ast.Attribute, ast.Name)): | ||
| key = ast.unparse(node) | ||
| if key in values: | ||
| return values[key] | ||
| raise AssertionError(f"unsupported scheduler expression node: {ast.dump(node)}") | ||
|
|
||
| return bool(evaluate(ast.parse(expression, mode="eval"))) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("action", "state", "expected"), | ||
| [ | ||
| ("submitted", "commented", False), | ||
| ("submitted", "approved", True), | ||
| ("submitted", "changes_requested", True), | ||
| ("dismissed", "commented", True), | ||
| ], | ||
| ) | ||
| def test_review_event_admission_truth_table( | ||
| action: str, state: str, expected: bool | ||
| ) -> None: | ||
| """Admit only review transitions that can change merge eligibility.""" | ||
| assert admits_review_event(action=action, state=state) is expected | ||
|
|
||
|
|
||
| def test_review_filter_preserves_exact_pr_group_and_least_privilege() -> None: | ||
| """Filtering COMMENTED reviews must not weaken scheduler trust boundaries.""" | ||
| workflow = WORKFLOW.read_text(encoding="utf-8") | ||
| assert ( | ||
| "github.event_name == 'pull_request_review' && " | ||
| "format('pr-{0}', github.event.pull_request.number)" in workflow | ||
| ) | ||
| assert ( | ||
| "cancel-in-progress: ${{ github.event_name == 'pull_request_target' || " | ||
| "github.event_name == 'pull_request_review' || " | ||
| "github.event_name == 'repository_dispatch' }}" in workflow | ||
| ) | ||
| assert "permissions:\n contents: read" in workflow | ||
|
|
||
| scan_header = workflow.split("\n scan-pr-queue:\n", 1)[1].split( | ||
| "\n env:\n", 1 | ||
| )[0] | ||
| for permission in ( | ||
| "actions: write", | ||
| "checks: read", | ||
| "contents: write", | ||
| "id-token: write", | ||
| "pull-requests: write", | ||
| ): | ||
| assert permission in scan_header |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.