diff --git a/.github/workflows/persona-mention-reusable.yml b/.github/workflows/persona-mention-reusable.yml index fa89bb935..177a8d76b 100644 --- a/.github/workflows/persona-mention-reusable.yml +++ b/.github/workflows/persona-mention-reusable.yml @@ -6,6 +6,18 @@ # for every persona — personas do NOT each ship a mention workflow (§4.1); that # per-agent drift is exactly what the manifest exists to prevent. # +# The same router also serves the `pull_request` EVENT surface (#1165). Rather +# than resolve an addressed handle, the PR path DERIVES which personas fire from +# each manifest's declared surfaces (#756): it lists the personas in +# .github-private and dispatches every one that declares an enabled +# `pull_request` surface. This is solution-architect decision (b) on +# .github-private#1869 and the ADR-0007 consolidation — one agent-ingress path, +# not a second published runtime per role. The PR path binds EVERY brake the +# mention path binds (stop markers, opt-out, the write-mode gate, the trust +# floor, and the two recursion axes), so a PR event never becomes an ungated, +# un-held write surface. The two paths are independent jobs (`route` for +# comments, `route-pull-request` for PRs) so neither perturbs the other. +# # How a mention resolves, and why there is no index: # `validate-personas.py` enforces address.handle's slug == id == the persona's # directory name, so '@petry-projects/qa-lead' resolves to @@ -71,8 +83,10 @@ permissions: {} # no default permissions; each job grants only what it needs concurrency: # Serialise per comment, not per thread: two different personas addressed in # one comment are dispatched by a single run, and cancelling an in-flight route - # would silently drop a mention. - group: persona-mention-${{ github.event.comment.id || github.run_id }} + # would silently drop a mention. A pull_request event has no comment id, so it + # serialises per PR number instead (rapid `synchronize`s queue rather than race + # a double-dispatch); the comment key is evaluated first, unchanged. + group: persona-mention-${{ github.event.comment.id || github.event.pull_request.number || github.run_id }} cancel-in-progress: false jobs: @@ -250,7 +264,7 @@ jobs: continue fi - if [ -n "$opt_out" ] && printf '%s\n' "$LABELS" | grep -qxF "$opt_out"; then + if [ -n "$opt_out" ] && printf '%s\n' "$LABELS" | grep -qxF -- "$opt_out"; then echo "Item carries '${opt_out}' — persona '${slug}' is opted out here. Skipping." echo "::endgroup::" continue @@ -324,7 +338,7 @@ jobs: echo "::endgroup::" continue fi - if ! printf '%s\n' "$LABELS" | grep -qxF "$gate"; then + if ! printf '%s\n' "$LABELS" | grep -qxF -- "$gate"; then echo "Persona '${slug}' is write-mode and NOT armed — '${gate}' absent. Skipping." echo "::endgroup::" continue @@ -361,3 +375,314 @@ jobs: done < <(pm_extract_slugs "$COMMENT_BODY") echo "Dispatched ${dispatched} persona(s)." + + route-pull-request: + runs-on: ubuntu-latest + permissions: + contents: read # actions/checkout of the tooling repo + # The CHEAP pre-filter for the PR path, mirrored from pm_pr_should_route + # (tests/persona_mention.bats). It runs BEFORE the job starts, so secrets are + # never exposed to a run a bot, a marked PR body, or an untrusted author + # triggered. Same two recursion axes and conservative §4 default floor as the + # comment path's pre-filter — a PR event is no laxer: + # 1. bot actor — a PR opened by an agent identity never routes + # 2. marker — a PR body carrying ' automated PR' + [ "$status" -eq 1 ] +} + +@test "pm_pr_should_route blocks a PR from an author below the default floor" { + run pm_pr_should_route drive-by drive-by CONTRIBUTOR "PR body" + [ "$status" -eq 1 ] +} + +# --- pm_pr_route_verdict (the composed PR gauntlet — AC #2/#4 proof) -------- +# Given a manifest that DECLARES the pull_request surface enabled and its +# interaction contract, decide the verdict for one PR: stop-marker → write-gate +# → trust-floor → dispatch. Stop markers bind here exactly as on the mention +# path, and an unreadable contract fails CLOSED — proven per branch below. + +@test "pm_pr_route_verdict dispatches when no stop marker holds the PR" { + run pm_pr_route_verdict "$(manifest "$PR_ON")" "$(interaction)" OWNER <<<'enhancement' + [ "$status" -eq 0 ] + [ "$output" = "dispatch advisory" ] +} + +@test "pm_pr_route_verdict skips and NAMES the marker when the PR is held" { + run pm_pr_route_verdict "$(manifest "$PR_ON")" "$(interaction)" OWNER <<<'needs-human-review' + [ "$status" -eq 0 ] + [ "$output" = "skip stop-marker needs-human-review" ] +} + +@test "pm_pr_route_verdict honours a cross-persona hold on the PR path" { + run pm_pr_route_verdict "$(manifest "$PR_ON")" "$(interaction)" OWNER <<<'dev-lead:needs-human' + [ "$status" -eq 0 ] + [ "$output" = "skip stop-marker dev-lead:needs-human" ] +} + +@test "pm_pr_route_verdict fails CLOSED on an unparseable contract (never dispatches a held PR)" { + run pm_pr_route_verdict "$(manifest "$PR_ON")" 'this: [is: not: yaml' OWNER <<<'enhancement' + [ "$status" -eq 2 ] +} + +@test "pm_pr_route_verdict fails CLOSED on a malformed boolean stop_markers" { + run pm_pr_route_verdict "$(manifest "$PR_ON")" "$(interaction ' stop_markers: false')" OWNER <<<'enhancement' + [ "$status" -eq 2 ] +} + +@test "pm_pr_route_verdict dispatches when the contract declares no markers" { + run pm_pr_route_verdict "$(manifest "$PR_ON")" "$(interaction ' stop_markers: []')" OWNER <<<'needs-human-review' + [ "$status" -eq 0 ] + [ "$output" = "dispatch advisory" ] +} + +@test "pm_pr_route_verdict skips an unarmed write-mode PR (no gate label present)" { + run pm_pr_route_verdict "$(manifest ' - surface: pull_request + enabled: true + mode: write + gate_label: qa-lead')" "$(interaction)" OWNER <<<'enhancement' + [ "$status" -eq 0 ] + [ "$output" = "skip not-armed qa-lead" ] +} + +@test "pm_pr_route_verdict dispatches an armed write-mode PR" { + run pm_pr_route_verdict "$(manifest ' - surface: pull_request + enabled: true + mode: write + gate_label: qa-lead')" "$(interaction)" OWNER <<<'qa-lead' + [ "$status" -eq 0 ] + [ "$output" = "dispatch write" ] +} + +@test "pm_pr_route_verdict fails CLOSED on a write surface with no gate_label (never an ungated write)" { + run pm_pr_route_verdict "$(manifest ' - surface: pull_request + enabled: true + mode: write')" "$(interaction)" OWNER <<<'enhancement' + [ "$status" -eq 3 ] +} + +@test "pm_pr_route_verdict skips a PR author below the persona floor" { + run pm_pr_route_verdict "$(manifest ' - surface: pull_request + enabled: true + mode: advisory + trust_floor: [OWNER]')" "$(interaction)" MEMBER <<<'enhancement' + [ "$status" -eq 0 ] + [ "$output" = "skip below-floor" ] +}