package thintest import ( "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) // barberLike is staging's barber task as it was: a change approved with // a preview config, its preview failed (no credential), Paul's Merge on // the card failed at the hub; then the start-up switch made it an // exploration. func (r *toolRig) barberLike(key string) string { r.t.Helper() r.asksBeforeMerging() r.previewsOn() id, pv := r.approvedWithPreview(key, baseX, candX, true) if pv == nil { r.t.Fatal("no preview") } r.step(key+"-pv-fail", wire.StepReport{TaskID: id, StepID: pv.StepID, Attempt: 1, State: wire.StepFailed, Reason: "preview_failed", BaseSHA: baseX, CandidateSHA: candX, Termination: true, Findings: []wire.Finding{}}) card := r.mergeCardsWait(id) if _, err := r.client.Answer(r.ctx, card.ID, wire.ChoiceMerge, card.Revision); err != nil { r.t.Fatal(err) } m := r.dispatched(wire.SpecialistMerge, baseX, candX, 0) r.step(key+"-m-run", wire.StepReport{TaskID: id, StepID: m.StepID, Attempt: 1, State: wire.StepRunning, BaseSHA: baseX, CandidateSHA: candX}) r.step(key+"-m-fail", wire.StepReport{TaskID: id, StepID: m.StepID, Attempt: 1, State: wire.StepFailed, Reason: "merge_failed", BaseSHA: baseX, CandidateSHA: candX, Termination: true}) r.wait("ready again", func(c *Conversation) bool { return c.Tasks[id].Stage == wire.StageReadyToMerge }) if switched, err := r.inst.Store.Chat().ExploreOnce(r.ctx, id); err != nil || !switched { r.t.Fatalf("switch: %t %v", switched, err) } r.directionCard(id) return id } // TestExploreNeedsYou: an exploration waiting for its direction is in // Needs you, the API's and the page's, and counted on the rail. func TestExploreNeedsYou(t *testing.T) { r := newToolRigAt(t, wire.ProtocolCurrent) id := r.barberLike("ny") if k := r.task(id); k.NeedsYou != wire.NeedsDirection { t.Fatalf("needs %q", k.NeedsYou) } needs, err := r.client.NeedsYou(r.ctx) if err != nil || len(needs.Items) != 1 || needs.Items[0].ID != id { t.Fatalf("API Needs you %+v %v", needs.Items, err) } page := r.get(r.inst.Cookie(), "/tasks?needs=you", 200) _, item, ok := strings.Cut(page, `data-decision="`+id+`"`) if !ok { t.Fatalf("Needs you page lacks the decision: %s", page) } // The question opens it; the preview line and the branch link sit // under it, beside the answers. q, line, link, answer := strings.Index(item, "What next for Barber mockups?"), strings.Index(item, "There's no preview of this version."), strings.Index(item, "Open the branch on Amadan"), strings.Index(item, `value="build"`) if q < 0 || line < 0 || link < 0 || answer < 0 || !(q < line && line < link && link < answer) { t.Fatalf("order: question %d, line %d, link %d, answer %d in %s", q, line, link, answer, item[:min(len(item), 3000)]) } if before, _, _ := strings.Cut(item, "What next for"); strings.Contains(before, "preview") || strings.Contains(before, "Amadan") { t.Fatalf("something before the question: %s", before) } // The task's line: one sentence, through "It waits on you". task := r.get(r.inst.Cookie(), "/tasks/"+id, 200) if strings.Contains(task, "..") || strings.Contains(task, "waiting for your choice. It waits") || strings.Count(task, "It waits on you.") == 0 { t.Fatal("the waiting line doubles up") } } // trackOf is the full stage track on a task page: its stops' labels and // the current one. func trackOf(t *testing.T, page string) (stops []string, current string) { t.Helper() _, rest, ok := strings.Cut(page, "data-track") if !ok { t.Fatal("no track") } rest, _, _ = strings.Cut(rest, "") for _, li := range strings.Split(rest, "