Mac slice F task 3: Mac Engineering placed on a worker, base first
Behind EQUIPO_MAC_ENGINEERING=1 (unset: mac-placement-wait unchanged), Engineering for Mac work goes to a Mac worker. Engineering needs claude. Candidates: the pinned worker alone, else the Macs in the 1.4 order. Both runners must speak 37 (waiting_mac_update, naming which). A Mac without claude waits as waiting_mac_connection (its status is read when rendered, Step.engineering_status). An offline Mac is waited for, with Needs you runner_offline after 30 minutes. A pinned Mac that lost a tag is waited for, never replaced; a removed pin re-pins to a Mac or waits, never the Linux primary. Base in two transactions: prepare_base to the primary (waiting_base), then its base report, from the primary's connection for the current attempt, binds the base and dispatches with the inbound Engineering transfer in one transaction. Other reports are refused and logged; base_unavailable ends the attempt with Retry. Fix rounds, Retry and republish skip phase 1. Xcode access only for a sandbox-proven, untainted Mac with F5 denied. Review stays on the primary; a Mac-made candidate never merges by policy (made_on_primary). Fixes advance starting a fix round while a worker's commit awaited publication. 14 pending copy drafts. Tests: mac_engineering_contract_test.go (15 contracts), gate, config and view tests; six brief mutations and 13 more each fail a named test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 files changed,
+1,733
−147
.rastrillo/budgets.txt+3 −3docs/api/equipo-v1.openapi.json+3 −0docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json+72 −0docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+14 −0internal/equipo/app.go+1 −0internal/equipo/chat/base_prepare.go+177 −0internal/equipo/chat/explore.go+3 −1internal/equipo/chat/macsandbox.go+51 −3internal/equipo/chat/mergeauth.go+10 −0internal/equipo/chat/review.go+4 −1internal/equipo/chat/runner.go+7 −1internal/equipo/chat/runners.go+239 −65internal/equipo/chat/store.go+7 −0internal/equipo/chat/stream.go+1 −1internal/equipo/chat/tasks.go+30 −4internal/equipo/config.go+5 −0internal/equipo/copy.go+16 −0internal/equipo/mac_engineering_config_test.go+18 −0internal/equipo/mac_engineering_view_test.go+47 −0internal/equipo/mergegate/gate.go+17 −2internal/equipo/mergegate/mac_made_test.go+34 −0internal/equipo/work_pages.go+5 −0internal/equipo/work_views.go+17 −2internal/thintest/instance.go+3 −1internal/thintest/mac_engineering_contract_test.go+931 −0internal/thintest/review1_contract_test.go+0 −33internal/thintest/transfer_contract_test.go+12 −30internal/wire/tasks.go+6 −0
Intent
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 2244870f..bd5305da 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 23946 - Preview grants, retry/timeline, no-access merges, kept work, check-db copy, notification actions, places page and its superseded card, GitHub owner routes, Mac waits; measured 23946. |
| +size internal/equipo 23988 - Preview grants, retry/timeline, no-access merges, kept work, check-db copy, notification actions, places page and its superseded card, GitHub owner routes, Mac waits; measured 23988. |
| size internal/wire 8590 - Protocol 31 facts, 32 unfinished work, task evidence, CI units, notification inputs, 33 Assistant files, 34 places, 35 diffs, Mac waits, 37 Mac Engineering; measured 8590. |
| size internal/equipotest - 12683 GitHub connect value search, lifecycle and sweep-log contracts; Task 21 migration fixtures and Rastrillo asset contract; measured 0/12683 source/test lines. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
| @@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device |
| perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen. |
| -size internal/equipo/chat 38141 12096 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places, waiting cards, Mac waits, 0120 storage; measured 38141/12096. |
| +size internal/equipo/chat 38586 12096 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places, waiting cards, Mac waits, Mac Engineering; measured 38586/12096. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
| @@ -71,7 +71,7 @@ perf GET /tasks/{id}/files/{file} skip Research kept images: the bytes of one im |
| perf GET /api/v1/runners skip Mac runners person API: bearer-only JSON for devices; the browser shows runners in the Team section. |
| time cmd/equipo-runner 60s TestReleaseRunnerHasNoFakeWorker builds the release runner and the thin package under testbuild (about 12s locally). |
| size internal/headless - 11977 Grant scenarios (#48); sign-in email at 1280 and 390; Assistant files end to end; the restart wait; the live site waits for a place; a card answer settles at the bottom; measured 11977 test lines. |
| -size internal/thintest - 37223 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places and where their cards land, Mac waits; measured 37223. |
| +size internal/thintest - 38103 Protocol 31 contracts, 35 diffs, stuck tasks, no-access merges, held retries, unfinished work, free rounds, previews, Assistant files, places, Mac waits, Mac Engineering; measured 38103. |
| perf GET /api/v1/projects/{id}/merge-policy skip Merge authority person API: bearer-only JSON for devices; the browser reads the policy on /projects/{id}. |
| perf GET /api/v1/usage skip Thin v1 person API: bearer-only JSON for devices; the browser reads usage through /usage. |
diff --git a/docs/api/equipo-v1.openapi.json b/docs/api/equipo-v1.openapi.json| index 1b2e19a8..ac00d28b 100644 |
| --- a/docs/api/equipo-v1.openapi.json |
| +++ b/docs/api/equipo-v1.openapi.json |
| @@ -22680,6 +22680,9 @@ |
| "runner_label": { |
| "type": "string" |
| }, |
| + "engineering_status": { |
| + "$ref": "#/components/schemas/EngineeringStatus" |
| + }, |
| "needs": { |
| "type": [ |
| "array", |
diff --git a/docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json b/docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json| new file mode 100644 |
| index 00000000..7e591c32 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-28-mac-slice-f-copy.json |
| @@ -0,0 +1,72 @@ |
| +[ |
| + { |
| + "key": "work.needs.mac_connection", |
| + "where": "Task line (Needs you), Mac Engineering waiting for a Mac's Claude connection; %s is the Mac", |
| + "draft": "Needs you: %s needs Claude to make this change" |
| + }, |
| + { |
| + "key": "work.needs.mac_update", |
| + "where": "Task line (Needs you), Mac Engineering waiting for an update; %s is the Mac or the main runner", |
| + "draft": "Needs you: %s needs an update to make changes" |
| + }, |
| + { |
| + "key": "work.decide.mac_connection_why.no_connection", |
| + "where": "Task decision card, why (waiting_mac_connection, Mac Engineering status no_connection); %s is the Mac", |
| + "draft": "This change needs a Mac. %s is ready, but it has no Claude connection yet." |
| + }, |
| + { |
| + "key": "work.decide.mac_connection_why.signed_out", |
| + "where": "Task decision card, why (waiting_mac_connection, Mac Engineering status signed_out); %s is the Mac", |
| + "draft": "This change needs a Mac. Claude on %s is signed out and needs signing in again." |
| + }, |
| + { |
| + "key": "work.decide.mac_connection_why.limited", |
| + "where": "Task decision card, why (waiting_mac_connection, Mac Engineering status limited); %s is the Mac", |
| + "draft": "This change needs a Mac. Claude on %s has reached its usage limit for now." |
| + }, |
| + { |
| + "key": "work.decide.mac_connection_why.probes_pending", |
| + "where": "Task decision card, why (waiting_mac_connection, Mac Engineering status probes_pending); %s is the Mac", |
| + "draft": "This change needs a Mac. %s is still checking that Claude runs safely there." |
| + }, |
| + { |
| + "key": "work.decide.mac_connection_why.probes_failed", |
| + "where": "Task decision card, why (waiting_mac_connection, Mac Engineering status probes_failed); %s is the Mac", |
| + "draft": "This change needs a Mac. %s couldn’t show that Claude runs safely there." |
| + }, |
| + { |
| + "key": "work.decide.mac_connection_why.cli_unpinned", |
| + "where": "Task decision card, why (waiting_mac_connection, Mac Engineering status cli_unpinned); %s is the Mac", |
| + "draft": "This change needs a Mac. %s doesn’t have the approved version of Claude Code yet." |
| + }, |
| + { |
| + "key": "work.decide.mac_connection_why.home_open", |
| + "where": "Task decision card, why (waiting_mac_connection, Mac Engineering status home_open); %s is the Mac", |
| + "draft": "This change needs a Mac. Other people on %s can open the runner’s home folder, so Claude can’t be used there yet." |
| + }, |
| + { |
| + "key": "work.decide.mac_connection_why.tainted", |
| + "where": "Task decision card, why (waiting_mac_connection, Mac Engineering status tainted); %s is the Mac", |
| + "draft": "This change needs a Mac. %s once ran checks outside the sandbox, so it can’t hold a Claude connection." |
| + }, |
| + { |
| + "key": "work.decide.mac_update_why", |
| + "where": "Task decision card, why (waiting_mac_update); %s is the runner that needs the update", |
| + "draft": "This change needs a Mac. %s needs an update before the change can be made there." |
| + }, |
| + { |
| + "key": "work.decide.mac_wait_ask", |
| + "where": "Task decision card, ask, for both Mac Engineering waits; %s is the Mac or main runner", |
| + "draft": "It starts by itself once %s is ready. You can also cancel it." |
| + }, |
| + { |
| + "key": "work.reason.base_unavailable", |
| + "where": "Step stop reason: the main runner could not resolve the base for an attempt on a Mac (Needs you: Try again)", |
| + "draft": "the main runner couldn’t get the version of the project to start from" |
| + }, |
| + { |
| + "key": "chat.merge.not.mac_made", |
| + "where": "Merge card, why Equipo did not merge on its own: the candidate was made on a Mac runner", |
| + "draft": "it was made on a Mac runner, so it merges only when you choose" |
| + } |
| +] |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index b908a7a7..be492776 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -7005,6 +7005,20 @@ records remain unchanged. |
| | `work.decide.mac_engineering_ask` | Leave it waiting, or cancel it. | Copy specialist | COPY REVIEW PENDING | |
| | `work.waits.mac_runner` | It needs a Mac runner | Copy specialist | COPY REVIEW PENDING | |
| | `work.waits.mac_engineering` | It needs a Mac that can make changes | Copy specialist | COPY REVIEW PENDING | |
| +| `work.needs.mac_connection` | Needs you: %s needs Claude to make this change | Copy specialist | COPY REVIEW PENDING | |
| +| `work.needs.mac_update` | Needs you: %s needs an update to make changes | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_connection_why.no_connection` | This change needs a Mac. %s is ready, but it has no Claude connection yet. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_connection_why.signed_out` | This change needs a Mac. Claude on %s is signed out and needs signing in again. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_connection_why.limited` | This change needs a Mac. Claude on %s has reached its usage limit for now. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_connection_why.probes_pending` | This change needs a Mac. %s is still checking that Claude runs safely there. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_connection_why.probes_failed` | This change needs a Mac. %s couldn’t show that Claude runs safely there. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_connection_why.cli_unpinned` | This change needs a Mac. %s doesn’t have the approved version of Claude Code yet. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_connection_why.home_open` | This change needs a Mac. Other people on %s can open the runner’s home folder, so Claude can’t be used there yet. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_connection_why.tainted` | This change needs a Mac. %s once ran checks outside the sandbox, so it can’t hold a Claude connection. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_update_why` | This change needs a Mac. %s needs an update before the change can be made there. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.decide.mac_wait_ask` | It starts by itself once %s is ready. You can also cancel it. | Copy specialist | COPY REVIEW PENDING | |
| +| `work.reason.base_unavailable` | the main runner couldn’t get the version of the project to start from | Copy specialist | COPY REVIEW PENDING | |
| +| `chat.merge.not.mac_made` | it was made on a Mac runner, so it merges only when you choose | Copy specialist | COPY REVIEW PENDING | |
| ## Task 21 |
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 6df0a879..c856059c 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -195,6 +195,7 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg |
| // The push outbox is written only where a sender will drain it. |
| store.Chat().SetPush(cfg.Push != nil) |
| store.Chat().SetNotificationActions(cfg.NotificationActions) |
| + store.Chat().SetMacEngineering(cfg.MacEngineering) |
| // What the Assistant's provider calls could not do, by call id only. |
| store.Chat().SetLogger(logger) |
| if cfg.OficinaConnectOrigin != "" { |
diff --git a/internal/equipo/chat/base_prepare.go b/internal/equipo/chat/base_prepare.go| new file mode 100644 |
| index 00000000..3b0580bd |
| --- /dev/null |
| +++ b/internal/equipo/chat/base_prepare.go |
| @@ -0,0 +1,177 @@ |
| +package chat |
| + |
| +import ( |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "strings" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "gorm.io/gorm" |
| +) |
| + |
| +// Base preparation (Mac runners spec §8.4, slice F). A worker has no |
| +// clone and no forge access, so the base an Engineering attempt on it |
| +// starts from is resolved by the primary, in two transactions: |
| +// |
| +// 1. placement chose a worker and the attempt has no bound base (a first |
| +// step, or a rebase round whose new tip is unknown): prepare_base goes |
| +// to the primary's mailbox and the attempt waits (waiting_base), |
| +// placed nowhere; |
| +// 2. the primary's base report for that attempt, from the primary's own |
| +// connection, binds the base to the attempt; in the same transaction |
| +// the attempt is placed again and, on a worker, dispatched with its |
| +// inbound Engineering transfer (dispatchStep). |
| +// |
| +// A fix round starts from the task branch's published tip, which is |
| +// known, so it skips phase 1; so do a Retry and a republish, which run |
| +// from the base the step already has. A report for anything else is |
| +// refused and logged. |
| + |
| +// boundBase is the base an Engineering attempt starts from, "" when none |
| +// is bound yet: the step's own, else (not a rebase round) the task's. |
| +func boundBase(k taskRecord, s stepRecord) string { |
| + if s.BaseSHA == "" && !s.Rebase { |
| + return k.BaseSHA |
| + } |
| + return s.BaseSHA |
| +} |
| + |
| +// prepareBase is phase 1 for the attempt placement put on worker |
| +// d.runner: the attempt waits for its base (placed nowhere, the Mac it is |
| +// for named), and the primary is asked once for this attempt. The caller |
| +// saves s. |
| +func (t *txn) prepareBase(k *taskRecord, s *stepRecord, primary string, d engineeringPlacement) error { |
| + if _, err := t.waitForMac(s, d.needs, wire.PlacementBase); err != nil { |
| + return err |
| + } |
| + s.SandboxRunner = d.runner |
| + var p projectRecord |
| + if err := t.db.Where("id = ?", k.ProjectID).First(&p).Error; err != nil { |
| + return err |
| + } |
| + cmd := wire.PrepareBaseCommand{TaskID: k.ID, StepID: s.ID, Attempt: s.Attempt, Repo: p.Repo} |
| + if s.Rebase { |
| + cmd.Rebase, cmd.FromBase, cmd.CandidateSHA = true, s.FromBase, s.FromCandidate |
| + } |
| + if !cmd.Valid() { |
| + // Nothing a primary could resolve (a rebase round without its old |
| + // base): the attempt ends as the primary would have ended it. |
| + baseUnavailable(t, s) |
| + return nil |
| + } |
| + var asked int64 |
| + if err := t.db.Model(&commandRecord{}).Where("runner_id = ? AND kind = ? AND body LIKE ?", primary, wire.FramePrepareBase, attemptLike(s.ID, s.Attempt)).Count(&asked).Error; err != nil || asked > 0 { |
| + return err |
| + } |
| + return t.commandTo(primary, s.Person, wire.FramePrepareBase, cmd) |
| +} |
| + |
| +// attemptLike matches the JSON of a command naming step's attempt. |
| +func attemptLike(step string, attempt int64) string { |
| + return `%"step_id":"` + step + `","attempt":` + itoa64(attempt) + `,%` |
| +} |
| + |
| +// baseUnavailable ends the attempt failed (base_unavailable): nothing |
| +// ran, so its end is proven; Needs you retry. |
| +func baseUnavailable(t *txn, s *stepRecord) { |
| + now := t.now() |
| + s.State, s.Reason, s.Terminated, s.FinishedAt = wire.StepFailed, wire.ReasonBaseUnavailable, true, &now |
| + s.Placement, s.WaitingSince, s.SandboxRunner, s.RunnerID = "", nil, "", "" |
| +} |
| + |
| +// errBaseRefused refuses a base report: logged, acked, no effect. |
| +func errBaseRefused(why string) error { |
| + return fmt.Errorf("%w: base_refused: %s", ErrRefused, why) |
| +} |
| + |
| +// base is phase 2: the primary's answer to prepare_base. Only from the |
| +// person's primary, for the Engineering attempt that is current, not |
| +// withdrawn, of a task neither cancelled nor ended. A second report for |
| +// an attempt no longer waiting for its base does nothing. |
| +func (t *txn) base(l Lease, v *wire.BaseReport) error { |
| + if !v.Valid() { |
| + return errBaseRefused("invalid report") |
| + } |
| + primary, err := t.s.authority.PrimaryRunner(t.db, l.Runner.Person) |
| + if err != nil { |
| + return err |
| + } |
| + if primary == "" || primary != l.Runner.RunnerID { |
| + return errBaseRefused("not the primary") |
| + } |
| + var s stepRecord |
| + if err := t.db.Where("id = ? AND task_id = ? AND person = ?", v.StepID, v.TaskID, l.Runner.Person).First(&s).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return errBaseRefused("no such step") |
| + } else if err != nil { |
| + return err |
| + } |
| + k, err := t.loadTask(s.TaskID) |
| + if err != nil { |
| + return err |
| + } |
| + if k.CancelRequested || wire.FinalStage(k.Stage) || k.MoveProject != "" || s.Retired { |
| + return errBaseRefused("task ended") |
| + } |
| + if s.Specialist != wire.SpecialistEngineering || s.Attempt != v.Attempt || s.Withdrawn { |
| + return errBaseRefused("attempt not current") |
| + } |
| + if s.State != wire.StepQueued || s.Placement != wire.PlacementBase { |
| + return nil |
| + } |
| + if v.Reason == wire.ReasonBaseUnavailable { |
| + baseUnavailable(t, &s) |
| + if err := t.saveStep(&s, &k); err != nil { |
| + return err |
| + } |
| + return t.advance(&k) |
| + } |
| + s.BaseSHA = v.BaseSHA |
| + if !s.Rebase && k.BaseSHA == "" { |
| + k.BaseSHA = v.BaseSHA |
| + } |
| + if err := t.dispatchStep(&k, &s); err != nil { |
| + return err |
| + } |
| + return t.saveStep(&s, &k) |
| +} |
| + |
| +// macEngineeringNeeds is what Mac Engineering waiting at s needs of the |
| +// person: a Mac's Claude connection, an update, or the Mac back online |
| +// after OfflineLimit; "" when nothing. |
| +func macEngineeringNeeds(s *stepRecord) string { |
| + if s == nil || s.State != wire.StepQueued { |
| + return "" |
| + } |
| + switch { |
| + case s.Placement == wire.PlacementMacConnection: |
| + return wire.NeedsMacConnection |
| + case s.Placement == wire.PlacementMacUpdate: |
| + return wire.NeedsMacUpdate |
| + case s.Specialist == wire.SpecialistEngineering && s.Placement == wire.PlacementWaiting && s.Reason == reasonRunnerOffline: |
| + return wire.NeedsRunnerOffline |
| + } |
| + return "" |
| +} |
| + |
| +// helloEngineering is what a stored hello says of its runner's readiness |
| +// for Mac Engineering: its tags and its Engineering status. |
| +func helloEngineering(raw string) string { |
| + var h wire.Hello |
| + if raw == "" || json.Unmarshal([]byte(raw), &h) != nil || h.Capabilities == nil { |
| + return "" |
| + } |
| + key := strings.Join(h.Capabilities.Tags, ",") |
| + if e := h.Capabilities.Engineering; e != nil { |
| + key += "|" + e.State |
| + } |
| + return key |
| +} |
| + |
| +// awaitingPublication: s is a worker's Engineering round that ended |
| +// (done) without its commit published yet, or whose publication failed: |
| +// the round is not over, so nothing judges or follows it (the primary's |
| +// published report, or the person's Retry, moves it on). |
| +func awaitingPublication(s *stepRecord) bool { |
| + return s.Specialist == wire.SpecialistEngineering && s.State == wire.StepDone && !s.Pushed |
| +} |
diff --git a/internal/equipo/chat/explore.go b/internal/equipo/chat/explore.go| index 17cf7177..4e302a0c 100644 |
| --- a/internal/equipo/chat/explore.go |
| +++ b/internal/equipo/chat/explore.go |
| @@ -53,6 +53,8 @@ func (p progress) needsExplore(k taskRecord) string { |
| return wire.NeedsMacRunner |
| case w.State == wire.StepQueued && w.Placement == wire.PlacementMacEngineering: |
| return wire.NeedsMacEngineering |
| + case macEngineeringNeeds(w) != "": |
| + return macEngineeringNeeds(w) |
| case w.State != wire.StepDone || p.candidate == "": |
| return "" |
| } |
| @@ -104,7 +106,7 @@ func (t *txn) advanceExplore(k *taskRecord) error { |
| return nil |
| } |
| w := p.work |
| - if w == nil || w.State != wire.StepDone || p.candidate == "" || p.eng == nil { |
| + if w == nil || w.State != wire.StepDone || p.candidate == "" || p.eng == nil || awaitingPublication(w) { |
| return nil |
| } |
| _, _, verdict, _ := p.judged() |
diff --git a/internal/equipo/chat/macsandbox.go b/internal/equipo/chat/macsandbox.go| index b9ea5fca..848ec379 100644 |
| --- a/internal/equipo/chat/macsandbox.go |
| +++ b/internal/equipo/chat/macsandbox.go |
| @@ -36,15 +36,63 @@ func unsandboxedChosen(s stepRecord, runner string) bool { |
| return s.UnsandboxedBy != "" && s.UnsandboxedAt != nil && s.UnsandboxedAttempt == s.Attempt && s.UnsandboxedRunner == runner && runner != "" |
| } |
| -// stepRunnerLabel names where a step's attempt runs, or the Mac it waits |
| -// for while it waits for that Mac's sandbox. |
| +// stepRunnerLabel names where a step's attempt runs, or, while it is |
| +// placed nowhere, the runner it waits for: a Mac's sandbox, a Mac's |
| +// Claude connection or update (or the primary's update), the base for |
| +// that Mac, or that Mac back online. |
| func (t *txn) stepRunnerLabel(s stepRecord) string { |
| - if s.Placement == wire.PlacementSandbox { |
| + if s.Placement == wire.PlacementSandbox || s.RunnerID == "" && s.SandboxRunner != "" { |
| return t.runnerLabel(s.SandboxRunner) |
| } |
| return t.runnerLabel(s.RunnerID) |
| } |
| +// stepWaitView adds to a step's view what the runner it waits for says |
| +// now: while it waits for a Mac's Claude connection, that Mac's |
| +// Engineering status (read when rendered, never stored). |
| +func (t *txn) stepWaitView(sv *wire.Step, s stepRecord) { |
| + sv.RunnerLabel = t.stepRunnerLabel(s) |
| + if s.Placement != wire.PlacementMacConnection || s.SandboxRunner == "" { |
| + return |
| + } |
| + var sess runnerSessionRecord |
| + if t.db.Where("runner_id = ?", s.SandboxRunner).First(&sess).Error != nil || sess.Hello == "" { |
| + return |
| + } |
| + var h wire.Hello |
| + if json.Unmarshal([]byte(sess.Hello), &h) != nil || h.Capabilities == nil { |
| + return |
| + } |
| + status := wire.EngineeringStatus{State: wire.EngineeringNoConnection} |
| + if e := h.Capabilities.Engineering; e != nil { |
| + status = *e |
| + } |
| + sv.EngineeringStatus = &status |
| +} |
| + |
| +// xcodeAccess is what Engineering on runner gets of Xcode's services |
| +// (spec §8.2): sandboxed only on a Mac the instance holds sandbox-proven |
| +// (its hello says seatbelt, so P2 denied, and it is not tainted) whose |
| +// probe F5 is denied too. Otherwise none: the change is built and tested |
| +// by Checks. |
| +func (t *txn) xcodeAccess(person, runner string) (string, error) { |
| + rs, err := t.runners(person) |
| + if err != nil { |
| + return "", err |
| + } |
| + for _, r := range rs { |
| + if r.ID != runner || !slices.Contains(r.tags(), wire.TagMacOS) || !r.sandboxProven() || r.Hello.Capabilities == nil { |
| + continue |
| + } |
| + for _, p := range r.Hello.Capabilities.Probes { |
| + if p.ID == "F5" && p.Verdict == wire.ProbeDenied { |
| + return wire.XcodeAccessSandboxed, nil |
| + } |
| + } |
| + } |
| + return "", nil |
| +} |
| + |
| // helloSandbox is the sandbox a stored hello says ("" when none). |
| func helloSandbox(raw string) string { |
| var h struct { |
diff --git a/internal/equipo/chat/mergeauth.go b/internal/equipo/chat/mergeauth.go| index 7dc91c10..57bacad2 100644 |
| --- a/internal/equipo/chat/mergeauth.go |
| +++ b/internal/equipo/chat/mergeauth.go |
| @@ -245,6 +245,14 @@ func (t *txn) mergeInputs(k taskRecord, p progress, person bool, protocol int) ( |
| } |
| // An exploration never merges: the gate says never, first. |
| in.Explore = wire.NormalKind(k.Kind) == wire.KindExplore |
| + // A Mac worker made some of it (its commit was published for it): its |
| + // Engineering ran where base gates cannot be enforced, so only a |
| + // person's Merge takes it (injection defences, slice F). |
| + var made int64 |
| + if err := t.db.Model(&stepRecord{}).Where("task_id = ? AND specialist = ? AND coalesce(publication, '') <> '' AND coalesce(retired, 0) = 0", k.ID, wire.SpecialistEngineering).Count(&made).Error; err != nil { |
| + return mergegate.Inputs{}, pr, err |
| + } |
| + in.MacMade = made > 0 |
| // 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 != "" |
| @@ -645,6 +653,8 @@ func (t *txn) mergeQuestion(k taskRecord, p progress, d mergegate.Decision) (str |
| phrase = t.words("chat.merge.not.hosted") |
| case c.Name == mergegate.CritSandbox: |
| phrase = t.words("chat.merge.not.sandbox") |
| + case c.Name == mergegate.CritPrimaryMade: |
| + phrase = t.words("chat.merge.not.mac_made") |
| } |
| if phrase == "" { |
| continue |
diff --git a/internal/equipo/chat/review.go b/internal/equipo/chat/review.go| index 88d7b834..c8926c77 100644 |
| --- a/internal/equipo/chat/review.go |
| +++ b/internal/equipo/chat/review.go |
| @@ -186,6 +186,9 @@ func (p progress) needsYou(k taskRecord) string { |
| if p.last.State == wire.StepQueued && p.last.Placement == wire.PlacementMacEngineering { |
| return wire.NeedsMacEngineering |
| } |
| + if n := macEngineeringNeeds(p.last); n != "" { |
| + return n |
| + } |
| if p.last.Specialist == wire.SpecialistEngineering && p.last.State == wire.StepDone && p.last.Publication == wire.PublicationFailed { |
| return wire.NeedsRetry |
| } |
| @@ -273,7 +276,7 @@ func (t *txn) advanceTask(k *taskRecord) error { |
| if l := p.last; l != nil && l.Specialist == wire.SpecialistMerge && l.State == wire.StepFailed && l.Terminated { |
| return t.mergeFailed(k, p, steps) |
| } |
| - if p.last == nil || p.last.State != wire.StepDone || p.candidate == "" { |
| + if p.last == nil || p.last.State != wire.StepDone || p.candidate == "" || awaitingPublication(p.last) { |
| return nil |
| } |
| if handled, err := t.copyBeforeChecks(k, p, steps); handled || err != nil { |
diff --git a/internal/equipo/chat/runner.go b/internal/equipo/chat/runner.go| index 518cdfb3..1f2b03b0 100644 |
| --- a/internal/equipo/chat/runner.go |
| +++ b/internal/equipo/chat/runner.go |
| @@ -191,6 +191,10 @@ func (s *Store) Heartbeat(ctx context.Context, l Lease, hello wire.Hello) error |
| online := r.Connected && t.now().Sub(r.SeenAt) < runnerOnline |
| // A Mac whose sandbox is proven now: checks waiting for it run. |
| proven := helloSandbox(r.Hello) != wire.SandboxSeatbelt && helloSandbox(string(raw)) == wire.SandboxSeatbelt |
| + // A Mac whose readiness for Engineering moved (its tags or its |
| + // Engineering status): Mac Engineering waiting for it is placed |
| + // again. |
| + macMoved := helloEngineering(r.Hello) != helloEngineering(string(raw)) |
| // Previews on now (the first hello never says so): approved |
| // candidates without a preview get one. |
| previewsOn := !helloPreviews(r.Hello) && hello.Capabilities != nil && hello.Capabilities.Previews |
| @@ -232,7 +236,7 @@ func (s *Store) Heartbeat(ctx context.Context, l Lease, hello wire.Hello) error |
| if err := t.resumeMoves(l.Runner.Person); err != nil { |
| return err |
| } |
| - if !online || proven { |
| + if !online || proven || macMoved { |
| if err := t.placeWaiting(l.Runner.Person); err != nil { |
| return err |
| } |
| @@ -355,6 +359,8 @@ func (s *Store) Apply(ctx context.Context, l Lease, f wire.Frame, body any) erro |
| return t.blob(l, v) |
| case *wire.PublishedReport: |
| return t.published(l, v) |
| + case *wire.BaseReport: |
| + return t.base(l, v) |
| case *wire.ConnectionReport: |
| return t.connectionReport(l, v) |
| case *wire.UsageReport: |
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go| index 3a536fbc..1361dda2 100644 |
| --- a/internal/equipo/chat/runners.go |
| +++ b/internal/equipo/chat/runners.go |
| @@ -137,6 +137,14 @@ func (s *Store) RemoveRunner(tx *gorm.DB, person, runner string, now bool) (unce |
| if err := tx.Where("runner_id = ? AND state IN ?", runner, []string{wire.StepQueued, wire.StepRunning}).Find(&rows).Error; err != nil { |
| return 0, err |
| } |
| + // Engineering waiting for the base of an attempt on it never started |
| + // either: withdrawn (its base report is refused from now on) and |
| + // placed again without it. |
| + var basing []stepRecord |
| + if err := tx.Where("sandbox_runner = ? AND placement = ? AND state = ?", runner, wire.PlacementBase, wire.StepQueued).Find(&basing).Error; err != nil { |
| + return 0, err |
| + } |
| + rows = append(rows, basing...) |
| for i := range rows { |
| st := rows[i] |
| k, err := t.loadTask(st.TaskID) |
| @@ -369,9 +377,13 @@ const phaseCommitted = "committed" |
| const WithdrawAfter = 2 * time.Minute |
| // OfflineLimit is how long a step waits for the only runner that fits |
| -// before checks resolve as not run (runner_offline). |
| +// before checks resolve as not run (runner_offline), and Mac Engineering |
| +// waiting for its Mac needs the person (still waiting). |
| const OfflineLimit = 30 * time.Minute |
| +// reasonRunnerOffline: the runner a step needs was offline too long. |
| +const reasonRunnerOffline = "runner_offline" |
| + |
| // checksNeeds are the tags checks of the task's newest candidate need: |
| // macOS and Xcode when the change touched Apple files or the |
| // repository's gate needs Xcode (the primary's index says so), and the |
| @@ -394,13 +406,23 @@ func (t *txn) checksNeeds(k taskRecord, s stepRecord) ([]string, error) { |
| // engineeringNeeds are the tags Engineering of the task needs: macOS and |
| // Xcode (and the simulator) when the repository's gate needs Xcode, as |
| // the primary's index of its default branch says (the base, not anything |
| -// the change wrote). Anything else needs nothing. |
| +// the change wrote), and claude to make the change there (slice F). |
| +// Anything else needs nothing. |
| func (t *txn) engineeringNeeds(k taskRecord, person string) ([]string, error) { |
| info, err := t.repoInfo(k, person) |
| if err != nil { |
| return nil, err |
| } |
| - return macNeeds(info.NeedsMacOS, info), nil |
| + needs := macNeeds(info.NeedsMacOS, info) |
| + if len(needs) > 0 { |
| + needs = append(needs, wire.TagClaude) |
| + } |
| + return needs, nil |
| +} |
| + |
| +// macTags are needs without claude: what makes a runner a Mac for them. |
| +func macTags(needs []string) []string { |
| + return slices.DeleteFunc(slices.Clone(needs), func(t string) bool { return t == wire.TagClaude }) |
| } |
| // repoInfo is the primary's catalog entry for the task's repository |
| @@ -461,12 +483,11 @@ func encodeList(v []string) string { |
| // place chooses the runner for a step's current attempt (Mac runners spec |
| // §1.4). Checks are placed by their needs; Review and merges run on the |
| // primary; Engineering runs on the primary (pinned there for the task) |
| -// unless it is Mac work. Mac work never runs on a Linux primary |
| -// (2026-11-28): checks that need macOS with no enrolled runner that fits |
| -// wait for a Mac runner (waiting_mac, the person's to add), and so does |
| -// Engineering for a repository whose gate needs Xcode; with a Mac |
| -// enrolled, that Engineering still waits (waiting_mac_engineering), since |
| -// a Mac worker takes only checks until slice F. Among the person's |
| +// unless it is Mac work, which engineeringPlace places (on a Mac worker |
| +// with EQUIPO_MAC_ENGINEERING, slice F). Mac work never runs on a Linux |
| +// primary (2026-11-28): checks that need macOS with no enrolled runner |
| +// that fits wait for a Mac runner (waiting_mac, the person's to add), and |
| +// so does Engineering for a repository whose gate needs Xcode. Among the person's |
| // runners whose tags cover the needs: the primary if it does, else the |
| // online worker running fewest steps, ties by enrolment order. A fitting |
| // runner that is offline leaves the step waiting (placed false). When the |
| @@ -483,33 +504,7 @@ func (t *txn) place(k *taskRecord, s *stepRecord) (placed bool, err error) { |
| s.Placement, s.WaitingSince, s.SandboxRunner = "", nil, "" |
| switch s.Specialist { |
| case wire.SpecialistEngineering: |
| - if wait, err := t.macEngineering(k, s, primary); err != nil || wait { |
| - return false, err |
| - } |
| - s.Needs = "" |
| - s.RunnerID = primary |
| - if k.EngineeringRunner != "" && k.EngineeringRunner != primary { |
| - // Pinned elsewhere (a worker, from slice F): fix rounds, |
| - // retries and republishes go there while it is enrolled. |
| - rs, err := t.runners(s.Person) |
| - if err != nil { |
| - return false, err |
| - } |
| - for _, r := range rs { |
| - if r.ID == k.EngineeringRunner && !r.Removing { |
| - s.RunnerID = r.ID |
| - } |
| - } |
| - } |
| - if k.EngineeringRunner == "" && s.RunnerID != "" { |
| - // On the task value the transaction carries, so its next save |
| - // keeps the pin. |
| - k.EngineeringRunner = s.RunnerID |
| - if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Update("engineering_runner", s.RunnerID).Error; err != nil { |
| - return false, err |
| - } |
| - } |
| - return true, nil |
| + return t.placeEngineering(k, s, primary) |
| case wire.SpecialistChecks: |
| default: |
| s.Needs, s.RunnerID = "", primary |
| @@ -586,41 +581,182 @@ func (t *txn) place(k *taskRecord, s *stepRecord) (placed bool, err error) { |
| return true, nil |
| } |
| -// macEngineering decides whether Engineering of the task is Mac work that |
| -// must wait rather than run on the Linux primary, and leaves it waiting |
| -// if so: for a Mac runner when none enrolled fits, else because no runner |
| -// that fits takes Engineering (only the primary does). An older primary |
| -// (protocol 1) is no exception. |
| -func (t *txn) macEngineering(k *taskRecord, s *stepRecord, primary string) (bool, error) { |
| - needs, err := t.engineeringNeeds(*k, s.Person) |
| - if err != nil || len(needs) == 0 { |
| +// engineeringPlacement is where Engineering's current attempt goes, as |
| +// decided without writing anything: on runner, or waiting (placement) |
| +// for waitFor, with needs. |
| +type engineeringPlacement struct { |
| + runner, placement, waitFor string |
| + needs []string |
| +} |
| + |
| +// placeEngineering places Engineering's attempt (placeEngineering's |
| +// decision, engineeringPlace). On a worker, the attempt's base must be |
| +// bound first: with none (a first step, or a rebase round whose new tip |
| +// is unknown) the primary is asked for it and the attempt waits |
| +// (waiting_base, base_prepare.go). Placed, the task is pinned to the |
| +// runner, on the task value the transaction carries so its next save |
| +// keeps the pin. |
| +func (t *txn) placeEngineering(k *taskRecord, s *stepRecord, primary string) (bool, error) { |
| + d, err := t.engineeringPlace(*k, *s, primary) |
| + if err != nil { |
| return false, err |
| } |
| + if s.State == wire.StepQueued && s.Reason == reasonRunnerOffline { |
| + // The wait for an offline Mac is over or starts again. |
| + s.Reason = "" |
| + } |
| + if d.placement != "" { |
| + _, err := t.waitForMac(s, d.needs, d.placement) |
| + s.SandboxRunner = d.waitFor |
| + return false, err |
| + } |
| + s.Needs, s.RunnerID = "", d.runner |
| + if d.runner == "" { |
| + // No runner at all (no primary): dispatchStep has it wait. |
| + return true, nil |
| + } |
| + if d.runner != primary { |
| + if boundBase(*k, *s) == "" { |
| + return false, t.prepareBase(k, s, primary, d) |
| + } |
| + s.Needs = encodeList(d.needs) |
| + } |
| + if k.EngineeringRunner != d.runner { |
| + k.EngineeringRunner = d.runner |
| + if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Update("engineering_runner", d.runner).Error; err != nil { |
| + return false, err |
| + } |
| + } |
| + return true, nil |
| +} |
| + |
| +// engineeringPlace decides where Engineering of the task runs (Mac |
| +// runners spec §1.4, §8.5). Work that is not Mac work, and not pinned to |
| +// a worker, runs on the primary. Mac work never runs on a Linux primary: |
| +// a primary that is a Mac takes it; otherwise, with EQUIPO_MAC_ENGINEERING |
| +// unset, it waits as mac-placement-wait left it (waiting_mac with no Mac |
| +// that fits, waiting_mac_engineering with one). Set, the candidates are |
| +// the pinned worker (enrolled, not removing) alone, else the workers that |
| +// are Macs for the needs, in §1.4's order. Each must speak protocol 37, |
| +// and so must the primary (waiting_mac_update, naming the one that does |
| +// not); a Mac without claude waits for it (waiting_mac_connection, whose |
| +// status says why); an offline one is waited for (waiting_runner). A |
| +// pinned worker that lost a tag is waited for, never replaced. An older |
| +// primary (protocol 1) is no exception. |
| +func (t *txn) engineeringPlace(k taskRecord, s stepRecord, primary string) (engineeringPlacement, error) { |
| + needs, err := t.engineeringNeeds(k, s.Person) |
| + if err != nil { |
| + return engineeringPlacement{}, err |
| + } |
| + if len(needs) == 0 && (k.EngineeringRunner == "" || k.EngineeringRunner == primary) { |
| + return engineeringPlacement{runner: primary}, nil |
| + } |
| rs, err := t.runners(s.Person) |
| if err != nil { |
| - return false, err |
| + return engineeringPlacement{}, err |
| } |
| - fit := false |
| - for _, r := range rs { |
| - if r.fits(needs, nil) { |
| - if r.ID == primary { |
| - // A primary that is a Mac takes it. |
| - return false, nil |
| + var pin, prim *runnerInfo |
| + for i := range rs { |
| + switch r := &rs[i]; { |
| + case r.ID == primary: |
| + prim = r |
| + case r.ID == k.EngineeringRunner && r.Role == wire.RoleWorker && !r.Removing: |
| + pin = r |
| + } |
| + } |
| + if len(needs) == 0 && pin == nil { |
| + return engineeringPlacement{runner: primary}, nil |
| + } |
| + if !t.s.macEngineering.Load() { |
| + // As mac-placement-wait left it: a Mac's tags, without claude. |
| + mac := macTags(needs) |
| + fit := false |
| + for _, r := range rs { |
| + if r.fits(mac, nil) { |
| + if r.ID == primary { |
| + return engineeringPlacement{runner: primary}, nil |
| + } |
| + fit = true |
| } |
| - fit = true |
| } |
| + if !fit { |
| + return engineeringPlacement{placement: wire.PlacementMac, needs: mac}, nil |
| + } |
| + return engineeringPlacement{placement: wire.PlacementMacEngineering, needs: mac}, nil |
| + } |
| + if len(needs) == 0 { |
| + // Pinned to a worker: what it needs to make a change at all. |
| + needs = []string{wire.TagClaude} |
| + } |
| + mac := macTags(needs) |
| + if prim == nil { |
| + return engineeringPlacement{placement: wire.PlacementWaiting, needs: needs}, nil |
| } |
| - if !fit { |
| - _, err := t.waitForMac(s, needs, wire.PlacementMac) |
| - return true, err |
| + if pin == nil && len(mac) > 0 && prim.fits(needs, nil) { |
| + // A primary that is a Mac takes it. |
| + return engineeringPlacement{runner: primary}, nil |
| } |
| - _, err = t.waitForMac(s, needs, wire.PlacementMacEngineering) |
| - return true, err |
| + // readiness is what keeps worker r from taking it now ("" when |
| + // nothing does) and the runner it waits for. |
| + readiness := func(r runnerInfo) (string, string) { |
| + switch { |
| + case r.Protocol < wire.ProtocolMacEngineering: |
| + return wire.PlacementMacUpdate, r.ID |
| + case prim.Protocol < wire.ProtocolMacEngineering: |
| + return wire.PlacementMacUpdate, prim.ID |
| + case !wire.Covers(r.tags(), needs): |
| + return wire.PlacementMacConnection, r.ID |
| + case !r.Online: |
| + return wire.PlacementWaiting, r.ID |
| + } |
| + return "", r.ID |
| + } |
| + if pin != nil { |
| + if !macFor(*pin, mac) { |
| + // It lost what makes it a Mac for this: wait for it. |
| + return engineeringPlacement{placement: wire.PlacementWaiting, waitFor: pin.ID, needs: needs}, nil |
| + } |
| + if why, who := readiness(*pin); why != "" { |
| + return engineeringPlacement{placement: why, waitFor: who, needs: needs}, nil |
| + } |
| + return engineeringPlacement{runner: pin.ID, needs: needs}, nil |
| + } |
| + var chosen *runnerInfo |
| + first := map[string]string{} |
| + for i := range rs { |
| + r := &rs[i] |
| + if r.Role != wire.RoleWorker || r.Removing || !macFor(*r, mac) { |
| + continue |
| + } |
| + why, who := readiness(*r) |
| + switch { |
| + case why == "" && (chosen == nil || r.Running < chosen.Running): |
| + chosen = r |
| + case why != "" && first[why] == "": |
| + first[why] = who |
| + } |
| + } |
| + if chosen != nil { |
| + return engineeringPlacement{runner: chosen.ID, needs: needs}, nil |
| + } |
| + for _, why := range []string{wire.PlacementWaiting, wire.PlacementMacConnection, wire.PlacementMacUpdate} { |
| + if who := first[why]; who != "" { |
| + return engineeringPlacement{placement: why, waitFor: who, needs: needs}, nil |
| + } |
| + } |
| + return engineeringPlacement{placement: wire.PlacementMac, needs: needs}, nil |
| +} |
| + |
| +// macFor reports whether r is a runner for work with tags at all |
| +// (protocol 2, tags covered). |
| +func macFor(r runnerInfo, tags []string) bool { |
| + return r.Protocol >= wire.Protocol2 && wire.Covers(r.tags(), tags) |
| } |
| // restartMacEngineering: whether the unstarted Engineering attempt s is |
| -// Mac work its runner cannot take; if so the attempt is ended and the |
| -// next one placed (it waits for a Mac). |
| +// not where placement would put it now (Mac work its runner cannot take, |
| +// or a worker that can no longer take it); if so the attempt is ended and |
| +// the next one placed (it waits, or goes where it now fits). |
| func (t *txn) restartMacEngineering(s *stepRecord) (bool, error) { |
| k, err := t.loadTask(s.TaskID) |
| if err != nil { |
| @@ -630,9 +766,8 @@ func (t *txn) restartMacEngineering(s *stepRecord) (bool, error) { |
| if err != nil { |
| return false, err |
| } |
| - probe := *s |
| - wait, err := t.macEngineering(&k, &probe, primary) |
| - if err != nil || !wait { |
| + d, err := t.engineeringPlace(k, *s, primary) |
| + if err != nil || d.runner == s.RunnerID { |
| return false, err |
| } |
| if err := t.replace(&k, s); err != nil { |
| @@ -666,7 +801,11 @@ func (t *txn) replace(k *taskRecord, s *stepRecord) error { |
| // voidAttempt makes sure nothing of an attempt is served again: its |
| // unacked dispatch and the chunks of its transfers. |
| func (t *txn) voidAttempt(s stepRecord) error { |
| - if err := t.db.Model(&commandRecord{}).Where("runner_id = ? AND kind = ? AND acked_at IS NULL AND body LIKE ?", s.RunnerID, wire.FrameDispatch, `%"step_id":"`+s.ID+`","attempt":`+itoa64(s.Attempt)+`,%`).Update("acked_at", t.now()).Error; err != nil { |
| + if err := t.db.Model(&commandRecord{}).Where("runner_id = ? AND kind = ? AND acked_at IS NULL AND body LIKE ?", s.RunnerID, wire.FrameDispatch, attemptLike(s.ID, s.Attempt)).Update("acked_at", t.now()).Error; err != nil { |
| + return err |
| + } |
| + // Its unanswered prepare_base too: the primary need not resolve it. |
| + if err := t.db.Model(&commandRecord{}).Where("kind = ? AND acked_at IS NULL AND body LIKE ?", wire.FramePrepareBase, attemptLike(s.ID, s.Attempt)).Update("acked_at", t.now()).Error; err != nil { |
| return err |
| } |
| return t.closeTransfers(s.ID, s.Attempt) |
| @@ -783,7 +922,9 @@ func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt i |
| } |
| // waitingPlacements are the placements of a step waiting to be placed. |
| -var waitingPlacements = []string{wire.PlacementWaiting, wire.PlacementSandbox, wire.PlacementMac, wire.PlacementMacEngineering} |
| +// waiting_base is not one: the attempt waits for the primary's base |
| +// report, never placed again meanwhile (base_prepare.go). |
| +var waitingPlacements = []string{wire.PlacementWaiting, wire.PlacementSandbox, wire.PlacementMac, wire.PlacementMacEngineering, wire.PlacementMacConnection, wire.PlacementMacUpdate} |
| // placeWaiting places the person's steps waiting for a runner, when one |
| // that fits may have come online or been added, or for a Mac's sandbox, |
| @@ -844,8 +985,12 @@ func (s *Store) Place(ctx context.Context) error { |
| }) |
| } |
| -// offline applies the offline rule to the person's checks. |
| +// offline applies the offline rule to the person's checks, and to Mac |
| +// Engineering waiting for its Mac (offlineEngineering). |
| func (t *txn) offline(person string) error { |
| + if err := t.offlineEngineering(person); err != nil { |
| + return err |
| + } |
| rs, err := t.runners(person) |
| if err != nil { |
| return err |
| @@ -907,6 +1052,35 @@ func (t *txn) offline(person string) error { |
| return nil |
| } |
| +// offlineEngineering: Mac Engineering that has waited OfflineLimit for |
| +// the only Mac that can take it keeps waiting and needs the person |
| +// (runner_offline). It is never resolved and never moves to Linux; |
| +// Cancel stays available. |
| +func (t *txn) offlineEngineering(person string) error { |
| + var rows []stepRecord |
| + if err := t.db.Where("person = ? AND specialist = ? AND state = ? AND placement = ? AND coalesce(sandbox_runner, '') <> '' AND coalesce(reason, '') = ''", person, wire.SpecialistEngineering, wire.StepQueued, wire.PlacementWaiting).Find(&rows).Error; err != nil { |
| + return err |
| + } |
| + for i := range rows { |
| + s := rows[i] |
| + if s.WaitingSince == nil || t.now().Sub(*s.WaitingSince) < OfflineLimit { |
| + continue |
| + } |
| + k, err := t.loadTask(s.TaskID) |
| + if err != nil { |
| + return err |
| + } |
| + if wire.FinalStage(k.Stage) || k.CancelRequested { |
| + continue |
| + } |
| + s.Reason = reasonRunnerOffline |
| + if err := t.saveStep(&s, &k); err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| +} |
| + |
| // resolveOffline ends waiting checks honestly: not run, the runner was |
| // offline. Review proceeds on the candidate. |
| func (t *txn) resolveOffline(k *taskRecord, s *stepRecord) error { |
diff --git a/internal/equipo/chat/store.go b/internal/equipo/chat/store.go| index 2f6b0d87..c3019fdb 100644 |
| --- a/internal/equipo/chat/store.go |
| +++ b/internal/equipo/chat/store.go |
| @@ -126,6 +126,10 @@ type Store struct { |
| // projectJobHook stands in for projectJob in the minute's sweep (a |
| // test's failing card); nil projects as usual. |
| projectJobHook func(*txn, handoffRecord) error |
| + // macEngineering is EQUIPO_MAC_ENGINEERING (SetMacEngineering): |
| + // Engineering for Mac work is placed on a Mac worker. Off, it waits as |
| + // mac-placement-wait left it. |
| + macEngineering atomic.Bool |
| } |
| // SetFrameTap sees every frame the instance sends a runner, as sent |
| @@ -143,6 +147,9 @@ func NewStore(d *db.DB, a Authority, hub *Hub) *Store { |
| // with a fake clock). |
| func (s *Store) SetClock(now func() time.Time) { s.now = now } |
| +// SetMacEngineering is EQUIPO_MAC_ENGINEERING, read at boot. |
| +func (s *Store) SetMacEngineering(on bool) { s.macEngineering.Store(on) } |
| + |
| // Process identifies this instance process in runner leases. |
| func (s *Store) Process() string { return s.process } |
diff --git a/internal/equipo/chat/stream.go b/internal/equipo/chat/stream.go| index 52e69c3c..997237f8 100644 |
| --- a/internal/equipo/chat/stream.go |
| +++ b/internal/equipo/chat/stream.go |
| @@ -179,7 +179,7 @@ func (rc *runnerConn) read(ctx context.Context) websocket.StatusCode { |
| switch v := body.(type) { |
| case *wire.Hello: |
| err = store.Heartbeat(ctx, rc.lease, *v) |
| - case *wire.ChangeDiffUpload, *wire.AccessReport, *wire.Sync, *wire.Ack, *wire.DeltaReport, *wire.Reply, *wire.TurnReport, *wire.ToolCall, *wire.ActivityReport, *wire.MoveIn, *wire.NotebookReport, *wire.StepReport, *wire.MergedReport, *wire.AnswerReport, *wire.BranchReport, *wire.ConnectionReport, *wire.UsageReport, *wire.StepActivityReport, *wire.Blob, *wire.PublishedReport, *wire.ResearchFile, *wire.GlanceReport: |
| + case *wire.ChangeDiffUpload, *wire.AccessReport, *wire.Sync, *wire.Ack, *wire.DeltaReport, *wire.Reply, *wire.TurnReport, *wire.ToolCall, *wire.ActivityReport, *wire.MoveIn, *wire.NotebookReport, *wire.StepReport, *wire.MergedReport, *wire.AnswerReport, *wire.BranchReport, *wire.ConnectionReport, *wire.UsageReport, *wire.StepActivityReport, *wire.Blob, *wire.PublishedReport, *wire.ResearchFile, *wire.GlanceReport, *wire.BaseReport: |
| err = store.Apply(ctx, rc.lease, f, body) |
| case *wire.LeaseCheck: |
| // Answered only while this connection holds the lease; at |
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go| index 79df8a50..885fcbe9 100644 |
| --- a/internal/equipo/chat/tasks.go |
| +++ b/internal/equipo/chat/tasks.go |
| @@ -555,7 +555,7 @@ func (t *txn) taskViewWith(k taskRecord, options taskViewOptions) (wire.Task, er |
| if options.changeFiles { |
| sv.ChangeFiles = stepChangeFilesView(s) |
| } |
| - sv.RunnerLabel = t.stepRunnerLabel(s) |
| + t.stepWaitView(&sv, s) |
| sv.Paused = t.stepPaused(k, s) |
| if s.Specialist == wire.SpecialistResearch && (s.State == wire.StepDone || s.State == wire.StepFailed || s.State == wire.StepCancelled) { |
| rv, err := t.researchView(s) |
| @@ -804,7 +804,7 @@ func (t *txn) writeStep(s *stepRecord) error { |
| } |
| s.Revision++ |
| s.UpdatedAt = t.now() |
| - if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("base_checks", "base_checks_sha", "copy_owner", "copy_revision", "copy_result", "failure_signature", "state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "headline", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "switched", "activity", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple", "checks_sandbox", "change_files", "change_facts", "decided_by", "merge_source", "merge_parents", "hosted_ci", "kind", "note", "sandbox_runner", "unsandboxed_by", "unsandboxed_at", "unsandboxed_attempt", "unsandboxed_runner", "has_preview", "preview", "boundary", "question", "request_turn", "sources_card", "sources_hash", "research_grant", "research_grant_revision", "hold", "housekeeping_attempt", "coordinator_attempt", "held_at", "publish", "model").Updates(s).Error; err != nil { |
| + if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("base_checks", "base_checks_sha", "copy_owner", "copy_revision", "copy_result", "failure_signature", "state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "headline", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "switched", "activity", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple", "checks_sandbox", "change_files", "change_facts", "decided_by", "merge_source", "merge_parents", "hosted_ci", "kind", "note", "sandbox_runner", "unsandboxed_by", "unsandboxed_at", "unsandboxed_attempt", "unsandboxed_runner", "has_preview", "preview", "boundary", "question", "request_turn", "sources_card", "sources_hash", "research_grant", "research_grant_revision", "hold", "housekeeping_attempt", "coordinator_attempt", "held_at", "publish", "model", "xcode_access").Updates(s).Error; err != nil { |
| return err |
| } |
| if s.Retired { |
| @@ -816,7 +816,7 @@ func (t *txn) writeStep(s *stepRecord) error { |
| } |
| for _, m := range members { |
| sv := stepViewSwitched(*s) |
| - sv.RunnerLabel = t.stepRunnerLabel(*s) |
| + t.stepWaitView(&sv, *s) |
| if err := t.event("", m, wire.EventStep, "step", s.ID, s.Revision, "", "", s.Attempt, sv); err != nil { |
| return err |
| } |
| @@ -1237,14 +1237,40 @@ func (t *txn) dispatchStep(k *taskRecord, s *stepRecord) error { |
| // The primary may take the hub's hosted CI verdict for checks (a |
| // protocol 5 runner; Encode drops the offer for older ones). |
| cmd.HostedChecks = s.Specialist == wire.SpecialistChecks && s.RunnerID == primary |
| + if s.Specialist == wire.SpecialistEngineering { |
| + // Only this attempt's grant counts (below, on a worker). |
| + s.XcodeAccess = "" |
| + } |
| if s.RunnerID != primary { |
| // Placed on a worker: what it needs, and the candidate relayed |
| // from the primary as a pack in an inbound transfer. |
| cmd.Needs = decodeList(s.Needs) |
| - if s.Specialist == wire.SpecialistChecks { |
| + switch s.Specialist { |
| + case wire.SpecialistChecks: |
| if _, err := t.openTransfer(*k, *s, primary, s.RunnerID, wire.TransferHeader{Direction: wire.TransferInbound, BaseSHA: cmd.BaseSHA, CandidateSHA: s.CandidateSHA}); err != nil { |
| return err |
| } |
| + case wire.SpecialistEngineering: |
| + // Mac Engineering (slice F): Xcode's services only as the |
| + // proof allows, and the commits it starts from, base bound |
| + // (placeEngineering), relayed in an Engineering transfer: the |
| + // base, and for a rebase round the old base and the candidate. |
| + if cmd.XcodeAccess, err = t.xcodeAccess(s.Person, s.RunnerID); err != nil { |
| + return err |
| + } |
| + s.XcodeAccess = cmd.XcodeAccess |
| + if !s.Republish { |
| + h := wire.TransferHeader{Direction: wire.TransferInbound, Kind: wire.TransferKindEngineering, BaseSHA: cmd.BaseSHA} |
| + if s.Rebase { |
| + h.OldBaseSHA, h.CandidateSHA = s.FromBase, s.FromCandidate |
| + } |
| + if !h.Valid() { |
| + return fmt.Errorf("%w: engineering transfer for %s", ErrInvalid, s.ID) |
| + } |
| + if _, err := t.openTransfer(*k, *s, primary, s.RunnerID, h); err != nil { |
| + return err |
| + } |
| + } |
| } |
| } |
| if s.Specialist == wire.SpecialistCopy { |
diff --git a/internal/equipo/config.go b/internal/equipo/config.go| index 44a01b1e..c8d10bc6 100644 |
| --- a/internal/equipo/config.go |
| +++ b/internal/equipo/config.go |
| @@ -58,12 +58,17 @@ type Config struct { |
| // Oficina apps. |
| OficinaConnectOrigin string |
| OficinaConnectClientID string |
| + // MacEngineering (EQUIPO_MAC_ENGINEERING=1) places Engineering for Mac |
| + // work on a Mac worker. Unset, it waits as before, so a release can |
| + // deploy inert. |
| + MacEngineering bool |
| } |
| func LoadConfig(getenv func(string) string) (Config, error) { |
| cfg := Config{AgentIssuer: getenv("EQUIPO_AGENT_ISSUER"), AgentTeam: getenv("EQUIPO_AGENT_TEAM"), RunnerReleaseDir: getenv("EQUIPO_RUNNER_RELEASE_DIR"), |
| GitHubEnabled: getenv("EQUIPO_GITHUB") == "1", |
| ExecutionEnabled: getenv("EQUIPO_EXECUTION_ENABLED") == "1", |
| + MacEngineering: getenv("EQUIPO_MAC_ENGINEERING") == "1", |
| ExecutionMarkerPath: getenv("EQUIPO_EXECUTION_MARKER_PATH"), |
| Origin: strings.TrimSpace(getenv("EQUIPO_ORIGIN")), |
| InstanceKey: strings.TrimSpace(getenv("EQUIPO_INSTANCE_KEY")), |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index bea45450..57c31d4d 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -2508,6 +2508,22 @@ var pageCopy = map[string]string{ |
| // stopped job card's sentence more. |
| "assistant.team.no_access": "The change is ready, but it can't go live until access to publish it is set up.", // COPY APPROVED (Paul, 2026-11-26, coordinator session, unchanged) |
| "assistant.job.detail.no_access": "It can't go live until access to publish it is set up.", // COPY APPROVED (Paul, 2026-11-26, coordinator session, unchanged) |
| + |
| + // Mac Engineering (slice F, plan task 3): drafts for task 15's review. |
| + "work.needs.mac_connection": "Needs you: %s needs Claude to make this change", // COPY REVIEW PENDING |
| + "work.needs.mac_update": "Needs you: %s needs an update to make changes", // COPY REVIEW PENDING |
| + "work.decide.mac_connection_why.no_connection": "This change needs a Mac. %s is ready, but it has no Claude connection yet.", // COPY REVIEW PENDING |
| + "work.decide.mac_connection_why.signed_out": "This change needs a Mac. Claude on %s is signed out and needs signing in again.", // COPY REVIEW PENDING |
| + "work.decide.mac_connection_why.limited": "This change needs a Mac. Claude on %s has reached its usage limit for now.", // COPY REVIEW PENDING |
| + "work.decide.mac_connection_why.probes_pending": "This change needs a Mac. %s is still checking that Claude runs safely there.", // COPY REVIEW PENDING |
| + "work.decide.mac_connection_why.probes_failed": "This change needs a Mac. %s couldn’t show that Claude runs safely there.", // COPY REVIEW PENDING |
| + "work.decide.mac_connection_why.cli_unpinned": "This change needs a Mac. %s doesn’t have the approved version of Claude Code yet.", // COPY REVIEW PENDING |
| + "work.decide.mac_connection_why.home_open": "This change needs a Mac. Other people on %s can open the runner’s home folder, so Claude can’t be used there yet.", // COPY REVIEW PENDING |
| + "work.decide.mac_connection_why.tainted": "This change needs a Mac. %s once ran checks outside the sandbox, so it can’t hold a Claude connection.", // COPY REVIEW PENDING |
| + "work.decide.mac_update_why": "This change needs a Mac. %s needs an update before the change can be made there.", // COPY REVIEW PENDING |
| + "work.decide.mac_wait_ask": "It starts by itself once %s is ready. You can also cancel it.", // COPY REVIEW PENDING |
| + "work.reason.base_unavailable": "the main runner couldn’t get the version of the project to start from", // COPY REVIEW PENDING |
| + "chat.merge.not.mac_made": "it was made on a Mac runner, so it merges only when you choose", // COPY REVIEW PENDING |
| } |
| // pasteLabels are the paste box's words, for the shared renderer, and |
diff --git a/internal/equipo/mac_engineering_config_test.go b/internal/equipo/mac_engineering_config_test.go| new file mode 100644 |
| index 00000000..ab9b2eb6 |
| --- /dev/null |
| +++ b/internal/equipo/mac_engineering_config_test.go |
| @@ -0,0 +1,18 @@ |
| +package equipo |
| + |
| +import "testing" |
| + |
| +// EQUIPO_MAC_ENGINEERING=1 turns on Mac Engineering; anything else |
| +// leaves it off, so a release deploys inert. |
| +func TestMacEngineeringSwitch(t *testing.T) { |
| + for _, value := range []string{"", "0", "true", "yes", "1"} { |
| + env := map[string]string{"EQUIPO_ORIGIN": "https://equipo.bds.oncarlos.com", "EQUIPO_INSTANCE_KEY": "fixture", "CARLOS_MAIL": "submit", "EQUIPO_MAC_ENGINEERING": value} |
| + cfg, err := LoadConfig(func(k string) string { return env[k] }) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if cfg.MacEngineering != (value == "1") { |
| + t.Fatal(value, cfg.MacEngineering) |
| + } |
| + } |
| +} |
diff --git a/internal/equipo/mac_engineering_view_test.go b/internal/equipo/mac_engineering_view_test.go| new file mode 100644 |
| index 00000000..3a28a4c1 |
| --- /dev/null |
| +++ b/internal/equipo/mac_engineering_view_test.go |
| @@ -0,0 +1,47 @@ |
| +package equipo |
| + |
| +import ( |
| + "fmt" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Mac Engineering's waits are the creator's to see under Needs you: a |
| +// Mac that fits all but Claude says, for each Engineering status, its own |
| +// line naming the Mac; a Mac or primary that needs an update names it. |
| +func TestMacEngineeringWaitLines(t *testing.T) { |
| + seen := map[string]string{} |
| + for _, state := range wire.EngineeringStates[1:] { |
| + task := wire.Task{ID: "t1", Creator: "owner@example.com", Stage: wire.StageInProgress, NeedsYou: wire.NeedsMacConnection, Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering, State: wire.StepQueued, Placement: wire.PlacementMacConnection, RunnerLabel: "Tito Studio", EngineeringStatus: &wire.EngineeringStatus{State: state}, Attempt: 1}}} |
| + if !needsViewer(task, "owner@example.com", nil) || !needsSomeone(task) || groupOf(task, "owner@example.com", nil) != "needs" { |
| + t.Fatalf("%s: not under Needs you", state) |
| + } |
| + v := taskLineOf(task, "owner@example.com") |
| + if want := fmt.Sprintf(copyText("work.needs.mac_connection"), "Tito Studio"); v.StageLine != want || copyText("work.needs.mac_connection") == "" { |
| + t.Fatalf("%s: stage line %q", state, v.StageLine) |
| + } |
| + v.Mine, v.Cancel = true, true |
| + d := decisionOf(task, v) |
| + key := "work.decide.mac_connection_why." + state |
| + if d == nil || copyText(key) == "" || d.Why != fmt.Sprintf(copyText(key), "Tito Studio") || d.Ask == "" || !d.Cancel { |
| + t.Fatalf("%s: decision %+v", state, d) |
| + } |
| + if other, ok := seen[d.Why]; ok { |
| + t.Fatalf("%s and %s say the same: %q", state, other, d.Why) |
| + } |
| + seen[d.Why] = state |
| + } |
| + task := wire.Task{ID: "t1", Creator: "owner@example.com", Stage: wire.StageInProgress, NeedsYou: wire.NeedsMacUpdate, Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering, State: wire.StepQueued, Placement: wire.PlacementMacUpdate, RunnerLabel: "docs-t1", Attempt: 1}}} |
| + if !needsViewer(task, "owner@example.com", nil) || !needsSomeone(task) { |
| + t.Fatal("mac_update: not under Needs you") |
| + } |
| + v := taskLineOf(task, "owner@example.com") |
| + if want := fmt.Sprintf(copyText("work.needs.mac_update"), "docs-t1"); v.StageLine != want || copyText("work.needs.mac_update") == "" { |
| + t.Fatalf("mac_update: stage line %q", v.StageLine) |
| + } |
| + v.Mine, v.Cancel = true, true |
| + if d := decisionOf(task, v); d == nil || d.Why != fmt.Sprintf(copyText("work.decide.mac_update_why"), "docs-t1") || copyText("work.decide.mac_update_why") == "" || d.Ask == "" || !d.Cancel { |
| + t.Fatalf("mac_update: decision %+v", d) |
| + } |
| +} |
diff --git a/internal/equipo/mergegate/gate.go b/internal/equipo/mergegate/gate.go| index 75d67ca0..dbb48d34 100644 |
| --- a/internal/equipo/mergegate/gate.go |
| +++ b/internal/equipo/mergegate/gate.go |
| @@ -71,6 +71,10 @@ const ( |
| CritRevert = "revert_exact" |
| CritEligible = "first_ready_checked" |
| CritSandbox = "checked_in_sandbox" |
| + // CritPrimaryMade: the candidate was made on the primary. A Mac |
| + // worker's Engineering cannot enforce immutable base gates, so its |
| + // candidate merges only on a person's Merge. |
| + CritPrimaryMade = "made_on_primary" |
| // CritChange: the task is a change. An exploration (mockups, |
| // prototypes, spikes) never merges, whoever asks. |
| CritChange = "is_a_change" |
| @@ -183,6 +187,8 @@ type Inputs struct { |
| Explore bool |
| // RevertSHA is set for a revert task: the merge commit it undoes. |
| RevertSHA string |
| + // MacMade: an Engineering round of the task ran on a Mac worker. |
| + MacMade bool |
| } |
| // Criterion is one rule's outcome, for the card and the audit. |
| @@ -242,7 +248,7 @@ func Decide(in Inputs) Decision { |
| rs := []Criterion{approved, {Name: CritEligible, OK: in.Eligible}, {Name: CritSandbox, OK: !in.OutsideSandbox}, {Name: CritBaseChecks, OK: in.BaseChecks}, protocol} |
| rs, matches := changeCriteria(rs, in, validPolicy) |
| rs = append(rs, policy, hold) |
| - return decided(rs, true, matches, []string{CritEligible, CritProtocol, CritPolicy}) |
| + return decided(macMade(rs, in), true, matches, []string{CritEligible, CritProtocol, CritPolicy}) |
| } |
| var rs []Criterion |
| if in.Checks == wire.ChecksPassed { |
| @@ -257,7 +263,16 @@ func Decide(in Inputs) Decision { |
| 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}) |
| + return decided(macMade(rs, in), in.Checks == wire.ChecksPassed, matches, []string{CritSmall, CritPolicy}) |
| +} |
| + |
| +// macMade adds, for a Mac-made candidate, the rule it fails: only a |
| +// person's Merge takes it, whatever setting or policy says (no waiver). |
| +func macMade(rs []Criterion, in Inputs) []Criterion { |
| + if !in.MacMade { |
| + return rs |
| + } |
| + return append(rs, Criterion{Name: CritPrimaryMade}) |
| } |
| // changeCriteria adds what the change itself must be to merge on its own: |
diff --git a/internal/equipo/mergegate/mac_made_test.go b/internal/equipo/mergegate/mac_made_test.go| new file mode 100644 |
| index 00000000..ad9f0a02 |
| --- /dev/null |
| +++ b/internal/equipo/mergegate/mac_made_test.go |
| @@ -0,0 +1,34 @@ |
| +package mergegate |
| + |
| +import ( |
| + "slices" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// A candidate made on a Mac worker never merges by policy: its executor |
| +// cannot enforce immutable base gates (injection defences), whatever |
| +// else holds, checked or not. The person's Merge still acts. |
| +func TestDecideMacMadeAsks(t *testing.T) { |
| + checked := passing() |
| + checked.Checks, checked.Eligible = wire.ChecksPassed, true |
| + for name, in := range map[string]Inputs{"unchecked": passing(), "checked": checked} { |
| + if d := Decide(in); d.Class != ClassAct { |
| + t.Fatalf("%s: primary-made work does not act: %+v", name, d) |
| + } |
| + in.MacMade = true |
| + d := Decide(in) |
| + if d.Class != ClassAsk || d.Stance != StanceWait || !slices.Contains(d.Failing(), CritPrimaryMade) { |
| + t.Fatalf("%s: Mac-made work: %+v", name, d) |
| + } |
| + in.AutoMergeCI, in.AutoMergeSensitive = true, true |
| + if d := Decide(in); d.Class != ClassAsk { |
| + t.Fatalf("%s: a standing setting merged Mac-made work: %+v", name, d) |
| + } |
| + in.Person = true |
| + if d := Decide(in); d.Class != ClassAct { |
| + t.Fatalf("%s: the person's Merge: %+v", name, d) |
| + } |
| + } |
| +} |
diff --git a/internal/equipo/work_pages.go b/internal/equipo/work_pages.go| index 026f4c2e..edb6aeed 100644 |
| --- a/internal/equipo/work_pages.go |
| +++ b/internal/equipo/work_pages.go |
| @@ -234,6 +234,11 @@ func taskLineOf(t wire.Task, viewer string) taskLine { |
| v.StageLine = copyText("work.checks.waiting_sandbox") |
| case wire.NeedsMacRunner, wire.NeedsMacEngineering: |
| v.StageLine = copyText("work.needs." + t.NeedsYou) |
| + case wire.NeedsMacConnection, wire.NeedsMacUpdate: |
| + // The Mac (or the primary) it waits for, by name. |
| + if s := lastStep(t); s != nil { |
| + v.StageLine = fmt.Sprintf(copyText("work.needs."+t.NeedsYou), s.RunnerLabel) |
| + } |
| case wire.NeedsBranchMoved: |
| // What was checked and reviewed is not what the branch holds now: |
| // none of it is shown beside the branch's link. |
diff --git a/internal/equipo/work_views.go b/internal/equipo/work_views.go| index 7906d3ba..8bd13165 100644 |
| --- a/internal/equipo/work_views.go |
| +++ b/internal/equipo/work_views.go |
| @@ -260,7 +260,7 @@ func needsViewer(t wire.Task, viewer string, card *wire.Card) bool { |
| return true |
| } |
| switch t.NeedsYou { |
| - case wire.NeedsRetry, wire.NeedsReviewBlocked, wire.NeedsFixRounds, wire.NeedsBranchMoved, wire.NeedsMergeConflict, wire.NeedsMachineRemoved, wire.NeedsMacSandbox, wire.NeedsMacRunner, wire.NeedsMacEngineering, wire.NeedsDirection: |
| + case wire.NeedsRetry, wire.NeedsReviewBlocked, wire.NeedsFixRounds, wire.NeedsBranchMoved, wire.NeedsMergeConflict, wire.NeedsMachineRemoved, wire.NeedsMacSandbox, wire.NeedsMacRunner, wire.NeedsMacEngineering, wire.NeedsMacConnection, wire.NeedsMacUpdate, wire.NeedsDirection: |
| return true |
| case wire.NeedsMerge, wire.NeedsHeld: |
| return card != nil |
| @@ -274,7 +274,7 @@ func needsSomeone(t wire.Task) bool { |
| return !wire.FinalStage(t.Stage) |
| } |
| switch t.NeedsYou { |
| - case wire.NeedsRetry, wire.NeedsReviewBlocked, wire.NeedsFixRounds, wire.NeedsBranchMoved, wire.NeedsMergeConflict, wire.NeedsMachineRemoved, wire.NeedsMacSandbox, wire.NeedsMacRunner, wire.NeedsMacEngineering, wire.NeedsDirection: |
| + case wire.NeedsRetry, wire.NeedsReviewBlocked, wire.NeedsFixRounds, wire.NeedsBranchMoved, wire.NeedsMergeConflict, wire.NeedsMachineRemoved, wire.NeedsMacSandbox, wire.NeedsMacRunner, wire.NeedsMacEngineering, wire.NeedsMacConnection, wire.NeedsMacUpdate, wire.NeedsDirection: |
| return !wire.FinalStage(t.Stage) |
| } |
| return false |
| @@ -811,6 +811,21 @@ func decisionOf(t wire.Task, v taskLine) *decisionView { |
| // A Mac runner takes only checks so far: the change waits, and |
| // never goes to Linux. |
| d.Why, d.Ask, d.Cancel = copyText("work.decide.mac_engineering_why"), copyText("work.decide.mac_engineering_ask"), v.Cancel |
| + case wire.NeedsMacConnection, wire.NeedsMacUpdate: |
| + // A Mac fits but cannot make the change yet: what it lacks, as |
| + // its Engineering status says now, or the update it (or the |
| + // primary) needs. It starts by itself; Cancel stays. |
| + if s := lastStep(t); s != nil { |
| + key := "work.decide.mac_update_why" |
| + if t.NeedsYou == wire.NeedsMacConnection { |
| + state := wire.EngineeringNoConnection |
| + if s.EngineeringStatus != nil && s.EngineeringStatus.State != wire.EngineeringReady { |
| + state = s.EngineeringStatus.State |
| + } |
| + key = "work.decide.mac_connection_why." + state |
| + } |
| + d.Why, d.Ask, d.Cancel = fmt.Sprintf(copyText(key), s.RunnerLabel), fmt.Sprintf(copyText("work.decide.mac_wait_ask"), s.RunnerLabel), v.Cancel |
| + } |
| case wire.NeedsMacSandbox: |
| // Not a failure: the checks wait, and run by themselves once the |
| // Mac's sandbox is proven. Only the creator may choose otherwise. |
diff --git a/internal/thintest/instance.go b/internal/thintest/instance.go| index 134ceb6d..02e7d601 100644 |
| --- a/internal/thintest/instance.go |
| +++ b/internal/thintest/instance.go |
| @@ -52,6 +52,8 @@ type Instance struct { |
| Store *equipo.Store |
| // NoExecution leaves EQUIPO_EXECUTION_ENABLED off after a Restart. |
| NoExecution bool |
| + // MacEngineering is EQUIPO_MAC_ENGINEERING from the next start. |
| + MacEngineering bool |
| // AssistantHosts is EQUIPO_ASSISTANT_HOSTS. Providers are served |
| // after the base and team providers (an in-process write that takes |
| // a client key, which Base's contract cannot offer yet). Both apply |
| @@ -129,7 +131,7 @@ func (i *Instance) serve(t testing.TB, l net.Listener) { |
| t.Fatal(err) |
| } |
| s := equipo.NewStore(d) |
| - router, err := equipo.RouterWithStore(d, equipo.Config{Origin: i.URL, InstanceKey: "thin-v1-test", AllowLoggedMail: true, ExecutionEnabled: !i.NoExecution, Owners: []string{Owner}, TestPeople: []string{".invalid"}, AssistantHosts: i.AssistantHosts, OficinaConnectOrigin: i.OficinaConnect, OficinaConnectClientID: i.OficinaClientID}, mail.Logged(i.logger), i.logger, s) |
| + router, err := equipo.RouterWithStore(d, equipo.Config{Origin: i.URL, InstanceKey: "thin-v1-test", AllowLoggedMail: true, ExecutionEnabled: !i.NoExecution, MacEngineering: i.MacEngineering, Owners: []string{Owner}, TestPeople: []string{".invalid"}, AssistantHosts: i.AssistantHosts, OficinaConnectOrigin: i.OficinaConnect, OficinaConnectClientID: i.OficinaClientID}, mail.Logged(i.logger), i.logger, s) |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/thintest/mac_engineering_contract_test.go b/internal/thintest/mac_engineering_contract_test.go| new file mode 100644 |
| index 00000000..f9710e49 |
| --- /dev/null |
| +++ b/internal/thintest/mac_engineering_contract_test.go |
| @@ -0,0 +1,931 @@ |
| +package thintest |
| + |
| +import ( |
| + "fmt" |
| + "slices" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Mac Engineering (Mac runners slice F, plan task 3): Engineering for a |
| +// repository whose gate needs Xcode is placed on a Mac worker that can |
| +// take it, behind EQUIPO_MAC_ENGINEERING. The primary resolves the |
| +// attempt's base first (prepare_base, then its base report), and only |
| +// then is the attempt dispatched to the worker with the inbound |
| +// Engineering transfer, in one transaction. The task is pinned to that |
| +// worker; review stays on the primary, and a Mac-made candidate is never |
| +// merged by policy. |
| + |
| +// sha is a distinct full SHA for n. |
| +func sha(n int) string { return fmt.Sprintf("%040x", n) } |
| + |
| +// macEngineerHello is a Mac worker's hello at protocol: seatbelt, the Mac |
| +// tags, and the Engineering status state (claude only when ready). With |
| +// f5, probe F5 is denied (Xcode's services denied under Claude's own |
| +// sandbox). |
| +func macEngineerHello(label, state string, protocol int, f5 bool) wire.Hello { |
| + h := WorkerHello(0) |
| + h.Protocol, h.Label, h.Sandbox = protocol, label, wire.SandboxSeatbelt |
| + caps := *h.Capabilities |
| + caps.Tags = []string{wire.TagMacOS, wire.TagXcode, wire.TagIOSSimulator} |
| + if state == wire.EngineeringReady { |
| + caps.Tags = append(caps.Tags, wire.TagClaude) |
| + } |
| + caps.Probes = []wire.Probe{{ID: "P1", Verdict: wire.ProbePassed}, {ID: "P2", Verdict: wire.ProbeDenied}, {ID: "P4", Verdict: wire.ProbePassed}} |
| + if protocol >= wire.ProtocolMacEngineering { |
| + caps.Engineering = &wire.EngineeringStatus{State: state} |
| + for _, id := range wire.EngineeringProbeIDs { |
| + verdict := wire.EngineeringProbeSuccess(id) |
| + if id == "F5" && !f5 { |
| + verdict = wire.ProbeFailed |
| + } |
| + caps.Probes = append(caps.Probes, wire.Probe{ID: id, Verdict: verdict}) |
| + } |
| + } |
| + h.Capabilities = &caps |
| + return h |
| +} |
| + |
| +// newMacRig is the runners rig with its primary at protocol 37, the |
| +// sample repository's gate needing Xcode, and the switch on. |
| +func newMacRig(t *testing.T) *runnersRig { return newMacRigAt(t, wire.ProtocolMacEngineering) } |
| + |
| +func newMacRigAt(t *testing.T, protocol int) *runnersRig { |
| + r := newRunnersRigAt(t, protocol) |
| + h := primaryHello(0) |
| + h.Protocol = protocol |
| + h.Catalog[0].NeedsMacOS = true |
| + r.primary.heartbeat(h) |
| + r.macEngineering(true) |
| + return r |
| +} |
| + |
| +// macEngineering is EQUIPO_MAC_ENGINEERING, for this process and the next. |
| +func (r *runnersRig) macEngineering(on bool) { |
| + r.inst.MacEngineering = on |
| + r.inst.Store.Chat().SetMacEngineering(on) |
| +} |
| + |
| +// newMacEngineer enrols and connects a Mac worker at protocol 37 whose |
| +// Engineering status is state. |
| +func (r *runnersRig) newMacEngineer(label, state string) *peer { |
| + return r.newMacEngineerAt(label, state, wire.ProtocolMacEngineering, false) |
| +} |
| + |
| +func (r *runnersRig) newMacEngineerAt(label, state string, protocol int, f5 bool) *peer { |
| + r.t.Helper() |
| + token := r.inst.EnrolRunner(r.t).Token |
| + fr, err := DialRunnerHello(r.ctx, r.inst.URL, token, macEngineerHello(label, state, protocol, f5)) |
| + if err != nil { |
| + r.t.Fatal(err) |
| + } |
| + r.t.Cleanup(fr.Close) |
| + r.creds[fr] = [2]string{token, label} |
| + return &peer{t: r.t, r: r.toolRig, fr: fr} |
| +} |
| + |
| +// macState says a new Engineering status (and tags) in w's hello. |
| +func (r *runnersRig) macState(w *peer, state string, f5 bool) { |
| + r.t.Helper() |
| + w.heartbeat(macEngineerHello(r.creds[w.fr][1], state, wire.ProtocolMacEngineering, f5)) |
| +} |
| + |
| +// fromPrimary is the next frame of kind sent to the primary, whichever of |
| +// the rig's readers took it off the socket, acked. |
| +func (r *runnersRig) fromPrimary(kind string) any { |
| + r.t.Helper() |
| + for i, h := range r.held { |
| + if h.f.Type == kind { |
| + r.held = append(r.held[:i:i], r.held[i+1:]...) |
| + r.primary.ack(h.f) |
| + return h.body |
| + } |
| + } |
| + _, body := r.primary.expect(kind) |
| + return body |
| +} |
| + |
| +// mailbox counts a runner's commands of kind, acked or not. |
| +func (r *runnersRig) mailbox(runner, kind string) int { |
| + r.t.Helper() |
| + var n int |
| + if err := r.inst.DB.Writer().QueryRow("SELECT count(*) FROM runner_commands WHERE runner_id = ? AND kind = ?", runner, kind).Scan(&n); err != nil { |
| + r.t.Fatal(err) |
| + } |
| + return n |
| +} |
| + |
| +// mailboxHas counts a runner's commands whose body contains text. |
| +func (r *runnersRig) mailboxHas(runner, text string) int { |
| + r.t.Helper() |
| + var n int |
| + if err := r.inst.DB.Writer().QueryRow("SELECT count(*) FROM runner_commands WHERE runner_id = ? AND instr(body, ?) > 0", runner, text).Scan(&n); err != nil { |
| + r.t.Fatal(err) |
| + } |
| + return n |
| +} |
| + |
| +// macTask records and starts a task in the Mac repository. |
| +func (r *runnersRig) macTask(title string) string { |
| + r.t.Helper() |
| + task := taskID(r.t, r.call("c-"+title, wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": title, "brief": "b"})) |
| + r.call("s-"+title, wire.ToolStartTask, map[string]string{"task": task, "brief": "go"}) |
| + return task |
| +} |
| + |
| +// prepared is the primary's prepare_base for the task's newest |
| +// Engineering attempt. |
| +func (r *runnersRig) prepared(task string) *wire.PrepareBaseCommand { |
| + r.t.Helper() |
| + pb := r.fromPrimary(wire.FramePrepareBase).(*wire.PrepareBaseCommand) |
| + if pb.TaskID != task || !pb.Valid() || !strings.HasSuffix(pb.Repo, "oficina/sample") { |
| + r.t.Fatalf("prepare_base %+v", pb) |
| + } |
| + return pb |
| +} |
| + |
| +// based answers prepare_base from the primary's connection. |
| +func (r *runnersRig) based(pb *wire.PrepareBaseCommand, base string) { |
| + r.t.Helper() |
| + r.primary.send(wire.FrameBase, wire.BaseReport{TaskID: pb.TaskID, StepID: pb.StepID, Attempt: pb.Attempt, BaseSHA: base}) |
| +} |
| + |
| +// newestEngineering is the task's newest Engineering step. |
| +func (r *runnersRig) newestEngineering(task string) wire.Step { |
| + r.t.Helper() |
| + k, err := r.client.Task(r.ctx, task) |
| + if err != nil { |
| + r.t.Fatal(err) |
| + } |
| + for i := len(k.Steps) - 1; i >= 0; i-- { |
| + if k.Steps[i].Specialist == wire.SpecialistEngineering { |
| + return k.Steps[i] |
| + } |
| + } |
| + r.t.Fatalf("no engineering step: %+v", k.Steps) |
| + return wire.Step{} |
| +} |
| + |
| +func (r *runnersRig) task(id string) wire.Task { |
| + r.t.Helper() |
| + k, err := r.client.Task(r.ctx, id) |
| + if err != nil { |
| + r.t.Fatal(err) |
| + } |
| + return k |
| +} |
| + |
| +// engineeringTransfer is the inbound Engineering transfer the primary is |
| +// asked to upload for an attempt on w. |
| +func (r *runnersRig) engineeringTransfer(w *peer, d *wire.DispatchCommand) wire.TransferHeader { |
| + r.t.Helper() |
| + h := r.fromPrimary(wire.FrameSendPack).(*wire.SendPackCommand).Transfer |
| + if h.Kind != wire.TransferKindEngineering || h.Direction != wire.TransferInbound || h.StepID != d.StepID || h.Attempt != d.Attempt || h.BaseSHA != d.BaseSHA || !h.Valid() { |
| + r.t.Fatalf("engineering transfer %+v for %+v", h, d) |
| + } |
| + return h |
| +} |
| + |
| +// workerCommitted runs w's Engineering attempt d to a commit: started, |
| +// committed (the outbound transfer opens for exactly that candidate), its |
| +// pack sent, which reaches the primary with a publish command. With done, |
| +// the worker's final report comes before the pack. |
| +func (r *runnersRig) workerCommitted(w *peer, d *wire.DispatchCommand, cand string, done bool) *wire.PublishCommand { |
| + r.t.Helper() |
| + if !w.lease(d.StepID, d.Attempt) { |
| + r.t.Fatal("start refused") |
| + } |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, BaseSHA: d.BaseSHA, Findings: []wire.Finding{}}) |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, CandidateSHA: cand, Phase: wire.OutcomeCommitted, Findings: []wire.Finding{}}) |
| + _, body := w.expect(wire.FrameSendPack) |
| + h := body.(*wire.SendPackCommand).Transfer |
| + if h.Direction != wire.TransferOutbound || h.CandidateSHA != cand || h.BaseSHA != d.BaseSHA || h.Kind != "" || h.Attempt != d.Attempt { |
| + r.t.Fatalf("outbound header %+v", h) |
| + } |
| + if done { |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepDone, CandidateSHA: cand, Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + } |
| + w.send(wire.FrameBlob, chunk(h, []byte("PACK commit"))) |
| + r.fromPrimary(wire.FrameBlob) |
| + pub := r.fromPrimary(wire.FramePublish).(*wire.PublishCommand) |
| + if pub.CandidateSHA != cand || pub.Transfer != h.ID || pub.StepID != d.StepID || pub.Attempt != d.Attempt { |
| + r.t.Fatalf("publish %+v", pub) |
| + } |
| + return pub |
| +} |
| + |
| +// macDispatch is the first Engineering attempt of a new Mac task on w: |
| +// prepared, based on base, dispatched with its transfer. |
| +func (r *runnersRig) macDispatch(w *peer, title, base string) (string, *wire.DispatchCommand) { |
| + r.t.Helper() |
| + task := r.macTask(title) |
| + r.based(r.prepared(task), base) |
| + _, body := w.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + if d.TaskID != task || d.Specialist != wire.SpecialistEngineering || d.BaseSHA != base || d.RunnerID != w.fr.Welcome.RunnerID { |
| + r.t.Fatalf("dispatch %+v", d) |
| + } |
| + r.engineeringTransfer(w, d) |
| + return task, d |
| +} |
| + |
| +// macCandidate is a Mac task whose first Engineering attempt ran on w and |
| +// whose candidate cand the primary published. |
| +func (r *runnersRig) macCandidate(w *peer, title, base, cand string) (string, *wire.DispatchCommand) { |
| + r.t.Helper() |
| + task, d := r.macDispatch(w, title, base) |
| + pub := r.workerCommitted(w, d, cand, true) |
| + r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: task, StepID: d.StepID, Attempt: d.Attempt, CandidateSHA: cand, Pushed: true}) |
| + if k := r.task(task); k.CandidateSHA != cand || k.EngineeringRunner != w.fr.Welcome.RunnerID { |
| + r.t.Fatalf("published %+v", k) |
| + } |
| + return task, d |
| +} |
| + |
| +// peerOf is the peer runner id is, of those given. |
| +func peerOf(id string, ps ...*peer) *peer { |
| + for _, p := range ps { |
| + if p.fr.Welcome.RunnerID == id { |
| + return p |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +// macChecked takes the checks dispatch of the task from whichever of ws |
| +// it was placed on, with its relay. |
| +func (r *runnersRig) macChecked(task string, ws ...*peer) (*peer, *wire.DispatchCommand) { |
| + r.t.Helper() |
| + s := r.newest(task, wire.SpecialistChecks) |
| + w := peerOf(s.RunnerID, ws...) |
| + if w == nil { |
| + r.t.Fatalf("checks not on a Mac worker: %+v", s) |
| + } |
| + _, body := w.expect(wire.FrameDispatch) |
| + c := body.(*wire.DispatchCommand) |
| + if c.Specialist != wire.SpecialistChecks || c.TaskID != task || c.StepID != s.ID || c.Attempt != s.Attempt { |
| + r.t.Fatalf("checks dispatch %+v for %+v", c, s) |
| + } |
| + r.fromPrimary(wire.FrameSendPack) |
| + return w, c |
| +} |
| + |
| +// 1. The first Engineering step of Mac work: prepare_base to the primary |
| +// first, nothing else; on its base, the dispatch to the worker and the |
| +// inbound Engineering transfer (base only) are written in one |
| +// transaction, and the task is pinned to the worker. |
| +func TestContractMacEngineeringPlacedOnWorker(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| + task := r.macTask("iOS settings") |
| + pb := r.prepared(task) |
| + if pb.Attempt != 1 || pb.Rebase || pb.FromBase != "" || pb.CandidateSHA != "" { |
| + t.Fatalf("prepare_base %+v", pb) |
| + } |
| + s := r.engineeringStep(task) |
| + if s.State != wire.StepQueued || s.Placement != wire.PlacementBase || s.RunnerID != "" || s.BaseSHA != "" || s.ID != pb.StepID { |
| + t.Fatalf("waiting for the base: %+v", s) |
| + } |
| + // Nothing goes to the worker, and no transfer opens, before the base |
| + // is bound. |
| + w.none(wire.FrameDispatch, 150*time.Millisecond) |
| + r.primary.none(wire.FrameSendPack, 0) |
| + if n := r.mailbox(r.primary.fr.Welcome.RunnerID, wire.FrameSendPack) + r.mailbox(w.fr.Welcome.RunnerID, wire.FrameDispatch); n != 0 { |
| + t.Fatalf("%d commands before the base", n) |
| + } |
| + if n := r.mailbox(r.primary.fr.Welcome.RunnerID, wire.FrameDispatch); n != 0 { |
| + t.Fatal("Mac engineering dispatched to the Linux primary") |
| + } |
| + base := sha(1) |
| + r.based(pb, base) |
| + // The base report's transaction wrote both: they are there once it is |
| + // acked. |
| + if n, m := r.mailbox(r.primary.fr.Welcome.RunnerID, wire.FrameSendPack), r.mailbox(w.fr.Welcome.RunnerID, wire.FrameDispatch); n != 1 || m != 1 { |
| + t.Fatalf("after the base: %d send_pack, %d dispatch", n, m) |
| + } |
| + _, body := w.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + if d.Specialist != wire.SpecialistEngineering || d.StepID != pb.StepID || d.Attempt != 1 || d.BaseSHA != base || d.RunnerID != w.fr.Welcome.RunnerID || strings.Join(d.Needs, ",") != "macos,xcode,claude" || d.XcodeAccess != "" { |
| + t.Fatalf("dispatch %+v", d) |
| + } |
| + h := r.engineeringTransfer(w, d) |
| + if h.OldBaseSHA != "" || h.CandidateSHA != "" || !slices.Equal(h.Commits(), []string{base}) || h.TaskID != task { |
| + t.Fatalf("transfer %+v", h) |
| + } |
| + k := r.task(task) |
| + if k.EngineeringRunner != w.fr.Welcome.RunnerID || k.BaseSHA != base { |
| + t.Fatalf("not pinned: %+v", k) |
| + } |
| + if s := r.engineeringStep(task); s.RunnerID != w.fr.Welcome.RunnerID || s.Placement != "" || s.BaseSHA != base || s.RunnerLabel != "Tito Studio" { |
| + t.Fatalf("placed %+v", s) |
| + } |
| + if !w.lease(d.StepID, 1) { |
| + t.Fatal("the worker's start was refused") |
| + } |
| + r.primary.none(wire.FrameDispatch, 0) |
| +} |
| + |
| +// 2. Unset, Mac Engineering waits exactly as mac-placement-wait left it, |
| +// with a Mac that could take it; set, the minute's placement takes it |
| +// from there. |
| +func TestContractMacEngineeringSwitchOff(t *testing.T) { |
| + r := newMacRig(t) |
| + r.macEngineering(false) |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| + task := r.macTask("iOS switch") |
| + w.none(wire.FrameDispatch, 150*time.Millisecond) |
| + r.primary.none(wire.FramePrepareBase, 0) |
| + r.primary.none(wire.FrameDispatch, 0) |
| + s := r.engineeringStep(task) |
| + if s.State != wire.StepQueued || s.Placement != wire.PlacementMacEngineering || s.RunnerID != "" || strings.Join(s.Needs, ",") != "macos,xcode" { |
| + t.Fatalf("switch off: %+v", s) |
| + } |
| + if got := r.needsYou(task); got != wire.NeedsMacEngineering { |
| + t.Fatalf("needs you %q", got) |
| + } |
| + r.macEngineering(true) |
| + if err := r.inst.Store.Chat().Place(r.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.prepared(task) |
| + if s := r.engineeringStep(task); s.Placement != wire.PlacementBase { |
| + t.Fatalf("switch on: %+v", s) |
| + } |
| +} |
| + |
| +// 3. A Mac that fits all but claude: each Engineering status is its own |
| +// wait (waiting_mac_connection, read from the Mac's status now) and |
| +// Needs-you line; once the status is ready, the step is placed. |
| +func TestContractMacEngineeringStatusWaits(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringNoConnection) |
| + task := r.macTask("iOS status") |
| + for _, state := range wire.EngineeringStates[1:] { |
| + r.macState(w, state, false) |
| + k := r.task(task) |
| + s := r.engineeringStep(task) |
| + if s.State != wire.StepQueued || s.Placement != wire.PlacementMacConnection || s.RunnerID != "" || s.RunnerLabel != "Tito Studio" || s.EngineeringStatus == nil || s.EngineeringStatus.State != state { |
| + t.Fatalf("%s: %+v", state, s) |
| + } |
| + if k.NeedsYou != wire.NeedsMacConnection { |
| + t.Fatalf("%s: needs you %q", state, k.NeedsYou) |
| + } |
| + w.none(wire.FrameDispatch, 50*time.Millisecond) |
| + r.primary.none(wire.FramePrepareBase, 0) |
| + } |
| + r.macState(w, wire.EngineeringReady, false) |
| + pb := r.prepared(task) |
| + if s := r.engineeringStep(task); s.Placement != wire.PlacementBase || s.EngineeringStatus != nil || r.needsYou(task) != "" { |
| + t.Fatalf("ready: %+v", s) |
| + } |
| + r.based(pb, sha(3)) |
| + _, body := w.expect(wire.FrameDispatch) |
| + if d := body.(*wire.DispatchCommand); d.TaskID != task || d.BaseSHA != sha(3) { |
| + t.Fatalf("dispatch %+v", d) |
| + } |
| +} |
| + |
| +// 4. A worker below protocol 37 waits waiting_mac_update, naming the |
| +// worker; nothing of protocol 37 reaches either runner. |
| +func TestContractMacEngineeringOldWorker(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineerAt("Tito Studio", wire.EngineeringReady, wire.ProtocolChangeDiffs, false) |
| + task := r.macTask("iOS old worker") |
| + w.none(wire.FrameDispatch, 150*time.Millisecond) |
| + s := r.engineeringStep(task) |
| + if s.State != wire.StepQueued || s.Placement != wire.PlacementMacUpdate || s.RunnerLabel != "Tito Studio" || s.RunnerID != "" { |
| + t.Fatalf("old worker: %+v", s) |
| + } |
| + if got := r.needsYou(task); got != wire.NeedsMacUpdate { |
| + t.Fatalf("needs you %q", got) |
| + } |
| + for _, id := range []string{w.fr.Welcome.RunnerID, r.primary.fr.Welcome.RunnerID} { |
| + if n := r.mailbox(id, wire.FramePrepareBase) + r.mailbox(id, wire.FrameDispatch) + r.mailboxHas(id, `"xcode_access"`) + r.mailboxHas(id, `"kind":"engineering"`); n != 0 { |
| + t.Fatalf("%d protocol 37 commands for %s", n, id) |
| + } |
| + } |
| +} |
| + |
| +// 4. A primary below protocol 37 cannot prepare a base: waiting_mac_update, |
| +// naming the primary, and it is sent nothing it cannot carry. |
| +func TestContractMacEngineeringOldPrimary(t *testing.T) { |
| + r := newMacRigAt(t, wire.ProtocolChangeDiffs) |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| + task := r.macTask("iOS old primary") |
| + w.none(wire.FrameDispatch, 150*time.Millisecond) |
| + s := r.engineeringStep(task) |
| + if s.State != wire.StepQueued || s.Placement != wire.PlacementMacUpdate || s.RunnerLabel != "docs-t1" || s.RunnerID != "" { |
| + t.Fatalf("old primary: %+v", s) |
| + } |
| + if got := r.needsYou(task); got != wire.NeedsMacUpdate { |
| + t.Fatalf("needs you %q", got) |
| + } |
| + for _, id := range []string{w.fr.Welcome.RunnerID, r.primary.fr.Welcome.RunnerID} { |
| + if n := r.mailbox(id, wire.FramePrepareBase) + r.mailbox(id, wire.FrameDispatch) + r.mailboxHas(id, `"xcode_access"`) + r.mailboxHas(id, `"kind":"engineering"`); n != 0 { |
| + t.Fatalf("%d protocol 37 commands for %s", n, id) |
| + } |
| + } |
| +} |
| + |
| +// 5. The only Mac that fits is offline: the step waits for it |
| +// (waiting_runner), raises Needs you runner_offline after 30 minutes and |
| +// keeps waiting; Cancel works; it never moves to Linux. |
| +func TestContractMacEngineeringOffline(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| + w.fr.Close() |
| + deadline := time.Now().Add(5 * time.Second) |
| + for { |
| + runners, err := r.client.Runners(r.ctx) |
| + offline := false |
| + for _, x := range runners.Items { |
| + offline = offline || x.ID == w.fr.Welcome.RunnerID && !x.Online |
| + } |
| + if err == nil && offline { |
| + break |
| + } |
| + if time.Now().After(deadline) { |
| + t.Fatalf("worker still online: %+v %v", runners, err) |
| + } |
| + time.Sleep(50 * time.Millisecond) |
| + } |
| + task := r.macTask("iOS offline") |
| + s := r.engineeringStep(task) |
| + if s.State != wire.StepQueued || s.Placement != wire.PlacementWaiting || s.RunnerLabel != "Tito Studio" || r.needsYou(task) != "" { |
| + t.Fatalf("waiting for the Mac: %+v needs %q", s, r.needsYou(task)) |
| + } |
| + clock := time.Now().UTC().Add(chat.OfflineLimit + time.Minute) |
| + r.inst.Store.Chat().SetClock(func() time.Time { return clock }) |
| + if err := r.inst.Store.Chat().Place(r.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + if s := r.engineeringStep(task); s.State != wire.StepQueued || s.Placement != wire.PlacementWaiting || s.Attempt != 1 { |
| + t.Fatalf("after the limit: %+v", s) |
| + } |
| + if got := r.needsYou(task); got != wire.NeedsRunnerOffline { |
| + t.Fatalf("needs you %q", got) |
| + } |
| + r.primary.none(wire.FrameDispatch, 50*time.Millisecond) |
| + r.primary.none(wire.FramePrepareBase, 0) |
| + if _, err := r.client.CancelTask(r.ctx, task); err != nil { |
| + t.Fatal(err) |
| + } |
| + if k := r.task(task); k.Stage != wire.StageCancelled || k.NeedsYou != "" { |
| + t.Fatalf("not cancelled: %+v", k) |
| + } |
| + if n := r.mailbox(r.primary.fr.Welcome.RunnerID, wire.FrameDispatch); n != 0 { |
| + t.Fatal("Mac engineering went to Linux") |
| + } |
| +} |
| + |
| +// 6. A fix round, a Retry, a republish and a rebase round all go to the |
| +// pinned worker while a second worker fits too. The fix round's base is |
| +// the published tip (no prepare_base); the rebase round's base comes from |
| +// the primary, and its transfer carries base, old base and candidate. |
| +func TestContractMacEngineeringPinHolds(t *testing.T) { |
| + r := newMacRig(t) |
| + r.shipsNo(r.project()) |
| + a := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| + base, c1, c2, tip := sha(1), sha(0xc1), sha(0xc2), sha(0x71) |
| + task, _ := r.macCandidate(a, "iOS pinned", base, c1) |
| + b := r.newMacEngineer("Mac B", wire.EngineeringReady) |
| + // Checks of c1 fail: a fix round, on c1, on Mac A. |
| + cw, c := r.macChecked(task, a, b) |
| + cw.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: c.StepID, Attempt: c.Attempt, State: wire.StepDone, CandidateSHA: c1, Checks: wire.ChecksFailed, Gate: "xcodebuild test", ExitCode: exit(65), Output: "FAILED", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + _, body := a.expect(wire.FrameDispatch) |
| + fix := body.(*wire.DispatchCommand) |
| + if fix.Specialist != wire.SpecialistEngineering || fix.Round != 1 || fix.BaseSHA != c1 || fix.Attempt != 1 { |
| + t.Fatalf("fix round %+v", fix) |
| + } |
| + if h := r.engineeringTransfer(a, fix); !slices.Equal(h.Commits(), []string{c1}) { |
| + t.Fatalf("fix transfer %+v", h) |
| + } |
| + if n := r.mailbox(r.primary.fr.Welcome.RunnerID, wire.FramePrepareBase); n != 1 { |
| + t.Fatalf("a fix round prepared a base: %d", n) |
| + } |
| + // It fails; Retry: Mac A again, from the same base. |
| + if !a.lease(fix.StepID, 1) { |
| + t.Fatal("fix round refused") |
| + } |
| + a.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: fix.StepID, Attempt: 1, State: wire.StepFailed, Reason: "provider_failed", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + if acc, err := r.client.RetryTask(r.ctx, task); err != nil || acc.Attempt != 2 { |
| + t.Fatalf("retry %+v %v", acc, err) |
| + } |
| + _, body = a.expect(wire.FrameDispatch) |
| + retry := body.(*wire.DispatchCommand) |
| + if retry.StepID != fix.StepID || retry.Attempt != 2 || retry.BaseSHA != c1 { |
| + t.Fatalf("retry %+v", retry) |
| + } |
| + r.engineeringTransfer(a, retry) |
| + // Its push fails; Retry publishes the same commit again, on the |
| + // primary, running nothing on any Mac. |
| + pub := r.workerCommitted(a, retry, c2, true) |
| + if !r.primary.leasePublication(retry.StepID, 2, pub.Publication) { |
| + t.Fatal("publication refused") |
| + } |
| + r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: task, StepID: retry.StepID, Attempt: 2, CandidateSHA: c2, Pushed: false, Reason: "push_failed"}) |
| + if acc, err := r.client.RetryTask(r.ctx, task); err != nil || acc.Attempt != 2 { |
| + t.Fatalf("republish %+v %v", acc, err) |
| + } |
| + again := r.fromPrimary(wire.FramePublish).(*wire.PublishCommand) |
| + if again.CandidateSHA != c2 || again.Transfer != pub.Transfer { |
| + t.Fatalf("republish %+v", again) |
| + } |
| + a.none(wire.FrameDispatch, 50*time.Millisecond) |
| + b.none(wire.FrameDispatch, 0) |
| + r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: again.Publication, TaskID: task, StepID: retry.StepID, Attempt: 2, CandidateSHA: c2, Pushed: true}) |
| + // Checks pass on a Mac, review approves on the primary, the person |
| + // merges, and the merge conflicts: a rebase round, on Mac A. |
| + cw, c = r.macChecked(task, a, b) |
| + cw.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: c.StepID, Attempt: c.Attempt, State: wire.StepDone, CandidateSHA: c2, Checks: wire.ChecksPassed, Gate: "xcodebuild test", ExitCode: exit(0), Output: "ok", Termination: true, TerminationKind: wire.TerminationProcessGroup, ChecksSandbox: wire.SandboxSeatbelt, Findings: []wire.Finding{}}) |
| + rv := r.fromPrimary(wire.FrameDispatch).(*wire.DispatchCommand) |
| + if rv.Specialist != wire.SpecialistReview || rv.RunnerID != r.primary.fr.Welcome.RunnerID { |
| + t.Fatalf("review %+v", rv) |
| + } |
| + r.primary.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: rv.StepID, Attempt: rv.Attempt, State: wire.StepDone, BaseSHA: rv.BaseSHA, CandidateSHA: c2, Termination: true, Family: "codex", Account: "codex-a", Verdict: wire.VerdictApprove, ReviewLabel: wire.ReviewOtherFamily, Change: facts(rv), Findings: []wire.Finding{}, Summary: "Read it."}) |
| + card := r.mergeCardFor(task) |
| + if _, err := r.client.Answer(r.ctx, card.ID, wire.ChoiceMerge, card.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + m := r.fromPrimary(wire.FrameDispatch).(*wire.DispatchCommand) |
| + if m.Specialist != wire.SpecialistMerge || m.CandidateSHA != c2 { |
| + t.Fatalf("merge %+v", m) |
| + } |
| + r.primary.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: m.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: base, CandidateSHA: c2}) |
| + r.primary.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: m.StepID, Attempt: 1, State: wire.StepFailed, Reason: "merge_conflict", BaseSHA: base, CandidateSHA: c2, Termination: true}) |
| + pb := r.prepared(task) |
| + if !pb.Rebase || pb.FromBase != base || pb.CandidateSHA != c2 || pb.Attempt != 1 { |
| + t.Fatalf("rebase prepare_base %+v", pb) |
| + } |
| + r.based(pb, tip) |
| + _, body = a.expect(wire.FrameDispatch) |
| + rb := body.(*wire.DispatchCommand) |
| + if !rb.Rebase || rb.BaseSHA != tip || rb.FromBase != base || rb.CandidateSHA != c2 { |
| + t.Fatalf("rebase round %+v", rb) |
| + } |
| + h := r.engineeringTransfer(a, rb) |
| + if h.OldBaseSHA != base || h.CandidateSHA != c2 || !slices.Equal(h.Commits(), []string{tip, base, c2}) { |
| + t.Fatalf("rebase transfer %+v", h) |
| + } |
| + b.none(wire.FrameDispatch, 50*time.Millisecond) |
| + if n := r.mailboxHas(b.fr.Welcome.RunnerID, `"specialist":"engineering"`); n != 0 { |
| + t.Fatalf("Mac B got %d engineering dispatches", n) |
| + } |
| + for _, s := range r.task(task).Steps { |
| + if s.Specialist == wire.SpecialistEngineering && s.RunnerID != a.fr.Welcome.RunnerID { |
| + t.Fatalf("an engineering step off the pinned Mac: %+v", s) |
| + } |
| + } |
| +} |
| + |
| +// mergeCardFor waits for the task's open merge card. |
| +func (r *runnersRig) mergeCardFor(task string) wire.Card { |
| + r.t.Helper() |
| + deadline := time.Now().Add(5 * time.Second) |
| + for time.Now().Before(deadline) { |
| + for _, c := range r.mergeCards(task) { |
| + if c.State == wire.CardOpen { |
| + return c |
| + } |
| + } |
| + time.Sleep(20 * time.Millisecond) |
| + } |
| + r.t.Fatalf("no merge card for %s: %+v", task, r.task(task)) |
| + return wire.Card{} |
| +} |
| + |
| +// 7. The pinned worker loses claude mid-task: the next round waits for |
| +// it (waiting_mac_connection, naming it) and is never placed on the |
| +// second worker that fits; once it is ready again, it runs there. |
| +func TestContractMacEngineeringPinnedLostTag(t *testing.T) { |
| + r := newMacRig(t) |
| + a := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| + b := r.newMacEngineer("Mac B", wire.EngineeringReady) |
| + c1 := sha(0xc1) |
| + task, _ := r.macCandidate(a, "iOS lost tag", sha(1), c1) |
| + r.macState(a, wire.EngineeringSignedOut, false) |
| + cw, c := r.macChecked(task, a, b) |
| + cw.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: c.StepID, Attempt: c.Attempt, State: wire.StepDone, CandidateSHA: c1, Checks: wire.ChecksFailed, Gate: "xcodebuild test", ExitCode: exit(65), Output: "FAILED", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + s := r.newestEngineering(task) |
| + if s.Round != 1 || s.State != wire.StepQueued || s.Placement != wire.PlacementMacConnection || s.RunnerLabel != "Mac A" || s.EngineeringStatus == nil || s.EngineeringStatus.State != wire.EngineeringSignedOut { |
| + t.Fatalf("fix round with the pinned Mac signed out: %+v", s) |
| + } |
| + if got := r.needsYou(task); got != wire.NeedsMacConnection { |
| + t.Fatalf("needs you %q", got) |
| + } |
| + if err := r.inst.Store.Chat().Place(r.ctx); err != nil { |
| + t.Fatal(err) |
| + } |
| + b.none(wire.FrameDispatch, 100*time.Millisecond) |
| + a.none(wire.FrameDispatch, 0) |
| + r.macState(a, wire.EngineeringReady, false) |
| + _, body := a.expect(wire.FrameDispatch) |
| + if d := body.(*wire.DispatchCommand); d.StepID != s.ID || d.BaseSHA != c1 { |
| + t.Fatalf("fix round %+v", d) |
| + } |
| + b.none(wire.FrameDispatch, 0) |
| +} |
| + |
| +// 8. The pinned worker is removed while its fix round may run: the step |
| +// is quarantined (machine_removed) until the creator recovers it; Retry |
| +// then re-pins to a fitting Mac, or waits for one (waiting_mac), and is |
| +// never placed on the Linux primary. |
| +func TestContractMacEngineeringPinnedRemoved(t *testing.T) { |
| + r := newMacRig(t) |
| + a := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| + c1 := sha(0xc1) |
| + task, _ := r.macCandidate(a, "iOS removed", sha(1), c1) |
| + cw, c := r.macChecked(task, a) |
| + cw.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: c.StepID, Attempt: c.Attempt, State: wire.StepDone, CandidateSHA: c1, Checks: wire.ChecksFailed, Gate: "xcodebuild test", ExitCode: exit(65), Output: "FAILED", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + _, body := a.expect(wire.FrameDispatch) |
| + fix := body.(*wire.DispatchCommand) |
| + r.engineeringTransfer(a, fix) |
| + if !a.lease(fix.StepID, fix.Attempt) { |
| + t.Fatal("fix round refused") |
| + } |
| + r.remove(a.fr.Welcome.RunnerID, true) |
| + if s := r.newestEngineering(task); s.State != wire.StepFailed || s.Reason != "machine_removed" || r.needsYou(task) != wire.NeedsMachineRemoved { |
| + t.Fatalf("not quarantined: %+v", s) |
| + } |
| + if _, err := r.client.RecoverTask(r.ctx, task); err != nil { |
| + t.Fatal(err) |
| + } |
| + if acc, err := r.client.RetryTask(r.ctx, task); err != nil || acc.Attempt != 2 { |
| + t.Fatalf("retry %+v %v", acc, err) |
| + } |
| + s := r.newestEngineering(task) |
| + if s.State != wire.StepQueued || s.Placement != wire.PlacementMac || s.RunnerID != "" || r.needsYou(task) != wire.NeedsMacRunner { |
| + t.Fatalf("after recovery, no Mac: %+v", s) |
| + } |
| + r.primary.none(wire.FrameDispatch, 100*time.Millisecond) |
| + b := r.newMacEngineer("Mac B", wire.EngineeringReady) |
| + _, body = b.expect(wire.FrameDispatch) |
| + d := body.(*wire.DispatchCommand) |
| + if d.StepID != fix.StepID || d.Attempt != 2 || d.BaseSHA != c1 { |
| + t.Fatalf("re-pinned %+v", d) |
| + } |
| + r.engineeringTransfer(b, d) |
| + if k := r.task(task); k.EngineeringRunner != b.fr.Welcome.RunnerID { |
| + t.Fatalf("pin %q", k.EngineeringRunner) |
| + } |
| + for _, s := range r.task(task).Steps { |
| + if s.Specialist == wire.SpecialistEngineering && s.RunnerID == r.primary.fr.Welcome.RunnerID { |
| + t.Fatalf("engineering on the Linux primary: %+v", s) |
| + } |
| + } |
| + r.primary.none(wire.FrameDispatch, 0) |
| +} |
| + |
| +// 9. Only the primary's base report for the attempt waiting for it binds: |
| +// one from the worker, for an older attempt, after the attempt was |
| +// withdrawn, or after Cancel is refused and logged; a second report for |
| +// the same attempt does nothing; base_unavailable ends the attempt |
| +// failed, Needs you retry. |
| +func TestContractPrepareBase(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| + task := r.macTask("iOS base") |
| + pb := r.prepared(task) |
| + waiting := func(what string, attempt int64) { |
| + t.Helper() |
| + s := r.engineeringStep(task) |
| + if s.Placement != wire.PlacementBase || s.Attempt != attempt || s.BaseSHA != "" || s.RunnerID != "" { |
| + t.Fatalf("%s: %+v", what, s) |
| + } |
| + w.none(wire.FrameDispatch, 50*time.Millisecond) |
| + r.primary.none(wire.FrameSendPack, 0) |
| + } |
| + // From the worker's connection. |
| + w.send(wire.FrameBase, wire.BaseReport{TaskID: task, StepID: pb.StepID, Attempt: 1, BaseSHA: sha(1)}) |
| + waiting("worker's report", 1) |
| + if !strings.Contains(r.inst.Logs(), "base_refused: not the primary") { |
| + t.Fatalf("worker's report not logged: %s", r.inst.Logs()) |
| + } |
| + // The primary cannot resolve it: the attempt fails, Needs you retry. |
| + r.primary.send(wire.FrameBase, wire.BaseReport{TaskID: task, StepID: pb.StepID, Attempt: 1, Reason: wire.ReasonBaseUnavailable}) |
| + s := r.engineeringStep(task) |
| + if s.State != wire.StepFailed || s.Reason != wire.ReasonBaseUnavailable || !s.Terminated || s.Placement != "" || r.needsYou(task) != wire.NeedsRetry { |
| + t.Fatalf("base unavailable: %+v needs %q", s, r.needsYou(task)) |
| + } |
| + if acc, err := r.client.RetryTask(r.ctx, task); err != nil || acc.Attempt != 2 { |
| + t.Fatalf("retry %+v %v", acc, err) |
| + } |
| + pb2 := r.prepared(task) |
| + if pb2.Attempt != 2 || pb2.StepID != pb.StepID { |
| + t.Fatalf("second prepare_base %+v", pb2) |
| + } |
| + // A late report for the older attempt. |
| + r.based(pb, sha(2)) |
| + waiting("older attempt", 2) |
| + if !strings.Contains(r.inst.Logs(), "base_refused: attempt not current") { |
| + t.Fatal("older attempt's report not logged") |
| + } |
| + // The Mac is removed while the attempt waits for its base: the attempt |
| + // is withdrawn (the next waits for a Mac), and its report is refused. |
| + r.remove(w.fr.Welcome.RunnerID, false) |
| + if s := r.engineeringStep(task); s.Attempt != 3 || s.Placement != wire.PlacementMac { |
| + t.Fatalf("withdrawn: %+v", s) |
| + } |
| + r.based(pb2, sha(3)) |
| + if s := r.engineeringStep(task); s.Attempt != 3 || s.BaseSHA != "" || s.Placement != wire.PlacementMac { |
| + t.Fatalf("withdrawn attempt's base bound: %+v", s) |
| + } |
| + if strings.Count(r.inst.Logs(), "base_refused: attempt not current") < 2 { |
| + t.Fatal("withdrawn attempt's report not logged") |
| + } |
| + // A Mac that fits enrols: the waiting attempt is prepared for it. |
| + w2 := r.newMacEngineer("Mac B", wire.EngineeringReady) |
| + if pb3 := r.prepared(task); pb3.Attempt != 3 { |
| + t.Fatalf("third prepare_base %+v", pb3) |
| + } |
| + // After Cancel. |
| + other := r.macTask("iOS cancelled") |
| + pc := r.prepared(other) |
| + if _, err := r.client.CancelTask(r.ctx, other); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.based(pc, sha(4)) |
| + if k := r.task(other); k.Stage != wire.StageCancelled || k.Steps[0].BaseSHA != "" { |
| + t.Fatalf("cancelled task's base bound: %+v", k) |
| + } |
| + if !strings.Contains(r.inst.Logs(), "base_refused: task ended") { |
| + t.Fatal("cancelled task's report not logged") |
| + } |
| + w2.none(wire.FrameDispatch, 50*time.Millisecond) |
| + // A second report for the same attempt changes nothing. |
| + third := r.macTask("iOS twice") |
| + pt := r.prepared(third) |
| + r.based(pt, sha(5)) |
| + w2.expect(wire.FrameDispatch) |
| + r.based(pt, sha(6)) |
| + if s := r.engineeringStep(third); s.BaseSHA != sha(5) || s.Attempt != 1 { |
| + t.Fatalf("second report rebound: %+v", s) |
| + } |
| + w2.none(wire.FrameDispatch, 50*time.Millisecond) |
| + if n := r.mailbox(r.primary.fr.Welcome.RunnerID, wire.FrameSendPack); n != 1 { |
| + t.Fatalf("%d transfers", n) |
| + } |
| +} |
| + |
| +// 10. Xcode access for Engineering follows the proof: sent only to a Mac |
| +// the instance holds sandbox-proven (seatbelt, untainted) whose probe F5 |
| +// is denied. Without F5, with the sandbox not proven, or tainted, none. |
| +func TestContractMacEngineeringXcodeAccess(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineerAt("Tito Studio", wire.EngineeringReady, wire.ProtocolMacEngineering, true) |
| + access := func(title string) string { |
| + t.Helper() |
| + task := r.macTask(title) |
| + r.based(r.prepared(task), sha(1)) |
| + _, body := w.expect(wire.FrameDispatch) |
| + r.fromPrimary(wire.FrameSendPack) |
| + return body.(*wire.DispatchCommand).XcodeAccess |
| + } |
| + if got := access("iOS proven"); got != wire.XcodeAccessSandboxed { |
| + t.Fatalf("proven with F5 denied: %q", got) |
| + } |
| + r.macState(w, wire.EngineeringReady, false) |
| + if got := access("iOS no F5"); got != "" { |
| + t.Fatalf("without F5: %q", got) |
| + } |
| + h := macEngineerHello("Tito Studio", wire.EngineeringReady, wire.ProtocolMacEngineering, true) |
| + h.Sandbox = wire.SandboxNone |
| + w.heartbeat(h) |
| + if got := access("iOS unproven"); got != "" { |
| + t.Fatalf("sandbox not proven: %q", got) |
| + } |
| + r.macState(w, wire.EngineeringReady, true) |
| + if _, err := r.inst.DB.Writer().Exec("UPDATE runners SET tainted_at = ? WHERE id = ?", time.Now().UTC(), w.fr.Welcome.RunnerID); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := access("iOS tainted"); got != "" { |
| + t.Fatalf("tainted: %q", got) |
| + } |
| +} |
| + |
| +// 11. A worker's Engineering reports: pushed is refused; committed opens |
| +// the outbound transfer for exactly that candidate; done waits for the |
| +// primary's published, in either order. |
| +func TestContractWorkerEngineeringReports(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| + base, cand := sha(1), sha(0xc1) |
| + task, d := r.macDispatch(w, "iOS reports", base) |
| + 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.StepRunning, BaseSHA: base, Findings: []wire.Finding{}}) |
| + // A worker claiming it pushed is refused: the step does not end. |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepDone, CandidateSHA: cand, Pushed: true, Termination: true, Findings: []wire.Finding{}}) |
| + if s := r.engineeringStep(task); s.State != wire.StepRunning || s.Pushed || s.CandidateSHA != "" { |
| + t.Fatalf("a worker's pushed counted: %+v", s) |
| + } |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, CandidateSHA: cand, Phase: wire.OutcomeCommitted, Findings: []wire.Finding{}}) |
| + _, body := w.expect(wire.FrameSendPack) |
| + h := body.(*wire.SendPackCommand).Transfer |
| + if h.Direction != wire.TransferOutbound || h.CandidateSHA != cand || h.BaseSHA != base || h.Kind != "" || h.Attempt != 1 { |
| + t.Fatalf("outbound %+v", h) |
| + } |
| + // Another committed, for another commit, opens nothing more. |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, CandidateSHA: sha(0xbad), Phase: wire.OutcomeCommitted, Findings: []wire.Finding{}}) |
| + w.none(wire.FrameSendPack, 50*time.Millisecond) |
| + if s := r.engineeringStep(task); s.CandidateSHA != cand { |
| + t.Fatalf("candidate moved: %+v", s) |
| + } |
| + // Done first: nothing is judged until the primary has published. |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepDone, CandidateSHA: cand, Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + w.send(wire.FrameBlob, chunk(h, []byte("PACK commit"))) |
| + r.fromPrimary(wire.FrameBlob) |
| + pub := r.fromPrimary(wire.FramePublish).(*wire.PublishCommand) |
| + if k := r.task(task); k.Steps[0].Pushed || k.CandidateSHA != "" || len(k.Steps) != 1 { |
| + t.Fatalf("judged before publication: %+v", k) |
| + } |
| + r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: task, StepID: d.StepID, Attempt: 1, CandidateSHA: cand, Pushed: true}) |
| + if k := r.task(task); !k.Steps[0].Pushed || k.CandidateSHA != cand { |
| + t.Fatalf("after publication %+v", k) |
| + } |
| + r.macChecked(task, w) |
| +} |
| + |
| +// The primary may publish before the worker's final report: that report |
| +// keeps the primary's publication, and checks follow. |
| +func TestContractPublishedBeforeWorkerDone(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| + cand := sha(0xc) |
| + task, d := r.macDispatch(w, "Published early", sha(1)) |
| + pub := r.workerCommitted(w, d, cand, false) |
| + r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: task, StepID: d.StepID, Attempt: 1, CandidateSHA: cand, Pushed: true}) |
| + w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepDone, CandidateSHA: cand, Termination: true, Findings: []wire.Finding{}}) |
| + k := r.task(task) |
| + if !k.Steps[0].Pushed || k.Steps[0].Publication != wire.PublicationPublished || k.CandidateSHA != cand { |
| + t.Fatalf("the worker's report cleared the publication: %+v", k.Steps[0]) |
| + } |
| + if _, c := r.macChecked(task, w); c.CandidateSHA != cand { |
| + t.Fatalf("checks %+v", c) |
| + } |
| +} |
| + |
| +// 12. Review of a Mac-made candidate is placed on the primary after |
| +// publication, never on a Mac. |
| +func TestContractReviewStaysOnPrimary(t *testing.T) { |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| + cand := sha(0xc1) |
| + task, _ := r.macCandidate(w, "iOS review", sha(1), cand) |
| + cw, c := r.macChecked(task, w) |
| + cw.send(wire.FrameStep, passed(task, c.StepID, c.Attempt, cand)) |
| + rv := r.fromPrimary(wire.FrameDispatch).(*wire.DispatchCommand) |
| + if rv.Specialist != wire.SpecialistReview || rv.RunnerID != r.primary.fr.Welcome.RunnerID || rv.CandidateSHA != cand || len(rv.Needs) != 0 { |
| + t.Fatalf("review %+v", rv) |
| + } |
| + w.none(wire.FrameDispatch, 50*time.Millisecond) |
| + for _, s := range r.task(task).Steps { |
| + if s.Specialist == wire.SpecialistReview && s.RunnerID != r.primary.fr.Welcome.RunnerID { |
| + t.Fatalf("review off the primary %+v", s) |
| + } |
| + } |
| +} |
| + |
| +// 12. Ready to merge never merges a Mac-made candidate by policy (a |
| +// worker cannot run certified base gates): work that would merge on its |
| +// own from the primary asks; the person's Merge acts. |
| +func TestContractMacMadeNeverAutoMerges(t *testing.T) { |
| + r := newMacRig(t) |
| + r.shipsNo(r.project()) |
| + w := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| + cand := sha(0xc1) |
| + task, _ := r.macCandidate(w, "iOS swipe", sha(1), cand) |
| + cw, c := r.macChecked(task, w) |
| + // Not run, for an environment reason: small, ordinary, approved work |
| + // that would merge on its own were it made on the primary. |
| + cw.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: c.StepID, Attempt: c.Attempt, State: wire.StepDone, CandidateSHA: cand, Checks: wire.ChecksCannotRun, Reason: "needs_macos", Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| + rv := r.fromPrimary(wire.FrameDispatch).(*wire.DispatchCommand) |
| + r.primary.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: rv.StepID, Attempt: rv.Attempt, State: wire.StepDone, BaseSHA: rv.BaseSHA, CandidateSHA: cand, Termination: true, Family: "codex", Account: "codex-a", Verdict: wire.VerdictApprove, ReviewLabel: wire.ReviewOtherFamily, Change: facts(rv), Findings: []wire.Finding{}, Summary: "Read it."}) |
| + card := r.mergeCardFor(task) |
| + k := r.task(task) |
| + if k.Stage != wire.StageReadyToMerge || k.MergeDecision == nil || k.MergeDecision.Class != "ask" { |
| + t.Fatalf("a Mac-made candidate was not asked about: %+v", k.MergeDecision) |
| + } |
| + made := false |
| + for _, c := range k.MergeDecision.Reasons { |
| + made = made || c.Name == "made_on_primary" && !c.OK |
| + } |
| + if !made { |
| + t.Fatalf("decision %+v", k.MergeDecision) |
| + } |
| + if n := r.mailbox(r.primary.fr.Welcome.RunnerID, wire.FrameDispatch); n != 1 { |
| + // Review, then nothing: no merge was dispatched. |
| + t.Fatalf("%d dispatches to the primary", n) |
| + } |
| + if _, err := r.client.Answer(r.ctx, card.ID, wire.ChoiceMerge, card.Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + if m := r.fromPrimary(wire.FrameDispatch).(*wire.DispatchCommand); m.Specialist != wire.SpecialistMerge || m.CandidateSHA != cand { |
| + t.Fatalf("the person's merge %+v", m) |
| + } |
| +} |
diff --git a/internal/thintest/review1_contract_test.go b/internal/thintest/review1_contract_test.go| index f11788da..bb1427ae 100644 |
| --- a/internal/thintest/review1_contract_test.go |
| +++ b/internal/thintest/review1_contract_test.go |
| @@ -190,39 +190,6 @@ func TestContractWithdrawnProofAfterFailure(t *testing.T) { |
| } |
| } |
| -// The primary may publish before the worker's final report: that report |
| -// keeps the primary's publication, and checks follow. |
| -func TestContractPublishedBeforeWorkerDone(t *testing.T) { |
| - r := newRunnersRig(t) |
| - w, _ := r.newWorker("Mac A") |
| - task := taskID(t, r.call("c-early", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Published early", "brief": "b"})) |
| - r.pinWorker(task, w) |
| - r.call("s-early", wire.ToolStartTask, map[string]string{"task": task, "brief": "go"}) |
| - _, body := w.expect(wire.FrameDispatch) |
| - d := body.(*wire.DispatchCommand) |
| - if !w.lease(d.StepID, d.Attempt) { |
| - t.Fatal("start refused") |
| - } |
| - sha := strings.Repeat("c", 40) |
| - w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: strings.Repeat("1", 40), Findings: []wire.Finding{}}) |
| - w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, CandidateSHA: sha, Phase: "committed", Findings: []wire.Finding{}}) |
| - _, body = w.expect(wire.FrameSendPack) |
| - h := body.(*wire.SendPackCommand).Transfer |
| - w.send(wire.FrameBlob, chunk(h, []byte("PACK commit"))) |
| - _, body = r.primary.expect(wire.FramePublish) |
| - pub := body.(*wire.PublishCommand) |
| - r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: pub.Publication, TaskID: task, StepID: d.StepID, Attempt: 1, CandidateSHA: sha, Pushed: true}) |
| - w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: 1, State: wire.StepDone, CandidateSHA: sha, Termination: true, Findings: []wire.Finding{}}) |
| - k, _ := r.client.Task(r.ctx, task) |
| - if !k.Steps[0].Pushed || k.Steps[0].Publication != wire.PublicationPublished || k.CandidateSHA != sha { |
| - t.Fatalf("the worker's report cleared the publication: %+v", k.Steps[0]) |
| - } |
| - _, body = r.expect(wire.FrameDispatch) |
| - if c := body.(*wire.DispatchCommand); c.Specialist != wire.SpecialistChecks || c.CandidateSHA != sha { |
| - t.Fatalf("checks %+v", c) |
| - } |
| -} |
| - |
| // A pack too large to relay is declared by its chunk count, and both ends |
| // read it the same way: the checks end as not run (checks_unavailable). |
| func TestContractTransferDeclaredTooLarge(t *testing.T) { |
diff --git a/internal/thintest/transfer_contract_test.go b/internal/thintest/transfer_contract_test.go| index 4314b22d..a04fa62b 100644 |
| --- a/internal/thintest/transfer_contract_test.go |
| +++ b/internal/thintest/transfer_contract_test.go |
| @@ -110,34 +110,19 @@ func TestContractTransferTooLarge(t *testing.T) { |
| } |
| } |
| -// pinWorker makes the next Engineering step of a task run on a worker (the |
| -// slice F placement; here a test seam on the pin). |
| -func (r *runnersRig) pinWorker(task string, w *peer) { |
| - r.t.Helper() |
| - if _, err := r.inst.DB.Writer().Exec("UPDATE chat_tasks SET engineering_runner = ? WHERE id = ?", w.fr.Welcome.RunnerID, task); err != nil { |
| - r.t.Fatal(err) |
| - } |
| -} |
| - |
| -// workerCommit runs a task's Engineering step on the worker to a commit |
| +// workerCommit runs a Mac task's Engineering step on the worker (placed |
| +// there by Mac Engineering, its base prepared by the primary) to a commit |
| // and its pack, which reaches the primary with a publish command. |
| func (r *runnersRig) workerCommit(w *peer, title string) (task string, d *wire.DispatchCommand, sha string, pub *wire.PublishCommand) { |
| r.t.Helper() |
| - task = taskID(r.t, r.call("c-"+title, wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": title, "brief": "b"})) |
| - r.pinWorker(task, w) |
| - r.call("s-"+title, wire.ToolStartTask, map[string]string{"task": task, "brief": "go"}) |
| - _, body := w.expect(wire.FrameDispatch) |
| - d = body.(*wire.DispatchCommand) |
| - if d.Specialist != wire.SpecialistEngineering { |
| - r.t.Fatalf("dispatch %+v", d) |
| - } |
| + task, d = r.macDispatch(w, title, strings.Repeat("1", 40)) |
| if !w.lease(d.StepID, d.Attempt) { |
| r.t.Fatal("start refused") |
| } |
| sha = strings.Repeat("c", 40) |
| w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, BaseSHA: strings.Repeat("1", 40), Findings: []wire.Finding{}}) |
| w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepRunning, CandidateSHA: sha, Phase: "committed", Findings: []wire.Finding{}}) |
| - _, body = w.expect(wire.FrameSendPack) |
| + _, body := w.expect(wire.FrameSendPack) |
| h := body.(*wire.SendPackCommand).Transfer |
| if h.Direction != wire.TransferOutbound || h.CandidateSHA != sha { |
| r.t.Fatalf("outbound header %+v", h) |
| @@ -149,9 +134,8 @@ func (r *runnersRig) workerCommit(w *peer, title string) (task string, d *wire.D |
| } |
| w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepDone, CandidateSHA: sha, Termination: true, TerminationKind: wire.TerminationProcessGroup, Findings: []wire.Finding{}}) |
| w.send(wire.FrameBlob, chunk(h, []byte("PACK commit"))) |
| - r.primary.expect(wire.FrameBlob) |
| - _, body = r.primary.expect(wire.FramePublish) |
| - pub = body.(*wire.PublishCommand) |
| + r.fromPrimary(wire.FrameBlob) |
| + pub = r.fromPrimary(wire.FramePublish).(*wire.PublishCommand) |
| if pub.CandidateSHA != sha || pub.Transfer != h.ID || pub.StepID != d.StepID { |
| r.t.Fatalf("publish %+v", pub) |
| } |
| @@ -164,8 +148,8 @@ func (r *runnersRig) workerCommit(w *peer, title string) (task string, d *wire.D |
| // created. A failed push is Needs you retry, and Retry publishes the same |
| // commit again without running Engineering. |
| func TestContractPublication(t *testing.T) { |
| - r := newRunnersRig(t) |
| - w, _ := r.newWorker("Mac A") |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| task, d, sha, pub := r.workerCommit(w, "iOS fix") |
| // The worker claiming it pushed is refused. |
| w.send(wire.FrameStep, wire.StepReport{TaskID: task, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepDone, CandidateSHA: sha, Pushed: true, Termination: true, Findings: []wire.Finding{}}) |
| @@ -191,8 +175,7 @@ func TestContractPublication(t *testing.T) { |
| if err != nil || acc.Attempt != d.Attempt { |
| t.Fatalf("retry %+v %v", acc, err) |
| } |
| - _, body := r.primary.expect(wire.FramePublish) |
| - again := body.(*wire.PublishCommand) |
| + again := r.fromPrimary(wire.FramePublish).(*wire.PublishCommand) |
| if again.CandidateSHA != sha || again.Transfer != pub.Transfer || again.Publication == pub.Publication || again.Attempt != d.Attempt { |
| t.Fatalf("republish %+v", again) |
| } |
| @@ -202,8 +185,7 @@ func TestContractPublication(t *testing.T) { |
| t.Fatal("a superseded publication was confirmed") |
| } |
| r.primary.send(wire.FramePublished, wire.PublishedReport{Publication: again.Publication, TaskID: task, StepID: d.StepID, Attempt: d.Attempt, CandidateSHA: sha, Pushed: true}) |
| - _, body = r.expect(wire.FrameDispatch) |
| - if c := body.(*wire.DispatchCommand); c.Specialist != wire.SpecialistChecks || c.CandidateSHA != sha { |
| + if _, c := r.macChecked(task, w); c.CandidateSHA != sha { |
| t.Fatalf("checks after publication %+v", c) |
| } |
| if k, _ = r.client.Task(r.ctx, task); !k.Steps[0].Pushed || k.Steps[0].Publication != wire.PublicationPublished || k.CandidateSHA != sha || k.EngineeringRunner != w.fr.Welcome.RunnerID { |
| @@ -214,8 +196,8 @@ func TestContractPublication(t *testing.T) { |
| // Cancel after the pack arrived and before the push: the primary's |
| // confirmation right before it pushes is refused, so nothing is pushed. |
| func TestContractCancelBeforePublication(t *testing.T) { |
| - r := newRunnersRig(t) |
| - w, _ := r.newWorker("Mac A") |
| + r := newMacRig(t) |
| + w := r.newMacEngineer("Mac A", wire.EngineeringReady) |
| task, d, sha, pub := r.workerCommit(w, "iOS cancel") |
| if _, err := r.client.CancelTask(r.ctx, task); err != nil { |
| t.Fatal(err) |
diff --git a/internal/wire/tasks.go b/internal/wire/tasks.go| index 69b7a68d..c019be77 100644 |
| --- a/internal/wire/tasks.go |
| +++ b/internal/wire/tasks.go |
| @@ -317,6 +317,9 @@ type Step struct { |
| Placement string `json:"placement"` |
| Publication string `json:"publication"` |
| TerminationKind string `json:"termination_kind"` |
| + // EngineeringStatus is, while Placement is waiting_mac_connection, the |
| + // Engineering status the Mac it waits for (RunnerLabel) says now. |
| + EngineeringStatus *EngineeringStatus `json:"engineering_status,omitempty"` |
| // ChecksSandbox: seatbelt or none (ran outside the sandbox) for a |
| // worker's checks; absent for the primary's. |
| ChecksSandbox string `json:"checks_sandbox,omitempty"` |
| @@ -1146,6 +1149,9 @@ var StepReasons = map[string]bool{ |
| ReasonSandboxUnproven: true, |
| "transfer_refused": true, |
| "runner_offline": true, |
| + // Mac Engineering (slice F): the primary could not resolve the base of |
| + // an attempt on a worker; nothing ran. |
| + ReasonBaseUnavailable: true, |
| // machine_removed: the runner was removed while the step may have been |
| // running; nothing proves its end (only Recover settles it). |
| "machine_removed": true, |