//go:build browser package headless import ( "context" "testing" "amadan.net/oficina/equipo/internal/browsertest" "github.com/chromedp/chromedp" ) // Ask the implementer from the task page (Paul, 2026-11-07): the thread // has the chat's quiet composer (a click anywhere in it focuses the // message, the dock is the page's own colour) and a quiet "Asking // Engineering ยท change" line that follows what is typed and switches // with change. A question shows at once; its answer streams into a // thinking line labelled with the specialist and settles in place, with // no reload. At 1280 with a mouse and 390 with touch. func TestBrowserTaskThread(t *testing.T) { for _, size := range []struct { w, h int64 pointer bool }{{1280, 900, true}, {390, 844, false}} { _, inst, r := localEnv(t) r.start(t) c := inst.Cookie() p := openPage(t, inst.URL, c.Name, c.Value, size.w, size.h, size.pointer) p.send("tool:record_task:oficina/sample|Fix the README typo|teh\ntool:start_task:$task|edit:README.md|teh panes|the panes") card := taskCard("Fix the README typo") // Engineering, checks, review and Equipo's merge take a while under // load. Merged work can still be asked about (Paul, 2026-11-08). for i := 0; ; i++ { err := chromedp.Do(p.ctx, browsertest.Wait(card+`?.querySelector('[equipo-stage]')?.textContent==='Done'`)) if err == nil { break } if i == 12 { t.Fatal(err) } } var link string p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { var err error link, err = chromedp.Evaluate[string](card+`.querySelector('[equipo-roster-links] a[href^="/tasks/"]').href`)(ctx, target) return err })) p.run(chromedp.Navigate(link), browsertest.Wait(`!!document.querySelector('[data-chat-stream][data-task] #composer')`)) p.check(`(()=>{window.__nav=performance.getEntriesByType('navigation').length;return true})()`, "mark") line := `document.querySelector('[data-ask-line]').textContent` p.check(line+`==='Asking Engineering' && !document.querySelector('[data-ask-change]').hidden && document.querySelector('#chat-body').placeholder==='Ask Engineering about this work'`, "the ask line") // It follows what is typed, and change switches it. p.check(`(()=>{const i=document.querySelector('#chat-body');i.value='Review, were you unsure?';i.dispatchEvent(new Event('input'));return `+line+`==='Asking Review'})()`, "addressing Review") p.check(`(()=>{const i=document.querySelector('#chat-body');i.value='';i.dispatchEvent(new Event('input'));document.querySelector('[data-ask-change]').click();return `+line+`==='Asking Review' && document.querySelector('[data-ask-specialist]').value==='review'})()`, "change to Review") p.check(`(()=>{document.querySelector('[data-ask-change]').click();return `+line+`==='Asking Engineering' && document.querySelector('[data-ask-specialist]').value==='engineering'})()`, "change back") // The chat's composer: a click in its padding focuses the message. p.check(`(()=>{document.activeElement&&document.activeElement.blur();document.querySelector('[equipo-thread] h2').scrollIntoView({block:'start'});return true})()`, "blur") var at []float64 p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { var err error at, err = chromedp.Evaluate[[]float64](`(()=>{const b=document.querySelector('#composer').getBoundingClientRect();return [b.x+5,b.y+b.height/2]})()`)(ctx, target) return err })) if size.pointer { p.run(chromedp.MouseClickXY(at[0], at[1])) } else { p.run(chromedp.TapXY(at[0], at[1])) } p.run(browsertest.Wait(`document.activeElement===document.querySelector('#chat-body')`)) p.check(`(`+effectiveBackground+`)(document.querySelector('#chat-composer'))===(`+effectiveBackground+`)(document.querySelector('[equipo-thread]'))`, "the dock is not the page's colour") p.check(`getComputedStyle(document.querySelector('#chat-composer')).position==='sticky'`, "the composer is not docked") // Ask: the question at once, then the answer streams and settles. // The session's own last reply leads it: Engineering's headline, // then its summary (as the API answer in ask_test.go). p.check(`(()=>{document.querySelector('#chat-body').value='What did you change and why? ask:git';document.querySelector('#composer').requestSubmit();return true})()`, "ask") p.check(`[...document.querySelectorAll('[equipo-thread] [equipo-message="own"] [equipo-message-body]')].some(e=>e.textContent.startsWith('What did you change'))`, "the question did not show at once") p.run(browsertest.Wait(`(()=>{const e=document.querySelector('[equipo-thread] [equipo-thinking]');if(!e)return false;e.__live=true;return e.querySelector('[data-who]').textContent==='Engineering'})()`)) p.run(browsertest.Wait(`(()=>{const a=document.querySelector('[equipo-thread] [equipo-message="incoming"][data-turn-id]');return !!a && a.__live===true && !a.hasAttribute('equipo-thinking') && a.textContent.includes('From my session: Headline: Made the change the task asks for.') && a.textContent.includes('Replaced "teh panes" with "the panes" in README.md.') && a.textContent.includes('The change: +')})()`)) p.check(`performance.getEntriesByType('navigation').length===window.__nav`, "the page reloaded") p.check(`document.querySelector('[data-ask-specialist]').value===''`, "the next question keeps the last choice") p.stop() } } // Astra 4c round 2: the task page offers asking the implementer about // merged work, like the API, for 14 days after the task is done: the // creator asks Engineering on a Done task and its answer arrives. func TestBrowserAskAfterMerge(t *testing.T) { _, inst, r := localEnv(t) r.start(t) c := inst.Cookie() p := openPage(t, inst.URL, c.Name, c.Value, 390, 844, false) p.send("tool:record_task:oficina/sample|Fix the README typo|teh\ntool:start_task:$task|edit:README.md|teh panes|the panes") card := taskCard("Fix the README typo") for i := 0; ; i++ { err := chromedp.Do(p.ctx, browsertest.Wait(card+`?.querySelector('[equipo-stage]')?.textContent==='Done'`)) if err == nil { break } if i == 12 { t.Fatal(err) } } var link string p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { var err error link, err = chromedp.Evaluate[string](card+`.querySelector('[equipo-roster-links] a[href^="/tasks/"]').href`)(ctx, target) return err })) p.run(chromedp.Navigate(link), browsertest.Wait(`!!document.querySelector('[data-chat-stream][data-task] #composer')`)) p.check(`document.querySelector('[data-ask-line]')?.textContent==='Asking Engineering'`, "a merged task offers no asking") p.check(`(()=>{document.querySelector('#chat-body').value='Now that it is merged, what did you change?';document.querySelector('#composer').requestSubmit();return true})()`, "ask") p.run(browsertest.Wait(`[...document.querySelectorAll('[equipo-thread] [equipo-message="incoming"][data-turn-id]')].some(a=>!a.hasAttribute('equipo-thinking') && a.textContent.includes('From my session:'))`)) p.stop() }