From e3ab0a9ce152b3814b040234796d24f731ea0f70 Mon Sep 17 00:00:00 2001 From: fullsend-code <278716306+fullsend-ai-coder[bot]@users.noreply.github.com> Date: Mon, 9 Nov 2026 20:44:51 +0000 Subject: [PATCH 1/2] test(dispatch): cover pull_request in event mapping and routing tests Mirror the pull_request_target rows for pull_request in the gha-event, review and retro routing and bot-role tests, and name both events in the normalized-event raw_type docs and the poller comment. Part of #9221. --- docs/normative/normalized-event/v1/README.md | 8 +- internal/cli/dispatch_botrole_test.go | 80 +++++++++++++++++++ internal/cli/dispatch_route_test.go | 8 +- internal/cli/retro_route_test.go | 54 +++++++++++-- internal/cli/review_route_parity_test.go | 15 ++++ .../harnessdispatch/input/ghaevent_test.go | 72 +++++++++++++++++ internal/poll/events.go | 5 +- 7 files changed, 229 insertions(+), 13 deletions(-) diff --git a/docs/normative/normalized-event/v1/README.md b/docs/normative/normalized-event/v1/README.md index e4c54459e8..0913072acc 100644 --- a/docs/normative/normalized-event/v1/README.md +++ b/docs/normative/normalized-event/v1/README.md @@ -455,9 +455,11 @@ contract): | `run-url` | Runtime-only; set by the dispatch workflow, not projected from `NormalizedEvent` | **`event_type` / `pull_request_target`:** v1 preserves the GitHub Actions event -name in `source.raw_type`. When the workflow runs on `pull_request_target`, -adapters emit `raw_type: "pull_request_target"` (not normalized to -`pull_request`) so downstream routing matches today's dispatch behavior. +name in `source.raw_type`, never normalized. When the workflow runs on +`pull_request_target`, adapters emit `raw_type: "pull_request_target"`; when it +runs on `pull_request`, they emit `raw_type: "pull_request"`. Both map to the +same entity, transition, actor and state, so downstream routing treats them +alike; only `raw_type` tells them apart. **`trigger_source` (fix agent only):** this field is emitted only for the fix harness execution ref. When `transition.kind == "review_submitted"`, set diff --git a/internal/cli/dispatch_botrole_test.go b/internal/cli/dispatch_botrole_test.go index 675ae82713..5b1c90a448 100644 --- a/internal/cli/dispatch_botrole_test.go +++ b/internal/cli/dispatch_botrole_test.go @@ -426,6 +426,86 @@ func TestRunDispatch_GHAEventBotRoleRoute(t *testing.T) { } } +// TestRunDispatch_GHAEventBotRolePullRequest checks that a bot-authored +// pull_request event (sent by per-repo shims on the pull_request trigger) +// behaves like the pull_request_target one: the bot-role lookup runs and +// decides the dispatch matrix and the --route decision the same way. +func TestRunDispatch_GHAEventBotRolePullRequest(t *testing.T) { + writePullRequestBotEvent := func(t *testing.T, action, label string) { + t.Helper() + writeGHABotPREvent(t, action, label) + t.Setenv("GITHUB_EVENT_NAME", "pull_request") + } + + matrixCases := []struct { + name string + action string + label string + resolver *fakeBotRoleResolver + wantProbe bool + wantQueried bool + }{ + {name: "recognized bot dispatches", action: "opened", resolver: &fakeBotRoleResolver{role: "coder"}, wantProbe: true, wantQueried: true}, + {name: "unregistered bot is denied", action: "opened", resolver: &fakeBotRoleResolver{}, wantQueried: true}, + {name: "lookup failure is denied without an error", action: "opened", resolver: &fakeBotRoleResolver{err: errFakeLookup}, wantQueried: true}, + {name: "label added by an unregistered bot is the control", action: "labeled", label: "ready-for-probe", resolver: &fakeBotRoleResolver{err: errFakeLookup}, wantProbe: true}, + } + for _, tc := range matrixCases { + t.Run("matrix/"+tc.name, func(t *testing.T) { + dir := writeBotProbeFixture(t) + writePullRequestBotEvent(t, tc.action, tc.label) + useBotRoleResolver(t, tc.resolver) + + out, err := captureDispatch(t, dispatchOpts{inputDriver: "gha-event", outputDriver: "gha-matrix", configDir: dir}) + require.NoError(t, err) + var matrix struct { + Include []map[string]any `json:"include"` + } + require.NoError(t, json.Unmarshal([]byte(strings.TrimSpace(out)), &matrix), "matrix: %q", out) + if tc.wantProbe { + require.Len(t, matrix.Include, 1) + assert.Equal(t, "bot-probe", matrix.Include[0]["agent"]) + } else { + assert.Empty(t, matrix.Include) + } + assert.Equal(t, tc.wantQueried, len(tc.resolver.queries) == 1, "queries: %v", tc.resolver.queries) + }) + } + + routeCases := []struct { + name string + resolver *fakeBotRoleResolver + wantDecision string + wantReason string + }{ + {name: "recognized bot runs", resolver: &fakeBotRoleResolver{role: "coder"}, wantDecision: routeRun, wantReason: "trigger matched"}, + {name: "unregistered bot skips", resolver: &fakeBotRoleResolver{}, wantDecision: routeSkip, wantReason: "bot has no registered role"}, + {name: "lookup failure skips", resolver: &fakeBotRoleResolver{err: errFakeLookup}, wantDecision: routeSkip, wantReason: "bot-role lookup failed"}, + } + for _, tc := range routeCases { + t.Run("route/"+tc.name, func(t *testing.T) { + dir := writeRouteFixture(t, routeFixture{ + agents: []config.AgentEntry{{ + Name: "review", + Source: "harness/review.yaml", + Trigger: `event.entity.kind == "change_proposal" && event.transition.kind == "opened"`, + }}, + files: map[string]string{"harness/review.yaml": routeTestHarnessBody}, + }) + writePullRequestBotEvent(t, "opened", "") + useBotRoleResolver(t, tc.resolver) + + out, err := captureDispatch(t, dispatchOpts{inputDriver: "gha-event", configDir: dir, route: "review"}) + require.NoError(t, err) + var got routeDecision + require.NoError(t, json.Unmarshal([]byte(strings.TrimSpace(out)), &got), "decision: %q", out) + assert.Equal(t, tc.wantDecision, got.Decision) + assert.Equal(t, tc.wantReason, got.Reason) + require.Len(t, tc.resolver.queries, 1) + }) + } +} + // envMintServers serves the Actions OIDC token endpoint and a mint that // recognizes every bot as coder, points FULLSEND_MINT_URL and the Actions OIDC // environment at them, and returns a counter of mint lookups. A lookup that diff --git a/internal/cli/dispatch_route_test.go b/internal/cli/dispatch_route_test.go index 6d746bed9c..3464641539 100644 --- a/internal/cli/dispatch_route_test.go +++ b/internal/cli/dispatch_route_test.go @@ -432,7 +432,10 @@ func TestReviewRouteAccepts(t *testing.T) { event string want bool }{ - "PR opened": {routePROpened, true}, + "PR opened": {routePROpened, true}, + "PR opened (pull_request)": { + strings.Replace(routePROpened, `"raw_type": "pull_request_target"`, `"raw_type": "pull_request"`, 1), true, + }, "comment on a PR": {routeReviewComment, true}, "comment on an issue": {routeIssueReviewComment, false}, } @@ -993,6 +996,9 @@ func TestRouteBuiltinAgent_ErrorsAndEvaluationFailures(t *testing.T) { "retro": { "write actor": routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroWriter, "pull_request_target", "closed"), "triage actor": routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroTriager, "pull_request_target", "closed"), + // Shims on the pull_request trigger send pull_request closes. + "write actor (pull_request)": routeRetroEvent(routeRetroPR, routeRetroMerged, routeRetroWriter, "pull_request", "closed"), + "triage actor (pull_request)": routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroTriager, "pull_request", "closed"), }, "triage": { "write actor": routeIssueTriageComment, diff --git a/internal/cli/retro_route_test.go b/internal/cli/retro_route_test.go index 4a8c5d06c2..fee8a7c14e 100644 --- a/internal/cli/retro_route_test.go +++ b/internal/cli/retro_route_test.go @@ -76,13 +76,15 @@ func TestRetroRouteAccepts(t *testing.T) { event string want bool }{ - "PR closed": {routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroWriter, "pull_request_target", "closed"), true}, - "PR merged": {routeRetroEvent(routeRetroPR, routeRetroMerged, routeRetroWriter, "pull_request_target", "closed"), true}, - "/fs-retro on a PR": {routeRetroEvent(routeRetroPR, routeRetroCommand, routeRetroWriter, "issue_comment", "created"), true}, - "/fs-retro on issue": {routeRetroEvent(routeRetroIssue, routeRetroCommand, routeRetroWriter, "issue_comment", "created"), true}, - "/fs-review on a PR": {routeRetroEvent(routeRetroPR, routeRetroOtherCommand, routeRetroWriter, "issue_comment", "created"), false}, - "issue closed": {routeRetroEvent(routeRetroIssue, routeRetroClosed, routeRetroWriter, "issues", "closed"), false}, - "PR opened": {routePROpened, false}, + "PR closed": {routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroWriter, "pull_request_target", "closed"), true}, + "PR merged": {routeRetroEvent(routeRetroPR, routeRetroMerged, routeRetroWriter, "pull_request_target", "closed"), true}, + "PR closed (pull_request)": {routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroWriter, "pull_request", "closed"), true}, + "PR merged (pull_request)": {routeRetroEvent(routeRetroPR, routeRetroMerged, routeRetroWriter, "pull_request", "closed"), true}, + "/fs-retro on a PR": {routeRetroEvent(routeRetroPR, routeRetroCommand, routeRetroWriter, "issue_comment", "created"), true}, + "/fs-retro on issue": {routeRetroEvent(routeRetroIssue, routeRetroCommand, routeRetroWriter, "issue_comment", "created"), true}, + "/fs-review on a PR": {routeRetroEvent(routeRetroPR, routeRetroOtherCommand, routeRetroWriter, "issue_comment", "created"), false}, + "issue closed": {routeRetroEvent(routeRetroIssue, routeRetroClosed, routeRetroWriter, "issues", "closed"), false}, + "PR opened": {routePROpened, false}, } for name, tc := range cases { t.Run(name, func(t *testing.T) { @@ -146,6 +148,30 @@ func TestRouteBuiltinAgent_Retro(t *testing.T) { event: routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroTriager, "pull_request_target", "closed"), wantDecision: routeSkip, wantReason: "closed pull request retro requires write", }, + { + name: "pull_request: PR merged by a write user starts a retro", + agents: []config.AgentEntry{{Name: "retro", Trigger: routeTrigger(t, "retro")}}, + event: routeRetroEvent(routeRetroPR, routeRetroMerged, routeRetroWriter, "pull_request", "closed"), + wantDecision: routeRun, + }, + { + name: "pull_request: PR closed by its read-only author starts a retro (lifecycle-close exception)", + agents: []config.AgentEntry{{Name: "retro", Trigger: routeTrigger(t, "retro")}}, + event: routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroReadAuthor, "pull_request", "closed"), + wantDecision: routeRun, + }, + { + name: "pull_request: PR closed by an app bot without a role starts a retro (lifecycle-close exception)", + agents: []config.AgentEntry{{Name: "retro", Trigger: routeTrigger(t, "retro")}}, + event: routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroAppBot, "pull_request", "closed"), + wantDecision: routeRun, + }, + { + name: "pull_request: PR closed by a triage user starts a retro (lifecycle-close exception)", + agents: []config.AgentEntry{{Name: "retro", Trigger: routeTrigger(t, "retro")}}, + event: routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroTriager, "pull_request", "closed"), + wantDecision: routeRun, + }, { name: "/fs-retro from a triage user is not authorized", agents: []config.AgentEntry{{Name: "retro", Trigger: routeTrigger(t, "retro")}}, @@ -414,6 +440,20 @@ func TestRetroRouteParity(t *testing.T) { }, } + // Per-repo shims on the pull_request trigger send pull_request; older + // shims keep sending pull_request_target. Retro routes and authorizes + // both alike, so every pull_request_target row is mirrored as a + // pull_request row with the same expectations. + for _, tc := range cases { + if tc.eventName != "pull_request_target" { + continue + } + mirrored := tc + mirrored.name = tc.name + " (pull_request)" + mirrored.eventName = "pull_request" + cases = append(cases, mirrored) + } + for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { eventPath := filepath.Join(t.TempDir(), "event.json") diff --git a/internal/cli/review_route_parity_test.go b/internal/cli/review_route_parity_test.go index 61fa4719b7..3958e06b4c 100644 --- a/internal/cli/review_route_parity_test.go +++ b/internal/cli/review_route_parity_test.go @@ -166,6 +166,21 @@ func TestReviewRouteParity(t *testing.T) { }, } + // Per-repo shims on the pull_request trigger (same-repo PRs) send + // pull_request; older shims keep sending pull_request_target. Both the + // bash router and the CEL route treat the two alike, so every + // pull_request_target row is mirrored as a pull_request row with the + // same expectations. + for _, tc := range cases { + if tc.eventName != "pull_request_target" { + continue + } + mirrored := tc + mirrored.name = tc.name + " (pull_request)" + mirrored.eventName = "pull_request" + cases = append(cases, mirrored) + } + for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { eventPath := filepath.Join(t.TempDir(), "event.json") diff --git a/internal/harnessdispatch/input/ghaevent_test.go b/internal/harnessdispatch/input/ghaevent_test.go index 99cc67c015..083e9c62e5 100644 --- a/internal/harnessdispatch/input/ghaevent_test.go +++ b/internal/harnessdispatch/input/ghaevent_test.go @@ -763,6 +763,78 @@ func TestLoadGHAEvent_PRAssignee(t *testing.T) { }) } +// TestLoadGHAEvent_PullRequestMatchesPullRequestTarget pins that the same +// payload delivered as pull_request (the per-repo shim's same-repo trigger) +// or pull_request_target (older shims) normalizes identically, except that +// source.raw_type keeps the exact GitHub Actions event name. +func TestLoadGHAEvent_PullRequestMatchesPullRequestTarget(t *testing.T) { + pr := func(author string, merged bool, labels ...string) map[string]any { + labelList := []any{} + for _, l := range labels { + labelList = append(labelList, map[string]any{"name": l}) + } + return map[string]any{ + "number": float64(100), + "html_url": "https://github.com/o/r/pull/100", + "user": map[string]any{"login": author}, + "labels": labelList, + "merged": merged, + "assignees": []any{map[string]any{"login": "alice"}}, + "head": map[string]any{ + "ref": "feature", + "sha": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + "repo": map[string]any{"full_name": "o/r"}, + }, + "base": map[string]any{ + "ref": "main", + "repo": map[string]any{"full_name": "o/r"}, + }, + } + } + human := map[string]any{"login": "alice", "type": "User"} + bot := map[string]any{"login": "myapp-coder[bot]", "type": "Bot"} + + payloads := map[string]map[string]any{ + "opened": {"action": "opened", "pull_request": pr("alice", false), "sender": human}, + "opened by bot": {"action": "opened", "pull_request": pr("myapp-coder[bot]", false), "sender": bot}, + "synchronize": {"action": "synchronize", "pull_request": pr("alice", false), "sender": human}, + "edited": {"action": "edited", "pull_request": pr("alice", false), "sender": human}, + "closed (merged)": {"action": "closed", "pull_request": pr("alice", true), "sender": human}, + "closed (unmerged)": {"action": "closed", "pull_request": pr("alice", false), "sender": human}, + "labeled": { + "action": "labeled", "pull_request": pr("alice", false, "ready-for-review"), + "label": map[string]any{"name": "ready-for-review"}, "sender": human, + }, + } + + load := func(t *testing.T, raw map[string]any, eventName string) *normevent.Event { + t.Helper() + client := forge.NewFakeClient() + client.CollaboratorPermissions = map[string]string{"o/r/alice": "write"} + ev, err := input.LoadGHAEvent(context.Background(), input.GHAEventOptions{ + EventPath: writeEventFile(t, raw), + EventName: eventName, + Repository: "o/r", + Forge: client, + }) + require.NoError(t, err) + return ev + } + + for name, raw := range payloads { + t.Run(name, func(t *testing.T) { + target := load(t, raw, "pull_request_target") + plain := load(t, raw, "pull_request") + + assert.Equal(t, "pull_request_target", target.Source.RawType) + assert.Equal(t, "pull_request", plain.Source.RawType, "raw_type is the exact event name, never normalized") + + plain.Source.RawType = target.Source.RawType + assert.Equal(t, target, plain) + }) + } +} + func copyMap(m map[string]any) map[string]any { out := make(map[string]any, len(m)) for k, v := range m { diff --git a/internal/poll/events.go b/internal/poll/events.go index 62a7aaa9c2..eab587ab33 100644 --- a/internal/poll/events.go +++ b/internal/poll/events.go @@ -637,8 +637,9 @@ func (p *Poller) filterBotEvents(events []RoutableEvent) []RoutableEvent { } // Bot-authored MR opens must dispatch review — the code agent // opens MRs as the project access token bot, matching GitHub's - // [bot] exception on pull_request_target.opened. Bot-authored - // closes and merges are both filtered: they are the enrolled + // [bot] exception on pull_request.opened / + // pull_request_target.opened. Bot-authored closes and merges + // are both filtered: they are the enrolled // bot's own lifecycle actions (e.g. closeStaleScaffoldPRs // closing the bot's own stale scaffold MRs) and must not spawn // retro pipelines for the bot's own cleanup. A human close is From 1403d433c7199fc2c2221362810bc109687c7e4b Mon Sep 17 00:00:00 2001 From: Wayne Sun Date: Mon, 9 Nov 2026 15:30:28 -0500 Subject: [PATCH 2/2] fix(dispatch)!: move the fullsend shim from pull_request_target to pull_request GitHub blocks pull_request_target by default in public repositories from 2026-12-02 (#9221). Follow github/gh-aw: the shim triggers on pull_request for same-repo PRs only (head.repo.id == github.repository_id); fork PRs are reviewed when a maintainer comments /fs-review (ADR 0164). - shim template and fullsend's own fullsend.yaml: pull_request trigger plus the same-repo guard. - reusable-dispatch.yml: - route pull_request like pull_request_target; warn when a public repository's caller still uses pull_request_target, which keeps working; - never route a fork or Dependabot PR on pull_request, in bash, CEL, the pre-routing review-dedup steps and the harness jobs. A pull_request run uses the PR's own copy of the shim, so a fork can drop the shim guard; Dependabot runs get only Dependabot secrets; - base side for every checkout on pull_request: base.sha where a ref is pinned, the default branch for the target-repo checkouts that used the event default (github.ref was the default branch on pull_request_target, it is the merge commit on pull_request); - job.workflow_sha reads use base.sha on pull_request when the reusable workflow is called with ./ (vendored installs), where job.workflow_sha is the PR merge commit; - the synchronize review-dedup steps and the closed-PR fail-closed flag (CLOSED_PULL_REQUEST) cover pull_request too. - reusable-prioritize.yml: same checkout and workflow_sha rules. - hack/workflow_triggers_test.py: no workflow is exempt any more. - scaffold tests: shim trigger and guard, every checkout has a trusted ref, every job.workflow_sha read is trusted, harness and dedup guards, routing of same-repo, fork, Dependabot and pull_request_target events, the write-gated close on both events, and a scan that fails on any line branching on pull_request_target without pull_request. - behaviour tests: fork PR scenarios expect no dispatch from fork PR events (open, label, push) and dispatch from a maintainer comment on the fork PR (new step "the posts ... on the fork pull request"); the outsider fork scenario checks the outsider's comment is denied; the GitHub Actions BT driver treats action_required runs (held for approval) as runs that ran no job; fork step trigger times are truncated. - docs: required-upgrade section (merge-conflict PRs, forks, Dependabot, private repositories, vendored installs), troubleshooting entry, ADR 0164 links, user and contributor guides, normative headings. BREAKING CHANGE: after upgrading, fork PRs and Dependabot-triggered events are no longer reviewed or retro'd automatically; someone with triage access or higher comments /fs-review instead. Assisted-by: Claude (fix, review), DeepSeek (review), Gemini (docs review) Signed-off-by: Wayne Sun --- .github/workflows/fullsend.yaml | 21 +- .github/workflows/reusable-dispatch.yml | 166 ++++++--- .github/workflows/reusable-prioritize.yml | 6 +- docs/agents/retro.md | 11 +- docs/agents/review.md | 5 +- docs/architecture.md | 6 +- docs/contributing/ci-workflows.md | 2 +- docs/guides/dev/behaviour-testing.md | 14 +- .../guides/getting-started/repo-management.md | 53 +++ .../openai-workload-identity.md | 3 +- docs/guides/user/bugfix-workflow.md | 6 +- docs/guides/user/cel-triggers-reference.md | 22 +- .../user/chaining-follow-up-workflows.md | 9 +- docs/guides/user/customizing-agents.md | 13 +- docs/guides/user/owners-file-authorization.md | 2 +- docs/normative/authorization/v1/README.md | 7 +- docs/normative/authorization/v2/README.md | 7 +- docs/normative/normalized-event/v1/README.md | 2 +- docs/problems/gitlab-implementation.md | 2 +- docs/problems/platform-nativeness.md | 4 +- .../dispatch/fork-bash-routing.feature | 16 +- .../features/dispatch/fork-dispatch.feature | 77 +++-- .../platform/actor-authorization.feature | 17 +- hack/workflow_triggers_test.py | 10 - internal/cli/prepareartifacts.go | 7 +- internal/cli/retro_route_test.go | 12 +- internal/scaffold/cel_route_test.go | 73 ++-- .../templates/shim-per-repo.yaml | 21 +- internal/scaffold/pr_trigger_test.go | 315 ++++++++++++++++++ .../ci/githubactions/dispatch_reads_test.go | 27 +- .../ci/githubactions/empty_matrix_test.go | 2 + .../drivers/ci/githubactions/githubactions.go | 19 +- pkg/behaviourtest/steps/actors.go | 22 ++ pkg/behaviourtest/steps/actors_test.go | 22 +- pkg/behaviourtest/steps/fork.go | 9 +- 35 files changed, 793 insertions(+), 217 deletions(-) create mode 100644 internal/scaffold/pr_trigger_test.go diff --git a/.github/workflows/fullsend.yaml b/.github/workflows/fullsend.yaml index 3d62f72968..12034cf404 100644 --- a/.github/workflows/fullsend.yaml +++ b/.github/workflows/fullsend.yaml @@ -5,10 +5,17 @@ # Routes events to agent workflows via reusable-dispatch.yml. # All agent execution happens in this repository's context. # -# Security: pull_request_target runs the BASE branch version of this workflow, -# preventing PRs from modifying it to exfiltrate credentials. -# This shim never checks out PR code, so it is not vulnerable to "pwn request" -# attacks. +# Security: pull request events use pull_request, not pull_request_target +# (GitHub blocks pull_request_target by default in public repositories; +# ADR 0164). On pull_request this workflow runs from the PR's own +# copy and forwards the repository secrets, so the dispatch job runs only for +# same-repo PRs, whose authors already have write access. Fork PRs are skipped +# here and again in reusable-dispatch.yml (a fork cannot edit the upstream +# copy; a vendored copy runs from the PR); a maintainer comments /fs-review +# to review one. In private repositories keep "Send secrets to workflows +# from pull requests" and "Send write tokens to workflows from pull +# requests" (Settings > Actions > General) turned off. +# reusable-dispatch.yml checks out the base side for pull request events. # # Routing: this shim forwards the raw event context to reusable-dispatch.yml, # which determines the stage and runs the agent inline (ADR 62). @@ -23,7 +30,7 @@ on: types: [opened, edited, labeled] issue_comment: types: [created] - pull_request_target: + pull_request: types: [opened, synchronize, ready_for_review, closed, labeled, unlabeled] pull_request_review: types: [submitted] @@ -33,8 +40,10 @@ permissions: {} jobs: dispatch: if: >- - (github.event_name != 'pull_request_target' && github.event_name != 'pull_request_review' + (github.event_name != 'pull_request' && github.event_name != 'pull_request_review' || github.event.pull_request.head.ref != 'fullsend/scaffold-install') + && (github.event_name != 'pull_request' + || github.event.pull_request.head.repo.id == github.repository_id) && (github.event_name != 'issue_comment' || startsWith(github.event.comment.body, '/fs-')) permissions: diff --git a/.github/workflows/reusable-dispatch.yml b/.github/workflows/reusable-dispatch.yml index cf6ac2b02a..909b59de78 100644 --- a/.github/workflows/reusable-dispatch.yml +++ b/.github/workflows/reusable-dispatch.yml @@ -161,7 +161,7 @@ jobs: # is executed, and credentials are not persisted. Pin to base branch # SHA for PR-scoped events so kill-switch / role gating always reads # trusted config — PR authors cannot self-authorize. - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} sparse-checkout: | @@ -203,6 +203,8 @@ jobs: PR_HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} PR_BASE_REPO: ${{ github.event.pull_request.base.repo.full_name }} PR_USER_LOGIN: ${{ github.event.pull_request.user.login }} + EVENT_ACTOR: ${{ github.actor }} + REPO_VISIBILITY: ${{ github.event.repository.visibility }} ORG_NAME: ${{ github.repository_owner }} FULLSEND_APP_SET: ${{ vars.FULLSEND_APP_SET || 'fullsend-ai' }} GH_TOKEN: ${{ github.token }} @@ -408,7 +410,37 @@ jobs: fi ;; - pull_request_target) + pull_request_target|pull_request) + # pull_request is the shim trigger from #9221 on (GitHub blocks + # pull_request_target by default in public repos from + # 2026-12-02). pull_request_target stays routed the same way so + # shims that have not upgraded keep working until they do. + # GitHub blocks pull_request_target by default only in public + # repositories, so only those get the upgrade warning. + if [[ "${EVENT_NAME}" == "pull_request_target" && "${REPO_VISIBILITY:-}" == "public" ]]; then + echo "::warning::This repository's fullsend shim still triggers on pull_request_target, which GitHub blocks by default in public repositories from its announced enforcement date. Re-run 'fullsend repos install' to move the shim to pull_request." + fi + # The shim skips fork PRs on pull_request with a same-repo guard, + # but a pull_request run uses the PR's own copy of the shim, so a + # fork can drop that guard. Upstream installs call this file from + # fullsend, which a fork cannot edit, so this re-check holds there + # (vendored installs run their own copy, and depend on GitHub not + # sending secrets to fork PR runs). A fork PR is never routed on + # pull_request; a maintainer comments /fs-review instead. Missing + # repo names also skip. + if [[ "${EVENT_NAME}" == "pull_request" ]] && [[ -z "${PR_HEAD_REPO:-}" || "${PR_HEAD_REPO:-}" != "${PR_BASE_REPO:-}" ]]; then + echo "::notice::Fork pull request on pull_request: not routed. A maintainer can comment /fs-review to review it." + echo "stage=" >> "${GITHUB_OUTPUT}" + exit 0 + fi + # GitHub gives pull_request runs triggered by Dependabot only + # Dependabot secrets, so an agent run would fail. Skip it; a + # maintainer's /fs-review runs with the repository's secrets. + if [[ "${EVENT_NAME}" == "pull_request" && "${EVENT_ACTOR:-}" == "dependabot[bot]" ]]; then + echo "::notice::Dependabot pull request on pull_request: not routed. A maintainer can comment /fs-review to review it." + echo "stage=" >> "${GITHUB_OUTPUT}" + exit 0 + fi case "${EVENT_ACTION}" in opened|synchronize|ready_for_review) if [[ "${PR_USER_LOGIN}" =~ \[bot\]$ ]] || is_event_actor_authorized "${PR_USER_LOGIN}" triage; then @@ -474,7 +506,7 @@ jobs: # still enforce the same policy for the final routed stage. - name: Check review deduplication guards id: review-dedup-guard - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]')) shell: bash run: | set -euo pipefail @@ -525,13 +557,13 @@ jobs: # runs. Vendored callers already provide it in the caller checkout; # fetch only this script for callers using upstream defaults. - name: Checkout review diff canonicalizer - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.review-dedup-guard.outputs.allowed == 'true' && hashFiles('.defaults/action.yml', '.fullsend/.defaults/action.yml') == '' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]')) && steps.review-dedup-guard.outputs.allowed == 'true' && hashFiles('.defaults/action.yml', '.fullsend/.defaults/action.yml') == '' continue-on-error: true timeout-minutes: 2 uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .review-diff-defaults fetch-depth: 1 sparse-checkout: | @@ -544,7 +576,7 @@ jobs: # Missing or incomplete metadata deliberately fails open. - name: Check unchanged review diff id: review-diff - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.review-dedup-guard.outputs.allowed == 'true' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]')) && steps.review-dedup-guard.outputs.allowed == 'true' env: GH_TOKEN: ${{ github.token }} SOURCE_REPO: ${{ github.repository }} @@ -741,7 +773,9 @@ jobs: # entry "Finalize stage" passes the authorized bash stage through. - name: Detect CEL route opt-in id: cel-opt-in - if: ${{ github.event_name == 'pull_request_target' || github.event_name == 'issue_comment' || github.event_name == 'issues' }} + # A fork or Dependabot PR on pull_request is never routed (see + # "Determine stage"), by CEL either: a maintainer comments /fs-review. + if: ${{ github.event_name == 'pull_request_target' || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]')) || github.event_name == 'issue_comment' || github.event_name == 'issues' }} continue-on-error: true shell: bash env: @@ -772,14 +806,18 @@ jobs: # Same parsing as "Determine stage". COMMAND="$(printf '%s\n' "${COMMENT_BODY}" | head -1 | tr -d '\r' | awk '{print $1}' | sed 's/[.,;:!?]*$//')" fi + IS_PR_EVENT=false + if [[ "${EVENT_NAME}" == "pull_request_target" || "${EVENT_NAME}" == "pull_request" ]]; then + IS_PR_EVENT=true + fi PR_CLOSED=false - if [[ "${EVENT_NAME}" == "pull_request_target" && "${EVENT_ACTION:-}" == "closed" ]]; then + if [[ "${IS_PR_EVENT}" == "true" && "${EVENT_ACTION:-}" == "closed" ]]; then PR_CLOSED=true fi fits="" # review: pull request events other than closed, and comments on a # pull request. - if [[ ( "${EVENT_NAME}" == "pull_request_target" && "${PR_CLOSED}" == "false" ) || ( "${EVENT_NAME}" == "issue_comment" && "${ISSUE_IS_PR}" == "true" ) ]]; then + if [[ ( "${IS_PR_EVENT}" == "true" && "${PR_CLOSED}" == "false" ) || ( "${EVENT_NAME}" == "issue_comment" && "${ISSUE_IS_PR}" == "true" ) ]]; then fits+=" review" fi # retro: a closed pull request, and comments on an issue or a pull @@ -817,7 +855,7 @@ jobs: agent="triage" elif [[ "${PR_CLOSED}" == "true" ]]; then agent="retro" - elif [[ "${EVENT_NAME}" == "pull_request_target" ]]; then + elif [[ "${IS_PR_EVENT}" == "true" ]]; then agent="review" fi @@ -880,7 +918,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: # Same trusted ref as the checkout above: the base branch for PR events. - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} path: cel-route persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -913,7 +951,7 @@ jobs: uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ${{ runner.temp }}/fullsend-cache - key: fullsend-cli-${{ steps.cel-cli-mode.outputs.mode }}-${{ job.workflow_sha }} + key: fullsend-cli-${{ steps.cel-cli-mode.outputs.mode }}-${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} # Vendored installs copy the committed binary directly, so the step does # not depend on where the vendored defaults (.defaults/ or @@ -939,7 +977,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .workflow-actions fetch-depth: 1 sparse-checkout: | @@ -957,7 +995,7 @@ jobs: with: mode: upstream workflow_repository: ${{ job.workflow_repository }} - workflow_sha: ${{ job.workflow_sha }} + workflow_sha: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} github_token: ${{ github.token }} - name: Expose cached fullsend CLI for CEL route @@ -987,7 +1025,7 @@ jobs: uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ${{ runner.temp }}/fullsend-cache - key: fullsend-cli-${{ steps.cel-cli-mode.outputs.mode }}-${{ job.workflow_sha }} + key: fullsend-cli-${{ steps.cel-cli-mode.outputs.mode }}-${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - name: Evaluate CEL route id: cel-route @@ -1041,7 +1079,7 @@ jobs: env: BASH_STAGE: ${{ steps.bash-route.outputs.stage }} BASH_TRIGGER_SOURCE: ${{ steps.bash-route.outputs.trigger_source }} - CLOSED_PULL_REQUEST: ${{ github.event_name == 'pull_request_target' && inputs.event_action == 'closed' }} + CLOSED_PULL_REQUEST: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'closed' }} ROUTE_AGENT: ${{ steps.cel-opt-in.outputs.agent }} CEL_OPT_IN_OUTCOME: ${{ steps.cel-opt-in.outcome }} CEL_CONFIG_OUTCOME: ${{ steps.cel-config.outcome }} @@ -1120,13 +1158,13 @@ jobs: # Only obtain a write-capable review token after final routing has # authorized the review stage. The diff check above remains read-only. - name: Checkout upstream defaults for review skip note - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.defaults/action.yml', '.fullsend/.defaults/action.yml') == '' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.defaults/action.yml', '.fullsend/.defaults/action.yml') == '' continue-on-error: true timeout-minutes: 2 uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -1135,7 +1173,7 @@ jobs: sparse-checkout-cone-mode: false - name: Prepare workspace for review skip note - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') == '' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') == '' id: review-token-workspace continue-on-error: true timeout-minutes: 2 @@ -1147,12 +1185,12 @@ jobs: # .defaults path internally. Provide that compatibility path while # the action's defaults_root input is adopted by existing callers. - name: Stage nested defaults compatibility path - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') != '' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') != '' shell: bash run: ln -s .fullsend/.defaults .defaults - name: Prepare workspace for review skip note (nested vendor) - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') != '' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') != '' id: review-token-workspace-nested continue-on-error: true timeout-minutes: 2 @@ -1162,7 +1200,7 @@ jobs: source_repo: ${{ github.repository }} - name: Mint review token for review skip note - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') == '' && steps.review-token-workspace.outcome == 'success' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') == '' && steps.review-token-workspace.outcome == 'success' id: review-token continue-on-error: true timeout-minutes: 2 @@ -1174,7 +1212,7 @@ jobs: mint_url: ${{ inputs.mint_url }} - name: Mint review token for review skip note (nested vendor) - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') != '' && steps.review-token-workspace-nested.outcome == 'success' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' && hashFiles('.fullsend/.defaults/action.yml') != '' && steps.review-token-workspace-nested.outcome == 'success' id: review-token-nested continue-on-error: true timeout-minutes: 2 @@ -1187,7 +1225,7 @@ jobs: - name: Publish review skip note id: review-skip-publish - if: github.event_name == 'pull_request_target' && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' + if: (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && inputs.event_action == 'synchronize' && steps.route.outputs.stage == 'review' && steps.review-diff.outputs.skip == 'true' continue-on-error: true env: GH_TOKEN: ${{ steps.review-token.outputs.token || steps.review-token-nested.outputs.token || github.token }} @@ -1494,7 +1532,7 @@ jobs: - name: Checkout caller repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -1503,7 +1541,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -1534,6 +1572,10 @@ jobs: path: target-repo fetch-depth: 1 persist-credentials: false + # With no ref, checkout uses github.ref: the default branch on + # pull_request_target, the PR merge commit on pull_request. Keep the + # default branch on pull_request (#9221). + ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} - name: Setup agent environment env: @@ -1582,7 +1624,7 @@ jobs: jira-client-secret: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} fullsend-dir: .fullsend - version: ${{ inputs.fullsend_version || job.workflow_sha }} + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} @@ -1610,7 +1652,7 @@ jobs: - name: Checkout caller repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -1619,7 +1661,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -1650,6 +1692,10 @@ jobs: path: target-repo fetch-depth: 0 persist-credentials: false + # With no ref, checkout uses github.ref: the default branch on + # pull_request_target, the PR merge commit on pull_request. Keep the + # default branch on pull_request (#9221). + ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} - name: Resolve bot identity env: @@ -1718,7 +1764,7 @@ jobs: jira-client-secret: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} fullsend-dir: .fullsend - version: ${{ inputs.fullsend_version || job.workflow_sha }} + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} @@ -1745,7 +1791,7 @@ jobs: - name: Checkout caller repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -1754,7 +1800,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -1785,6 +1831,10 @@ jobs: path: target-repo fetch-depth: 1 persist-credentials: false + # With no ref, checkout uses github.ref: the default branch on + # pull_request_target, the PR merge commit on pull_request. Keep the + # default branch on pull_request (#9221). + ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} - name: Pre-fetch prior review context id: prior-review @@ -1895,7 +1945,7 @@ jobs: jira-client-secret: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} fullsend-dir: .fullsend - version: ${{ inputs.fullsend_version || job.workflow_sha }} + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} @@ -1923,7 +1973,7 @@ jobs: - name: Checkout caller repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -1932,7 +1982,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -2163,7 +2213,7 @@ jobs: jira-client-secret: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} fullsend-dir: .fullsend - version: ${{ inputs.fullsend_version || job.workflow_sha }} + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ steps.context.outputs.pr_number }} @@ -2189,7 +2239,7 @@ jobs: - name: Checkout caller repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -2198,7 +2248,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -2229,6 +2279,10 @@ jobs: path: target-repo fetch-depth: 1 persist-credentials: false + # With no ref, checkout uses github.ref: the default branch on + # pull_request_target, the PR merge commit on pull_request. Keep the + # default branch on pull_request (#9221). + ref: ${{ github.event_name == 'pull_request' && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} - name: Setup agent environment env: @@ -2277,7 +2331,7 @@ jobs: jira-client-secret: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} fullsend-dir: .fullsend - version: ${{ inputs.fullsend_version || job.workflow_sha }} + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).pull_request.number || fromJSON(needs.route.outputs.event_payload).issue.number }} @@ -2303,7 +2357,7 @@ jobs: - name: Checkout caller repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -2312,7 +2366,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -2377,7 +2431,7 @@ jobs: jira-client-secret: ${{ fromJSON(needs.route.outputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} fullsend-dir: .fullsend - version: ${{ inputs.fullsend_version || job.workflow_sha }} + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ github.repository }} status-number: ${{ fromJSON(needs.route.outputs.event_payload).issue.number }} @@ -2385,7 +2439,9 @@ jobs: harness-dispatch: name: Harness dispatch - if: ${{ inputs.matrix == '' }} + # A fork or Dependabot PR on pull_request never dispatches (see + # "Determine stage" in the route job, #9221). + if: ${{ inputs.matrix == '' && (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]')) }} runs-on: ${{ inputs.runner_image }} permissions: actions: write @@ -2404,7 +2460,7 @@ jobs: - name: Checkout caller repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} sparse-checkout: | @@ -2463,7 +2519,7 @@ jobs: uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ${{ runner.temp }}/fullsend-cache - key: fullsend-cli-${{ steps.mode.outputs.mode }}-${{ job.workflow_sha }} + key: fullsend-cli-${{ steps.mode.outputs.mode }}-${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - name: Install fullsend CLI (vendored defaults) if: steps.triggers.outputs.has_triggers == 'true' && steps.mode.outputs.mode == 'vendored' && steps.cli-cache.outputs.cache-hit != 'true' @@ -2478,7 +2534,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .workflow-actions fetch-depth: 1 sparse-checkout: | @@ -2491,7 +2547,7 @@ jobs: with: mode: upstream workflow_repository: ${{ job.workflow_repository }} - workflow_sha: ${{ job.workflow_sha }} + workflow_sha: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} github_token: ${{ github.token }} - name: Expose cached fullsend CLI @@ -2518,7 +2574,7 @@ jobs: uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: ${{ runner.temp }}/fullsend-cache - key: fullsend-cli-${{ steps.mode.outputs.mode }}-${{ job.workflow_sha }} + key: fullsend-cli-${{ steps.mode.outputs.mode }}-${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} - name: Run fullsend dispatch id: dispatch @@ -2549,7 +2605,9 @@ jobs: harness-run: name: Harness run (${{ matrix.agent }}) needs: [harness-dispatch] - if: ${{ !cancelled() && ((inputs.matrix != '' && fromJSON(inputs.matrix).include[0] != null) || (needs.harness-dispatch.outputs.matrix != '' && fromJSON(needs.harness-dispatch.outputs.matrix).include[0] != null)) }} + # A fork or Dependabot PR on pull_request never dispatches (see + # "Determine stage" in the route job, #9221). + if: ${{ !cancelled() && (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]')) && ((inputs.matrix != '' && fromJSON(inputs.matrix).include[0] != null) || (needs.harness-dispatch.outputs.matrix != '' && fromJSON(needs.harness-dispatch.outputs.matrix).include[0] != null)) }} strategy: fail-fast: false matrix: ${{ fromJSON(inputs.matrix != '' && inputs.matrix || (needs.harness-dispatch.outputs.matrix != '' && needs.harness-dispatch.outputs.matrix || '{"include":[]}')) }} @@ -2567,7 +2625,7 @@ jobs: - name: Checkout caller repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request' || github.event_name == 'pull_request_review') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -2576,7 +2634,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -2635,6 +2693,10 @@ jobs: path: target-repo fetch-depth: 1 persist-credentials: false + # With no ref, checkout uses github.ref: the default branch on + # pull_request_target, the PR merge commit on pull_request. Keep the + # default branch on pull_request (#9221). + ref: ${{ github.event_name == 'pull_request' && matrix.source_repo == github.repository && format('refs/heads/{0}', github.event.repository.default_branch) || '' }} - name: Resolve bot identity env: @@ -2762,7 +2824,7 @@ jobs: jira-client-secret: ${{ matrix.event_payload._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} role: ${{ matrix.role }} runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} - version: ${{ inputs.fullsend_version || job.workflow_sha }} + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} fullsend-dir: .fullsend run-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} status-repo: ${{ matrix.status_repo }} diff --git a/.github/workflows/reusable-prioritize.yml b/.github/workflows/reusable-prioritize.yml index 28e4dccbad..68ffac9f37 100644 --- a/.github/workflows/reusable-prioritize.yml +++ b/.github/workflows/reusable-prioritize.yml @@ -107,7 +107,7 @@ jobs: # checkout@v7 blocks fork PR checkouts on pull_request_target by default. # Safe here: only .fullsend/ config is read, no fork code is executed, # and credentials are not persisted. - ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha }} + ref: ${{ (github.event_name == 'pull_request_target' || github.event_name == 'pull_request') && github.event.pull_request.base.sha || github.sha }} persist-credentials: false allow-unsafe-pr-checkout: ${{ github.event_name == 'pull_request_target' }} @@ -116,7 +116,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: ${{ job.workflow_repository }} - ref: ${{ job.workflow_sha }} + ref: ${{ (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} path: .defaults fetch-depth: 1 sparse-checkout: | @@ -201,7 +201,7 @@ jobs: jira-client-id: ${{ fromJSON(inputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_ID || '' }} jira-client-secret: ${{ fromJSON(inputs.event_payload)._normalized_event.source.system == 'jira' && secrets.FULLSEND_JIRA_CLIENT_SECRET || '' }} runner_secrets: ${{ secrets.FULLSEND_GITHUB_RUNNER_SECRETS }} - version: ${{ inputs.fullsend_version || job.workflow_sha }} + version: ${{ inputs.fullsend_version || (github.event_name == 'pull_request' && job.workflow_sha == github.sha && github.event.pull_request.base.sha || job.workflow_sha) }} fullsend-dir: .fullsend mint-url: ${{ inputs.mint_url }} gcp_wif_provider: ${{ secrets.FULLSEND_GCP_WIF_PROVIDER }} diff --git a/docs/agents/retro.md b/docs/agents/retro.md index 5aedffeba1..4ed905c253 100644 --- a/docs/agents/retro.md +++ b/docs/agents/retro.md @@ -11,9 +11,8 @@ Performs retrospectives on agent workflows — analyzes what happened, identifie ## How the agent works The retro agent is triggered after a workflow completes when the event actor -has write access and closes or merges its PR. Users with write access can also -start it -with `/fs-retro`. It reconstructs the full workflow graph — [triage](triage.md), +has write access and closes or merges a same-repository PR. Users with write +access can also start it with `/fs-retro`. It reconstructs the full workflow graph — [triage](triage.md), [code](code.md), [review](review.md), [fix](fix.md), and human interactions — by fetching issue and PR timelines, agent run logs, and review threads. GitLab merge requests use the same write-level requirement: the actor who @@ -48,8 +47,10 @@ to focus on: - `/fs-retro figure out why the review agent approved this and make sure it never happens again` - `/fs-retro the code agent spent 30 minutes on a 2-line fix, what went wrong` -The retro agent also runs automatically when a PR is closed (merged or not) by -an actor with write access. Merge-queue events follow the same rule: the event +The retro agent also runs automatically when a same-repository PR is closed +(merged or not) by an actor with write access. Fork PRs get no automatic +retro; a user with write access can run `/fs-retro` on a closed or merged fork PR. +Merge-queue events follow the same rule: the event sender must have write access. Other automated senders without repository write access do not start retro; a write-authorized user can run `/fs-retro` afterward. On GitLab, merged or closed MRs also start retro only when the actor diff --git a/docs/agents/review.md b/docs/agents/review.md index 3143b1e88a..a7084e83dc 100644 --- a/docs/agents/review.md +++ b/docs/agents/review.md @@ -35,9 +35,10 @@ Requires triage-level repository permission or higher (triage, write, maintain, or admin). Mutation stages such as `/fs-fix` still require write or higher. -The `/fs-review` command does not accept arguments and always forces a review. The review agent also runs automatically when a PR is opened, +The `/fs-review` command does not accept arguments and always forces a review. The review agent also runs automatically on a same-repository PR when it is opened, when its effective diff changes on a synchronize event, or when it is moved out of draft by a user with triage-level repository permission or higher. -For GitHub `pull_request_target` synchronize events, the review is skipped when the complete effective diff matches the previous app-verified approved review. The guard posts or updates one PR-visible `fullsend:review-skip` status comment linking the previous approved review. GitLab diff metadata uses the same normalized model, but the GitLab poller does not consume this marker yet and continues to review synchronized merge requests. +Fork and Dependabot PRs are not reviewed automatically; someone with triage access or higher (or an OWNERS approver or reviewer) can comment `/fs-review` on them. +For GitHub `pull_request` synchronize events (and `pull_request_target` from shims that have not been upgraded), the review is skipped when the complete effective diff matches the previous app-verified approved review. The guard posts or updates one PR-visible `fullsend:review-skip` status comment linking the previous approved review. GitLab diff metadata uses the same normalized model, but the GitLab poller does not consume this marker yet and continues to review synchronized merge requests. The deduplication check runs before final Bash/CEL stage selection, so CEL-selected review routes participate as well. File modes are part of the compared effective diff identity, so executable-bit changes cannot be hidden by an otherwise identical textual patch. The guard fails open and runs the review when there is no prior diff hash, the prior review cannot be verified, a required hash/head or base/head tree-mode API call fails, the file listing is incomplete or truncated, or any file has no representable patch (for example, a binary or rename-only change). diff --git a/docs/architecture.md b/docs/architecture.md index 0a58d66f26..66d9bcb657 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -55,7 +55,7 @@ sole supported installation model - Event-source routing for status notifications: the notification destination for run-status comments and reactions is dynamically determined by event provenance — a Jira-triggered run posts status to Jira, a GitHub-triggered run posts to GitHub — rather than being hardwired to the code-output forge. Status notifications route through `tracker.Client`; reactions are an optional `tracker.Reactor` capability (Jira Cloud supports comment reactions but not issue reactions, so `Reactor` is not implemented for Jira currently) ([ADR 0093](ADRs/0093-tracker-routed-status-notifications.md)). - Installation model: the CLI installs per repository only (`fullsend github setup `, `fullsend admin install ` (deprecated), `fullsend repos install`); per-org CLI installation was removed ([ADR 0044](ADRs/0044-deprecate-per-org-installation-mode.md)). The concrete layers of the ordered layer stack (vendor-binary, secrets, inference, and the per-org workflows layer) were removed along with per-org mode; `internal/layers` keeps only the `Layer` interface and shared helpers, and the CLI no longer orchestrates a layer stack ([ADR 0006](ADRs/0006-ordered-layer-model.md)). - Dispatch: each repository's `.github/workflows/fullsend.yaml` shim calls the upstream `reusable-dispatch.yml` via `workflow_call`; that workflow mints OIDC tokens exchanged at a central token mint (GCP Cloud Function or Cloudflare Worker) for scoped GitHub App installation tokens per agent role. App PEM secrets are stored in Secret Manager (GCF mint), Worker secrets (CF mint), or the local filesystem (standalone mint), not the config repo ([ADR 0008](ADRs/0008-workflow-dispatch-for-cross-repo-dispatch.md)). -- Shim workflow security (target state): the shim's PR events run on `pull_request`, only for same-repo PRs (head repository id equals the base repository id); fork PRs are reviewed when someone authorized for `/fs-review` (triage access or higher, or an OWNERS approver or reviewer) comments it. Same-repo authors already have write access and are trusted with the secrets the PR-branch shim receives; fork runs get no secrets; the dispatch workflow takes the base side for every checkout and runs no PR code. The mint accepts only OIDC tokens whose `job_workflow_ref` names an allowed workflow host repository ([ADR 0164](ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md), superseding the `pull_request_target` shim of [ADR 0009](ADRs/0009-pull-request-target-in-shim-workflows.md)). +- Shim workflow security: the shim's PR events run on `pull_request`, so the shim runs from the PR's own copy and forwards the repository's secrets. Its dispatch job therefore runs only for same-repo PRs (head repository id equals the base repository id), whose authors already have write access; fork and Dependabot PRs get no automatic run and are reviewed when someone authorized for `/fs-review` (triage access or higher, or an OWNERS approver or reviewer) comments it. `reusable-dispatch.yml` refuses those PRs again (a fork cannot edit the upstream copy; a vendored copy runs from the PR, so vendored installs rely on GitHub not sending secrets to fork PR runs), takes the base side for every checkout (base SHA, or the default branch where a checkout used the event default), runs no PR code, and still accepts `pull_request_target` from shims that have not upgraded, with a warning. The mint accepts only OIDC tokens whose `job_workflow_ref` names an allowed workflow host repository ([ADR 0164](ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md), superseding the `pull_request_target` shim of [ADR 0009](ADRs/0009-pull-request-target-in-shim-workflows.md)). - Installer scaffold: per-repo installs deploy content from an embedded scaffold (`internal/scaffold/`), keeping deployable files as real files under version control rather than Go string constants. The per-org dispatch, repo-maintenance, and enrollment-reconciliation scaffolds were removed with the rest of per-org mode ([ADR 0044](ADRs/0044-deprecate-per-org-installation-mode.md)). - Reusable workflows: each repository's `fullsend.yaml` shim calls the upstream `reusable-dispatch.yml` (`fullsend-ai/fullsend/.github/workflows/reusable-dispatch.yml`), which runs every agent stage as an inline job; the only standalone stage workflow is `reusable-prioritize.yml`, called by the explicit prioritize thin caller. The per-org thin stage callers and `reusable-{code,fix,review,retro,triage}.yml` were removed with per-org mode (the per-org architecture described in the linked ADRs is historical and deprecated). Infrastructure patches ship once upstream and propagate to all repositories without re-install ([ADR 0031](ADRs/0031-reusable-workflows-for-action-installed-distribution.md)). **Vendoring** (`vendor: true` in `repos.yaml` for `repos install`, `--vendor` for `github setup`; [ADR 0047](ADRs/0047-vendored-installs-with-vendor-flag.md)) commits workflows and agent content at install time; layered installs (default) fetch upstream at runtime. - Event-driven stage dispatch: eliminate `workflow_dispatch` + `gh workflow run` fan-out from the (now removed per-org) `dispatch.yml` in favor of synchronous `workflow_call` so the dispatched run stays linked to the caller ([ADR 0041](ADRs/0041-synchronous-workflow-call-event-dispatch.md)). @@ -900,7 +900,7 @@ ADR 0002: [Building block 7](ADRs/0002-initial-fullsend-design.md#7-test-artifac ### 8. code agent runtime -Implements changes, runs local/CI-equivalent tests, handles check failures, and opens or updates a PR. Review dispatch is triggered automatically by `pull_request_target` events today; the decided target state is same-repo `pull_request` events ([ADR 0164](ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md)). +Implements changes, runs local/CI-equivalent tests, handles check failures, and opens or updates a PR. Review dispatch is triggered automatically by `pull_request` events on same-repo PRs ([ADR 0164](ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md)). ADR 0002: [Building block 8](ADRs/0002-initial-fullsend-design.md#8-implementation-agent-runtime). ### 9. PR sandbox / CI mirror @@ -943,7 +943,7 @@ ADR 0002: [Building block 13](ADRs/0002-initial-fullsend-design.md#13-observabil Retrospective analyst — examines completed or in-progress agent workflows, identifies improvement opportunities, and files proposals as GitHub issues. -Runs automatically on PR close (merged or rejected) when the event actor has +Runs automatically on same-repo PR close (merged or rejected) when the event actor has write access, including for merge-queue events. GitLab MR close and merge use the same threshold, expressed as Developer access. Users with write access can also start it with `/fs-retro`; a custom retro harness role cannot lower this diff --git a/docs/contributing/ci-workflows.md b/docs/contributing/ci-workflows.md index d422972f50..b4daf44799 100644 --- a/docs/contributing/ci-workflows.md +++ b/docs/contributing/ci-workflows.md @@ -187,7 +187,7 @@ Jobs triggered by `pull_request_target` that check out and execute PR-head code When all five components are present, any code the PR author controls can read and exfiltrate every secret in that step's environment. -**ADR-0009 and the shim distinction:** ADR-0009 documents why `pull_request_target` is safe for the shim workflow — the shim never checks out PR code, so components 2–3 are absent. This safety reasoning does **not** transfer to jobs that check out and execute PR-head code (e.g., the behaviour and playback jobs in `e2e.yml`). +**ADR-0009 and the shim distinction:** ADR-0009 documents why `pull_request_target` was safe for the shim workflow — the shim never checks out PR code, so components 2–3 are absent. The shim has since moved to `pull_request` for same-repo PRs ([ADR 0164](../ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md)); `reusable-dispatch.yml` still accepts `pull_request_target` from shims that have not upgraded. This safety reasoning does **not** transfer to jobs that check out and execute PR-head code (e.g., the behaviour and playback jobs in `e2e.yml`). ### Credential blast radius diff --git a/docs/guides/dev/behaviour-testing.md b/docs/guides/dev/behaviour-testing.md index 20a232e95d..5e7322aa70 100644 --- a/docs/guides/dev/behaviour-testing.md +++ b/docs/guides/dev/behaviour-testing.md @@ -1216,7 +1216,7 @@ See [behaviour-drivers.md](behaviour-drivers.md) for driver configuration and [A ## Fork PR scenarios -Fork dispatch scenarios test `pull_request_target` harness triggering from cross-fork pull requests. +Fork dispatch scenarios test harness dispatch on cross-fork pull requests. The shim runs on `pull_request` and skips fork pull requests ([ADR 0164](../../ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md)), so fork pull request events (open, label, push) never dispatch; each scenario dispatches through a maintainer's slash command on the fork pull request (`the posts "..." on the fork pull request`). ### Logical fork name → leased base @@ -1269,12 +1269,12 @@ The `fork-dispatch.feature` file defines the canonical fork-PR behaviour contrac | Scenario | Expected | How tested | |----------|----------|------------| -| Fork PR matches CEL trigger; authorized actor | Agent runs via `harness-dispatch`; workflow completes | Positive dispatch + artifact assertion | +| Fork PR label is skipped; a write actor's comment matches the CEL trigger | Label: agent did not run. Comment: agent runs via `harness-dispatch`; workflow completes | Negative check after the label, then positive dispatch + artifact assertion | | Kill switch active (`kill_switch: true`) on fork event | Empty matrix, exit 0 | Separate scenario; `the kill switch is active` step + assert agent did not run | | Disabled harness (`enabled: false`) on fork event | Empty matrix, exit 0 | Disabled harness in positive scenario; assert agent did not run | -| Fork PR `synchronize` + label dispatches harness | Harness dispatched exactly 1 time; workflow completes | Separate scenario with sync commit + label | +| Fork PR `synchronize` does not dispatch; a later comment does | Push: agent did not run. Comment: harness dispatched exactly 1 time; workflow completes | Separate scenario with sync commit, then a comment | | CEL `is_fork` exclusion (`!event.state.change_proposal.is_fork`) | Empty matrix, exit 0 | Harness with `is_fork` guard in positive scenario; assert agent did not run | -| Fork PR matches CEL `trigger` on `pull_request_target`; unauthorized actor ([ADR 0054](../../ADRs/0054-require-authorization-on-all-agent-dispatch-paths.md)) | Empty matrix, exit 0 — no agent run | `platform/actor-authorization.feature`. The outsider opens a PR from its own fork; assert the harness dispatch completed with an empty matrix, the agent did not run, and it was dispatched exactly 0 times, then a label as the positive control | +| Comment on a fork PR matches the CEL `trigger`; unauthorized actor ([ADR 0054](../../ADRs/0054-require-authorization-on-all-agent-dispatch-paths.md)) | Empty matrix, exit 0 — no agent run | `platform/actor-authorization.feature`. The outsider opens a PR from its own fork and comments on it; assert the harness dispatch completed with an empty matrix and was dispatched exactly 0 times, then the write actor's comment as the positive control | | Human actors at each permission level comment `/fs-do` and add a label | Each harness is dispatched or not by the actor's role: the write actor starts the triage-level and write-level harnesses, the triage actor only the triage-level one, the outsider none; the label harness runs for both labelers | `platform/actor-authorization.feature`, the ` comments "/fs-do" and labels the issue` outline | | Bot actors (review, coder and triage role bots, the e2e bot) and the write actor as a control comment `/fs-do` and add a label | One harness per bot role triggers on `/fs-do` with `event.actor.bot_role == ""`; one harness triggers on the label. The shim forwards `/fs-` comments from bots, so a comment reaches the bot-role lookup. Each registered role bot dispatches only the harness of its own role. The write actor (a human, so no bot role) and the unregistered e2e bot (denied by the lookup before CEL) dispatch no role harness. Every actor's label dispatches the label harness, because label-added events skip the lookup. The matrix counts the dispatches of each harness per actor | `platform/bot-actor-authorization.feature`, the `registered posts "/fs-do" and labels the issue "do-it"` outline and the ` posts "/fs-do" and labels the issue "do-it" without a bot role` outline. See [Bot actor steps](#bot-actor-steps) | | The three role bots and the e2e bot submit a review comment on a pull request, with the write actor's review as a control | A pull request review is a bot transition the shim forwards, so it reaches the dispatch-time bot-role lookup. Each registered role bot dispatches the harness of its own role (`event.actor.bot_role`) and the unrestricted `on-review` harness. The unregistered e2e bot dispatches nothing, not even `on-review`, until the write actor's review dispatches it. A failed lookup cannot be induced against the deployed mint; the unit tests of the gate cover it | `platform/bot-actor-authorization.feature`, the `registered submits a review comment on a pull request` outline and the `unregistered e2e bot submits a review comment on a pull request` scenario | @@ -1283,10 +1283,10 @@ The `fork-dispatch.feature` file defines the canonical fork-PR behaviour contrac **Consolidation pattern:** To conserve parallel execution slots, add negative-path harnesses (disabled agent, CEL exclusion) alongside the positive-path harness in a single scenario rather than creating separate scenarios. The positive harness wait acts as the settle window for negative assertions (piggyback pattern — see `negativeSettleDuration` in `dispatch.go`). The kill switch scenario cannot be consolidated because it blocks all harnesses. -**Unauthorized-actor denial:** The row lives in `e2e/behaviour/features/platform/actor-authorization.feature`, the canonical default platform actor authorization matrix, rather than in `fork-dispatch.feature`. The dispatch gate (`harnessdispatch.IsEventAuthorized`, then the per-harness `role:` threshold from `IsHarnessAuthorized`) authorizes label-added events without any role. So the denial can only be exercised through a transition that needs one — for the `fork-auth-probe` harness (`role: triage`), the `triage` threshold: the PR `opened` event, sent by the outsider when it opens the PR from its own fork. The harness trigger matches both `opened` and a label, and the scenario orders its steps as follows: +**Unauthorized-actor denial:** The row lives in `e2e/behaviour/features/platform/actor-authorization.feature`, the canonical default platform actor authorization matrix, rather than in `fork-dispatch.feature`. Fork pull request events never dispatch on `pull_request` (ADR 0164), and GitHub holds a first-time contributor's run for approval, so the denial is exercised through a comment on the fork pull request. The dispatch gate (`harnessdispatch.IsEventAuthorized`, then the per-harness `role:` threshold from `IsHarnessAuthorized`) applies the `fork-auth-probe` harness's `role: triage` threshold to the comment, and the scenario orders its steps as follows: -1. The denial assertions (`the harness dispatch completes with an empty matrix`, then `agent did not run`, then `dispatched exactly 0 times`) run before the label is added. The first is the one that checks the required outcome: the other two also pass when the dispatch job errored or when no run was created, because neither counts a run without an agent job. `harness-run` uses a `cancel-in-progress` concurrency group per agent and PR, and the dispatch count excludes cancelled jobs. A leaked `opened` dispatch that the label run cancelled would therefore not be counted. -2. The label, added afterwards by the e2e identity, must dispatch. This positive control shows that the harness is registered and its trigger matches the PR, so the denial cannot pass just because the harness never loaded. +1. The outsider comments `/fs-fork-auth` on its own fork pull request. The denial assertions (`the harness dispatch completes with an empty matrix`, then `dispatched exactly 0 times`) follow. The first is the one that checks the required outcome: the count also passes when the dispatch job errored or when no run was created, because it does not count a run without an agent job. +2. The write actor then comments `/fs-fork-auth`, which must dispatch. This positive control shows that the harness is registered and its trigger matches the comment, so the denial cannot pass just because the harness never loaded. ### Dispatch step reference diff --git a/docs/guides/getting-started/repo-management.md b/docs/guides/getting-started/repo-management.md index f9f6b77244..aad1b1000e 100644 --- a/docs/guides/getting-started/repo-management.md +++ b/docs/guides/getting-started/repo-management.md @@ -1003,6 +1003,48 @@ to commit SHAs and uses git ancestry checking via the forge API to detect downgrades. If the ancestry check fails (e.g., API error), the upgrade proceeds rather than blocking — graceful degradation. +### Required upgrade: shim moves from `pull_request_target` to `pull_request` + +GitHub blocks `pull_request_target` by default in public repositories from +December 2, 2026. Repositories whose `.github/workflows/fullsend.yaml` still +triggers on it lose automatic review and retro from that date. Triage, +`/fs-*` commands (including `/fs-review`) and the fix loop keep working. + +Upgrade every public repository before that date, using the steps in +[Rolling out a new fullsend version](#rolling-out-a-new-fullsend-version). +Private and internal repositories are not blocked, and a shim that is not +upgraded keeps working there (the warning appears only in public +repositories). Any upgrade to a fullsend version with the new shim installs +the same `pull_request` shim, with the effects below. +`fullsend repos install` rewrites the trigger and the workflow pin in one +commit. After the upgrade: + +- **Same-repo PRs** are reviewed automatically, as before, except while the + PR has a merge conflict: GitHub does not run `pull_request` workflows until + the conflict is resolved. Comment `/fs-review` or `/fs-retro` meanwhile. +- **Fork PRs** are not reviewed or retro'd automatically, whoever the author + is: an org member or maintainer working from a fork loses the automatic + review they got before. Someone with triage or higher access (or an OWNERS + approver or reviewer, when the `owners_file` provider is on) comments + `/fs-review` on the PR to start a review. Contributors who want automatic + review push their branch to the repository instead of a fork. +- **Dependabot PRs**: events Dependabot itself triggers (opening the PR, + its own pushes and closes) are not routed, because GitHub gives those + `pull_request` runs only Dependabot secrets. A maintainer's push, merge or + close is routed as usual. Someone with triage access or higher comments + `/fs-review` on the PR to review it. +- **Private repositories:** before upgrading, check **Settings → Actions → + General → Fork pull request workflows** and keep "Send write tokens to + workflows from pull requests" and "Send secrets to workflows from pull + requests" turned off; `fullsend repos install` does not check them yet + ([#9630](https://github.com/fullsend-ai/fullsend/issues/9630)). For vendored + installs (`vendor: true`) it is the only control, because a fork PR runs + its own copy of the vendored workflows. + +Until a repository upgrades, the dispatch still accepts `pull_request_target` +and logs a warning on each such run (see +[Troubleshooting](#shim-still-triggers-on-pull_request_target)). + ## Troubleshooting ### Errors that say "server error text withheld" @@ -1021,6 +1063,17 @@ and token-shaped values are redacted; see [Verbose output](../../cli/repos.md#verbose-output) for what is shown and what is redacted. +### Shim still triggers on pull_request_target + +The dispatch run shows: + +``` +This repository's fullsend shim still triggers on pull_request_target, which GitHub blocks by default in public repositories from its announced enforcement date. Re-run 'fullsend repos install' to move the shim to pull_request. +``` + +The repository runs an old shim. Upgrade it as described in +[Required upgrade: shim moves from `pull_request_target` to `pull_request`](#required-upgrade-shim-moves-from-pull_request_target-to-pull_request). + ### Unknown field errors in repos.yaml The manifest parser strictly validates field names in all sections diff --git a/docs/guides/infrastructure/openai-workload-identity.md b/docs/guides/infrastructure/openai-workload-identity.md index 0cb37248c2..b69620698c 100644 --- a/docs/guides/infrastructure/openai-workload-identity.md +++ b/docs/guides/infrastructure/openai-workload-identity.md @@ -207,7 +207,8 @@ Two things not to do: setting: the mapping trusts **any job in that repository that can request an OIDC token** — not one named workflow, and not one ref. The default mapping has no `ref` assertion, matching the Vertex path's `attribute.repository` scoping: `issues`, `issue_comment`, and `pull_request_target` events -carry the default branch ref, while `pull_request_review` events carry `refs/pull//merge`. A +carry the default branch ref, while `pull_request` and `pull_request_review` events carry +`refs/pull//merge`. A repository-only mapping covers all of them. Anyone with write access can obtain a model token: pushing a branch with a workflow that has diff --git a/docs/guides/user/bugfix-workflow.md b/docs/guides/user/bugfix-workflow.md index aaac85f8d3..134e583e2b 100644 --- a/docs/guides/user/bugfix-workflow.md +++ b/docs/guides/user/bugfix-workflow.md @@ -138,11 +138,11 @@ The code agent: 3. **Tests iteratively.** Runs the test suite, incorporates triage-provided tests if present, writes new tests if needed. Iterates until tests pass. 4. **Opens a PR.** Links the issue, describes the changes. 5. **Handles CI failures.** Fetches failing check logs, fixes issues, pushes again. Repeats until all required checks pass (up to a fixed retry cap). -6. **Hands off to review.** The PR creation or push triggers review dispatch automatically via `pull_request_target`. +6. **Hands off to review.** The PR creation or push triggers review dispatch automatically via `pull_request`. ### Stage 3: Review -**Triggered by:** `pull_request_target` events (PR opened, push to PR branch, or marked ready for review), `/fs-review` on a PR comment, or applying `ready-for-review` to a PR (per-repo installs enforce PR context for the latter two). +**Triggered by:** `pull_request` events on same-repo PRs (PR opened, push to PR branch, marked ready for review, or labeled `ready-for-review`), or `/fs-review` on a PR comment. PRs from forks are not reviewed automatically, and labeling a fork PR does not start a review either: someone with triage access or higher (or an OWNERS approver or reviewer) comments `/fs-review` to start one. The review swarm: @@ -191,7 +191,7 @@ actor has Developer access. ### Stopping automation -- Remove the triggering label (`ready-to-code`) to prevent the next stage from starting. Note: review is triggered automatically by PR events (`pull_request_target`), so closing the PR is the way to stop review dispatch. +- Remove the triggering label (`ready-to-code`) to prevent the next stage from starting. Note: review is triggered automatically by PR events (`pull_request`), so closing the PR is the way to stop review dispatch. - Close the issue. Agents don't act on closed issues (except `/fs-triage` which explicitly reopens). ### Restarting a stage diff --git a/docs/guides/user/cel-triggers-reference.md b/docs/guides/user/cel-triggers-reference.md index c853eff552..7626db8b38 100644 --- a/docs/guides/user/cel-triggers-reference.md +++ b/docs/guides/user/cel-triggers-reference.md @@ -299,8 +299,8 @@ agent, see ### Choosing when review runs By default, the dispatch workflow decides when the review agent runs: when a -pull request is opened, pushed to or marked ready, when the -`ready-for-review` label is added, and on a `/fs-review` comment. To decide it +same-repository pull request is opened, pushed to, marked ready or labeled +`ready-for-review`, and on a `/fs-review` comment. To decide it yourself, give the `review` entry in `.fullsend/config.yaml` a `trigger`: a [CEL expression](#writing-cel-triggers) over the event. The review still runs in the same `Review` job; the trigger only decides whether that job @@ -350,6 +350,10 @@ to CEL: | `trigger` on the `review` entry | The trigger | | A `review` entry with `source:` whose harness sets or inherits `trigger:` | The dispatch workflow, as before | +Neither path routes fork or Dependabot pull request events on `pull_request`; +review on those pull requests starts from a `/fs-review` comment (see +[Required upgrade](../getting-started/repo-management.md#required-upgrade-shim-moves-from-pull_request_target-to-pull_request)). + A harness `trigger:` field never changes when a built-in agent runs, whether your own harness writes it, inherits it through `base:`, or the entry's `harness:` block sets it. To route review by @@ -372,7 +376,7 @@ the dispatch workflow's built-in rules: | Pull request opened or pushed by a bot without a registered fullsend role | Reviewed | Not reviewed | | Pull request pushed by the fix agent | Reviewed | Not reviewed until [#8329](https://github.com/fullsend-ai/fullsend/issues/8329) ships, so the review → fix → re-review loop stops | | Who is checked when a pull request is opened, pushed to or marked ready | The pull request author | The user who sent the event | -| A maintainer's push to an outside contributor's fork pull request | Not reviewed | Reviewed | +| A push by a user with triage access or higher to an outside contributor's fork pull request | Not reviewed (the pull request author is checked; with the `pull_request` shim, fork PR events are not routed at all) | Not reviewed with the `pull_request` shim (fork PR events are not routed). Reviewed only by a shim still on `pull_request_target` | > [!WARNING] > Opt in only after @@ -413,9 +417,9 @@ the review entry is disabled. ### Choosing when retro runs -By default, the dispatch workflow starts the retro agent when a pull request -is closed, merged or not, and on a `/fs-retro` comment on an issue or a pull -request. To decide it yourself, give the `retro` entry in +By default, the dispatch workflow starts the retro agent when a +same-repository pull request is closed, merged or not, and on a `/fs-retro` +comment on an issue or a pull request (a fork pull request needs the comment). To decide it yourself, give the `retro` entry in `.fullsend/config.yaml` a `trigger`. The retro still runs in the same `Retro` job; the trigger only decides whether that job starts. What opts a repository in, and how to check the decision, work as for review: see @@ -451,13 +455,15 @@ and a bot's `/fs-retro` comment never starts a retro. A trigger decides which events start a retro, not who may start one: -- **Closing a pull request:** the closing actor needs write access. If the +- **Closing a pull request:** applies to same-repository pull requests (fork + pull requests get no automatic retro on close; comment `/fs-retro`). The + closing actor needs write access. If the permission lookup or CEL routing fails, the close event does not start retro. A custom retro harness role cannot lower this write requirement. Merge-queue events follow the same rule: the event sender needs write access. Other automated senders without write access are denied; a write user can run `/fs-retro` afterward. See the - [authorization contract](../../normative/authorization/v1/README.md#closed-pull-request-retro-pull_request_targetclosed). + [authorization contract](../../normative/authorization/v1/README.md#closed-pull-request-retro-pull_request-and-pull_request_target-closed). - **`/fs-retro`:** users with write access or above. A custom retro harness role cannot lower this fixed floor, and CEL cannot start retro when the Bash route denied the actor. diff --git a/docs/guides/user/chaining-follow-up-workflows.md b/docs/guides/user/chaining-follow-up-workflows.md index 2a76271f37..4af0922003 100644 --- a/docs/guides/user/chaining-follow-up-workflows.md +++ b/docs/guides/user/chaining-follow-up-workflows.md @@ -343,10 +343,11 @@ What each guard does: - **The API lookup** confirms each id is a failed job in this repository, in the workflow named by `CI_WORKFLOW`, with a name listed in `CI_JOBS`. - **`HEAD_SHA`** comes from the event, not the agent. A job on any other - commit is skipped. For pull request events (`pull_request_target`) the shim - run's `head_sha` is the pull request head, the same SHA a `pull_request` CI - job reports; the job's own `GITHUB_SHA` (the base branch) is a different - value. For comment and issue events it is the default branch, so the + commit is skipped. For pull request events (`pull_request`, or + `pull_request_target` from a shim that has not been upgraded) the shim run's + `head_sha` is the pull request head, the same SHA a `pull_request` CI job + reports; the job's own `GITHUB_SHA` (the merge commit on `pull_request`, the + default branch on `pull_request_target`) is a different value. For comment and issue events it is the default branch, so the follow-up skips those runs rather than guessing. The agent can only choose among failed, allowlisted jobs on the commit it ran on. - **`run_attempt`** bounds repeats without any bookkeeping of your own. diff --git a/docs/guides/user/customizing-agents.md b/docs/guides/user/customizing-agents.md index e1a2834be8..12146f3295 100644 --- a/docs/guides/user/customizing-agents.md +++ b/docs/guides/user/customizing-agents.md @@ -563,7 +563,8 @@ disables nothing because no agent has that harness name. ## Choosing when review runs By default, the dispatch workflow decides when the review agent runs: when a -pull request is opened, pushed to or marked ready, when the +same-repository pull request is opened, pushed to or marked ready (fork and +Dependabot pull requests need a `/fs-review` comment), when the `ready-for-review` label is added, and on a `/fs-review` comment. To decide it yourself, give the `review` entry in `.fullsend/config.yaml` a `trigger`: a [CEL expression](cel-triggers-reference.md) over the event. The review still @@ -596,14 +597,14 @@ job, and how to ## Choosing when retro runs -By default, the dispatch workflow starts the retro agent when a pull request -is closed, merged or not, and on a `/fs-retro` comment on an issue or a pull -request. To decide it yourself, give the `retro` entry in +By default, the dispatch workflow starts the retro agent when a +same-repository pull request is closed, merged or not, and on a `/fs-retro` +comment on an issue or a pull request (a fork pull request needs the comment). To decide it yourself, give the `retro` entry in `.fullsend/config.yaml` a `trigger`. The retro still runs in the same `Retro` job; the trigger only decides whether that job starts. -Closing or merging a pull request starts retro only when the event actor has -write access. Merge-queue events follow the same rule, and a CEL routing +Closing or merging a same-repository pull request starts retro only when the +event actor has write access (a fork pull request needs `/fs-retro`). Merge-queue events follow the same rule, and a CEL routing failure skips retro for that close event. The `/fs-retro` command also requires write access, regardless of a lower `role:` on the retro harness; CEL cannot promote a command the Bash route diff --git a/docs/guides/user/owners-file-authorization.md b/docs/guides/user/owners-file-authorization.md index 3ae1546cb7..1dbc591379 100644 --- a/docs/guides/user/owners-file-authorization.md +++ b/docs/guides/user/owners-file-authorization.md @@ -67,7 +67,7 @@ thresholds, dispatch-path differences), see OWNERS can only **raise** a user's effective role, never lower it. Users not found in OWNERS fall through to the forge's permission API. The OWNERS file is read from a trusted ref so that PR authors cannot add themselves: -`pull_request_target` and `pull_request_review` events use the PR's +`pull_request`, `pull_request_target` and `pull_request_review` events use the PR's **base-branch SHA**; all other events — including slash commands posted on a PR (`issue_comment`) — use the **default branch**. diff --git a/docs/normative/authorization/v1/README.md b/docs/normative/authorization/v1/README.md index cc06a2169d..58126d1dff 100644 --- a/docs/normative/authorization/v1/README.md +++ b/docs/normative/authorization/v1/README.md @@ -341,10 +341,13 @@ bot and resolves its exact registered `actor.bot_role`; `actor.role` remains `none`. The downstream harness CEL trigger may further constrain which bot role and review state are accepted. -### Closed pull request retro (pull\_request\_target.closed) +### Closed pull request retro (pull\_request and pull\_request\_target closed) A closed pull request may trigger retro only when the closing actor meets the -standard write-level permission threshold. The bash dispatch path checks the +standard write-level permission threshold and, for a `pull_request` close, the +pull request comes from the same repository (head repository id equals the +base repository id). A fork pull request close on `pull_request` does not +dispatch retro; a write-authorized user can run `/fs-retro`. The bash dispatch path checks the event sender's repository permission; the GitHub CEL route applies a fixed write floor before the ordinary event and harness authorization gates. A custom retro harness role cannot lower this floor. Merge-queue merges follow diff --git a/docs/normative/authorization/v2/README.md b/docs/normative/authorization/v2/README.md index 62ebe0b468..e724b53164 100644 --- a/docs/normative/authorization/v2/README.md +++ b/docs/normative/authorization/v2/README.md @@ -527,10 +527,13 @@ bot and resolves its exact registered `actor.bot_role`; `actor.role` remains `none`. The downstream harness CEL trigger may further constrain which bot role and review state are accepted. -### Closed pull request retro (pull\_request\_target.closed) +### Closed pull request retro (pull\_request and pull\_request\_target closed) The GitHub bash dispatcher checks that the event sender has write access -before routing a closed pull request to retro. The CEL route applies the +before routing a closed pull request to retro. On `pull_request`, only a +same-repository pull request (head repository id equals the base repository +id) is routed; a fork pull request close does not dispatch retro, and a +write-authorized user can run `/fs-retro`. The CEL route applies the same fixed write floor before applying the selected harness's role-derived threshold; a `retro` role requires `write` by default. Merge-queue merges use the same rule: the event sender must have write-level repository permission. diff --git a/docs/normative/normalized-event/v1/README.md b/docs/normative/normalized-event/v1/README.md index 0913072acc..73dcf0ea7d 100644 --- a/docs/normative/normalized-event/v1/README.md +++ b/docs/normative/normalized-event/v1/README.md @@ -454,7 +454,7 @@ contract): | `project_number` | Not in `NormalizedEvent`; prioritize agent reads `PRIORITIZE_PROJECT_NUMBER` from workflow env | | `run-url` | Runtime-only; set by the dispatch workflow, not projected from `NormalizedEvent` | -**`event_type` / `pull_request_target`:** v1 preserves the GitHub Actions event +**`event_type` / `pull_request` and `pull_request_target`:** v1 preserves the GitHub Actions event name in `source.raw_type`, never normalized. When the workflow runs on `pull_request_target`, adapters emit `raw_type: "pull_request_target"`; when it runs on `pull_request`, they emit `raw_type: "pull_request"`. Both map to the diff --git a/docs/problems/gitlab-implementation.md b/docs/problems/gitlab-implementation.md index d7de55af2d..1d06cdf89e 100644 --- a/docs/problems/gitlab-implementation.md +++ b/docs/problems/gitlab-implementation.md @@ -27,7 +27,7 @@ This document contains implementation details for GitLab support in fullsend. Fo ## Shim Pipeline Security -**GitHub**: `pull_request_target` ensures the shim workflow runs the base branch version, preventing untrusted PR code from modifying the workflow to exfiltrate secrets. *(Superseded by [ADR 0164](../ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md), target state: the shim moves to `pull_request` for same-repo PRs only, because GitHub blocks `pull_request_target` by default on public repositories.)* +**GitHub**: the shim runs on `pull_request` for same-repo PRs only, because GitHub blocks `pull_request_target` by default on public repositories ([ADR 0164](../ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md)). Same-repo authors already have write access; fork PRs get no automatic run, and the dispatch workflow takes the base side for every checkout. Before ADR 0164, `pull_request_target` ran the base-branch version of the shim so PR code could not modify it. **GitLab**: No `pull_request_target` equivalent. The protected-branch pipeline approach (using `CI_COMMIT_REF_PROTECTED == "true"`) conflicts with MR-event triggering (which runs on unprotected MR source branches), so a different architecture is required. diff --git a/docs/problems/platform-nativeness.md b/docs/problems/platform-nativeness.md index 6b638f0155..967b00436f 100644 --- a/docs/problems/platform-nativeness.md +++ b/docs/problems/platform-nativeness.md @@ -20,7 +20,7 @@ Fullsend used a centralized `.fullsend` config repo as the hub for agent pipelin - `workflow_dispatch` as the cross-repo trigger mechanism, because `workflow_call` would require the caller to have the App PEM ([ADR 0008](../ADRs/0008-workflow-dispatch-for-cross-repo-dispatch.md)) - A fine-grained PAT (`FULLSEND_DISPATCH_TOKEN`) stored as an org secret with selected-repo visibility, so enrolled repos can trigger `.fullsend` workflows -- `pull_request_target` in the shim workflow, so PR authors cannot rewrite the dispatch code to steal the token ([ADR 0009](../ADRs/0009-pull-request-target-in-shim-workflows.md)) +- `pull_request_target` in the shim workflow, so PR authors cannot rewrite the dispatch code to steal the token ([ADR 0009](../ADRs/0009-pull-request-target-in-shim-workflows.md); superseded by [ADR 0164](../ADRs/0164-run-the-shim-on-pull-request-for-same-repo-prs.md), which runs the shim on `pull_request` for same-repo PRs) - Verification logic — the CLI dispatches `agent.yaml` with `event_type=verify` to confirm the token works gh-aw workflows are defined **in the repo itself** as markdown files. Events trigger Actions workflows directly. There is no cross-repo dispatch to set up, no dispatch token to manage, no shim to secure. @@ -43,7 +43,7 @@ That weakens retriggering as its own justification for per-role Apps: it's solva ### Repository enrollment -Fullsend must inject a shim workflow into each target repo. The CLI creates a branch (`fullsend/onboard`), writes `.github/workflows/fullsend.yaml` with the `pull_request_target` trigger, and opens a PR. A human must merge this PR to complete enrollment ([ADR 0013, proposed](../ADRs/0013-admin-install-repo-enrollment-v1.md)). +Fullsend must inject a shim workflow into each target repo. The CLI creates a branch (`fullsend/onboard`), writes `.github/workflows/fullsend.yaml` with the `pull_request` trigger, and opens a PR. A human must merge this PR to complete enrollment ([ADR 0013, proposed](../ADRs/0013-admin-install-repo-enrollment-v1.md)). gh-aw enrollment is adding a markdown file to your repo. `gh aw compile` generates the corresponding `.lock.yml`; `gh aw run` is a separate command that executes a workflow immediately in Actions. diff --git a/e2e/behaviour/features/dispatch/fork-bash-routing.feature b/e2e/behaviour/features/dispatch/fork-bash-routing.feature index ac19f144e2..697006e366 100644 --- a/e2e/behaviour/features/dispatch/fork-bash-routing.feature +++ b/e2e/behaviour/features/dispatch/fork-bash-routing.feature @@ -1,22 +1,26 @@ +# GitHub only: fork pull request dispatch follows the GitHub shim (#9221). +@skip:gitlab Feature: Fork PR bash routing smoke - Verify that a fork pull request dispatches through the bash routing - path (reusable-dispatch.yml route job) on a per-repo installation. - This is a time-boxed guard until harness CEL cutover (#2902). It - owns bash routing only; actor authorization is owned by + Verify the fork pull request path through bash routing (the + reusable-dispatch.yml route job) on a per-repo installation. The shim + runs on pull_request and skips fork pull requests (#9221), so a fork + pull request is reviewed only when a maintainer comments /fs-review. + This is a time-boxed guard until harness CEL cutover (#2902). It owns + bash routing only; actor authorization is owned by platform/actor-authorization.feature. Background: Given the enrolled test repository And a fork "test-repo-fork" of the enrolled test repository - Scenario: Fork PR labeled ready-for-review dispatches review via bash routing + Scenario: Fork PR is reviewed only after a maintainer comments /fs-review Given a dummy agent that would: | description | op | args | | Prove bash routing | write_fixture | output/bash-routing-ok.json, fixtures/dispatch/ok.json | | Emit review JSON | write_fixture | output/agent-result.json, fixtures/review/comment.json | When a fork pull request is opened - And the fork pull request is labeled "ready-for-review" + And the write actor posts "/fs-review" on the fork pull request Then the harness "review" workflow completes successfully And the agent will succeed to Prove bash routing And the agent will succeed to Emit review JSON diff --git a/e2e/behaviour/features/dispatch/fork-dispatch.feature b/e2e/behaviour/features/dispatch/fork-dispatch.feature index ab9ff5c39d..1dd442b3bc 100644 --- a/e2e/behaviour/features/dispatch/fork-dispatch.feature +++ b/e2e/behaviour/features/dispatch/fork-dispatch.feature @@ -1,8 +1,12 @@ +# GitHub only: fork pull request dispatch follows the GitHub shim (#9221). +@skip:gitlab Feature: Fork PR dispatch - Owns fork pull request CEL matching (is_fork, entity kind, disabled + Owns fork pull request CEL matching (is_fork, linked change proposal, disabled harnesses), the kill switch and synchronize handling for harness - dispatch. Every scenario dispatches through the label-added exception. + dispatch. The shim runs on pull_request and skips fork pull requests + (#9221): fork pull request events never dispatch, so every scenario + dispatches through a maintainer's slash command on the fork pull request. Which actors may trigger a harness on a fork pull request is owned by platform/actor-authorization.feature. @@ -10,7 +14,7 @@ Feature: Fork PR dispatch Given the enrolled test repository And a fork "test-repo-fork" of the enrolled test repository - Scenario: Fork PR label dispatches harness + Scenario: Fork PR dispatches a harness only from a maintainer comment Given a custom harness "fork-pr-ping" with: """ agent: agents/triage.md @@ -20,9 +24,14 @@ Feature: Fork PR dispatch image: ghcr.io/fullsend-ai/fullsend-sandbox:latest policy: policies/base.yaml trigger: | - event.entity.kind == "change_proposal" - && event.transition.kind == "label_changed" - && event.transition.label.name == "ready-for-fork-ping" + (event.entity.kind == "change_proposal" + && event.transition.kind == "label_changed" + && event.transition.label.name == "ready-for-fork-ping") + || (event.transition.kind == "comment_added" + && has(event.transition.comment.command) + && event.transition.comment.command == "/fs-fork-ping" + && has(event.entity.linked_change_proposal) + && event.state.change_proposal.is_fork) """ And a custom harness "fork-issue-ping" with: """ @@ -33,9 +42,10 @@ Feature: Fork PR dispatch image: ghcr.io/fullsend-ai/fullsend-sandbox:latest policy: policies/base.yaml trigger: | - event.entity.kind == "work_item" - && event.transition.kind == "label_changed" - && event.transition.label.name == "ready-for-fork-ping" + event.transition.kind == "comment_added" + && has(event.transition.comment.command) + && event.transition.comment.command == "/fs-fork-ping" + && !has(event.entity.linked_change_proposal) """ And a disabled custom harness "fork-pr-killed" with: """ @@ -46,9 +56,10 @@ Feature: Fork PR dispatch image: ghcr.io/fullsend-ai/fullsend-sandbox:latest policy: policies/base.yaml trigger: | - event.entity.kind == "change_proposal" - && event.transition.kind == "label_changed" - && event.transition.label.name == "ready-for-fork-ping" + event.transition.kind == "comment_added" + && has(event.transition.comment.command) + && event.transition.comment.command == "/fs-fork-ping" + && has(event.entity.linked_change_proposal) """ And a custom harness "fork-pr-nofork" with: """ @@ -59,9 +70,10 @@ Feature: Fork PR dispatch image: ghcr.io/fullsend-ai/fullsend-sandbox:latest policy: policies/base.yaml trigger: | - event.entity.kind == "change_proposal" - && event.transition.kind == "label_changed" - && event.transition.label.name == "ready-for-fork-ping" + event.transition.kind == "comment_added" + && has(event.transition.comment.command) + && event.transition.comment.command == "/fs-fork-ping" + && has(event.entity.linked_change_proposal) && !event.state.change_proposal.is_fork """ And a dummy agent that would: @@ -69,6 +81,9 @@ Feature: Fork PR dispatch | Prove fork execution | write_fixture| output/dispatch-fork-ok.json, fixtures/dispatch/ok.json | When a fork pull request is opened And the fork pull request is labeled "ready-for-fork-ping" + # The label branch of fork-pr-ping matches this event; the shim skips it. + Then the harness "fork-pr-ping" agent did not run + When the write actor posts "/fs-fork-ping" on the fork pull request Then the harness "fork-pr-ping" workflow completes successfully And the agent will succeed to Prove fork execution And the harness "fork-pr-ping" was dispatched exactly 1 time @@ -86,13 +101,14 @@ Feature: Fork PR dispatch image: ghcr.io/fullsend-ai/fullsend-sandbox:latest policy: policies/base.yaml trigger: | - event.entity.kind == "change_proposal" - && event.transition.kind == "label_changed" - && event.transition.label.name == "ready-for-fork-killswitch" + event.transition.kind == "comment_added" + && has(event.transition.comment.command) + && event.transition.comment.command == "/fs-fork-killswitch" + && has(event.entity.linked_change_proposal) """ And the kill switch is active When a fork pull request is opened - And the fork pull request is labeled "ready-for-fork-killswitch" + And the write actor posts "/fs-fork-killswitch" on the fork pull request Then the harness "fork-pr-killswitch" agent did not run Scenario: Fork PR kill switch in config.base.yaml blocks all harnesses @@ -105,16 +121,17 @@ Feature: Fork PR dispatch image: ghcr.io/fullsend-ai/fullsend-sandbox:latest policy: policies/base.yaml trigger: | - event.entity.kind == "change_proposal" - && event.transition.kind == "label_changed" - && event.transition.label.name == "ready-for-fork-killswitch-base" + event.transition.kind == "comment_added" + && has(event.transition.comment.command) + && event.transition.comment.command == "/fs-fork-killswitch-base" + && has(event.entity.linked_change_proposal) """ And the kill switch is active in config.base.yaml When a fork pull request is opened - And the fork pull request is labeled "ready-for-fork-killswitch-base" + And the write actor posts "/fs-fork-killswitch-base" on the fork pull request Then the harness "fork-pr-killswitch-base" agent did not run - Scenario: Fork PR sync + label dispatches harness + Scenario: Fork PR push does not dispatch; a maintainer comment does Given a custom harness "fork-pr-sync" with: """ agent: agents/triage.md @@ -124,16 +141,20 @@ Feature: Fork PR dispatch image: ghcr.io/fullsend-ai/fullsend-sandbox:latest policy: policies/base.yaml trigger: | - event.entity.kind == "change_proposal" - && event.transition.kind == "label_changed" - && event.transition.label.name == "ready-for-fork-sync" + (event.entity.kind == "change_proposal" + && event.transition.kind == "synchronized") + || (event.transition.kind == "comment_added" + && has(event.transition.comment.command) + && event.transition.comment.command == "/fs-fork-sync" + && has(event.entity.linked_change_proposal)) """ And a dummy agent that would: | description | op | args | | Prove sync execution | write_fixture| output/dispatch-sync-ok.json, fixtures/dispatch/ok.json | When a fork pull request is opened And a commit is pushed to the fork pull request - And the fork pull request is labeled "ready-for-fork-sync" + Then the harness "fork-pr-sync" agent did not run + When the write actor posts "/fs-fork-sync" on the fork pull request Then the harness "fork-pr-sync" workflow completes successfully And the agent will succeed to Prove sync execution And the harness "fork-pr-sync" was dispatched exactly 1 time diff --git a/e2e/behaviour/features/platform/actor-authorization.feature b/e2e/behaviour/features/platform/actor-authorization.feature index 0927783f9c..8de0b3fc7e 100644 --- a/e2e/behaviour/features/platform/actor-authorization.feature +++ b/e2e/behaviour/features/platform/actor-authorization.feature @@ -77,6 +77,8 @@ Feature: Platform actor authorization When the write actor posts "/fs-do" on the issue Then the harness "do-needs-triage" workflow completes successfully + # GitHub only: fork pull request dispatch follows the GitHub shim (#9221). + @skip:gitlab Scenario: outsider opens a pull request from a fork Given a fork "test-repo-fork" of the enrolled test repository owned by the outsider And a custom harness "fork-auth-probe" with: @@ -88,15 +90,18 @@ Feature: Platform actor authorization image: ghcr.io/fullsend-ai/fullsend-sandbox:latest policy: policies/base.yaml trigger: | - event.entity.kind == "change_proposal" - && (event.transition.kind == "opened" - || (event.transition.kind == "label_changed" - && event.transition.label.name == "ready-for-fork-auth")) + event.transition.kind == "comment_added" + && has(event.transition.comment.command) + && event.transition.comment.command == "/fs-fork-auth" + && has(event.entity.linked_change_proposal) """ + # Fork pull request events never dispatch on pull_request (#9221), and + # GitHub holds a first-time contributor's run for approval; a comment on + # the pull request is the way in, so the role threshold decides there. When a fork pull request is opened by the outsider + And the outsider posts "/fs-fork-auth" on the fork pull request Then the harness dispatch completes with an empty matrix - And the harness "fork-auth-probe" agent did not run And the harness "fork-auth-probe" was dispatched exactly 0 times - When the fork pull request is labeled "ready-for-fork-auth" + When the write actor posts "/fs-fork-auth" on the fork pull request Then the harness "fork-auth-probe" workflow completes successfully And the agent will succeed to Prove run diff --git a/hack/workflow_triggers_test.py b/hack/workflow_triggers_test.py index 19984229fb..73de765351 100644 --- a/hack/workflow_triggers_test.py +++ b/hack/workflow_triggers_test.py @@ -14,9 +14,6 @@ WORKFLOWS = Path(__file__).resolve().parent.parent / ".github" / "workflows" -# The consumer shim moves in #9230; drop it from this set when that merges. -ALLOWED = {"fullsend.yaml"} - def triggers(path: Path) -> set[str]: doc = yaml.safe_load(path.read_text()) or {} @@ -36,16 +33,9 @@ def triggers(path: Path) -> set[str]: @pytest.mark.parametrize("path", FILES, ids=lambda p: p.name) def test_no_pull_request_target_trigger(path: Path) -> None: - if path.name in ALLOWED: - pytest.skip("moves in #9230") assert "pull_request_target" not in triggers(path) -def test_allowlist_entries_exist() -> None: - names = {p.name for p in FILES} - assert names >= ALLOWED - - def test_trigger_parser_reads_on_keys(tmp_path: Path) -> None: wf = tmp_path / "x.yml" wf.write_text("on:\n pull_request_target:\n types: [opened]\n") diff --git a/internal/cli/prepareartifacts.go b/internal/cli/prepareartifacts.go index d99218baa8..a5c97c190d 100644 --- a/internal/cli/prepareartifacts.go +++ b/internal/cli/prepareartifacts.go @@ -229,9 +229,10 @@ func artifactRunSource(absFullsendDir, eventFile string) (source, how string, er // nativeGitHubEvents are the GitHub Actions event names that only GitHub // itself starts: the triggers of the shipped fullsend shim (issues, -// issue_comment, pull_request_target, pull_request_review) plus the -// pull_request and pull_request_review_comment events a custom caller may -// use. None of them can carry a run started from a tracker. +// issue_comment, pull_request, pull_request_review), pull_request_target +// from shims that have not been upgraded (#9221), and the +// pull_request_review_comment event a custom caller may use. None of them +// can carry a run started from a tracker. // // In a reusable workflow GITHUB_EVENT_NAME is the caller's event. The Jira // poller's caller runs on schedule or workflow_dispatch, so the stage jobs diff --git a/internal/cli/retro_route_test.go b/internal/cli/retro_route_test.go index fee8a7c14e..128177adb7 100644 --- a/internal/cli/retro_route_test.go +++ b/internal/cli/retro_route_test.go @@ -155,22 +155,22 @@ func TestRouteBuiltinAgent_Retro(t *testing.T) { wantDecision: routeRun, }, { - name: "pull_request: PR closed by its read-only author starts a retro (lifecycle-close exception)", + name: "pull_request: PR closed by its read-only author is denied", agents: []config.AgentEntry{{Name: "retro", Trigger: routeTrigger(t, "retro")}}, event: routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroReadAuthor, "pull_request", "closed"), - wantDecision: routeRun, + wantDecision: routeSkip, wantReason: "closed pull request retro requires write", }, { - name: "pull_request: PR closed by an app bot without a role starts a retro (lifecycle-close exception)", + name: "pull_request: PR closed by an app bot without write is denied", agents: []config.AgentEntry{{Name: "retro", Trigger: routeTrigger(t, "retro")}}, event: routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroAppBot, "pull_request", "closed"), - wantDecision: routeRun, + wantDecision: routeSkip, wantReason: "closed pull request retro requires write", }, { - name: "pull_request: PR closed by a triage user starts a retro (lifecycle-close exception)", + name: "pull_request: PR closed by a triage user is denied", agents: []config.AgentEntry{{Name: "retro", Trigger: routeTrigger(t, "retro")}}, event: routeRetroEvent(routeRetroPR, routeRetroClosed, routeRetroTriager, "pull_request", "closed"), - wantDecision: routeRun, + wantDecision: routeSkip, wantReason: "closed pull request retro requires write", }, { name: "/fs-retro from a triage user is not authorized", diff --git a/internal/scaffold/cel_route_test.go b/internal/scaffold/cel_route_test.go index f57ebe8e9c..c74da1ee6e 100644 --- a/internal/scaffold/cel_route_test.go +++ b/internal/scaffold/cel_route_test.go @@ -96,6 +96,16 @@ var ( "EVENT_NAME": "pull_request_target", "EVENT_ACTION": "closed", "PR_USER_LOGIN": "someone", "EVENT_SENDER_LOGIN": "", } + celRouteSameRepoClosed = map[string]string{ + "EVENT_NAME": "pull_request", "EVENT_ACTION": "closed", + "PR_USER_LOGIN": "someone", "PR_HEAD_REPO": "acme/widgets", "PR_BASE_REPO": "acme/widgets", + "EVENT_SENDER_LOGIN": "", + } + celRouteSameRepoLabel = map[string]string{ + "EVENT_NAME": "pull_request", "EVENT_ACTION": "labeled", + "TRIGGERING_LABEL": "ready-for-review", "PR_USER_LOGIN": "someone", + "PR_HEAD_REPO": "acme/widgets", "PR_BASE_REPO": "acme/widgets", + } celRoutePRComment = map[string]string{ "EVENT_NAME": "issue_comment", "EVENT_ACTION": "created", "COMMENT_BODY": "looks good", "ISSUE_IS_PR": "true", @@ -153,13 +163,15 @@ func TestRouteJob_NoReviewEntryIsByteIdentical(t *testing.T) { " - name: prioritize\n model: sonnet\n", } for name, event := range map[string]map[string]string{ - "review label": celRouteReviewLabel, - "other label": celRouteOtherLabel, - "closed": celRouteClosed, - "PR comment": celRoutePRComment, - "issue comment": celRouteIssueComment, - "triage label": celRouteTriageLabel, - "other issue label": celRouteIssueOtherLabel, + "review label": celRouteReviewLabel, + "other label": celRouteOtherLabel, + "closed": celRouteClosed, + "pull_request closed": celRouteSameRepoClosed, + "pull_request label": celRouteSameRepoLabel, + "PR comment": celRoutePRComment, + "issue comment": celRouteIssueComment, + "triage label": celRouteTriageLabel, + "other issue label": celRouteIssueOtherLabel, } { for cfgName, cfg := range configs { t.Run(name+"/"+cfgName, func(t *testing.T) { @@ -257,6 +269,14 @@ func TestCELRouteOptIn_EventGate(t *testing.T) { {"review stage on an issue comment does not fit", "issue_comment", "false", "review", "created", "/fs-review", ""}, {"retro stage on an open PR event does not fit", "pull_request_target", "false", "retro", "opened", "", ""}, {"review stage on a closed PR does not fit", "pull_request_target", "false", "review", "closed", "", ""}, + // pull_request (the shim trigger since #9221) selects like pull_request_target. + {"pull_request event with no bash stage", "pull_request", "false", "", "opened", "", "review"}, + {"pull_request event routed to review", "pull_request", "false", "review", "synchronize", "", "review"}, + {"pull_request event routed to another stage", "pull_request", "false", "fix", "opened", "", ""}, + {"pull_request closed routed to retro", "pull_request", "false", "retro", "closed", "", "retro"}, + {"pull_request closed with no bash stage", "pull_request", "false", "", "closed", "", "retro"}, + {"retro stage on an open pull_request does not fit", "pull_request", "false", "retro", "opened", "", ""}, + {"review stage on a closed pull_request does not fit", "pull_request", "false", "review", "closed", "", ""}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { @@ -336,21 +356,27 @@ printf '%s\n' "${MOCK_PERMISSION_ROLE:-none}" {name: "actor with no permission is denied", role: "none"}, {name: "permission lookup failure is denied", lookupErr: true}, } - for _, tc := range cases { - t.Run(tc.name, func(t *testing.T) { - env := map[string]string{ - "EVENT_NAME": "pull_request_target", - "EVENT_ACTION": "closed", - "EVENT_SENDER_LOGIN": "closer", - "GITHUB_REPOSITORY": "org/repo", - "MOCK_PERMISSION_ROLE": tc.role, - } - if tc.lookupErr { - env["MOCK_PERMISSION_ERROR"] = "true" - } - got := runRouteStep(t, "Determine stage", env, map[string]string{"bin/gh": ghStub}) - assert.Equal(t, tc.wantStage, got.outputs["stage"]) - }) + // pull_request is the shim trigger since #9221; a same-repo close + // follows the same write threshold as pull_request_target. + for _, event := range []string{"pull_request_target", "pull_request"} { + for _, tc := range cases { + t.Run(event+"/"+tc.name, func(t *testing.T) { + env := map[string]string{ + "EVENT_NAME": event, + "EVENT_ACTION": "closed", + "EVENT_SENDER_LOGIN": "closer", + "GITHUB_REPOSITORY": "org/repo", + "PR_HEAD_REPO": "org/repo", + "PR_BASE_REPO": "org/repo", + "MOCK_PERMISSION_ROLE": tc.role, + } + if tc.lookupErr { + env["MOCK_PERMISSION_ERROR"] = "true" + } + got := runRouteStep(t, "Determine stage", env, map[string]string{"bin/gh": ghStub}) + assert.Equal(t, tc.wantStage, got.outputs["stage"]) + }) + } } } @@ -576,7 +602,8 @@ func TestCELRouteStepsGatedAndIsolated(t *testing.T) { assert.True(t, step.ContinueOnError, "step %q must continue on error", step.Name) switch step.ID { case "cel-opt-in": - assert.Equal(t, "${{ github.event_name == 'pull_request_target' || github.event_name == 'issue_comment' || github.event_name == 'issues' }}", step.If) + assert.Equal(t, "${{ github.event_name == 'pull_request_target' || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]')) || github.event_name == 'issue_comment' || github.event_name == 'issues' }}", step.If, + "CEL routing covers same-repo pull_request events and never a fork or Dependabot PR on pull_request (#9221)") case "cel-config": assert.Equal(t, "steps.cel-opt-in.outputs.opt_in == 'true'", step.If) default: diff --git a/internal/scaffold/fullsend-repo/templates/shim-per-repo.yaml b/internal/scaffold/fullsend-repo/templates/shim-per-repo.yaml index cc9e5287ba..3370151798 100644 --- a/internal/scaffold/fullsend-repo/templates/shim-per-repo.yaml +++ b/internal/scaffold/fullsend-repo/templates/shim-per-repo.yaml @@ -3,10 +3,17 @@ # Routes events to agent workflows via reusable-dispatch.yml. # All agent execution happens in this repository's context. # -# Security: pull_request_target runs the BASE branch version of this workflow, -# preventing PRs from modifying it to exfiltrate credentials. -# This shim never checks out PR code, so it is not vulnerable to "pwn request" -# attacks. +# Security: pull request events use pull_request, not pull_request_target +# (GitHub blocks pull_request_target by default in public repositories; +# ADR 0164). On pull_request this workflow runs from the PR's own +# copy and forwards the repository secrets, so the dispatch job runs only for +# same-repo PRs, whose authors already have write access. Fork PRs are skipped +# here and again in reusable-dispatch.yml (a fork cannot edit the upstream +# copy; a vendored copy runs from the PR); a maintainer comments /fs-review +# to review one. In private repositories keep "Send secrets to workflows +# from pull requests" and "Send write tokens to workflows from pull +# requests" (Settings > Actions > General) turned off. +# reusable-dispatch.yml checks out the base side for pull request events. # # Routing: this shim forwards the raw event context to reusable-dispatch.yml, # which determines the stage and runs the agent inline (ADR 62). @@ -21,7 +28,7 @@ on: types: [opened, edited, labeled] issue_comment: types: [created] - pull_request_target: + pull_request: types: [opened, synchronize, ready_for_review, closed, labeled, unlabeled] pull_request_review: types: [submitted] @@ -31,8 +38,10 @@ permissions: {} jobs: dispatch: if: >- - (github.event_name != 'pull_request_target' && github.event_name != 'pull_request_review' + (github.event_name != 'pull_request' && github.event_name != 'pull_request_review' || github.event.pull_request.head.ref != 'fullsend/scaffold-install') + && (github.event_name != 'pull_request' + || github.event.pull_request.head.repo.id == github.repository_id) && (github.event_name != 'issue_comment' || startsWith(github.event.comment.body, '/fs-')) permissions: diff --git a/internal/scaffold/pr_trigger_test.go b/internal/scaffold/pr_trigger_test.go new file mode 100644 index 0000000000..3ce1edc169 --- /dev/null +++ b/internal/scaffold/pr_trigger_test.go @@ -0,0 +1,315 @@ +package scaffold + +import ( + "regexp" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v3" +) + +// shimTriggers decodes only the on: block of a shim workflow. +type shimTriggers struct { + On map[string]struct { + Types []string `yaml:"types"` + } `yaml:"on"` +} + +// sameRepoGuard is the job if: clause, as github/gh-aw compiles it for +// pull_request, that skips fork PRs (#9221). +const sameRepoGuard = "github.event.pull_request.head.repo.id == github.repository_id" + +// TestShimPullRequestTrigger checks that the per-repo shim (and fullsend's own +// copy of it) triggers on pull_request, never pull_request_target, which +// GitHub blocks by default in public repositories from 2026-12-02 (#9221), +// and that the dispatch job skips fork PRs. +func TestShimPullRequestTrigger(t *testing.T) { + cases := []struct { + name string + content func(t *testing.T) []byte + }{ + {"shim-per-repo", loadScaffoldFile("templates/shim-per-repo.yaml")}, + {"fullsend.yaml", loadRepoFile(".github/workflows/fullsend.yaml")}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + content := tc.content(t) + + var triggers shimTriggers + require.NoError(t, yaml.Unmarshal(content, &triggers)) + assert.NotContains(t, triggers.On, "pull_request_target", + "the shim must not trigger on pull_request_target") + require.Contains(t, triggers.On, "pull_request") + assert.ElementsMatch(t, + []string{"opened", "synchronize", "ready_for_review", "closed", "labeled", "unlabeled"}, + triggers.On["pull_request"].Types) + + var wf callerWorkflow + require.NoError(t, yaml.Unmarshal(content, &wf)) + dispatch, ok := wf.Jobs["dispatch"] + require.True(t, ok, "dispatch job not found") + assert.Contains(t, dispatch.If, + "(github.event_name != 'pull_request'\n || "+sameRepoGuard+")", + "the dispatch job must skip fork PRs on pull_request") + assert.NotContains(t, dispatch.If, "pull_request_target") + }) + } +} + +// trustedWorkflowSHA is the ref for files from the reusable workflow's own +// repository. A vendored install calls the workflow with ./, so on +// pull_request it runs from the caller's commit and job.workflow_sha equals +// github.sha, the PR merge commit; the base SHA is used then. A remote call +// (@main, @) never equals the merge commit and keeps job.workflow_sha. +const trustedWorkflowSHA = "(github.event_name == 'pull_request' && job.workflow_sha == github.sha" + + " && github.event.pull_request.base.sha || job.workflow_sha)" + +// checkoutSteps returns every actions/checkout step's with: block, by job. +func checkoutSteps(t *testing.T, content []byte) map[string][]map[string]string { + t.Helper() + var wf struct { + Jobs map[string]struct { + Steps []struct { + Name string `yaml:"name"` + Uses string `yaml:"uses"` + With map[string]string `yaml:"with"` + } `yaml:"steps"` + } `yaml:"jobs"` + } + require.NoError(t, yaml.Unmarshal(content, &wf)) + out := map[string][]map[string]string{} + for job, j := range wf.Jobs { + for _, step := range j.Steps { + if !strings.HasPrefix(step.Uses, "actions/checkout@") { + continue + } + with := map[string]string{"name": step.Name} + for k, v := range step.With { + with[k] = v + } + out[job] = append(out[job], with) + } + } + return out +} + +// TestEveryCheckoutHasTrustedRef checks every actions/checkout step in the +// reusable workflows. With no ref, checkout uses github.ref, which on +// pull_request is the PR merge commit, so every step must name a ref that is +// trusted on pull_request: +// - the caller repository at the base SHA (or the default branch, which is +// what github.ref was on pull_request_target); +// - the reusable workflow's repository at trustedWorkflowSHA; +// - the fix job's explicit PR-head checkout, which runs on pull_request_review. +func TestEveryCheckoutHasTrustedRef(t *testing.T) { + for _, file := range []string{".github/workflows/reusable-dispatch.yml", ".github/workflows/reusable-prioritize.yml"} { + t.Run(file, func(t *testing.T) { + steps := checkoutSteps(t, loadRepoFile(file)(t)) + require.NotEmpty(t, steps) + for job, list := range steps { + for _, with := range list { + ref, repo := with["ref"], with["repository"] + where := job + " / " + with["name"] + require.NotEmpty(t, ref, "%s: checkout must set ref", where) + switch { + case repo == "${{ job.workflow_repository }}": + assert.Equal(t, "${{ "+trustedWorkflowSHA+" }}", ref, where) + case ref == "${{ steps.context.outputs.head_ref }}": + assert.Equal(t, "fix", job, "%s: only the fix job checks out the PR head", where) + case repo == "": + assert.Regexp(t, `github\.event_name == 'pull_request'[ )]`, ref, where) + assert.Contains(t, ref, "github.event_name == 'pull_request_target'", where) + assert.True(t, strings.HasSuffix(ref, "&& github.event.pull_request.base.sha || github.sha }}"), "%s: %s", where, ref) + default: + assert.Contains(t, []string{"${{ github.repository }}", "${{ matrix.source_repo }}"}, repo, where) + assert.Contains(t, ref, "github.event_name == 'pull_request' && ", where) + assert.True(t, strings.HasSuffix(ref, + "&& format('refs/heads/{0}', github.event.repository.default_branch) || '' }}"), + "%s: target-repo checkout must use the default branch on pull_request: %s", where, ref) + } + } + } + }) + } +} + +// TestWorkflowSHAUsesAreTrusted checks that every expression that reads +// job.workflow_sha (checkout refs, CLI install and version inputs, cache +// keys) goes through trustedWorkflowSHA. +func TestWorkflowSHAUsesAreTrusted(t *testing.T) { + for _, file := range []string{".github/workflows/reusable-dispatch.yml", ".github/workflows/reusable-prioritize.yml"} { + t.Run(file, func(t *testing.T) { + var uses int + for _, line := range strings.Split(string(loadRepoFile(file)(t)), "\n") { + if !strings.Contains(line, "${{") || !strings.Contains(line, "job.workflow_sha") { + continue + } + uses++ + assert.NotContains(t, strings.ReplaceAll(line, trustedWorkflowSHA, ""), "job.workflow_sha", + "job.workflow_sha must be read through the trusted expression: %s", strings.TrimSpace(line)) + } + assert.NotZero(t, uses) + }) + } +} + +// prDispatchGuard skips fork and Dependabot PRs on pull_request. +const prDispatchGuard = "(github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name ==" + + " github.event.pull_request.base.repo.full_name && github.actor != 'dependabot[bot]'))" + +// TestHarnessJobsSkipForkPullRequest checks that the harness jobs, which +// bypass "Determine stage", also never run for a fork or Dependabot PR on +// pull_request. +func TestHarnessJobsSkipForkPullRequest(t *testing.T) { + content := loadRepoFile(".github/workflows/reusable-dispatch.yml")(t) + var wf struct { + Jobs map[string]struct { + If string `yaml:"if"` + } `yaml:"jobs"` + } + require.NoError(t, yaml.Unmarshal(content, &wf)) + for _, job := range []string{"harness-dispatch", "harness-run"} { + j, ok := wf.Jobs[job] + require.True(t, ok, "job %q not found", job) + assert.Contains(t, j.If, prDispatchGuard, "%s must skip fork and Dependabot PRs on pull_request", job) + } +} + +// TestReviewDedupStepsSkipForkPullRequest checks that the route job's +// synchronize review-dedup steps, which run before "Determine stage", do no +// work for a fork or Dependabot PR on pull_request. +func TestReviewDedupStepsSkipForkPullRequest(t *testing.T) { + content := loadRepoFile(".github/workflows/reusable-dispatch.yml")(t) + var wf struct { + Jobs map[string]struct { + Steps []struct { + Name string `yaml:"name"` + If string `yaml:"if"` + } `yaml:"steps"` + } `yaml:"jobs"` + } + require.NoError(t, yaml.Unmarshal(content, &wf)) + var checked int + for _, step := range wf.Jobs["route"].Steps { + // Steps gated on the routed stage already exclude these PRs. + if !strings.Contains(step.If, "inputs.event_action == 'synchronize'") || + strings.Contains(step.If, "steps.route.outputs.stage") { + continue + } + checked++ + assert.Contains(t, step.If, prDispatchGuard, "route step %q must skip fork and Dependabot PRs on pull_request", step.Name) + } + assert.NotZero(t, checked, "route job synchronize steps") +} + +// TestPullRequestTargetBranchesCoverPullRequest fails on any line in the +// reusable workflows that branches on pull_request_target without also +// naming pull_request. Shims that have not upgraded still send +// pull_request_target, upgraded ones send pull_request, and a branch on only +// one of them silently changes behaviour for the other (#9221). +func TestPullRequestTargetBranchesCoverPullRequest(t *testing.T) { + allowed := []string{ + "allow-unsafe-pr-checkout:", // checkout's fork guard runs only on pull_request_target + "::warning::This repository's fullsend shim still triggers on pull_request_target", + `if [[ "${EVENT_NAME}" == "pull_request_target" && "${REPO_VISIBILITY:-}" == "public" ]]; then`, + } + pr := regexp.MustCompile(`\bpull_request\b`) + for _, file := range []string{".github/workflows/reusable-dispatch.yml", ".github/workflows/reusable-prioritize.yml"} { + t.Run(file, func(t *testing.T) { + for i, line := range strings.Split(string(loadRepoFile(file)(t)), "\n") { + code := strings.TrimSpace(line) + if strings.HasPrefix(code, "#") || !strings.Contains(code, "pull_request_target") { + continue + } + skip := false + for _, a := range allowed { + if strings.Contains(code, a) { + skip = true + break + } + } + if skip { + continue + } + assert.Regexp(t, pr, code, "%s:%d branches on pull_request_target without pull_request: %s", file, i+1, code) + } + }) + } +} + +// TestDetermineStagePullRequest runs "Determine stage" on pull_request events: +// same-repo PRs route like pull_request_target, fork PRs never route, and +// only pull_request_target prints the upgrade warning. +func TestDetermineStagePullRequest(t *testing.T) { + requireBash4(t) + requireYQ(t) + // A closed pull request routes retro only for a write closer (#8912); + // the stub answers the collaborator permission lookup with write. + const ghStub = "#!/usr/bin/env bash\nprintf '%s\\n' write\n" + pr := func(event, action, label, headRepo string) map[string]string { + return map[string]string{ + "EVENT_NAME": event, "EVENT_ACTION": action, + "TRIGGERING_LABEL": label, "PR_USER_LOGIN": "someone", + "PR_HEAD_REPO": headRepo, "PR_BASE_REPO": "acme/widgets", + "EVENT_ACTOR": "someone", "EVENT_SENDER_LOGIN": "closer", + "GITHUB_REPOSITORY": "acme/widgets", "REPO_VISIBILITY": "public", + } + } + privateRepo := pr("pull_request_target", "labeled", "ready-for-review", "acme/widgets") + privateRepo["REPO_VISIBILITY"] = "private" + dependabot := func(event, action string) map[string]string { + env := pr(event, action, "", "acme/widgets") + env["PR_USER_LOGIN"] = "dependabot[bot]" + env["EVENT_ACTOR"] = "dependabot[bot]" + env["EVENT_SENDER_LOGIN"] = "dependabot[bot]" + return env + } + humanPushToDependabot := dependabot("pull_request", "synchronize") + humanPushToDependabot["EVENT_ACTOR"] = "maintainer" + humanPushToDependabot["EVENT_SENDER_LOGIN"] = "maintainer" + botOpened := pr("pull_request", "opened", "", "acme/widgets") + botOpened["PR_USER_LOGIN"] = "fullsend-ai-coder[bot]" + botOpened["EVENT_ACTOR"] = "fullsend-ai-coder[bot]" + cases := []struct { + name string + env map[string]string + wantStage string + warning bool + }{ + {"same-repo label", pr("pull_request", "labeled", "ready-for-review", "acme/widgets"), "review", false}, + {"same-repo closed", pr("pull_request", "closed", "", "acme/widgets"), "retro", false}, + {"same-repo other label", pr("pull_request", "labeled", "documentation", "acme/widgets"), "", false}, + {"fork label", pr("pull_request", "labeled", "ready-for-review", "someone/widgets"), "", false}, + {"fork closed", pr("pull_request", "closed", "", "someone/widgets"), "", false}, + {"deleted head repo", pr("pull_request", "closed", "", ""), "", false}, + {"pull_request_target label", pr("pull_request_target", "labeled", "ready-for-review", "acme/widgets"), "review", true}, + {"pull_request_target fork closed", pr("pull_request_target", "closed", "", "someone/widgets"), "retro", true}, + {"same-repo bot opened", botOpened, "review", false}, + {"dependabot opened", dependabot("pull_request", "opened"), "", false}, + {"dependabot closes its own PR", dependabot("pull_request", "closed"), "", false}, + // A human push runs with the repository's secrets, so it routes. + {"human push to a dependabot PR", humanPushToDependabot, "review", false}, + {"pull_request_target dependabot opened", dependabot("pull_request_target", "opened"), "review", true}, + // GitHub blocks pull_request_target only in public repositories. + {"pull_request_target in a private repository does not warn", privateRepo, "review", false}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + got := runRouteStep(t, "Determine stage", tc.env, map[string]string{"bin/gh": ghStub}) + assert.Equal(t, tc.wantStage, got.outputs["stage"]) + if tc.warning { + assert.Contains(t, got.stdout, "::warning::This repository's fullsend shim still triggers on pull_request_target") + } else { + assert.NotContains(t, got.stdout, "::warning::") + } + if tc.env["EVENT_NAME"] == "pull_request" && tc.env["PR_HEAD_REPO"] != "acme/widgets" { + assert.Contains(t, got.stdout, "::notice::Fork pull request on pull_request: not routed") + } + if tc.env["EVENT_NAME"] == "pull_request" && tc.env["EVENT_ACTOR"] == "dependabot[bot]" { + assert.Contains(t, got.stdout, "::notice::Dependabot pull request on pull_request: not routed") + } + }) + } +} diff --git a/pkg/behaviourtest/drivers/ci/githubactions/dispatch_reads_test.go b/pkg/behaviourtest/drivers/ci/githubactions/dispatch_reads_test.go index d5987c3b59..7048637f94 100644 --- a/pkg/behaviourtest/drivers/ci/githubactions/dispatch_reads_test.go +++ b/pkg/behaviourtest/drivers/ci/githubactions/dispatch_reads_test.go @@ -98,16 +98,23 @@ func TestHarnessDispatchAssertions_RequestCounts(t *testing.T) { func TestHarnessDispatchAssertions_SkippedRunNeedsNoJobs(t *testing.T) { t.Parallel() after := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) - fake := forge.NewFakeClient() - fake.WorkflowRunsList = map[string][]forge.WorkflowRun{"org/repo/fullsend.yaml": { - {ID: 1, Status: "completed", Conclusion: "skipped", CreatedAt: after.Format(time.RFC3339)}, - }} - fake.Errors["ListWorkflowRunJobs"] = errors.New("jobs must not be requested for a skipped workflow") - d := &Driver{Client: fake} - count, err := d.CountHarnessDispatches(context.Background(), "org", "repo", "fix", after) - require.NoError(t, err) - assert.Zero(t, count) - require.NoError(t, d.AssertNoHarnessAgentArtifact(context.Background(), "org", "repo", "fix", after)) + // action_required: a first-time contributor's fork pull request run held + // for approval; it ran no job and its listing can 404 (#9221). + for _, conclusion := range []string{"skipped", "action_required"} { + t.Run(conclusion, func(t *testing.T) { + t.Parallel() + fake := forge.NewFakeClient() + fake.WorkflowRunsList = map[string][]forge.WorkflowRun{"org/repo/fullsend.yaml": { + {ID: 1, Status: "completed", Conclusion: conclusion, CreatedAt: after.Format(time.RFC3339)}, + }} + fake.Errors["ListWorkflowRunJobs"] = errors.New("jobs must not be requested for a run that ran no job") + d := &Driver{Client: fake} + count, err := d.CountHarnessDispatches(context.Background(), "org", "repo", "fix", after) + require.NoError(t, err) + assert.Zero(t, count) + require.NoError(t, d.AssertNoHarnessAgentArtifact(context.Background(), "org", "repo", "fix", after)) + }) + } } func TestHarnessDispatchAssertions_NotStartedRunJobs(t *testing.T) { diff --git a/pkg/behaviourtest/drivers/ci/githubactions/empty_matrix_test.go b/pkg/behaviourtest/drivers/ci/githubactions/empty_matrix_test.go index 277f4d7058..2fdbece645 100644 --- a/pkg/behaviourtest/drivers/ci/githubactions/empty_matrix_test.go +++ b/pkg/behaviourtest/drivers/ci/githubactions/empty_matrix_test.go @@ -75,6 +75,8 @@ func TestWaitForHarnessEmptyMatrix_IgnoresSkippedRuns(t *testing.T) { client := emptyMatrixClient( []forge.WorkflowRun{ {ID: 10, Status: "completed", Conclusion: "skipped", CreatedAt: "2026-01-02T00:00:00Z"}, + // Held for approval: no jobs, so no listing entry (#9221). + {ID: 15, Status: "completed", Conclusion: "action_required", CreatedAt: "2026-01-02T00:00:30Z"}, {ID: 20, Status: "completed", Conclusion: "success", CreatedAt: "2026-01-02T00:01:00Z"}, }, map[int][]forge.WorkflowJob{ diff --git a/pkg/behaviourtest/drivers/ci/githubactions/githubactions.go b/pkg/behaviourtest/drivers/ci/githubactions/githubactions.go index 9906266173..15443ac51e 100644 --- a/pkg/behaviourtest/drivers/ci/githubactions/githubactions.go +++ b/pkg/behaviourtest/drivers/ci/githubactions/githubactions.go @@ -1785,6 +1785,15 @@ const ( jobsFatal ) +// runRanNoJob reports whether a completed run ran no job: skipped (every +// job's if: was false, e.g. the shim's run for a fork pull request) or +// action_required (held for a maintainer's approval, e.g. a first-time +// contributor's fork pull request on pull_request, #9221). Such a run holds +// no agent work and no dispatch decision, and its job listing can 404. +func runRanNoJob(r forge.WorkflowRun) bool { + return r.Status == "completed" && (r.Conclusion == "skipped" || r.Conclusion == "action_required") +} + // classifyJobsError is the only place that maps a run's status and a // jobs-listing error to a tolerance rule. The dispatch-count and // negative-assertion paths both route their listing errors through it @@ -1834,7 +1843,7 @@ func (d *Driver) settleHarnessDispatchCount(ctx context.Context, owner, repo, ag return 0, 0, err } for _, r := range allRuns { - if r.Status == "completed" && r.Conclusion == "skipped" { + if runRanNoJob(r) { continue } if runUnstarted(r.Status) { @@ -1956,9 +1965,9 @@ func (d *Driver) emptyMatrixPollOnce(ctx context.Context, remaining time.Duratio pending := 0 for i := range runs { r := runs[i] - // A skipped run ran no job, e.g. the shim's run for a bot comment, - // so it holds no dispatch decision. - if r.Status == "completed" && (r.Conclusion == "cancelled" || r.Conclusion == "skipped") { + // A skipped or approval-held run ran no job, e.g. the shim's run + // for a bot comment, so it holds no dispatch decision. + if (r.Status == "completed" && r.Conclusion == "cancelled") || runRanNoJob(r) { continue } if r.Status != "completed" { @@ -2039,7 +2048,7 @@ func (d *Driver) AssertNoHarnessAgentArtifact(ctx context.Context, owner, repo, return err } for _, r := range allRuns { - if r.Status == "completed" && r.Conclusion == "skipped" { + if runRanNoJob(r) { continue } jobs, err := d.Client.ListWorkflowRunJobs(ctx, owner, repo, r.ID) diff --git a/pkg/behaviourtest/steps/actors.go b/pkg/behaviourtest/steps/actors.go index 30fb171a6f..d2a56582f2 100644 --- a/pkg/behaviourtest/steps/actors.go +++ b/pkg/behaviourtest/steps/actors.go @@ -50,6 +50,9 @@ func registerActorSteps(sc *godog.ScenarioContext) { sc.Step(`^the (`+actorAlternation+`) posts "([^"]+)" on the pull request$`, func(ctx context.Context, actor, body string) (context.Context, error) { return ctx, whenActorPostsPRComment(world.FromContext(ctx), actor, body) }) + sc.Step(`^the (`+actorAlternation+`) posts "([^"]+)" on the fork pull request$`, func(ctx context.Context, actor, body string) (context.Context, error) { + return ctx, whenActorPostsForkPRComment(world.FromContext(ctx), actor, body) + }) sc.Step(`^the comment "([^"]+)" on the issue is authored by the (`+actorAlternation+`)$`, func(ctx context.Context, body, actor string) (context.Context, error) { return ctx, thenIssueCommentAuthoredBy(world.FromContext(ctx), body, actor) }) @@ -234,6 +237,25 @@ func whenActorPostsPRComment(w *world.World, actor, body string) error { return err } +// whenActorPostsForkPRComment posts body on the scenario's fork pull request +// as the named test actor. Fork pull request events no longer dispatch on +// pull_request (#9221); a maintainer's slash command on the pull request is +// the way to run an agent on one. +func whenActorPostsForkPRComment(w *world.World, actor, body string) error { + actorSCM, _, err := actorIdentity(w, actor) + if err != nil { + return err + } + if w.ForkPRNumber == 0 { + return fmt.Errorf("no fork pull request opened") + } + // Run created_at has second precision (#7957). + w.ScenarioStart = time.Now().Truncate(time.Second) + _, err = actorSCM.AddComment(context.Background(), + w.RepoOwner, w.RepoName, w.ForkPRNumber, body) + return err +} + // thenIssueCommentAuthoredBy checks that the scenario's issue has a // comment with exactly body, and that every such comment was authored // by the named test actor's login. Comments are read through the diff --git a/pkg/behaviourtest/steps/actors_test.go b/pkg/behaviourtest/steps/actors_test.go index 97aa6a8cc8..89f33efc48 100644 --- a/pkg/behaviourtest/steps/actors_test.go +++ b/pkg/behaviourtest/steps/actors_test.go @@ -24,6 +24,7 @@ type fakeActorSCM struct { comments []forge.IssueComment listErr error addedBodies []string + addedNumbers []int addedLabels []string createdIssue []string branches []string @@ -65,8 +66,9 @@ func (f *fakeActorSCM) CloseIssue(_ context.Context, _, _ string, number int) er return nil } -func (f *fakeActorSCM) AddComment(_ context.Context, _, _ string, _ int, body string) (*forge.IssueComment, error) { +func (f *fakeActorSCM) AddComment(_ context.Context, _, _ string, number int, body string) (*forge.IssueComment, error) { f.addedBodies = append(f.addedBodies, body) + f.addedNumbers = append(f.addedNumbers, number) return &forge.IssueComment{Body: body}, nil } @@ -296,6 +298,24 @@ func TestWhenActorPostsPRComment(t *testing.T) { require.ErrorContains(t, err, "TEST_ACTOR_WRITE_PAT not set") } +func TestWhenActorPostsForkPRComment(t *testing.T) { + t.Parallel() + + w, drivers := actorWorld() + w.PRNumber = 3 + require.ErrorContains(t, whenActorPostsForkPRComment(w, actorWrite, "/fs-review"), "no fork pull request opened") + + w.ForkPRNumber = 9 + require.NoError(t, whenActorPostsForkPRComment(w, actorWrite, "/fs-review")) + assert.Equal(t, []string{"/fs-review"}, drivers[actorWrite].addedBodies) + assert.Equal(t, []int{9}, drivers[actorWrite].addedNumbers, "the comment goes on the fork pull request") + assert.Empty(t, drivers["default"].addedBodies, "the comment must not use the e2e installation identity") + assert.False(t, w.ScenarioStart.IsZero()) + + err := whenActorPostsForkPRComment(&world.World{ForkPRNumber: 9}, actorWrite, "/fs-review") + require.ErrorContains(t, err, "TEST_ACTOR_WRITE_PAT not set") +} + func TestThenIssueCommentAuthoredBy(t *testing.T) { t.Parallel() diff --git a/pkg/behaviourtest/steps/fork.go b/pkg/behaviourtest/steps/fork.go index 3807e38938..4619b0de10 100644 --- a/pkg/behaviourtest/steps/fork.go +++ b/pkg/behaviourtest/steps/fork.go @@ -382,7 +382,8 @@ func openForkPullRequest(w *world.World, opener scm.Driver) error { return fmt.Errorf("no fork created: use 'Given a fork' first") } - w.ScenarioStart = time.Now() + // Run created_at has second precision (#7957). + w.ScenarioStart = time.Now().Truncate(time.Second) branch := fmt.Sprintf("behaviour-fork-pr-%d", time.Now().UnixNano()) ctx := context.Background() @@ -418,7 +419,8 @@ func whenForkPullRequestLabeled(w *world.World, label string) error { if w.ForkPRNumber == 0 { return fmt.Errorf("no fork pull request opened") } - w.ScenarioStart = time.Now() + // Run created_at has second precision (#7957). + w.ScenarioStart = time.Now().Truncate(time.Second) // Fork PRs are opened against the base repo, so label on the base repo. return w.SCM.AddIssueLabels(context.Background(), w.RepoOwner, w.RepoName, w.ForkPRNumber, label) } @@ -430,7 +432,8 @@ func whenCommitPushedToForkPR(w *world.World) error { return fmt.Errorf("no fork pull request opened") } - w.ScenarioStart = time.Now() + // Run created_at has second precision (#7957). + w.ScenarioStart = time.Now().Truncate(time.Second) ctx := context.Background() msg := fmt.Sprintf("behaviour: push to fork PR #%d", w.ForkPRNumber)