//go:build browser package thintest import ( "amadan.net/oficina/equipo/internal/wire" "fmt" "testing" ) func TestBrowserCoordinatorQueue(t *testing.T) { for _, width := range []int64{1280, 390} { for _, scheme := range []string{"light", "dark"} { t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { r := newToolRig(t) p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") defer p.stop() p.open("/conversation") p.wait(`document.querySelectorAll('[equipo-thinking]').length===1 && document.querySelector('[equipo-offline]').hidden`, "original thinking") watch := `(()=>{window.thinkingPeak=document.querySelectorAll('[equipo-thinking]').length;new MutationObserver(()=>{window.thinkingPeak=Math.max(window.thinkingPeak,document.querySelectorAll('[equipo-thinking]').length)}).observe(document.querySelector('[data-chat-stream]'),{childList:true,subtree:true});return true})()` p.check(watch, "observe live thinking count") if err := r.runner.Send(r.ctx, "explore", wire.FrameMoveIn, wire.MoveIn{Person: Owner, Kind: wire.TurnExplore}); err != nil { t.Fatal(err) } var explore string r.wait("explore queued", func(c *Conversation) bool { for id, v := range c.Turns { if v.Kind == wire.TurnExplore { explore = id return true } } return false }) if err := r.runner.Send(r.ctx, "read-after-queue", wire.FrameActivity, wire.ActivityReport{TurnID: r.turn, Attempt: 1, Kind: wire.ActivityTool, Tool: wire.ToolReadFile}); err != nil { t.Fatal(err) } p.wait(`document.querySelector('[equipo-thinking] [equipo-activity]')?.textContent==='Reading the code…'`, "activity after queued turn reached browser") p.check(`window.thinkingPeak===1 && document.querySelectorAll('[equipo-thinking]').length===1`, "one live thinking line") p.open("/conversation") p.check(`document.querySelectorAll('[equipo-thinking]').length===1`, "one thinking line after reload") p.check(watch, "observe queue advance") if err := r.runner.Send(r.ctx, "reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "Done."}); err != nil { t.Fatal(err) } r.runner.Expect(r.ctx, wire.FrameMessage) if err := r.runner.Send(r.ctx, "explore-running", wire.FrameTurn, wire.TurnReport{TurnID: explore, Attempt: 1, State: wire.TurnRunning}); err != nil { t.Fatal(err) } p.wait(`document.querySelector('[equipo-thinking][data-turn="`+explore+`"]')`, "queued explore starts") p.check(`window.thinkingPeak===1 && document.querySelectorAll('[equipo-thinking]').length===1`, "one line when queue advances") p.shot(fmt.Sprintf("access-queue-%d-%s", width, scheme)) }) } } } func TestBrowserAccessEmojiByline(t *testing.T) { r := newAlignRig(t) if err := r.inst.DB.G.Exec("UPDATE chat_projects SET title = ?, title_set = 1", "🤖 CARLOS platform").Error; 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.wait(`document.querySelector('[equipo-roster-byline] [equipo-placement]')`, "project byline") p.check(`Array.from(document.querySelectorAll('[equipo-roster-byline]')).filter(n=>n.querySelector('[equipo-placement]')).every(n=>(n.textContent.match(/🤖/gu)||[]).length===1)`, "project mark appears once") p.check(`Array.from(document.querySelectorAll('[equipo-roster-byline]')).filter(n=>n.querySelector('[equipo-placement]')&&n.querySelector('b')).every(n=>{const a=n.querySelector('b').getBoundingClientRect(),b=n.querySelector('summary').getBoundingClientRect(),t=n.querySelector('time').getBoundingClientRect();return Math.abs((a.top+a.height/2)-(b.top+b.height/2))<3 && t.height<24})`, "author and project share a line; time wraps as a unit") p.fits("emoji byline") p.check(`(()=>{const n=Array.from(document.querySelectorAll('[equipo-roster-byline]')).find(n=>n.querySelector('[equipo-placement]')&&n.querySelector('b'));n.scrollIntoView({block:'center',behavior:'instant'});return true})()`, "show report byline") p.shot(fmt.Sprintf("access-byline-%d-%s", width, scheme)) }) } } }