oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package thintest
4
5import (
6 "amadan.net/oficina/equipo/internal/wire"
7 "fmt"
8 "github.com/chromedp/cdproto/input"
9 "github.com/chromedp/chromedp"
10 "strings"
11 "testing"
12)
13
14func TestBrowserRosterVisual(t *testing.T) {
15 r := newRollupRig(t)
16 for _, width := range []int64{1280, 390} {
17 for _, scheme := range []string{"light", "dark"} {
18 t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) {
19 p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce")
20 defer p.stop()
21 p.open("/conversation")
22 p.wait(`document.querySelector('[equipo-offline]').hidden`, "connected")
23 p.check(`!!document.querySelector('[equipo-roster-byline]')`, "roster bylines missing")
24 // A report beside its decision card is one line; with the card
25 // set aside it shows its track, facts and actions.
26 p.check(`document.querySelector('[equipo-roster-report]').hasAttribute('data-compact') || !!document.querySelector('[equipo-card="merge"] [equipo-aside-stub]')`, "report repeats its decision card")
27 if eval[bool](p, `!!document.querySelector('[equipo-card="merge"] [data-set-aside]')`) {
28 p.click(`[equipo-card="merge"] [data-set-aside]`)
29 }
30 p.wait(`document.querySelector('[equipo-roster-report] [data-track]')`, "full report")
31 p.check(`[...document.querySelectorAll("[equipo-daybar] i")].every(i=>i.getBoundingClientRect().width>0) && !document.querySelector("[equipo-daybar] [style]")`, "roll-up bar violates the style policy")
32 p.check(`document.querySelector('[equipo-roster-report] [data-track]').children.length===5`, "report needs five stages")
33 p.check(`!!document.querySelector('[equipo-roster-facts]')`, "report facts missing")
34 p.check(`(()=>{const r=document.querySelector("[equipo-roster-report]"),c=r.closest("[equipo-roster-card]");return c.getBoundingClientRect().bottom-r.getBoundingClientRect().bottom<20})()`, "hidden task actions reserve empty space")
35 p.check(`(()=>{const s=getComputedStyle(document.querySelector('[equipo-coordinator-mark]'));return s.backgroundColor==='rgba(0, 0, 0, 0)' && s.boxShadow==='none'})()`, "coordinator has a tile")
36 p.check(`(()=>{const r=document.querySelector('[equipo-roster-report]');return !r.closest('[data-card]').querySelector('[equipo-receipt-more]') && !r.querySelector('[data-pushed]') && !r.querySelector('[equipo-roster-links] a').hasAttribute('rst-btn') && !!r.querySelector('[data-report-next]') && [...r.querySelectorAll('[equipo-roster-links] a')].every(a=>getComputedStyle(a).textDecorationLine==='none')})()`, "report actions drifted")
37 p.check(`document.querySelector('[equipo-roster-report] [aria-current]').dataset.tone==='warning'`, "waiting for you looks failed")
38 p.check(`[...document.querySelectorAll('[equipo-roster-facts] small')].every(e=>getComputedStyle(e).whiteSpace==='normal' && e.scrollWidth<=e.clientWidth+1)`, "fact details truncate")
39 p.check(`(()=>{const c=document.querySelector('[equipo-roster-byline] b'),m=document.querySelector('[equipo-message="incoming"] [equipo-message-meta] strong');return !m||getComputedStyle(c).fontSize===getComputedStyle(m).fontSize})()`, "byline sizes differ")
40 p.check(`[...document.querySelectorAll('[equipo-card="task"], [equipo-card="merge"]')].every(c=>c.querySelector('[equipo-roster-project]')?.textContent.includes('Sample') && c.querySelector('[equipo-roster-project] [equipo-mono]'))`, "task and coordinator cards lack project context")
41 p.check(`(()=>{const r=document.querySelector('[equipo-roster-report]'),c=r.closest('[equipo-roster-card]'),b=c.previousElementSibling;return parseFloat(getComputedStyle(c).paddingTop)===0 && parseFloat(getComputedStyle(b).marginBottom)===8 && parseFloat(getComputedStyle(r).rowGap)===12 && parseFloat(getComputedStyle(c.querySelector('[equipo-roster-facts]')).paddingTop)===12})()`, "report spacing left the inset scale")
42 if width == 390 {
43 p.check(`document.querySelector('[equipo-roster-links] [data-report-next]').getBoundingClientRect().height>=44`, "task button lost its phone target")
44 p.check(`parseFloat(getComputedStyle(document.querySelector('[equipo-roster-report-head] h3 a'),'::after').height)>=44`, "task title has a small phone hit area")
45 }
46 p.fits("Roster")
47 p.check(`(()=>{const s=document.querySelector('[equipo-scroll]');s.scrollTop=0;s.dispatchEvent(new Event('scroll'));return true})()`, "top")
48 p.shot(fmt.Sprintf("roster-%d-%s", width, scheme))
49 p.check(`(()=>{document.querySelector('[equipo-card="merge"]').scrollIntoView({block:'center'});return true})()`, "show coordinator decision")
50 p.shot(fmt.Sprintf("roster-question-%d-%s", width, scheme))
51 if width == 1280 {
52 p.check(`(()=>{document.querySelector('[equipo-conversation]').style.inlineSize='440px';return true})()`, "narrow conversation container")
53 p.check(`getComputedStyle(document.querySelector('[equipo-roster-avatar]')).width==='30px'`, "narrow container did not use phone roster")
54 }
55
56 })
57 }
58 }
59}
60
61func TestBrowserRosterSetAside(t *testing.T) {
62 for _, width := range []int64{1280, 390} {
63 for _, scheme := range []string{"light", "dark"} {
64 t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) {
65 r := newRollupRig(t)
66 p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce")
67 defer p.stop()
68 p.open("/conversation")
69 card := `[data-card="` + r.askCard.ID + `"]`
70 p.wait(`document.querySelector('`+card+` [data-set-aside]')`, "Set aside")
71 before := eval[string](p, `document.querySelector("[equipo-needs-pill]").textContent`)
72 p.click(card + ` [data-set-aside]`)
73 p.wait(`document.querySelector('`+card+` [equipo-aside-stub]')`, "persisted stub")
74 p.check(`document.querySelector("[equipo-needs-pill]").textContent===`+jsString(before), "set aside changed Needs you count")
75 p.wait(`document.querySelector('[equipo-roster-toast] [data-aside-undo]')`, "toast undo")
76 p.check(`(()=>{const s=document.querySelector('[equipo-aside-stub]');return parseFloat(getComputedStyle(s).fontSize)<=14 && s.querySelector('[data-aside-title]') && s.getBoundingClientRect().height<=64})()`, "aside is a full question instead of a compact stub")
77 p.check(`(()=>{const t=document.querySelector('[equipo-roster-toast]'),c=document.querySelector('#chat-composer');return t.getBoundingClientRect().left>=c.getBoundingClientRect().left && t.getBoundingClientRect().bottom<=c.getBoundingClientRect().bottom})()`, "toast outside composer column")
78 p.check(`(()=>{const t=document.querySelector('[equipo-roster-toast]').getBoundingClientRect(),b=document.querySelector('[data-turn-stop]')?.getBoundingClientRect();return !b || (b.bottom<=t.top && b.bottom<=document.querySelector('[equipo-scroll]').getBoundingClientRect().bottom)})()`, "toast covers Stop")
79 p.check(`document.querySelector('`+card+` [equipo-roster-project]')?.textContent.includes('Sample')`, "aside lost project context")
80 if width == 390 {
81 p.check(`document.querySelector('[equipo-aside-stub] button').getBoundingClientRect().width>=44`, "Undo has a narrow phone target")
82 }
83 p.shot(fmt.Sprintf("roster-aside-%d-%s", width, scheme))
84 p.open("/conversation")
85 p.wait(`document.querySelector('`+card+` [equipo-aside-stub]')`, "stub after reload")
86 p.open("/tasks?needs=you")
87 p.check(`!!document.querySelector('a[href="/tasks/`+r.asked+`"]')`, "set-aside task left Needs you")
88 p.open("/conversation")
89 p.click(card + ` [data-aside-undo]`)
90 p.wait(`document.querySelector('`+card+` [data-set-aside]')`, "restored card")
91 p.open("/conversation")
92 p.check(`!document.querySelector('`+card+` [equipo-aside-stub]')`, "undo did not persist")
93 p.fits("set aside and undo")
94 p.click(card + ` [data-set-aside]`)
95 p.wait(`document.querySelector('`+card+` [equipo-aside-stub]')`, "set aside again")
96 if _, err := r.client.Answer(r.ctx, r.askCard.ID, wire.ChoiceWaitMac, r.askCard.Revision); err != nil {
97 t.Fatal(err)
98 }
99 p.wait(`!document.querySelector('`+card+` [equipo-aside-stub]') && document.querySelector('`+card+` [equipo-card-done]')`, "answer from elsewhere resolves the stub")
100 })
101 }
102 }
103}
104
105func TestBrowserRosterSubchat(t *testing.T) {
106 for _, width := range []int64{1280, 390} {
107 for _, scheme := range []string{"light", "dark"} {
108 t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) {
109 r := newToolRig(t)
110 task := taskID(t, r.call("thread-task", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Improve sign-in", "brief": "Keep sign-in clear."}))
111 if res := r.call("roster-q", wire.ToolAskPerson, map[string]any{"question": "Which page should change?", "options": []string{}}); res.Code != "asked" {
112 t.Fatalf("ask: %+v", res)
113 }
114 if _, err := r.inst.DB.Writer().Exec("UPDATE chat_cards SET task_id=?,project_id=(SELECT project_id FROM chat_tasks WHERE id=?) WHERE kind='question'", task, task); err != nil {
115 t.Fatal(err)
116 }
117 if err := r.runner.Send(r.ctx, "roster-q-reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "One question before I start."}); err != nil {
118 t.Fatal(err)
119 }
120 r.wait("replied", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnReplied })
121 p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce")
122 defer p.stop()
123 p.open("/conversation")
124 p.wait(`document.querySelector('[data-question-thread] [equipo-mini-composer]')`, "question as a sub-chat")
125 p.check(`document.querySelector('[data-question-thread] [equipo-thread-turn]').textContent.includes('Which page should change?')`, "first word is not a turn")
126 p.check(`(()=>{const i=document.querySelector('[data-question-thread] [equipo-mini-composer] textarea');i.value='The sign-in page.';i.dispatchEvent(new Event('input',{bubbles:true}));i.focus();return true})()`, "type")
127 p.shot(fmt.Sprintf("roster-thread-typing-%d-%s", width, scheme))
128 p.click(`[data-set-aside]`)
129 p.wait(`document.querySelector('[equipo-aside-stub]')`, "question set aside")
130 p.wait(`document.querySelector('[equipo-roster-toast] [data-aside-undo]')`, "question toast")
131 p.click(`[equipo-roster-toast] [data-aside-undo]`)
132 p.wait(`document.querySelector('[data-question-thread] [equipo-mini-composer] textarea')?.value==='The sign-in page.'`, "undo retains the draft")
133 p.check(`(()=>{window.__fetch=window.fetch;window.fetch=(url,opts)=>opts?.method==='POST'?new Promise(resolve=>{window.__fail=()=>resolve(new Response('{}',{status:503}))}):window.__fetch(url,opts);return true})()`, "hold question send")
134 p.click(`[data-question-thread] [equipo-mini-composer] [data-thread-send]`)
135 p.check(`document.querySelector('[data-question-thread] [data-thread-send]').getAttribute('aria-busy')==='true'`, "question busy")
136 p.shot(fmt.Sprintf("roster-thread-busy-%d-%s", width, scheme))
137 p.check(`(()=>{window.__fail();window.fetch=window.__fetch;return true})()`, "question send fails")
138 p.wait(`document.querySelector('[data-question-thread]').parentElement.querySelector('[equipo-card-error]:not([hidden])')`, "question send error")
139 p.shot(fmt.Sprintf("roster-thread-error-%d-%s", width, scheme))
140
141 p.click(`[data-question-thread] [equipo-mini-composer] [data-thread-send]`)
142 f, body := r.expect(wire.FrameMessage)
143 m := body.(*wire.MessageCommand)
144 r.runner.Send(r.ctx, "roster-a", wire.FrameAck, wire.Ack{ID: f.ID})
145 p.wait(`document.querySelector('[data-question-thread] [data-own]') && document.querySelector('[equipo-thread-wait]')`, "sent and waiting")
146 p.shot(fmt.Sprintf("roster-thread-waiting-%d-%s", width, scheme))
147 r.runner.Send(r.ctx, "roster-delta", wire.FrameDelta, wire.DeltaReport{TurnID: m.TurnID, Attempt: 1, Offset: 0, Text: "I’ll start"})
148 p.wait(`document.querySelector('[equipo-thread-draft]')?.textContent==='I’ll start'`, "streamed reply in the drawer")
149 r.runner.Send(r.ctx, "roster-answer", wire.FrameReply, wire.Reply{TurnID: m.TurnID, Attempt: 1, Text: "I’ll start with the sign-in page."})
150 p.wait(`document.querySelector('[data-question-thread]').textContent.includes('I’ll start with the sign-in page.')`, "reply inside the sub-chat")
151 p.open("/conversation")
152 p.wait(`document.querySelector('[data-question-thread]').textContent.includes('I’ll start with the sign-in page.')`, "thread after reload")
153 p.check(`!document.querySelector('[equipo-thread-turn][data-own] [equipo-thread-who]')`, "own thread turn repeats a byline")
154 p.check(`parseFloat(getComputedStyle(document.querySelector('[data-first] [equipo-thread-bubble]')).fontWeight)<600`, "question is entirely title weight")
155 p.check(`(()=>{const c=document.querySelector('[data-question-thread]').closest('[data-card]');return c.querySelector('[equipo-roster-project]')?.textContent.includes('Sample') && c.querySelector('[equipo-roster-task]')?.textContent==='Improve sign-in'})()`, "thread lost project or task context")
156 p.fits("sub-chat")
157 p.shot(fmt.Sprintf("roster-thread-answered-%d-%s", width, scheme))
158 p.check(`(()=>{const i=document.querySelector('[data-question-thread] [equipo-mini-composer] textarea');i.value='Keep the email link.';i.dispatchEvent(new Event('input',{bubbles:true}));return true})()`, "follow-up")
159 p.click(`[data-question-thread] [equipo-mini-composer] [data-thread-send]`)
160 f2, b2 := r.expect(wire.FrameMessage)
161 m2 := b2.(*wire.MessageCommand)
162 if !strings.Contains(m2.Text, "Which page should change?") || len(m2.PersonText) != 1 || m2.PersonText[0] != "Keep the email link." {
163 t.Fatalf("follow-up context %+v", m2)
164 }
165 r.runner.Send(r.ctx, "roster-a2", wire.FrameAck, wire.Ack{ID: f2.ID})
166 r.runner.Send(r.ctx, "roster-answer2", wire.FrameReply, wire.Reply{TurnID: m2.TurnID, Attempt: 1, Text: "The email link will stay."})
167 p.wait(`document.querySelector('[data-question-thread]').textContent.includes('The email link will stay.') && document.querySelectorAll('[data-question-thread] [data-own]').length===2`, "second round stays in the thread")
168 })
169 }
170 }
171}
172
173func TestBrowserRosterDecisionStates(t *testing.T) {
174 for _, width := range []int64{1280, 390} {
175 for _, scheme := range []string{"light", "dark"} {
176 t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) {
177 r := newToolRigAt(t, wire.ProtocolCurrent)
178 id, c := r.toDirection("roster", "Explore a shorter setup")
179 _, built := r.toDirection("roster-build", "Explore compact navigation")
180 p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce")
181 defer p.stop()
182 p.open("/conversation")
183 card := `[data-card="` + c.ID + `"]`
184 p.wait(`document.querySelector('`+card+` [data-direction-choice="build"]')`, "direction")
185 p.check(`(()=>{document.querySelector('`+card+` [equipo-actions] [name=revision]').value='0';return true})()`, "make stale")
186 p.click(card + ` [data-direction-choice="build"]`)
187 p.wait(`document.querySelector('`+card+` [equipo-card-error]').textContent.includes('This item has changed')`, "stale revision error")
188 if k := r.task(id); k.Stage != wire.StageInReview {
189 t.Fatalf("stale choice changed task: %s", k.Stage)
190 }
191 p.shot(fmt.Sprintf("roster-decision-stale-%d-%s", width, scheme))
192 p.click(card + ` [equipo-card-error] button`)
193 p.wait(`document.querySelector('`+card+` [equipo-actions] [name=revision]').value==='1'`, "refresh stale decision")
194 p.check(`(()=>{const b=document.querySelector('`+card+` [data-direction-choice="build"]');b.scrollIntoView({block:'center'});b.addEventListener('click',e=>e.preventDefault(),{once:true});return true})()`, "inspect pointer states")
195 xy := eval[[]float64](p, `(()=>{const r=document.querySelector('`+card+` [data-direction-choice="build"]').getBoundingClientRect();return [r.x+r.width/2,r.y+r.height/2]})()`)
196 p.do(chromedp.MouseEvent(input.DispatchMouseEventTypeMouseMoved, xy[0], xy[1]))
197 p.check(`document.querySelector('`+card+` [data-direction-choice="build"]').matches(':hover')`, "hover state")
198 p.shot(fmt.Sprintf("roster-decision-hover-%d-%s", width, scheme))
199 // FullScreenshot can restore a different scroll offset on a phone.
200 xy = eval[[]float64](p, `(()=>{const r=document.querySelector('`+card+` [data-direction-choice="build"]').getBoundingClientRect();return [r.x+r.width/2,r.y+r.height/2]})()`)
201 p.do(chromedp.MouseEvent(input.DispatchMouseEventTypeMouseMoved, xy[0], xy[1]))
202 p.do(chromedp.MouseEvent(input.DispatchMouseEventTypeMousePressed, xy[0], xy[1], chromedp.ButtonLeft, chromedp.ClickCount(1)))
203 p.check(`getComputedStyle(document.querySelector('`+card+` [data-direction-choice="build"]')).transform!=='none'`, "pressed state")
204 p.shot(fmt.Sprintf("roster-decision-pressed-%d-%s", width, scheme))
205 p.do(chromedp.MouseEvent(input.DispatchMouseEventTypeMouseReleased, xy[0], xy[1], chromedp.ButtonLeft, chromedp.ClickCount(1)))
206
207 p.check(`(()=>{window.__fetch=window.fetch;window.fetch=function(url,opts){if(opts&&opts.method==='POST')return new Promise(resolve=>{window.__release=()=>resolve(new Response('{}',{status:503}));});return window.__fetch(url,opts)};return true})()`, "hold request")
208 p.click(card + ` [data-direction-choice="build"]`)
209 p.check(`(()=>{const c=document.querySelector('`+card+`');return c.getAttribute('aria-busy')==='true' && c.querySelector('[aria-busy="true"]').textContent.includes('Building') && [...c.querySelectorAll('button')].every(b=>b.disabled)})()`, "busy and sibling disabled")
210 p.shot(fmt.Sprintf("roster-decision-busy-%d-%s", width, scheme))
211 p.check(`(()=>{window.__release();return true})()`, "fail")
212 p.wait(`!document.querySelector('`+card+` [equipo-card-error]').hidden`, "in-place error")
213 p.shot(fmt.Sprintf("roster-decision-error-%d-%s", width, scheme))
214 p.check(`(()=>{window.fetch=window.__fetch;return true})()`, "restore request")
215 p.click(card + ` [data-thread-open]`)
216 p.check(`document.activeElement===document.querySelector('`+card+` textarea')`, "Try again focuses sub-chat")
217 p.check(`(()=>{const i=document.querySelector('`+card+` textarea');i.value='Keep the runner step, drop the tour.';i.dispatchEvent(new Event('input',{bubbles:true}));return true})()`, "note")
218 p.click(card + ` [data-thread-send]`)
219 p.wait(`document.querySelector('`+card+` [data-own]')`, "sent direction note")
220 if k := r.task(id); k.Stage != wire.StageInProgress {
221 t.Fatalf("note did not choose another round: %s", k.Stage)
222 }
223 p.check(`document.querySelector('`+card+` [equipo-roster-project]')?.textContent.includes('Sample')`, "decision lost project context")
224 p.fits("direction states")
225 p.shot(fmt.Sprintf("roster-decision-sent-%d-%s", width, scheme))
226 build := `[data-card="` + built.ID + `"]`
227 p.click(build + ` [data-direction-choice="build"]`)
228 p.wait(`document.querySelector('`+build+` [data-done]')`, "Build collapses to success")
229 p.check(`getComputedStyle(document.querySelector('`+build+` [equipo-card-line]')).display==='none'`, "success retained the open card title")
230 p.shot(fmt.Sprintf("roster-decision-success-%d-%s", width, scheme))
231 })
232 }
233 }
234}
235
236func TestBrowserRosterThinking(t *testing.T) {
237 for _, width := range []int64{1280, 390} {
238 for _, scheme := range []string{"light", "dark"} {
239 t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) {
240 r := newToolRig(t)
241 p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce")
242 defer p.stop()
243 p.open("/conversation")
244 p.wait(`document.querySelector('[equipo-thinking] [data-turn-stop]')`, "Stop on thinking line")
245 p.check(`(()=>{const s=getComputedStyle(document.querySelector('[equipo-thinking] [equipo-sparkle]'));return s.display==='none'})()`, "filled thinking mark remains")
246 p.wait(`(()=>{const c=document.querySelector('[equipo-thinking]'),n=c.querySelector('[equipo-message-meta] [equipo-coordinator-mark] svg'),a=c.querySelector('[equipo-phrase]') || c.querySelector('[equipo-activity]'),b=c.querySelector('[data-turn-stop]');return n.getBoundingClientRect().width>0 && Math.abs(n.getBoundingClientRect().top-a.getBoundingClientRect().top)<10 && getComputedStyle(b).boxShadow==='none'})()`, "one thinking line with a quiet Stop")
247 if width == 390 {
248 p.check(`document.querySelector('[data-turn-stop]').getBoundingClientRect().height>=44`, "Stop has a small touch target")
249 }
250 p.wait(`[...document.querySelectorAll('[equipo-thinking] [equipo-phrase] [data-in] > span')].every(e=>Number(getComputedStyle(e).opacity)>=.99)`, "settled thinking phrase")
251 p.fits("thinking line")
252 p.shot(fmt.Sprintf("roster-thinking-%d-%s", width, scheme))
253 p.click(`[equipo-thinking] [data-turn-stop]`)
254 cf, _ := r.expect(wire.FrameCancel)
255 r.runner.Send(r.ctx, "roster-stop-ack", wire.FrameAck, wire.Ack{ID: cf.ID})
256 r.runner.Send(r.ctx, "roster-stop-report", wire.FrameTurn, wire.TurnReport{TurnID: r.turn, Attempt: 1, State: wire.TurnCancelled, Reason: "cancelled"})
257 r.wait("stopped", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnCancelled })
258 p.wait(`!document.querySelector('[equipo-thinking]')`, "stopped line removed")
259 })
260 }
261 }
262}
263