package thintest import ( "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) // rowsFixture is a Tasks list with one row for each kind of decision the // redesigned rows answer (Retry, Retry push, Another round, What next?), // three merged tasks for Done's "Show N more", a title too long for two // lines, and enough noted tasks to fill the list past twenty rows. type rowsFixture struct { r *toolRig retry, push, rounds, explore, long string done []string noted []string } const rowsLongTitle = "Make the compose sheet keep its draft, attachments and scroll position when the app comes back from the background" func newRowsFixture(t *testing.T, noted int) *rowsFixture { t.Helper() r := newToolRigAt(t, wire.ProtocolCurrent) f := &rowsFixture{r: r} sha := func(c string) string { return strings.Repeat(c, 40) } // Done: three tasks Equipo merged. for i, c := range []string{"a", "b", "c"} { key := "d" + itoa(i) id, _ := r.pushed(key, "Fix README typo number "+itoa(i+1), sha("1"), sha(c)) r.expect(wire.FrameWatchMerge) ch := r.dispatched(wire.SpecialistChecks, sha("1"), sha(c), 0) r.checks(key+"-c", ch, wire.ChecksPassed, exit(0), "", "ok\n") rv := r.dispatched(wire.SpecialistReview, sha("1"), sha(c), 0) r.verdict(key+"-r", rv, wire.VerdictApprove) m := r.dispatched(wire.SpecialistMerge, sha("1"), sha(c), 0) r.mergedStep(key+"-m", m, sha("d")) r.wait("merged", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageDone }) f.done = append(f.done, id) } // Stopped: the model connection failed (Retry), the push failed // (Retry push). stopped := func(key, title, reason string) string { id := taskID(t, r.call(key+"-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": title, "brief": "Fix it.", "separate": true})) if res := r.call(key+"-start", wire.ToolStartTask, map[string]string{"task": id, "brief": "Fix it."}); res.IsError { t.Fatalf("start: %+v", res) } r.stop(key, r.nextDispatch(), reason) r.wait("stopped", func(c *Conversation) bool { return c.Tasks[id].NeedsYou == wire.NeedsRetry }) return id } f.retry = stopped("s1", "Show project and stream context on thinking indicators", "provider_failed") f.push = stopped("s2", "Create two clickable barber app mockups", "push_failed") // Still not approved after two fix rounds: Another round. cands := []string{sha("2"), sha("3"), sha("4")} f.rounds, _ = r.pushed("fr", "Add project rename control and ship the update", sha("1"), cands[0]) r.expect(wire.FrameWatchMerge) c := r.dispatched(wire.SpecialistChecks, sha("1"), cands[0], 0) r.checks("fr-c0", c, wire.ChecksFailed, exit(2), "", "--- FAIL: TestRename\nFAIL\n") fix := r.dispatched(wire.SpecialistEngineering, cands[0], "", 1) for round := 1; round <= 2; round++ { key := "fr" + itoa(round) r.step(key+"-done", wire.StepReport{TaskID: f.rounds, StepID: fix.StepID, Attempt: 1, State: wire.StepDone, BaseSHA: cands[round-1], CandidateSHA: cands[round], Pushed: true, Termination: true}) c = r.dispatched(wire.SpecialistChecks, sha("1"), cands[round], round) r.checks(key+"-c", c, wire.ChecksNone, nil, "", "") rv := r.dispatched(wire.SpecialistReview, sha("1"), cands[round], round) r.verdict(key+"-r", rv, wire.VerdictChanges, wire.Finding{Text: "Still wrong.", Path: "README.md", Line: 5}) if round == 1 { fix = r.dispatched(wire.SpecialistEngineering, cands[1], "", 2) } } r.wait("fix rounds", func(c *Conversation) bool { return c.Tasks[f.rounds].NeedsYou == wire.NeedsFixRounds }) // An exploration waiting on its direction: What next? f.explore, _ = r.toDirection("x", "Barber app mockups") // A title too long for two lines, and the noted tasks. f.long = taskID(t, r.call("long-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/sample", "title": rowsLongTitle, "brief": "Keep the draft.", "separate": true})) subjects := []string{"invite emails", "the sign-in page", "runner logs", "the merge card", "project stars", "the notebook", "dark mode charts", "machine names", "thread replies", "preview links", "budget alerts", "the composer", "file uploads", "team links", "housekeeping", "the stage track", "spend totals", "settings search"} for i := 0; i < noted; i++ { title := "Tidy up " + subjects[i%len(subjects)] id := taskID(t, r.call("n"+itoa(i)+"-rec", wire.ToolRecordTask, map[string]any{"repo": "oficina/equipo", "title": title, "brief": "Look at " + subjects[i%len(subjects)] + " when there is time.", "separate": true})) f.noted = append(f.noted, id) } want := 3 + 2 + 1 + 1 + 1 + noted r.wait("all rows", func(c *Conversation) bool { return len(c.Tasks) >= want }) return f }