Report a merge Equipo refuses itself as refused, not unknown
A merge the runner refused before anything reached the hub (no credential for the repository, or the repository not among the agent's) went down the "no answer, may have landed" path: the record stayed requested, the runner logged "merge outcome unknown", tried three times, and the step said merge_failed. The Assistant then told the person to try the go-ahead once more, which could never help. - forge: ErrMergeNoAccess (NoAccess, NoAccessCause: not_listed or no_credential). A Request error with no HTTP status that is a local refusal (no access, or ErrMergeRefused) is final for the attempt: the record is refused with reason no_access or refused, never ErrMergeUncertain. Transport errors and 5xx stay uncertain. - fileForge.Merge and HubMerge (no bearer) return NoAccess. - mergestep: merge_no_access, a new step reason (older instances record it as unknown), with a WARN naming the precondition and the repository, never a credential. - Instance: a merge refused for want of access (merge_no_access or merge_forbidden) stops its job on causeNoAccess. The Assistant's note says what is missing and that trying again will not help, the summary no longer says it waits for a go-ahead, and the job card has its own detail. Equipo's views show the reason's own words. - New strings are drafts marked COPY REVIEW PENDING (copy.go) with COPY REVIEW REQUIRED inventory rows; the release copy gate stays closed until they are reviewed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18 files changed,
+456
−28
.rastrillo/budgets.txt+5 −5docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+3 −0internal/equipo/chat/handoff.go+25 −4internal/equipo/chat/handoff_test.go+26 −1internal/equipo/chat/jobs.go+13 −4internal/equipo/chat/tools.go+10 −1internal/equipo/copy.go+10 −0internal/equipo/work_views_test.go+28 −0internal/runner/forge/merge.go+65 −5internal/runner/forge/merge_detail_test.go+15 −4internal/runner/forge/merge_test.go+94 −0internal/runner/thin/access_review_test.go+1 −1internal/runner/thin/forge.go+5 −3internal/runner/thin/mergeaccess_test.go+105 −0internal/runner/thin/mergestep.go+7 −0internal/thintest/assistant_job_state_contract_test.go+26 −0internal/thintest/assistant_team_contract_test.go+7 −0internal/wire/tasks.go+11 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 48456cfa..a2516dc3 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -14,8 +14,8 @@ perf GET /* skip Unknown private paths render 404; this fallback contains no scr |
| time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial reruns measured 18.079s and 22.031s. Keep migration, recovery, accounting and concurrency assertions; 60s leaves 30 percent headroom above loaded CI. |
| time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage. |
| -size internal/equipo 22564 - Paused work: the report card and task page lead, stop and Run now, in the person's zone (2026-11-24); measured 22564 source lines. |
| -size internal/wire 6946 - StepPaused, RunNowOffer, the paused job state, CarryOn, TimeZone and protocol 29's pinned release (2026-11-24); measured 6946 source lines. |
| +size internal/equipo 22574 - Paused work: the report card and task page lead, stop and Run now, in the person's zone (2026-11-24); a merge refused for want of access says so (2026-11-25); measured 22574 source lines. |
| +size internal/wire 6957 - StepPaused, RunNowOffer, the paused job state, CarryOn, TimeZone and protocol 29's pinned release (2026-11-24); the merge_no_access step reason (2026-11-25); measured 6957 source lines. |
| size internal/equipotest - 12017 Task 21 repairs historical migration and conversation fixtures after Plan 3, and the Rastrillo upgrade contract comparing served assets with what Assets serves; measured 0/12017 source/test lines. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
| time internal/runner 330s Plan 3 CI repair measured 292.120s for the full package (controller CI 472.184s). |
| @@ -38,7 +38,7 @@ time internal/runner/provider 15s Plan 3 CI repair measured 10.346s for the full |
| perf GET /releases/* skip Verified runner release file downloads, not browser GET screens. |
| perf GET /install.sh skip Mac runners: the one-line bootstrap a terminal pipes to sh, not a browser screen. |
| time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s; |
| -size internal/runner/thin 28478 22713 Forge review fixes, fileForge router coverage, authority and proposal regressions, and protocol 29's pinned release (2026-11-24); measured 28478/22713. |
| +size internal/runner/thin 28487 22818 Forge review fixes, fileForge router coverage, authority and proposal regressions, and protocol 29's pinned release (2026-11-24); a merge refused for want of access is final and logged with its cause (2026-11-25); measured 28487/22818. |
| time internal/thintest 240s Thin contract and page tests, the Assistant's and the models' included, share one harness. Measured 202s on a shared 16 CPU box (2026-11-13); CI runs two lanes. |
| time internal/runner/mac 30s Mac runners (Darwin worker): real process groups killed after a grace and proven gone (SIGTERM, SIGKILL, the marker sweep), and the probes run end to end with fake srt and xcodebuild, P6 killing. |
| time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s). |
| @@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device |
| perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen. |
| -size internal/equipo/chat 34507 9500 Paused work: zone, Run now prediction, pinned release checked against the tap, paused job card, carry_on, per-card sweep (2026-11-24); measured 34507/9500. |
| +size internal/equipo/chat 34546 9525 Paused work: zone, Run now prediction, pinned release checked against the tap, paused job card, carry_on, per-card sweep (2026-11-24); going live refused for want of access never invites a retry (2026-11-25); measured 34546/9525. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
| @@ -71,7 +71,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im |
| perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section. |
| time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally). |
| size internal/headless - 11437 Grant scenarios for a named repository (hub #48); the sign-in's account email at 1280 and 390; measured 11437 test lines. |
| -size internal/thintest - 34650 Paused work: the paused job contract, the paused card in the browser, housekeeping and day boxes on Madrid's clock (2026-11-24); measured 34650 test lines. |
| +size internal/thintest - 34683 Paused work: the paused job contract, the paused card in the browser, housekeeping and day boxes on Madrid's clock (2026-11-24); the no-access merge job contract (2026-11-25); measured 34683 test lines. |
| perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}. |
| perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage. |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 2d0d402b..49baa432 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -6904,6 +6904,9 @@ records remain unchanged. |
| | `api.already_running` | A request to run this work is already in progress. | A second Run now for the same hold (paused work review S2) | COPY ACCEPTED BY DELEGATION (Luna, 2026-11-24) | |
| | `api.offer_changed` | The option to run this work has changed. Check the current option, then try again. | A Run now tap whose offer changed since the page was drawn (paused work re-review R1) | COPY ACCEPTED BY DELEGATION (Luna, 2026-11-24) | |
| | `work.pause.run_now_may_bill` | This may use a plan that bills per use. | Under plain Run it now anyway, for an older runner, when a pay-per-use connection could take it (re-review R1) | COPY ACCEPTED BY DELEGATION (Luna, 2026-11-24) | |
| +| `work.reason.merge_no_access` | Equipo has no access to publish to this repository | Task page and work views: fills "Stopped: %s", "Merge stopped" and "%s stopped: %s. It waits on %s." when the runner refused a merge itself for want of a credential for the repository (honest merge refusals, 2026-11-25) | Runtime; COPY REVIEW REQUIRED | |
| +| `assistant.team.no_access` | The change is ready, but it can't go live until access to publish it is set up. | Told to the Assistant: where the work stands once going live was refused for want of access (merge_no_access, merge_forbidden), instead of "waits for a go-ahead" (honest merge refusals, 2026-11-25) | Runtime; COPY REVIEW REQUIRED | |
| +| `assistant.job.detail.no_access` | It can't go live until access to publish it is set up. | Base job card: a stopped job's sentence more when going live was refused for want of access (honest merge refusals, 2026-11-25) | Runtime; COPY REVIEW REQUIRED | |
| ## Task 21 |
diff --git a/internal/equipo/chat/handoff.go b/internal/equipo/chat/handoff.go| index 92b147c2..8805e138 100644 |
| --- a/internal/equipo/chat/handoff.go |
| +++ b/internal/equipo/chat/handoff.go |
| @@ -740,6 +740,23 @@ func (t *txn) handoffSettled(h handoffRecord) (bool, error) { |
| return true, nil |
| } |
| +// noAccess: s is a merge step refused for want of access to publish to |
| +// the repository: the runner had no credential for it (merge_no_access), |
| +// or the hub said the agent may not merge there (merge_forbidden). |
| +func noAccess(s *stepRecord) bool { |
| + return s != nil && s.Specialist == wire.SpecialistMerge && (s.Reason == wire.ReasonMergeNoAccess || s.Reason == "merge_forbidden") |
| +} |
| + |
| +// goingLiveCause is why going live stopped on the failed step s: |
| +// causeNoAccess when it is a merge refused for want of access (trying |
| +// again cannot help), else causeGoingLive. |
| +func goingLiveCause(s *stepRecord) string { |
| + if noAccess(s) { |
| + return causeNoAccess |
| + } |
| + return causeGoingLive |
| +} |
| + |
| // mergeFailed: the task is back at Ready to merge because its candidate's |
| // merge failed and ended (merge.go's mergeFailed): only the person's |
| // Merge tries it again. |
| @@ -827,6 +844,10 @@ func (t *txn) taskSummary(k taskRecord) (string, error) { |
| stage := "assistant.team.stage." + k.Stage |
| switch needs := pr.needsYou(k); { |
| case wire.FinalStage(k.Stage): |
| + case (needs == wire.NeedsMerge || needs == wire.NeedsRetry) && !k.CancelRequested && pr.merge != nil && pr.merge.State == wire.StepFailed && pr.merge.Terminated && noAccess(pr.merge): |
| + // Going live was refused for want of access: what is missing, |
| + // never "waits for a go-ahead". |
| + stage = "assistant.team.no_access" |
| case needs != "" && needs != wire.NeedsMerge: |
| stage = "assistant.team.stopped" |
| case !slices.Contains(wire.Stages, k.Stage) || k.CancelRequested: |
| @@ -932,9 +953,9 @@ func (t *txn) jobStop(h handoffRecord, settled bool) (reason, cause string, ende |
| pr := progressFor(k, steps) |
| switch needs := pr.needsYou(k); { |
| case needs == wire.NeedsMerge && mergeFailed(k, pr): |
| - return stopBlocked, causeGoingLive, false, nil |
| + return stopBlocked, goingLiveCause(pr.merge), false, nil |
| case needs == wire.NeedsRetry && live: |
| - return stopBlocked, causeGoingLive, false, nil |
| + return stopBlocked, goingLiveCause(newest), false, nil |
| case needs == wire.NeedsRetry: |
| failed = true |
| case needs != "" && needs != wire.NeedsMerge: |
| @@ -1115,9 +1136,9 @@ func (t *txn) jobNote(h handoffRecord) (string, error) { |
| return "", err |
| } |
| // A Publish asked again because going live failed is not ready: the |
| - // person tries again. |
| + // person tries again. Nor is going live refused for want of access. |
| ready := false |
| - if !asking && cause != causeGoingLive { |
| + if !asking && cause != causeGoingLive && cause != causeNoAccess { |
| if ready, err = t.readyToTry(h); err != nil { |
| return "", err |
| } |
diff --git a/internal/equipo/chat/handoff_test.go b/internal/equipo/chat/handoff_test.go| index 5114835b..09240c65 100644 |
| --- a/internal/equipo/chat/handoff_test.go |
| +++ b/internal/equipo/chat/handoff_test.go |
| @@ -101,7 +101,7 @@ func TestFallbackTitle(t *testing.T) { |
| // step, and going live that failed. Unknown, it is no line. |
| func TestJobNoteBlockedLines(t *testing.T) { |
| causes := []string{wire.CardAccess, wire.CardHome, wire.CardDirection, wire.CardSpecialist, wire.CardResearchSources, wire.CardResearchInventory, wire.CardMergeShips, wire.CardMergePolicy, |
| - wire.NeedsHeld, wire.NeedsBranchMoved, wire.NeedsReviewBlocked, wire.NeedsFixRounds, wire.NeedsMergeConflict, wire.NeedsMachineRemoved, wire.NeedsRunnerOffline, wire.NeedsMacSandbox, wire.NeedsDirection, causeGoingLive} |
| + wire.NeedsHeld, wire.NeedsBranchMoved, wire.NeedsReviewBlocked, wire.NeedsFixRounds, wire.NeedsMergeConflict, wire.NeedsMachineRemoved, wire.NeedsRunnerOffline, wire.NeedsMacSandbox, wire.NeedsDirection, causeGoingLive, causeNoAccess} |
| for _, c := range causes { |
| if line := blockedLine(c); line == "" || strings.HasSuffix(line, ".") || strings.ContainsAny(line, "\n[]") { |
| t.Errorf("%s: %q", c, line) |
| @@ -115,4 +115,29 @@ func TestJobNoteBlockedLines(t *testing.T) { |
| t.Errorf("%q: %q", c, line) |
| } |
| } |
| + // Going live refused for want of access: what is missing, and never |
| + // an invitation to try the same again. |
| + if line := blockedLine(causeNoAccess); !strings.Contains(line, "no access") || strings.Contains(strings.ToLower(line), "equipo") || strings.Contains(line, "need to try it again") || line == blockedLine(causeGoingLive) { |
| + t.Errorf("no access: %q", line) |
| + } |
| +} |
| + |
| +// TestGoingLiveCause: a failed merge refused for want of access (the |
| +// runner's own refusal, or the hub's forbidden) stops its job on access; |
| +// any other failed merge or publish on going live. |
| +func TestGoingLiveCause(t *testing.T) { |
| + for _, c := range []struct { |
| + s *stepRecord |
| + want string |
| + }{ |
| + {&stepRecord{Specialist: wire.SpecialistMerge, Reason: wire.ReasonMergeNoAccess}, causeNoAccess}, |
| + {&stepRecord{Specialist: wire.SpecialistMerge, Reason: "merge_forbidden"}, causeNoAccess}, |
| + {&stepRecord{Specialist: wire.SpecialistMerge, Reason: "merge_failed"}, causeGoingLive}, |
| + {&stepRecord{Specialist: wire.SpecialistPublish, Reason: wire.ReasonMergeNoAccess}, causeGoingLive}, |
| + {nil, causeGoingLive}, |
| + } { |
| + if got := goingLiveCause(c.s); got != c.want { |
| + t.Errorf("%+v: %q, want %q", c.s, got, c.want) |
| + } |
| + } |
| } |
diff --git a/internal/equipo/chat/jobs.go b/internal/equipo/chat/jobs.go| index 96a99efa..990c6fc0 100644 |
| --- a/internal/equipo/chat/jobs.go |
| +++ b/internal/equipo/chat/jobs.go |
| @@ -223,11 +223,16 @@ func (t *txn) jobView(h handoffRecord) (state, result, detail, carryOn string, l |
| } |
| return state, t.copy("assistant.job.status." + key), t.copy("assistant.job.detail." + key), "", links, nil |
| } |
| - return state, t.copy("assistant.job." + state), t.copy("assistant.job.detail." + state), "", links, nil |
| + detail = t.copy("assistant.job.detail." + state) |
| + if state == wire.JobStopped && key != "" { |
| + detail = t.copy("assistant.job.detail." + key) |
| + } |
| + return state, t.copy("assistant.job." + state), detail, "", links, nil |
| } |
| -// jobState is jobView's state, a working job's status key and the link |
| -// the state offers first, if any. |
| +// jobState is jobView's state, a working job's status key (a stopped |
| +// job's detail key when it has one of its own) and the link the state |
| +// offers first, if any. |
| func (t *txn) jobState(h handoffRecord) (state, key string, first *wire.CardLink, err error) { |
| if h.State == handoffCancelled { |
| return wire.JobStopped, "", nil, nil |
| @@ -238,7 +243,7 @@ func (t *txn) jobState(h handoffRecord) (state, key string, first *wire.CardLink |
| } |
| // The job's note's stop (jobStop): a blocker only the person clears |
| // stops it before its work settles too. |
| - reason, _, ended, err := t.jobStop(h, settled) |
| + reason, cause, ended, err := t.jobStop(h, settled) |
| if err != nil { |
| return "", "", nil, err |
| } |
| @@ -271,6 +276,10 @@ func (t *txn) jobState(h handoffRecord) (state, key string, first *wire.CardLink |
| if err != nil || asking { |
| return wire.JobAsking, "", nil, err |
| } |
| + if reason != "" && cause == causeNoAccess { |
| + // Going live refused for want of access: its own sentence. |
| + return wire.JobStopped, causeNoAccess, nil, nil |
| + } |
| if reason != "" { |
| return wire.JobStopped, "", nil, nil |
| } |
diff --git a/internal/equipo/chat/tools.go b/internal/equipo/chat/tools.go| index 9e0b19e4..fddce2f1 100644 |
| --- a/internal/equipo/chat/tools.go |
| +++ b/internal/equipo/chat/tools.go |
| @@ -134,9 +134,15 @@ const ( |
| // the person tries going live again. |
| const causeGoingLive = "going_live" |
| +// causeNoAccess: a job's merge was refused for want of access to publish |
| +// to its repository (goingLiveCause): trying again cannot help until |
| +// someone gives Equipo that access, so the person is never invited to. |
| +const causeNoAccess = "no_access" |
| + |
| // blockedLine is noteBlocked's plain words for what stopped a job for |
| // its person: a team card that waits on them (by kind), a task's need, |
| -// or going live that failed ("" for anything else). |
| +// going live that failed, or going live refused for want of access ("" for |
| +// anything else). |
| func blockedLine(cause string) string { |
| switch cause { |
| case wire.CardAccess: |
| @@ -167,6 +173,9 @@ func blockedLine(cause string) string { |
| return "they need to let it be tested on their Mac" |
| case causeGoingLive: |
| return "going live failed, and they need to try it again" |
| + case causeNoAccess: |
| + // COPY REVIEW PENDING (model-facing; honest merge refusals, 2026-11-25) |
| + return "there is no access to publish it where the work lives, and someone needs to set that access up before it can go live; trying again will not help until then" |
| } |
| return "" |
| } |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 824e399e..50246b63 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -2408,6 +2408,16 @@ var pageCopy = map[string]string{ |
| "api.already_running": "A request to run this work is already in progress.", // COPY ACCEPTED BY DELEGATION (Luna, 2026-11-24) |
| "api.offer_changed": "The option to run this work has changed. Check the current option, then try again.", // COPY ACCEPTED BY DELEGATION (Luna, 2026-11-24) |
| "work.pause.run_now_may_bill": "This may use a plan that bills per use.", // COPY ACCEPTED BY DELEGATION (Luna, 2026-11-24) |
| + |
| + // A merge refused for want of access to publish to the repository: the |
| + // runner had no credential for it (merge_no_access), or the hub said the |
| + // agent may not merge there (merge_forbidden). Trying again cannot help |
| + // until someone sets that access up, so none of these invites it: |
| + // the stopped merge's reason in Equipo; where the work stands, told to |
| + // the Assistant; and the stopped job card's sentence more. |
| + "work.reason.merge_no_access": "Equipo has no access to publish to this repository", // COPY REVIEW PENDING |
| + "assistant.team.no_access": "The change is ready, but it can't go live until access to publish it is set up.", // COPY REVIEW PENDING |
| + "assistant.job.detail.no_access": "It can't go live until access to publish it is set up.", // COPY REVIEW PENDING |
| } |
| // pasteLabels are the paste box's words, for the shared renderer, and |
diff --git a/internal/equipo/work_views_test.go b/internal/equipo/work_views_test.go| index fa9393e7..8f2aabf2 100644 |
| --- a/internal/equipo/work_views_test.go |
| +++ b/internal/equipo/work_views_test.go |
| @@ -1,6 +1,7 @@ |
| package equipo |
| import ( |
| + "fmt" |
| "strings" |
| "testing" |
| "time" |
| @@ -51,6 +52,33 @@ func TestStoppedMergeShowsTheHubAnswer(t *testing.T) { |
| t.Fatalf("no stopped merge in %+v", timelineOf(task, v)) |
| } |
| +// A merge the runner refused for want of access says what is missing, |
| +// on the stage line and in the timeline, not that Amadan did not merge |
| +// it; the runner's words on which precondition failed are its details. |
| +func TestStoppedMergeWithoutAccess(t *testing.T) { |
| + now := time.Now() |
| + words := copyText("work.reason." + wire.ReasonMergeNoAccess) |
| + if words == "" { |
| + t.Fatal("no words for merge_no_access") |
| + } |
| + tail := "error: forge: no access to publish to this repository (no_credential)" |
| + task := wire.Task{ID: "tk1", Creator: "a@example.com", Stage: wire.StageReadyToMerge, Steps: []wire.Step{{Specialist: wire.SpecialistMerge, State: wire.StepFailed, Reason: wire.ReasonMergeNoAccess, Attempt: 1, Terminated: true, LogTail: tail, FinishedAt: &now}}} |
| + v := taskLineOf(task, "a@example.com") |
| + v.richOf(task, "a@example.com", nil, now) |
| + if v.StageLine != fmt.Sprintf(copyText("work.stopped"), words) { |
| + t.Fatalf("stage line %q", v.StageLine) |
| + } |
| + for _, it := range timelineOf(task, v) { |
| + if it.Kind == "stopped" && it.Headline == sentenceCase(words)+"." { |
| + if html := string(pasteBox.Render(it.Markdown)); !strings.Contains(html, "no_credential") { |
| + t.Fatalf("details %q", html) |
| + } |
| + return |
| + } |
| + } |
| + t.Fatalf("no stopped merge in %+v", timelineOf(task, v)) |
| +} |
| + |
| // A push the hub refused shows the person why: the stopped step's details |
| // carry the refusal and git's answer from the runner's report, as written |
| // (the runner redacts and bounds them). |
diff --git a/internal/runner/forge/merge.go b/internal/runner/forge/merge.go| index e0c78c4d..fe707444 100644 |
| --- a/internal/runner/forge/merge.go |
| +++ b/internal/runner/forge/merge.go |
| @@ -39,8 +39,53 @@ var ( |
| // the hub refused to make the first merge (unborn_default, or |
| // is_default once a rebuild pointed its HEAD at the task branch). |
| ErrMergeUnbornDefault = errors.New("forge: the hub cannot make the first merge into an empty repository") |
| + // ErrMergeNoAccess: the runner holds nothing that may publish to the |
| + // repository, so it refused the merge itself and sent the hub nothing |
| + // (NoAccess says which precondition failed). Final for the attempt: |
| + // asking again changes nothing until someone gives it access. |
| + ErrMergeNoAccess = errors.New("forge: no access to publish to this repository") |
| ) |
| +// Why a merge had no access (NoAccess): the repository is not among the |
| +// agent's, or it is and the runner has no credential to publish with. |
| +const ( |
| + AccessNotListed = "not_listed" |
| + AccessNoCredential = "no_credential" |
| +) |
| + |
| +// accessError is ErrMergeNoAccess with the precondition that failed. |
| +type accessError struct{ cause string } |
| + |
| +func (e *accessError) Error() string { return ErrMergeNoAccess.Error() + " (" + e.cause + ")" } |
| +func (e *accessError) Unwrap() error { return ErrMergeNoAccess } |
| + |
| +// NoAccess is ErrMergeNoAccess for cause (AccessNotListed, |
| +// AccessNoCredential; any other word reads unknown): a fixed word, never |
| +// a credential or a path. |
| +func NoAccess(cause string) error { |
| + if cause != AccessNotListed && cause != AccessNoCredential { |
| + cause = "unknown" |
| + } |
| + return &accessError{cause: cause} |
| +} |
| + |
| +// NoAccessCause is the precondition a no-access refusal names, "" for |
| +// any other error. |
| +func NoAccessCause(err error) string { |
| + var a *accessError |
| + if errors.As(err, &a) { |
| + return a.cause |
| + } |
| + return "" |
| +} |
| + |
| +// refusedHere: a request the runner refused itself, before it reached |
| +// the hub (no status, nothing uncertain): no access, or its own |
| +// validation. |
| +func refusedHere(res MergeResult, err error) bool { |
| + return err != nil && res.Status == 0 && !errors.Is(err, ErrMergeUncertain) && (errors.Is(err, ErrMergeNoAccess) || errors.Is(err, ErrMergeRefused)) |
| +} |
| + |
| // HubError is the hub's answer to a merge it did not make: its HTTP |
| // status, its machine-readable reason (the JSON "reason") and its |
| // sentence (the JSON "error", or a page's text), both redacted and |
| @@ -65,7 +110,8 @@ func hubError(res MergeResult, err error) error { |
| // uncertain is ErrMergeUncertain with what is known of why: the hub's |
| // answer when it gave one, else the cause's words. Only the words: a |
| -// cause's own identity (a local refusal, say) never decides the outcome. |
| +// cause's own identity never decides the outcome (a refusal made here |
| +// before anything was sent never reaches this: refusedHere). |
| func uncertain(res MergeResult, cause error) error { |
| switch { |
| case res.Status != 0: |
| @@ -151,9 +197,12 @@ type hubMergeBody struct { |
| // A transport failure or an unreadable answer is an error: the caller |
| // cannot know whether the merge happened. |
| func HubMerge(ctx context.Context, client *http.Client, hub string, cred Credential, repo, branch string, req MergeRequest) (MergeResult, error) { |
| - if !validRepository(repo) || !validRef(branch) || cred.Bearer == "" || strings.ContainsAny(cred.Bearer, "\r\n") { |
| + if !validRepository(repo) || !validRef(branch) { |
| return MergeResult{}, ErrMergeRefused |
| } |
| + if cred.Bearer == "" || strings.ContainsAny(cred.Bearer, "\r\n") { |
| + return MergeResult{}, NoAccess(AccessNoCredential) |
| + } |
| parts := strings.Split(strings.TrimPrefix(repo, "amadan.net/"), "/") |
| body, _ := json.Marshal(req) |
| hr, err := http.NewRequestWithContext(ctx, http.MethodPost, strings.TrimRight(hub, "/")+"/api/v1/repos/"+url.PathEscape(parts[0])+"/"+url.PathEscape(parts[1])+"/branches/"+url.PathEscape(branch)+"/merge", bytes.NewReader(body)) |
| @@ -263,7 +312,8 @@ type mergeRecord struct { |
| // Merge record phases: prepared (nothing sent), requested (a request may |
| // have reached the hub), merged (the hub confirmed it, or the default |
| -// branch shows it), refused (the hub answered no; a new request may go). |
| +// branch shows it), refused (the hub answered no, or the runner refused |
| +// the request itself before sending it; a new request may go). |
| const ( |
| mergePrepared = "prepared" |
| mergeRequested = "requested" |
| @@ -419,6 +469,16 @@ func MergeBranch(ctx context.Context, m BranchMerge) (MergeOutcome, error) { |
| } |
| return MergeOutcome{SHA: rec.SHA, Into: rec.Into, Strategy: rec.Strategy, Source: SourceHub}, nil |
| } |
| + if refusedHere(res, rerr) { |
| + // Refused here, before anything reached the hub: certain, and |
| + // final for this request. Never an outcome unknown, so the record |
| + // does not stay requested. |
| + reason := "refused" |
| + if errors.Is(rerr, ErrMergeNoAccess) { |
| + reason = "no_access" |
| + } |
| + return MergeOutcome{}, m.refused(rec, MergeResult{Reason: reason}, rerr) |
| + } |
| if rerr == nil && st.Unborn && (res.Reason == "unborn_default" || res.Reason == "is_default") { |
| // The hub cannot make the first merge yet: final for this request, |
| // never sent again blind. |
| @@ -458,8 +518,8 @@ func MergeBranch(ctx context.Context, m BranchMerge) (MergeOutcome, error) { |
| return MergeOutcome{}, m.refused(rec, res, ErrMergeFailed) |
| } |
| -// refused records the hub's refusal (a new request may go later) and |
| -// returns err. |
| +// refused records the hub's refusal, or the runner's own before the |
| +// request went (a new request may go later), and returns err. |
| func (m BranchMerge) refused(rec mergeRecord, res MergeResult, err error) error { |
| rec.Phase, rec.Reason = mergeRefusedPh, res.Reason |
| if serr := m.save(rec); serr != nil { |
diff --git a/internal/runner/forge/merge_detail_test.go b/internal/runner/forge/merge_detail_test.go| index c2d5478a..2c1da9a8 100644 |
| --- a/internal/runner/forge/merge_detail_test.go |
| +++ b/internal/runner/forge/merge_detail_test.go |
| @@ -69,18 +69,29 @@ func TestMergeBranchKeepsTheHubAnswer(t *testing.T) { |
| t.Fatalf("detail %q", detail) |
| } |
| } |
| - // No answer at all: the cause in words, redacted; its own identity |
| - // (here a local refusal) never decides the outcome. |
| + // No answer at all: the cause in words, redacted. |
| h := &fakeHub{head: strings.Repeat("a", 40), answer: func(*fakeHub, MergeRequest) (MergeResult, error) { |
| - return MergeResult{}, errors.Join(ErrMergeRefused, errors.New(secret)) |
| + return MergeResult{}, errors.New("connection reset; " + secret) |
| }} |
| _, err := MergeBranch(context.Background(), newMerge(t, h)) |
| - if !errors.Is(err, ErrMergeUncertain) || errors.Is(err, ErrMergeRefused) || !strings.Contains(err.Error(), "refused by validation") { |
| + if !errors.Is(err, ErrMergeUncertain) || !strings.Contains(err.Error(), "connection reset") { |
| t.Fatalf("no answer: %v", err) |
| } |
| if d := MergeDetail(err); !strings.HasPrefix(d, "error: ") || strings.Contains(d, "s3cr3t") { |
| t.Fatalf("no answer detail %q", d) |
| } |
| + // Refused here, before the hub was asked: a refusal, never an outcome |
| + // unknown, in its words, redacted. |
| + h = &fakeHub{head: strings.Repeat("a", 40), answer: func(*fakeHub, MergeRequest) (MergeResult, error) { |
| + return MergeResult{}, errors.Join(ErrMergeRefused, errors.New(secret)) |
| + }} |
| + _, err = MergeBranch(context.Background(), newMerge(t, h)) |
| + if !errors.Is(err, ErrMergeRefused) || errors.Is(err, ErrMergeUncertain) || !strings.Contains(err.Error(), "refused by validation") { |
| + t.Fatalf("refused here: %v", err) |
| + } |
| + if d := MergeDetail(err); !strings.HasPrefix(d, "error: ") || strings.Contains(d, "s3cr3t") { |
| + t.Fatalf("refused here detail %q", d) |
| + } |
| // The remote could not be read: nothing was asked, and the reason says |
| // why. |
| m := newMerge(t, &fakeHub{head: strings.Repeat("a", 40)}) |
diff --git a/internal/runner/forge/merge_test.go b/internal/runner/forge/merge_test.go| index 77a39300..2c6f9006 100644 |
| --- a/internal/runner/forge/merge_test.go |
| +++ b/internal/runner/forge/merge_test.go |
| @@ -4,6 +4,7 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| "net/http" |
| "net/http/httptest" |
| "strings" |
| @@ -258,3 +259,96 @@ func TestHubMerge(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestMergeBranchLocalRefusalIsFinal: a request refused here, before |
| +// anything reached the hub (no access to the repository, or the runner's |
| +// own validation), is a refusal for this attempt, never an outcome |
| +// unknown: the record says refused with why, not requested, and a later |
| +// call (once access is there) asks the hub again. |
| +func TestMergeBranchLocalRefusalIsFinal(t *testing.T) { |
| + for _, c := range []struct { |
| + name string |
| + err error |
| + want error |
| + reason string |
| + }{ |
| + {"no credential", NoAccess(AccessNoCredential), ErrMergeNoAccess, "no_access"}, |
| + {"not listed", NoAccess(AccessNotListed), ErrMergeNoAccess, "no_access"}, |
| + {"refused here", ErrMergeRefused, ErrMergeRefused, "refused"}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + h := &fakeHub{head: strings.Repeat("a", 40), answer: mergeNow} |
| + m := newMerge(t, h) |
| + inspected := 0 |
| + inspect := m.Inspect |
| + m.Inspect = func(ctx context.Context) (RemoteState, error) { inspected++; return inspect(ctx) } |
| + refused := m |
| + refused.Request = func(context.Context, MergeRequest) (MergeResult, error) { return MergeResult{}, c.err } |
| + _, err := MergeBranch(context.Background(), refused) |
| + if !errors.Is(err, c.want) || errors.Is(err, ErrMergeUncertain) { |
| + t.Fatalf("refused: %v, want %v and not uncertain", err, c.want) |
| + } |
| + if rec, ok, _ := m.load(); !ok || rec.Phase != mergeRefusedPh || rec.Reason != c.reason { |
| + t.Fatalf("record %+v", rec) |
| + } |
| + if inspected != 1 { |
| + t.Fatalf("the remote was read %d times for a refusal nothing sent", inspected) |
| + } |
| + out, err := MergeBranch(context.Background(), m) |
| + if err != nil || out.Source != SourceHub || len(h.requests) != 1 { |
| + t.Fatalf("with access: %+v %v (%d requests)", out, err, len(h.requests)) |
| + } |
| + }) |
| + } |
| + // A request that may have gone stays uncertain, whatever words it |
| + // carries: a refusal is local only with no status and no uncertainty. |
| + for name, res := range map[string]struct { |
| + res MergeResult |
| + err error |
| + }{ |
| + "transport": {MergeResult{}, fmt.Errorf("%w: connection reset", ErrMergeUncertain)}, |
| + "hub page": {MergeResult{Status: 502}, ErrMergeUncertain}, |
| + "status refused": {MergeResult{Status: 400}, ErrMergeRefused}, |
| + } { |
| + h := &fakeHub{head: strings.Repeat("a", 40), answer: func(*fakeHub, MergeRequest) (MergeResult, error) { return res.res, res.err }} |
| + m := newMerge(t, h) |
| + if _, err := MergeBranch(context.Background(), m); !errors.Is(err, ErrMergeUncertain) { |
| + t.Fatalf("%s: %v, want uncertain", name, err) |
| + } |
| + if rec, _, _ := m.load(); rec.Phase != mergeRequested { |
| + t.Fatalf("%s: record %+v", name, rec) |
| + } |
| + } |
| +} |
| + |
| +// TestNoAccessSaysWhich: the error names the precondition that failed, |
| +// in a fixed word, and nothing else. |
| +func TestNoAccessSaysWhich(t *testing.T) { |
| + err := NoAccess(AccessNoCredential) |
| + if !errors.Is(err, ErrMergeNoAccess) || NoAccessCause(err) != AccessNoCredential || !strings.Contains(err.Error(), AccessNoCredential) { |
| + t.Fatalf("%v cause %q", err, NoAccessCause(err)) |
| + } |
| + if NoAccessCause(fmt.Errorf("wrapped: %w", NoAccess(AccessNotListed))) != AccessNotListed || NoAccessCause(ErrMergeRefused) != "" { |
| + t.Fatal("cause of a wrapped or other error") |
| + } |
| + if NoAccess("Bearer s3cr3t").Error() != ErrMergeNoAccess.Error()+" (unknown)" { |
| + t.Fatalf("a cause that is not one of ours: %v", NoAccess("Bearer s3cr3t")) |
| + } |
| +} |
| + |
| +// TestHubMergeWithoutABearer: no bearer to send is no access, and |
| +// nothing reaches the hub. |
| +func TestHubMergeWithoutABearer(t *testing.T) { |
| + srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { t.Fatal("the hub was asked") })) |
| + defer srv.Close() |
| + req := MergeRequest{ExpectSHA: strings.Repeat("a", 40), Strategy: "merge"} |
| + for _, bearer := range []string{"", "a\r\nb"} { |
| + res, err := HubMerge(context.Background(), srv.Client(), srv.URL, Credential{Bearer: bearer}, "amadan.net/oficina/sample", "equipo/tk1-fix-typo", req) |
| + if !errors.Is(err, ErrMergeNoAccess) || NoAccessCause(err) != AccessNoCredential || res.Status != 0 { |
| + t.Fatalf("bearer %q: %+v %v", bearer, res, err) |
| + } |
| + } |
| + if _, err := HubMerge(context.Background(), srv.Client(), srv.URL, Credential{Bearer: "t"}, "github.com/x/y", "equipo/tk1-fix-typo", req); !errors.Is(err, ErrMergeRefused) { |
| + t.Fatalf("invalid repository: %v", err) |
| + } |
| +} |
diff --git a/internal/runner/thin/access_review_test.go b/internal/runner/thin/access_review_test.go| index 2aaae838..728d3e95 100644 |
| --- a/internal/runner/thin/access_review_test.go |
| +++ b/internal/runner/thin/access_review_test.go |
| @@ -160,7 +160,7 @@ func TestAccessReadGrantCannotWrite(t *testing.T) { |
| if _, err := f.Remote(ctx, repo, Push); err == nil { |
| t.Fatal("read grant got write credential") |
| } |
| - if _, err := f.Merge(ctx, repo, "branch", forge.MergeRequest{}); !errors.Is(err, forge.ErrMergeRefused) { |
| + if _, err := f.Merge(ctx, repo, "branch", forge.MergeRequest{}); !errors.Is(err, forge.ErrMergeNoAccess) || forge.NoAccessCause(err) != forge.AccessNotListed { |
| t.Fatal("read grant reached merge", err) |
| } |
| if _, err := f.ciCredential(ctx, repo); !errors.Is(err, forge.ErrCIRead) { |
diff --git a/internal/runner/thin/forge.go b/internal/runner/thin/forge.go| index 156c80a3..edf4ad88 100644 |
| --- a/internal/runner/thin/forge.go |
| +++ b/internal/runner/thin/forge.go |
| @@ -316,15 +316,17 @@ func (f *fileForge) adopt(repo string) error { |
| } |
| // Merge sends the hub the merge request with the agent's credential for |
| -// repo (its own entry, or the agent-wide one). |
| +// repo (its own entry, or the agent-wide one). Without one it sends |
| +// nothing: no access, saying which (not among the agent's repositories, |
| +// or no credential for it), never the credential error's own words. |
| func (f *fileForge) Merge(ctx context.Context, repo, branch string, req forge.MergeRequest) (forge.MergeResult, error) { |
| f.list(ctx) |
| if !slices.Contains(f.Repos(), repo) { |
| - return forge.MergeResult{}, forge.ErrMergeRefused |
| + return forge.MergeResult{}, forge.NoAccess(forge.AccessNotListed) |
| } |
| c, err := f.creds.Credential(ctx, repo) |
| if err != nil { |
| - return forge.MergeResult{}, forge.ErrMergeRefused |
| + return forge.MergeResult{}, forge.NoAccess(forge.AccessNoCredential) |
| } |
| return forge.HubMerge(ctx, f.client, f.hub, c, repo, branch, req) |
| } |
diff --git a/internal/runner/thin/mergeaccess_test.go b/internal/runner/thin/mergeaccess_test.go| new file mode 100644 |
| index 00000000..f434a580 |
| --- /dev/null |
| +++ b/internal/runner/thin/mergeaccess_test.go |
| @@ -0,0 +1,105 @@ |
| +package thin |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "log/slog" |
| + "net/http" |
| + "net/http/httptest" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/forge" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// TestFileForgeMergeWithoutAccess: a merge for a repository the runner |
| +// holds no credential for is refused here, before anything reaches the |
| +// hub, and says which precondition failed: not among the agent's |
| +// repositories, or among them with no credential to publish with (a |
| +// runner with per-repository credentials only, the hub listing more). |
| +func TestFileForgeMergeWithoutAccess(t *testing.T) { |
| + merges := 0 |
| + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + switch { |
| + case r.Method == http.MethodGet && r.URL.Path == "/api/v1/repos": |
| + w.Write([]byte(`{"repos":[{"ns":"oficina","name":"listed"},{"ns":"paulca","name":"nearys"}]}`)) |
| + case strings.HasSuffix(r.URL.Path, "/merge"): |
| + merges++ |
| + if got := r.Header.Get("Authorization"); got != "Bearer SECRET-LISTED" { |
| + t.Errorf("merge with %q", got) |
| + } |
| + w.Write([]byte(`{"merged":true,"sha":"` + strings.Repeat("8", 40) + `","into":"main"}`)) |
| + default: |
| + w.WriteHeader(404) |
| + } |
| + })) |
| + defer srv.Close() |
| + dir := t.TempDir() |
| + p := filepath.Join(dir, "forge.json") |
| + if err := os.WriteFile(p, []byte(`{"agent":"equipo~owner@example.com","repositories":{"amadan.net/oficina/listed":{"api":"SECRET-LISTED","git":"SECRET-GIT"}}}`), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + f := NewFileForge(p, dir, false).(*fileForge) |
| + f.hub, f.client = srv.URL, srv.Client() |
| + req := forge.MergeRequest{ExpectSHA: strings.Repeat("a", 40), Strategy: "merge", Agent: forge.AgentMeta{Session: "equipo-tk1", Harness: "equipo", Host: "test"}} |
| + ctx := context.Background() |
| + for repo, cause := range map[string]string{"amadan.net/paulca/nearys": forge.AccessNoCredential, "amadan.net/oficina/elsewhere": forge.AccessNotListed} { |
| + res, err := f.Merge(ctx, repo, "equipo/tk1-fix-typo", req) |
| + if !errors.Is(err, forge.ErrMergeNoAccess) || forge.NoAccessCause(err) != cause || res.Status != 0 { |
| + t.Fatalf("%s: %+v %v, want no access (%s)", repo, res, err, cause) |
| + } |
| + if strings.Contains(err.Error(), "SECRET") { |
| + t.Fatalf("%s: %v", repo, err) |
| + } |
| + } |
| + if merges != 0 { |
| + t.Fatalf("%d merges reached the hub without access", merges) |
| + } |
| + if res, err := f.Merge(ctx, "amadan.net/oficina/listed", "equipo/tk1-fix-typo", req); err != nil || !res.Merged || merges != 1 { |
| + t.Fatalf("with access: %+v %v (%d merges)", res, err, merges) |
| + } |
| +} |
| + |
| +// TestMergeStepWithoutAccess: a merge the runner refuses for want of |
| +// access ends the step at once as merge_no_access, final (never tried |
| +// again as an uncertain outcome), with the record refused rather than |
| +// requested; the runner's log says which precondition failed and never |
| +// a credential. |
| +func TestMergeStepWithoutAccess(t *testing.T) { |
| + old := mergeBackoff |
| + mergeBackoff = time.Millisecond |
| + t.Cleanup(func() { mergeBackoff = old }) |
| + e, f, r, _ := hubRig(t) |
| + logs := &lockedBuffer{} |
| + e.O.Logger = slog.New(slog.NewTextHandler(logs, nil)) |
| + f.answer = func(int, func() (forge.MergeResult, error)) (forge.MergeResult, error) { |
| + return forge.MergeResult{}, forge.NoAccess(forge.AccessNoCredential) |
| + } |
| + rep := e.Exec(context.Background(), r, func(wire.StepReport) {}) |
| + if rep.State != wire.StepFailed || rep.Reason != wire.ReasonMergeNoAccess || !rep.Termination { |
| + t.Fatalf("report %+v", rep) |
| + } |
| + if f.requests != 1 { |
| + t.Fatalf("asked %d times: a refusal here is not tried again", f.requests) |
| + } |
| + line := string(logs.Bytes()) |
| + if !strings.Contains(line, "msg=merge") || !strings.Contains(line, "refused=no_access") || !strings.Contains(line, "cause="+forge.AccessNoCredential) || !strings.Contains(line, "repo="+r.Repo) { |
| + t.Fatalf("log %q", line) |
| + } |
| + if strings.Contains(line, "outcome unknown") || strings.Contains(rep.LogTail, "outcome unknown") { |
| + t.Fatalf("a refusal here reads as uncertain: %q / %q", line, rep.LogTail) |
| + } |
| + if !strings.Contains(rep.LogTail, forge.AccessNoCredential) { |
| + t.Fatalf("log tail %q", rep.LogTail) |
| + } |
| + // Access given: the next attempt asks the hub and merges. |
| + f.answer = nil |
| + r.Attempt++ |
| + if rep := e.Exec(context.Background(), r, func(wire.StepReport) {}); rep.State != wire.StepDone || f.requests != 2 { |
| + t.Fatalf("with access %+v (%d requests)", rep, f.requests) |
| + } |
| +} |
diff --git a/internal/runner/thin/mergestep.go b/internal/runner/thin/mergestep.go| index 4b39a078..7f47af1b 100644 |
| --- a/internal/runner/thin/mergestep.go |
| +++ b/internal/runner/thin/mergestep.go |
| @@ -159,6 +159,13 @@ func (e *Engineer) mergeStep(ctx context.Context, r stepRow, progress func(wire. |
| return fail("merge_forbidden") |
| case errors.Is(err, forge.ErrMergeUnbornDefault): |
| return fail(wire.ReasonMergeUnbornDefault) |
| + case errors.Is(err, forge.ErrMergeNoAccess): |
| + // Refused here, nothing sent: which precondition failed, for |
| + // whoever gives the runner access (never the credential). |
| + if e.O.Logger != nil { |
| + e.O.Logger.Warn("merge", "refused", "no_access", "cause", forge.NoAccessCause(err), "repo", r.Repo) |
| + } |
| + return fail(wire.ReasonMergeNoAccess) |
| case errors.Is(err, forge.ErrMergeRefused): |
| return fail("policy_rejected") |
| } |
diff --git a/internal/thintest/assistant_job_state_contract_test.go b/internal/thintest/assistant_job_state_contract_test.go| index dc90ebbe..d49790d0 100644 |
| --- a/internal/thintest/assistant_job_state_contract_test.go |
| +++ b/internal/thintest/assistant_job_state_contract_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "testing" |
| "time" |
| + "amadan.net/oficina/equipo/internal/equipo" |
| "amadan.net/oficina/equipo/internal/wire" |
| ) |
| @@ -194,6 +195,31 @@ func TestContractTeamJobSettledStates(t *testing.T) { |
| o.settledStopped(request) |
| o.noteFor("the failed merge's note", blockedOn("going live failed, and they need to try it again")) |
| }}, |
| + {"merge_no_access", func(o *teamRig, request, id string, merge *wire.DispatchCommand) { |
| + // The runner refused the merge itself: no access to publish to |
| + // the repository. Stopped, saying what is missing, and the |
| + // Assistant is not told to have the person try again. |
| + o.step("pw-m-run", wire.StepReport{TaskID: merge.TaskID, StepID: merge.StepID, Attempt: merge.Attempt, State: wire.StepRunning, BaseSHA: merge.BaseSHA, CandidateSHA: merge.CandidateSHA}) |
| + o.step("pw-m-fail", wire.StepReport{TaskID: merge.TaskID, StepID: merge.StepID, Attempt: merge.Attempt, State: wire.StepFailed, Reason: wire.ReasonMergeNoAccess, BaseSHA: merge.BaseSHA, CandidateSHA: merge.CandidateSHA, Termination: true}) |
| + o.wait("ready to merge again", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageReadyToMerge }) |
| + o.endUpdates() |
| + card := o.jobOf(request, "stopped", func(c wire.AssistantCard) bool { return c.State != wire.JobWorking }) |
| + if card.State != wire.JobStopped || card.Result != equipo.RunnerCopy("assistant.job.stopped") || card.Detail != equipo.RunnerCopy("assistant.job.detail.no_access") { |
| + o.t.Fatalf("the job card %+v, want stopped for want of access", card) |
| + } |
| + if n := o.openOutcomes(); n != 0 { |
| + o.t.Fatalf("%d go-ahead or Publish cards open", n) |
| + } |
| + note := o.noteFor("the refused merge's note", blockedOn(noAccessLine)) |
| + for _, retry := range []string{"try it again", "go-ahead", "team_nudge", equipo.RunnerCopy("assistant.team.stage.ready_to_merge")} { |
| + if strings.Contains(note, retry) { |
| + o.t.Fatalf("the note invites %q: %q", retry, note) |
| + } |
| + } |
| + if !strings.Contains(note, equipo.RunnerCopy("assistant.team.no_access")) { |
| + o.t.Fatalf("the note does not say what is missing: %q", note) |
| + } |
| + }}, |
| {"publish_declined", func(o *teamRig, request, id string, merge *wire.DispatchCommand) { |
| o.mergedStep("pw-m", merge, strings.Repeat("e", 40)) |
| o.wait("done", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageDone }) |
diff --git a/internal/thintest/assistant_team_contract_test.go b/internal/thintest/assistant_team_contract_test.go| index 1a6dffcf..85a99ad9 100644 |
| --- a/internal/thintest/assistant_team_contract_test.go |
| +++ b/internal/thintest/assistant_team_contract_test.go |
| @@ -1708,9 +1708,16 @@ func personNeeds() []personNeed { |
| {"merge_failed", "going live failed, and they need to try it again", func(o *teamRig, id, step string) { |
| o.exec("UPDATE chat_steps SET specialist = ?, state = ?, terminated = 1, reason = 'provider_failed' WHERE id = ?", wire.SpecialistMerge, wire.StepFailed, step) |
| }}, |
| + {"merge_no_access", noAccessLine, func(o *teamRig, id, step string) { |
| + o.exec("UPDATE chat_steps SET specialist = ?, state = ?, terminated = 1, reason = ? WHERE id = ?", wire.SpecialistMerge, wire.StepFailed, wire.ReasonMergeNoAccess, step) |
| + }}, |
| } |
| } |
| +// noAccessLine is the note's plain line for going live refused for want |
| +// of access to the repository: what is missing, not "try it again". |
| +const noAccessLine = "there is no access to publish it where the work lives, and someone needs to set that access up before it can go live; trying again will not help until then" |
| + |
| // TestContractTeamUpdatePersonNeeds (ruling P4j): every need only the |
| // person can meet stops the job for them: the note says what in plain |
| // words and never asks the Assistant to nudge it, however its step |
diff --git a/internal/wire/tasks.go b/internal/wire/tasks.go| index 2d8ed289..94facf15 100644 |
| --- a/internal/wire/tasks.go |
| +++ b/internal/wire/tasks.go |
| @@ -1043,6 +1043,10 @@ var StepReasons = map[string]bool{ |
| // The first merge into an empty repository waits on the hub |
| // (ReasonMergeUnbornDefault). |
| ReasonMergeUnbornDefault: true, |
| + // The runner has no access to publish to the repository and refused |
| + // the merge itself (ReasonMergeNoAccess). An older instance records |
| + // it as unknown. |
| + ReasonMergeNoAccess: true, |
| // merge_not_authorized: the instance refused the merge request's |
| // confirmation (merge authority); nothing was sent to the hub. |
| "merge_not_authorized": true, |
| @@ -1126,3 +1130,10 @@ const MaxSimilarTasks = 3 |
| // the first merge (before amadan#139). Nothing merged; it waits on the |
| // platform, never retried on its own (protocol 8). |
| const ReasonMergeUnbornDefault = "merge_unborn_default" |
| + |
| +// ReasonMergeNoAccess: the runner holds no credential that may publish to |
| +// the repository (not among the agent's repositories, or no credential |
| +// for it), so it refused the merge step itself and sent the hub nothing. |
| +// Final for the attempt: trying again cannot help until someone gives it |
| +// access. |
| +const ReasonMergeNoAccess = "merge_no_access" |