//go:build browser package thintest import ( "amadan.net/oficina/equipo/internal/wire" "fmt" "testing" "time" ) func TestBrowserRosterReports(t *testing.T) { r := newToolRigSaying(t, wire.ProtocolCurrent, personWords) r.researchOn() r.inventoryOn() d := r.runningResearch("roster-research") if _, err := r.inst.DB.Writer().Exec("UPDATE chat_tasks SET title='Research the shop' WHERE id=?", d.TaskID); err != nil { t.Fatal(err) } r.step("roster-findings", wire.StepReport{TaskID: d.TaskID, StepID: d.StepID, Attempt: d.Attempt, State: wire.StepDone, Termination: true, Summary: "Read four pages.", Research: &wire.ResearchResult{Findings: findingsJSON(t, goodFindings()), Fetches: fetchLog()}}) r.nextDispatch() // A paused Copy attempt, with the runner's stored extraction and review. held := r.shopTask("roster-copy") now := r.inst.Store.Chat().Now() raw := `{"extraction":{"version":1,"strings":[{"key":"a","text":"One"},{"key":"b","text":"Two"}]},"review":{"version":1,"strings":[{"key":"a","text":"One"}]}}` if _, err := r.inst.DB.Writer().Exec("INSERT INTO chat_steps(id,task_id,idx,specialist,person,state,reason,attempt,candidate_sha,copy_result,held_at,revision,created_at,updated_at) VALUES('roster-copy-step',?,1,'copy',?,'queued','copy_budget',1,?,?,?,1,?,?)", held, Owner, candX, raw, now, now, now); err != nil { t.Fatal(err) } if _, err := r.inst.DB.Writer().Exec("UPDATE chat_tasks SET copy_hold=1,stage='in_review' WHERE id=?", held); err != nil { t.Fatal(err) } for _, width := range []int64{1280, 390} { for _, scheme := range []string{"light", "dark"} { t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { if _, err := r.inst.DB.Writer().Exec("UPDATE chat_steps SET state='queued',reason='copy_budget',note='',withdrawn=0,terminated=0 WHERE id='roster-copy-step'"); err != nil { t.Fatal(err) } if _, err := r.inst.DB.Writer().Exec("UPDATE chat_tasks SET copy_hold=1 WHERE id=?", held); err != nil { t.Fatal(err) } p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") defer p.stop() p.open("/conversation") p.wait(`document.querySelector('[equipo-offline]').hidden && document.querySelector('[data-research-report]')`, "research findings") p.check(`document.querySelectorAll('[data-research-report] [equipo-roster-findings] a').length===3 && !!document.querySelector('[data-research-report] [data-gap]')`, "findings lost sources or gaps") p.check(`(()=>{document.querySelector('[data-research-report]').previousElementSibling.scrollIntoView({block:'start'});document.querySelector('[equipo-scroll]').dispatchEvent(new Event('scroll'));return true})()`, "show Research") p.check(`[...document.querySelectorAll('[equipo-roster-findings] a')].every(a=>a.textContent===new URL(a.href).hostname && getComputedStyle(a).textDecorationLine==='none')`, "Research sources are raw URLs") p.check(`(()=>{const c=document.querySelector('[data-research-report]');return !!c.previousElementSibling.querySelector('[equipo-roster-project] [equipo-mono]') && c.querySelector('[equipo-roster-task]')?.textContent==='Research the shop'})()`, "Research lacks project and task context") if width == 390 { p.check(`[...document.querySelectorAll('[data-research-report] a')].every(a=>a.getBoundingClientRect().height>=44)`, "Research links lost phone tap targets") } p.check(`!!document.querySelector('[data-research-report] [data-report-talk]')`, "Research report cannot be discussed") p.fits("Research") p.wait(`(()=>{const b=document.querySelector('[data-research-report]').previousElementSibling.getBoundingClientRect(),s=document.querySelector('[equipo-scroll]').getBoundingClientRect();return b.top>=s.top-1 && b.bottom{document.querySelector('[equipo-copy-hold]').closest('[data-card]').scrollIntoView({block:'start'});document.querySelector('[equipo-scroll]').dispatchEvent(new Event('scroll'));return true})()`, "show Copy") p.check(`document.querySelector('[data-copy-continue]').getAttribute('rst-btn')!=='primary' && document.querySelector('[equipo-copy-hold] [equipo-actions]').firstElementChild.matches('a[rst-btn="primary"]') && document.querySelector('[equipo-copy-hold] a[rst-btn="primary"]')?.textContent==='Ask the coordinator'`, "Copy skip encouraged") p.check(`!document.querySelector('[equipo-copy-hold]').textContent.includes('..') && !document.querySelector('[equipo-copy-hold] [equipo-link]')`, "Copy copy or actions drifted") p.check(`!!document.querySelector('[equipo-copy-hold]').closest('[data-card]').querySelector('[equipo-roster-project] [equipo-mono]')`, "Copy lacks project context") p.check(`!!document.querySelector('[equipo-copy-hold]').closest('[data-card]').querySelector('[data-report-talk]')`, "Copy report cannot be discussed") p.fits("Copy hold") if width == 390 { p.check(`(()=>{const c=document.querySelector("[equipo-copy-hold]"),b=c.querySelector('[rst-btn="primary"]');return b.getBoundingClientRect().width>=c.clientWidth-2 && b.getBoundingClientRect().height>=44})()`, "phone primary does not span its row") } p.check(`[...document.querySelectorAll("[equipo-roster-card]")].every(c=>c.scrollWidth<=c.clientWidth+1)`, "content overflows a card") p.shot(fmt.Sprintf("roster-copy-%d-%s", width, scheme)) p.check(`(()=>{document.querySelector('[equipo-copy-hold]').closest('[data-card]').querySelector('[data-set-aside]').click();return true})()`, "set Copy aside") p.wait(`document.querySelector('[equipo-aside-stub]')`, "Copy stub") p.open("/tasks?needs=you") p.check(`!!document.querySelector('a[href="/tasks/`+held+`"]')`, "Copy hold missing from Needs you") p.open("/tasks/" + held) p.check(`!!document.querySelector('[data-copy-continue]')`, "Copy hold unreachable from task") p.open("/conversation") p.click(`[equipo-aside-stub] [data-aside-undo]`) p.wait(`document.querySelector('[equipo-copy-meter]')`, "Copy restored") 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 Copy action") p.click(`[data-copy-continue]`) p.check(`document.querySelector('[data-copy-continue]').getAttribute('aria-busy')==='true' && document.querySelector('[equipo-copy-hold]').closest('[data-card]').querySelector('[data-set-aside]').disabled`, "Copy busy state") p.shot(fmt.Sprintf("roster-copy-busy-%d-%s", width, scheme)) p.check(`(()=>{window.__fail();window.fetch=window.__fetch;return true})()`, "fail Copy action") p.wait(`document.querySelector('[equipo-copy-hold]').parentElement.querySelector('[equipo-card-error]:not([hidden])')`, "Copy error") p.shot(fmt.Sprintf("roster-copy-error-%d-%s", width, scheme)) p.click(`[equipo-copy-hold] ~ [equipo-card-error] button`) p.wait(`[...document.querySelectorAll('[equipo-card-done]')].some(e=>e.textContent.includes('Continuing without Copy.'))`, "Copy success") p.shot(fmt.Sprintf("roster-copy-done-%d-%s", width, scheme)) }) } } } func TestBrowserRosterQuietDay(t *testing.T) { r := newToolRig(t) r.runner.Send(r.ctx, "quiet-reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "Nothing else today."}) r.wait("quiet reply", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnReplied }) now := r.inst.Store.Chat().Now() y := time.Date(now.Year(), now.Month(), now.Day()-1, 12, 0, 0, 0, time.UTC) if _, err := r.inst.DB.Writer().Exec("UPDATE chat_messages SET created_at=?", y); err != nil { t.Fatal(err) } for _, width := range []int64{1280, 390} { for _, scheme := range []string{"light", "dark"} { t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") defer p.stop() p.open("/conversation") p.check(`!!document.querySelector('[equipo-day-quiet]') && !document.querySelector('[equipo-daybar]')`, "quiet day invents work") p.shot(fmt.Sprintf("roster-quiet-%d-%s", width, scheme)) p.click(`[data-day-toggle]`) p.wait(`document.querySelector('[equipo-day-feed]')?.textContent.includes('Nothing else today.')`, "quiet transcript") p.fits("quiet day") p.shot(fmt.Sprintf("roster-quiet-open-%d-%s", width, scheme)) }) } } }