package thintest import ( "regexp" "strings" "testing" "time" "amadan.net/oficina/equipo/internal/equipo" "amadan.net/oficina/equipo/internal/wire" ) // gallery is a team in the middle of its work, as the inner screens // mockup draws it: the owner and Nora, three projects (an iOS app whose // checks need a Mac, a docs repository with make ci, a Go service), and // tasks in every state the screens show. Everything goes through the // real instance: tool calls, step reports, activity lines and the // notebook, from fake runners. type gallery struct { a, b *toolRig unchecked, stopped, noras, merging string running, looking, nora string runningStep *wire.DispatchCommand } const ( galleryWoodstar = "amadan.net/oficina/sample" gallerySuite = "amadan.net/oficina/suite" galleryEquipo = "amadan.net/oficina/equipo" ) func galleryHello(r *toolRig, gen int64) wire.Hello { at := time.Now().Add(-3 * time.Hour).UTC().Truncate(time.Second) return wire.Hello{Generation: gen, Repos: []string{galleryWoodstar, gallerySuite, galleryEquipo}, CreateIn: []string{"oficina"}, Agent: "equipo-test", Catalog: []wire.RepoInfo{ {Repo: galleryWoodstar, DefaultBranch: "main", Summary: "An iOS app for reading and posting in a timeline without an account.", Names: []string{"sample", "Woodstar"}, Hints: []string{"swift", "swiftui"}, UpdatedAt: at, HeadSHA: strings.Repeat("9c1f3e2", 6)[:40], HeadSubject: "Trim the compose sheet's bottom inset", ChecksReason: "needs_macos"}, {Repo: gallerySuite, DefaultBranch: "main", Summary: "The shared suite contract: what every Oficina app agrees to about accounts, teams and sign-in.", Names: []string{"suite", "Suite"}, Hints: []string{"go"}, UpdatedAt: at.Add(2 * time.Hour), HeadSHA: strings.Repeat("3d9e0f1", 6)[:40], HeadSubject: "Replace em dash in README", Gate: "make ci"}, {Repo: galleryEquipo, DefaultBranch: "main", Summary: "The team of agents you are talking to: a coordinator, Engineering and Review.", Names: []string{"equipo", "Equipo"}, Hints: []string{"go"}, UpdatedAt: at.Add(-3 * time.Hour), HeadSHA: strings.Repeat("a0d418f", 6)[:40], HeadSubject: "Keep sessions 14 days", Gate: ".amadan/ci"}, }, Connections: []wire.HeldConnection{{LocalID: "claude-a", Person: Owner, Provider: "claude", Kind: "subscription", Label: Owner, State: "healthy"}}, Versions: map[string]string{"runner": "test", "claude": "2.1.312"}} } // galleryPushed records a task in repo and runs Engineering to a pushed // candidate with a summary. func (r *toolRig) galleryPushed(key, repo, title, brief, base, cand, summary string, separate bool) (string, *wire.DispatchCommand) { r.t.Helper() id := taskID(r.t, r.call(key+"-rec", wire.ToolRecordTask, map[string]any{"repo": repo, "title": title, "brief": brief, "separate": separate})) if res := r.call(key+"-start", wire.ToolStartTask, map[string]string{"task": id, "brief": brief}); res.IsError { r.t.Fatalf("start: %+v", res) } _, body := r.expect(wire.FrameDispatch) d := body.(*wire.DispatchCommand) r.step(key+"-run", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: base, Family: "claude", Account: "claude-a"}) r.step(key+"-done", wire.StepReport{TaskID: id, StepID: d.StepID, Attempt: 1, State: wire.StepDone, BaseSHA: base, CandidateSHA: cand, Pushed: true, Termination: true, Family: "claude", Account: "claude-a", Summary: summary, LogTail: "Read README.md\nEdit README.md"}) r.expect(wire.FrameWatchMerge) return id, d } // galleryJudged runs checks (outcome) and an approving review. func (r *toolRig) galleryJudged(key string, base, cand, outcome, reason string) { r.t.Helper() c := r.dispatched(wire.SpecialistChecks, base, cand, 0) code := exit(0) if outcome != wire.ChecksPassed { code = nil } r.checks(key+"-c", c, outcome, code, reason, "ok \texample/panes\t0.012s") rv := r.dispatched(wire.SpecialistReview, base, cand, 0) r.verdict(key+"-r", rv, wire.VerdictApprove) } func newGallery(t *testing.T) *gallery { t.Helper() a := newToolRigAt(t, wire.ProtocolInjectionDefences) g := &gallery{a: a} if err := a.runner.Send(a.ctx, "h-gallery", wire.FrameHello, primaryAt(galleryHello(a, a.runner.Welcome.Generation), wire.ProtocolInjectionDefences)); err != nil { t.Fatal(err) } a.wait("catalog", func(c *Conversation) bool { return true }) g.b = personToolRigAt(t, a, "nora@example.com", equipo.RoleOwner, wire.ProtocolInjectionDefences) b := g.b if err := b.runner.Send(b.ctx, "h-gallery", wire.FrameHello, primaryAt(galleryHello(b, b.runner.Welcome.Generation), wire.ProtocolInjectionDefences)); err != nil { t.Fatal(err) } sha := func(c string) string { return strings.Repeat(c, 40) } // Woodstar: approved, checks cannot run (needs macOS): the owner's // merge card, Needs you. g.unchecked, _ = a.galleryPushed("g1", "oficina/sample", "Swipe back from the edge doesn't work", "On the Account pane, swiping in from the left edge should go back, as it does everywhere else.\n\n- Happens on a device, every time\n- Other panes go back fine", sha("1"), "bc025ca"+sha("2")[7:], "Let the navigation stack's pop gesture run alongside the pane's recogniser.\n\n- `AccountNavigationHost` allows both gestures for the edge swipe\n- Added a note on why the pane needs it\n\nNot run here: the Xcode tests need macOS.", false) a.call("g1-find", wire.ToolAddFinding, map[string]any{"task": g.unchecked, "text": "The pane's gesture recogniser takes the edge swipe before the navigation stack sees it.", "repo": "oficina/sample", "path": "ios/Woodstar/AccountNavigationHost.swift", "line": 15}) a.galleryJudged("g1", sha("1"), "bc025ca"+sha("2")[7:], wire.ChecksCannotRun, "needs_macos") a.wait("merge card", func(c *Conversation) bool { return c.Tasks[g.unchecked].Stage == wire.StageReadyToMerge }) // The same bug, filed again: a possible duplicate, and it stopped. g.stopped = taskID(t, a.call("g2-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": "Swipe from the edge to go back doesn't work", "brief": "Swiping from the left edge does nothing on the account screen.", "separate": true})) a.call("g2-start", wire.ToolStartTask, map[string]string{"task": g.stopped, "brief": "Fix it."}) _, body := a.expect(wire.FrameDispatch) d := body.(*wire.DispatchCommand) a.step("g2-run", wire.StepReport{TaskID: g.stopped, StepID: d.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: sha("1")}) a.step("g2-fail", wire.StepReport{TaskID: g.stopped, StepID: d.StepID, Attempt: 1, State: wire.StepFailed, Reason: "provider_failed", Termination: true}) // Nora's copy of it: approved, unchecked, waiting on Nora. g.noras, _ = b.galleryPushed("g3", "oficina/sample", "iOS edge swipe to go back doesn't work on panes", "Edge swipe to go back does nothing inside panes.", sha("1"), "e71d20b"+sha("3")[7:], "Forward the edge swipe from `PaneNavigationHost` to the stack.", true) b.galleryJudged("g3", sha("1"), "e71d20b"+sha("3")[7:], wire.ChecksCannotRun, "needs_macos") // Suite: Nora's task merged by Equipo. g.nora, _ = b.galleryPushed("g4", "oficina/suite", "Fix line break in README", "A hard line break in the teams section splits a sentence in two.", sha("4"), "f04c8a7"+sha("5")[7:], "Joined the two lines in `README.md`.", false) b.galleryJudged("g4", sha("4"), "f04c8a7"+sha("5")[7:], wire.ChecksPassed, "") m := b.dispatched(wire.SpecialistMerge, sha("4"), "f04c8a7"+sha("5")[7:], 0) b.mergedStep("g4-m", m, "c7d0a52"+sha("6")[7:]) // Suite: the owner's, merging now. g.merging, _ = a.galleryPushed("g5", "oficina/suite", "Replace em dash in README", "The README has one em dash left, in the sign-in section.", sha("4"), "3d9e0f1"+sha("7")[7:], "Split the sentence at the em dash in `README.md`.", false) a.galleryJudged("g5", sha("4"), "3d9e0f1"+sha("7")[7:], wire.ChecksPassed, "") mm := a.dispatched(wire.SpecialistMerge, sha("4"), "3d9e0f1"+sha("7")[7:], 0) a.step("g5-m-run", wire.StepReport{TaskID: mm.TaskID, StepID: mm.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: mm.BaseSHA, CandidateSHA: mm.CandidateSHA}) // Equipo: Engineering at work, with its activity lines. g.running = taskID(t, a.call("g6-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/equipo", "title": "Task list loses its scroll position after a refresh", "brief": "When the task list refreshes itself, the page jumps back to the top.", "separate": true})) a.call("g6-find", wire.ToolAddFinding, map[string]any{"task": g.running, "text": "The live swap replaces the whole list; the browser has nothing to anchor to.", "repo": "oficina/equipo", "path": "internal/equipo/static/live.js", "line": 88}) a.call("g6-start", wire.ToolStartTask, map[string]string{"task": g.running, "brief": "Keep the scroll position."}) _, body = a.expect(wire.FrameDispatch) g.runningStep = body.(*wire.DispatchCommand) a.step("g6-run", wire.StepReport{TaskID: g.running, StepID: g.runningStep.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: sha("8"), Family: "claude", Account: "claude-a"}) for i, l := range []wire.StepActivityReport{{Kind: wire.ActivityRead, Subject: "internal/equipo/static/live.js"}, {Kind: wire.ActivitySearch, Subject: "replaceWith"}, {Kind: wire.ActivityRead, Subject: "internal/equipo/static/nav-stream.js"}, {Kind: wire.ActivityEdit, Subject: "internal/equipo/static/live.js"}} { l.TaskID, l.StepID, l.Attempt = g.running, g.runningStep.StepID, 1 a.activity("g6-act-"+itoa(i), l) } a.wait("activity", func(c *Conversation) bool { return len(c.StepActivity[g.runningStep.StepID]) == 4 }) // Woodstar: looked into, with a finding, not started. g.looking = taskID(t, a.call("g7-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": "Timeline jumps when images load", "brief": "Scrolling the timeline, the list shifts under my thumb as images arrive.", "separate": true})) a.call("g7-find", wire.ToolAddFinding, map[string]any{"task": g.looking, "text": "Image cells size themselves after the image arrives; the list needs the size up front.", "repo": "oficina/sample", "path": "ios/Woodstar/Timeline/ImageCell.swift", "line": 22}) // The coordinator's notes about Woodstar. nb := wire.NotebookReport{Person: Owner, Entries: []wire.NotebookEntry{ {ID: "n1", Source: wire.NoteRepo, Repo: "oficina/sample", Path: "README.md", Text: "Panes are the app's own container: each tab is a pane with its own navigation stack, so system gestures are forwarded by hand.", At: time.Now().Add(-48 * time.Hour).UTC()}, {ID: "n2", Source: wire.NoteOwn, Repo: "oficina/sample", Text: "Gesture bugs need a device to confirm; the simulator hides them.", At: time.Now().Add(-24 * time.Hour).UTC()}, }} a.step2("g-nb", wire.FrameNotebook, nb) a.wait("all tasks", func(c *Conversation) bool { return len(c.Tasks) == 7 }) return g } // TestPagesInnerScreens: the inner screens draw the gallery as the // mockup does, from API v1 data alone. func TestPagesInnerScreens(t *testing.T) { g := newGallery(t) a := g.a noInlineStyles(t, g) owner := a.inst.Cookie() has := func(page, what string, wants ...string) { t.Helper() for _, w := range wants { if !strings.Contains(page, w) { t.Fatalf("%s lacks %q:\n%s", what, w, page) } } } not := func(page, what string, nots ...string) { t.Helper() for _, n := range nots { if strings.Contains(page, n) { t.Fatalf("%s shows %q", what, n) } } } tasks := a.get(owner, "/tasks", 200) // Groups in order, each row a link with its track, badges and source. order := []string{`data-group="needs"`, `data-group="progress"`, `data-group="ready"`, `data-group="done"`} for i := 1; i < len(order); i++ { if !strings.Contains(tasks, order[i-1]) || strings.Index(tasks, order[i-1]) > strings.Index(tasks, order[i]) { t.Fatalf("groups out of order: %s before %s", order[i-1], order[i]) } } has(tasks, "Tasks", `
Approved.
", `AccountNavigationHost", "Pushed bc025ca", "The brief", "Where it lives", `data-open-amadan>Open on Amadan`)
// Paths and commits live behind Details only.
outside := regexp.MustCompile(`(?s)