| 1 | package equipo |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "amadan.net/oficina/equipo/internal/wire" |
| 8 | ) |
| 9 | |
| 10 | // Mac work waiting for a Mac runner, or for a Mac that can make changes, |
| 11 | // is the creator's to see under Needs you (2026-11-28): the decision says |
| 12 | // why in words, the line says what waits, and a waiting checks step does |
| 13 | // not read as running. Only the wait for a runner links setting up a Mac. |
| 14 | func TestMacWaitNeedsYou(t *testing.T) { |
| 15 | for _, c := range []struct { |
| 16 | need, specialist, placement, why, line, checks string |
| 17 | mac bool |
| 18 | }{ |
| 19 | {wire.NeedsMacRunner, wire.SpecialistChecks, wire.PlacementMac, "work.decide.mac_runner_why", "work.needs.mac_runner", "work.chip.waiting_mac", true}, |
| 20 | {wire.NeedsMacRunner, wire.SpecialistEngineering, wire.PlacementMac, "work.decide.mac_runner_why", "work.needs.mac_runner", "", true}, |
| 21 | {wire.NeedsMacEngineering, wire.SpecialistEngineering, wire.PlacementMacEngineering, "work.decide.mac_engineering_why", "work.needs.mac_engineering", "", false}, |
| 22 | } { |
| 23 | task := wire.Task{ID: "t1", Creator: "owner@example.com", Stage: wire.StageInProgress, NeedsYou: c.need, Steps: []wire.Step{{ID: "s1", Specialist: c.specialist, State: wire.StepQueued, Placement: c.placement, Attempt: 1}}} |
| 24 | if !needsViewer(task, "owner@example.com", nil) || !needsSomeone(task) || groupOf(task, "owner@example.com", nil) != "needs" { |
| 25 | t.Fatalf("%s: not under Needs you", c.need) |
| 26 | } |
| 27 | if needsViewer(task, "other@example.com", nil) { |
| 28 | t.Fatalf("%s: someone else's decision", c.need) |
| 29 | } |
| 30 | v := taskLineOf(task, "owner@example.com") |
| 31 | if v.StageLine != copyText(c.line) || copyText(c.line) == "" { |
| 32 | t.Fatalf("%s: stage line %q", c.need, v.StageLine) |
| 33 | } |
| 34 | if c.checks != "" && v.ChecksLine != copyText(c.checks) { |
| 35 | t.Fatalf("%s: checks line %q", c.need, v.ChecksLine) |
| 36 | } |
| 37 | v.Mine, v.Cancel = true, true |
| 38 | d := decisionOf(task, v) |
| 39 | if d == nil || d.Why != copyText(c.why) || d.Why == "" || d.Ask == "" || d.Mac != c.mac || !d.Cancel { |
| 40 | t.Fatalf("%s: decision %+v", c.need, d) |
| 41 | } |
| 42 | if r := waitReason(task, v); r == "" || strings.HasPrefix(r, "Needs you") { |
| 43 | t.Fatalf("%s: wait reason %q", c.need, r) |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |