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
This commit is contained in:
2026-11-22 01:46:49 +01:00
parent b76b9c58f4
commit 13d960a120
20 changed files with 463 additions and 64 deletions
@@ -20,7 +20,7 @@ const Form = 2
// whose fields changed while its forms did not (design 47 H2 §780).
const (
generatedForms = "2"
generatedFieldsDigest = "DeliveriesAnswer=d6ae3ca4e5da Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 HeadsByRepositoryBranchValue=b32fd594ee25 Owed=005330be954f OwedByRepositoryNumberHeadActValue=f16ff5733d62 OwedEvent=86af3b56de28 RecordEndedEvent=566edb8684e5 RecordEndedEventAwayItem=44ad7d26bd16 RecordOpenedEvent=9cf9afaa25b4 RecoveryAnswer=8c705e17cdf8 RecoveryMergedEvent=014d4d00d2e5 RoomEvent=5bd4df78ed84 ShowAnswer=7538f2f5e68e SourceAnswer=6ae84f05f10d SourceByBranchValue=31aa822718c0 SourceHead=e722e2d9492f SourceMovedEvent=5231909928e9 SourceMovedEventHeadsItem=774b4bf88ba4 StalledAnswer=7538f2f5e68e"
generatedFieldsDigest = "DeliveriesAnswer=d6ae3ca4e5da Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 HeadsByRepositoryBranchValue=b32fd594ee25 Owed=a30ee01924cc OwedByRepositoryNumberHeadActValue=f16ff5733d62 OwedEvent=86af3b56de28 RecordEndedEvent=566edb8684e5 RecordEndedEventAwayItem=44ad7d26bd16 RecordOpenedEvent=9cf9afaa25b4 RecoveryAnswer=8c705e17cdf8 RecoveryMergedEvent=014d4d00d2e5 RoomEvent=5bd4df78ed84 ShowAnswer=7538f2f5e68e SourceAnswer=6ae84f05f10d SourceByBranchValue=31aa822718c0 SourceHead=e722e2d9492f SourceMovedEvent=5231909928e9 SourceMovedEventHeadsItem=774b4bf88ba4 StalledAnswer=7538f2f5e68e"
)
const (
@@ -244,6 +244,8 @@ type Owed struct {
Line string `json:"line,omitempty"`
// the pull request's number
Number int64 `json:"number"`
// the delivery record the act is for, by its source revision, <branch>.<source>; absent on an act said before it was named, which bridge_owed_again by record never finds (design 47 H2 §807, H-A-432)
Record string `json:"record,omitempty"`
// the repository, <owner>/<name>
Repository string `json:"repository"`
// when the gate first said it
@@ -649,6 +649,10 @@
"type": "string",
"format": "date-time",
"description": "when the gate first said it"
},
"record": {
"type": "string",
"description": "the delivery record the act is for, by its source revision, <branch>.<source>; absent on an act said before it was named, which bridge_owed_again by record never finds (design 47 H2 §807, H-A-432)"
}
},
"required": [
@@ -110,6 +110,8 @@ export interface Owed {
"line"?: string;
/** the pull request's number */
"number": number;
/** the delivery record the act is for, by its source revision, <branch>.<source>; absent on an act said before it was named, which bridge_owed_again by record never finds (design 47 H2 §807, H-A-432) */
"record"?: string;
/** the repository, <owner>/<name> */
"repository": string;
/** when the gate first said it */
@@ -164,8 +164,8 @@ func main() {
tools = append(tools, OwedTools(askState(owedAsks, groups.OwedAsksBucket(served), 25*time.Second, func(v []byte) bool {
a, err := groups.DecodeOwedAsk(v)
return err == nil && a.Done()
}), func(f OwedFilter) ([]OwedRow, error) { return performedRows(performed, f) }, func(what, why string) error {
_, err := recorder.Record(meshhandactsclient.Request{What: what, Why: why, Cause: "owed-dropped"})
}), func(f OwedFilter) ([]OwedRow, error) { return performedRows(performed, f) }, func(what, why, cause string) error {
_, err := recorder.Record(meshhandactsclient.Request{What: what, Why: why, Cause: cause})
return err
}, time.Now)...)
tools = append(tools, PerformedPruneTools(prunedPerformed(), recorder)...)
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"reflect"
"strings"
"testing"
"time"
@@ -111,7 +112,10 @@ func TestTheBridgeTools(t *testing.T) {
}
var recorded []string
recordErr := error(nil)
record := func(what, why string) error { recorded = append(recorded, what+": "+why); return recordErr }
record := func(what, why, cause string) error {
recorded = append(recorded, what+": "+why+" ("+cause+")")
return recordErr
}
tools := map[string]func(map[string]any) (any, error){}
for _, tl := range OwedTools(ask, performed, record, func() time.Time { return at }) {
tools[tl.Name] = tl.Run
@@ -164,6 +168,19 @@ func TestTheBridgeTools(t *testing.T) {
if _, _, err := groups.NewOwedAsk(groups.OwedAgain, "", "a", "", "", at); err == nil {
t.Error("an ask naming no seat was taken")
}
// Design 47 H2 §807 (H-A-432 (1)): bridge_owed_again by record asks the bridge for every act of one delivery record,
// written in the hand-act log first; with no why, or with an act named beside it, nothing is asked.
n, r := len(asked), len(recorded)
for _, bad := range []map[string]any{{"record": "main.212"}, {"record": "main.212", "of": seat.Seat, "id": "a", "why": "x"}} {
if _, err := tools[OwedAgainTool](bad); err == nil || len(asked) != n || len(recorded) != r {
t.Errorf("bridge_owed_again %v: %v, asked %d; want refused, nothing asked", bad, err, len(asked)-n)
}
}
if out, err := tools[OwedAgainTool](map[string]any{"record": "main.212", "why": "the forge was away"}); err != nil ||
len(asked) != n+1 || asked[n].Record != "main.212" || asked[n].Kind != groups.OwedAgain || asked[n].ID != "" ||
len(recorded) != r+1 || !strings.HasSuffix(recorded[r], "(owed-again)") {
t.Errorf("bridge_owed_again by record: %v %v, asked %+v, recorded %v", out, err, asked[n:], recorded[r:])
}
})
// Design 47 H2 §812 (H-A-380 (3), H-A-433): the bridge serves the two prune tools over its state performed, named for
// its module, each written in the hand-act log before it acts.
@@ -72,9 +72,9 @@ func performedRows(s stdio.KeptState, f OwedFilter) ([]OwedRow, error) {
}
// OwedTools are bridge_owed, bridge_owed_again and bridge_owed_drop: ask writes an owed-asks value and waits for the
// bridge's answer; performed reads the state performed; record writes a hand act in the seat mesh-hand-acts' log before
// a drop is asked, so a drop is never made without its record.
func OwedTools(ask func(key string, value []byte) ([]byte, error), performed func(OwedFilter) ([]OwedRow, error), record func(what, why string) error, now func() time.Time) []stdio.Tool {
// bridge's answer; performed reads the state performed; record writes a hand act in the seat mesh-hand-acts' log (what,
// why and its cause) before a drop or a record's acts performed again is asked, so neither is made without its record.
func OwedTools(ask func(key string, value []byte) ([]byte, error), performed func(OwedFilter) ([]OwedRow, error), record func(what, why, cause string) error, now func() time.Time) []stdio.Tool {
str := func(args map[string]any, k string) string { s, _ := args[k].(string); return strings.TrimSpace(s) }
act := map[string]any{
"of": map[string]any{"type": "string", "description": "the seat that said the act: mesh-delivery (the gate)"},
@@ -96,6 +96,12 @@ func OwedTools(ask func(key string, value []byte) ([]byte, error), performed fun
for k, v := range act {
read[k] = v
}
againArgs := map[string]any{
"record": map[string]any{"type": "string", "description": "instead of of and id: a delivery record's source revision, <branch>.<source>; with why"},
"why": map[string]any{"type": "string", "description": "with record: why its acts are performed again, in plain words"}}
for k, v := range act {
againArgs[k] = v
}
withWhy := map[string]any{"why": map[string]any{"type": "string", "description": "why it is dropped, in plain words"}}
for k, v := range act {
withWhy[k] = v
@@ -104,7 +110,7 @@ func OwedTools(ask func(key string, value []byte) ([]byte, error), performed fun
{Name: OwedTool,
Description: "What the forge bridge performed of what the gate and the checker owe the forge (design 47): each act it said as " +
"owed.ended, newest first, with its seat, id, pull request, outcome (performed, refused, could not be performed, " +
"undecodable, dropped), the forge's words and when, from its state performed (kept 7 days), of one act (id, of " +
"undecodable, dropped, not-needed), the forge's words and when, from its state performed (kept 3 days), of one act (id, of " +
"narrowing it) or of one pull request (repository and number), never the whole state; and the backlog of its " +
"durable on each seat's stream owed: the last event applied, the events waiting and held, the age of the oldest. " +
"Read-only.",
@@ -133,9 +139,33 @@ func OwedTools(ask func(key string, value []byte) ([]byte, error), performed fun
Description: "Perform one act owed to the forge again now, by hand, whatever its last outcome (a refusal the forge no longer " +
"makes, an act that could not be performed): the bridge calls the seat git's verb of the act under its id (safe to " +
"repeat) and says its outcome as owed.ended. The act is read from the stream owed of the seat that said it, on the " +
"subject of the pull request the bridge's state performed names (kept 7 days there). Answers the outcome.",
Input: map[string]any{"type": "object", "required": []string{"of", "id"}, "properties": act},
"subject of the pull request the bridge's state performed names (kept 3 days there). Or, with record (a delivery " +
"record's source revision, <branch>.<source>) and why instead of of and id, every act of that record that ended " +
"could not be performed, written first in the hand-act log (design 47 H2 §807). Each act reads its pull request " +
"again before it acts: one closed unmerged ends not-needed. Answers the outcome, or each act's.",
Input: map[string]any{"type": "object", "properties": againArgs},
Run: func(args map[string]any) (any, error) {
if rec := str(args, "record"); rec != "" {
if str(args, "of") != "" || str(args, "id") != "" {
return nil, fmt.Errorf("bridge_owed_again names one act (of and id) or one record, not both")
}
key, value, err := groups.NewOwedRecordAsk(rec, str(args, "why"), stdio.CallerOf(args), now())
if err != nil {
return nil, err
}
if err := record("performed again every act of the record "+rec+" that could not be performed", str(args, "why"), "owed-again"); err != nil {
return nil, err
}
v, err := ask(key, value)
if err != nil {
return nil, err
}
a, err := groups.DecodeOwedAsk(v)
if err != nil {
return nil, err
}
return map[string]any{"record": a.Record, "answer": a.Answer}, nil
}
a, err := asked(groups.OwedAgain, args)
if err != nil {
return nil, err
@@ -151,7 +181,7 @@ func OwedTools(ask func(key string, value []byte) ([]byte, error), performed fun
if str(args, "why") == "" {
return nil, fmt.Errorf("a drop says why")
}
if err := record(fmt.Sprintf("dropped the act %s that %s owes the forge", str(args, "id"), str(args, "of")), str(args, "why")); err != nil {
if err := record(fmt.Sprintf("dropped the act %s that %s owes the forge", str(args, "id"), str(args, "of")), str(args, "why"), "owed-dropped"); err != nil {
return nil, err
}
a, err := asked(groups.OwedDrop, args)
@@ -48,7 +48,7 @@ func performedIsOpenedByItsBinding(t *testing.T) {
o, pub, kept := newOwing(f)
o.waits = binding.Waiting
gate := gitfixture.Seat(t, seat.Seat, "events", "owed is said, a status", "event:owed")[0]
if _, err := o.heard(context.Background(), seat.Seat, gate); err == nil || len(f.calls) != 0 || len(pub.data) != 0 || len(kept) != 0 {
if _, err := o.heard(context.Background(), seat.Seat, gate, nil); err == nil || len(f.calls) != 0 || len(pub.data) != 0 || len(kept) != 0 {
t.Errorf("unbound: %v, called %v, said %d; want the act left unperformed and unsaid", err, f.calls, len(pub.data))
}
answered = true
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"log"
"strconv"
"strings"
"testing"
"time"
@@ -14,6 +15,8 @@ import (
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
"git.novox.be/novox/mesh-sdk/go/busretry"
"mesh-delivery-forge-bridge/internal/gitfixture"
"mesh-delivery-forge-bridge/internal/groups"
)
@@ -38,6 +41,13 @@ func (m memPerformed) Get(_ context.Context, key string) ([]byte, bool, error) {
return v, ok, nil
}
func (m memPerformed) Put(_ context.Context, key string, v []byte) error { m[key] = v; return nil }
func (m memPerformed) Keys(context.Context) ([]string, error) {
var out []string
for k := range m {
out = append(out, k)
}
return out, nil
}
// memActs is a seat's stream owed by pull request subject (`<repository>#<number>`); asked records what was read.
type memActs struct {
@@ -58,13 +68,28 @@ func (m *memActs) act(_ context.Context, of, repository string, number int, id s
}
// seatFake answers each seat verb from answers, by its key; one absent is not answered (an error, as a bound passed).
// The seat git's pull, read before each try of an act (H-A-432), is counted apart in pulls and answers an open pull
// request unless answers names it; away answers the act verbs `away` that many times first (§807).
type seatFake struct {
calls []string
pulls int
away int
answers map[string]json.RawMessage
}
func (f *seatFake) call(_ context.Context, key string, _ any) (json.RawMessage, error) {
if key == "seat:git.pull" {
f.pulls++
if a, ok := f.answers[key]; ok {
return a, nil
}
return json.RawMessage(`{"pull":{"repository":"novox/mesh-sdk","number":178,"branch":"b","head":"` + headA + `","base":"main","state":"open"}}`), nil
}
f.calls = append(f.calls, key)
if f.away > 0 {
f.away--
return json.Marshal(busretry.AwayAnswer("the forge", "401 while the store is replaced"))
}
if a, ok := f.answers[key]; ok {
return a, nil
}
@@ -104,11 +129,16 @@ func TestWhatIsOwedIsPerformedSaidAndKept(t *testing.T) {
{"a seat that says no owed act", "mesh-wants", gate("owed is said, a status"), nil, nil, "", forgemsg.OwedUndecodable, false, ""},
{"the stream forge refusing the outcome", seat.Seat, gate("owed is said, a status"), statusOK, errors.New("no responders"),
"seat:git.status", "", false, "could not be said"},
// Design 47 H2 §807 (H-A-432 (2)): a pull request closed unmerged, read before the try, ends the act not-needed.
{"a status whose pull request closed unmerged", seat.Seat, gate("owed is said, a status"),
map[string]json.RawMessage{"seat:git.status": answer("status", "status answers"),
"seat:git.pull": json.RawMessage(`{"pull":{"repository":"novox/mesh-sdk","number":178,"branch":"b","head":"` + headA + `","base":"main","state":"closed"}}`)},
nil, "", forgemsg.OwedNotNeeded, true, ""},
} {
f := &seatFake{answers: c.answers}
o, pub, kept := newOwing(f)
pub.err = c.pubErr
_, err := o.heard(context.Background(), c.of, c.data)
_, err := o.heard(context.Background(), c.of, c.data, nil)
if c.err != "" {
if err == nil || !strings.Contains(err.Error(), c.err) || len(kept) != 0 {
t.Errorf("%s: %v, kept %d; want an error naming %q and nothing kept", c.name, err, len(kept), c.err)
@@ -138,6 +168,55 @@ func TestWhatIsOwedIsPerformedSaidAndKept(t *testing.T) {
}
}
// Design 47 H2 §807, §775: an act met by the seat git's away is called again at the kept-call pace, its pull request
// read before each try, and performed when the forge answers; one away past owed-away-bound ends could not be
// performed, naming every try.
t.Run("an act through a part away", func(t *testing.T) {
defer busretry.Waits(time.Minute, time.Millisecond, 2*time.Millisecond)()
f := &seatFake{answers: statusOK, away: 2}
o, pub, _ := newOwing(f)
if e, err := o.heard(context.Background(), seat.Seat, gate("owed is said, a status"), nil); err != nil || e.Outcome != forgemsg.OwedPerformed ||
len(f.calls) != 3 || f.pulls != 3 || len(pub.data) != 1 {
t.Errorf("away twice: %+v %v, called %v, pulls %d; want performed at the third try, its pull request read before each", e, err, f.calls, f.pulls)
}
f = &seatFake{answers: statusOK, away: 1 << 30}
o, _, _ = newOwing(f)
o.awayBound = 10 * time.Millisecond
if e, err := o.heard(context.Background(), seat.Seat, gate("owed is said, a status"), nil); err != nil || e.Outcome != forgemsg.OwedCouldNotBePerformed ||
!strings.Contains(e.Words, "called "+strconv.Itoa(len(f.calls))+" times") || len(f.calls) < 2 {
t.Errorf("away past the bound: %+v %v after %d calls; want could not be performed naming every try", e, err, len(f.calls))
}
})
// Design 47 H2 §807 (H-A-432 (1)): bridge_owed_again by record performs again every act of that record that ended
// could not be performed, found in performed by the record kept with it; an act of it that ended otherwise, and one
// of another record, are left.
t.Run("a record's acts performed again", func(t *testing.T) {
f := &seatFake{answers: statusOK}
o, pub, kept := newOwing(f)
status := "status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate"
o.acts = &memActs{held: map[string][][]byte{"mesh-delivery novox/mesh-sdk#178": {gate("owed is said, a status")}}}
at := time.Date(2026, 11, 9, 20, 0, 0, 0, time.UTC)
for id, c := range map[string]struct{ record, outcome string }{
status: {"main.212", forgemsg.OwedCouldNotBePerformed}, "done": {"main.212", forgemsg.OwedPerformed},
"another": {"main.213", forgemsg.OwedCouldNotBePerformed}} {
kept[performedKey(seat.Seat, id)], _ = json.Marshal(Performed{Ended: forgemsg.OwedEnded{V: 1, Of: seat.Seat, ID: id,
Outcome: c.outcome, Words: "x", At: at}, Repository: "novox/mesh-sdk", Number: 178, Record: c.record})
}
a := o.answer(context.Background(), groups.OwedAsk{Kind: groups.OwedAgain, Record: "main.212", Why: "the forge was away"}, nil)
if !a.Done() || !strings.Contains(a.Answer, "1 acts of the record main.212") || !strings.Contains(a.Answer, status+": performed") ||
len(f.calls) != 1 || f.pulls != 1 || len(pub.data) != 1 {
t.Errorf("again by record: %+v, called %v, pulls %d, said %d; want the one act that could not be performed, performed", a, f.calls, f.pulls, len(pub.data))
}
var p Performed
if err := json.Unmarshal(kept[performedKey(seat.Seat, status)], &p); err != nil || p.Ended.Outcome != forgemsg.OwedPerformed || p.Record != "main.212" {
t.Errorf("performed after again by record: %+v %v", p, err)
}
if a := o.answer(context.Background(), groups.OwedAsk{Kind: groups.OwedAgain, Record: "main.212"}, nil); !strings.Contains(a.Answer, "holds no act") {
t.Errorf("again by record, nothing left: %+v", a)
}
})
t.Run("heard from a seat's stream owed", func(t *testing.T) {
f := &seatFake{answers: statusOK}
o, pub, _ := newOwing(f)
@@ -168,7 +247,7 @@ func TestWhatIsOwedIsPerformedSaidAndKept(t *testing.T) {
acts := &memActs{held: map[string][][]byte{"mesh-delivery novox/mesh-sdk#178": {[]byte(`{`), gate("owed is said, a status")}}}
o.acts = acts
status := "status.novox/mesh-sdk#178.aaaaaaaaaaaa.mesh/merge-gate"
if _, err := o.heard(context.Background(), seat.Seat, gate("owed is said, a status")); err != nil {
if _, err := o.heard(context.Background(), seat.Seat, gate("owed is said, a status"), nil); err != nil {
t.Fatal(err)
}
backlog := func(context.Context) []groups.Backlog { return []groups.Backlog{{Stream: seat.StreamOwed, Waiting: 2}} }
@@ -22,6 +22,8 @@ import (
git "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/keys"
"git.novox.be/novox/mesh-sdk/go/process"
@@ -111,6 +113,8 @@ accounts {
"mesh.seat.git.tool.note"
"mesh.seat.git.call.tags.n1~mesh-delivery-forge-bridge"
"mesh.seat.git.tool.tags"
"mesh.seat.git.call.pull.n1~mesh-delivery-forge-bridge"
"mesh.seat.git.tool.pull"
"mesh.seat.mesh-hand-acts.call.hand-act.n1~mesh-delivery-forge-bridge"
"mesh.seat.mesh-hand-acts.tool.hand-act"
"mesh.stream.mesh-delivery-forge-bridge.event.forge.>"
@@ -178,6 +182,11 @@ type bed struct {
// answerOf is a verb's answer in the reply envelope of mesh-sdk go/process/call.go ({result, error, node}).
func answerOf(answer string) []byte { return []byte(`{"result":` + answer + `,"node":"n0"}`) }
// pullAnswer is the seat git's pull answering one pull request in state (open, merged or closed).
func pullAnswer(repository string, number int, state string) string {
return fmt.Sprintf(`{"pull":{"repository":%q,"number":%d,"branch":"b","head":"%s","base":"main","state":%q}}`, repository, number, strings.Repeat("a", 40), state)
}
// boundPerformed is the bus name the stand-in seat mesh-broker's show answers for the state performed.
const boundPerformed = "mod_mesh-delivery-forge-bridge_performed_b1"
@@ -248,6 +257,7 @@ func startBed(t *testing.T, head string) *bed {
"mesh-delivery.source": `{"branches":["main"]}`,
"mesh-broker.show": `{"state":"created","binding":{"local":"performed","storage":"key-value","template":"state","bucket":"` + boundPerformed + `"}}`,
"git.branch " + catalog: `{"repository":"` + catalog + `","branch":"main","head":"` + head + `","protected":true}`,
"git.pull": pullAnswer("novox/mesh-sdk", 178, "open"),
}
for _, verb := range []string{"status", "comment", "view", "note"} {
answers["git."+verb] = string(gitfixture.Given(t, verb+" answers", "verb:"+verb+".answer"))
@@ -488,6 +498,10 @@ func refusedRead(t *testing.T, b *bed, bucket string) {
// Acceptance 49: the forge bridge sets the group on each member's merged message and says the group's end once, after the
// last member's, from the seat mesh-delivery's verb groups; its account reads no state of the gate's.
func TestBridgePerformsWhatIsOwedOnce(t *testing.T) {
// The bridge's kept-call pace, read at its start (§775), in milliseconds here so the forge's minute away is short.
t.Cleanup(busretry.Waits(busretry.Bound, busretry.FirstWait, busretry.MostWait))
t.Setenv(stdio.SettingWord(busretry.PaceFirstSetting), "10ms")
t.Setenv(stdio.SettingWord(busretry.PaceMaxSetting), "40ms")
b := startBed(t, strings.Repeat("1", 40))
ch := heard(t, b)
ended := func() forgemsg.OwedEnded {
@@ -632,6 +646,47 @@ func TestBridgePerformsWhatIsOwedOnce(t *testing.T) {
}
refusedRead(t, b, "mesh-delivery-gate_owed")
// Design 47 H2 §807 (F1, the bridge's whole test): with the forge away (the seat git answering away to every call), a
// note line owed in that time is performed once the forge answers again, with no hand act; an act whose pull request
// closed unmerged meanwhile ends not-needed, never performed (H-A-432 (2), (3)).
away, _ := json.Marshal(busretry.AwayAnswer("the forge", "401 while the store is replaced"))
for _, verb := range []string{"git.pull", "git.note", "git.comment"} {
b.answer(verb, string(away))
}
handActs, pulls, comments := callsOf(b, "mesh-hand-acts.hand-act"), callsOf(b, "git.pull"), callsOf(b, "git.comment")
note := map[string]any{"id": "note.novox/mesh-sdk#178.aaaaaaaaaaaa.away", "act": "note", "repository": "novox/mesh-sdk",
"number": 178, "head": strings.Repeat("a", 40), "line": "built while the forge was away"}
comment := map[string]any{"id": "comment.novox/mesh-catalog#9.aaaaaaaaaaaa.away", "act": "comment", "repository": catalog,
"number": 9, "head": strings.Repeat("a", 40), "text": "closed meanwhile"}
for _, act := range []map[string]any{note, comment} {
data, _ := json.Marshal(act)
if _, err := b.js.Publish(b.ctx, seat.SubjectOwed(keys.EscapeName(act["repository"].(string)), fmt.Sprint(act["number"])), data); err != nil {
t.Fatal(err)
}
}
calledTimes(t, b, "git.pull", pulls+3) // tried, met away, and tried again at the pace
b.answer("git.pull "+"novox/mesh-sdk", pullAnswer("novox/mesh-sdk", 178, "merged"))
b.answer("git.pull "+catalog, pullAnswer(catalog, 9, "closed"))
b.answer("git.note", string(gitfixture.Given(t, "note answers", "verb:note.answer")))
// Read until both acts ended (bridge_owed_again's outcome above is on the stream before them).
outcomes := map[string]forgemsg.OwedEnded{}
for i := 0; i < 4 && (outcomes[note["id"].(string)].ID == "" || outcomes[comment["id"].(string)].ID == ""); i++ {
e := ended()
outcomes[e.ID] = e
}
if e := outcomes[note["id"].(string)]; e.Outcome != forgemsg.OwedPerformed {
t.Errorf("the note owed while the forge was away: %+v, want performed once it answers", e)
}
if e := outcomes[comment["id"].(string)]; e.Outcome != forgemsg.OwedNotNeeded || !strings.Contains(e.Words, "closed unmerged") {
t.Errorf("the comment on a pull request closed meanwhile: %+v, want not-needed naming it", e)
}
if n := callsOf(b, "git.comment"); n != comments {
t.Errorf("the comment on a pull request closed meanwhile was asked of the forge %d times, want never", n-comments)
}
if n := callsOf(b, "mesh-hand-acts.hand-act"); n != handActs {
t.Errorf("%d hand acts while the forge was away, want none", n-handActs)
}
// Design 47 H2 §812 (F2, the bridge's whole test): a write that takes performed past prune-mark (70 % of its cap)
// prunes it, oldest acts first, down to prune-target (50 %); a key kept under _keep/ survives the prune. performed is
// filled while the bridge is stopped, so the bridge's bind at its start reads the fill once (H-A-380 (1)).
@@ -17,6 +17,7 @@ import (
"time"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/process"
"git.novox.be/novox/mesh-sdk/go/views"
@@ -58,10 +59,18 @@ type delivered interface {
Data() []byte
Headers() nats.Header
Ack() error
InProgress() error
Term() error
NakWithDelay(delay time.Duration) error
}
// owedAwayBoundSetting is the setting owed-away-bound: how long an owed act is called again through a part away before
// it ends could not be performed (design 47 H2 §807), 60 minutes when none is composed.
const (
owedAwayBoundSetting = "owed-away-bound"
owedAwayBoundDefault = 60 * time.Minute
)
// retryDelay is how long the server waits before it delivers again an event the forge could not be asked about (the
// server's redelivery is the only clock; issue 1236/AC3).
const retryDelay = 10 * time.Second
@@ -107,6 +116,16 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
if w := binding.Waiting(); w != "" {
logger.Printf("the bridge %s: nothing owed to the forge is performed until it is bound", w)
}
// Each owed act is a kept call (design 47 H2 §807, §775): at the module's kept-call pace, until owed-away-bound. A
// setting that is no duration is said, and its default holds.
if err := busretry.ReadPace(stdio.SettingDuration); err != nil {
logger.Printf("the kept-call pace keeps %s doubling to %s: %v", busretry.KeptPace.First, busretry.KeptPace.Max, err)
}
awayBound, err := stdio.SettingDuration(owedAwayBoundSetting, owedAwayBoundDefault)
if err != nil {
logger.Printf("owed-away-bound keeps its default %s: %v", owedAwayBoundDefault, err)
awayBound = owedAwayBoundDefault
}
// performed is pruned toward its cap at the bridge's own writes (design 47 H2 §812): past prune-mark the oldest acts
// go down to prune-target, in one journal line, a key kept under _keep/ staying. A setting that is no percentage is
// said, and the defaults hold.
@@ -117,7 +136,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
}
performedKV := &boundBucket{binding: binding, local: performedLocal, js: js, prune: &prune}
// What the gate owes the forge, performed through the seat git (design 47 *What the gate owes the forge*).
owe := &owing{call: call, pub: js, performed: kvPerformed{performedKV}, acts: streamActs{js: js}, waits: binding.Waiting, now: time.Now, logger: logger}
owe := &owing{call: call, pub: js, performed: kvPerformed{performedKV}, acts: streamActs{js: js}, waits: binding.Waiting,
awayBound: awayBound, now: time.Now, logger: logger}
keptCall := keptCallOf(ctx, call)
reader := &views.ProcessReader{Module: forgeBridgeModule(), Call: keptCall, Logf: logger.Printf, Hub: hub}
src := sourcebranches.New(sourcebranches.Call(keptCall))
@@ -191,7 +211,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
// What the gate says it owes, on its seat's stream owed through this module's durable there (made from its consumes).
// A stream not there yet is said, and the bridge goes on: its other work does not wait on the gate.
if cc, err := cred.HearSeatEvents(ctx, js, seat.StreamOwed, func(m jetstream.Msg) {
hctx, cancel := context.WithTimeout(ctx, handleDeadline)
hctx, cancel := context.WithTimeout(ctx, awayBound+handleDeadline) // an act waits out a part away until owed-away-bound
defer cancel()
owe.hear(hctx, seat.Seat, m)
}, logger.Printf); err != nil {
@@ -205,7 +225,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
backlog := owedBacklog(js, cred, time.Now)
go func() {
err := watch(ctx, kv, func(key string, rev uint64, value []byte) {
hctx, cancel := context.WithTimeout(ctx, handleDeadline)
hctx, cancel := context.WithTimeout(ctx, awayBound+handleDeadline) // each act performed again is a kept call
defer cancel()
owe.asked(hctx, kv, key, rev, value, backlog)
})
@@ -30,6 +30,7 @@ func (f *fakeMsg) Subject() string { return f.subject }
func (f *fakeMsg) Data() []byte { return f.data }
func (f *fakeMsg) Headers() nats.Header { return nats.Header{} }
func (f *fakeMsg) Ack() error { f.acked++; return nil }
func (f *fakeMsg) InProgress() error { return nil }
func (f *fakeMsg) NakWithDelay(d time.Duration) error { f.nak = append(f.nak, d); return nil }
func (f *fakeMsg) Term() error { f.termd++; return nil }
@@ -6,6 +6,8 @@ import (
"errors"
"fmt"
"log"
"sort"
"strings"
"time"
"github.com/nats-io/nats.go/jetstream"
@@ -14,6 +16,7 @@ import (
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-forge-bridge/forgemsg"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/process"
"mesh-delivery-forge-bridge/internal/bridge"
@@ -30,13 +33,16 @@ func performedKey(of, id string) string { return groups.PerformedKey(of, id) }
// Performed is one value of the state performed.
type Performed = groups.Performed
// performedStore is the state performed as the owing reads and writes it.
// performedStore is the state performed as the owing reads and writes it; Keys lists it for bridge_owed_again by record.
type performedStore interface {
Get(ctx context.Context, key string) (value []byte, found bool, err error)
Put(ctx context.Context, key string, value []byte) error
Keys(ctx context.Context) ([]string, error)
}
type kvPerformed struct{ kv keptStore }
type kvPerformed struct{ kv *boundBucket }
func (s kvPerformed) Keys(ctx context.Context) ([]string, error) { return s.kv.Keys(ctx) }
func (s kvPerformed) Get(ctx context.Context, key string) ([]byte, bool, error) {
e, err := s.kv.Get(ctx, key)
@@ -64,9 +70,12 @@ type owing struct {
// acts reads an act again from the stream owed of the seat that said it (H-A-181), for bridge_owed_again.
acts actReader
// waits, when set, says why the state performed cannot be used yet (its binding, design 47 G §577); empty when it can.
waits func() string
now func() time.Time
logger *log.Logger
waits func() string
// awayBound is owed-away-bound: how long an act is called again through transport faults and the seat git's `away`
// before it ends could not be performed, naming its tries (design 47 H2 §807, §775); zero is busretry.Bound.
awayBound time.Duration
now func() time.Time
logger *log.Logger
}
// readerOf is the reading of the seat of's owed event into the seat git's verb.
@@ -80,15 +89,17 @@ func readerOf(of string) (func([]byte) (bridge.OwedCall, error), error) {
// heard performs one owed event the seat of said. Its error is only an outcome that could not be said on the stream
// forge: the event is then heard again, and the act, safe to repeat, performed again.
func (o *owing) heard(ctx context.Context, of string, data []byte) (forgemsg.OwedEnded, error) {
// tried, when set, is told before each try of the act's kept call (the message's progress, so the bus does not hand it
// again while the act waits out a part away).
func (o *owing) heard(ctx context.Context, of string, data []byte, tried func()) (forgemsg.OwedEnded, error) {
read, err := readerOf(of)
if err != nil {
return o.end(ctx, forgemsg.OwedEnded{Of: of, Outcome: forgemsg.OwedUndecodable, Words: err.Error()}, "", 0)
return o.end(ctx, forgemsg.OwedEnded{Of: of, Outcome: forgemsg.OwedUndecodable, Words: err.Error()}, bridge.OwedCall{})
}
c, err := read(data)
if err != nil {
return o.end(ctx, forgemsg.OwedEnded{Of: of, ID: c.ID,
Outcome: forgemsg.OwedUndecodable, Words: err.Error()}, c.Repository, c.Number)
Outcome: forgemsg.OwedUndecodable, Words: err.Error()}, c)
}
if w := o.waiting(); w != "" {
return forgemsg.OwedEnded{Of: c.Of, ID: c.ID}, fmt.Errorf("the bridge %s", w)
@@ -97,13 +108,13 @@ func (o *owing) heard(ctx context.Context, of string, data []byte) (forgemsg.Owe
// said twice, or said again while its outcome was on its way: performed once, the outcome said once
return forgemsg.OwedEnded{Of: c.Of, ID: c.ID}, nil
}
return o.perform(ctx, c)
return o.perform(ctx, c, tried)
}
// hear is one message of a seat's stream owed: performed and acknowledged, or, when its outcome could not be said,
// left to come again (design 47: the bridge stopped between an act and its owed.ended performs it again).
func (o *owing) hear(ctx context.Context, of string, m delivered) {
if _, err := o.heard(ctx, of, m.Data()); err != nil {
if _, err := o.heard(ctx, of, m.Data(), func() { _ = m.InProgress() }); err != nil {
o.logger.Printf("%s, so the act is heard again: %v", m.Subject(), err)
_ = m.NakWithDelay(retryDelay)
return
@@ -119,21 +130,77 @@ func (o *owing) waiting() string {
return o.waits()
}
// perform calls the seat git's verb of one act and says what it came to.
func (o *owing) perform(ctx context.Context, c bridge.OwedCall) (forgemsg.OwedEnded, error) {
answer, callErr := o.call(ctx, "seat:"+git.Seat+"."+c.Verb, c.Input)
outcome, words := bridge.Outcome(answer, callErr)
// perform calls the seat git's verb of one act as a kept call (design 47 H2 §807, §775) and says what it came to: through
// transport faults and the seat's `away` it is called again at the kept-call pace until owed-away-bound, then ends could
// not be performed naming every try. Before each try its precondition is read again (H-A-432 (2), (3)): an act whose
// pull request closed unmerged ends not-needed, never performed.
func (o *owing) perform(ctx context.Context, c bridge.OwedCall, tried func()) (forgemsg.OwedEnded, error) {
type try struct {
answer json.RawMessage
closed string
}
t, callErr := busretry.DoPaced(busretry.Kept{Seat: git.Seat, Verb: c.Verb, Ask: c.ID, Bound: o.awayBound, Logf: o.logger.Printf}, func() (try, error) {
if tried != nil {
tried()
}
closed, err := o.closed(ctx, c)
if err != nil || closed != "" {
return try{closed: closed}, err
}
answer, err := o.call(ctx, "seat:"+git.Seat+"."+c.Verb, c.Input)
if err == nil {
if away := busretry.AwayIn(answer); away != nil {
return try{answer: answer}, away
}
}
return try{answer: answer}, err
})
outcome, words := bridge.Outcome(t.answer, callErr)
if callErr == nil && t.closed != "" {
outcome, words = forgemsg.OwedNotNeeded, t.closed
}
if outcome != forgemsg.OwedPerformed {
o.logger.Printf("the owed %s %s of %s#%d (said by %s) is %s: %s", c.Act, c.ID, c.Repository, c.Number, c.Of, outcome, words)
}
return o.end(ctx, forgemsg.OwedEnded{Of: c.Of, ID: c.ID,
Outcome: outcome, Words: words}, c.Repository, c.Number)
Outcome: outcome, Words: words}, c)
}
// closed is why the act is not needed: its pull request closed unmerged, as the seat git's pull answers it now (open
// and merged both need it, since the gate owes notes and views on merged pull requests; H-A-432 (2)); empty when it is
// needed. An act that names no pull request (a status said on `.0`) has none to read. A pull the forge does not answer
// is the try's transport fault, called again; one it refuses is the act's error, never performed unread.
func (o *owing) closed(ctx context.Context, c bridge.OwedCall) (string, error) {
if c.Number <= 0 {
return "", nil
}
raw, err := o.call(ctx, "seat:"+git.Seat+"."+git.VerbPull, git.PullInput{Repository: c.Repository, Number: int64(c.Number)})
if err == nil {
if away := busretry.AwayIn(raw); away != nil {
err = away
}
}
if err != nil {
return "", fmt.Errorf("the pull request %s#%d could not be read before the act: %w", c.Repository, c.Number, err)
}
var a git.PullAnswer
switch {
case json.Unmarshal(raw, &a) != nil:
return "", fmt.Errorf("the seat git's pull of %s#%d answered what its contract cannot read: %s", c.Repository, c.Number, raw)
case a.Error != "":
return "", fmt.Errorf("the pull request %s#%d could not be read before the act: %s", c.Repository, c.Number, a.Error)
case a.Pull == nil:
return "", fmt.Errorf("the seat git's pull of %s#%d answered no pull request", c.Repository, c.Number)
case a.Pull.State == git.PullStateClosed:
return fmt.Sprintf("the pull request %s#%d closed unmerged, so the %s is not needed", c.Repository, c.Number, c.Act), nil
}
return "", nil
}
// end says an act's outcome as owed.ended on the stream forge, then keeps it in performed with the pull request the act
// names (repository and number). An outcome not kept is logged: the act may be performed again, which changes nothing at
// the forge.
func (o *owing) end(ctx context.Context, e forgemsg.OwedEnded, repository string, number int) (forgemsg.OwedEnded, error) {
// names (repository and number) and its delivery record. An outcome not kept is logged: the act may be performed again,
// which changes nothing at the forge.
func (o *owing) end(ctx context.Context, e forgemsg.OwedEnded, c bridge.OwedCall) (forgemsg.OwedEnded, error) {
e.At = o.now().UTC()
data, err := forgemsg.EncodeOwedEnded(e)
if err != nil {
@@ -145,7 +212,7 @@ func (o *owing) end(ctx context.Context, e forgemsg.OwedEnded, repository string
if e.ID == "" {
return e, nil // an undecodable act with no id is said, and has no key to keep
}
v, err := json.Marshal(Performed{Ended: e, Repository: repository, Number: number})
v, err := json.Marshal(Performed{Ended: e, Repository: c.Repository, Number: c.Number, Record: c.Record})
if err == nil {
err = o.performed.Put(ctx, performedKey(e.Of, e.ID), v)
}
@@ -179,14 +246,19 @@ func (o *owing) kept(ctx context.Context, of, id string) (Performed, error) {
return p, nil
}
// answer answers one owed ask: an act performed again now, whatever performed holds of it; an act dropped, said as
// owed.ended with the outcome dropped and the ask's why (the tool wrote the hand-act log first); or the consumers' backlog.
// answer answers one owed ask: an act performed again now, whatever performed holds of it; every act of one delivery
// record that ended could not be performed, performed again (design 47 H2 §807, H-A-432 (1)); an act dropped, said as
// owed.ended with the outcome dropped and the ask's why (the tool wrote the hand-act log first); or the consumers'
// backlog. Each act performed again reads its precondition again before it acts (perform).
func (o *owing) answer(ctx context.Context, a groups.OwedAsk, backlog func(context.Context) []groups.Backlog) groups.OwedAsk {
a.Answered = o.now().UTC()
switch a.Kind {
case groups.OwedBacklog:
switch {
case a.Kind == groups.OwedBacklog:
a.Backlog, a.Answer = backlog(ctx), "the backlog of each seat's stream owed"
return a
case a.Kind == groups.OwedAgain && a.Record != "":
a.Answer = o.againRecord(ctx, a.Record)
return a
}
p, err := o.kept(ctx, a.Of, a.ID)
if err != nil {
@@ -195,15 +267,9 @@ func (o *owing) answer(ctx context.Context, a groups.OwedAsk, backlog func(conte
}
var e forgemsg.OwedEnded
if a.Kind == groups.OwedDrop {
e, err = o.end(ctx, forgemsg.OwedEnded{Of: a.Of, ID: a.ID, Outcome: forgemsg.OwedDropped, Words: a.Why + " (dropped by " + a.By + ")"}, p.Repository, p.Number)
} else if read, rerr := readerOf(a.Of); rerr != nil {
err = rerr
} else if data, rerr := o.actOf(ctx, a.Of, p, a.ID); rerr != nil {
err = rerr
} else if c, rerr := read(data); rerr != nil {
e, err = o.end(ctx, forgemsg.OwedEnded{Of: a.Of, ID: a.ID, Outcome: forgemsg.OwedUndecodable, Words: rerr.Error()}, p.Repository, p.Number)
e, err = o.end(ctx, forgemsg.OwedEnded{Of: a.Of, ID: a.ID, Outcome: forgemsg.OwedDropped, Words: a.Why + " (dropped by " + a.By + ")"}, callOf(p))
} else {
e, err = o.perform(ctx, c)
e, err = o.again(ctx, a.Of, a.ID, p)
}
if err != nil {
a.Answer = err.Error()
@@ -216,6 +282,68 @@ func (o *owing) answer(ctx context.Context, a groups.OwedAsk, backlog func(conte
return a
}
// callOf is what performed holds of an act as the call an outcome is kept with: its pull request and its record.
func callOf(p Performed) bridge.OwedCall {
return bridge.OwedCall{Repository: p.Repository, Number: p.Number, Record: p.Record}
}
// again performs one act of of again, read from its seat's stream owed on the pull request p names.
func (o *owing) again(ctx context.Context, of, id string, p Performed) (forgemsg.OwedEnded, error) {
read, err := readerOf(of)
if err != nil {
return forgemsg.OwedEnded{}, err
}
data, err := o.actOf(ctx, of, p, id)
if err != nil {
return forgemsg.OwedEnded{}, err
}
c, err := read(data)
if err != nil {
return o.end(ctx, forgemsg.OwedEnded{Of: of, ID: id, Outcome: forgemsg.OwedUndecodable, Words: err.Error()}, callOf(p))
}
if c.Record == "" {
c.Record = p.Record // the record kept with the act stays with it
}
return o.perform(ctx, c, nil)
}
// againRecord performs again every act of the delivery record (its source revision) that performed holds as ended could
// not be performed, oldest first, and answers what each came to; a record none of whose acts so ended is said.
func (o *owing) againRecord(ctx context.Context, record string) string {
keys, err := o.performed.Keys(ctx)
if err != nil {
return "performed cannot be listed, so no act of the record " + record + " is performed again: " + err.Error()
}
var acts []Performed
for _, k := range keys {
v, found, err := o.performed.Get(ctx, k)
var p Performed
if err != nil || !found || json.Unmarshal(v, &p) != nil {
continue
}
if p.Record == record && p.Ended.Outcome == forgemsg.OwedCouldNotBePerformed {
acts = append(acts, p)
}
}
if len(acts) == 0 {
return "the record " + record + " holds no act that ended " + forgemsg.OwedCouldNotBePerformed
}
sort.Slice(acts, func(i, j int) bool { return acts[i].Ended.At.Before(acts[j].Ended.At) })
lines := make([]string, 0, len(acts))
for _, p := range acts {
e, err := o.again(ctx, p.Ended.Of, p.Ended.ID, p)
switch {
case err != nil:
lines = append(lines, p.Ended.ID+": "+err.Error())
case e.Words != "":
lines = append(lines, p.Ended.ID+": "+e.Outcome+": "+e.Words)
default:
lines = append(lines, p.Ended.ID+": "+e.Outcome)
}
}
return fmt.Sprintf("%d acts of the record %s performed again: %s", len(acts), record, strings.Join(lines, "; "))
}
// asked answers one value of the state owed-asks not yet answered, written back by compare-and-set at its revision; an
// answered one (this bridge's own write) is left.
func (o *owing) asked(ctx context.Context, kv jetstream.KeyValue, key string, rev uint64, value []byte, backlog func(context.Context) []groups.Backlog) {
@@ -96,6 +96,9 @@ func TestForge(t *testing.T) {
{"no id", func(e *OwedEnded) { e.ID = "" }, "no id"},
{"a refusal with no words", func(e *OwedEnded) { e.Outcome = OwedRefused }, "no words"},
{"dropped with no reason", func(e *OwedEnded) { e.Outcome = OwedDropped }, "no words"},
// Design 47 H2 §807 (H-A-432 (2)): an act whose pull request closed unmerged is said not-needed, naming it.
{"not needed, naming why", func(e *OwedEnded) { e.Outcome, e.Words = OwedNotNeeded, "novox/x#9 closed unmerged" }, ""},
{"not needed with no words", func(e *OwedEnded) { e.Outcome = OwedNotNeeded }, "no words"},
{"no time", func(e *OwedEnded) { e.At = time.Time{} }, "no time"},
{"undecodable with no id is said", func(e *OwedEnded) { e.ID, e.Outcome, e.Words = "", OwedUndecodable, "not json" }, ""},
} {
@@ -13,18 +13,20 @@ import (
const OwedEndedEvent = "owed.ended"
// The outcomes of an owed act (design 47 G §164, §168): performed, refused (the forge's own words), could not be
// performed (the forge did not answer within the call's bound, with the error), undecodable (an act the bridge cannot
// read, with why) and, from the tool `bridge_owed_drop`, dropped.
// performed (the forge did not answer within the bridge's owed-away-bound, naming every try, or answered an error),
// undecodable (an act the bridge cannot read, with why), from the tool `bridge_owed_drop`, dropped, and not-needed (the
// act's pull request closed unmerged, read before a try, so it is not performed; design 47 H2 §807, H-A-432 (2)).
const (
OwedPerformed = "performed"
OwedRefused = "refused"
OwedCouldNotBePerformed = "could not be performed"
OwedUndecodable = "undecodable"
OwedDropped = "dropped"
OwedNotNeeded = "not-needed"
)
// OwedOutcomes are the outcomes an owed.ended says, one of them.
var OwedOutcomes = []string{OwedPerformed, OwedRefused, OwedCouldNotBePerformed, OwedUndecodable, OwedDropped}
var OwedOutcomes = []string{OwedPerformed, OwedRefused, OwedCouldNotBePerformed, OwedUndecodable, OwedDropped, OwedNotNeeded}
// OwedEnded is an owed act's outcome (design 47 G §164): the act's id and one outcome, with the words of any outcome
// but performed. Of is the seat that said the act (mesh-delivery for the gate's), so it hears its own ids (§164). An act the bridge cannot decode may name no id.
@@ -19,8 +19,11 @@ type OwedCall struct {
Act string
Repository string
Number int
Verb string
Input any
// Record is the delivery record the act is for, its source revision (design 47 H2 §807, H-A-432 (1)); empty when the
// owed named none.
Record string
Verb string
Input any
}
// ErrUndecodable is an owed event the bridge cannot read: it is said as owed.ended `undecodable`, never only logged.
@@ -36,7 +39,7 @@ func GateOwed(data []byte) (OwedCall, error) {
if err := json.Unmarshal(data, &o); err != nil {
return OwedCall{}, undecodable("the gate's owed is not json: %v", err)
}
c := OwedCall{Of: seat.Seat, ID: o.ID, Act: o.Act, Repository: o.Repository, Number: int(o.Number)}
c := OwedCall{Of: seat.Seat, ID: o.ID, Act: o.Act, Repository: o.Repository, Number: int(o.Number), Record: o.Record}
if err := c.common(o.Head); err != nil {
return c, err
}
@@ -62,6 +62,13 @@ func TestAnOwedEventIsTheSeatGitsVerbAndItsAnswerOneOutcome(t *testing.T) {
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")
@@ -46,9 +46,12 @@ type Backlog struct {
// and once the bridge answered, when, what it came to (the outcome said as owed.ended) and its words; a backlog ask is
// answered with the consumers' backlog.
type OwedAsk struct {
Kind string `json:"kind"`
Of string `json:"of,omitempty"`
ID string `json:"id,omitempty"`
Kind string `json:"kind"`
Of string `json:"of,omitempty"`
ID string `json:"id,omitempty"`
// Record, for again instead of an act, is a delivery record's source revision: every act of it that ended could not
// be performed is performed again (design 47 H2 §807, H-A-432 (1)).
Record string `json:"record,omitempty"`
Why string `json:"why,omitempty"`
By string `json:"by,omitempty"`
At time.Time `json:"at"`
@@ -84,6 +87,20 @@ func NewOwedAsk(kind, of, id, why, by string, at time.Time) (string, []byte, err
return key, v, err
}
// NewOwedRecordAsk is the key and value of an ask to perform again every act of one delivery record (its source revision,
// <branch>.<source>) that ended could not be performed: under again.record and the record (unpadded base64url). It says why.
func NewOwedRecordAsk(record, why, by string, at time.Time) (string, []byte, error) {
a := OwedAsk{Kind: OwedAgain, Record: strings.TrimSpace(record), Why: strings.TrimSpace(why), By: by, At: at.UTC()}
if a.Record == "" {
return "", nil, fmt.Errorf("a record is named by its source revision, <branch>.<source>")
}
if a.Why == "" {
return "", nil, fmt.Errorf("performing a record's acts again says why")
}
v, err := json.Marshal(a)
return OwedAgain + ".record." + base64.RawURLEncoding.EncodeToString([]byte(a.Record)), v, err
}
// DecodeOwedAsk reads a value of owed-asks.
func DecodeOwedAsk(data []byte) (OwedAsk, error) {
var a OwedAsk
@@ -16,11 +16,14 @@ func PerformedKey(of, id string) string {
return of + "." + base64.RawURLEncoding.EncodeToString([]byte(id))
}
// Performed is one value of the state performed (§163, H-A-182): the outcome said as owed.ended, with when, and the
// Performed is one value of the state performed (§163, H-A-182): the outcome said as owed.ended, with when, the
// repository and number of the pull request the act names, so bridge_owed reads one pull request's acts and
// bridge_owed_again finds the act on its pull request's subject of the stream owed (H-A-181).
// bridge_owed_again finds the act on its pull request's subject of the stream owed (H-A-181), and the delivery record
// the act is for (its source revision, <branch>.<source>), so bridge_owed_again by record finds the record's acts in
// this state (design 47 H2 §807, H-A-432 (1)); absent for an act whose owed named none.
type Performed struct {
Ended forgemsg.OwedEnded `json:"ended"`
Repository string `json:"repository,omitempty"`
Number int `json:"number,omitempty"`
Record string `json:"record,omitempty"`
}
@@ -106,6 +106,7 @@ func sorted(s []string) []string {
}
func TestManifestDeclarations(t *testing.T) { // 1235/AC1
t.Run("the process", manifestProcess) // design 47 H2 §819: one top-level test fewer
m, top := load(t)
if m.Module != "mesh-delivery-forge-bridge" {
t.Errorf("module = %q", m.Module)
@@ -127,8 +128,9 @@ func TestManifestDeclarations(t *testing.T) { // 1235/AC1
if len(m.Reads) != 0 {
t.Errorf("reads = %v, want none", m.Reads)
}
// No pull, tree, file, open pull requests, merge or group is asked (design 47 H §739, §764).
if want := []string{"seat:git.branch", "seat:git.comment", "seat:git.note", "seat:git.status", "seat:git.tags", "seat:git.view",
// No tree, file, open pull requests, merge or group is asked (design 47 H §739, §764); one pull request's state is read
// before each try of an act (design 47 H2 §807, H-A-432 (2)).
if want := []string{"seat:git.branch", "seat:git.comment", "seat:git.note", "seat:git.pull", "seat:git.status", "seat:git.tags", "seat:git.view",
"seat:mesh-broker.show", "seat:mesh-catalog.registrations", "seat:mesh-delivery.source", "seat:mesh-hand-acts.hand-act"}; !reflect.DeepEqual(sorted(m.Invokes), want) {
t.Errorf("invokes = %v, want %v", m.Invokes, want)
}
@@ -155,8 +157,10 @@ func TestManifestDeclarations(t *testing.T) { // 1235/AC1
t.Errorf("tools = %v, want %v", m.Tools, want)
}
// performed's prune starts past prune-mark and ends at prune-target, settings read at run time (§812).
for key, def := range map[string]float64{"prune-mark": 70, "prune-target": 50} {
if c := m.Config[key]; c.Default != any(def) || !c.Runtime {
// Each owed act is a kept call at the module's pace until owed-away-bound (§807, §775).
for key, def := range map[string]any{"prune-mark": float64(70), "prune-target": float64(50), "owed-away-bound": "60m",
"kept-call-pace-first": "1s", "kept-call-pace-max": "30s"} {
if c := m.Config[key]; c.Default != def || !c.Runtime {
t.Errorf("config %s = %+v, want a runtime setting defaulting to %v", key, c, def)
}
}
@@ -183,7 +187,7 @@ func TestManifestDeclarations(t *testing.T) { // 1235/AC1
}
}
func TestManifestProcess(t *testing.T) { // 1235/AC1
func manifestProcess(t *testing.T) { // 1235/AC1
m, _ := load(t)
var procs []map[string]any
for _, r := range m.Resources {
@@ -30,6 +30,7 @@
"seat:git.status",
"seat:git.comment",
"seat:git.view",
"seat:git.pull",
"seat:git.note",
"seat:mesh-hand-acts.hand-act",
"seat:git.tags",
@@ -47,6 +48,27 @@
}
],
"config": {
"owed-away-bound": {
"type": "string",
"description": "How long the bridge calls an owed act again through transport faults and the seat git's away before it says owed.ended could not be performed, naming its tries, a Go duration (design 47 H2 §807).",
"trusted": false,
"runtime": true,
"default": "60m"
},
"kept-call-pace-first": {
"type": "string",
"description": "the first wait before a kept call met by a transport fault is made again, doubled per call up to kept-call-pace-max, a Go duration (design 47 H2 §775).",
"trusted": false,
"runtime": true,
"default": "1s"
},
"kept-call-pace-max": {
"type": "string",
"description": "the most a kept call's wait between calls grows to, a Go duration (design 47 H2 §775).",
"trusted": false,
"runtime": true,
"default": "30s"
},
"prune-mark": {
"type": "number",
"description": "The fill of the bridge's state performed, in percent of its cap, past which the bridge prunes it at its own write, oldest acts first (design 47 H2 §812): below the bus module's raise mark of 75 %.",