Twice an unreviewed pull request was asked and merged on a warning line alone.
98 lines
4.0 KiB
Go
98 lines
4.0 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// novox/hq issue 1079: mesh-catalog #354's description was edited ten seconds after it was opened to add its
|
|
// `Reviewed-by` line, but the line was read only when the head was announced, so the Approve's ask said "not reviewed at
|
|
// this head". The forge's edit event is followed; an Approve ask not yet answered is withdrawn and asked again with the
|
|
// record read (the operator agreed, 2026-10-18). The review record is never a gate (ADR 0421 §5).
|
|
|
|
// askedReviewed is a green pull request whose Approve is asked, its review line naming the head by one reviewer.
|
|
func askedReviewed(t *testing.T) *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 = "Reviewed-by: first@shanks at " + readyHead
|
|
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()
|
|
if open := w.op.open(); len(open) != 1 || !strings.Contains(w.op.ask(open[0]).Explanation, "reviewed by first on shanks") {
|
|
t.Fatalf("setup: the ask is %v", w.op.open())
|
|
}
|
|
return w
|
|
}
|
|
|
|
func edited(body string) PullEvent {
|
|
p := pr("novox/app", 7, readyHead, "feat/x")
|
|
p.Body = body
|
|
return p
|
|
}
|
|
|
|
func TestAReviewedByLineChangedAfterTheAskWithdrawsTheUnansweredAskAndAsksAgain(t *testing.T) {
|
|
w := askedReviewed(t)
|
|
first := w.op.open()[0]
|
|
w.h.PullEdited(edited("Reviewed-by: second@shanks at " + readyHead))
|
|
w.settleAll()
|
|
open := w.op.open()
|
|
// The heads are the same, so the key is: the ask is taken away and written again with the record in its words, which the
|
|
// teller reads as the ask to withdraw and ask afresh.
|
|
if len(open) != 1 || open[0] != first || w.op.count() != 2 {
|
|
t.Fatalf("after the edit the open asks are %v (first %s), %d asked; wanted the first withdrawn and written again once", open, first, w.op.count())
|
|
}
|
|
if len(w.op.cancelled) != 0 || w.op.byKey[first].Asking != 2 {
|
|
t.Fatalf("the first ask was taken away (%v) or not written again as asking 2 (%d)", w.op.cancelled, w.op.byKey[first].Asking)
|
|
}
|
|
if e := w.op.ask(open[0]).Explanation; !strings.Contains(e, "reviewed by second on shanks at "+shortOf(readyHead, 12)) {
|
|
t.Fatalf("the new ask does not say the record: %s", e)
|
|
}
|
|
if len(w.forge.comments) != 0 {
|
|
t.Fatalf("a withdrawn ask is not an ended Approve, so nothing is said on the pull request: %v", w.forge.comments)
|
|
}
|
|
// The new ask is the one the Approve answers.
|
|
w.op.answer(open[0], OptionApprove)
|
|
w.settleAll()
|
|
if len(w.forge.merges) != 1 {
|
|
t.Fatalf("the new ask's Approve did not merge: %v", w.forge.merges)
|
|
}
|
|
}
|
|
|
|
func TestAnEditThatChangesNothingTheAskSaysAsksNothingAndNoEditChangesAnAnsweredAsk(t *testing.T) {
|
|
w := askedReviewed(t)
|
|
// The same words: a description with the same line and a new sentence.
|
|
w.h.PullEdited(edited("A new sentence.\nReviewed-by: first@shanks at " + readyHead))
|
|
w.settleAll()
|
|
if w.op.count() != 1 || len(w.op.cancelled) != 0 {
|
|
t.Fatalf("an edit that changes no word of the ask asked again: %d asks, cancelled %v", w.op.count(), w.op.cancelled)
|
|
}
|
|
// Answered: a later edit changes nothing.
|
|
w.op.answer(w.op.open()[0], OptionApprove)
|
|
w.settleAll()
|
|
asked := w.op.count()
|
|
w.h.PullEdited(edited("Reviewed-by: second@shanks at " + readyHead))
|
|
w.settleAll()
|
|
if w.op.count() != asked || len(w.op.open()) != 0 {
|
|
t.Fatalf("an edit after the Approve asked again: %d asks, open %v", w.op.count(), w.op.open())
|
|
}
|
|
if d := w.delivery(IDOf("novox/app", readyHead)); d.ReviewedBy != "second@shanks" {
|
|
t.Fatalf("the record is still read: %q", d.ReviewedBy)
|
|
}
|
|
}
|
|
|
|
func TestAnEditOfAnUnknownOrMergedOrEmptyPullRequestChangesNothing(t *testing.T) {
|
|
w := askedReviewed(t)
|
|
other := pr("novox/other", 3, readyHead, "feat/y")
|
|
other.Body = "Reviewed-by: a@b at " + readyHead
|
|
w.h.PullEdited(other) // no delivery: nothing made
|
|
w.h.PullEdited(edited(""))
|
|
w.settleAll()
|
|
if w.op.count() != 1 || len(w.h.deliveries) != 1 {
|
|
t.Fatalf("asks %d, deliveries %d", w.op.count(), len(w.h.deliveries))
|
|
}
|
|
}
|