| 1 | package thintest |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | "html" |
| 7 | "io" |
| 8 | "net/http" |
| 9 | "net/url" |
| 10 | "regexp" |
| 11 | "strings" |
| 12 | "testing" |
| 13 | "time" |
| 14 | |
| 15 | "amadan.net/oficina/equipo/internal/equipo" |
| 16 | "amadan.net/oficina/equipo/internal/wire" |
| 17 | "amadan.net/rastrillo/rastrillo/sessions" |
| 18 | ) |
| 19 | |
| 20 | // get reads a page as the browser session c. |
| 21 | func (r *toolRig) get(c *http.Cookie, path string, want int) string { |
| 22 | r.t.Helper() |
| 23 | req, _ := http.NewRequest("GET", r.inst.URL+path, nil) |
| 24 | req.AddCookie(c) |
| 25 | res, err := http.DefaultClient.Do(req) |
| 26 | if err != nil { |
| 27 | r.t.Fatal(err) |
| 28 | } |
| 29 | defer res.Body.Close() |
| 30 | raw, _ := io.ReadAll(res.Body) |
| 31 | if res.StatusCode != want { |
| 32 | r.t.Fatalf("GET %s: %d, want %d: %.300s", path, res.StatusCode, want, raw) |
| 33 | } |
| 34 | return string(raw) |
| 35 | } |
| 36 | |
| 37 | // post submits a page form as c and returns the status and redirect. |
| 38 | func (r *toolRig) post(c *http.Cookie, path string, form url.Values) (int, string) { |
| 39 | r.t.Helper() |
| 40 | req, _ := http.NewRequest("POST", r.inst.URL+path, strings.NewReader(form.Encode())) |
| 41 | req.AddCookie(c) |
| 42 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") |
| 43 | req.Header.Set("Origin", r.inst.URL) |
| 44 | req.Header.Set("Sec-Fetch-Site", "same-origin") |
| 45 | res, err := (&http.Client{CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}).Do(req) |
| 46 | if err != nil { |
| 47 | r.t.Fatal(err) |
| 48 | } |
| 49 | res.Body.Close() |
| 50 | return res.StatusCode, res.Header.Get("Location") |
| 51 | } |
| 52 | |
| 53 | // memberCookie signs in a team member who is not an owner. |
| 54 | func (r *toolRig) memberCookie() *http.Cookie { |
| 55 | r.t.Helper() |
| 56 | const member = "member@example.com" |
| 57 | if err := r.inst.Store.SetMember(context.Background(), equipo.Actor{Address: Owner}, member, equipo.RoleMember, true, 0); err != nil { |
| 58 | r.t.Fatal(err) |
| 59 | } |
| 60 | token := "member-" + strings.ToLower(time.Now().Format("150405.000000")) |
| 61 | now := time.Now().UTC() |
| 62 | if _, err := r.inst.DB.Writer().Exec("INSERT INTO sessions(token_hash,subject,method,auth_time,created_at,expires_at) VALUES(?,?,?,?,?,?)", sessions.HashToken(token), member, "fixture", now.Format(time.RFC3339Nano), now.Format(time.RFC3339Nano), now.Add(time.Hour).Format(time.RFC3339Nano)); err != nil { |
| 63 | r.t.Fatal(err) |
| 64 | } |
| 65 | return &http.Cookie{Name: r.inst.Cookie().Name, Value: token} |
| 66 | } |
| 67 | |
| 68 | // TestPagesTasksAndProjects: the task card, the Tasks and Projects pages |
| 69 | // and their actions are a thin layer over the same store a device reads. |
| 70 | func TestPagesTasksAndProjects(t *testing.T) { |
| 71 | r := newToolRigAt(t, wire.ProtocolInjectionDefences) |
| 72 | owner := r.inst.Cookie() |
| 73 | id := taskID(t, r.call("p1", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Swipe back does nothing", "brief": "On iOS."})) |
| 74 | r.call("p2", wire.ToolAddFinding, map[string]any{"task": id, "text": "EdgeSwipe returns false.", "repo": "oficina/sample", "path": "panes/swipe.go", "line": 4}) |
| 75 | r.call("p3", wire.ToolStartTask, map[string]string{"task": id, "brief": "Make it go back."}) |
| 76 | _, body := r.expect(wire.FrameDispatch) |
| 77 | d := body.(*wire.DispatchCommand) |
| 78 | base, cand := strings.Repeat("1", 40), "abcdef0"+strings.Repeat("2", 33) |
| 79 | r.step("r-p1", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: base, CandidateSHA: cand}) |
| 80 | page := r.get(owner, "/conversation", 200) |
| 81 | if !strings.Contains(page, `equipo-card="task" equipo-receipt`) || !strings.Contains(page, "Swipe back does nothing") || strings.Contains(page, `data-task-cancel`) || !strings.Contains(page, `/tasks/`+id) || strings.Contains(page, "data-open-amadan") || strings.Contains(page, "data-task-retry") { |
| 82 | t.Fatalf("running task card: %s", page) |
| 83 | } |
| 84 | r.step("r-p2", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepDone, BaseSHA: base, CandidateSHA: cand, Pushed: true, Termination: true, Summary: "EdgeSwipe goes back now.", LogTail: "Edit panes/swipe.go"}) |
| 85 | r.wait("pushed", func(c *Conversation) bool { return c.Tasks[id].URL != "" }) |
| 86 | task, _ := r.client.Task(r.ctx, id) |
| 87 | page = r.get(owner, "/conversation", 200) |
| 88 | for _, want := range []string{`data-open-amadan`, `href="` + task.URL + `" rel="noopener" target="_blank"`, task.Branch, "abcdef0"} { |
| 89 | if !strings.Contains(page, want) { |
| 90 | t.Fatalf("pushed card lacks %q", want) |
| 91 | } |
| 92 | } |
| 93 | // Checks and review on the pushed SHA; the card says what they found |
| 94 | // and, ready to merge, offers the person's one decision. |
| 95 | c := r.dispatched(wire.SpecialistChecks, base, cand, 0) |
| 96 | page = r.get(owner, "/conversation", 200) |
| 97 | if !strings.Contains(page, "Running checks…") || !strings.Contains(page, ">In review<") { |
| 98 | t.Fatalf("card while checks run: %s", page) |
| 99 | } |
| 100 | r.checks("r-pc", c, wire.ChecksPassed, exit(0), "", "ok\n") |
| 101 | rv := r.dispatched(wire.SpecialistReview, base, cand, 0) |
| 102 | if page = r.get(owner, "/conversation", 200); !strings.Contains(page, "data-checks>Passed</dd><small>make ci</small>") || !strings.Contains(page, "data-verdict>Reviewing</dd>") || strings.Contains(page, "data-merge") { |
| 103 | t.Fatalf("card while review runs: %s", page) |
| 104 | } |
| 105 | r.verdict("r-pr", rv, wire.VerdictApprove) |
| 106 | // Ready to merge, and Equipo merges it: the card says so, with the |
| 107 | // judgements and the quiet link, and there is no merge button. |
| 108 | m := r.dispatched(wire.SpecialistMerge, base, cand, 0) |
| 109 | r.wait("merging", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageMerging }) |
| 110 | page = r.get(owner, "/conversation", 200) |
| 111 | for _, want := range []string{">Merging…<", "data-checks>Passed</dd><small>make ci</small>", "data-verdict>Approved</dd><small>same family</small>", `data-open-amadan>Open on Amadan</a>`} { |
| 112 | if !strings.Contains(page, want) { |
| 113 | t.Fatalf("merging card lacks %q: %s", want, page) |
| 114 | } |
| 115 | } |
| 116 | if strings.Contains(page, "to merge</a>") || strings.Contains(page, "data-merge>") { |
| 117 | t.Fatalf("the card still offers the person a merge: %s", page) |
| 118 | } |
| 119 | // The task page's timeline: each judgement on its SHA, then Equipo |
| 120 | // merging it, live. |
| 121 | if detail := r.get(owner, "/tasks/"+id, 200); !strings.Contains(detail, "<b>Checks</b>") || !strings.Contains(detail, "On commit abcdef0.") || !strings.Contains(detail, "<b>Review</b>") || !strings.Contains(detail, `<li data-kind="merging" data-live>`) || !strings.Contains(detail, "Merging into the default branch") { |
| 122 | t.Fatalf("task page timeline: %s", detail) |
| 123 | } |
| 124 | r.step("r-pm-run", wire.StepReport{TaskID: id, StepID: m.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: base, CandidateSHA: cand}) |
| 125 | r.step("r-pm", wire.StepReport{TaskID: id, StepID: m.StepID, Attempt: 1, State: wire.StepDone, BaseSHA: base, CandidateSHA: cand, Termination: true, MergeSHA: strings.Repeat("e", 40), Into: "main", Strategy: wire.MergeCommit}) |
| 126 | r.wait("done", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageDone }) |
| 127 | page = r.get(owner, "/conversation", 200) |
| 128 | for _, want := range []string{">Done<", "Merged into main at eeeeeee", `href="https://amadan.net/oficina/sample" rel="noopener" target="_blank" data-open-amadan>Open on Amadan</a>`, `Swipe back does nothing</a> into Sample.`} { |
| 129 | if !strings.Contains(page, want) { |
| 130 | t.Fatalf("merged card lacks %q: %s", want, page) |
| 131 | } |
| 132 | } |
| 133 | if strings.Contains(page, "Pushed "+task.Branch) { |
| 134 | t.Fatalf("the merged card still links the deleted branch: %s", page) |
| 135 | } |
| 136 | member := r.memberCookie() |
| 137 | if p := r.get(member, "/tasks/"+id, 200); !strings.Contains(p, "Merged into main at eeeeeee") || !strings.Contains(p, "Approved (same family)") { |
| 138 | t.Fatal("a teammate does not see the merge") |
| 139 | } |
| 140 | list := r.get(owner, "/tasks", 200) |
| 141 | // Rows: the whole row links the task; who filed it and from where; the |
| 142 | // Done group; the project by name; the detail line says Merged. |
| 143 | for _, want := range []string{`data-task="` + id + `"`, `equipo-row-link href="/tasks/` + id + `"`, `<span equipo-project-name>Sample</span>`, ">You</span>", "From your conversation, ", `data-group="done"`, ">Merged.</span>"} { |
| 144 | if !strings.Contains(list, want) { |
| 145 | t.Fatalf("Tasks page lacks %q", want) |
| 146 | } |
| 147 | } |
| 148 | if p := r.get(owner, "/tasks?project="+task.ProjectID, 200); !strings.Contains(p, `data-task="`+id+`"`) { |
| 149 | t.Fatal("project filter dropped the task") |
| 150 | } |
| 151 | if p := r.get(owner, "/tasks?project=p_other", 200); strings.Contains(p, `data-task="`+id+`"`) { |
| 152 | t.Fatal("project filter kept another project's task") |
| 153 | } |
| 154 | detail := r.get(owner, "/tasks/"+id, 200) |
| 155 | for _, want := range []string{"EdgeSwipe returns false.", "panes/swipe.go:4", "EdgeSwipe goes back now.", "<pre equipo-work-log>Edit panes/swipe.go</pre>", `action="/tasks/` + id + `/notes"`} { |
| 156 | if !strings.Contains(detail, want) { |
| 157 | t.Fatalf("task page lacks %q", want) |
| 158 | } |
| 159 | } |
| 160 | r.get(owner, "/tasks/tknotthere", 404) |
| 161 | if status, loc := r.post(owner, "/tasks/"+id+"/notes", url.Values{"body": {"Only on the iPhone."}, "request_id": {"n1"}}); status != 303 || loc != "/tasks/"+id { |
| 162 | t.Fatalf("note: %d %s", status, loc) |
| 163 | } |
| 164 | if !strings.Contains(r.get(owner, "/tasks/"+id, 200), "Only on the iPhone.") { |
| 165 | t.Fatal("note not shown") |
| 166 | } |
| 167 | projects := r.get(owner, "/projects", 200) |
| 168 | // Its one task is merged: nothing open, said in words, no empty bar. |
| 169 | for _, want := range []string{"data-thin-projects", "Sample", "1 repository", "data-no-open>No open tasks<", "Woodstar is a reading app.", "Checks run here (make ci)"} { |
| 170 | if !strings.Contains(projects, want) { |
| 171 | t.Fatalf("Projects page lacks %q", want) |
| 172 | } |
| 173 | } |
| 174 | if strings.Contains(projects, "<span equipo-bar>") { |
| 175 | t.Fatal("an empty bar for a project with nothing open") |
| 176 | } |
| 177 | if strings.Contains(projects, `<form method="post" action="/projects"`) || strings.Contains(projects, "budget") { |
| 178 | t.Fatal("Projects page offers setup") |
| 179 | } |
| 180 | if p := r.get(owner, "/projects/"+task.ProjectID, 200); !strings.Contains(p, `data-task="`+id+`"`) { |
| 181 | t.Fatal("project page lacks its task") |
| 182 | } |
| 183 | r.get(owner, "/projects/p_notthere", 404) |
| 184 | |
| 185 | // Cancel and Retry: owners only, through the store, back to the page. |
| 186 | other := taskID(t, r.call("p4", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Second", "brief": "b"})) |
| 187 | r.call("p5", wire.ToolStartTask, map[string]string{"task": other, "brief": "go"}) |
| 188 | _, body = r.expect(wire.FrameDispatch) |
| 189 | d2 := body.(*wire.DispatchCommand) |
| 190 | r.step("r-p3", wire.StepReport{TaskID: other, StepID: d2.StepID, Attempt: 1, State: wire.StepFailed, Reason: "provider_failed", Termination: true}) |
| 191 | if p := r.get(owner, "/tasks/"+other, 200); !strings.Contains(p, "<strong>Stopped at ") || !strings.Contains(p, "the model connection failed") || !strings.Contains(p, `action="/conversation/tasks/`+other+`/retry"`) { |
| 192 | t.Fatal("failed card lacks its reason or Retry") |
| 193 | } |
| 194 | // A failure without the runner's termination proof offers no Retry. |
| 195 | third := taskID(t, r.call("p6", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Third", "brief": "b"})) |
| 196 | r.call("p7", wire.ToolStartTask, map[string]string{"task": third, "brief": "go"}) |
| 197 | _, body = r.expect(wire.FrameDispatch) |
| 198 | d3 := body.(*wire.DispatchCommand) |
| 199 | r.step("r-p4", wire.StepReport{TaskID: third, StepID: d3.StepID, Attempt: 1, State: wire.StepFailed, Reason: "push_failed"}) |
| 200 | if p := r.get(owner, "/tasks/"+third, 200); !strings.Contains(p, "<strong>Stopped at ") || !strings.Contains(p, "the push to Amadan failed") || strings.Contains(p, `action="/conversation/tasks/`+third+`/retry"`) { |
| 201 | t.Fatal("Retry offered before termination") |
| 202 | } |
| 203 | // A teammate reads the task, without the creator's actions. |
| 204 | if p := r.get(member, "/tasks/"+other, 200); !strings.Contains(p, "<strong>Stopped at ") || !strings.Contains(p, "the model connection failed") || strings.Contains(p, "/retry\"") || strings.Contains(p, "/cancel\"") { |
| 205 | t.Fatalf("teammate's task page offers actions: %s", p) |
| 206 | } |
| 207 | if status, _ := r.post(member, "/conversation/tasks/"+other+"/retry", url.Values{}); status != 403 { |
| 208 | t.Fatalf("member retry: %d", status) |
| 209 | } |
| 210 | if status, loc := r.post(owner, "/conversation/tasks/"+other+"/retry", url.Values{"from": {"task"}}); status != 303 || loc != "/tasks/"+other { |
| 211 | t.Fatalf("retry: %d %s", status, loc) |
| 212 | } |
| 213 | _, body = r.expect(wire.FrameDispatch) |
| 214 | if d := body.(*wire.DispatchCommand); d.Attempt != 2 { |
| 215 | t.Fatalf("retry dispatch %+v", d) |
| 216 | } |
| 217 | if status, _ := r.post(member, "/conversation/tasks/"+other+"/cancel", url.Values{}); status != 403 { |
| 218 | t.Fatalf("member cancel: %d", status) |
| 219 | } |
| 220 | if status, loc := r.post(owner, "/conversation/tasks/"+other+"/cancel", url.Values{"from": {"elsewhere"}}); status != 303 || loc != "/conversation" { |
| 221 | t.Fatalf("cancel: %d %s", status, loc) |
| 222 | } |
| 223 | r.expect(wire.FrameCancelStep) |
| 224 | } |
| 225 | |
| 226 | // TestPagesGrantCard: the grant card shows the real command and a check, |
| 227 | // and a resolved card is one quiet line. A card is raised only for an |
| 228 | // explicit repository in a namespace Equipo knows (it reads moonbeam/docs |
| 229 | // and acme/other), never for one it cannot tell exists (#48). |
| 230 | func TestPagesGrantCard(t *testing.T) { |
| 231 | r := newToolRig(t) |
| 232 | owner := r.inst.Cookie() |
| 233 | hello := wire.Hello{Generation: r.runner.Welcome.Generation, Repos: []string{}, CreateIn: []string{}, Agent: "equipo-test", Catalog: []wire.RepoInfo{{Repo: "amadan.net/moonbeam/docs", Names: []string{"docs"}, Hints: []string{}}, {Repo: "amadan.net/acme/other", Names: []string{"other"}, Hints: []string{}}}, Connections: []wire.HeldConnection{}, Versions: map[string]string{}} |
| 234 | if err := r.runner.Send(r.ctx, "h-pg0", wire.FrameHello, hello); err != nil { |
| 235 | t.Fatal(err) |
| 236 | } |
| 237 | if got := r.call("g0", wire.ToolFind, map[string]string{"query": "zeta/web"}); got.Code != "unknown_namespace" { |
| 238 | t.Fatalf("unknown namespace: %+v", got) |
| 239 | } |
| 240 | r.call("g1", wire.ToolFind, map[string]string{"query": "moonbeam/web"}) |
| 241 | var card wire.Card |
| 242 | r.wait("access card", func(c *Conversation) bool { |
| 243 | for _, k := range c.Cards { |
| 244 | if k.Kind == wire.CardAccess { |
| 245 | card = k |
| 246 | } |
| 247 | } |
| 248 | return card.ID != "" |
| 249 | }) |
| 250 | page := r.get(owner, "/conversation", 200) |
| 251 | // An explicit repository names the namespace to grant. |
| 252 | if !strings.Contains(page, "amadan agent grant equipo-test moonbeam") || !strings.Contains(page, `data-grant-check`) { |
| 253 | t.Fatal("grant card lacks the named command or the check") |
| 254 | } |
| 255 | if !strings.Contains(page, html.EscapeString(equipo.RunnerText("chat.card.grant_how"))) { |
| 256 | t.Fatal("grant card does not explain the grant") |
| 257 | } |
| 258 | if status, _ := r.post(owner, "/conversation/cards/"+card.ID+"/answer", url.Values{"choice": {"check"}, "revision": {"1"}}); status != 303 { |
| 259 | t.Fatalf("check: %d", status) |
| 260 | } |
| 261 | r.expect(wire.FrameRecheck) |
| 262 | hello.Catalog = append(hello.Catalog, wire.RepoInfo{Repo: "amadan.net/moonbeam/web", Names: []string{"web", "Moonbeam"}, Hints: []string{}}) |
| 263 | if err := r.runner.Send(r.ctx, "h-pg", wire.FrameHello, hello); err != nil { |
| 264 | t.Fatal(err) |
| 265 | } |
| 266 | r.wait("resolved", func(c *Conversation) bool { return c.Cards[card.ID].State == wire.CardResolved }) |
| 267 | page = r.get(owner, "/conversation", 200) |
| 268 | if !strings.Contains(page, "moonbeam/web is reachable now.") || strings.Contains(page, "amadan agent grant") { |
| 269 | t.Fatal("resolved card still asks") |
| 270 | } |
| 271 | // A repository named with its namespace: the command names that |
| 272 | // namespace, and only that repository resolves the card. |
| 273 | r.next("acme") |
| 274 | r.call("g2", wire.ToolFind, map[string]string{"query": "acme/Stardust"}) |
| 275 | var named wire.Card |
| 276 | r.wait("named access card", func(c *Conversation) bool { |
| 277 | for _, k := range c.Cards { |
| 278 | if k.Kind == wire.CardAccess && k.State == wire.CardOpen { |
| 279 | named = k |
| 280 | } |
| 281 | } |
| 282 | return named.ID != "" |
| 283 | }) |
| 284 | page = r.get(owner, "/conversation", 200) |
| 285 | if !strings.Contains(page, "amadan agent grant equipo-test acme</code>") || !strings.Contains(page, html.EscapeString(equipo.RunnerText("chat.card.grant_how"))) { |
| 286 | t.Fatal("grant card does not name the namespace given") |
| 287 | } |
| 288 | hello.Catalog = append(hello.Catalog, wire.RepoInfo{Repo: "amadan.net/acme/more", Names: []string{"more"}, Hints: []string{}}) |
| 289 | if err := r.runner.Send(r.ctx, "h-pg2", wire.FrameHello, hello); err != nil { |
| 290 | t.Fatal(err) |
| 291 | } |
| 292 | r.call("g3", wire.ToolStatus, map[string]string{}) |
| 293 | if c, _ := r.client.Snapshot(r.ctx); cardState(c.Cards, named.ID) != wire.CardOpen { |
| 294 | t.Fatal("resolved by another repository in the namespace") |
| 295 | } |
| 296 | hello.Catalog = append(hello.Catalog, wire.RepoInfo{Repo: "amadan.net/acme/stardust", Names: []string{"stardust"}, Hints: []string{}}) |
| 297 | if err := r.runner.Send(r.ctx, "h-pg3", wire.FrameHello, hello); err != nil { |
| 298 | t.Fatal(err) |
| 299 | } |
| 300 | r.wait("named resolved", func(c *Conversation) bool { return c.Cards[named.ID].State == wire.CardResolved }) |
| 301 | // A card whose need passed (the turn's task is filed in the very |
| 302 | // repository it asked for, granted but not read yet) says Equipo has |
| 303 | // access, not that it is reachable. |
| 304 | r.next("acme web") |
| 305 | r.call("g4", wire.ToolFind, map[string]string{"query": "acme/web"}) |
| 306 | var passed wire.Card |
| 307 | r.wait("acme/web access card", func(c *Conversation) bool { |
| 308 | for _, k := range c.Cards { |
| 309 | if k.Kind == wire.CardAccess && k.State == wire.CardOpen { |
| 310 | passed = k |
| 311 | } |
| 312 | } |
| 313 | return passed.ID != "" |
| 314 | }) |
| 315 | hello.Repos = []string{"amadan.net/acme/web"} |
| 316 | if err := r.runner.Send(r.ctx, "h-pg4", wire.FrameHello, hello); err != nil { |
| 317 | t.Fatal(err) |
| 318 | } |
| 319 | if got := r.call("g5", wire.ToolRecordTask, map[string]string{"repo": "acme/web", "title": "Fix the header", "brief": "go"}); got.Code != "recorded" { |
| 320 | t.Fatalf("record: %+v", got) |
| 321 | } |
| 322 | r.wait("need passed", func(c *Conversation) bool { return c.Cards[passed.ID].State == wire.CardResolved }) |
| 323 | page = r.get(owner, "/conversation", 200) |
| 324 | if !strings.Contains(page, html.EscapeString(equipo.RunnerText("access.already"))) || strings.Contains(page, "acme/web is reachable now.") { |
| 325 | t.Fatal("a card whose need passed does not say so") |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // TestPagesGrantCardNewTeam: a new team whose agent reaches nothing gets |
| 330 | // the grant card for a repository the person names (review R1), and its |
| 331 | // line does not end on an empty list of namespaces. |
| 332 | func TestPagesGrantCardNewTeam(t *testing.T) { |
| 333 | r := newToolRig(t) |
| 334 | owner := r.inst.Cookie() |
| 335 | hello := wire.Hello{Generation: r.runner.Welcome.Generation, Repos: []string{}, CreateIn: []string{}, Agent: "equipo-test", Catalog: []wire.RepoInfo{}, Connections: []wire.HeldConnection{}, Versions: map[string]string{}} |
| 336 | if err := r.runner.Send(r.ctx, "h-new", wire.FrameHello, hello); err != nil { |
| 337 | t.Fatal(err) |
| 338 | } |
| 339 | r.next("Fix the header in acme/website.") |
| 340 | if got := r.call("n1", wire.ToolFind, map[string]string{"query": "acme/website"}); got.Code != "none" { |
| 341 | t.Fatalf("find: %+v", got) |
| 342 | } |
| 343 | r.wait("access card", func(c *Conversation) bool { |
| 344 | for _, k := range c.Cards { |
| 345 | if k.Kind == wire.CardAccess && k.State == wire.CardOpen { |
| 346 | return true |
| 347 | } |
| 348 | } |
| 349 | return false |
| 350 | }) |
| 351 | page := r.get(owner, "/conversation", 200) |
| 352 | want := html.EscapeString(fmt.Sprintf(equipo.RunnerText("chat.card.access_first"), "acme/website")) |
| 353 | if !strings.Contains(page, want) || strings.Contains(page, "Its agent reaches .") || !strings.Contains(page, "amadan agent grant equipo-test acme") { |
| 354 | t.Fatal("new team's grant card") |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | func cardState(cards []wire.Card, id string) string { |
| 359 | for _, k := range cards { |
| 360 | if k.ID == id { |
| 361 | return k.State |
| 362 | } |
| 363 | } |
| 364 | return "" |
| 365 | } |
| 366 | |
| 367 | // railOf is the sidebar of a rendered page. |
| 368 | func railOf(t *testing.T, page string) string { |
| 369 | t.Helper() |
| 370 | i := strings.Index(page, `<nav rst-shell-nav id="rail"`) |
| 371 | if i < 0 { |
| 372 | t.Fatalf("no sidebar: %s", page) |
| 373 | } |
| 374 | j := strings.Index(page[i:], "</nav>") |
| 375 | return page[i : i+j] |
| 376 | } |
| 377 | |
| 378 | var hrefs = regexp.MustCompile(`href="([^"]*)"`) |
| 379 | |
| 380 | // TestPagesRail: the sidebar reads the thin core only. It links no page |
| 381 | // of the old engine; the specialists the thin core runs say what they |
| 382 | // are doing (Engineering working on a linked task while its step runs), |
| 383 | // the others are not shown; the counts are the person's. |
| 384 | func TestPagesRail(t *testing.T) { |
| 385 | r := newToolRig(t) |
| 386 | owner := r.inst.Cookie() |
| 387 | allowed := regexp.MustCompile(`^/(conversation|conversation/settings|tasks|projects|people|work|usage|tasks\?needs=you|tasks/tk[a-z0-9]+|team/(engineering|copy|review|checks))$`) |
| 388 | for _, path := range []string{"/conversation", "/tasks", "/projects", "/people", "/tasks?needs=you"} { |
| 389 | rail := railOf(t, r.get(owner, path, 200)) |
| 390 | for _, m := range hrefs.FindAllStringSubmatch(rail, -1) { |
| 391 | if !allowed.MatchString(m[1]) { |
| 392 | t.Fatalf("%s: the sidebar links %q", path, m[1]) |
| 393 | } |
| 394 | } |
| 395 | for _, gone := range []string{"Journey", "Playbooks", "Product", "Design", "nav-coordinator", "nav-connections", `id="nav-settings"`} { |
| 396 | if strings.Contains(rail, gone) { |
| 397 | t.Fatalf("%s: the sidebar shows %s", path, gone) |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | rail := railOf(t, r.get(owner, "/conversation", 200)) |
| 402 | if !strings.Contains(rail, `data-specialist="copy" data-state="idle"`) || !strings.Contains(rail, `data-specialist="engineering" data-state="idle"`) || !strings.Contains(rail, `data-specialist="review" data-state="idle"`) || strings.Contains(rail, "data-count>") { |
| 403 | t.Fatalf("idle sidebar: %s", rail) |
| 404 | } |
| 405 | id := taskID(t, r.call("n1", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Swipe back does nothing", "brief": "x"})) |
| 406 | r.call("n2", wire.ToolStartTask, map[string]string{"task": id, "brief": "go"}) |
| 407 | _, body := r.expect(wire.FrameDispatch) |
| 408 | d := body.(*wire.DispatchCommand) |
| 409 | r.step("n-run", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: strings.Repeat("1", 40)}) |
| 410 | rail = railOf(t, r.get(owner, "/nav/rail?key=tasks", 200)) |
| 411 | for _, want := range []string{`data-specialist="engineering" data-state="working"`, `<span equipo-nav-task>Swipe back does nothing</span>`, `id="nav-tasks" href="/tasks" aria-current="page"`, `<small equipo-count data-count>1</small>`} { |
| 412 | if !strings.Contains(rail, want) { |
| 413 | t.Fatalf("working sidebar lacks %q: %s", want, rail) |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | |