Skip to content

Commit caa8fc5

Browse files
committed
fix(ci): rerun PR gate on review findings
1 parent 2468502 commit caa8fc5

3 files changed

Lines changed: 41 additions & 23 deletions

File tree

‎.github/scripts/enforce-pr-target.test.cjs‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ describe("enforce-pr-target workflow", () => {
4848
assert.match(workflow, /synchronize/);
4949
});
5050

51-
it("does not add review events that would break the trusted-base model", () => {
52-
// `pull_request_review` / `pull_request_review_comment` load the workflow
53-
// from the PR head branch (like `pull_request`), while this workflow's
54-
// checkout pins the base SHA — head YAML + base scripts mismatch, so the
55-
// gate crashes (`parseGateState is not a function`) and the head controls
56-
// the workflow definition under a write token. The findings claim runs on
57-
// every `pull_request_target` event instead (opened/edited/synchronize/
58-
// ready_for_review).
59-
assert.doesNotMatch(workflow, /^ pull_request_review:/m);
60-
assert.doesNotMatch(workflow, /^ pull_request_review_comment:/m);
51+
it("reruns when review findings are posted, changed, or removed", () => {
52+
assert.match(
53+
workflow,
54+
/^ pull_request_review:\n types:\n - submitted\n - edited\n - dismissed$/m,
55+
);
56+
assert.match(
57+
workflow,
58+
/^ pull_request_review_comment:\n types:\n - created\n - edited\n - deleted$/m,
59+
);
6160
});
6261

6362
it("queries review threads and feeds them to the findings claim check", () => {

‎.github/workflows/enforce-pr-target.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ on:
88
- edited
99
- ready_for_review
1010
- synchronize
11+
pull_request_review:
12+
types:
13+
- submitted
14+
- edited
15+
- dismissed
16+
pull_request_review_comment:
17+
types:
18+
- created
19+
- edited
20+
- deleted
1121

1222
# pull-requests:write covers title/comment/label updates.
1323
# contents:write is required for convertPullRequestToDraft /

‎tests/ci-workflows.test.ts‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,11 @@ describe("GitHub Actions hardening", () => {
675675
};
676676
type WorkflowJob = Record<string, unknown> & { "runs-on"?: unknown; steps?: WorkflowStep[] };
677677
type WorkflowShape = Record<string, unknown> & {
678-
on?: { pull_request_target?: { types?: string[] } };
678+
on?: {
679+
pull_request_target?: { types?: string[] };
680+
pull_request_review?: { types?: string[] };
681+
pull_request_review_comment?: { types?: string[] };
682+
};
679683
permissions?: Record<string, string> | string;
680684
concurrency?: Record<string, unknown> & { group?: string };
681685
jobs?: Record<string, WorkflowJob>;
@@ -828,13 +832,13 @@ describe("GitHub Actions hardening", () => {
828832
"permissions",
829833
]);
830834

831-
// pull_request_target runs with the base repo's token. Checking out or
832-
// executing the PR's code under it is the classic escalation. Review
833-
// events are deliberately NOT added: they load the workflow from the PR
834-
// head branch (like `pull_request`), which would run head-controlled
835-
// workflow YAML under a write token against base-pinned scripts — a
836-
// mismatch that crashes the gate and breaks the trusted-base model.
837-
expect(Object.keys(workflow.on ?? {})).toEqual(["pull_request_target"]);
835+
// The review triggers ensure findings posted after the initial target
836+
// event immediately invalidate the gate's previous verdict.
837+
expect(Object.keys(workflow.on ?? {})).toEqual([
838+
"pull_request_target",
839+
"pull_request_review",
840+
"pull_request_review_comment",
841+
]);
838842

839843
// And the trigger is exactly a `types:` list — nothing else.
840844
//
@@ -946,11 +950,16 @@ describe("GitHub Actions hardening", () => {
946950
"reopened",
947951
"synchronize",
948952
]);
949-
// Review events must NOT be added: they load the workflow from the PR
950-
// head branch, breaking the base-pinned checkout (`pull_request_review`
951-
// runs head YAML + base scripts → `parseGateState is not a function`).
952-
expect(workflow.on?.pull_request_review).toBeUndefined();
953-
expect(workflow.on?.pull_request_review_comment).toBeUndefined();
953+
expect(workflow.on?.pull_request_review?.types).toEqual([
954+
"submitted",
955+
"edited",
956+
"dismissed",
957+
]);
958+
expect(workflow.on?.pull_request_review_comment?.types).toEqual([
959+
"created",
960+
"edited",
961+
"deleted",
962+
]);
954963

955964
// The verdict is a live PR read plus ancestry/description checks.
956965
expect(script).toContain("github.rest.pulls.get");

0 commit comments

Comments
 (0)