Merge main (mac-recheck); a re-run pass goes through the gate
Merge of origin/main 961a7db. Migration renumbered 0061 (main has 0060
for chat_steps.recheck_by). The recheck contracts run on a
ProtocolMergeFacts primary and answer Wait for a Mac.
A Mac re-run's pass on the exact candidate is eligible when the passing
result lands (mac-recheck's advance), and authorizeMerge now judges it
like a merge without checks less the environment rule
(mergegate.Inputs.Rechecked): a routine change merges on its own, a
sensitive, large or shipping one, a held one, or one in an asking
project asks; a result on another SHA counts for nothing. The on-enrol
recheck contract becomes the routine case (measured review, owner says
main does not ship). Perf record for GET /api/v1/projects/{id}/merge-policy.
TestContractMacRecheckMergeAuthority before the gate change:
--- FAIL: TestContractMacRecheckMergeAuthority (4.80s)
--- FAIL: TestContractMacRecheckMergeAuthority/sensitive (0.90s)
macrecheck_mergeauth_contract_test.go:94: 1 dispatch waiting for this runner
--- FAIL: TestContractMacRecheckMergeAuthority/ships (0.87s)
macrecheck_mergeauth_contract_test.go:116: 1 dispatch waiting for this runner
FAIL
After: ok. Mutations: the gate's re-run rule (TestDecideRecheckedPass,
TestDecideNeverLooser) and the instance's Rechecked input
(TestContractMacRecheckMergeAuthority), both killed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 files changed,
+624
−23
.rastrillo/budgets.txt+3 −2docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+9 −1docs/superpowers/plans/MERGEAUTH-PROGRESS.md+13 −0docs/superpowers/specs/2026-11-11-equipo-merge-authority.md+10 −2internal/equipo/chat/macrecheck.go+90 −0internal/equipo/chat/mergeauth.go+3 −0internal/equipo/chat/review.go+4 −0internal/equipo/chat/runner.go+8 −2internal/equipo/chat/runners.go+7 −1internal/equipo/chat/tasks.go+3 −0internal/equipo/copy.go+1 −1internal/equipo/mergegate/gate.go+29 −9internal/equipo/mergegate/gate_test.go+36 −0internal/equipo/migrations/0060_thin_mac_recheck.sql+1 −0internal/equipo/migrations/{0060_thin_merge_authority.sql => 0061_thin_merge_authority.sql}+0 −0internal/equipo/migrations/schema.sql+1 −1internal/thintest/macrecheck_contract_test.go+267 −0internal/thintest/macrecheck_mergeauth_contract_test.go+129 −0internal/thintest/placement_contract_test.go+9 −3internal/thintest/projects_pages_test.go+1 −1
CI passed — run details
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 8dffc344..df321b8c 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -49,7 +49,7 @@ perf GET /api/v1/notebook skip Thin v1 person API: bearer-only JSON for devices; |
| perf GET /api/v1/thinking skip Thin v1 person API: bearer-only JSON for devices; the browser reads thinking words on /settings/thinking. |
| perf GET /api/v1/tasks skip Thin v1 person API: bearer-only JSON for devices; the browser reads tasks through /tasks. |
| perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads a task through /tasks/{id}. |
| -size internal/equipo/chat 13700 - Merge authority thin v1 adds the gate's store side (mergeauth.go: authorizeMerge before dispatch and at each hub request, the fence for runners below the merge-facts protocol, the ask card in Equipo's words, the ships question, receipts with Undo, the policy tool and API, about 1000 lines); the gate is pure, in internal/equipo/mergegate, but its inputs and audit must be read and written inside the store's transactions. Measured 13204. Spend 1 merged onto Projects UX: measured 12376 with both. Spend 1 adds a task's spend from its usage rows (TaskSpend, about 60 lines) and the usage rows' round; measured 12047. Projects UX adds per-person project stars with the auto-star reconciliation, the person's and the coordinator's star_project (stars.go, about 210 lines) and the project's own repository in its view; measured 12206. Claude's sign-in by a link adds the code route beside the token's in SendSecret, the sign-in prompt and the kind it becomes (about 40 lines); measured 11933. Mac runners slices A and B add per-runner mailboxes, placement, withdrawal, the offline rule, the runners view, transfers and publication (runners.go, transfers.go, about 1100 lines). Composer attachments add uploads, the message link, the mailbox relay with chunk frames hydrated from the stored file, and serving (attachments.go, attachments_http.go, about 330 lines); the link and relay run inside the send and dispatch transactions, so they live beside them; sniffing and stripping are pure, in internal/attach. Measured 10292. Merged with UX1 thinking words (f2602d3), measured 9801. Housekeeping slice 1 adds the loop's ledger and state machine, the housekeeping principal's checks inside the shared store functions, reservations, Pause, quiet hours, the digest, claim recovery and the API (housekeeping.go, housekeeping_control.go, housekeeping_http.go, about 1,350 lines); the checks must run inside the store's transactions, so they live beside them; the detectors themselves are pure, in internal/equipo/housekeeping. Measured 9637. Thin v1 UX1 thinking words adds the per-person set and its API (thinking.go, about 100 lines); measured 8305. Connections slice 1 review round 2: the mutation ledger matches record_task by subject only and refuses an ambiguous call with the earlier operations, the preference and forget (about 120 lines); measured 8236. Thin v1 UX1 round 3 adds Equipo combining duplicate tasks reversibly (duplicates.go: detection, the in-transaction fold checks, fold, Undo, about 400 lines) and headlines on findings and steps (headline.go); measured 7898. Connections slice 1 adds connection records from hello and attempts, the connect mailbox, the API, usage rows and the turn's mutation ledger (connections.go and tools.go, about 600 lines); measured 7400 after merging UX1. Thin v1 UX1 adds step activity lines, duplicates and their fold, the coordinator at work on a task, project facts from the runner catalog and open merge cards for the pages (inner.go, about 330 lines); measured 6610 with slice 4c's review fixes. Thin v1 slice 4c adds the merge policy, the merge card, the rebase round and duplicate reports (merge.go, about 380 lines). Thin v1 instance core: conversation, projects, tasks, review and, from slice 4b, questions to the specialists (questions.go, about 470 lines) share one store, transaction and event log; splitting would export the transaction internals. Measured 5514 source lines; revisit at the slice 7 sweep. |
| +size internal/equipo/chat 13820 - Merge authority thin v1 adds the gate's store side (mergeauth.go: authorizeMerge before dispatch and at each hub request, the fence for runners below the merge-facts protocol, the ask card in Equipo's words, the ships question, receipts with Undo, the policy tool and API, about 1000 lines); the gate is pure, in internal/equipo/mergegate, but its inputs and audit must be read and written inside the store's transactions. Measured 13204. Mac recheck runs a waiting task's needs_macos checks again when a Mac that fits arrives (macrecheck.go, about 90 lines); measured 12485. Spend 1 merged onto Projects UX: measured 12376 with both. Spend 1 adds a task's spend from its usage rows (TaskSpend, about 60 lines) and the usage rows' round; measured 12047. Projects UX adds per-person project stars with the auto-star reconciliation, the person's and the coordinator's star_project (stars.go, about 210 lines) and the project's own repository in its view; measured 12206. Claude's sign-in by a link adds the code route beside the token's in SendSecret, the sign-in prompt and the kind it becomes (about 40 lines); measured 11933. Mac runners slices A and B add per-runner mailboxes, placement, withdrawal, the offline rule, the runners view, transfers and publication (runners.go, transfers.go, about 1100 lines). Composer attachments add uploads, the message link, the mailbox relay with chunk frames hydrated from the stored file, and serving (attachments.go, attachments_http.go, about 330 lines); the link and relay run inside the send and dispatch transactions, so they live beside them; sniffing and stripping are pure, in internal/attach. Measured 10292. Merged with UX1 thinking words (f2602d3), measured 9801. Housekeeping slice 1 adds the loop's ledger and state machine, the housekeeping principal's checks inside the shared store functions, reservations, Pause, quiet hours, the digest, claim recovery and the API (housekeeping.go, housekeeping_control.go, housekeeping_http.go, about 1,350 lines); the checks must run inside the store's transactions, so they live beside them; the detectors themselves are pure, in internal/equipo/housekeeping. Measured 9637. Thin v1 UX1 thinking words adds the per-person set and its API (thinking.go, about 100 lines); measured 8305. Connections slice 1 review round 2: the mutation ledger matches record_task by subject only and refuses an ambiguous call with the earlier operations, the preference and forget (about 120 lines); measured 8236. Thin v1 UX1 round 3 adds Equipo combining duplicate tasks reversibly (duplicates.go: detection, the in-transaction fold checks, fold, Undo, about 400 lines) and headlines on findings and steps (headline.go); measured 7898. Connections slice 1 adds connection records from hello and attempts, the connect mailbox, the API, usage rows and the turn's mutation ledger (connections.go and tools.go, about 600 lines); measured 7400 after merging UX1. Thin v1 UX1 adds step activity lines, duplicates and their fold, the coordinator at work on a task, project facts from the runner catalog and open merge cards for the pages (inner.go, about 330 lines); measured 6610 with slice 4c's review fixes. Thin v1 slice 4c adds the merge policy, the merge card, the rebase round and duplicate reports (merge.go, about 380 lines). Thin v1 instance core: conversation, projects, tasks, review and, from slice 4b, questions to the specialists (questions.go, about 470 lines) share one store, transaction and event log; splitting would export the transaction internals. Measured 5514 source lines; revisit at the slice 7 sweep. |
| 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. |
| @@ -62,4 +62,5 @@ perf GET /conversation/attachments/{id}/preview skip Composer attachments: an 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 Mac runners slice B: TestReleaseRunnerHasNoFakeWorker builds the release runner exactly as make release-runner does and the thin package under the testbuild tag (measured 11.9s locally with a warm cache). |
| size internal/headless - 8300 Claude's sign-in by a link adds its end-to-end, contained-launch and real runner kill tests (signin_test.go, signin_contained_test.go, about 400 lines); measured 8090. |
| -size internal/thintest - 12100 Merge authority thin v1 adds its contracts (mergeauth_contract_test.go, about 650 lines) and the protocol-aware tool rig; measured 12032 with main merged. Spend 1 merged onto the four UI branches: measured 11325. Spend 1 marks overcounting Claude rows (about 120 lines); it adds the task page's spend contract and the 0059 upgrade (spend_pages_test.go, about 100 lines) and the fix round feedback by protocol (about 40); measured 10224. The team panel merged onto Projects UX and the Settings UX pass: measured 11064 with all three. The team panel adds its page contract and the drawer's browser drive at 1280 and 390 (team_panel_test.go, team_panel_browser_test.go, about 300 lines); measured 10235. Projects UX merged onto the Settings UX pass: measured 10768 with both. Projects UX adds the Projects page contracts (order, quiet fold, filter, stars and Undo, the coordinator's star, repository counts, whole words), the decision cards' Mac and Ask about this contracts and their browser drive (projects_pages_test.go, projects_browser_test.go, about 330 lines); measured 10321. The Settings UX pass adds the Settings pattern's page contracts and the savebar, Housekeeping groups and Teams browser drives (settings_ux_pages_test.go, settings_ux_browser_test.go, about 430 lines); measured 10390. Claude's sign-in by a link adds the code contract (signin_contract_test.go: the card, the code route's refusals, the wrong-code card, the kind it becomes and the canary sweep, about 220 lines); measured 9896. The Connections Add page and the Settings rail add their page contracts and the rail's browser drive (connections_add_pages_test.go, settings_rail_pages_test.go, about 230 lines); measured 9676. Claude setup tokens add the token and Check again contracts; measured 9444 with the composer and Mac lines merged. The instant thinking line adds its browser drive (instant_browser_test.go, about 230 lines); measured 9064 with the composer and Mac lines merged. Mac runners add the role, scoping, migration, placement, withdrawal, transfer and publication contracts (about 900 test lines) beside the thin v1 contracts; one package keeps one instance harness. |
| +size internal/thintest - 12500 Merge authority thin v1 adds its contracts (mergeauth_contract_test.go, about 650 lines) the protocol-aware rigs and the Mac re-run contract (macrecheck_mergeauth_contract_test.go); measured 12434 with main merged. Mac recheck adds its enrolment, skip and outcome contracts (macrecheck_contract_test.go, about 210 lines); measured 11537. Spend 1 merged onto the four UI branches: measured 11325. Spend 1 marks overcounting Claude rows (about 120 lines); it adds the task page's spend contract and the 0059 upgrade (spend_pages_test.go, about 100 lines) and the fix round feedback by protocol (about 40); measured 10224. The team panel merged onto Projects UX and the Settings UX pass: measured 11064 with all three. The team panel adds its page contract and the drawer's browser drive at 1280 and 390 (team_panel_test.go, team_panel_browser_test.go, about 300 lines); measured 10235. Projects UX merged onto the Settings UX pass: measured 10768 with both. Projects UX adds the Projects page contracts (order, quiet fold, filter, stars and Undo, the coordinator's star, repository counts, whole words), the decision cards' Mac and Ask about this contracts and their browser drive (projects_pages_test.go, projects_browser_test.go, about 330 lines); measured 10321. The Settings UX pass adds the Settings pattern's page contracts and the savebar, Housekeeping groups and Teams browser drives (settings_ux_pages_test.go, settings_ux_browser_test.go, about 430 lines); measured 10390. Claude's sign-in by a link adds the code contract (signin_contract_test.go: the card, the code route's refusals, the wrong-code card, the kind it becomes and the canary sweep, about 220 lines); measured 9896. The Connections Add page and the Settings rail add their page contracts and the rail's browser drive (connections_add_pages_test.go, settings_rail_pages_test.go, about 230 lines); measured 9676. Claude setup tokens add the token and Check again contracts; measured 9444 with the composer and Mac lines merged. The instant thinking line adds its browser drive (instant_browser_test.go, about 230 lines); measured 9064 with the composer and Mac lines merged. Mac runners add the role, scoping, migration, placement, withdrawal, transfer and publication contracts (about 900 test lines) beside the thin v1 contracts; one package keeps one instance harness. |
| +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}. |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index abefa884..bfb744c5 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -6031,7 +6031,7 @@ records remain unchanged. |
| | `work.chip.waiting_mac` | Waiting for a Mac to run checks | Tasks and Needs you (projects-ux) | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) | |
| | `work.summary.waiting_mac` | Approved. Waiting for a Mac to run checks. You can merge now without checks. | Tasks and Needs you (projects-ux) | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) | |
| | `work.decide.mac_why` | Review approved. Checks need a Mac, and no Mac is set up to run them. | Tasks and Needs you (projects-ux) | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) | |
| -| `work.decide.mac_hint` | Merge now merges it without checks. Wait for a Mac leaves it as it is. Once a Mac is set up, checks run on its next change, and if they pass, Equipo merges it by itself. | Tasks and Needs you (projects-ux) | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) | |
| +| `work.decide.mac_hint` | Merge now merges it without checks. Wait for a Mac keeps it ready. Once a Mac is set up, checks run, and if they pass, Equipo merges it by itself. | Tasks and Needs you (projects-ux) | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) | |
| | `work.decide.mac.merge` | Merge now | Tasks and Needs you (projects-ux) | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) | |
| | `work.decide.mac.wait` | Wait for a Mac | Tasks and Needs you (projects-ux) | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) | |
| | `work.decide.mac_set_up` | Set up a Mac | Tasks and Needs you (projects-ux) | COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) | |
| @@ -6795,3 +6795,11 @@ coordinator's ruling (2026-11-11), still accepted by delegation: |
| Spend 1's eight strings (`work.spend*`, with `work.spend_left_out`) had |
| their own small Astra pass on 2026-11-11 with the same brief: all eight |
| kept, no flags; marked accepted by delegation. |
| + |
| +Mac recheck (2026-11-11) closes the `work.decide.mac_hint` gap above: a |
| +Mac that fits, enrolling or back online, runs a waiting task's |
| +`needs_macos` checks again on its candidate (`chat/macrecheck.go`), and a |
| +pass merges under slice 4c. The hint is a plain line again: "Merge now |
| +merges it without checks. Wait for a Mac keeps it ready. Once a Mac is set |
| +up, checks run, and if they pass, Equipo merges it by itself." Accepted by |
| +delegation like its neighbours. |
diff --git a/docs/superpowers/plans/MERGEAUTH-PROGRESS.md b/docs/superpowers/plans/MERGEAUTH-PROGRESS.md| index d6b48b4f..ac24c3f5 100644 |
| --- a/docs/superpowers/plans/MERGEAUTH-PROGRESS.md |
| +++ b/docs/superpowers/plans/MERGEAUTH-PROGRESS.md |
| @@ -72,6 +72,19 @@ and the controller directed the other four findings). |
| allowlist (`TestConversePolicyCoversEveryTool`), and one house-rule |
| sentence about them. |
| +9. **Main merged twice** (spend-1 and the four UI branches; then |
| + mac-recheck). Migration now **0061** (main has 0060 for |
| + `chat_steps.recheck_by`). Protocol 4 is `wire.ProtocolMergeFacts`. |
| + A Mac re-run's pass (mac-recheck sets eligibility when the passing |
| + result lands, on the exact candidate) is judged like a merge without |
| + checks less the environment rule (`Inputs.Rechecked`): |
| + `TestContractMacRecheckMergeAuthority` (routine merges through |
| + authorizeMerge and its request is confirmed; sensitive asks; held |
| + asks; main ships asks; a pass on another SHA counts for nothing), |
| + first failing on sensitive and ships (Equipo merged), and |
| + `TestDecideRecheckedPass`. Mutations: the gate's re-run rule and the |
| + instance's Rechecked input, both killed. |
| + |
| ## Tests (targeted, local, niced) |
| - `go test ./internal/equipo/mergegate` (9 tests, including a 20,000-input |
diff --git a/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md b/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md| index edf4ff08..37fd8a1e 100644 |
| --- a/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md |
| +++ b/docs/superpowers/specs/2026-11-11-equipo-merge-authority.md |
| @@ -98,7 +98,15 @@ func Decide(in Inputs) Decision |
| 3. **Checks passed**, not outside the sandbox, `Eligible`: `act` with |
| `Checks: true` unless `Policy.Mode == ask` or `Hold != ""` (then |
| `ask`, options Merge, Not now). Not eligible: `ask` (slice 4c's adopt |
| - card). Outside the sandbox: `ask`, as today. |
| + card). Outside the sandbox: `ask`, as today. The runner must speak |
| + `wire.ProtocolMergeFacts` here too (Refuse old runners). A pass from a |
| + Mac re-run (mac-recheck, `chat_steps.recheck_by`) on the exact |
| + candidate makes it eligible when the passing result lands, and is |
| + then judged like a merge without checks less the environment rule: a |
| + routine change merges on its own; a sensitive, large or shipping one, |
| + a held one, or one in an asking project asks. A re-run that fails |
| + takes the normal fix round; a result on another SHA counts for |
| + nothing. |
| 4. **Without checks**: `act` only when ALL hold, else `ask`: |
| | Criterion | Holds when | |
| @@ -400,7 +408,7 @@ it exactly reverts %s."). |
| ### 7.1 Storage |
| -Migration **0060** (main has 0058 project stars and 0059 usage rounds; |
| +Migration **0061** (main has 0058 project stars, 0059 usage rounds and 0060 Mac recheck; |
| the next free number if another branch lands 0060 first). Tables `chat_merge_policies` and `chat_merge_audit`; |
| columns `chat_steps.change_facts`, `chat_steps.decided_by`, |
| `chat_steps.merge_source`, `chat_steps.merge_parents`, |
diff --git a/internal/equipo/chat/macrecheck.go b/internal/equipo/chat/macrecheck.go| new file mode 100644 |
| index 00000000..0d8e9ad6 |
| --- /dev/null |
| +++ b/internal/equipo/chat/macrecheck.go |
| @@ -0,0 +1,90 @@ |
| +package chat |
| + |
| +import ( |
| + "slices" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// recheckMac runs again the checks of the person's tasks that wait for a |
| +// Mac, when runner (just enrolled, or back online) fits them: Ready to |
| +// merge, approved, their newest checks not run because no runner could |
| +// (needs_macos), the branch still at that candidate and no merge of it. |
| +// The checks are placed afresh on that exact candidate through the usual |
| +// placement (nextStep), so a pass merges under the slice 4c policy |
| +// (advance grants it) and a failure takes the fix round. Once per |
| +// candidate per runner: a reconnect of the same runner runs nothing. |
| +func (t *txn) recheckMac(person, runner string) error { |
| + rs, err := t.runners(person) |
| + if err != nil { |
| + return err |
| + } |
| + primary, err := t.s.authority.PrimaryRunner(t.db, person) |
| + if err != nil { |
| + return err |
| + } |
| + var mac *runnerInfo |
| + relay := false |
| + for i := range rs { |
| + if rs[i].ID == runner && rs[i].Online && slices.Contains(rs[i].tags(), wire.TagMacOS) { |
| + mac = &rs[i] |
| + } |
| + if rs[i].ID == primary && rs[i].Protocol >= wire.Protocol2 { |
| + relay = true |
| + } |
| + } |
| + if mac == nil || !relay && runner != primary { |
| + // Not a Mac, or placement would end on the primary again. |
| + return nil |
| + } |
| + var tasks []taskRecord |
| + if err := t.db.Where("creator = ? AND stage = ? AND cancel_requested = ?", person, wire.StageReadyToMerge, false).Order("created_at, id").Find(&tasks).Error; err != nil { |
| + return err |
| + } |
| + for i := range tasks { |
| + k := &tasks[i] |
| + steps, err := t.steps(k.ID) |
| + if err != nil { |
| + return err |
| + } |
| + p := progressFor(*k, steps) |
| + c := p.checks |
| + if p.moved || p.merge != nil || p.eng == nil || p.eng.Person != person || c == nil || c.State != wire.StepDone || c.Checks != wire.ChecksCannotRun || c.Reason != "needs_macos" { |
| + continue |
| + } |
| + if _, _, verdict, _ := p.judged(); verdict != wire.VerdictApprove { |
| + continue |
| + } |
| + needs := decodeList(c.Needs) |
| + if len(needs) == 0 { |
| + if needs, err = t.checksNeeds(*k, *c); err != nil { |
| + return err |
| + } |
| + } |
| + if !slices.Contains(needs, wire.TagMacOS) || !mac.fits(needs, decodeList(c.RefusedBy)) { |
| + continue |
| + } |
| + var ran int64 |
| + if err := t.db.Model(&stepRecord{}).Where("task_id = ? AND specialist = ? AND candidate_sha = ? AND recheck_by = ?", k.ID, wire.SpecialistChecks, p.candidate, runner).Count(&ran).Error; err != nil { |
| + return err |
| + } |
| + if ran > 0 { |
| + continue |
| + } |
| + // The card asked whether to merge without checks; they run now, |
| + // and their outcome asks afresh if it must. |
| + if err := t.withdrawMergeCards(*k); err != nil { |
| + return err |
| + } |
| + k.MergeAsked = "" |
| + if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Update("merge_asked", "").Error; err != nil { |
| + return err |
| + } |
| + s := stepRecord{Specialist: wire.SpecialistChecks, Person: p.eng.Person, Round: p.eng.Round, BaseSHA: k.BaseSHA, CandidateSHA: p.candidate, RecheckBy: runner} |
| + k.Stage = wire.StageInReview |
| + if err := t.nextStep(k, steps, s); err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| +} |
diff --git a/internal/equipo/chat/mergeauth.go b/internal/equipo/chat/mergeauth.go| index 43f2aa4f..1a48d356 100644 |
| --- a/internal/equipo/chat/mergeauth.go |
| +++ b/internal/equipo/chat/mergeauth.go |
| @@ -182,6 +182,9 @@ func (t *txn) mergeInputs(k taskRecord, p progress, person bool, protocol int) ( |
| if !p.moved { |
| in.Candidate = p.candidate |
| } |
| + // A pass from a Mac re-run (macrecheck.go) is judged like a merge |
| + // without checks, less the environment rule. |
| + in.Rechecked = p.checks != nil && p.checks.RecheckBy != "" |
| if r := p.review; r != nil && r.ChangeFacts != "" { |
| var f wire.ChangeFacts |
| if json.Unmarshal([]byte(r.ChangeFacts), &f) == nil && f.SHA == p.candidate { |
diff --git a/internal/equipo/chat/review.go b/internal/equipo/chat/review.go| index 319461b2..c019a211 100644 |
| --- a/internal/equipo/chat/review.go |
| +++ b/internal/equipo/chat/review.go |
| @@ -192,6 +192,10 @@ func (t *txn) advance(k *taskRecord) error { |
| if checks == wire.ChecksPassed { |
| k.MergeEligible = p.candidate |
| } |
| + } else if checks == wire.ChecksPassed && p.checks.RecheckBy != "" && k.MergeEligible != p.candidate { |
| + // Its checks waited for a Mac and passed there (macrecheck.go): |
| + // what passing at the first Ready would have granted. |
| + k.MergeEligible, ready = p.candidate, true |
| } |
| if ready { |
| if err := t.saveTask(k); err != nil { |
diff --git a/internal/equipo/chat/runner.go b/internal/equipo/chat/runner.go| index 3114e7db..3646113e 100644 |
| --- a/internal/equipo/chat/runner.go |
| +++ b/internal/equipo/chat/runner.go |
| @@ -95,7 +95,10 @@ func (s *Store) Connect(ctx context.Context, p RunnerPrincipal, process string, |
| return err |
| } |
| // A runner that fits may have come online. |
| - return t.placeWaiting(p.Person) |
| + if err := t.placeWaiting(p.Person); err != nil { |
| + return err |
| + } |
| + return t.recheckMac(p.Person, p.RunnerID) |
| }) |
| return lease, err |
| } |
| @@ -174,7 +177,10 @@ func (s *Store) Heartbeat(ctx context.Context, l Lease, hello wire.Hello) error |
| if err := t.runnerEvent(l.Runner.Person, r); err != nil { |
| return err |
| } |
| - return t.placeWaiting(l.Runner.Person) |
| + if err := t.placeWaiting(l.Runner.Person); err != nil { |
| + return err |
| + } |
| + return t.recheckMac(l.Runner.Person, l.Runner.RunnerID) |
| } |
| return nil |
| }) |
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go| index 36a1fc88..5cf64a95 100644 |
| --- a/internal/equipo/chat/runners.go |
| +++ b/internal/equipo/chat/runners.go |
| @@ -248,6 +248,12 @@ func (r runnerInfo) tags() []string { |
| return r.Hello.Capabilities.Tags |
| } |
| +// fits reports whether checks with needs, refused by those runners, may |
| +// be placed on r. |
| +func (r runnerInfo) fits(needs, refused []string) bool { |
| + return wire.Covers(r.tags(), needs) && !slices.Contains(refused, r.ID) && r.Protocol >= wire.Protocol2 && !r.Removing |
| +} |
| + |
| // runners are the person's unrevoked runners in enrolment order, with |
| // what each last said and how many steps it runs. |
| func (t *txn) runners(person string) ([]runnerInfo, error) { |
| @@ -464,7 +470,7 @@ func (t *txn) place(k *taskRecord, s *stepRecord) (placed bool, err error) { |
| if r.ID == primary && r.Protocol >= wire.Protocol2 { |
| relay = true |
| } |
| - if wire.Covers(r.tags(), needs) && !slices.Contains(refused, r.ID) && r.Protocol >= wire.Protocol2 && !r.Removing { |
| + if r.fits(needs, refused) { |
| fit = append(fit, r) |
| } |
| } |
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go| index 7a626c62..e6fd158a 100644 |
| --- a/internal/equipo/chat/tasks.go |
| +++ b/internal/equipo/chat/tasks.go |
| @@ -184,6 +184,9 @@ type stepRecord struct { |
| DecidedBy string |
| MergeSource string |
| MergeParents string |
| + // RecheckBy is the runner whose arrival ran these checks again, after |
| + // they waited for a Mac (macrecheck.go). Set only at creation. |
| + RecheckBy string |
| } |
| func (stepRecord) TableName() string { return "chat_steps" } |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index d2b27ca6..f5966759 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -1139,7 +1139,7 @@ var pageCopy = map[string]string{ |
| "work.chip.waiting_mac": "Waiting for a Mac to run checks", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "work.summary.waiting_mac": "Approved. Waiting for a Mac to run checks. You can merge now without checks.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "work.decide.mac_why": "Review approved. Checks need a Mac, and no Mac is set up to run them.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| - "work.decide.mac_hint": "Merge now merges it without checks. Wait for a Mac leaves it as it is. Once a Mac is set up, checks run on its next change, and if they pass, Equipo merges it by itself.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| + "work.decide.mac_hint": "Merge now merges it without checks. Wait for a Mac keeps it ready. Once a Mac is set up, checks run, and if they pass, Equipo merges it by itself.", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "work.decide.mac.merge": "Merge now", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "work.decide.mac.wait": "Wait for a Mac", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
| "work.decide.mac_set_up": "Set up a Mac", // COPY ACCEPTED BY DELEGATION (Astra, 2026-11-11) |
diff --git a/internal/equipo/mergegate/gate.go b/internal/equipo/mergegate/gate.go| index 3723b28c..d2fa67a0 100644 |
| --- a/internal/equipo/mergegate/gate.go |
| +++ b/internal/equipo/mergegate/gate.go |
| @@ -149,8 +149,14 @@ type Inputs struct { |
| // OutsideSandbox: the checks ran with checks_sandbox none. |
| OutsideSandbox bool |
| // Eligible: Candidate first earned Ready with checks passed (slice 4c's |
| - // merge_eligible). |
| + // merge_eligible), or its checks passed on a Mac re-run later. |
| Eligible bool |
| + // Rechecked: the checks that passed are a Mac re-run (mac-recheck) |
| + // for a candidate that first reached Ready unchecked. Such a pass is |
| + // judged like a merge without checks, less the environment rule: a |
| + // routine change merges on its own, a sensitive, large or shipping one |
| + // asks. |
| + Rechecked bool |
| // Person: the task's creator, a current owner, chose Merge for this |
| // SHA. |
| Person bool |
| @@ -216,13 +222,32 @@ func Decide(in Inputs) Decision { |
| protocol := Criterion{Name: CritProtocol, OK: in.Protocol >= MinProtocol} |
| policy := Criterion{Name: CritPolicy, OK: validPolicy && in.Policy.Mode == ModeRules, Value: in.Policy.Mode} |
| hold := Criterion{Name: CritHold, OK: in.Hold == ""} |
| - if in.Checks == wire.ChecksPassed { |
| + if in.Checks == wire.ChecksPassed && !in.Rechecked { |
| rs := []Criterion{approved, {Name: CritEligible, OK: in.Eligible}, {Name: CritSandbox, OK: !in.OutsideSandbox}, protocol, policy, hold} |
| return decided(rs, true, nil, []string{CritEligible, CritProtocol, CritPolicy}) |
| } |
| + var rs []Criterion |
| + if in.Checks == wire.ChecksPassed { |
| + rs = []Criterion{approved, {Name: CritEligible, OK: in.Eligible}, {Name: CritSandbox, OK: !in.OutsideSandbox}, protocol} |
| + } else { |
| + rs = []Criterion{approved, {Name: CritEnvironment, OK: in.Checks == wire.ChecksCannotRun && slices.Contains(environment, in.ChecksReason), Value: in.ChecksReason}, protocol} |
| + } |
| + rs, matches := changeCriteria(rs, in, validPolicy) |
| + rs = append(rs, policy, hold) |
| + if in.RevertSHA != "" { |
| + c := in.Change |
| + ok := c != nil && c.Complete && c.Revert != nil && c.Revert.SHA == in.RevertSHA && c.Revert.OnTop && c.Revert.Exact |
| + rs = append(rs, Criterion{Name: CritRevert, OK: ok}) |
| + } |
| + return decided(rs, in.Checks == wire.ChecksPassed, matches, []string{CritSmall, CritPolicy}) |
| +} |
| + |
| +// changeCriteria adds what the change itself must be to merge on its own: |
| +// measured, small, nothing sensitive, and main not a release. |
| +func changeCriteria(rs []Criterion, in Inputs, validPolicy bool) ([]Criterion, []Match) { |
| c := in.Change |
| facts := Criterion{Name: CritFacts, OK: c != nil && c.Complete} |
| - rs := []Criterion{approved, {Name: CritEnvironment, OK: in.Checks == wire.ChecksCannotRun && slices.Contains(environment, in.ChecksReason), Value: in.ChecksReason}, protocol, facts} |
| + rs = append(rs, facts) |
| var matches []Match |
| if facts.OK { |
| small := validPolicy && c.Lines <= in.Policy.MaxLines && c.Files <= in.Policy.MaxFiles && c.Binary == 0 |
| @@ -231,12 +256,7 @@ func Decide(in Inputs) Decision { |
| } else { |
| rs = append(rs, Criterion{Name: CritSmall}, Criterion{Name: CritSensitive}) |
| } |
| - rs = append(rs, Criterion{Name: CritShips, OK: validPolicy && in.Policy.MainShips == ShipsNo, Value: in.Policy.MainShips}, policy, hold) |
| - if in.RevertSHA != "" { |
| - ok := facts.OK && c.Revert != nil && c.Revert.SHA == in.RevertSHA && c.Revert.OnTop && c.Revert.Exact |
| - rs = append(rs, Criterion{Name: CritRevert, OK: ok}) |
| - } |
| - return decided(rs, false, matches, []string{CritSmall, CritPolicy}) |
| + return append(rs, Criterion{Name: CritShips, OK: validPolicy && in.Policy.MainShips == ShipsNo, Value: in.Policy.MainShips}), matches |
| } |
| // decided is act when every criterion holds, else ask; the stance is |
diff --git a/internal/equipo/mergegate/gate_test.go b/internal/equipo/mergegate/gate_test.go| index 38b44ae9..2b390f7e 100644 |
| --- a/internal/equipo/mergegate/gate_test.go |
| +++ b/internal/equipo/mergegate/gate_test.go |
| @@ -147,6 +147,34 @@ func TestDecideChecksPassedPath(t *testing.T) { |
| } |
| } |
| +// TestDecideRecheckedPass: checks that passed on a Mac re-run, for a |
| +// candidate that first reached Ready unchecked, merge on their own only |
| +// for a routine change: measured, small, nothing sensitive, main not a |
| +// release, no hold, the project not asking. |
| +func TestDecideRecheckedPass(t *testing.T) { |
| + in := passing() |
| + in.Checks, in.ChecksReason, in.Eligible, in.Rechecked = wire.ChecksPassed, "", true, true |
| + if d := Decide(in); d.Class != ClassAct || !d.Checks { |
| + t.Fatalf("routine re-run pass: %+v", d) |
| + } |
| + for name, change := range map[string]func(*Inputs){ |
| + CritSensitive: func(in *Inputs) { in.Change.Entries[0].New = "ios/StoreKit/Purchase.swift" }, |
| + CritShips: func(in *Inputs) { in.Policy.MainShips = ShipsYes }, |
| + CritSmall: func(in *Inputs) { in.Change.Lines = 5000 }, |
| + CritFacts: func(in *Inputs) { in.Change = nil }, |
| + CritHold: func(in *Inputs) { in.Hold = "device first" }, |
| + CritEligible: func(in *Inputs) { in.Eligible = false }, |
| + CritSandbox: func(in *Inputs) { in.OutsideSandbox = true }, |
| + } { |
| + in := passing() |
| + in.Checks, in.ChecksReason, in.Eligible, in.Rechecked = wire.ChecksPassed, "", true, true |
| + change(&in) |
| + if d := Decide(in); d.Class != ClassAsk || !slices.Contains(failing(d), name) { |
| + t.Errorf("%s: %+v", name, d) |
| + } |
| + } |
| +} |
| + |
| // TestDecidePersonMerge: a person's Merge acts on approved work whatever |
| // the policy, the hold or the runner say; never on unapproved work. |
| func TestDecidePersonMerge(t *testing.T) { |
| @@ -231,6 +259,7 @@ func TestDecideNeverLooser(t *testing.T) { |
| Hold: pick("", "", "", "careful"), |
| Policy: Policy{Mode: pick(ModeRules, ModeRules, ModeAsk, "loose"), MaxLines: rng.IntN(3000) - 500, MaxFiles: rng.IntN(200) - 20, MainShips: pick(ShipsNo, ShipsNo, ShipsYes, ShipsUnknown, "maybe")}, |
| RevertSHA: pick("", "", strings.Repeat("e", 40)), |
| + Rechecked: rng.IntN(3) == 0, |
| } |
| if rng.IntN(5) > 0 { |
| c := &wire.ChangeFacts{Complete: rng.IntN(6) > 0, Files: rng.IntN(30), Lines: rng.IntN(800), Binary: rng.IntN(3) / 2, Special: rng.IntN(8) == 0, Signing: rng.IntN(8) == 0} |
| @@ -255,6 +284,13 @@ func TestDecideNeverLooser(t *testing.T) { |
| if d.Class == ClassAct && d.Checks && (in.Checks != wire.ChecksPassed || !in.Eligible || in.OutsideSandbox || in.Protocol < wire.ProtocolMergeFacts || in.Policy.Mode != ModeRules) { |
| t.Fatalf("checked merge against the rule: %+v", in) |
| } |
| + if d.Class == ClassAct && d.Checks && in.Rechecked { |
| + unchecked := in |
| + unchecked.Checks, unchecked.ChecksReason = wire.ChecksCannotRun, "needs_macos" |
| + if !oracle(unchecked) { |
| + t.Fatalf("a re-run pass merged what the unchecked rule would not: %+v", in) |
| + } |
| + } |
| } |
| } |
diff --git a/internal/equipo/migrations/0060_thin_mac_recheck.sql b/internal/equipo/migrations/0060_thin_mac_recheck.sql| new file mode 100644 |
| index 00000000..1cdbed2a |
| --- /dev/null |
| +++ b/internal/equipo/migrations/0060_thin_mac_recheck.sql |
| @@ -0,0 +1 @@ |
| +ALTER TABLE chat_steps ADD COLUMN recheck_by text; |
diff --git a/internal/equipo/migrations/0060_thin_merge_authority.sql b/internal/equipo/migrations/0061_thin_merge_authority.sql| similarity index 100% |
| rename from internal/equipo/migrations/0060_thin_merge_authority.sql |
| rename to internal/equipo/migrations/0061_thin_merge_authority.sql |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index 4cd621be..d1a49444 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -598,7 +598,7 @@ CREATE INDEX chat_card_task ON chat_cards(task_id); |
| CREATE TABLE chat_project_attachments (project_id text, kind text, ref text, name text, created_at datetime, PRIMARY KEY (project_id, kind, ref)); |
| CREATE TABLE chat_tasks (id text PRIMARY KEY, project_id text, title text, brief text, stage text, branch text, base_sha text, creator text, turn_id text, cancel_requested numeric, revision integer, created_at datetime, updated_at datetime, watching text, moved_from text, branch_head text, merge_asked text, merged_sha text, merged_into text, merge_strategy text, merged_without_checks numeric, merged_at datetime, ready_sha text, merge_eligible text, done_at datetime, duplicate_of text, folded_into text, folded_stage text, folded_at datetime, engineering_runner text, merge_hold text, merge_verified numeric, revert_of text, revert_sha text); |
| CREATE INDEX chat_task_project ON chat_tasks(project_id); |
| -CREATE TABLE chat_steps (id text PRIMARY KEY, task_id text, idx integer, specialist text, person text, state text, reason text, attempt integer, base_sha text, candidate_sha text, pushed numeric, terminated numeric, summary text, log_tail text, started_at datetime, finished_at datetime, revision integer, created_at datetime, updated_at datetime, round integer, family text, account text, verdict text, review_label text, findings text, checks text, gate text, exit_code integer, output text, republish numeric, from_attempt integer, askable numeric, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, activity text, switched text, headline text, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text, apple numeric, checks_sandbox text, change_facts text, decided_by text, merge_source text, merge_parents text); |
| +CREATE TABLE chat_steps (id text PRIMARY KEY, task_id text, idx integer, specialist text, person text, state text, reason text, attempt integer, base_sha text, candidate_sha text, pushed numeric, terminated numeric, summary text, log_tail text, started_at datetime, finished_at datetime, revision integer, created_at datetime, updated_at datetime, round integer, family text, account text, verdict text, review_label text, findings text, checks text, gate text, exit_code integer, output text, republish numeric, from_attempt integer, askable numeric, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, activity text, switched text, headline text, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text, apple numeric, checks_sandbox text, recheck_by text, change_facts text, decided_by text, merge_source text, merge_parents text); |
| CREATE INDEX chat_step_task ON chat_steps(task_id); |
| CREATE TABLE chat_task_entries (id text PRIMARY KEY, task_id text, idempotency_key text, kind text, author text, text text, repo text, path text, line integer, created_at datetime, headline text, folded_from text); |
| CREATE INDEX chat_entry_task ON chat_task_entries(task_id); |
diff --git a/internal/thintest/macrecheck_contract_test.go b/internal/thintest/macrecheck_contract_test.go| new file mode 100644 |
| index 00000000..19f575e0 |
| --- /dev/null |
| +++ b/internal/thintest/macrecheck_contract_test.go |
| @@ -0,0 +1,267 @@ |
| +package thintest |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// waitingForMac runs an iOS change with no Mac enrolled to Ready to merge: |
| +// its checks end on the primary as not run (needs_macos), review |
| +// approves, and the merge card asks. It returns the task, its candidate |
| +// and the card. |
| +func (r *runnersRig) waitingForMac(title string) (task, sha string, card wire.Card) { |
| + r.t.Helper() |
| + task, sha = r.candidate(title, true) |
| + _, body := r.expect(wire.FrameDispatch) |
| + c := body.(*wire.DispatchCommand) |
| + if c.Specialist != wire.SpecialistChecks || c.TaskID != task || len(c.Needs) != 0 { |
| + r.t.Fatalf("checks on the primary %+v", c) |
| + } |
| + r.checks(task+"-c", c, wire.ChecksCannotRun, nil, "needs_macos", "") |
| + _, body = r.expect(wire.FrameDispatch) |
| + r.verdict(task+"-r", body.(*wire.DispatchCommand), wire.VerdictApprove) |
| + r.wait("waiting for a Mac", func(c *Conversation) bool { |
| + for _, k := range c.Cards { |
| + if k.Kind == wire.CardMerge && k.TaskID == task && c.Tasks[task].Stage == wire.StageReadyToMerge { |
| + card = k |
| + return true |
| + } |
| + } |
| + return false |
| + }) |
| + return task, sha, card |
| +} |
| + |
| +// checksRuns are the task's checks steps. |
| +func (r *runnersRig) checksRuns(task string) []wire.Step { |
| + r.t.Helper() |
| + k, err := r.client.Task(r.ctx, task) |
| + if err != nil { |
| + r.t.Fatal(err) |
| + } |
| + var out []wire.Step |
| + for _, s := range k.Steps { |
| + if s.Specialist == wire.SpecialistChecks { |
| + out = append(out, s) |
| + } |
| + } |
| + return out |
| +} |
| + |
| +// macRecheck reads the Mac's dispatch of a task's checks again, on sha. |
| +func macRecheck(t *testing.T, w *peer, task, sha string) *wire.DispatchCommand { |
| + t.Helper() |
| + _, body := w.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + if d.Specialist != wire.SpecialistChecks || d.TaskID != task || d.CandidateSHA != sha || d.Attempt != 1 || strings.Join(d.Needs, ",") != "macos,xcode" { |
| + t.Fatalf("checks again on the Mac %+v", d) |
| + } |
| + return d |
| +} |
| + |
| +// A task waiting for a Mac (Wait for a Mac on its card) gets its checks |
| +// again, on the exact candidate, the moment a Mac that fits enrols: once, |
| +// a reconnect places nothing more. They pass on the Mac (sandboxed), so |
| +// Equipo merges that SHA with no tap. |
| +func TestContractMacRecheckOnEnrol(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + project := r.project() |
| + // A routine change (measured by the review) that asked only because |
| + // nobody had said whether main ships; the owner says it doesn't. |
| + task, sha, _ := r.waitingForMacMeasured("Swipe back on iOS") |
| + r.shipsNo(project) |
| + card := r.cardOf(task) |
| + if out, err := r.client.Answer(r.ctx, card.ID, wire.ChoiceWaitMac, card.Revision); err != nil || out.Card.Choice != wire.ChoiceWaitMac { |
| + t.Fatalf("wait %+v %v", out, err) |
| + } |
| + w, _ := r.newWorker("Tito Studio") |
| + d := macRecheck(t, w, task, sha) |
| + if runs := r.checksRuns(task); len(runs) != 2 || runs[1].ID != d.StepID || runs[1].RunnerLabel != "Tito Studio" { |
| + t.Fatalf("checks runs %+v", runs) |
| + } |
| + w = r.reconnectPeer(w) |
| + w.none(wire.FrameDispatch, 200*time.Millisecond) |
| + if runs := r.checksRuns(task); len(runs) != 2 { |
| + t.Fatalf("a reconnect ran the checks again: %+v", runs) |
| + } |
| + r.relay(w, []byte("PACK swipe back")) |
| + if !w.lease(d.StepID, 1) { |
| + t.Fatal("start refused") |
| + } |
| + pass := passed(task, d.StepID, 1, sha) |
| + pass.ChecksSandbox = wire.SandboxSeatbelt |
| + w.send(wire.FrameStep, pass) |
| + _, body := r.expect(wire.FrameDispatch) |
| + if m := body.(*wire.DispatchCommand); m.Specialist != wire.SpecialistMerge || m.TaskID != task || m.CandidateSHA != sha { |
| + t.Fatalf("merge dispatch %+v", m) |
| + } |
| + if k, _ := r.client.Task(r.ctx, task); k.Stage != wire.StageMerging || k.Checks != wire.ChecksPassed { |
| + t.Fatalf("after the Mac's pass %+v", k) |
| + } |
| +} |
| + |
| +// Only tasks still waiting: a Linux runner enrolling places nothing; a |
| +// Mac enrolling skips cancelled tasks, merged ones, ones whose person |
| +// chose Merge (without checks, even back at Ready after the hub refused |
| +// it) and ones whose branch moved off the |
| +// candidate, and re-runs only the one still waiting (left with its card |
| +// open, which the run withdraws). |
| +func TestContractMacRecheckOnlyWaiting(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + waiting, sha, open := r.waitingForMac("Still waiting") |
| + cancelled, _, _ := r.waitingForMac("Cancelled one") |
| + if _, err := r.client.CancelTask(r.ctx, cancelled); err != nil { |
| + t.Fatal(err) |
| + } |
| + merged, _, mc := r.waitingForMac("Merged") |
| + if _, err := r.client.Answer(r.ctx, mc.ID, wire.ChoiceMerge, mc.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, body := r.expect(wire.FrameDispatch) |
| + r.mergedStep("merged-m", body.(*wire.DispatchCommand), strings.Repeat("f", 40)) |
| + chosen, _, cc := r.waitingForMac("Merge chosen") |
| + if _, err := r.client.Answer(r.ctx, cc.ID, wire.ChoiceMerge, cc.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, body = r.expect(wire.FrameDispatch) |
| + m := body.(*wire.DispatchCommand) |
| + if m.Specialist != wire.SpecialistMerge { |
| + t.Fatalf("merge chosen %+v", m) |
| + } |
| + // The hub refused it: back at Ready to merge, with Retry. |
| + r.step("chosen-m", wire.StepReport{TaskID: chosen, StepID: m.StepID, Attempt: 1, State: wire.StepFailed, Reason: "amadan_ci_pending", BaseSHA: m.BaseSHA, CandidateSHA: m.CandidateSHA, Termination: true}) |
| + moved, msha, _ := r.waitingForMac("Moved") |
| + if err := r.runner.Send(r.ctx, "moved-b", wire.FrameBranch, wire.BranchReport{TaskID: moved, CandidateSHA: msha, Head: strings.Repeat("9", 40)}); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.wait("ended or moved", func(c *Conversation) bool { |
| + return c.Tasks[moved].NeedsYou == wire.NeedsBranchMoved && c.Tasks[merged].Stage == wire.StageDone && c.Tasks[cancelled].Stage == wire.StageCancelled && c.Tasks[chosen].Stage == wire.StageReadyToMerge |
| + }) |
| + |
| + linux := WorkerHello(0) |
| + linux.Label, linux.Platform, linux.Sandbox = "Build box", &wire.Platform{OS: "linux", Arch: "amd64"}, wire.SandboxBubblewrap |
| + linux.Capabilities = &wire.Capabilities{Simulators: []wire.Simulator{}, Tags: []string{wire.TagLinux, wire.TagGo}} |
| + lr, err := DialRunnerHello(r.ctx, r.inst.URL, r.inst.EnrolRunner(t).Token, linux) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(lr.Close) |
| + (&peer{t: t, r: r.toolRig, fr: lr}).none(wire.FrameDispatch, 200*time.Millisecond) |
| + for _, id := range []string{waiting, cancelled, merged, chosen, moved} { |
| + if runs := r.checksRuns(id); len(runs) != 1 { |
| + t.Fatalf("a Linux runner re-ran %s's checks: %+v", id, runs) |
| + } |
| + } |
| + |
| + w, _ := r.newWorker("Tito Studio") |
| + macRecheck(t, w, waiting, sha) |
| + w.none(wire.FrameDispatch, 200*time.Millisecond) |
| + for _, id := range []string{cancelled, merged, chosen, moved} { |
| + if runs := r.checksRuns(id); len(runs) != 1 { |
| + t.Fatalf("checks of %s re-ran: %+v", id, runs) |
| + } |
| + } |
| + r.wait("card withdrawn", func(c *Conversation) bool { return c.Cards[open.ID].State == wire.CardResolved }) |
| +} |
| + |
| +// The run follows the usual paths: ending not run again on the Mac |
| +// (needs_macos) asks the card afresh, and that Mac reconnecting runs |
| +// nothing (once per candidate per enrolment); another Mac enrolling runs |
| +// them once more, and checks that fail send Engineering its fix round. |
| +func TestContractMacRecheckOutcomes(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + task, sha, _ := r.waitingForMac("Swipe back on iOS") |
| + a, _ := r.newWorker("Mac A") |
| + d := macRecheck(t, a, task, sha) |
| + r.relay(a, []byte("PACK a")) |
| + if !a.lease(d.StepID, 1) { |
| + t.Fatal("start refused") |
| + } |
| + a.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepDone, Reason: "needs_macos", CandidateSHA: sha, Checks: wire.ChecksCannotRun, Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + var card wire.Card |
| + r.wait("asked again", func(c *Conversation) bool { |
| + for _, k := range c.Cards { |
| + if k.Kind == wire.CardMerge && k.TaskID == task && k.State == wire.CardOpen { |
| + card = k |
| + } |
| + } |
| + return card.ID != "" && c.Tasks[task].Stage == wire.StageReadyToMerge |
| + }) |
| + a = r.reconnectPeer(a) |
| + a.none(wire.FrameDispatch, 200*time.Millisecond) |
| + if runs := r.checksRuns(task); len(runs) != 2 { |
| + t.Fatalf("the same Mac reconnecting re-ran them: %+v", runs) |
| + } |
| + // Mac A away, so placement takes the newcomer. |
| + a.fr.Close() |
| + time.Sleep(100 * time.Millisecond) |
| + b, _ := r.newWorker("Mac B") |
| + _, body := b.expect(wire.FrameDispatch) |
| + d2 := body.(*wire.DispatchCommand) |
| + if d2.TaskID != task || d2.CandidateSHA != sha || d2.StepID == d.StepID { |
| + t.Fatalf("second Mac's checks %+v", d2) |
| + } |
| + r.relay(b, []byte("PACK b")) |
| + if !b.lease(d2.StepID, 1) { |
| + t.Fatal("start refused") |
| + } |
| + one := 1 |
| + b.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d2.StepID, Attempt: 1, State: wire.StepDone, CandidateSHA: sha, Checks: wire.ChecksFailed, Gate: "xcodebuild test", ExitCode: &one, Output: "** TEST FAILED **", ChecksSandbox: wire.SandboxSeatbelt, Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + _, body = r.expect(wire.FrameDispatch) |
| + if e := body.(*wire.DispatchCommand); e.Specialist != wire.SpecialistEngineering || e.TaskID != task || e.Round != 1 { |
| + t.Fatalf("fix round %+v", e) |
| + } |
| +} |
| + |
| +// A Mac that comes back online (a heartbeat after it was offline) runs |
| +// the waiting checks too, once: it connected before its capability report |
| +// was in (no tags, so nothing then), went quiet, and says hello as a Mac. |
| +// Even with those checks ended not run again, its coming back again, or |
| +// reconnecting, runs nothing more. |
| +func TestContractMacRecheckBackOnline(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + task, sha, _ := r.waitingForMac("Swipe back on iOS") |
| + token := r.inst.EnrolRunner(t).Token |
| + bare := WorkerHello(0) |
| + bare.Capabilities = nil |
| + fr, err := DialRunnerHello(r.ctx, r.inst.URL, token, bare) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(fr.Close) |
| + w := &peer{t: t, r: r.toolRig, fr: fr} |
| + w.none(wire.FrameDispatch, 200*time.Millisecond) |
| + if runs := r.checksRuns(task); len(runs) != 1 { |
| + t.Fatalf("a runner with no tags re-ran the checks: %+v", runs) |
| + } |
| + clock := time.Now().UTC() |
| + r.inst.Store.Chat().SetClock(func() time.Time { return clock }) |
| + back := func() { |
| + clock = clock.Add(2 * time.Minute) |
| + w.heartbeat(WorkerHello(0)) |
| + } |
| + back() |
| + d := macRecheck(t, w, task, sha) |
| + r.relay(w, []byte("PACK swipe back")) |
| + if !w.lease(d.StepID, 1) { |
| + t.Fatal("start refused") |
| + } |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepDone, Reason: "needs_macos", CandidateSHA: sha, Checks: wire.ChecksCannotRun, Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + r.wait("ready again", func(c *Conversation) bool { return c.Tasks[task].Stage == wire.StageReadyToMerge }) |
| + back() |
| + w.none(wire.FrameDispatch, 200*time.Millisecond) |
| + fr.Close() |
| + time.Sleep(100 * time.Millisecond) |
| + again, err := DialRunnerHello(r.ctx, r.inst.URL, token, WorkerHello(fr.Welcome.Generation)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(again.Close) |
| + (&peer{t: t, r: r.toolRig, fr: again}).none(wire.FrameDispatch, 200*time.Millisecond) |
| + if runs := r.checksRuns(task); len(runs) != 2 { |
| + t.Fatalf("coming back again re-ran the checks: %+v", runs) |
| + } |
| +} |
diff --git a/internal/thintest/macrecheck_mergeauth_contract_test.go b/internal/thintest/macrecheck_mergeauth_contract_test.go| new file mode 100644 |
| index 00000000..097f1d23 |
| --- /dev/null |
| +++ b/internal/thintest/macrecheck_mergeauth_contract_test.go |
| @@ -0,0 +1,129 @@ |
| +package thintest |
| + |
| +import ( |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// waitingForMacMeasured is waitingForMac with the review reporting what |
| +// the change is (paths), on a primary that speaks wire.ProtocolMergeFacts. |
| +func (r *runnersRig) waitingForMacMeasured(title string, paths ...string) (task, sha string, card wire.Card) { |
| + r.t.Helper() |
| + task, sha = r.candidate(title, true) |
| + _, body := r.expect(wire.FrameDispatch) |
| + c := body.(*wire.DispatchCommand) |
| + if c.Specialist != wire.SpecialistChecks || c.TaskID != task { |
| + r.t.Fatalf("checks on the primary %+v", c) |
| + } |
| + r.checks(task+"-c", c, wire.ChecksCannotRun, nil, "needs_macos", "") |
| + _, body = r.expect(wire.FrameDispatch) |
| + rv := body.(*wire.DispatchCommand) |
| + r.step(task+"-r", wire.StepReport{TaskID: rv.TaskID, StepID: rv.StepID, Attempt: rv.Attempt, State: wire.StepDone, BaseSHA: rv.BaseSHA, CandidateSHA: rv.CandidateSHA, Termination: true, Family: "codex", Account: "codex-a", Verdict: wire.VerdictApprove, ReviewLabel: wire.ReviewOtherFamily, Findings: []wire.Finding{}, Summary: "Read it.", Change: facts(rv, paths...)}) |
| + card = r.mergeCardsWait(task) |
| + return task, sha, card |
| +} |
| + |
| +// recheckPasses enrols a Mac, which runs the task's checks again on sha, |
| +// and reports them passed (sandboxed) on reported (sha, or another). |
| +func (r *runnersRig) recheckPasses(task, sha, reported string) { |
| + r.t.Helper() |
| + w, _ := r.newWorker("Tito Studio") |
| + d := macRecheck(r.t, w, task, sha) |
| + r.relay(w, []byte("PACK "+task)) |
| + if !w.lease(d.StepID, 1) { |
| + r.t.Fatal("start refused") |
| + } |
| + pass := passed(task, d.StepID, 1, reported) |
| + pass.ChecksSandbox = wire.SandboxSeatbelt |
| + w.send(wire.FrameStep, pass) |
| +} |
| + |
| +// TestContractMacRecheckMergeAuthority: a Mac re-run that passes on the |
| +// exact candidate counts as that SHA's checks, and the merge it allows |
| +// still goes through authorizeMerge: a routine change merges on its own |
| +// (Equipo's decision, confirmed again at the hub request); a sensitive |
| +// change asks; a held one, or one whose main ships, asks; a pass on |
| +// another SHA counts for nothing. |
| +func TestContractMacRecheckMergeAuthority(t *testing.T) { |
| + t.Run("routine", func(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + project := r.project() |
| + // It asks first only because nobody has said whether main ships; |
| + // the owner then says it doesn't, and Waits for a Mac. |
| + task, sha, _ := r.waitingForMacMeasured("Swipe back") |
| + r.shipsNo(project) |
| + card := r.cardOf(task) |
| + if _, err := r.client.Answer(r.ctx, card.ID, wire.ChoiceWaitMac, card.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.recheckPasses(task, sha, sha) |
| + _, body := r.expect(wire.FrameDispatch) |
| + m := body.(*wire.DispatchCommand) |
| + if m.Specialist != wire.SpecialistMerge || m.CandidateSHA != sha { |
| + t.Fatalf("merge dispatch %+v", m) |
| + } |
| + if refused := r.lease(r.runner, "routine-confirm", wire.LeaseCheck{StepID: m.StepID, Attempt: m.Attempt, Purpose: wire.LeasePurposeMerge}); refused != "" { |
| + t.Fatalf("the request refused %q", refused) |
| + } |
| + if k, _ := r.client.Task(r.ctx, task); k.MergeDecision == nil || k.MergeDecision.Class != "act" || k.MergeDecision.DecidedBy != "policy" { |
| + t.Fatalf("decision %+v", k.MergeDecision) |
| + } |
| + }) |
| + asks := func(t *testing.T, r *runnersRig, task, sha, want string) { |
| + t.Helper() |
| + r.primary.none(wire.FrameDispatch, 300*time.Millisecond) |
| + card := r.mergeCardsWait(task) |
| + if !strings.Contains(card.Question, want) { |
| + t.Fatalf("card %q, want %q", card.Question, want) |
| + } |
| + if k, _ := r.client.Task(r.ctx, task); k.Stage != wire.StageReadyToMerge || k.CandidateSHA != sha || k.MergeDecision == nil || k.MergeDecision.Class != "ask" { |
| + t.Fatalf("after the pass %+v", k.MergeDecision) |
| + } |
| + } |
| + t.Run("sensitive", func(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + r.shipsNo(r.project()) |
| + task, sha, card := r.waitingForMacMeasured("Pay wall", "ios/Woodstar/StoreKit/Purchase.swift") |
| + if _, err := r.client.Answer(r.ctx, card.ID, wire.ChoiceWaitMac, card.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.recheckPasses(task, sha, sha) |
| + asks(t, r, task, sha, "it touches payments") |
| + }) |
| + t.Run("held", func(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + project := r.project() |
| + task, sha, _ := r.waitingForMacMeasured("Edge pan") |
| + if res := r.call("held-hold", wire.ToolHoldMerge, map[string]string{"task": task, "reason": "the person wants to try it on a device first"}); res.IsError { |
| + t.Fatalf("hold %+v", res) |
| + } |
| + r.shipsNo(project) |
| + r.recheckPasses(task, sha, sha) |
| + asks(t, r, task, sha, "the person wants to try it on a device first") |
| + }) |
| + t.Run("ships", func(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + project := r.project() |
| + p, _ := r.client.MergePolicy(r.ctx, project) |
| + if _, err := r.client.SetMergePolicy(r.ctx, project, wire.SetMergePolicy{Mode: p.Mode, MaxLines: p.MaxLines, MaxFiles: p.MaxFiles, MainShips: "yes", ExtraSensitive: p.ExtraSensitive, Revision: p.Revision}); err != nil { |
| + t.Fatal(err) |
| + } |
| + task, sha, _ := r.waitingForMacMeasured("Tab bar") |
| + r.recheckPasses(task, sha, sha) |
| + asks(t, r, task, sha, "main ships to users") |
| + }) |
| + t.Run("other SHA", func(t *testing.T) { |
| + r := newRunnersRigAt(t, wire.ProtocolMergeFacts) |
| + project := r.project() |
| + task, sha, _ := r.waitingForMacMeasured("Scroll") |
| + r.shipsNo(project) |
| + r.recheckPasses(task, sha, strings.Repeat("0", 40)) |
| + r.primary.none(wire.FrameDispatch, 300*time.Millisecond) |
| + if k, _ := r.client.Task(r.ctx, task); k.Stage == wire.StageMerging || k.Checks == wire.ChecksPassed { |
| + t.Fatalf("a pass on another SHA counted %+v", k) |
| + } |
| + }) |
| +} |
diff --git a/internal/thintest/placement_contract_test.go b/internal/thintest/placement_contract_test.go| index d14378b6..720d7eee 100644 |
| --- a/internal/thintest/placement_contract_test.go |
| +++ b/internal/thintest/placement_contract_test.go |
| @@ -161,16 +161,22 @@ type runnersRig struct { |
| creds map[*FakeRunner][2]string |
| } |
| -func newRunnersRig(t *testing.T) *runnersRig { |
| +func newRunnersRig(t *testing.T) *runnersRig { return newRunnersRigAt(t, wire.Protocol2) } |
| + |
| +// newRunnersRigAt is the runners rig with its primary at protocol |
| +// (wire.ProtocolMergeFacts where Equipo should merge on its own). |
| +func newRunnersRigAt(t *testing.T, protocol int) *runnersRig { |
| r := newToolRig(t) |
| gen := r.runner.Welcome.Generation |
| r.runner.Close() |
| - p, err := DialRunnerHello(r.ctx, r.inst.URL, r.rig.runner, primaryHello(gen)) |
| + h := primaryHello(gen) |
| + h.Protocol = protocol |
| + p, err := DialRunnerHello(r.ctx, r.inst.URL, r.rig.runner, h) |
| if err != nil { |
| t.Fatal(err) |
| } |
| t.Cleanup(p.Close) |
| - if p.Welcome.Role != wire.RolePrimary || p.Welcome.Protocol != wire.Protocol2 { |
| + if p.Welcome.Role != wire.RolePrimary || p.Welcome.Protocol != protocol { |
| t.Fatalf("primary welcome %+v", p.Welcome) |
| } |
| r.runner = p |
diff --git a/internal/thintest/projects_pages_test.go b/internal/thintest/projects_pages_test.go| index 3d3d1d05..1d00c13c 100644 |
| --- a/internal/thintest/projects_pages_test.go |
| +++ b/internal/thintest/projects_pages_test.go |
| @@ -252,7 +252,7 @@ func TestPagesTaskDecisionsSayWhy(t *testing.T) { |
| card := regexp.MustCompile(`(?s)<div equipo-decision[^>]*data-decision="` + g.unchecked + `">.*?</div>\n</div>`).FindString(needs) |
| for _, want := range []string{"Review approved. Checks need a Mac, and no Mac is set up to run them.", "Merge without checks?", |
| `data-merge-choice="merge">Merge now</button>`, `data-merge-choice="wait_mac">Wait for a Mac</button>`, |
| - "Merge now merges it without checks. Wait for a Mac leaves it as it is. Once a Mac is set up, checks run on its next change, and if they pass, Equipo merges it by itself.", |
| + "Merge now merges it without checks. Wait for a Mac keeps it ready. Once a Mac is set up, checks run, and if they pass, Equipo merges it by itself.", |
| `<a equipo-link href="/runners/enrol" data-set-up-mac>Set up a Mac</a>`, `href="/conversation?about=` + g.unchecked + `" data-ask-about>Ask about this</a>`} { |
| if !strings.Contains(card, want) { |
| t.Fatalf("Mac decision lacks %q:\n%s", want, card) |