96 lines
3.9 KiB
Go
96 lines
3.9 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// **A head nobody checks is found from events, not from a poll** (novox/hq ADR 0406 §1, issue 975, issues 347 and 722):
|
|
// the forge's open pull requests are read when this owner starts and when an event says something they show may have
|
|
// changed — a merge check's status, a new head, a ready mark — and once more at the bound a head's check is said.
|
|
|
|
func statusEvent(sha, context, state string) ForgeStatusEvent {
|
|
return ForgeStatusEvent{Owner: "novox", Repo: "hq", SHA: sha, Context: context, State: state}
|
|
}
|
|
|
|
func TestAMergeCheckStatusReadsTheOpenPullRequestsAndAnotherContextDoesNot(t *testing.T) {
|
|
w := newWorld(t)
|
|
before := w.forge.openCalls
|
|
hear(t, w, "gitea.forge.status", statusEvent("cccc", "mesh/delivery", "success"))
|
|
if w.forge.openCalls != before {
|
|
t.Fatalf("a status of a context that is no merge check read the forge %d times", w.forge.openCalls-before)
|
|
}
|
|
hear(t, w, "gitea.forge.status", statusEvent("cccc", "mesh/merge-gate", "pending"))
|
|
if w.forge.openCalls != before+1 {
|
|
t.Fatalf("a merge check's status read the forge %d times, wanted once", w.forge.openCalls-before)
|
|
}
|
|
}
|
|
|
|
func TestAHeadWhoseCheckNeverAnsweredIsSaidFromTheEventsAndOneReadAtTheBound(t *testing.T) {
|
|
w := newWorld(t)
|
|
w.forge.open = []OpenPull{{Owner: "novox", Repo: "hq", Number: 1, Base: "main", HeadSHA: "cccc",
|
|
Required: []string{"mesh/merge-gate"}, Statuses: []string{"mesh/merge-gate"},
|
|
Checks: map[string]HeadCheck{"mesh/merge-gate": {State: "pending", UpdatedAt: "2026-10-06T12:00:00Z"}}}}
|
|
hear(t, w, "gitea.forge.status", statusEvent("cccc", "mesh/merge-gate", "pending"))
|
|
if len(w.h.Stalled()) != 0 {
|
|
t.Fatal("a head just seen waiting is said already")
|
|
}
|
|
reads := w.forge.openCalls
|
|
// Minutes pass with no event: nothing polls. At the bound, one read confirms it, and it is said.
|
|
for range 3 {
|
|
w.later(5 * time.Minute)
|
|
w.h.React()
|
|
}
|
|
w.later(Bounds[Proposed].For)
|
|
w.h.React()
|
|
w.h.React()
|
|
if got := w.forge.openCalls - reads; got != 1 {
|
|
t.Fatalf("the forge's open pull requests were read %d times between the status and the bound's end; wanted once, at the bound", got)
|
|
}
|
|
if lines := w.h.Stalled(); len(lines) != 1 || lines[0].State != Unanswered {
|
|
t.Fatalf("the head whose check never answered is not said: %+v", lines)
|
|
}
|
|
}
|
|
|
|
func TestANewlyAnnouncedHeadReadsTheForgeAndAKnownOneDoesNot(t *testing.T) {
|
|
w := newWorld(t)
|
|
before := w.forge.openCalls
|
|
hear(t, w, "gitea.pull.updated", pr("novox/app", 7, readyHead, "feat/x", "src/a.go"))
|
|
if w.forge.openCalls != before+2 { // the unchecked heads, and the head's standing verdict before its check is asked (issue 1115)
|
|
t.Fatalf("a new head read the forge %d times, wanted twice", w.forge.openCalls-before)
|
|
}
|
|
hear(t, w, "gitea.pull.updated", pr("novox/app", 7, readyHead, "feat/x", "src/a.go"))
|
|
if w.forge.openCalls != before+3 { // the look of a delivery awaiting its verdict reads its standing one
|
|
t.Fatalf("the same head announced again read the forge again (%d reads)", w.forge.openCalls-before)
|
|
}
|
|
}
|
|
|
|
func TestNothingReadsTheForgeWithoutAnEvent(t *testing.T) {
|
|
w := newWorld(t)
|
|
w.forge.open = []OpenPull{openPull("novox/app", 7, readyHead)}
|
|
before := w.forge.openCalls
|
|
for range 6 {
|
|
w.later(time.Minute)
|
|
w.settleAll()
|
|
}
|
|
if w.forge.openCalls != before {
|
|
t.Fatalf("the forge's open pull requests were read %d times with no event", w.forge.openCalls-before)
|
|
}
|
|
}
|
|
|
|
func TestAClosedOrMergedPullRequestIsNoLongerSaidUnchecked(t *testing.T) {
|
|
w := newWorld(t)
|
|
w.forge.open = []OpenPull{{Owner: "novox", Repo: "hq", Number: 1, Base: "main", HeadSHA: "cccc",
|
|
Required: []string{"mesh/merge-gate"}}}
|
|
w.h.SeeOpenPulls()
|
|
w.later(11 * time.Minute)
|
|
if len(w.h.Stalled()) != 1 {
|
|
t.Fatal("not said")
|
|
}
|
|
closed := pr("novox/hq", 1, "cccc", "feat/x")
|
|
hear(t, w, "gitea.pull.closed", closed)
|
|
if lines := w.h.Stalled(); len(lines) != 0 {
|
|
t.Fatalf("a closed pull request is still said: %+v", lines)
|
|
}
|
|
}
|