At the gate's start every unanswered act is said again under the same id; an outcome is written into the record that holds the pull request, then answered; an outcome other than performed is said; the checker's are not the gate's. Needs the forge bridge's forgemsg owed.ended (feat/47-G-forge). Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ (Joined from cf3715ea.) Builds: design 47 G §162, §163, §164, §165, §166 (GATE5) Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
108 lines
3.9 KiB
Go
108 lines
3.9 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
|
|
)
|
|
|
|
// W11.17 (design 47 *What the gate owes the forge*): every act owed is said as the seat's event owed under one id and stays
|
|
// on its delivery's state until its owed.ended is heard; at the owner's start every unanswered act is said again under the
|
|
// same id; an outcome is written into the record holding the pull request before the act is answered, once; an outcome
|
|
// other than performed is said; the checker's outcomes are not the gate's.
|
|
func TestAnActOwedStaysUntilItsOutcomeIsRecorded(t *testing.T) {
|
|
w := newWorld(t)
|
|
w.owed.silent = true
|
|
l := newLedgerFake(t)
|
|
id := IDOf("novox/app", head)
|
|
w.h.Records = &Records{Ledger: l, Now: w.h.Now}
|
|
if _, _, err := w.h.Records.Open("feat/x", map[string]string{id: head}, false); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
w.h.PullUpdated(pr("novox/app", 7, head, "feat/x", "src/a.go"))
|
|
w.settleAll()
|
|
w.settleAll()
|
|
held := map[string]bool{}
|
|
for _, e := range w.delivery(id).Owed {
|
|
if e.Said != nil && e.ID != "" {
|
|
held[e.ID] = true
|
|
}
|
|
}
|
|
if len(held) < 3 {
|
|
t.Fatalf("the acts said and held on the delivery: %v; its owed %+v", held, w.delivery(id).Owed)
|
|
}
|
|
saidOnce := map[string]int{}
|
|
for _, o := range w.owed.said {
|
|
saidOnce[o.ID]++
|
|
if !held[o.ID] && strings.Contains(o.ID, ".view@") {
|
|
t.Errorf("the view %s was said but is not held", o.ID)
|
|
}
|
|
}
|
|
for heldID := range held {
|
|
if saidOnce[heldID] != 1 {
|
|
t.Errorf("%s was said %d times before any answer, want once", heldID, saidOnce[heldID])
|
|
}
|
|
}
|
|
|
|
// The owner starts again over the same state: every unanswered act is said again, under the same id.
|
|
w2 := newWorldOver(t, w.store, w.forge, w.now)
|
|
w2.owed.silent = true
|
|
w2.h.Records = &Records{Ledger: l, Now: w2.h.Now}
|
|
w2.h.Flush()
|
|
again := map[string]bool{}
|
|
for _, o := range w2.owed.said {
|
|
again[o.ID] = true
|
|
}
|
|
for heldID := range held {
|
|
if !again[heldID] {
|
|
t.Errorf("%s was not said again at the start; said %v", heldID, again)
|
|
}
|
|
}
|
|
w2.h.Flush()
|
|
if len(w2.owed.said) != len(again) {
|
|
t.Errorf("a second flush said %d acts again, want none", len(w2.owed.said)-len(again))
|
|
}
|
|
|
|
var one string
|
|
for heldID := range held {
|
|
one = heldID
|
|
break
|
|
}
|
|
// The checker's outcome of an id is not the gate's: nothing is answered.
|
|
checkers, _ := forgemsg.EncodeOwedEnded(forgemsg.OwedEnded{Of: "mesh-delivery-checker", ID: one, Outcome: forgemsg.OwedPerformed, At: w.now})
|
|
if err := w2.h.OwedEnded(checkers); err != nil || !owedHolds(w2, id, one) {
|
|
t.Fatalf("the checker's outcome answered the gate's act: %v", err)
|
|
}
|
|
// The ledger away: the act is not answered, and the event is heard again.
|
|
l.failOn = OpAct
|
|
if err := w2.h.OwedEnded(owedEndedBody(one, forgemsg.OwedRefused, "the branch is protected")); err == nil || !owedHolds(w2, id, one) {
|
|
t.Fatalf("an outcome the record could not take answered the act: %v", err)
|
|
}
|
|
l.failOn = ""
|
|
if err := w2.h.OwedEnded(owedEndedBody(one, forgemsg.OwedRefused, "the branch is protected")); err != nil || owedHolds(w2, id, one) {
|
|
t.Fatalf("the refused outcome did not answer the act: %v", err)
|
|
}
|
|
records, _ := w2.h.Records.Current()
|
|
if a := records[0].Acts[one]; a.Outcome != forgemsg.OwedRefused || a.Words != "the branch is protected" || a.Head != head || a.Number != 7 {
|
|
t.Fatalf("the record holds the act as %+v", a)
|
|
}
|
|
if !strings.Contains(w2.logs(), "was refused: the branch is protected") {
|
|
t.Errorf("a refused act was not said: %s", w2.logs())
|
|
}
|
|
seq := records[0].Sequence
|
|
if err := w2.h.OwedEnded(owedEndedBody(one, forgemsg.OwedRefused, "the branch is protected")); err != nil || records[0].Sequence != seq {
|
|
t.Errorf("an outcome heard twice changed the record (%d, was %d): %v", records[0].Sequence, seq, err)
|
|
}
|
|
}
|
|
|
|
// owedHolds is whether the delivery still holds the act unanswered.
|
|
func owedHolds(w *world, id, act string) bool {
|
|
for _, e := range w.delivery(id).Owed {
|
|
if e.ID == act {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|