mesh/merge-gate head c4fd31aa7e97 merged into trunk eb4f16431ce3 — pass: builds mesh-delivery-gate → novox; no bus step; every machine composes with the ch…
mesh/repo-check head c4fd31aa7e97 merged into trunk eb4f16431ce3 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (go), merge-…
mesh/delivery delivered
mesh/check failed: unit: clipmenu/cmd/clipmenu-tools.TestTheLauncherWaitsQuietlyWhileAnotherClipmenudHoldsTheLock: manifest_test.go:199: the launcher …
224 lines
8.6 KiB
Go
224 lines
8.6 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// novox/hq issue 1803, ADR 0496: the Approve is asked only for a head with a review recorded at that head. A missing
|
|
// line, `Reviewed-by: pending` or a line naming another commit holds the ask; the delivery stays ready and says it waits
|
|
// for a review at the head. An edit naming the head asks at once. A group asks when every member is reviewed. An ask
|
|
// already raised is not touched.
|
|
|
|
const stale1803 = "9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f"
|
|
|
|
// greenWithBody is a green pull request whose description is body, the operator not answering by himself.
|
|
func greenWithBody(t *testing.T, body string) *world {
|
|
w := newWorld(t)
|
|
w.op.auto = false
|
|
p := pr("novox/app", 7, readyHead, "feat/x", "src/a.go")
|
|
p.Title = "Fix the apostrophe (issue 948)"
|
|
p.Body = body
|
|
w.h.PullUpdated(p)
|
|
w.h.Checked(judgedAt("novox/app", 7, readyHead, "pass", "t1t1t1t1t1t1"))
|
|
w.forge.open = []OpenPull{openPull("novox/app", 7, readyHead)}
|
|
w.h.SeeOpenPulls()
|
|
w.settleAll()
|
|
return w
|
|
}
|
|
|
|
func (w *world) wantHeld(t *testing.T, label string) {
|
|
t.Helper()
|
|
want := "waits for a review at " + shortOf(readyHead, 12)
|
|
d := w.delivery(IDOf("novox/app", readyHead))
|
|
if w.op.count() != 0 || len(w.op.open()) != 0 {
|
|
t.Fatalf("%s: the operator was asked (%d asks)", label, w.op.count())
|
|
}
|
|
if d.State != Ready || d.Ready == nil || !strings.Contains(d.Ready.Waits, want) {
|
|
t.Fatalf("%s: state %s, waits %+v; wanted ready and %q", label, d.State, d.Ready, want)
|
|
}
|
|
found := false
|
|
for k, v := range w.forge.statuses {
|
|
if strings.HasSuffix(strings.SplitN(k, " ", 2)[1], "mesh/delivery") && strings.Contains(v, want) {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("%s: no mesh/delivery status says %q: %v", label, want, w.forge.statuses)
|
|
}
|
|
}
|
|
|
|
func TestA1803PendingReviewLineHoldsTheAsk(t *testing.T) {
|
|
w := greenWithBody(t, "Reviewed-by: pending")
|
|
w.wantHeld(t, "1803/AC1 pending")
|
|
for range 3 {
|
|
w.later(2 * 60 * 1e9)
|
|
w.settleAll()
|
|
}
|
|
w.wantHeld(t, "1803/AC1 pending after ticks")
|
|
}
|
|
|
|
func TestA1803MissingReviewLineHoldsTheAsk(t *testing.T) {
|
|
w := greenWithBody(t, "No review line at all.")
|
|
w.wantHeld(t, "1803/AC1 missing")
|
|
}
|
|
|
|
func TestA1803ReviewLineOfAnotherCommitHoldsTheAsk(t *testing.T) {
|
|
w := greenWithBody(t, "Reviewed-by: reviewer@shanks at "+stale1803)
|
|
w.wantHeld(t, "1803/AC2 stale")
|
|
}
|
|
|
|
func TestA1803ReviewLineNamingTheHeadIsAsked(t *testing.T) {
|
|
w := greenWithBody(t, "Reviewed-by: reviewer@shanks at "+readyHead)
|
|
if len(w.op.open()) != 1 {
|
|
t.Fatalf("1803/AC3: a review at the head is not asked: %v", w.op.open())
|
|
}
|
|
if e := w.op.ask(w.op.open()[0]).Explanation; !strings.Contains(e, "reviewed by reviewer on shanks") {
|
|
t.Fatalf("the ask does not name the review: %s", e)
|
|
}
|
|
}
|
|
|
|
func TestA1803AnEditNamingTheHeadRaisesTheAskAtOnce(t *testing.T) {
|
|
w := greenWithBody(t, "Reviewed-by: pending")
|
|
w.wantHeld(t, "1803/AC4 before the edit")
|
|
e := pr("novox/app", 7, readyHead, "feat/x")
|
|
e.Body = "Reviewed-by: reviewer@shanks at " + readyHead
|
|
w.h.PullEdited(e)
|
|
w.settleAll()
|
|
if len(w.op.open()) != 1 {
|
|
t.Fatalf("1803/AC4: the edit naming the head raised no ask: %d asks", w.op.count())
|
|
}
|
|
// An unanswered ask whose review is taken back is withdrawn: the hold applies again (ADR 0496 §1).
|
|
e.Body = "Reviewed-by: pending"
|
|
w.h.PullEdited(e)
|
|
w.settleAll()
|
|
if len(w.op.open()) != 0 {
|
|
t.Fatalf("1803/AC4: an unanswered ask stayed after its review was taken back: open %v", w.op.open())
|
|
}
|
|
}
|
|
|
|
func TestA1803AnApproveAlreadyGivenIsNotAffected(t *testing.T) {
|
|
w := greenWithBody(t, "Reviewed-by: reviewer@shanks at "+readyHead)
|
|
w.op.answer(w.op.open()[0], OptionApprove)
|
|
w.settleAll()
|
|
if len(w.forge.merges) != 1 {
|
|
t.Fatalf("1803/AC6: the approved head was not merged: %v", w.forge.merges)
|
|
}
|
|
// A later edit to pending changes nothing of the Approve given.
|
|
e := pr("novox/app", 7, readyHead, "feat/x")
|
|
e.Body = "Reviewed-by: pending"
|
|
w.h.PullEdited(e)
|
|
w.settleAll()
|
|
if d := w.delivery(IDOf("novox/app", readyHead)); d.Ready == nil || d.Ready.Approved == nil {
|
|
t.Fatalf("1803/AC6: the Approve given was lost: %+v", d.Ready)
|
|
}
|
|
}
|
|
|
|
const gTools, gHt = "novox/mesh-tools", "e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3"
|
|
|
|
// groupOf is a green group of the given members (repository, number, head, review body), composed green, the operator not
|
|
// answering by himself.
|
|
func groupOf(t *testing.T, members [][4]string) *world {
|
|
w := newWorld(t)
|
|
w.op.auto = false
|
|
for i, m := range members {
|
|
p := pr(m[0], i+1, m[2], "feat/g", "src/a.go")
|
|
p.Body = m[3]
|
|
w.h.PullUpdated(p)
|
|
}
|
|
for i, m := range members {
|
|
w.h.Checked(judged(m[0], i+1, m[2], "pass", gTrunk0))
|
|
}
|
|
w.settleAll()
|
|
g := w.h.groups["feat/g"]
|
|
if g == nil || g.Check == nil {
|
|
t.Fatalf("no composed check was asked: %+v", g)
|
|
}
|
|
c := CheckedEvent{Group: "feat/g", ID: g.Check.Asked, Verdict: "pass", Summary: "composed"}
|
|
for _, m := range members {
|
|
owner, repo, _ := strings.Cut(m[0], "/")
|
|
c.Members = append(c.Members, struct {
|
|
Owner string `json:"owner"`
|
|
Repo string `json:"repo"`
|
|
Commit string `json:"commit"`
|
|
Trunk string `json:"trunk,omitempty"`
|
|
}{Owner: owner, Repo: repo, Commit: m[2], Trunk: gTrunk0[:12]})
|
|
}
|
|
w.h.Checked(c)
|
|
w.settleAll()
|
|
return w
|
|
}
|
|
|
|
func reviewedAt(head string) string { return "Reviewed-by: reviewer@shanks at " + head }
|
|
|
|
// wantGroupSays checks the group's state, its mesh/delivery-group status and the member's mesh/delivery status.
|
|
func (w *world) wantGroupSays(t *testing.T, label, member, head string, want, notWant string) {
|
|
t.Helper()
|
|
g := w.h.groups["feat/g"]
|
|
state, why, held := w.h.groupState(g, w.h.membersOf(g))
|
|
if state != "ready" || !held || !strings.Contains(why, want) || (notWant != "" && strings.Contains(why, notWant)) {
|
|
t.Fatalf("%s: group state %s, why %q, held %v; wanted ready waiting with %q and without %q", label, state, why, held, want, notWant)
|
|
}
|
|
for _, c := range []string{"mesh/delivery-group", "mesh/delivery"} {
|
|
said := w.forge.statuses[member+"@"+head+" "+c]
|
|
if !strings.HasPrefix(said, "pending") || !strings.Contains(said, want) || (notWant != "" && strings.Contains(said, notWant)) {
|
|
t.Fatalf("%s: %s on %s says %q; wanted pending with %q and without %q", label, c, member, said, want, notWant)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestA1803AGroupIsAskedOnlyWhenEveryMemberIsReviewedAtItsHead(t *testing.T) {
|
|
w := groupOf(t, [][4]string{{gCtl, "", gHc, reviewedAt(gHc)}, {gCat, "", gHk, "Reviewed-by: pending"}})
|
|
if w.op.count() != 0 {
|
|
t.Fatalf("1803/AC5: a group with an unreviewed member was asked: %d asks", w.op.count())
|
|
}
|
|
w.wantGroupSays(t, "1803/AC5", gCtl, gHc, "mesh-catalog#2", "mesh-controller#1")
|
|
e := pr(gCat, 2, gHk, "feat/g")
|
|
e.Body = reviewedAt(gHk)
|
|
w.h.PullEdited(e)
|
|
w.settleAll()
|
|
if len(w.op.open()) != 1 {
|
|
t.Fatalf("1803/AC5: every member reviewed, yet %d asks", w.op.count())
|
|
}
|
|
if said := w.forge.statuses[gCtl+"@"+gHc+" mesh/delivery-group"]; !strings.HasPrefix(said, "success") {
|
|
t.Fatalf("1803/AC5: the group's status once asked is %q", said)
|
|
}
|
|
}
|
|
|
|
func TestA1803TheWaitingWordsFollowTheMembersStillWaiting(t *testing.T) {
|
|
w := groupOf(t, [][4]string{{gCtl, "", gHc, reviewedAt(gHc)}, {gCat, "", gHk, "Reviewed-by: pending"}, {gTools, "", gHt, "Reviewed-by: pending"}})
|
|
w.wantGroupSays(t, "1803/AC7 two waiting", gCtl, gHc, "mesh-catalog#2", "")
|
|
w.wantGroupSays(t, "1803/AC7 two waiting", gCtl, gHc, "mesh-tools#3", "")
|
|
e := pr(gCat, 2, gHk, "feat/g")
|
|
e.Body = reviewedAt(gHk)
|
|
w.h.PullEdited(e)
|
|
w.settleAll()
|
|
if w.op.count() != 0 {
|
|
t.Fatalf("1803/AC7: a member still waits, yet %d asks", w.op.count())
|
|
}
|
|
// Only the other member is named now, on the group and on every member's own status.
|
|
w.wantGroupSays(t, "1803/AC7 one waiting", gCtl, gHc, "mesh-tools#3", "mesh-catalog#2")
|
|
w.wantGroupSays(t, "1803/AC7 one waiting", gCat, gHk, "mesh-tools#3", "mesh-catalog#2")
|
|
}
|
|
|
|
func TestA1803APushAfterAnApprovingReviewHoldsTheNewHead(t *testing.T) {
|
|
w := greenWithBody(t, reviewedAt(readyHead))
|
|
if len(w.op.open()) != 1 {
|
|
t.Fatalf("setup: the reviewed head is not asked")
|
|
}
|
|
// A new head on the same pull request whose description still names the old commit.
|
|
const pushed2 = "7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a"
|
|
p := pr("novox/app", 7, pushed2, "feat/x", "src/a.go")
|
|
p.Body = reviewedAt(readyHead)
|
|
w.h.PullUpdated(p)
|
|
w.h.Checked(judgedAt("novox/app", 7, pushed2, "pass", "t1t1t1t1t1t1"))
|
|
w.settleAll()
|
|
d := w.delivery(IDOf("novox/app", pushed2))
|
|
if d.Ready == nil || !strings.Contains(d.Ready.Waits, waitsForReview+shortOf(pushed2, 12)) {
|
|
t.Fatalf("1803/AC8: the new head waits %+v; wanted it to wait for a review at %s", d.Ready, shortOf(pushed2, 12))
|
|
}
|
|
if len(w.op.open()) != 0 {
|
|
t.Fatalf("1803/AC8: the new head was asked on the old review: %v", w.op.open())
|
|
}
|
|
}
|