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 thintest
4
5import (
6 "amadan.net/oficina/equipo/internal/wire"
7 "fmt"
8 "testing"
9)
10
11func TestBrowserAccessReview(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 := newToolRigSaying(t, wire.ProtocolCurrent, "Give access to the whole carlos namespace")
16 reason := `I need access. <img src=x onerror="window.accessInjection=true">`
17 got := r.call("broad-access", wire.ToolRequestAccess, map[string]any{"target": "carlos", "reason": reason})
18 if got.Code != "asked" {
19 t.Fatal(got)
20 }
21 r.runner.Send(r.ctx, "broad-reply", wire.FrameReply, wire.Reply{TurnID: r.turn, Attempt: 1, Text: "Please confirm."})
22 r.wait("reply", func(c *Conversation) bool { return c.Turns[r.turn].State == wire.TurnReplied })
23 p := openInner(t, r.inst.URL, r.inst.Cookie(), width, 844, width == 390, scheme, "reduce")
24 defer p.stop()
25 p.open("/conversation")
26 p.wait(`document.querySelector('[data-access-confirm]')`, "confirmation")
27 p.check(`document.querySelector('[data-access-state]').textContent.includes('Ask Amadan for access to everything in carlos?')`, "broad scope")
28 p.check(`!document.querySelector('[data-access-state] img') && !window.accessInjection && document.querySelector('[data-access-state]').textContent.includes('<img')`, "reason is escaped text")
29 p.fits("broad confirmation")
30 p.shot(fmt.Sprintf("access-review-broad-%d-%s", width, scheme))
31 p.click(`[data-access-confirm]`)
32 _, body, err := r.runner.Expect(r.ctx, wire.FrameRequestAccess)
33 if err != nil {
34 t.Fatal(err)
35 }
36 cmd := body.(*wire.AccessCommand)
37 r.runner.Send(r.ctx, "broad-pending", wire.FrameAccess, wire.AccessReport{CardID: cmd.CardID, Person: cmd.Person, RequestID: "ar_broad", State: "pending", ApproveURL: "https://amadan.net/settings/agents/requests/ar_broad"})
38 p.wait(`document.querySelector('[data-access-state="pending"]')`, "pending")
39 p.check(`document.querySelector('[data-access-state]').textContent.includes('Everything in carlos')`, "pending stays broad")
40 p.click(`[data-access-aside]`)
41 p.wait(`document.querySelector('[equipo-aside-stub]')`, "aside")
42 r.runner.Send(r.ctx, "broad-approved", wire.FrameAccess, wire.AccessReport{CardID: cmd.CardID, Person: cmd.Person, RequestID: "ar_broad", State: "approved", ApproveURL: "https://amadan.net/settings/agents/requests/ar_broad"})
43 p.wait(`document.querySelector('[equipo-card-done]')?.textContent.includes('Access granted')`, "visible grant note")
44 p.check(`!document.querySelector('[equipo-aside-stub]')`, "grant replaces aside stub")
45 p.fits("grant note")
46 p.shot(fmt.Sprintf("access-review-granted-%d-%s", width, scheme))
47 })
48 }
49 }
50}
51