oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import (
4 "regexp"
5 "strings"
6 "testing"
7 "time"
8
9 "amadan.net/oficina/equipo/internal/equipo"
10 "amadan.net/oficina/equipo/internal/wire"
11)
12
13// gallery is a team in the middle of its work, as the inner screens
14// mockup draws it: the owner and Nora, three projects (an iOS app whose
15// checks need a Mac, a docs repository with make ci, a Go service), and
16// tasks in every state the screens show. Everything goes through the
17// real instance: tool calls, step reports, activity lines and the
18// notebook, from fake runners.
19type gallery struct {
20 a, b *toolRig
21 unchecked, stopped, noras, merging string
22 running, looking, nora string
23 runningStep *wire.DispatchCommand
24}
25
26const (
27 galleryWoodstar = "amadan.net/oficina/sample"
28 gallerySuite = "amadan.net/oficina/suite"
29 galleryEquipo = "amadan.net/oficina/equipo"
30)
31
32func galleryHello(r *toolRig, gen int64) wire.Hello {
33 at := time.Now().Add(-3 * time.Hour).UTC().Truncate(time.Second)
34 return wire.Hello{Generation: gen, Repos: []string{galleryWoodstar, gallerySuite, galleryEquipo}, CreateIn: []string{"oficina"}, Agent: "equipo-test",
35 Catalog: []wire.RepoInfo{
36 {Repo: galleryWoodstar, DefaultBranch: "main", Summary: "An iOS app for reading and posting in a timeline without an account.", Names: []string{"sample", "Woodstar"}, Hints: []string{"swift", "swiftui"}, UpdatedAt: at, HeadSHA: strings.Repeat("9c1f3e2", 6)[:40], HeadSubject: "Trim the compose sheet's bottom inset", ChecksReason: "needs_macos"},
37 {Repo: gallerySuite, DefaultBranch: "main", Summary: "The shared suite contract: what every Oficina app agrees to about accounts, teams and sign-in.", Names: []string{"suite", "Suite"}, Hints: []string{"go"}, UpdatedAt: at.Add(2 * time.Hour), HeadSHA: strings.Repeat("3d9e0f1", 6)[:40], HeadSubject: "Replace em dash in README", Gate: "make ci"},
38 {Repo: galleryEquipo, DefaultBranch: "main", Summary: "The team of agents you are talking to: a coordinator, Engineering and Review.", Names: []string{"equipo", "Equipo"}, Hints: []string{"go"}, UpdatedAt: at.Add(-3 * time.Hour), HeadSHA: strings.Repeat("a0d418f", 6)[:40], HeadSubject: "Keep sessions 14 days", Gate: ".amadan/ci"},
39 },
40 Connections: []wire.HeldConnection{{LocalID: "claude-a", Person: Owner, Provider: "claude", Kind: "subscription", Label: Owner, State: "healthy"}}, Versions: map[string]string{"runner": "test", "claude": "2.1.312"}}
41}
42
43// galleryPushed records a task in repo and runs Engineering to a pushed
44// candidate with a summary.
45func (r *toolRig) galleryPushed(key, repo, title, brief, base, cand, summary string, separate bool) (string, *wire.DispatchCommand) {
46 r.t.Helper()
47 id := taskID(r.t, r.call(key+"-rec", wire.ToolRecordTask, map[string]any{"repo": repo, "title": title, "brief": brief, "separate": separate}))
48 if res := r.call(key+"-start", wire.ToolStartTask, map[string]string{"task": id, "brief": brief}); res.IsError {
49 r.t.Fatalf("start: %+v", res)
50 }
51 _, body := r.expect(wire.FrameDispatch)
52 d := body.(*wire.DispatchCommand)
53 r.step(key+"-run", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: base, Family: "claude", Account: "claude-a"})
54 r.step(key+"-done", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepDone, BaseSHA: base, CandidateSHA: cand, Pushed: true, Termination: true, Family: "claude", Account: "claude-a", Summary: summary, LogTail: "Read README.md\nEdit README.md"})
55 r.expect(wire.FrameWatchMerge)
56 return id, d
57}
58
59// galleryJudged runs checks (outcome) and an approving review.
60func (r *toolRig) galleryJudged(key string, base, cand, outcome, reason string) {
61 r.t.Helper()
62 c := r.dispatched(wire.SpecialistChecks, base, cand, 0)
63 code := exit(0)
64 if outcome != wire.ChecksPassed {
65 code = nil
66 }
67 r.checks(key+"-c", c, outcome, code, reason, "ok \texample/panes\t0.012s")
68 rv := r.dispatched(wire.SpecialistReview, base, cand, 0)
69 r.verdict(key+"-r", rv, wire.VerdictApprove)
70}
71
72func newGallery(t *testing.T) *gallery {
73 t.Helper()
74 a := newToolRigAt(t, wire.ProtocolInjectionDefences)
75 g := &gallery{a: a}
76 if err := a.runner.Send(a.ctx, "h-gallery", wire.FrameHello, primaryAt(galleryHello(a, a.runner.Welcome.Generation), wire.ProtocolInjectionDefences)); err != nil {
77 t.Fatal(err)
78 }
79 a.wait("catalog", func(c *Conversation) bool { return true })
80 g.b = personToolRigAt(t, a, "nora@example.com", equipo.RoleOwner, wire.ProtocolInjectionDefences)
81 b := g.b
82 if err := b.runner.Send(b.ctx, "h-gallery", wire.FrameHello, primaryAt(galleryHello(b, b.runner.Welcome.Generation), wire.ProtocolInjectionDefences)); err != nil {
83 t.Fatal(err)
84 }
85 sha := func(c string) string { return strings.Repeat(c, 40) }
86
87 // Woodstar: approved, checks cannot run (needs macOS): the owner's
88 // merge card, Needs you.
89 g.unchecked, _ = a.galleryPushed("g1", "oficina/sample", "Swipe back from the edge doesn't work", "On the Account pane, swiping in from the left edge should go back, as it does everywhere else.\n\n- Happens on a device, every time\n- Other panes go back fine", sha("1"), "bc025ca"+sha("2")[7:], "Let the navigation stack's pop gesture run alongside the pane's recogniser.\n\n- `AccountNavigationHost` allows both gestures for the edge swipe\n- Added a note on why the pane needs it\n\nNot run here: the Xcode tests need macOS.", false)
90 a.call("g1-find", wire.ToolAddFinding, map[string]any{"task": g.unchecked, "text": "The pane's gesture recogniser takes the edge swipe before the navigation stack sees it.", "repo": "oficina/sample", "path": "ios/Woodstar/AccountNavigationHost.swift", "line": 15})
91 a.galleryJudged("g1", sha("1"), "bc025ca"+sha("2")[7:], wire.ChecksCannotRun, "needs_macos")
92 a.wait("merge card", func(c *Conversation) bool { return c.Tasks[g.unchecked].Stage == wire.StageReadyToMerge })
93
94 // The same bug, filed again: a possible duplicate, and it stopped.
95 g.stopped = taskID(t, a.call("g2-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": "Swipe from the edge to go back doesn't work", "brief": "Swiping from the left edge does nothing on the account screen.", "separate": true}))
96 a.call("g2-start", wire.ToolStartTask, map[string]string{"task": g.stopped, "brief": "Fix it."})
97 _, body := a.expect(wire.FrameDispatch)
98 d := body.(*wire.DispatchCommand)
99 a.step("g2-run", wire.StepReport{TaskID: g.stopped, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: sha("1")})
100 a.step("g2-fail", wire.StepReport{TaskID: g.stopped, StepID: d.StepID, Attempt: 1, State: wire.StepFailed, Reason: "provider_failed", Termination: true})
101
102 // Nora's copy of it: approved, unchecked, waiting on Nora.
103 g.noras, _ = b.galleryPushed("g3", "oficina/sample", "iOS edge swipe to go back doesn't work on panes", "Edge swipe to go back does nothing inside panes.", sha("1"), "e71d20b"+sha("3")[7:], "Forward the edge swipe from `PaneNavigationHost` to the stack.", true)
104 b.galleryJudged("g3", sha("1"), "e71d20b"+sha("3")[7:], wire.ChecksCannotRun, "needs_macos")
105
106 // Suite: Nora's task merged by Equipo.
107 g.nora, _ = b.galleryPushed("g4", "oficina/suite", "Fix line break in README", "A hard line break in the teams section splits a sentence in two.", sha("4"), "f04c8a7"+sha("5")[7:], "Joined the two lines in `README.md`.", false)
108 b.galleryJudged("g4", sha("4"), "f04c8a7"+sha("5")[7:], wire.ChecksPassed, "")
109 m := b.dispatched(wire.SpecialistMerge, sha("4"), "f04c8a7"+sha("5")[7:], 0)
110 b.mergedStep("g4-m", m, "c7d0a52"+sha("6")[7:])
111
112 // Suite: the owner's, merging now.
113 g.merging, _ = a.galleryPushed("g5", "oficina/suite", "Replace em dash in README", "The README has one em dash left, in the sign-in section.", sha("4"), "3d9e0f1"+sha("7")[7:], "Split the sentence at the em dash in `README.md`.", false)
114 a.galleryJudged("g5", sha("4"), "3d9e0f1"+sha("7")[7:], wire.ChecksPassed, "")
115 mm := a.dispatched(wire.SpecialistMerge, sha("4"), "3d9e0f1"+sha("7")[7:], 0)
116 a.step("g5-m-run", wire.StepReport{TaskID: mm.TaskID, StepID: mm.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: mm.BaseSHA, CandidateSHA: mm.CandidateSHA})
117
118 // Equipo: Engineering at work, with its activity lines.
119 g.running = taskID(t, a.call("g6-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/equipo", "title": "Task list loses its scroll position after a refresh", "brief": "When the task list refreshes itself, the page jumps back to the top.", "separate": true}))
120 a.call("g6-find", wire.ToolAddFinding, map[string]any{"task": g.running, "text": "The live swap replaces the whole list; the browser has nothing to anchor to.", "repo": "oficina/equipo", "path": "internal/equipo/static/live.js", "line": 88})
121 a.call("g6-start", wire.ToolStartTask, map[string]string{"task": g.running, "brief": "Keep the scroll position."})
122 _, body = a.expect(wire.FrameDispatch)
123 g.runningStep = body.(*wire.DispatchCommand)
124 a.step("g6-run", wire.StepReport{TaskID: g.running, StepID: g.runningStep.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: sha("8"), Family: "claude", Account: "claude-a"})
125 for i, l := range []wire.StepActivityReport{{Kind: wire.ActivityRead, Subject: "internal/equipo/static/live.js"}, {Kind: wire.ActivitySearch, Subject: "replaceWith"}, {Kind: wire.ActivityRead, Subject: "internal/equipo/static/nav-stream.js"}, {Kind: wire.ActivityEdit, Subject: "internal/equipo/static/live.js"}} {
126 l.TaskID, l.StepID, l.Attempt = g.running, g.runningStep.StepID, 1
127 a.activity("g6-act-"+itoa(i), l)
128 }
129 a.wait("activity", func(c *Conversation) bool { return len(c.StepActivity[g.runningStep.StepID]) == 4 })
130
131 // Woodstar: looked into, with a finding, not started.
132 g.looking = taskID(t, a.call("g7-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": "Timeline jumps when images load", "brief": "Scrolling the timeline, the list shifts under my thumb as images arrive.", "separate": true}))
133 a.call("g7-find", wire.ToolAddFinding, map[string]any{"task": g.looking, "text": "Image cells size themselves after the image arrives; the list needs the size up front.", "repo": "oficina/sample", "path": "ios/Woodstar/Timeline/ImageCell.swift", "line": 22})
134
135 // The coordinator's notes about Woodstar.
136 nb := wire.NotebookReport{Person: Owner, Entries: []wire.NotebookEntry{
137 {ID: "n1", Source: wire.NoteRepo, Repo: "oficina/sample", Path: "README.md", Text: "Panes are the app's own container: each tab is a pane with its own navigation stack, so system gestures are forwarded by hand.", At: time.Now().Add(-48 * time.Hour).UTC()},
138 {ID: "n2", Source: wire.NoteOwn, Repo: "oficina/sample", Text: "Gesture bugs need a device to confirm; the simulator hides them.", At: time.Now().Add(-24 * time.Hour).UTC()},
139 }}
140 a.step2("g-nb", wire.FrameNotebook, nb)
141 a.wait("all tasks", func(c *Conversation) bool { return len(c.Tasks) == 7 })
142 return g
143}
144
145// TestPagesInnerScreens: the inner screens draw the gallery as the
146// mockup does, from API v1 data alone.
147func TestPagesInnerScreens(t *testing.T) {
148 g := newGallery(t)
149 a := g.a
150 noInlineStyles(t, g)
151 owner := a.inst.Cookie()
152 has := func(page, what string, wants ...string) {
153 t.Helper()
154 for _, w := range wants {
155 if !strings.Contains(page, w) {
156 t.Fatalf("%s lacks %q:\n%s", what, w, page)
157 }
158 }
159 }
160 not := func(page, what string, nots ...string) {
161 t.Helper()
162 for _, n := range nots {
163 if strings.Contains(page, n) {
164 t.Fatalf("%s shows %q", what, n)
165 }
166 }
167 }
168 tasks := a.get(owner, "/tasks", 200)
169 // Groups in order, each row a link with its track, badges and source.
170 order := []string{`data-group="needs"`, `data-group="progress"`, `data-group="ready"`, `data-group="done"`}
171 for i := 1; i < len(order); i++ {
172 if !strings.Contains(tasks, order[i-1]) || strings.Index(tasks, order[i-1]) > strings.Index(tasks, order[i]) {
173 t.Fatalf("groups out of order: %s before %s", order[i-1], order[i])
174 }
175 }
176 has(tasks, "Tasks",
177 `<li equipo-row equipo-trow data-task="`+g.unchecked+`" data-stage="ready_to_merge" data-group="needs">`,
178 `<li equipo-row equipo-trow data-task="`+g.stopped+`" data-stage="in_progress" data-group="needs">`,
179 `<li equipo-row equipo-trow data-task="`+g.merging+`" data-stage="merging" data-group="ready">`,
180 `<li equipo-row equipo-trow data-task="`+g.noras+`" data-stage="ready_to_merge" data-group="ready">`,
181 `<li equipo-row equipo-trow data-task="`+g.nora+`" data-stage="done" data-group="done">`,
182 "Possible duplicate of <a href=\"/tasks/"+g.unchecked+"\">Swipe back from the edge doesn&#39;t work</a>",
183 "Waiting for a Mac to run checks", "Engineering working", "Coordinator looking into it", "Merging into the default branch",
184 "Checks: needs macOS", "Checks passed", "Approved", ">Merged.</span>",
185 "From your conversation, ", "From Nora&#39;s conversation, ",
186 `<li data-s="current" data-tone="negative" title=`, `<li data-s="current" data-live title="In progress">`,
187 "7 tasks across 3 projects", "Anyone", "All projects")
188 // Only the creator's own tasks carry the quiet ⋯ and its actions.
189 has(tasks, "Tasks", `action="/tasks/`+g.stopped+`/duplicate"`, `action="/conversation/tasks/`+g.stopped+`/retry"`)
190 not(tasks, "Tasks", `action="/conversation/tasks/`+g.noras+`/cancel"`, `action="/tasks/`+g.noras+`/duplicate"`, "Open on Amadan to merge")
191 if p := a.get(owner, "/tasks?person=nora@example.com", 200); strings.Contains(p, `data-task="`+g.unchecked+`"`) || !strings.Contains(p, `data-task="`+g.noras+`"`) {
192 t.Fatal("person filter")
193 }
194
195 needs := a.get(owner, "/tasks?needs=you", 200)
196 has(needs, "Needs you", "3 waiting for you", `data-decision="`+g.unchecked+`"`, "Merge without checks?",
197 `data-merge-choice="merge"`, `data-merge-choice="wait_mac"`, `name="from" value="needs"`, `data-decision="`+g.stopped+`"`, "Try again?", `data-group="others"`, `data-task="`+g.noras+`"`)
198 // No card for duplicates: Equipo tidies them, or names them quietly.
199 not(needs, "Needs you", `data-decision="`+g.noras+`"`, "Fold it into the other task?", `action="/tasks/`+g.stopped+`/duplicate"`)
200
201 detail := a.get(owner, "/tasks/"+g.running, 200)
202 has(detail, "running task", `<ol equipo-track-full data-track`, "Engineering is on it now: editing internal/equipo/static/live.js.",
203 `<li data-kind="step" data-live>`, "Reading internal/equipo/static/nav-stream.js", "Coordinator looked into it", "internal/equipo/static/live.js:88",
204 `<details equipo-details id="task-details">`, "What happened", "Questions and notes")
205 ready := a.get(owner, "/tasks/"+g.unchecked, 200)
206 has(ready, "unchecked task", "Approved. Waiting for a Mac to run checks. You can merge now without checks.", "<b>Checks</b>", "Checks: needs macOS", "Checks need macOS, so Review judged it alone.", "On commit bc025ca.",
207 "<b>Review</b>", "<p equipo-headline>Approved.</p>", `<details equipo-tl-more id="tl-more-`, `<li data-kind="ready">`, "Merge without checks?", `name="from" value="task"`,
208 "<code>AccountNavigationHost</code>", "Pushed bc025ca", "The brief", "Where it lives", `data-open-amadan>Open on Amadan</a>`)
209 // Paths and commits live behind Details only.
210 outside := regexp.MustCompile(`(?s)<details.*?</details>`).ReplaceAllString(ready, "")
211 for _, hidden := range []string{"ios/Woodstar/AccountNavigationHost.swift", "bc025ca", "AccountNavigationHost.swift:15"} {
212 if strings.Contains(outside, hidden) {
213 t.Fatalf("%q outside Details", hidden)
214 }
215 }
216 // Open on Amadan is a quiet link in Details only.
217 if strings.Count(ready, "data-open-amadan") != 1 || strings.Index(ready, "data-open-amadan") < strings.Index(ready, "equipo-details") {
218 t.Fatal("Open on Amadan outside Details")
219 }
220 stopped := a.get(owner, "/tasks/"+g.stopped, 200)
221 // Stopped, in red, at the step's end, with Try again (paused work).
222 has(stopped, "stopped task", "the model connection failed")
223 has(stopped, "stopped task", "Nothing more happens until you try again.")
224 has(stopped, "stopped task", `data-pause-act="retry"`)
225 not(stopped, "stopped task", "(Stopped:")
226 // The source link opens the conversation at that message; relative
227 // times carry their instant so they keep current.
228 src := a.conv.Tasks[g.unchecked].SourceMessageID
229 if src == "" {
230 t.Fatal("no source message")
231 }
232 has(ready, "unchecked task", `href="/conversation?message=`+src+`#m-`+src+`"`, `equipo-ago data-at="`, `data-format="Changed {t}"`)
233 has(a.get(owner, "/conversation?message="+src, 200), "conversation", `data-message="`+src+`"`)
234 has(tasks, "Tasks", `data-ago-formats="{&#34;days&#34;:&#34;{n} days ago&#34;`)
235 done := a.get(owner, "/tasks/"+g.nora, 200)
236 has(done, "merged task", "Merged into main. Checks and review passed before it went in.", `<li data-kind="merged">`, "<b>Merged into main</b>", "The coordinator told Nora in the conversation.", "Merged as commit c7d0a52.")
237 not(done, "merged task", "data-task-cancel", "data-task-retry")
238
239 projects := a.get(owner, "/projects", 200)
240 has(projects, "Projects", "An iOS app for reading and posting", "Swift, SwiftUI", "Checks need a Mac", "Checks run here (make ci)", "1 repository", `equipo-bar`, "waiting on someone", `title="nora@example.com" aria-hidden="true">N<`, "equipo-key")
241 woodstar := a.conv.Tasks[g.unchecked].ProjectID
242 project := a.get(owner, "/projects/"+woodstar, 200)
243 has(project, "Woodstar", "Attachments", "Trim the compose sheet&#39;s bottom inset", "Recently", "Coordinator&#39;s notes", "Panes are the app&#39;s own container", "From README.md, ", "Gesture bugs need a device", `data-group="needs"`)
244}
245