G18 unanswered-said-at-start: the gate says again every act owed with no outcome at its start and when it hears the forge bridge's module running
Builds: design 47 G §165, H-A-712 (3) (hq 7c5c3860), H-A-717 (DMC-15, DQ-51) (hq eed55e62)
This commit is contained in:
@@ -117,6 +117,10 @@ func run(h *Holder, l *listening) {
|
||||
logf("[mesh-delivery] the record indexes are not kept yet (%v); asking again in %s", err, wait)
|
||||
time.Sleep(wait)
|
||||
}
|
||||
// The acts owed to the forge that have no outcome are said again, once the records are read after the indexes (G §165).
|
||||
h.applying.Lock()
|
||||
h.sayUnanswered("the gate's start")
|
||||
h.applying.Unlock()
|
||||
go h.Work()
|
||||
for _, pattern := range followed {
|
||||
pattern := pattern
|
||||
@@ -173,7 +177,13 @@ func take(h *Holder, e stdio.Envelope) error {
|
||||
h.applying.Lock()
|
||||
defer h.applying.Unlock()
|
||||
if h.Consumer != nil && h.Consumer.Takes(e.Key) {
|
||||
return h.Consumer.Hear(e)
|
||||
err := h.Consumer.Hear(e)
|
||||
if err == nil && bridgeRunning(e.Key) {
|
||||
// The forge bridge runs (again): its answer to an act owed is heard whichever of it and the gate was delivered
|
||||
// first (H-A-717, DQ-51).
|
||||
h.sayUnanswered("the forge bridge runs")
|
||||
}
|
||||
return err
|
||||
}
|
||||
if stdio.TopicMatches(headMovedEvent, e.Key) {
|
||||
return h.HeadMoved(e)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
nodeengine "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
|
||||
)
|
||||
|
||||
@@ -114,3 +115,60 @@ func endedFailedOrHeld(r *Record) string {
|
||||
sort.Strings(lines)
|
||||
return fmt.Sprintf("The delivery record %s ended (%s), with outcomes failed or held:\n%s", r.Instance, r.Ended.Why, strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
// sayUnanswered says again, under each act's id and first said time, every act of every record kept that has no outcome yet
|
||||
// (design 47 G §165, H-A-712 (3), H-A-717 on DMC-15), with one journal line naming the count and why: the owner of the act
|
||||
// answers one it performed already by its kept outcome. An act that cannot be said is counted and shown as refused; the
|
||||
// others go on. The caller holds the gate's applying lock where events may be heard.
|
||||
func (h *Holder) sayUnanswered(why string) {
|
||||
if h.Owed == nil || h.Records == nil {
|
||||
return
|
||||
}
|
||||
kept, err := h.Records.Kept()
|
||||
if err != nil {
|
||||
h.Refuse(fmt.Errorf("the acts owed to the forge are not said again (%s): the records are not read: %w", why, err))
|
||||
return
|
||||
}
|
||||
said, failed := 0, 0
|
||||
for _, r := range kept {
|
||||
ids := make([]string, 0, len(r.Acts))
|
||||
for id, a := range r.Acts {
|
||||
if a.Outcome == "" {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
sort.Strings(ids)
|
||||
for _, id := range ids {
|
||||
a := r.Acts[id]
|
||||
o := a.Owed
|
||||
o.Record = r.Milestone
|
||||
if o.ID == "" {
|
||||
o.ID = a.ID
|
||||
}
|
||||
if o.Said == nil {
|
||||
at := a.At
|
||||
o.Said = &at
|
||||
}
|
||||
if err := h.Owed.Say(o); err != nil {
|
||||
failed++
|
||||
h.Refuse(fmt.Errorf("the %s owed on %s#%d for the record %s is not said again: %w", a.Act, a.Repository, a.Number, r.Instance, err))
|
||||
continue
|
||||
}
|
||||
said++
|
||||
}
|
||||
}
|
||||
if h.Logf != nil {
|
||||
h.Logf("[mesh-delivery] %s: %d acts owed to the forge without an outcome said again, %d not said", why, said, failed)
|
||||
}
|
||||
}
|
||||
|
||||
// bridgeRunning is whether the key is the node-engine seat's running of the module that owns the event owed.ended, the forge
|
||||
// bridge, found from the manifest's consumes (the gate names no other module in code): `<seat>.running.<node>.<module>`.
|
||||
func bridgeRunning(key string) bool {
|
||||
owner, _, ok := strings.Cut(owedEndedEvent, ".")
|
||||
if !ok || owner == "" {
|
||||
return false
|
||||
}
|
||||
parts := strings.Split(key, ".")
|
||||
return len(parts) == 4 && parts[1] == nodeengine.EventRunning && parts[3] == owner
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -179,3 +180,47 @@ func TestARecordsChangesOweTheNoteTheViewAndWhenFailedOrHeldAComment(t *testing.
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Design 47 G §165, H-A-712 (3), H-A-717 (DMC-15, DQ-51): the gate says again, at its start and when it hears the forge bridge's
|
||||
// module running, every act owed that has no outcome, under its id and first said time, with one journal line naming the count.
|
||||
func TestTheGateSaysItsUnansweredActsAgain(t *testing.T) {
|
||||
at := time.Date(2026, 11, 25, 17, 0, 0, 0, time.UTC)
|
||||
head := strings.Repeat("1", 40)
|
||||
var journal []string
|
||||
rs := &Records{Ledger: newLedgerFake(t), Now: func() time.Time { return at }}
|
||||
first := &sayerFake{}
|
||||
h := &Holder{Now: func() time.Time { return at }, Owed: first, Records: rs, Logf: func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) }}
|
||||
rs.Changed = h.recordChanged
|
||||
r, _, err := rs.Open(opening("main", 47, map[string]string{"novox/app@7": head}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := rs.AddEntry(r, RecordEntry{Module: "mesh-x", Fingerprint: "src2:f1", Node: "ace"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := rs.Outcome(r, RecordOutcome{Module: "mesh-x", Fingerprint: "src2:f1", Node: "ace", Step: "build", Outcome: OutcomeBuilt}); err != nil || len(first.said) != 2 {
|
||||
t.Fatalf("%v, said %d", err, len(first.said))
|
||||
}
|
||||
// One act is answered: it is not said again.
|
||||
answered := first.said[0]
|
||||
body, err := forgemsg.EncodeOwedEnded(forgemsg.OwedEnded{V: 1, ID: answered.ID, Of: seat.Seat, Outcome: forgemsg.OwedNotNeeded, Words: "closed", At: at})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := h.OwedEnded(body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
again := &sayerFake{}
|
||||
h.Owed = again
|
||||
h.sayUnanswered("the gate's start")
|
||||
if len(again.said) != 1 || again.said[0].ID != first.said[1].ID || again.said[0].Said == nil || !again.said[0].Said.Equal(*first.said[1].Said) ||
|
||||
len(journal) != 1 || !strings.Contains(journal[0], "1 acts owed to the forge without an outcome said again") {
|
||||
t.Fatalf("said %+v, journal %v", again.said, journal)
|
||||
}
|
||||
for key, want := range map[string]bool{"node-engine.running.ace.mesh-delivery-forge-bridge": true, "node-engine.running.ace.mesh-x": false,
|
||||
"node-engine.wait-held.ace.mesh-delivery-forge-bridge": false} {
|
||||
if got := bridgeRunning(key); got != want {
|
||||
t.Errorf("bridgeRunning(%s) is %v", key, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user