Accept the sweep log copy and pin the re-review guards
Luna approved copyGitHubSweep on 2026-11-25, so the inventory row is accepted and plan3-copy-check passes. The value search reads BLOB columns as text, both lost fences and the sweep log wiring are pinned, an expired start without a callback leaves the page, and InstallationURL's roster check and displaced-token revocation are tested.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+207
−2
docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+1 −1internal/equipo/github/review_fixes_test.go+141 −0internal/equipo/github/store.go+5 −0internal/equipotest/github_app_test.go+8 −0internal/equipotest/github_review_test.go+49 −0internal/plan3test/plan3_release_test.go+3 −1
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 176d624e..596f90db 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -6876,7 +6876,7 @@ records remain unchanged. |
| | `github.suspended` | GitHub access is suspended | (GitHub App connection, 2026-11-23; Luna, house rules) | COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23) | |
| | `github.too_many` | Equipo can list up to %s repositories from this GitHub account. Choose fewer repositories on GitHub. | (GitHub App connection, 2026-11-23; Luna, house rules) | COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23) | |
| | `github.choose_repositories` | Choose repositories on GitHub | (GitHub App connection, 2026-11-23; Luna, house rules) | COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23) | |
| -| `copyGitHubSweep` | Could not clear expired GitHub setups. | GitHub App connection sweep log line (2026-11-23; controller approved for branch A, Luna review queued for 11-25) | Runtime (log line); COPY REVIEW REQUIRED | |
| +| `copyGitHubSweep` | Could not clear expired GitHub setups. | GitHub App connection sweep log line (2026-11-25; Luna, house rules) | COPY ACCEPTED BY DELEGATION (Luna, 2026-11-25) | |
| ## Task 21 |
diff --git a/internal/equipo/github/review_fixes_test.go b/internal/equipo/github/review_fixes_test.go| index e286dec0..230ada61 100644 |
| --- a/internal/equipo/github/review_fixes_test.go |
| +++ b/internal/equipo/github/review_fixes_test.go |
| @@ -3,6 +3,7 @@ package github |
| import ( |
| "context" |
| "encoding/json" |
| + "errors" |
| "io" |
| "net/http" |
| "strings" |
| @@ -441,3 +442,143 @@ func TestMetadataLockNotHeldAcrossNetwork(t *testing.T) { |
| t.Fatal("token minted across Forget was retained or not revoked") |
| } |
| } |
| + |
| +// Re-review P3-2: a lost fence in Check's commit is a concurrent claim. |
| +func TestForgeCheckLostFenceIsBusy(t *testing.T) { |
| + r := storeRig(t) |
| + ctx := context.Background() |
| + view := r.created(t) |
| + entered, release := make(chan struct{}), make(chan struct{}) |
| + base := r.g.Transport() |
| + r.s.API = NewAPI(transportFunc(func(req *http.Request) (*http.Response, error) { |
| + response, err := base.RoundTrip(req) |
| + if req.URL.Path == "/installation/repositories" { |
| + close(entered) |
| + <-release |
| + } |
| + return response, err |
| + }), func() time.Time { return r.now }) |
| + done := make(chan error, 1) |
| + go func() { _, e := r.s.Check(ctx, r.owner, view.ID); done <- e }() |
| + <-entered |
| + // The first claim outlives its 30 seconds; another owner's Check takes over. |
| + r.advance(31 * time.Second) |
| + other := *r.s |
| + other.API = NewAPI(r.g.Transport(), func() time.Time { return r.now }) |
| + if _, err := other.Check(ctx, r.other, view.ID); err != nil { |
| + close(release) |
| + t.Fatal(err) |
| + } |
| + close(release) |
| + if err := <-done; !errors.Is(err, ErrBusy) || !Retryable(err) { |
| + t.Fatal("lost Check fence not busy:", err) |
| + } |
| +} |
| + |
| +// Re-review P3-2: a lost fence in Connect's own transaction is a concurrent claim. |
| +func TestForgeConnectLostFenceIsBusy(t *testing.T) { |
| + r := storeRig(t) |
| + ctx := context.Background() |
| + view := r.created(t) |
| + owner, calls := r.s.Owner, 0 |
| + r.s.Owner = func(tx *gorm.DB, person string) error { |
| + // Check claims and commits (calls 1 and 2); Connect's own write is call 3. |
| + if calls++; calls == 3 { |
| + if err := tx.Exec("UPDATE forge_connections SET generation = generation + 1 WHERE id = ?", view.ID).Error; err != nil { |
| + return err |
| + } |
| + } |
| + return owner(tx, person) |
| + } |
| + if _, err := r.s.Connect(ctx, r.owner, view.ID); !errors.Is(err, ErrBusy) || !Retryable(err) { |
| + t.Fatal("lost Connect fence not busy:", err) |
| + } |
| + var c Connection |
| + r.s.DB.First(&c, "id = ?", view.ID) |
| + if c.Confirmed { |
| + t.Fatal("Connect committed across a lost fence") |
| + } |
| +} |
| + |
| +// Re-review P3-4: a start with no callback leaves the page at its deadline, |
| +// but its hash stays so a late callback still gets its answer. |
| +func TestForgeExpiredManifestStartHidden(t *testing.T) { |
| + r := storeRig(t) |
| + ctx := context.Background() |
| + began, err := r.s.Start(ctx, r.owner, r.g.Login, r.g.AccountType) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + r.advance(9 * time.Minute) |
| + if views := r.list(t); len(views) != 1 { |
| + t.Fatal("live start hidden before its deadline") |
| + } |
| + r.advance(time.Minute) |
| + if views := r.list(t); len(views) != 0 { |
| + t.Fatalf("start listed past its deadline: %+v", views) |
| + } |
| + got, err := r.s.Convert(ctx, r.owner, began.State, r.g.Code) |
| + var refused *Refusal |
| + if !errors.As(err, &refused) || got.State != StateManifestExpired { |
| + t.Fatal("late callback lost its answer:", err, got.State) |
| + } |
| + if views := r.list(t); len(views) != 1 || views[0].State != StateManifestExpired { |
| + t.Fatalf("late callback's App not listed: %+v", views) |
| + } |
| +} |
| + |
| +// Re-review P3-5: InstallationURL checks the current roster itself. |
| +func TestForgeInstallationURLRoster(t *testing.T) { |
| + r := storeRig(t) |
| + view := r.created(t) |
| + r.s.DB.Model(&testOwner{}).Where("address = ?", r.owner.Address).Update("active", false) |
| + if target, err := r.s.InstallationURL(context.Background(), r.owner, view.ID); err == nil || target != "" { |
| + t.Fatal("removed owner received the installation handoff") |
| + } |
| +} |
| + |
| +// Re-review P3-5: a token displaced by a concurrent mint is revoked. |
| +func TestMetadataDisplacedTokenRevoked(t *testing.T) { |
| + r := storeRig(t) |
| + ctx := context.Background() |
| + view := r.created(t) |
| + var c Connection |
| + r.s.DB.First(&c, "id = ?", view.ID) |
| + app, err := r.s.app(c) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + inst, err := r.s.API.Installation(ctx, app, r.g.InstallationID) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + entered, release := make(chan struct{}), make(chan struct{}) |
| + first := true |
| + base := r.g.Transport() |
| + api := NewAPI(transportFunc(func(req *http.Request) (*http.Response, error) { |
| + response, err := base.RoundTrip(req) |
| + if strings.HasSuffix(req.URL.Path, "/access_tokens") && first { |
| + first = false |
| + close(entered) |
| + <-release |
| + } |
| + return response, err |
| + }), func() time.Time { return r.now }) |
| + done := make(chan error, 1) |
| + go func() { _, e := api.metadata(ctx, app, inst); done <- e }() |
| + <-entered |
| + if _, err = api.metadata(ctx, app, inst); err != nil { |
| + close(release) |
| + t.Fatal(err) |
| + } |
| + close(release) |
| + if err = <-done; err != nil { |
| + t.Fatal(err) |
| + } |
| + api.mu.Lock() |
| + n := len(api.tokens) |
| + api.mu.Unlock() |
| + if n != 1 || r.g.Calls("DELETE", "/installation/token") != 1 { |
| + t.Fatal("displaced metadata token was not revoked") |
| + } |
| +} |
diff --git a/internal/equipo/github/store.go b/internal/equipo/github/store.go| index 0c791c87..73befc6d 100644 |
| --- a/internal/equipo/github/store.go |
| +++ b/internal/equipo/github/store.go |
| @@ -190,6 +190,11 @@ func (s *Store) List(ctx context.Context, p Principal) ([]View, error) { |
| shown := map[string]bool{} |
| views := make([]View, 0, len(records)) |
| for _, record := range records { |
| + // A start GitHub never called back leaves the page at its redirect |
| + // deadline. Its hash stays, so a late callback still gets its answer. |
| + if record.State == StateManifest && !s.now().Before(record.RedirectUntil) { |
| + continue |
| + } |
| if record.State.Dead() { |
| key := account(record) |
| if record.State == StateAbandoned || connected[key] || shown[key] { |
diff --git a/internal/equipotest/github_app_test.go b/internal/equipotest/github_app_test.go| index b769f583..184e5654 100644 |
| --- a/internal/equipotest/github_app_test.go |
| +++ b/internal/equipotest/github_app_test.go |
| @@ -152,6 +152,14 @@ func TestGitHubHTTPFlowAndValues(t *testing.T) { |
| if err := f.db.G.Table(table).Find(&rows).Error; err != nil { |
| t.Fatal(err) |
| } |
| + // json.Marshal would base64 a BLOB and hide a stored key from the search. |
| + for _, row := range rows { |
| + for column, value := range row { |
| + if blob, ok := value.([]byte); ok { |
| + row[column] = string(blob) |
| + } |
| + } |
| + } |
| raw, err := json.Marshal(rows) |
| if err != nil { |
| t.Fatal(err) |
diff --git a/internal/equipotest/github_review_test.go b/internal/equipotest/github_review_test.go| index 9ba6832e..ef28dea9 100644 |
| --- a/internal/equipotest/github_review_test.go |
| +++ b/internal/equipotest/github_review_test.go |
| @@ -1,15 +1,19 @@ |
| package equipotest |
| import ( |
| + "bytes" |
| + "log/slog" |
| "net/http" |
| "net/url" |
| "strings" |
| + "sync" |
| "testing" |
| "time" |
| "amadan.net/oficina/equipo/internal/equipo" |
| "amadan.net/oficina/equipo/internal/equipo/github" |
| "amadan.net/oficina/equipo/internal/runner/forge/forgetest" |
| + "amadan.net/rastrillo/rastrillo" |
| ) |
| // Review fixes (Fable, 2026-11-23): page-level lifecycle rendering. |
| @@ -123,3 +127,48 @@ func TestGitHubSettingsNav(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +type githubSyncBuffer struct { |
| + mu sync.Mutex |
| + b bytes.Buffer |
| +} |
| + |
| +func (s *githubSyncBuffer) Write(p []byte) (int, error) { |
| + s.mu.Lock() |
| + defer s.mu.Unlock() |
| + return s.b.Write(p) |
| +} |
| +func (s *githubSyncBuffer) String() string { s.mu.Lock(); defer s.mu.Unlock(); return s.b.String() } |
| + |
| +// Re-review P3-3: the serving minute loop logs a failed GitHub sweep with the |
| +// diagnostic constant and its type, never the UI string or the error text. |
| +func TestGitHubSweepFailureLogged(t *testing.T) { |
| + d, _ := foundationDB(t) |
| + logs := &githubSyncBuffer{} |
| + logger := slog.New(slog.NewTextHandler(logs, nil)) |
| + cfg := testConfig(testOrigin) |
| + router, err := equipo.Router(d, cfg, &capturingMailer{}, logger) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + // The sweep's own query fails on the loop's first pass. |
| + if err = d.G.Exec("DROP TABLE forge_connections").Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + var opts rastrillo.Options |
| + opts.Logger = logger |
| + equipo.Configure(&opts, equipo.Mux(router), time.Now()) |
| + t.Cleanup(opts.Background.Stop) |
| + deadline := time.Now().Add(10 * time.Second) |
| + for !strings.Contains(logs.String(), "Could not clear expired GitHub setups.") { |
| + if time.Now().After(deadline) { |
| + t.Fatalf("sweep failure not logged: %s", logs.String()) |
| + } |
| + time.Sleep(20 * time.Millisecond) |
| + } |
| + for _, line := range strings.Split(logs.String(), "\n") { |
| + if strings.Contains(line, "GitHub setups") && (!strings.Contains(line, "kind=other") || !strings.Contains(line, "err_type=") || strings.Contains(line, "forge_connections") || strings.Contains(line, "could not check GitHub")) { |
| + t.Fatalf("sweep log line: %s", line) |
| + } |
| + } |
| +} |
diff --git a/internal/plan3test/plan3_release_test.go b/internal/plan3test/plan3_release_test.go| index d2cba223..674ee49a 100644 |
| --- a/internal/plan3test/plan3_release_test.go |
| +++ b/internal/plan3test/plan3_release_test.go |
| @@ -199,13 +199,15 @@ func plan3CopyInventory(t *testing.T) { |
| acceptedAPIErrors := slices.Contains([]string{"api.repo_not_allowed", "api.card_answered", "api.card_stale", "api.confirmation_required", "api.coordinator_busy", "api.hold_bar", "api.idempotency_conflict", "api.models_not_allowed", "api.not_active", "api.not_askable", "api.not_mergeable", "api.not_retryable", "api.question_ended", "api.runner_offline", "api.task_busy", "api.task_ended", "api.task_merging", "api.turn_ended"}, key) && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23)") |
| acceptedNativeProjects := slices.Contains([]string{"projects.new_request", "projects.remove_selection"}, key) && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23)") |
| acceptedGitHubApp := slices.Contains([]string{"github.title", "github.connect", "github.account", "github.account_type", "github.organization", "github.personal_account", "github.create_app", "github.create_hint", "github.confirm_account", "github.repository_count", "github.confirm", "github.connected", "github.already_connected", "github.disconnect", "github.disconnect_hint", "github.pending", "github.pending_hint", "github.pending_approval", "github.check_again", "github.redirect_expired", "github.pending_expired", "github.setup_failed", "github.app_remains", "github.app_settings", "github.reconnect", "github.reconnect_hint", "github.check_failed", "github.not_connected", "github.suspended", "github.too_many", "github.choose_repositories"}, key) && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23)") |
| + // Luna's verdict on the GitHub sweep log line, 2026-11-25. |
| + acceptedGitHubSweep := key == "copyGitHubSweep" && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-25)") |
| acceptedGitHubEgress := key == "CopyGitHubEgress" && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23)") |
| acceptedForgeSeam := key == "work.reason.proposal_failed" && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23)") |
| acceptedCardNames := slices.Contains([]string{"projects.carried_selection", "projects.remember_name", "projects.name_to_remember", "projects.use_title", "docs/api/equipo-v1.md / Projects and starting a request"}, key) && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-23)") |
| acceptedProjects := slices.Contains([]string{"projects.amadan", "projects.yours", "projects.can_add", "projects.add_reachable", "projects.names", "projects.names_hint", "projects.details", "projects.title", "projects.description", "projects.save", "projects.context", "projects.found", "projects.selected", "projects.owner_add", "projects.selection_lost", "projects.other", "projects.name_question", "projects.personal_names", "projects.forget_name", "docs/api/equipo-v1.md / Projects and starting a request"}, key) && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-22)") |
| acceptedAgentAccess := slices.Contains([]string{"copyAgentConfig", "copyAgentForbidden", "copyAgentNotFound", "copyAgentUnavailable", "copyAgentTooLarge", "copyAgentInvalid", "copyAgentMedia", "copyAgentUnauthenticated", "agent.equipo_projects_list", "agent.equipo_tasks_list", "agent.equipo_task_get", "agent.equipo_needs_you", "docs/api/equipo-v1.md / Delegated read-only operations"}, key) && strings.HasSuffix(strings.TrimSuffix(cells[3], " |"), "COPY ACCEPTED BY DELEGATION (Luna, 2026-11-20)") |
| acceptedCopy := strings.TrimSuffix(cells[3], " |") == "COPY ACCEPTED BY DELEGATION (Copy, record-bound) sha256:"+copydesk.Hash(rows[key]) |
| - if !acceptedGitHubApp && !acceptedGitHubEgress && !acceptedForgeSeam && !acceptedAPIErrors && !acceptedNativeProjects && !acceptedInjection && !acceptedMail && !acceptedPush && !acceptedAgentAccess && !acceptedProjects && !acceptedCardNames && !acceptedAccess && !acceptedPlacementEdges && !acceptedPlacement && !acceptedReportActions && !acceptedRoster && !acceptedCopy && !strings.Contains(cells[3], "COPY REVIEW REQUIRED") && !acceptedAll && !acceptedGuide && !acceptedRound2 && !acceptedStarter && !acceptedDelegation && !approvedPublish && !approvedAssistant && !approvedJobs && !approvedOficina && !approvedFailedReplies && !approvedStopReasons { |
| + if !acceptedGitHubApp && !acceptedGitHubSweep && !acceptedGitHubEgress && !acceptedForgeSeam && !acceptedAPIErrors && !acceptedNativeProjects && !acceptedInjection && !acceptedMail && !acceptedPush && !acceptedAgentAccess && !acceptedProjects && !acceptedCardNames && !acceptedAccess && !acceptedPlacementEdges && !acceptedPlacement && !acceptedReportActions && !acceptedRoster && !acceptedCopy && !strings.Contains(cells[3], "COPY REVIEW REQUIRED") && !acceptedAll && !acceptedGuide && !acceptedRound2 && !acceptedStarter && !acceptedDelegation && !approvedPublish && !approvedAssistant && !approvedJobs && !approvedOficina && !approvedFailedReplies && !approvedStopReasons { |
| t.Fatal("entry has no copy review status or applicable acceptance", key) |
| } |
| } |