| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "amadan.net/oficina/equipo/internal/wire" |
| 7 | "fmt" |
| 8 | "testing" |
| 9 | "time" |
| 10 | ) |
| 11 | |
| 12 | func TestBrowserRosterReports(t *testing.T) { |
| 13 | r := newToolRigSaying(t, wire.ProtocolCurrent, personWords) |
| 14 | r.researchOn() |
| 15 | r.inventoryOn() |
| 16 | d := r.runningResearch("roster-research") |
| 17 | if _, err := r.inst.DB.Writer().Exec("UPDATE chat_tasks SET title='Research the shop' WHERE id=?", d.TaskID); err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | 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()}}) |
| 21 | r.nextDispatch() |
| 22 | // A paused Copy attempt, with the runner's stored extraction and review. |
| 23 | held := r.shopTask("roster-copy") |
| 24 | now := r.inst.Store.Chat().Now() |
| 25 | raw := `{"extraction":{"version":1,"strings":[{"key":"a","text":"One"},{"key":"b","text":"Two"}]},"review":{"version":1,"strings":[{"key":"a","text":"One"}]}}` |
| 26 | 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 { |
| 27 | t.Fatal(err) |
| 28 | } |
| 29 | if _, err := r.inst.DB.Writer().Exec("UPDATE chat_tasks SET copy_hold=1,stage='in_review' WHERE id=?", held); err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | for _, width := range []int64{1280, 390} { |
| 33 | for _, scheme := range []string{"light", "dark"} { |
| 34 | t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { |
| 35 | 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 { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | if _, err := r.inst.DB.Writer().Exec("UPDATE chat_tasks SET copy_hold=1 WHERE id=?", held); err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") |
| 42 | defer p.stop() |
| 43 | p.open("/conversation") |
| 44 | p.wait(`document.querySelector('[equipo-offline]').hidden && document.querySelector('[data-research-report]')`, "research findings") |
| 45 | 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") |
| 46 | p.check(`(()=>{document.querySelector('[data-research-report]').previousElementSibling.scrollIntoView({block:'start'});document.querySelector('[equipo-scroll]').dispatchEvent(new Event('scroll'));return true})()`, "show Research") |
| 47 | 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") |
| 48 | 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") |
| 49 | if width == 390 { |
| 50 | p.check(`[...document.querySelectorAll('[data-research-report] a')].every(a=>a.getBoundingClientRect().height>=44)`, "Research links lost phone tap targets") |
| 51 | } |
| 52 | p.check(`!!document.querySelector('[data-research-report] [data-report-talk]')`, "Research report cannot be discussed") |
| 53 | p.fits("Research") |
| 54 | 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<s.bottom})()`, "Research byline in view") |
| 55 | p.shot(fmt.Sprintf("roster-research-%d-%s", width, scheme)) |
| 56 | p.check(`document.querySelector('[equipo-copy-meter]').textContent.includes('1 of 2 strings reviewed') && document.querySelector('[equipo-copy-meter] meter').value===1`, "Copy coverage") |
| 57 | p.check(`(()=>{document.querySelector('[equipo-copy-hold]').closest('[data-card]').scrollIntoView({block:'start'});document.querySelector('[equipo-scroll]').dispatchEvent(new Event('scroll'));return true})()`, "show Copy") |
| 58 | 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") |
| 59 | p.check(`!document.querySelector('[equipo-copy-hold]').textContent.includes('..') && !document.querySelector('[equipo-copy-hold] [equipo-link]')`, "Copy copy or actions drifted") |
| 60 | p.check(`!!document.querySelector('[equipo-copy-hold]').closest('[data-card]').querySelector('[equipo-roster-project] [equipo-mono]')`, "Copy lacks project context") |
| 61 | p.check(`!!document.querySelector('[equipo-copy-hold]').closest('[data-card]').querySelector('[data-report-talk]')`, "Copy report cannot be discussed") |
| 62 | p.fits("Copy hold") |
| 63 | if width == 390 { |
| 64 | 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") |
| 65 | } |
| 66 | p.check(`[...document.querySelectorAll("[equipo-roster-card]")].every(c=>c.scrollWidth<=c.clientWidth+1)`, "content overflows a card") |
| 67 | p.shot(fmt.Sprintf("roster-copy-%d-%s", width, scheme)) |
| 68 | p.check(`(()=>{document.querySelector('[equipo-copy-hold]').closest('[data-card]').querySelector('[data-set-aside]').click();return true})()`, "set Copy aside") |
| 69 | p.wait(`document.querySelector('[equipo-aside-stub]')`, "Copy stub") |
| 70 | p.open("/tasks?needs=you") |
| 71 | p.check(`!!document.querySelector('a[href="/tasks/`+held+`"]')`, "Copy hold missing from Needs you") |
| 72 | p.open("/tasks/" + held) |
| 73 | p.check(`!!document.querySelector('[data-copy-continue]')`, "Copy hold unreachable from task") |
| 74 | p.open("/conversation") |
| 75 | p.click(`[equipo-aside-stub] [data-aside-undo]`) |
| 76 | p.wait(`document.querySelector('[equipo-copy-meter]')`, "Copy restored") |
| 77 | 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") |
| 78 | p.click(`[data-copy-continue]`) |
| 79 | 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") |
| 80 | p.shot(fmt.Sprintf("roster-copy-busy-%d-%s", width, scheme)) |
| 81 | p.check(`(()=>{window.__fail();window.fetch=window.__fetch;return true})()`, "fail Copy action") |
| 82 | p.wait(`document.querySelector('[equipo-copy-hold]').parentElement.querySelector('[equipo-card-error]:not([hidden])')`, "Copy error") |
| 83 | p.shot(fmt.Sprintf("roster-copy-error-%d-%s", width, scheme)) |
| 84 | p.click(`[equipo-copy-hold] ~ [equipo-card-error] button`) |
| 85 | p.wait(`[...document.querySelectorAll('[equipo-card-done]')].some(e=>e.textContent.includes('Continuing without Copy.'))`, "Copy success") |
| 86 | p.shot(fmt.Sprintf("roster-copy-done-%d-%s", width, scheme)) |
| 87 | }) |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | func TestBrowserRosterQuietDay(t *testing.T) { |
| 93 | r := newToolRig(t) |
| 94 | r.runner.Send(r.ctx, "quiet-reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "Nothing else today."}) |
| 95 | r.wait("quiet reply", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnReplied }) |
| 96 | now := r.inst.Store.Chat().Now() |
| 97 | y := time.Date(now.Year(), now.Month(), now.Day()-1, 12, 0, 0, 0, time.UTC) |
| 98 | if _, err := r.inst.DB.Writer().Exec("UPDATE chat_messages SET created_at=?", y); err != nil { |
| 99 | t.Fatal(err) |
| 100 | } |
| 101 | for _, width := range []int64{1280, 390} { |
| 102 | for _, scheme := range []string{"light", "dark"} { |
| 103 | t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { |
| 104 | p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") |
| 105 | defer p.stop() |
| 106 | p.open("/conversation") |
| 107 | p.check(`!!document.querySelector('[equipo-day-quiet]') && !document.querySelector('[equipo-daybar]')`, "quiet day invents work") |
| 108 | p.shot(fmt.Sprintf("roster-quiet-%d-%s", width, scheme)) |
| 109 | p.click(`[data-day-toggle]`) |
| 110 | p.wait(`document.querySelector('[equipo-day-feed]')?.textContent.includes('Nothing else today.')`, "quiet transcript") |
| 111 | p.fits("quiet day") |
| 112 | p.shot(fmt.Sprintf("roster-quiet-open-%d-%s", width, scheme)) |
| 113 | }) |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |