oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "strings"
5 "testing"
6 "time"
7
8 "amadan.net/oficina/equipo/internal/wire"
9)
10
11// pausedTask is Paul's task on 2026-11-24 at noon in Dublin: Engineering
12// held for the Claude allowance, which resets at 21:00 UTC.
13func pausedTask(h wire.StepHold, p *wire.StepPaused) wire.Task {
14 return wire.Task{ID: "tk1", Title: "Swipe down to dismiss the keyboard on iOS", Stage: wire.StageInProgress, Creator: "paul@example.com",
15 Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering, State: wire.StepQueued, Attempt: 1, RunnerLabel: "Paul’s Mac mini", Hold: &h, Paused: p}}}
16}
17
18var paulNow = time.Date(2026, 11, 24, 12, 0, 0, 0, time.UTC)
19
20func dublinLoc(t *testing.T) *time.Location {
21 t.Helper()
22 loc, err := time.LoadLocation("Europe/Dublin")
23 if err != nil {
24 t.Fatal(err)
25 }
26 return loc
27}
28
29// The regression for Paul's case: not green and pulsing but Paused in
30// indigo; the lead names what stopped and when it resumes, in Dublin's
31// time and relative, with no UTC; and the action names Codex.
32func TestPaulsCaseOnTheReportCard(t *testing.T) {
33 reset := time.Date(2026, 11, 24, 21, 0, 0, 0, time.UTC)
34 used := 100
35 task := pausedTask(wire.StepHold{Reason: wire.HoldHeadroom, Connection: "claude-1", Provider: wire.ProviderClaude, ResetsAt: &reset, WakeAt: &reset, StepRevision: 4},
36 &wire.StepPaused{UsedPercent: &used, RunNow: &wire.RunNowOffer{Connection: "cn_codex", Provider: wire.ProviderCodex, Name: "Codex", Billing: wire.BillingSubscription}})
37 p := pauseOf(task, "paul@example.com", paulNow, dublinLoc(t))
38 if p == nil {
39 t.Fatal("no pause")
40 }
41 if p.Tone != "paused" || p.Stop != "Paused" {
42 t.Fatalf("tone %q stop %q", p.Tone, p.Stop)
43 }
44 if p.Strong != "Paused until 21:00 tonight" || p.Rest != " (in 9 hours): your Claude allowance has run out." {
45 t.Fatalf("lead %q %q", p.Strong, p.Rest)
46 }
47 if p.Next != "It carries on by itself then." {
48 t.Fatalf("next %q", p.Next)
49 }
50 if len(p.Actions) != 1 || p.Actions[0].Label != "Run it now with Codex" || p.Actions[0].Step != "s1" || p.Actions[0].Revision != 4 || p.Note != "Codex has room now" {
51 t.Fatalf("actions %+v note %q", p.Actions, p.Note)
52 }
53 if strings.Contains(p.Strong+p.Rest+p.Next, "UTC") {
54 t.Fatal("UTC on the card")
55 }
56 track := []trackStop{{Stage: wire.StageNoted, State: "done"}, {Stage: wire.StageInProgress, Label: "In progress", State: "current", Tone: "positive", Working: true, Live: true}}
57 pausedTrack(track, p)
58 if c := track[1]; c.Label != "Paused" || c.Tone != "paused" || c.Working || c.Live || c.Was != "In progress" {
59 t.Fatalf("stepper %+v", c)
60 }
61 // Someone else reading Paul's task sees why, and no button.
62 if q := pauseOf(task, "nora@example.com", paulNow, dublinLoc(t)); q == nil || len(q.Actions) != 0 || q.Note != "" || q.Strong != p.Strong {
63 t.Fatalf("a teammate's view %+v", q)
64 }
65}
66
67// Equipo keeps the last share for urgent work: Run it now on Claude.
68func TestPausedSavingTheLastShare(t *testing.T) {
69 reset := time.Date(2026, 11, 24, 21, 0, 0, 0, time.UTC)
70 used := 85
71 p := pauseOf(pausedTask(wire.StepHold{Reason: wire.HoldHeadroom, Connection: "claude-1", Provider: wire.ProviderClaude, ResetsAt: &reset, StepRevision: 1},
72 &wire.StepPaused{UsedPercent: &used, RunNow: &wire.RunNowOffer{Name: "Claude", Billing: wire.BillingSubscription, Same: true, LeftPercent: 15}}), "paul@example.com", paulNow, dublinLoc(t))
73 if p.Rest != " (in 9 hours): your Claude allowance is 85% used, so Equipo is keeping the rest for urgent work." || p.Actions[0].Label != "Run it now on Claude" || p.Note != "Uses some of the last 15%" {
74 t.Fatalf("%+v", p)
75 }
76}
77
78// Every reason the mockups list, by tone: indigo resumes by itself,
79// amber needs the person, red failed.
80func TestPauseTones(t *testing.T) {
81 loc := dublinLoc(t)
82 midnight := time.Date(2026, 11, 25, 0, 0, 0, 0, time.UTC)
83 since := time.Date(2026, 11, 24, 11, 20, 0, 0, time.UTC)
84 finished := time.Date(2026, 11, 24, 10, 42, 0, 0, time.UTC)
85 cases := []struct {
86 name string
87 task wire.Task
88 tone, stop, strong string
89 next, action string
90 }{
91 {"budget", pausedTask(wire.StepHold{Reason: wire.HoldBudget, Connection: "tx", Provider: wire.ProviderTensorX, WakeAt: &midnight}, nil), "paused", "Paused", "Paused until midnight", "It carries on by itself when the budget resets.", "Raise the budget"},
92 {"busy", pausedTask(wire.StepHold{Reason: wire.HoldBusy, Connection: "tx", Provider: wire.ProviderTensorX}, nil), "paused", "Paused", "Paused for a moment:", "It starts by itself as soon as that step finishes.", ""},
93 {"offline", wire.Task{ID: "tk1", Stage: wire.StageInProgress, Creator: "paul@example.com", Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering, State: wire.StepQueued, RunnerLabel: "Paul’s Mac mini", Paused: &wire.StepPaused{Offline: true, Since: &since}}}}, "paused", "Paused", "Paused since 11:20:", "It carries on by itself when Paul’s Mac mini is back online.", "Check the machine"},
94 {"spend unknown", pausedTask(wire.StepHold{Reason: wire.HoldSpendUnknown, Connection: "tx", Provider: wire.ProviderTensorX}, nil), "warning", "Needs you", "Paused:", "Check your spending on TensorX, then resume. Nothing runs on TensorX until you do.", "Resume"},
95 {"no connection", pausedTask(wire.StepHold{Reason: wire.HoldNoConnection, NeedsPerson: wire.HoldNeedsNoConnection}, &wire.StepPaused{RunNow: &wire.RunNowOffer{Name: "TensorX", Billing: wire.BillingMetered}}), "warning", "Needs you", "Waiting:", "Nothing happens until you choose.", "Run it now with TensorX"},
96 {"too old", wire.Task{ID: "tk1", Stage: wire.StageInProgress, Creator: "paul@example.com", NeedsYou: wire.NeedsRetry, Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering, State: wire.StepFailed, Reason: "runner_outdated", RunnerLabel: "Paul’s Mac mini", FinishedAt: &finished}}}, "warning", "Needs you", "Waiting for an update:", "It carries on by itself once the runner is updated.", "Update the runner"},
97 {"failed", wire.Task{ID: "tk1", Stage: wire.StageInProgress, Creator: "paul@example.com", NeedsYou: wire.NeedsRetry, Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering, State: wire.StepFailed, Reason: "push_failed", Terminated: true, FinishedAt: &finished}}}, "negative", "Stopped", "Stopped at 10:42:", "Nothing more happens until you try again.", "Try again"},
98 }
99 for _, c := range cases {
100 p := pauseOf(c.task, "paul@example.com", paulNow, loc)
101 if p == nil {
102 t.Errorf("%s: no pause", c.name)
103 continue
104 }
105 label := ""
106 if len(p.Actions) > 0 {
107 label = p.Actions[0].Label
108 }
109 if p.Tone != c.tone || p.Stop != c.stop || p.Strong != c.strong || p.Next != c.next || label != c.action {
110 t.Errorf("%s: tone %q stop %q strong %q next %q action %q", c.name, p.Tone, p.Stop, p.Strong, p.Next, label)
111 }
112 }
113}
114
115// Nothing waits: no pause, and the stepper is left as it was.
116func TestNoPauseWhileWorking(t *testing.T) {
117 task := wire.Task{ID: "tk1", Stage: wire.StageInProgress, Creator: "paul@example.com", Steps: []wire.Step{{ID: "s1", Specialist: wire.SpecialistEngineering, State: wire.StepRunning}}}
118 if p := pauseOf(task, "paul@example.com", paulNow, time.UTC); p != nil {
119 t.Fatalf("%+v", p)
120 }
121 track := []trackStop{{Stage: wire.StageInProgress, Label: "In progress", State: "current", Tone: "positive", Working: true}}
122 pausedTrack(track, nil)
123 if !track[0].Working || track[0].Label != "In progress" {
124 t.Fatalf("%+v", track[0])
125 }
126}
127
128// An older runner (below protocol 29) gets plain Run now: no model named,
129// no "has room now".
130func TestPlainRunNowForAnOlderRunner(t *testing.T) {
131 reset := time.Date(2026, 11, 24, 21, 0, 0, 0, time.UTC)
132 used := 100
133 task := pausedTask(wire.StepHold{Reason: wire.HoldHeadroom, Connection: "claude-1", Provider: wire.ProviderClaude, ResetsAt: &reset, StepRevision: 4},
134 &wire.StepPaused{UsedPercent: &used, RunNow: &wire.RunNowOffer{Plain: true}})
135 p := pauseOf(task, "paul@example.com", paulNow, dublinLoc(t))
136 if len(p.Actions) != 1 || p.Actions[0].Label != "Run it now anyway" || p.Note != "" {
137 t.Fatalf("%+v note %q", p.Actions, p.Note)
138 }
139}
140