oficina / equipo Public

Check merge access first; keep an earlier uncertain request open

Astra review of the honest-refusal change:
- A local refusal no longer settles a record left requested by an
  earlier attempt that may have reached the hub: it stays uncertain
  and requested, and the default branch decides as before.
- BranchMerge.Access runs before the remote is read (reading it may
  need the same missing credential), unless a request is outstanding.
  fileForge and Forges implement MergeAccess; mergestep wires it.
- A merge refused by the runner's own validation is logged.
- A stopped merge refused for want of access asks no "Try again?" in
  Equipo's decision panel; Retry stays for once access is given.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 9d15195688f2d76f8b3bcf8500755569e25d8e48 parent ef90958
10 files changed, +193 −7
  • .rastrillo/budgets.txt +2 −2
  • internal/equipo/templates/work_parts.html +1 −1
  • internal/equipo/work_views.go +6 −0
  • internal/equipo/work_views_test.go +16 −0
  • internal/runner/forge/merge.go +17 −0
  • internal/runner/forge/merge_test.go +70 −0
  • internal/runner/thin/forge.go +19 −4
  • internal/runner/thin/forges.go +13 −0
  • internal/runner/thin/mergeaccess_test.go +39 −0
  • internal/runner/thin/mergestep.go +10 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index a2516dc3..10575c3a 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -14,7 +14,7 @@ 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 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/equipo 22580 - 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 22580 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);
@@ -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 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.
+size internal/runner/thin 28525 22857 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 28525/22857.
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).
diff --git a/internal/equipo/templates/work_parts.html b/internal/equipo/templates/work_parts.html
index 1a04a0cd..4e1be335 100644
--- a/internal/equipo/templates/work_parts.html
+++ b/internal/equipo/templates/work_parts.html
@@ -36,7 +36,7 @@
{{define "decision"}}{{$t := .Task}}{{with $t.Decision}}<div equipo-decision{{if eq $.From "task"}} id="decide"{{end}}{{with .Tone}} data-tone="{{.}}"{{end}} data-need="{{.Need}}" data-decision="{{$t.ID}}">
{{if $.Head}}{{template "mono" $t.Mono}}<div equipo-d-title><a href="/tasks/{{$t.ID}}">{{$t.Title}}</a><div equipo-quiet>{{template "placement-chip" $t}} · {{template "source" $t}}</div></div>{{end}}
<p equipo-d-why>{{.Why}}</p>
-<p equipo-d-ask>{{.Ask}}</p>{{if .Link}}<p equipo-quiet data-direction-line>{{with .LinkText}}{{.}} {{end}}<a equipo-link href="{{.Link}}" rel="noopener noreferrer" target="_blank" data-direction-link>{{.LinkLabel}}</a>{{with .AltLink}} <a equipo-link href="{{.}}" rel="noopener noreferrer" target="_blank" data-direction-branch>{{$t.Decision.AltLabel}}</a>{{end}}</p>{{end}}{{with .Said}}<p equipo-quiet data-triage-said>{{.}}</p>{{end}}{{with .Failed}}<p equipo-quiet data-triage-failed>{{.}}</p>{{end}}{{with .Recommend}}<p equipo-quiet data-triage-recommend>{{.}}</p>{{end}}
+{{with .Ask}}<p equipo-d-ask>{{.}}</p>{{end}}{{if .Link}}<p equipo-quiet data-direction-line>{{with .LinkText}}{{.}} {{end}}<a equipo-link href="{{.Link}}" rel="noopener noreferrer" target="_blank" data-direction-link>{{.LinkLabel}}</a>{{with .AltLink}} <a equipo-link href="{{.}}" rel="noopener noreferrer" target="_blank" data-direction-branch>{{$t.Decision.AltLabel}}</a>{{end}}</p>{{end}}{{with .Said}}<p equipo-quiet data-triage-said>{{.}}</p>{{end}}{{with .Failed}}<p equipo-quiet data-triage-failed>{{.}}</p>{{end}}{{with .Recommend}}<p equipo-quiet data-triage-recommend>{{.}}</p>{{end}}
<div equipo-d-actions>{{if .CopyContinue}}<form method="post" action="/conversation/tasks/{{$t.ID}}/continue-without-copy"><input type="hidden" name="from" value="{{$.From}}"><button equipo-btn data-primary type="submit" data-copy-continue>{{copy "copy.continue"}}</button></form>{{end}}{{with .Card}}<form method="post" action="/conversation/cards/{{.ID}}/answer"><input type="hidden" name="revision" value="{{.Revision}}"><input type="hidden" name="from" value="{{$.From}}"><input type="hidden" name="task" value="{{$t.ID}}">{{if $.Task.Decision.Note}}<textarea rst-input name="note" maxlength="1000" rows="2" aria-label="{{copy "chat.card.direction_note"}}" placeholder="{{copy "chat.card.direction_note"}}" data-direction-note></textarea>{{end}}{{range $.Task.Decision.Choices}}<button equipo-btn{{if .Primary}} data-primary{{end}} type="submit" name="choice" value="{{.Value}}" data-merge-choice="{{.Value}}">{{.Label}}</button>{{end}}</form>{{end}}{{if .Fold}}<form method="post" action="/tasks/{{$t.ID}}/duplicate"><input type="hidden" name="from" value="{{$.From}}"><input type="hidden" name="of" value="{{$t.Dup.ID}}"><button equipo-btn data-primary type="submit" data-task-duplicate>{{copy "work.decide.fold"}}</button></form>{{end}}{{if .Recover}}<form method="post" action="/conversation/tasks/{{$t.ID}}/recover"><input type="hidden" name="from" value="{{$.From}}"><button equipo-btn data-primary type="submit" data-task-recover>{{copy "work.recover"}}</button></form>{{end}}{{with .Unsandboxed}}<details equipo-mach-confirm data-unsandboxed><summary equipo-btn>{{copy "work.decide.unsandboxed"}}</summary><div><p>{{.Warning}}</p><form method="post" action="/conversation/tasks/{{$t.ID}}/unsandboxed"><input type="hidden" name="from" value="{{$.From}}"><input type="hidden" name="step" value="{{.Step}}"><input type="hidden" name="attempt" value="{{.Attempt}}"><button equipo-btn data-danger type="submit" data-task-unsandboxed>{{copy "work.decide.unsandboxed_confirm"}}</button></form></div></details>{{end}}{{if .Retry}}<form method="post" action="/conversation/tasks/{{$t.ID}}/retry"><input type="hidden" name="from" value="{{$.From}}"><button {{if .Fold}}equipo-link{{else}}equipo-btn data-primary{{end}} type="submit" data-task-retry>{{copy "work.retry"}}</button></form>{{end}}{{if .Round}}<form method="post" action="/conversation/tasks/{{$t.ID}}/round"><input type="hidden" name="from" value="{{$.From}}"><button equipo-btn data-primary type="submit" data-task-round>{{copy "work.decide.round"}}</button></form>{{end}}{{if .Talk}}<a equipo-btn href="/conversation?about={{$t.ID}}" data-ask-coordinator>{{copy "work.decide.ask_coordinator"}}</a>{{end}}{{if .Cancel}}<form method="post" action="/conversation/tasks/{{$t.ID}}/cancel"><input type="hidden" name="from" value="{{$.From}}"><button equipo-link type="submit" data-task-cancel>{{copy "work.decide.cancel"}}</button></form>{{end}}{{with .Hint}}<span equipo-quiet>{{.}}</span>{{end}}<span equipo-d-quiet>{{if .Mac}}<a equipo-link href="/conversation/settings/machines/add" data-set-up-mac>{{copy "work.decide.mac_set_up"}}</a>{{end}}<a equipo-link href="/conversation?about={{$t.ID}}" data-ask-about>{{copy "work.ask_about"}}</a></span></div>
</div>{{end}}{{end}}
{{define "star-toggle"}}{{$p := .P}}<form method="post" action="/projects/{{$p.ID}}/star" equipo-star-form><input type="hidden" name="starred" value="{{if $p.Star.On}}0{{else}}1{{end}}"><input type="hidden" name="from" value="{{.From}}"><button type="submit" equipo-star{{if $p.Star.On}} aria-pressed="true"{{if $p.Star.Auto}} data-auto{{end}}{{else}} aria-pressed="false"{{end}} aria-label="{{$p.Star.Label}}" title="{{$p.Star.Who}}" data-star-toggle>{{icon "star"}}</button></form>{{end}}
diff --git a/internal/equipo/work_views.go b/internal/equipo/work_views.go
index 803dfd64..9686bd61 100644
--- a/internal/equipo/work_views.go
+++ b/internal/equipo/work_views.go
@@ -750,6 +750,12 @@ func decisionOf(t wire.Task, v taskLine) *decisionView {
d.Why = fmt.Sprintf(copyText("work.decide.stopped_why"), who(v.Stopped), reason, attempt)
d.Retry, d.Cancel = v.Retry, v.Cancel
d.Ask = copyText("work.decide.retry_ask")
+ if v.Stopped != nil && v.Stopped.Specialist == wire.SpecialistMerge && (v.Stopped.Reason == wire.ReasonMergeNoAccess || v.Stopped.Reason == "merge_forbidden") {
+ // Trying again cannot help until someone gives Equipo access:
+ // the reason says what is missing, and nothing asks to try
+ // again (Retry stays, for once access is given).
+ d.Ask = ""
+ }
case wire.NeedsFixRounds:
d.Tone, d.Why, d.Ask, d.Talk, d.Cancel, d.Round = "attention", copyText("work.decide.fix_rounds_why"), copyText("work.decide.talk_ask"), true, v.Cancel, v.Mine
if t.ChecksReason == "base_checks_failed" {
diff --git a/internal/equipo/work_views_test.go b/internal/equipo/work_views_test.go
index 8f2aabf2..cc7ad1be 100644
--- a/internal/equipo/work_views_test.go
+++ b/internal/equipo/work_views_test.go
@@ -79,6 +79,22 @@ func TestStoppedMergeWithoutAccess(t *testing.T) {
t.Fatalf("no stopped merge in %+v", timelineOf(task, v))
}
+// A merge stopped for want of access that waits on the person asks no
+// "Try again?": nothing the person can retry helps until access is
+// given. Another stopped merge still asks.
+func TestStoppedMergeWithoutAccessAsksNoRetry(t *testing.T) {
+ now := time.Now()
+ for reason, ask := range map[string]string{wire.ReasonMergeNoAccess: "", "merge_forbidden": "", "merge_failed": copyText("work.decide.retry_ask")} {
+ task := wire.Task{ID: "tk1", Creator: "a@example.com", Stage: wire.StageMerging, NeedsYou: wire.NeedsRetry, Steps: []wire.Step{{Specialist: wire.SpecialistMerge, State: wire.StepFailed, Reason: reason, Attempt: 1, Terminated: true, FinishedAt: &now}}}
+ v := taskLineOf(task, "a@example.com")
+ v.richOf(task, "a@example.com", nil, now)
+ d := decisionOf(task, v)
+ if d == nil || d.Ask != ask || !strings.Contains(d.Why, copyText("work.reason."+reason)) {
+ t.Fatalf("%s: %+v", reason, d)
+ }
+ }
+}
+
// 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 fe707444..f4317162 100644
--- a/internal/runner/forge/merge.go
+++ b/internal/runner/forge/merge.go
@@ -274,6 +274,10 @@ type BranchMerge struct {
Request func(context.Context, MergeRequest) (MergeResult, error)
// Confirm checks the execution lease right before the request.
Confirm func(context.Context) error
+ // Access, if set, says whether the runner may publish to the
+ // repository at all (ErrMergeNoAccess when not), before the remote is
+ // read: reading it may need the same missing credential.
+ Access func(context.Context) error
// beforeRequest runs right before the request (tests move the branch).
beforeRequest func()
}
@@ -428,6 +432,14 @@ func MergeBranch(ctx context.Context, m BranchMerge) (MergeOutcome, error) {
if !found {
rec = mergeRecord{Task: m.Task, Repo: m.Repo, Branch: m.Branch, Commit: m.Commit, Phase: mergePrepared, Strategy: m.Strategy}
}
+ // outstanding: an earlier request may have reached the hub. Only the
+ // default branch settles it; nothing refused here does.
+ outstanding := found && rec.Phase == mergeRequested
+ if m.Access != nil && !outstanding {
+ if err := m.Access(ctx); errors.Is(err, ErrMergeNoAccess) {
+ return MergeOutcome{}, m.refused(rec, MergeResult{Reason: "no_access"}, err)
+ }
+ }
st, err := m.Inspect(ctx)
if err != nil {
return MergeOutcome{}, fmt.Errorf("%w: reading the repository: %v", ErrMergeUncertain, err)
@@ -469,6 +481,11 @@ 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) && outstanding {
+ // This request never went, but an earlier one may have: still
+ // uncertain, the record still requested.
+ return MergeOutcome{}, uncertain(res, rerr)
+ }
if refusedHere(res, rerr) {
// Refused here, before anything reached the hub: certain, and
// final for this request. Never an outcome unknown, so the record
diff --git a/internal/runner/forge/merge_test.go b/internal/runner/forge/merge_test.go
index 2c6f9006..f905563a 100644
--- a/internal/runner/forge/merge_test.go
+++ b/internal/runner/forge/merge_test.go
@@ -352,3 +352,73 @@ func TestHubMergeWithoutABearer(t *testing.T) {
t.Fatalf("invalid repository: %v", err)
}
}
+
+// TestMergeBranchLocalRefusalKeepsAnEarlierUncertainty: a request that
+// may have reached the hub left the record requested; a later attempt
+// refused here (no access now) settles nothing about the earlier one: it
+// stays uncertain and requested, and when the earlier merge lands the
+// next call finds it.
+func TestMergeBranchLocalRefusalKeepsAnEarlierUncertainty(t *testing.T) {
+ h := &fakeHub{head: strings.Repeat("a", 40), answer: func(*fakeHub, MergeRequest) (MergeResult, error) {
+ return MergeResult{}, fmt.Errorf("%w: timeout", ErrMergeUncertain)
+ }}
+ m := newMerge(t, h)
+ if _, err := MergeBranch(context.Background(), m); !errors.Is(err, ErrMergeUncertain) {
+ t.Fatalf("timeout: %v", err)
+ }
+ h.answer = func(*fakeHub, MergeRequest) (MergeResult, error) { return MergeResult{}, NoAccess(AccessNoCredential) }
+ if _, err := MergeBranch(context.Background(), m); !errors.Is(err, ErrMergeUncertain) || !strings.Contains(err.Error(), AccessNoCredential) {
+ t.Fatalf("no access after an uncertain request: %v", err)
+ }
+ if rec, _, _ := m.load(); rec.Phase != mergeRequested {
+ t.Fatalf("record %+v", rec)
+ }
+ // The first request lands after all.
+ h.mu.Lock()
+ h.landed, h.merge, h.head = true, strings.Repeat("8", 40), ""
+ h.mu.Unlock()
+ if out, err := MergeBranch(context.Background(), m); err != nil || !out.Reconciled || out.SHA != strings.Repeat("8", 40) {
+ t.Fatalf("landed: %+v %v", out, err)
+ }
+}
+
+// TestMergeBranchAccessFirst: with no access the merge is refused before
+// the remote is read (reading it may need the same missing credential),
+// final and recorded; with an earlier request outstanding the remote is
+// read first, as ever.
+func TestMergeBranchAccessFirst(t *testing.T) {
+ h := &fakeHub{head: strings.Repeat("a", 40), answer: mergeNow}
+ m := newMerge(t, h)
+ inspected := 0
+ m.Inspect = func(context.Context) (RemoteState, error) {
+ inspected++
+ return RemoteState{}, errors.New("no credential to read")
+ }
+ m.Access = func(context.Context) error { return NoAccess(AccessNotListed) }
+ if _, err := MergeBranch(context.Background(), m); !errors.Is(err, ErrMergeNoAccess) || errors.Is(err, ErrMergeUncertain) || inspected != 0 || len(h.requests) != 0 {
+ t.Fatalf("no access: %v (%d reads, %d requests)", err, inspected, len(h.requests))
+ }
+ if rec, ok, _ := m.load(); !ok || rec.Phase != mergeRefusedPh || rec.Reason != "no_access" {
+ t.Fatalf("record %+v", rec)
+ }
+ // Access there: on as before.
+ m = newMerge(t, h)
+ checked := 0
+ m.Access = func(context.Context) error { checked++; return nil }
+ if out, err := MergeBranch(context.Background(), m); err != nil || out.Source != SourceHub || checked != 1 {
+ t.Fatalf("with access: %+v %v (%d checks)", out, err, checked)
+ }
+ // An outstanding request: the remote decides first, never the check.
+ h2 := &fakeHub{head: strings.Repeat("a", 40), answer: func(h *fakeHub, req MergeRequest) (MergeResult, error) {
+ return MergeResult{}, ErrMergeUncertain
+ }}
+ m = newMerge(t, h2)
+ if _, err := MergeBranch(context.Background(), m); !errors.Is(err, ErrMergeUncertain) {
+ t.Fatal(err)
+ }
+ h2.landed, h2.merge = true, strings.Repeat("8", 40)
+ m.Access = func(context.Context) error { return NoAccess(AccessNotListed) }
+ if out, err := MergeBranch(context.Background(), m); err != nil || !out.Reconciled {
+ t.Fatalf("outstanding: %+v %v", out, err)
+ }
+}
diff --git a/internal/runner/thin/forge.go b/internal/runner/thin/forge.go
index edf4ad88..f2d0fa65 100644
--- a/internal/runner/thin/forge.go
+++ b/internal/runner/thin/forge.go
@@ -320,15 +320,30 @@ func (f *fileForge) adopt(repo string) error {
// 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) {
+ c, err := f.mergeCredential(ctx, repo)
+ if err != nil {
+ return forge.MergeResult{}, err
+ }
+ return forge.HubMerge(ctx, f.client, f.hub, c, repo, branch, req)
+}
+
+// MergeAccess is nil when the runner may ask the hub to merge in repo,
+// else Merge's no-access refusal: asked before anything is read.
+func (f *fileForge) MergeAccess(ctx context.Context, repo string) error {
+ _, err := f.mergeCredential(ctx, repo)
+ return err
+}
+
+func (f *fileForge) mergeCredential(ctx context.Context, repo string) (forge.Credential, error) {
f.list(ctx)
if !slices.Contains(f.Repos(), repo) {
- return forge.MergeResult{}, forge.NoAccess(forge.AccessNotListed)
+ return forge.Credential{}, forge.NoAccess(forge.AccessNotListed)
}
c, err := f.creds.Credential(ctx, repo)
- if err != nil {
- return forge.MergeResult{}, forge.NoAccess(forge.AccessNoCredential)
+ if err != nil || c.Bearer == "" {
+ return forge.Credential{}, forge.NoAccess(forge.AccessNoCredential)
}
- return forge.HubMerge(ctx, f.client, f.hub, c, repo, branch, req)
+ return c, nil
}
// CIHosted asks the hub whether it runs repo's CI on its own machines,
diff --git a/internal/runner/thin/forges.go b/internal/runner/thin/forges.go
index c2828e79..d593263a 100644
--- a/internal/runner/thin/forges.go
+++ b/internal/runner/thin/forges.go
@@ -100,6 +100,19 @@ func (f *Forges) Merge(ctx context.Context, repo, branch string, req forge.Merge
}
return fg.Merge(ctx, key, branch, req)
}
+
+// MergeAccess is the routed forge's MergeAccess, nil for a forge without
+// one (its Merge decides).
+func (f *Forges) MergeAccess(ctx context.Context, repo string) error {
+ fg, key, err := f.route(repo)
+ if err != nil {
+ return nil
+ }
+ if a, ok := fg.(mergeAccess); ok {
+ return a.MergeAccess(ctx, key)
+ }
+ return nil
+}
func (f *Forges) catalog(list func(Forge) []string) []string {
var out []string
for host, fg := range f.byHost {
diff --git a/internal/runner/thin/mergeaccess_test.go b/internal/runner/thin/mergeaccess_test.go
index f434a580..83544406 100644
--- a/internal/runner/thin/mergeaccess_test.go
+++ b/internal/runner/thin/mergeaccess_test.go
@@ -103,3 +103,42 @@ func TestMergeStepWithoutAccess(t *testing.T) {
t.Fatalf("with access %+v (%d requests)", rep, f.requests)
}
}
+
+// noAccessForge is a hub forge the runner holds no credential for: its
+// access check says so, and reading the repository fails too.
+type noAccessForge struct{ *hubForge }
+
+func (noAccessForge) MergeAccess(context.Context, string) error {
+ return forge.NoAccess(forge.AccessNotListed)
+}
+
+// TestMergeStepAccessBeforeReading: with no access the step ends
+// merge_no_access before the repository is read (which would fail on
+// the same missing credential and read as uncertain), and the hub is
+// never asked.
+func TestMergeStepAccessBeforeReading(t *testing.T) {
+ e, f, r, _ := hubRig(t)
+ logs := &lockedBuffer{}
+ e.O.Logger = slog.New(slog.NewTextHandler(logs, nil))
+ e.Forge = noAccessForge{f}
+ e.Clones.Forge = brokenRemote{f}
+ rep := e.Exec(context.Background(), r, func(wire.StepReport) {})
+ if rep.State != wire.StepFailed || rep.Reason != wire.ReasonMergeNoAccess || f.requests != 0 {
+ t.Fatalf("report %+v (%d requests)", rep, f.requests)
+ }
+ if line := string(logs.Bytes()); !strings.Contains(line, "cause="+forge.AccessNotListed) || strings.Contains(line, "s3cr3t") {
+ t.Fatalf("log %q", line)
+ }
+}
+
+// TestForgesRouteMergeAccess: the router asks the routed forge.
+func TestForgesRouteMergeAccess(t *testing.T) {
+ f := accessForge(t, func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(`{"repos":[]}`)) })
+ fs, err := NewForges(f)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := fs.MergeAccess(context.Background(), "amadan.net/o/elsewhere"); forge.NoAccessCause(err) != forge.AccessNotListed {
+ t.Fatalf("routed: %v", err)
+ }
+}
diff --git a/internal/runner/thin/mergestep.go b/internal/runner/thin/mergestep.go
index 7f47af1b..bba6d8d9 100644
--- a/internal/runner/thin/mergestep.go
+++ b/internal/runner/thin/mergestep.go
@@ -37,6 +37,12 @@ var (
mergeCIPoll = 15 * time.Second
)
+// mergeAccess is a forge that says, before anything is read, whether the
+// runner may publish to a repository at all (forge.ErrMergeNoAccess).
+type mergeAccess interface {
+ MergeAccess(ctx context.Context, repo string) error
+}
+
// MergeAgentHarness names the runner to the hub in the merge's agent block.
const MergeAgentHarness = "equipo"
@@ -93,6 +99,9 @@ func (e *Engineer) mergeStep(ctx context.Context, r stepRow, progress func(wire.
return e.Forge.Merge(ctx, r.Repo, r.Branch, req)
},
Confirm: confirmMerge}
+ if a, ok := e.Forge.(mergeAccess); ok {
+ m.Access = func(ctx context.Context) error { return a.MergeAccess(ctx, r.Repo) }
+ }
// Once the request may be with the hub, a cancel never stops the
// merge from being settled: the forge calls outlive the step's context
// (the instance refuses cancels while merging; shutdown keeps the
@@ -167,6 +176,7 @@ func (e *Engineer) mergeStep(ctx context.Context, r stepRow, progress func(wire.
}
return fail(wire.ReasonMergeNoAccess)
case errors.Is(err, forge.ErrMergeRefused):
+ e.logDetail("merge", err)
return fail("policy_rejected")
}
e.logDetail("merge", err)