Files
mesh-delivery/modules/mesh-delivery-forge-bridge/internal/bridge/owed_test.go
T
jschoubben 13d960a120 F1: an owed act failing on a part away stays owed, and a record's acts are performed again
An owed act met by the forge away (401 while the store was replaced) ended
could not be performed and nothing performed it again. Each act is now a kept
call at the module's pace (kept-call-pace-first, kept-call-pace-max) until
owed-away-bound (60 minutes), then ends could not be performed naming every
try. Before each try the bridge reads the pull request through the seat git's
pull: one closed unmerged ends owed.ended not-needed, never performed. The
gate's owed event gains record (the delivery record's source revision), kept
with the act in performed, and bridge_owed_again by record and why performs
again every act of that record that ended could not be performed, written in
the hand-act log first.

Builds: design 47 H2 §807, §775, §819, H-A-432
2026-11-22 01:46:49 +01:00

96 lines
5.0 KiB
Go

package bridge
import (
"encoding/json"
"errors"
"reflect"
"strings"
"testing"
git "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
"mesh-delivery-forge-bridge/internal/gitfixture"
)
// Design 47 *What the gate owes the forge*: each act the gate or the checker says as owed is the seat git's verb of that
// act, under the act's id; what cannot be read is undecodable, and every answer is one outcome.
func TestAnOwedEventIsTheSeatGitsVerbAndItsAnswerOneOutcome(t *testing.T) {
gate := func(name string) []byte { return gitfixture.Seat(t, "mesh-delivery", "events", name, "event:owed")[0] }
a40 := strings.Repeat("a", 40)
edit := func(raw []byte, k string, v any) []byte {
var m map[string]any
_ = json.Unmarshal(raw, &m)
if v == nil {
delete(m, k)
} else {
m[k] = v
}
b, _ := json.Marshal(m)
return b
}
for _, c := range []struct {
name string
read func([]byte) (OwedCall, error)
data []byte
verb string
input any
bad string
}{
{"a status on the head", GateOwed, gate("owed is said, a status"), "status", git.StatusInput{ID: "status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate",
Repository: "novox/mesh-sdk", Commit: a40, Context: "mesh/merge-gate", State: "pending", Description: "waits for the operator's Approve", Target: "https://forge.test/x"}, ""},
{"a view", GateOwed, edit(edit(gate("owed is said, a status"), "act", "view"), "text", "the view"), "view",
git.ViewInput{ID: "status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate", Repository: "novox/mesh-sdk", Number: 178, Text: "the view"}, ""},
{"a comment", GateOwed, edit(edit(gate("owed is said, a status"), "act", "comment"), "text", "hello"), "comment",
git.CommentInput{ID: "status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate", Repository: "novox/mesh-sdk", Number: 178, Text: "hello"}, ""},
{"a note line on its commit", GateOwed, edit(edit(edit(gate("owed is said, a status"), "act", "note"), "line", "a line"), "commit", strings.Repeat("c", 40)), "note",
git.NoteInput{ID: "status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate", Repository: "novox/mesh-sdk", Commit: strings.Repeat("c", 40), Line: "a line"}, ""},
{"not json", GateOwed, []byte("{"), "", nil, "not json"},
{"no id", GateOwed, edit(gate("owed is said, a status"), "id", nil), "", nil, "no id"},
{"a short head", GateOwed, edit(gate("owed is said, a status"), "head", "abc"), "", nil, "40 hex"},
{"a comment on no pull request", GateOwed, edit(edit(gate("owed is said, a status"), "act", "comment"), "number", 0), "", nil, "no pull request"},
{"an act of no kind", GateOwed, edit(gate("owed is said, a status"), "act", "label"), "", nil, "none the seat git"},
{"a repository not owner/name", GateOwed, edit(gate("owed is said, a status"), "repository", "mesh-sdk"), "", nil, "owner"},
} {
got, err := c.read(c.data)
switch {
case c.bad != "":
if !errors.Is(err, ErrUndecodable) || !strings.Contains(err.Error(), c.bad) {
t.Errorf("%s: %v, want undecodable naming %q", c.name, err, c.bad)
}
case err != nil || got.Verb != c.verb || !reflect.DeepEqual(got.Input, c.input):
t.Errorf("%s: %s %+v %v, want %s %+v", c.name, got.Verb, got.Input, err, c.verb, c.input)
}
}
// Design 47 H2 §807 (H-A-432 (1)): the delivery record an owed act names is carried with it; an act naming none has none.
if got, err := GateOwed(edit(gate("owed is said, a status"), "record", "main.212")); err != nil || got.Record != "main.212" {
t.Errorf("an act of a record: %+v %v, want its record main.212", got, err)
}
if got, err := GateOwed(gate("owed is said, a status")); err != nil || got.Record != "" {
t.Errorf("an act of no record: %+v %v, want none", got, err)
}
answers := func(verb string) []json.RawMessage { return gitfixture.All(t, verb+" answers", "verb:"+verb+".answer") }
failed := func(verb string) json.RawMessage {
return gitfixture.Given(t, verb+" answers an error, never none", "verb:"+verb+".answer")
}
for _, c := range []struct {
name string
raw json.RawMessage
err error
outcome, words string
}{
{"a status performed", answers("status")[0], nil, forgemsg.OwedPerformed, ""},
{"a comment already held", answers("comment")[0], nil, forgemsg.OwedPerformed, ""},
{"the forge's error, of the kind refused", failed("comment"), nil, forgemsg.OwedRefused, "403"},
{"the forge's error, of the kind failed", failed("view"), nil, forgemsg.OwedCouldNotBePerformed, "502"},
{"no answer in the call's bound", nil, errors.New("nats: timeout"), forgemsg.OwedCouldNotBePerformed, "timeout"},
{"an answer saying nothing", json.RawMessage(`{"id":"x"}`), nil, forgemsg.OwedCouldNotBePerformed, "neither"},
{"an answer not the contract's", json.RawMessage(`[1]`), nil, forgemsg.OwedCouldNotBePerformed, "contract"},
} {
outcome, words := Outcome(c.raw, c.err)
if outcome != c.outcome || !strings.Contains(words, c.words) {
t.Errorf("%s: %q %q, want %q naming %q", c.name, outcome, words, c.outcome, c.words)
}
}
}