oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package thintest
2
3import (
4 "net/http"
5 "net/url"
6 "strings"
7 "testing"
8
9 "amadan.net/oficina/equipo/internal/wire"
10)
11
12// TestPagesConnectionsAdd: Paul, 2026-11-10: "Can 'Add a connection' go
13// to a new screen?" Connections links to its own Add page, a Settings
14// page with Connections current and, on a phone, Connections in its bar;
15// the page is the chooser (Claude, Codex and TensorX, two greyed) and then the
16// attempt's card. Without scripts the forms still work: an Add posts and
17// comes back to the Add page, its Check again leads back to Connections
18// once the attempt connected, with the new row marked.
19func TestPagesConnectionsAdd(t *testing.T) {
20 r := &toolRig{rig: newRig(t)}
21 owner := r.inst.Cookie()
22 runner := r.dial(0)
23 r.wait("runner online", func(c *Conversation) bool { return c.Runner.Online })
24
25 list := r.get(owner, "/conversation/settings/connections", 200)
26 if !strings.Contains(list, `href="/conversation/settings/connections/add" equipo-conn-add data-add-link`) || strings.Contains(list, "equipo-conn-chooser") {
27 t.Fatal("Connections does not link to the Add page, or still holds the chooser")
28 }
29 add := r.get(owner, "/conversation/settings/connections/add", 200)
30 for _, want := range []string{`data-settings-link="connections" aria-current="page"`, `href="/conversation/settings/connections" rel="up" aria-label="Connections"`, "<title>Add a connection</title>", `data-add="claude"`, `data-add="codex"`, "data-paste-instead", "data-sign-in-how", "data-adding"} {
31 if !strings.Contains(add, want) {
32 t.Fatalf("the Add page lacks %s", want)
33 }
34 }
35 // TensorX is offered now (connectors spec S1); two stay greyed.
36 if n := strings.Count(add, "equipo-conn-opt disabled"); n != 2 || !strings.Contains(add, `data-add-metered="tensorx"`) {
37 t.Fatalf("%d greyed choices, want 2, and TensorX", n)
38 }
39
40 // Scriptless: Add Codex posts and comes back to the Add page.
41 if status, loc := r.post(owner, "/conversation/connections", url.Values{"provider": {"codex"}}); status != http.StatusSeeOther || loc != "/conversation/settings/connections/add" {
42 t.Fatalf("Add posted: %d to %q", status, loc)
43 }
44 f, body, err := runner.Expect(r.ctx, wire.FrameConnect)
45 if err != nil {
46 t.Fatal(err)
47 }
48 id := body.(*wire.ConnectCommand).Connection
49 if err = runner.Send(r.ctx, "a-c", wire.FrameAck, wire.Ack{ID: f.ID}); err != nil {
50 t.Fatal(err)
51 }
52 if err = runner.Send(r.ctx, "r-1", wire.FrameConnection, wire.ConnectionReport{Connection: id, Person: Owner, Provider: "codex", State: wire.ConnConnecting, Prompt: &wire.ConnectPrompt{Kind: wire.PromptDeviceCode, URL: "https://auth.openai.com/codex/device", Code: "ABCD-1234"}}); err != nil {
53 t.Fatal(err)
54 }
55 r.wait("device code", func(c *Conversation) bool { p := c.Connections[id].Prompt; return p != nil && p.Code == "ABCD-1234" })
56 add = r.get(owner, "/conversation/settings/connections/add", 200)
57 if !strings.Contains(add, "data-device-code") || !strings.Contains(add, `href="/conversation/settings/connections/add?attempt=`+id+`"`) || strings.Contains(add, "equipo-conn-chooser") {
58 t.Fatal("the Add page does not show the attempt's card with its scriptless Check again")
59 }
60 if strings.Contains(r.get(owner, "/conversation/settings/connections", 200), "data-device-code") {
61 t.Fatal("the attempt's card is on Connections too")
62 }
63 // Connecting: Check again stays; connected: back to Connections.
64 noFollow := &http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
65 check := func() (int, string) {
66 req, _ := http.NewRequest("GET", r.inst.URL+"/conversation/settings/connections/add?attempt="+id, nil)
67 req.AddCookie(owner)
68 res, err := noFollow.Do(req)
69 if err != nil {
70 t.Fatal(err)
71 }
72 res.Body.Close()
73 return res.StatusCode, res.Header.Get("Location")
74 }
75 if status, _ := check(); status != 200 {
76 t.Fatalf("Check again while connecting: %d", status)
77 }
78 if err = runner.Send(r.ctx, "r-2", wire.FrameConnection, wire.ConnectionReport{Connection: id, Person: Owner, LocalID: "codex-1", Provider: "codex", State: wire.ConnHealthy, Label: Owner, Plan: "pro"}); err != nil {
79 t.Fatal(err)
80 }
81 r.wait("connected", func(c *Conversation) bool { return c.Connections[id].State == wire.ConnHealthy })
82 if status, loc := check(); status != http.StatusSeeOther || loc != "/conversation/settings/connections?added="+id {
83 t.Fatalf("Check again once connected: %d to %q", status, loc)
84 }
85 page := r.get(owner, "/conversation/settings/connections?added="+id, 200)
86 if !strings.Contains(page, `data-connection="`+id+`" data-provider="codex" data-state="healthy" data-new>`) {
87 t.Fatal("the new row is not marked")
88 }
89 if strings.Contains(r.get(owner, "/conversation/settings/connections", 200), "data-new") {
90 t.Fatal("a row is marked without ?added")
91 }
92}
93