| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "amadan.net/oficina/equipo/internal/wire" |
| 7 | "fmt" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestBrowserCoordinatorQueue(t *testing.T) { |
| 12 | for _, width := range []int64{1280, 390} { |
| 13 | for _, scheme := range []string{"light", "dark"} { |
| 14 | t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { |
| 15 | r := newToolRig(t) |
| 16 | p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") |
| 17 | defer p.stop() |
| 18 | p.open("/conversation") |
| 19 | p.wait(`document.querySelectorAll('[equipo-thinking]').length===1 && document.querySelector('[equipo-offline]').hidden`, "original thinking") |
| 20 | 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})()` |
| 21 | p.check(watch, "observe live thinking count") |
| 22 | if err := r.runner.Send(r.ctx, "explore", wire.FrameMoveIn, wire.MoveIn{Person: Owner, Kind: wire.TurnExplore}); err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | var explore string |
| 26 | r.wait("explore queued", func(c *Conversation) bool { |
| 27 | for id, v := range c.Turns { |
| 28 | if v.Kind == wire.TurnExplore { |
| 29 | explore = id |
| 30 | return true |
| 31 | } |
| 32 | } |
| 33 | return false |
| 34 | }) |
| 35 | 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 { |
| 36 | t.Fatal(err) |
| 37 | } |
| 38 | p.wait(`document.querySelector('[equipo-thinking] [equipo-activity]')?.textContent==='Reading the code…'`, "activity after queued turn reached browser") |
| 39 | p.check(`window.thinkingPeak===1 && document.querySelectorAll('[equipo-thinking]').length===1`, "one live thinking line") |
| 40 | p.open("/conversation") |
| 41 | p.check(`document.querySelectorAll('[equipo-thinking]').length===1`, "one thinking line after reload") |
| 42 | p.check(watch, "observe queue advance") |
| 43 | if err := r.runner.Send(r.ctx, "reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "Done."}); err != nil { |
| 44 | t.Fatal(err) |
| 45 | } |
| 46 | r.runner.Expect(r.ctx, wire.FrameMessage) |
| 47 | if err := r.runner.Send(r.ctx, "explore-running", wire.FrameTurn, wire.TurnReport{TurnID: explore, Attempt: 1, State: wire.TurnRunning}); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | p.wait(`document.querySelector('[equipo-thinking][data-turn="`+explore+`"]')`, "queued explore starts") |
| 51 | p.check(`window.thinkingPeak===1 && document.querySelectorAll('[equipo-thinking]').length===1`, "one line when queue advances") |
| 52 | p.shot(fmt.Sprintf("access-queue-%d-%s", width, scheme)) |
| 53 | }) |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestBrowserAccessEmojiByline(t *testing.T) { |
| 59 | r := newAlignRig(t) |
| 60 | if err := r.inst.DB.G.Exec("UPDATE chat_projects SET title = ?, title_set = 1", "🤖 CARLOS platform").Error; err != nil { |
| 61 | t.Fatal(err) |
| 62 | } |
| 63 | for _, width := range []int64{1280, 390} { |
| 64 | for _, scheme := range []string{"light", "dark"} { |
| 65 | t.Run(fmt.Sprintf("%d-%s", width, scheme), func(t *testing.T) { |
| 66 | p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce") |
| 67 | defer p.stop() |
| 68 | p.open("/conversation") |
| 69 | p.wait(`document.querySelector('[equipo-roster-byline] [equipo-placement]')`, "project byline") |
| 70 | 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") |
| 71 | |
| 72 | 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") |
| 73 | p.fits("emoji byline") |
| 74 | 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") |
| 75 | p.shot(fmt.Sprintf("access-byline-%d-%s", width, scheme)) |
| 76 | }) |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |