oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package headless
4
5import (
6 "strconv"
7 "testing"
8
9 "amadan.net/oficina/equipo/internal/browsertest"
10 "amadan.net/oficina/equipo/internal/thintest"
11 "amadan.net/oficina/equipo/internal/wire"
12 "github.com/chromedp/chromedp"
13)
14
15// signInEmailDay is where the sign-in email's screenshots go.
16const signInEmailDay = "2026-11-24"
17
18// Paul, 2026-11-23: a sign-in by a link makes a token connection whose
19// account Claude will not name, so the code's step asks for the account
20// email once, optionally: Claude account email under the code field,
21// empty, with its hint, and Connect after both. An email the server
22// refuses says so beside the field, the code waiting in its own; one it
23// takes is posted alone, before the sealed code, and is on the row as
24// the person's own once the connection is made.
25func TestBrowserConnectionsSignInEmail(t *testing.T) {
26 for _, width := range []int64{1280, 390} {
27 t.Run(strconv.FormatInt(width, 10), func(t *testing.T) {
28 inst := thintest.StartInstance(t)
29 runner := dialFake(t, inst)
30 c := inst.Cookie()
31 p := openPage(t, inst.URL, c.Name, c.Value, width, 900, width > 600)
32 t.Cleanup(p.stop)
33 shot := func(name string) { t.Helper(); connShotOn(t, p, signInEmailDay, name, width) }
34 p.run(chromedp.Navigate(inst.URL+"/conversation/settings/connections/add"), browsertest.Wait(`!!document.querySelector('[data-connections]') && !!window.EquipoSeal && !!window.nacl`))
35 p.check(`(()=>{window.__equipoStayed=true;return true})()`, "mark")
36 p.check(recordPosts, "record posts")
37 p.check(`(()=>{document.querySelector('[data-add="claude"]').click();return true})()`, "Claude")
38 cmd := runner.expect(t, wire.FrameConnect).(*wire.ConnectCommand)
39 runner.send(t, wire.FrameConnection, wire.ConnectionReport{Connection: cmd.Connection, Person: thintest.Owner, Provider: "claude", State: wire.ConnConnecting, Prompt: &wire.ConnectPrompt{Kind: wire.PromptAuthorize, URL: signInLinks[0], Attempt: 1}})
40 p.run(waitLong(`!!document.querySelector('[data-code-steps]')`))
41 p.check(`(()=>{const form=document.querySelector('[data-code-form]');const code=form.querySelector('[data-code-field]');const mail=form.querySelector('[data-email-field]');const label=form.querySelector('label[for="'+mail.id+'"]');const hint=mail.nextElementSibling;const go=form.querySelector('[data-code-connect]');const all=[...form.querySelectorAll('*')];const follows=(a,b)=>all.indexOf(a)<all.indexOf(b);return !code.name && mail.type==='email' && mail.name==='email' && mail.value==='' && !mail.required && label.textContent==='Claude account email' && hint.textContent==='Optional. Shown wherever Equipo names this connection. Equipo does not verify it with Claude.' && mail.checkVisibility() && follows(code,mail) && follows(mail,go) && go.getBoundingClientRect().top>=mail.getBoundingClientRect().bottom && getComputedStyle(label).fontSize!==getComputedStyle(form.querySelector('label[for="'+code.id+'"]')).fontSize && document.documentElement.scrollWidth<=innerWidth+1})()`, "the sign-in step does not ask for the account email, empty and optional, before Connect")
42 p.run(waitLong(`document.getAnimations().every(a=>a.playState!=='running'||a.effect&&a.effect.getTiming().iterations===Infinity)`))
43 shot("signin-email")
44
45 // Refused by the server: said beside the field; the code waits.
46 p.check(`(()=>{window.__posts=[];const f=document.querySelector('[data-code-form]');f.querySelector('[data-code-field]').value=`+jsonString(canarySignInCode)+`;f.querySelector('[data-email-field]').value='me@example';f.requestSubmit();return true})()`, "a bad email")
47 p.run(waitLong(`(()=>{const n=document.querySelector('[data-code-form] [data-email-note]');return !n.hidden && n.textContent==='That does not look like an email address.' && n.checkVisibility()})()`))
48 p.check(`(()=>{const f=document.querySelector('[data-code-form]');return window.__posts.length===1 && window.__posts[0].url.endsWith('/email') && !window.__posts[0].body.includes('CANARY') && f.querySelector('[data-code-field]').value===`+jsonString(canarySignInCode)+` && document.activeElement===f.querySelector('[data-email-field]') && !f.closest('[data-code-steps]').hidden})()`, "a refused email sent the code, or lost it")
49 shot("signin-email-bad")
50
51 // Taken: the email alone, then the sealed code.
52 p.check(`(()=>{window.__posts=[];const f=document.querySelector('[data-code-form]');f.querySelector('[data-email-field]').value=' me@example.com ';f.requestSubmit();return true})()`, "a good email")
53 p.run(waitLong(`window.__posts.length===2`))
54 p.check(`(()=>{const [a,b]=window.__posts;return a.url.endsWith('/email') && a.body==='from=add&email=me%40example.com' && !a.body.includes('CANARY') && b.url.endsWith('/secret') && !b.body.includes('example.com') && !b.body.includes('CANARY')})()`, "the email and the code did not go apart, email first")
55 secret := runner.expect(t, wire.FrameSecret).(*wire.SecretCommand)
56 if opened := runner.open(t, secret.Sealed); opened.Secret != canarySignInCode {
57 t.Fatal("the code")
58 }
59
60 // Connected: the row has the email as the person's own.
61 runner.send(t, wire.FrameConnection, wire.ConnectionReport{Connection: cmd.Connection, Person: thintest.Owner, LocalID: "claude-1", Provider: "claude", State: wire.ConnHealthy})
62 runner.hello(t, wire.HeldConnection{LocalID: "claude-1", Person: thintest.Owner, Provider: "claude", Kind: wire.KindToken, State: wire.ConnHealthy})
63 p.run(waitLong(`location.pathname==='/conversation/settings/connections' && [...document.querySelectorAll('[equipo-conn-row][data-provider="claude"]')].some(e=>e.querySelector('[data-stated-email]')?.textContent==='me@example.com' && !e.querySelector('details[data-account-email]').open)`))
64 p.run(waitLong(`document.getAnimations().every(a=>a.playState!=='running'||a.effect&&a.effect.getTiming().iterations===Infinity)`))
65 shot("signin-email-row")
66 })
67 }
68}
69