Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/scripts/review_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,17 @@ def evaluate_sweep_gate(
return GateDecision(
False, f"SKIP_ALREADY_REVIEWED_BY_HUMAN:{reviewer}"
)
# Anyone can paste a SHA marker, so only bot-authored markers count.
if not _is_bot_actor(review.get("user") or review.get("author")):
continue
body = str(review.get("body") or "")
for match in SHA_MARKER_RE.finditer(body):
if head_sha and match.group(1) == head_sha and not force_manual:
return GateDecision(False, f"SKIP_SHA_ALREADY_REVIEWED:{head_sha}")

for comment in issue_comments:
if not _is_bot_actor(comment.get("user") or comment.get("author")):
continue
body = str(comment.get("body") or "")
for match in SHA_MARKER_RE.finditer(body):
if head_sha and match.group(1) == head_sha and not force_manual:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pr-triage-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ jobs:
? await client.paginate(client.rest.pulls.listReviews, { owner, repo, pull_number: prNumber, per_page: 100 })
: (await client.rest.pulls.listReviews({ owner, repo, pull_number: prNumber, per_page: 100 })).data;
const shaMarkerRe = new RegExp(`<!--\\s*(?:egm-triage-review|egm-triage-bot):sha=${plan.head_sha}\\s*-->`);
if (existingReviews.some(r => shaMarkerRe.test(String(r.body || "")))) {
// Anyone can paste a SHA marker, so only bot-authored markers count.
const isBot = user => Boolean(user) && (user.type === "Bot" || user.login === "egm-triage-bot");
Comment thread
gautamrn marked this conversation as resolved.
Resolved
if (existingReviews.some(r => isBot(r.user) && shaMarkerRe.test(String(r.body || "")))) {
core.info(`Skipping duplicate post for ${plan.head_sha}: SHA review marker already present.`);
return;
}
Expand Down
69 changes: 68 additions & 1 deletion tests/pr_triage_post.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ test('expired EGM_TRIAGE_BOT_TOKEN (HTTP 401) falls back to GITHUB_TOKEN via get

test('concurrent trigger race skips duplicate review when SHA marker already exists', async () => {
const state = createHarness({
existingReviews: [{ body: '<!-- egm-triage-review:sha=abc12345 -->\nClean pass.' }],
existingReviews: [{
user: { login: 'egm-triage-bot', type: 'User' },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking suggestion: updating this case to egm-triage-bot leaves the type === "Bot" arm untested. Adding cases for github-actions[bot] (type: 'Bot') and a deleted reviewer (user: null) would exercise the full isBot check.

@gautamrn gautamrn Nov 20, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for github-actions[bot] (type[bot]) and a deleted reviewer (user: null) in the latest commit

body: '<!-- egm-triage-review:sha=abc12345 -->\nClean pass.',
}],
})
await state.run({
action: 'clean_handoff',
Expand All @@ -237,3 +240,67 @@ test('concurrent trigger race skips duplicate review when SHA marker already exi
assert.equal(state.labels.size, 0)
assert.ok(state.infos.some(msg => /already present/.test(msg)))
})

test('SHA marker from the GITHUB_TOKEN fallback bot skips duplicate review', async () => {
const state = createHarness({
existingReviews: [{
user: { login: 'github-actions[bot]', type: 'Bot' },
body: '<!-- egm-triage-review:sha=abc12345 -->\nClean pass.',
}],
})
await state.run({
action: 'clean_handoff',
pr_number: 42,
head_sha: 'abc12345',
add_labels: ['triage: passed'],
remove_labels: [],
team_reviewers: ['egm-maintainers'],
review_payload: { commit_id: 'abc12345', body: 'Clean pass.', comments: [] },
})
assert.equal(state.failed, null)
assert.equal(state.reviews.length, 1)
assert.equal(state.labels.size, 0)
})

test('SHA marker from a deleted reviewer does not suppress the bot review', async () => {
const state = createHarness({
existingReviews: [{ user: null, body: '<!-- egm-triage-review:sha=abc12345 -->' }],
})
await state.run({
action: 'clean_handoff',
pr_number: 42,
head_sha: 'abc12345',
add_labels: ['triage: passed'],
remove_labels: [],
team_reviewers: ['egm-maintainers'],
review_payload: { commit_id: 'abc12345', body: 'Clean pass.', comments: [] },
})
assert.equal(state.failed, null)
assert.equal(state.reviews.length, 2)
assert.deepEqual([...state.labels], ['triage: passed'])
})

test('SHA marker in a human review does not suppress the bot review', async () => {
const state = createHarness({
existingReviews: [{
user: { login: 'alice', type: 'User' },
body: '<!-- egm-triage-review:sha=abc12345 -->',
}],
})
await state.run({
action: 'clean_handoff',
pr_number: 42,
head_sha: 'abc12345',
add_labels: ['triage: passed'],
remove_labels: [],
team_reviewers: ['egm-maintainers'],
review_payload: {
commit_id: 'abc12345',
body: '<!-- egm-triage-review:sha=abc12345 -->\nClean pass.',
comments: [],
},
})
assert.equal(state.failed, null)
assert.equal(state.reviews.length, 2)
assert.deepEqual([...state.labels], ['triage: passed'])
})
40 changes: 40 additions & 0 deletions tests/unit/test_pr_triage_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,46 @@ def test_evaluate_sweep_gate_uses_author_association_dynamically() -> None:
assert not same_sha.should_review
assert same_sha.reason == "SKIP_SHA_ALREADY_REVIEWED:deadbeef"

triage_bot = {
"user": {"login": "egm-triage-bot", "type": "User"},
"author_association": "MEMBER",
"body": "<!-- egm-triage-review:sha=deadbeef -->",
}
for reviews, issue_comments in (([triage_bot], []), ([], [triage_bot])):
bot_marker = review_pr.evaluate_sweep_gate(
{
"state": "open",
"draft": False,
"body": VALID_PR_BODY,
"user": {"login": "alice"},
"head": {"sha": "deadbeef"},
},
reviews=reviews,
issue_comments=issue_comments,
files=[{"filename": "README.md", "changes": 4}],
)
assert bot_marker.reason == "SKIP_SHA_ALREADY_REVIEWED:deadbeef"

spoofed = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking suggestion: same_sha above only covers github-actions[bot] in reviews. Adding a SKIP_SHA_ALREADY_REVIEWED check for egm-triage-bot (type: "User", author_association: "MEMBER") and a bot-authored marker in issue_comments would pin the primary paths too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added cases for an egm-triage-bot marker (type User, MEMBER) in both reviews and issue comments.

"user": {"login": "alice", "type": "User"},
"author_association": "CONTRIBUTOR",
"body": "<!-- egm-triage-review:sha=deadbeef -->",
}
for reviews, issue_comments in (([spoofed], []), ([], [spoofed])):
human_marker = review_pr.evaluate_sweep_gate(
{
"state": "open",
"draft": False,
"body": VALID_PR_BODY,
"user": {"login": "alice"},
"head": {"sha": "deadbeef"},
},
reviews=reviews,
issue_comments=issue_comments,
files=[{"filename": "README.md", "changes": 4}],
)
assert human_marker.should_review


def test_sanitization_nonce_boundary_and_source_first_diff_packing() -> None:
# Strips duplicate [High]: prefixes, BLUF labels, and neutralizes @mentions
Expand Down
Loading