| 1 | //go:build browser |
| 2 | |
| 3 | package headless |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/browsertest" |
| 10 | "github.com/chromedp/chromedp" |
| 11 | ) |
| 12 | |
| 13 | // Ask the implementer from the task page (Paul, 2026-11-07): the thread |
| 14 | // has the chat's quiet composer (a click anywhere in it focuses the |
| 15 | // message, the dock is the page's own colour) and a quiet "Asking |
| 16 | // Engineering · change" line that follows what is typed and switches |
| 17 | // with change. A question shows at once; its answer streams into a |
| 18 | // thinking line labelled with the specialist and settles in place, with |
| 19 | // no reload. At 1280 with a mouse and 390 with touch. |
| 20 | func TestBrowserTaskThread(t *testing.T) { |
| 21 | for _, size := range []struct { |
| 22 | w, h int64 |
| 23 | pointer bool |
| 24 | }{{1280, 900, true}, {390, 844, false}} { |
| 25 | _, inst, r := localEnv(t) |
| 26 | r.start(t) |
| 27 | c := inst.Cookie() |
| 28 | p := openPage(t, inst.URL, c.Name, c.Value, size.w, size.h, size.pointer) |
| 29 | p.send("tool:record_task:oficina/sample|Fix the README typo|teh\ntool:start_task:$task|edit:README.md|teh panes|the panes") |
| 30 | card := taskCard("Fix the README typo") |
| 31 | // Engineering, checks, review and Equipo's merge take a while under |
| 32 | // load. Merged work can still be asked about (Paul, 2026-11-08). |
| 33 | for i := 0; ; i++ { |
| 34 | err := chromedp.Do(p.ctx, browsertest.Wait(card+`?.querySelector('[equipo-stage]')?.textContent==='Done'`)) |
| 35 | if err == nil { |
| 36 | break |
| 37 | } |
| 38 | if i == 12 { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | } |
| 42 | var link string |
| 43 | p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| 44 | var err error |
| 45 | link, err = chromedp.Evaluate[string](card+`.querySelector('[equipo-roster-links] a[href^="/tasks/"]').href`)(ctx, target) |
| 46 | return err |
| 47 | })) |
| 48 | p.run(chromedp.Navigate(link), browsertest.Wait(`!!document.querySelector('[data-chat-stream][data-task] #composer')`)) |
| 49 | p.check(`(()=>{window.__nav=performance.getEntriesByType('navigation').length;return true})()`, "mark") |
| 50 | line := `document.querySelector('[data-ask-line]').textContent` |
| 51 | p.check(line+`==='Asking Engineering' && !document.querySelector('[data-ask-change]').hidden && document.querySelector('#chat-body').placeholder==='Ask Engineering about this work'`, "the ask line") |
| 52 | // It follows what is typed, and change switches it. |
| 53 | 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") |
| 54 | 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") |
| 55 | p.check(`(()=>{document.querySelector('[data-ask-change]').click();return `+line+`==='Asking Engineering' && document.querySelector('[data-ask-specialist]').value==='engineering'})()`, "change back") |
| 56 | // The chat's composer: a click in its padding focuses the message. |
| 57 | p.check(`(()=>{document.activeElement&&document.activeElement.blur();document.querySelector('[equipo-thread] h2').scrollIntoView({block:'start'});return true})()`, "blur") |
| 58 | var at []float64 |
| 59 | p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| 60 | var err error |
| 61 | at, err = chromedp.Evaluate[[]float64](`(()=>{const b=document.querySelector('#composer').getBoundingClientRect();return [b.x+5,b.y+b.height/2]})()`)(ctx, target) |
| 62 | return err |
| 63 | })) |
| 64 | if size.pointer { |
| 65 | p.run(chromedp.MouseClickXY(at[0], at[1])) |
| 66 | } else { |
| 67 | p.run(chromedp.TapXY(at[0], at[1])) |
| 68 | } |
| 69 | p.run(browsertest.Wait(`document.activeElement===document.querySelector('#chat-body')`)) |
| 70 | p.check(`(`+effectiveBackground+`)(document.querySelector('#chat-composer'))===(`+effectiveBackground+`)(document.querySelector('[equipo-thread]'))`, "the dock is not the page's colour") |
| 71 | p.check(`getComputedStyle(document.querySelector('#chat-composer')).position==='sticky'`, "the composer is not docked") |
| 72 | // Ask: the question at once, then the answer streams and settles. |
| 73 | // The session's own last reply leads it: Engineering's headline, |
| 74 | // then its summary (as the API answer in ask_test.go). |
| 75 | p.check(`(()=>{document.querySelector('#chat-body').value='What did you change and why? ask:git';document.querySelector('#composer').requestSubmit();return true})()`, "ask") |
| 76 | 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") |
| 77 | 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'})()`)) |
| 78 | 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: +')})()`)) |
| 79 | p.check(`performance.getEntriesByType('navigation').length===window.__nav`, "the page reloaded") |
| 80 | p.check(`document.querySelector('[data-ask-specialist]').value===''`, "the next question keeps the last choice") |
| 81 | p.stop() |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Astra 4c round 2: the task page offers asking the implementer about |
| 86 | // merged work, like the API, for 14 days after the task is done: the |
| 87 | // creator asks Engineering on a Done task and its answer arrives. |
| 88 | func TestBrowserAskAfterMerge(t *testing.T) { |
| 89 | _, inst, r := localEnv(t) |
| 90 | r.start(t) |
| 91 | c := inst.Cookie() |
| 92 | p := openPage(t, inst.URL, c.Name, c.Value, 390, 844, false) |
| 93 | p.send("tool:record_task:oficina/sample|Fix the README typo|teh\ntool:start_task:$task|edit:README.md|teh panes|the panes") |
| 94 | card := taskCard("Fix the README typo") |
| 95 | for i := 0; ; i++ { |
| 96 | err := chromedp.Do(p.ctx, browsertest.Wait(card+`?.querySelector('[equipo-stage]')?.textContent==='Done'`)) |
| 97 | if err == nil { |
| 98 | break |
| 99 | } |
| 100 | if i == 12 { |
| 101 | t.Fatal(err) |
| 102 | } |
| 103 | } |
| 104 | var link string |
| 105 | p.run(chromedp.Func(func(ctx context.Context, target *chromedp.Target) error { |
| 106 | var err error |
| 107 | link, err = chromedp.Evaluate[string](card+`.querySelector('[equipo-roster-links] a[href^="/tasks/"]').href`)(ctx, target) |
| 108 | return err |
| 109 | })) |
| 110 | p.run(chromedp.Navigate(link), browsertest.Wait(`!!document.querySelector('[data-chat-stream][data-task] #composer')`)) |
| 111 | p.check(`document.querySelector('[data-ask-line]')?.textContent==='Asking Engineering'`, "a merged task offers no asking") |
| 112 | p.check(`(()=>{document.querySelector('#chat-body').value='Now that it is merged, what did you change?';document.querySelector('#composer').requestSubmit();return true})()`, "ask") |
| 113 | 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:'))`)) |
| 114 | p.stop() |
| 115 | } |
| 116 | |