diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcestart.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcestart.go index 6bca6972e..dbd772a1a 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcestart.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcestart.go @@ -145,7 +145,7 @@ func (h *Holder) startSources(only string) (started, leftOut []string, err error if len(heads) == 0 { continue } - wrote, group := false, "" + wrote := false rev, err := h.Source.Set(branch, func(prev *Source) (Source, bool) { next := Source{Heads: map[string]string{}} if prev != nil { @@ -161,7 +161,6 @@ func (h *Holder) startSources(only string) (started, leftOut []string, err error wrote = true } } - group = next.Group return next, wrote }) if err != nil { @@ -177,7 +176,7 @@ func (h *Holder) startSources(only string) (started, leftOut []string, err error } at := h.Now().UTC() if err := h.SaySeat(seat.SubjectSourceMoved(keys.EscapeName(branch)), - seat.SourceMovedEvent{Branch: branch, Group: group, Revision: int64(rev), At: &at}, + seat.SourceMovedEvent{Branch: branch, Revision: int64(rev), At: &at}, "source-moved."+keys.EscapeName(branch)+"."+strconv.FormatUint(rev, 10)); err != nil { errs = append(errs, err) } diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go index 7a3c52382..0ba9afc6f 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/sourcetools_test.go @@ -1,10 +1,12 @@ package main import ( + "encoding/json" "errors" "fmt" 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" + stdio "git.novox.be/novox/mesh-sdk/go" "reflect" "strings" "testing" @@ -173,8 +175,8 @@ func TestAWatchedBranchStartsFromTheForge(t *testing.T) { Logf: func(f string, a ...any) { logged = append(logged, fmt.Sprintf(f, a...)) }, SaySeat: func(subject string, body any, id string) error { events++ - if ev := body.(seat.SourceMovedEvent); ev.Group != c.held[ev.Branch].Group { - t.Errorf("the group is the key's own (empty for a new key), got %q", ev.Group) + if ev := body.(seat.SourceMovedEvent); ev.Group != "" { + t.Errorf("a source-moved for started heads names no group (A-404), got %q", ev.Group) } return nil }} @@ -193,6 +195,11 @@ func TestAWatchedBranchStartsFromTheForge(t *testing.T) { t.Errorf("source.%s heads %v, want %v", b, got, want) } } + for b, h := range c.held { + if src.vals[b].Group != h.Group { + t.Errorf("source.%s keeps the group %q a take-in wrote, got %q", b, h.Group, src.vals[b].Group) + } + } if c.only == "" && c.held == nil && !strings.Contains(strings.Join(logged, "\n"), "o/photos") { t.Errorf("the repository left out was not said: %v", logged) } @@ -220,3 +227,35 @@ func TestSourceStartByHandIsRecordedFirst(t *testing.T) { t.Fatalf("log %+v source %+v", acts.took, src.vals) } } + +// Design 47 G A-401: the registration-changed branch of take and the start pass both write the new branch's key and say +// source-moved; removing either leaves the branch unstarted. +func TestRegistrationChangedAndTheStartPassStartABranch(t *testing.T) { + regs := []meshcatalog.Registration{{Module: "f1", Origin: "o/f1", Branches: []string{"master"}}} + for _, c := range []struct { + name string + run func(h *Holder) error + }{ + {"registration-changed", func(h *Holder) error { + return take(h, stdio.Envelope{Key: registrationChangedEvent, Body: json.RawMessage(`{}`)}) + }}, + {"the start pass", func(h *Holder) error { startSourcesAtStart(h); return nil }}, + } { + t.Run(c.name, func(t *testing.T) { + if registrationChangedEvent == "" { + t.Fatal("the manifest does not consume registration-changed") + } + src := &branchSource{memSource{vals: map[string]Source{}}} + var subjects []string + h := &Holder{Now: time.Now, Source: src, Forge: &fakeForge{heads: map[string]string{"o/f1@master": "c3"}}, + Catalog: fakeCatalog{regs: regs}, Logf: func(string, ...any) {}, + SaySeat: func(subject string, body any, id string) error { subjects = append(subjects, subject); return nil }} + if err := c.run(h); err != nil { + t.Fatal(err) + } + if src.vals["master"].Heads["o/f1"] != "c3" || len(subjects) != 1 || !strings.HasSuffix(subjects[0], ".event.source-moved.master") { + t.Fatalf("source %+v events %v", src.vals, subjects) + } + }) + } +}