//go:build browser package headless import ( "strconv" "testing" "amadan.net/oficina/equipo/internal/browsertest" "amadan.net/oficina/equipo/internal/thintest" "amadan.net/oficina/equipo/internal/wire" "github.com/chromedp/chromedp" ) // addDay is where the Add page's screenshots go. const addDay = "2026-11-10" // Paul, 2026-11-10: "Can 'Add a connection' go to a new screen?" From // Connections, Add a connection opens its own page in Settings (on a // phone, Connections in its bar). The chooser is there; Codex's device // code card arrives in place from the stream, with no reload; once the // runner reports the connection healthy, the flourish plays and the page // goes back to Connections, the new row marked for a moment. func TestBrowserConnectionsAddPage(t *testing.T) { for _, width := range []int64{1280, 390} { t.Run(strconv.FormatInt(width, 10), func(t *testing.T) { inst := thintest.StartInstance(t) runner := dialFake(t, inst) c := inst.Cookie() p := openPage(t, inst.URL, c.Name, c.Value, width, 900, width > 600) t.Cleanup(p.stop) shot := func(name string) { t.Helper(); connShotOn(t, p, addDay, name, width) } p.run(chromedp.Navigate(inst.URL+"/conversation/settings/connections"), browsertest.Wait(`!!document.querySelector('[data-connections]')`)) p.check(`(()=>{const a=document.querySelector('[data-add-link]');return !!a && a.checkVisibility() && a.textContent.trim()==='Add a connection' && !document.querySelector('[equipo-conn-chooser]')})()`, "Connections has no Add a connection link, or still holds the chooser") p.check(`(()=>{document.querySelector('[data-add-link]').click();return true})()`, "Add a connection") p.run(waitLong(`location.pathname==='/conversation/settings/connections/add' && !!document.querySelector('[equipo-conn-chooser]')`)) p.check(`(()=>{window.__equipoStayed=true;sessionStorage.removeItem('success');new MutationObserver(()=>{if(document.querySelector('[data-success]'))sessionStorage.setItem('success','1')}).observe(document.body,{childList:true,subtree:true});return true})()`, "mark") // The page: its heading, the chooser with Claude and Codex // live, TensorX, and two greyed, in Settings with Connections current. p.check(`(()=>{const c=document.querySelector('[equipo-conn-chooser]');return document.querySelector('[equipo-settings-body] h1').textContent==='Add a connection' && c.checkVisibility() && !document.querySelector('[data-add="codex"]').disabled && !document.querySelector('[data-add="claude"]').disabled && c.querySelectorAll('[equipo-conn-opt][disabled]').length===2 && !!c.querySelector('[data-add-metered="tensorx"]') && document.querySelector('[equipo-settings-link][aria-current="page"]').dataset.settingsLink==='connections' && document.documentElement.scrollWidth<=innerWidth+1})()`, "the Add page is not the chooser in Settings") if width < 600 { p.check(`(()=>{const back=document.querySelector('[rst-shell-back] a');return back.checkVisibility() && back.getAttribute('href')==='/conversation/settings/connections' && back.textContent.trim()==='Connections' && !document.querySelector('[equipo-settings-nav]').checkVisibility()})()`, "390: no way back to Connections in the bar") } else { p.check(`document.querySelector('[equipo-settings-rail]').checkVisibility() && document.querySelector('[equipo-settings-rail] [aria-current="page"]').dataset.railSettings==='connections-add'`, "1280: the rail is not the Settings nav with Add a connection current") } p.run(waitLong(`document.getAnimations().every(a=>a.playState!=='running'||a.effect&&a.effect.getTiming().iterations===Infinity)`)) shot("add-chooser") // Codex: the card at once, then the device code from the stream. p.check(`(()=>{document.querySelector('[data-add="codex"]').click();return !!document.querySelector('[data-connecting][data-provider="codex"]')})()`, "no card the instant Codex is chosen") cmd := runner.expect(t, wire.FrameConnect).(*wire.ConnectCommand) if cmd.Provider != "codex" { t.Fatalf("connect frame %+v", cmd) } runner.send(t, wire.FrameConnection, wire.ConnectionReport{Connection: cmd.Connection, Person: thintest.Owner, Provider: "codex", State: wire.ConnConnecting, Prompt: &wire.ConnectPrompt{Kind: wire.PromptDeviceCode, URL: "https://auth.openai.com/codex/device", Code: "FAKE-2468"}}) p.run(waitLong(`!!document.querySelector('[data-device-code]')`)) p.check(`(()=>{const card=document.querySelector('[data-connecting][data-provider="codex"]');return card.querySelector('[data-code]').textContent==='FAKE-2468' && card.querySelectorAll('ol > li').length===3 && !!card.querySelector('[data-copy-link]') && !!card.querySelector('[equipo-conn-waiting]') && !document.querySelector('[equipo-conn-chooser]')})()`, "the device code card is not the three steps") p.check(stayed, "the page reloaded or navigated while the code arrived") shot("add-codex-code") // Approved: the flourish here, then Connections with the row. runner.send(t, wire.FrameConnection, wire.ConnectionReport{Connection: cmd.Connection, Person: thintest.Owner, LocalID: "codex-1", Provider: "codex", State: wire.ConnHealthy, Label: second, Plan: "pro"}) runner.hello(t, wire.HeldConnection{LocalID: "codex-1", Person: thintest.Owner, Provider: "codex", Kind: wire.KindSubscription, Label: second, State: wire.ConnHealthy, Plan: "pro"}) p.run(waitLong(`location.pathname==='/conversation/settings/connections' && !!document.querySelector('[equipo-conn-row][data-connection="` + cmd.Connection + `"][data-new]')`)) p.check(`(()=>{const row=document.querySelector('[equipo-conn-row][data-connection="`+cmd.Connection+`"]');const nav=performance.getEntriesByType('navigation')[0];return sessionStorage.getItem('success')==='1' && nav.type==='navigate' && location.search==='' && row.checkVisibility() && row.querySelector('[data-connection-state]').textContent==='Ready' && row.textContent.includes('`+second+`') && row.getAnimations().length>0})()`, "no flourish before Connections, or the new row is not marked") shot("add-connected") // The mark fades and does not come back with the stream. p.run(waitLong(`!document.querySelector('[equipo-conn-row][data-new]')`)) }) } } // Paul, 2026-11-10: after an expired Claude sign-in, "The sign-in was // not finished in time." stayed under the list. It is a quiet notice // with Dismiss, and it goes by itself, live, once a newer attempt starts // or connects. func TestBrowserConnectionsEndedNote(t *testing.T) { const note = `[...document.querySelectorAll('[data-connection-note]')].filter(n=>n.checkVisibility() && n.textContent==='The sign-in was not finished in time.')` for _, width := range []int64{1280, 390} { t.Run(strconv.FormatInt(width, 10), func(t *testing.T) { inst := thintest.StartInstance(t) runner := dialFake(t, inst) client := thintest.NewClient(inst.URL, inst.DeviceToken(t)) c := inst.Cookie() p := openPage(t, inst.URL, c.Name, c.Value, width, 900, width > 600) t.Cleanup(p.stop) ended := func(provider string) { t.Helper() a, err := client.Connect(t.Context(), wire.Connect{Provider: provider}) if err != nil { t.Fatal(err) } runner.expect(t, wire.FrameConnect) runner.send(t, wire.FrameConnection, wire.ConnectionReport{Connection: a.ID, Person: thintest.Owner, Provider: provider, State: wire.ConnError, Reason: "timed_out"}) } ended("claude") p.run(chromedp.Navigate(inst.URL+"/conversation/settings/connections"), browsertest.Wait(note+`.length===1`)) p.check(`(()=>{window.__equipoStayed=true;const b=document.querySelector('[data-connection-note] [data-dismiss]');return b.checkVisibility() && b.getAttribute('aria-label')==='Dismiss'})()`, "the notice has no Dismiss") connShotOn(t, p, addDay, "ended-note", width) // Dismissed: gone at once, and for good. p.check(`(()=>{document.querySelector('[data-connection-note] [data-dismiss]').click();return `+note+`.length===0})()`, "Dismiss did not hide the notice") p.run(waitLong(`!document.querySelector('[data-connection-note]')`)) p.check(stayed, "the page reloaded or navigated on Dismiss") // A newer attempt that connects clears it, live. ended("claude") p.run(waitLong(note + `.length===1`)) a, err := client.Connect(t.Context(), wire.Connect{Provider: "codex"}) if err != nil { t.Fatal(err) } runner.expect(t, wire.FrameConnect) runner.send(t, wire.FrameConnection, wire.ConnectionReport{Connection: a.ID, Person: thintest.Owner, LocalID: "codex-1", Provider: "codex", State: wire.ConnHealthy, Label: second, Plan: "pro"}) p.run(waitLong(`!!document.querySelector('[equipo-conn-row][data-provider="codex"]') && ` + note + `.length===0`)) p.check(stayed, "the page reloaded or navigated") // On the Add page, choosing a provider starts a newer attempt: // the notice goes at once and stays gone. ended("claude") p.run(chromedp.Navigate(inst.URL+"/conversation/settings/connections/add"), browsertest.Wait(note+`.length===1`)) p.check(`(()=>{window.__equipoStayed=true;document.querySelector('[data-add="claude"]').click();return `+note+`.length===0})()`, "a new attempt left the notice") runner.expect(t, wire.FrameConnect) p.run(waitLong(`!!document.querySelector('[data-connecting][data-provider="claude"]') && ` + note + `.length===0`)) p.check(stayed, "the page reloaded or navigated") }) } }