| 1 | package thintest |
| 2 | |
| 3 | import ( |
| 4 | "html" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/equipo" |
| 9 | "amadan.net/oficina/equipo/internal/wire" |
| 10 | ) |
| 11 | |
| 12 | // The first merge into an empty repository (no base: the candidate is |
| 13 | // its initial commit) before the hub can make it: the merge step stops |
| 14 | // with merge_unborn_default. The task stays Ready to merge and waits on |
| 15 | // the platform: triage says so and does nothing on its own (no retry, no |
| 16 | // recommendation), the task is not in the person's Needs you, and its |
| 17 | // page says in plain words that the merge needs an Amadan update. Once |
| 18 | // the hub can, the person's Merge goes again. |
| 19 | func TestTriageWaitsOnThePlatform(t *testing.T) { |
| 20 | r := newToolRigAt(t, wire.ProtocolEmptyMerge) |
| 21 | owner := r.inst.Cookie() |
| 22 | cand := strings.Repeat("2", 40) |
| 23 | id := r.judgedTask("u", "Create two barber mockups", "", cand, wire.ChecksNone, "") |
| 24 | if k := r.task(id); k.Stage != wire.StageReadyToMerge || k.NeedsYou != wire.NeedsMerge { |
| 25 | t.Fatalf("judged %s %q", k.Stage, k.NeedsYou) |
| 26 | } |
| 27 | // No checks: Equipo asks; the person chooses Merge on the card. |
| 28 | card := r.mergeCardsWait(id) |
| 29 | if _, err := r.client.Answer(r.ctx, card.ID, wire.ChoiceMerge, card.Revision); err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | m := r.dispatched(wire.SpecialistMerge, "", cand, 0) |
| 33 | r.step("u-m-run", wire.StepReport{TaskID: id, StepID: m.StepID, Attempt: 1, State: wire.StepRunning, CandidateSHA: cand}) |
| 34 | r.step("u-m-stop", wire.StepReport{TaskID: id, StepID: m.StepID, Attempt: 1, State: wire.StepFailed, Reason: wire.ReasonMergeUnbornDefault, CandidateSHA: cand, Termination: true, Findings: []wire.Finding{}}) |
| 35 | r.syncNow("u-sync") |
| 36 | if _, err := r.inst.Store.Chat().Retriage(r.ctx, false); err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | k := r.task(id) |
| 40 | if k.Stage != wire.StageReadyToMerge || k.NeedsYou != wire.NeedsMerge || k.Triage == nil || k.Triage.Kind != wire.TriageWaiting || k.Triage.Reason != wire.ReasonMergeUnbornDefault || k.Triage.Recommend != "" { |
| 41 | t.Fatalf("task %s %q triage %+v", k.Stage, k.NeedsYou, k.Triage) |
| 42 | } |
| 43 | if acts := r.triageActions("triage_retry"); len(acts) != 0 || r.heldKinds(wire.FrameDispatch) != 0 { |
| 44 | t.Fatalf("retried on its own: %+v", acts) |
| 45 | } |
| 46 | page := r.get(owner, "/tasks/"+id, 200) |
| 47 | if !strings.Contains(page, html.EscapeString(equipo.RunnerText("work.triage.waiting"))) { |
| 48 | t.Fatal("the task does not say it waits on an Amadan update") |
| 49 | } |
| 50 | if needs := r.get(owner, "/tasks?needs=you", 200); strings.Contains(needs, "Create two barber mockups") { |
| 51 | t.Fatal("a platform wait is in Needs you") |
| 52 | } |
| 53 | // The hub updated: the person's Merge on the task sends it again. |
| 54 | if _, err := r.client.MergeTask(r.ctx, id); err != nil { |
| 55 | t.Fatal(err) |
| 56 | } |
| 57 | _, body := r.expect(wire.FrameDispatch) |
| 58 | if d := body.(*wire.DispatchCommand); d.Specialist != wire.SpecialistMerge || d.CandidateSHA != cand { |
| 59 | t.Fatalf("merge again: %+v", d) |
| 60 | } |
| 61 | } |
| 62 | |