gate: take-in.taken moves a head only forward too (A-464d)

Also corrects the manifest test's comment, which said the gate does not hear merged (A-464).

Builds: design 47 G-22 A-464d, A-464
This commit is contained in:
2026-11-17 02:10:36 +01:00
parent 7da6dd20a1
commit 46f3dc8cd7
3 changed files with 41 additions and 2 deletions
@@ -134,8 +134,8 @@ func TestItClaimsTheDeliverySeatAndFollowsWhatItHandles(t *testing.T) {
}
}
}
// From G's delivery the gate hears neither the bridge's merged and pushed messages nor the teller's answers nor the view's
// reach (design 47 G §592, §593): it consumes the indexer's take-in.taken and the bridge's owed.ended, and the git events that clear
// From G's delivery the gate hears neither the bridge's pushed messages nor the teller's answers nor the view's reach
// (design 47 G §592, §593); it hears the bridge's merged message alone, to follow every merge (A-464): it consumes the indexer's take-in.taken and the bridge's owed.ended, and the git events that clear
// an approval carried.
if want := append(slices.Clone(followed), meshconditions.Seat+"."+meshconditions.EventFindingsAsked); !reflect.DeepEqual(m.Consumes, want) {
t.Fatalf("consumes %v, follows %v", m.Consumes, followed)
@@ -149,3 +149,18 @@ func mustTaken(t *testing.T, body []byte) meshcatalog.TakeInTaken {
}
return v
}
// Design 47 G A-464d: a take-in.taken arriving after a later merge moved the head leaves the head where it is.
func TestATakeInTakenAfterALaterMergeLeavesTheHead(t *testing.T) {
oldC, newC := strings.Repeat("a", 40), strings.Repeat("b", 40)
src := &memSource{vals: map[string]Source{"main": {Heads: map[string]string{"novox/app": newC}}}}
var said []string
h := &Holder{Now: time.Now, Source: src, Logf: func(string, ...any) {},
Forge: &fakeForge{contains: func(commit, in string) bool { return commit == in || (commit == oldC && in == newC) }},
SaySeat: func(_ string, _ any, id string) error { said = append(said, id); return nil }}
body := []byte(`{"v":1,"kind":"taken","key":"g.feat","what":"group","group":"feat","branch":"main","source":7,` +
`"merges":[{"repository":"novox/app","number":3,"merge":"` + oldC + `"}],"entries":[]}`)
if err := h.moveSource(mustTaken(t, body)); err != nil || src.vals["main"].Heads["novox/app"] != newC || src.rev != 0 || len(said) != 0 {
t.Fatalf("take-in of an older merge: %v, source %+v, revision %d, said %v: want the head left at the later merge", err, src.vals["main"], src.rev, said)
}
}
@@ -9,6 +9,7 @@ import (
mdc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshdeliveryclient"
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
"git.novox.be/novox/mesh-sdk/go/keys"
)
@@ -107,6 +108,29 @@ func (h *Holder) moveSource(t meshcatalog.TakeInTaken) error {
for _, m := range t.Merges {
heads[m.Repository] = m.Merge
}
// A head moves only forward (A-464d): a repository whose held head is not contained in the merge is left where it is.
if held, _, err := h.Source.Read(t.Branch); err != nil {
return err
} else if held != nil && h.Forge != nil {
for r, c := range heads {
for name, was := range held.Heads {
if !trunk.SameRepository(name, r) || was == c {
continue
}
ahead, err := h.Forge.Contains(name, was, c)
if err != nil {
return fmt.Errorf("whether %.12s is in %.12s of %s cannot be read, so the head stays: %w", was, c, name, err)
}
if !ahead {
h.logf("[mesh-delivery] source.%s keeps %s at %.12s: the take-in's merge %.12s does not contain it, left without effect", t.Branch, name, was, c)
delete(heads, r)
}
}
}
if len(heads) == 0 {
return nil
}
}
wrote := false
rev, err := h.Source.Set(t.Branch, func(prev *Source) (Source, bool) {
wrote = false