gate: AC-G4a and AC-G4b are steps of TestAGateWholeTakesAMergeCallAndWatchesTheHeadsOverARealBus

Builds: design 47 H2 H-A-597, H-A-609, H-A-617
This commit is contained in:
2026-11-25 18:55:23 +01:00
parent 6f7311820c
commit ce2455d189
2 changed files with 79 additions and 0 deletions
@@ -20,6 +20,7 @@ import (
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
meshdelivery "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
stdio "git.novox.be/novox/mesh-sdk/go"
"github.com/nats-io/nats-server/v2/server"
"github.com/nats-io/nats.go"
@@ -134,10 +135,29 @@ type runtime struct {
operatorCancels []string
// owedSaid are the subjects of the seat events owed the gate said, in order (W11.17).
owedSaid []string
// endedSaid are the bodies of the record-ended events the gate said, in order (AC-G4a, AC-G4b).
endedSaid []json.RawMessage
// logs is what the bundle said in its journal.
logs *testLog
}
// endedSays are the end counts the gate said record-ended with for a record, in order.
func (r *runtime) endedSays(record string) []int64 {
r.mu.Lock()
defer r.mu.Unlock()
var out []int64
for _, raw := range r.endedSaid {
var e struct {
Record string `json:"record"`
Ends int64 `json:"ends"`
}
if json.Unmarshal(raw, &e) == nil && e.Record == record {
out = append(out, e.Ends)
}
}
return out
}
// journalHas is whether the bundle said a line in its journal holding every one of words.
func (r *runtime) journalHas(words ...string) bool {
r.logs.mu.Lock()
@@ -349,6 +369,11 @@ func (r *runtime) answer(m rpcMessage) {
r.operatorAsks = append(r.operatorAsks, a)
r.mu.Unlock()
}
if p.Subject == meshdelivery.SubjectRecordEnded {
r.mu.Lock()
r.endedSaid = append(r.endedSaid, p.Body)
r.mu.Unlock()
}
if strings.HasPrefix(p.Subject, "mesh.seat.mesh-delivery.event.owed.") {
r.mu.Lock()
r.owedSaid = append(r.owedSaid, p.Subject)
@@ -111,6 +111,35 @@ func TestAGateWholeTakesAMergeCallAndWatchesTheHeadsOverARealBus(t *testing.T) {
want.Round(time.Minute))
}
// AC-G4b (H-A-609 (2), H-A-617, H-A-728), over the bus: a mover-added counts its mover in the record its pipeline names, a
// pipeline-ended of a higher end count reopens the ended record, and its next end says record-ended with ends 2.
rt.until("the first end said record-ended with ends 1", eventWithin, func() bool {
says := rt.endedSays(instance)
return len(says) == 1 && says[0] == 1
})
b.publish(t, "mesh.seat.mesh-pipeline-runner.event.mover-added."+escaped+".1", map[string]any{"v": 1, "pipeline": recordMilestone(branch, 1),
"revision": 4, "module": "extra", "fingerprint": "x", "from": recordMilestone(branch, 1) + ".again.1"})
added, _ := MoverInstance(recordMilestone(branch, 1), "extra")
rt.until("the added mover counted in the record that carries its pipeline", eventWithin, func() bool {
b.mu.Lock()
defer b.mu.Unlock()
return strings.Contains(string(b.ledger.states[added]), `"module":"extra"`)
})
b.publish(t, "mesh.seat.mesh-pipeline-runner.event.pipeline-ended."+escaped+".1", map[string]any{"v": 1, "branch": branch, "source": 1,
"pipeline": recordMilestone(branch, 1), "outcome": "passed", "end-count": 2, "movers": []any{}})
rt.until("the record reopened by the pipeline's higher end", eventWithin, func() bool {
b.mu.Lock()
defer b.mu.Unlock()
reopened := Record{}
return json.Unmarshal(b.ledger.states[instance], &reopened) == nil && reopened.Ended == nil && reopened.PipelineEnds == 2
})
b.publish(t, "mesh.seat.mesh-wants.event.pipeline-wanted."+escaped+".1", map[string]any{"v": 1, "branch": branch,
"source": 1, "pipeline": recordMilestone(branch, 1), "outcome": "running"})
rt.until("the reopened record ended again with ends 2", eventWithin, func() bool {
says := rt.endedSays(instance)
return len(says) == 2 && says[1] == 2
})
// GT1 (design 47 H2 §809; H-A-385, H-A-391, H-A-453 (3), H-A-455): a record of 126 movers writes 127 entries, its head
// and one per mover, and its acts owed the forge each an entry of its own, none over 64 KiB, the head counting 126 and
// holding no act; an entry made too large raises record-too-large, and the record's end clears it.
@@ -194,6 +223,31 @@ func TestAGateWholeTakesAMergeCallAndWatchesTheHeadsOverARealBus(t *testing.T) {
rt.until("the journal line naming the record, the mover on test and both times", eventWithin, func() bool {
return rt.journalHas(instance2, late["module"].(string)+" on test", "after it ended")
})
// AC-G4a (H-A-597, H-A-609 (2)), over the bus: the late running said record-ended again with ends 2, and the same running
// heard again moves nothing and says nothing. A running from a machine that was away at the end cannot be heard here: no
// event of the gate's marks a machine away (only the unit tests mark one).
rt.until("record-ended said again with ends 2", eventWithin, func() bool {
says := rt.endedSays(instance2)
return len(says) == 2 && says[0] == 1 && says[1] == 2
})
endedAt := ended2.Ended.At
b.publish(t, "mesh.seat.node-engine.event.running.test."+late["module"].(string), map[string]any{"v": 1, "module": late["module"],
"node": "test", "fingerprint": late["fingerprint"], "at": time.Now().Add(time.Minute).UTC().Format(time.RFC3339)})
b.publish(t, "mesh.seat.mesh-pipeline-runner.event.mover-added."+escaped+".2", map[string]any{"v": 1, "pipeline": recordMilestone(branch, 2),
"revision": 4, "module": "witness", "fingerprint": "w", "from": recordMilestone(branch, 2) + ".again.1"})
witness, _ := MoverInstance(recordMilestone(branch, 2), "witness")
rt.until("the event heard after the repeated running", eventWithin, func() bool {
b.mu.Lock()
defer b.mu.Unlock()
return strings.Contains(string(b.ledger.states[witness]), `"module":"witness"`)
})
b.mu.Lock()
again := Record{}
err = json.Unmarshal(b.ledger.states[instance2], &again)
b.mu.Unlock()
if says := rt.endedSays(instance2); err != nil || again.Ends != 2 || !again.Ended.At.Equal(endedAt) || len(says) != 2 {
t.Errorf("a repeated running left the record at end %d, ended %v (was %v), said %v: want it unchanged, ends 2", again.Ends, again.Ended, endedAt, says)
}
// The seed (§768): every watched branch's first source revision at its head; its head-moved then holds nothing.
seeded := strings.Repeat("5", 40)