Indexer: say catalog-revision on its branch's subject, the one the bus allows
The bus refused the bare subject mesh.seat.mesh-catalog.event.catalog-revision: the seat definition (mesh-delivery-contracts/seats/mesh-catalog/seat.json) gives the event the subject catalog-revision.<branch>, and the holder is granted catalog-revision.*. The publish now uses meshcatalog.SubjectCatalogRevision(the event's branch); an event with no branch is refused loudly, never given a bare subject. Builds: design 47 G, the seat definition mesh-catalog (event catalog-revision, subject catalog-revision.<branch>) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
|
||||
func TestACatalogRevisionIsSaidOnTheSeatsSubjectWithItsBranch(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
e meshcatalog.CatalogRevisionEvent
|
||||
want string
|
||||
refused bool
|
||||
}{
|
||||
{"trunk", meshcatalog.CatalogRevisionEvent{Kind: "trunk", Branch: "main", Revision: 3}, "mesh.seat.mesh-catalog.event.catalog-revision.main", false},
|
||||
{"candidate", meshcatalog.CatalogRevisionEvent{Kind: "candidate", Branch: "fix/x=2ey", Revision: 1}, "mesh.seat.mesh-catalog.event.catalog-revision.fix/x=2ey", false},
|
||||
{"no branch", meshcatalog.CatalogRevisionEvent{Kind: "trunk", Revision: 3}, "", true},
|
||||
} {
|
||||
got, err := catalogRevisionSubject(c.e)
|
||||
if (err != nil) != c.refused || got != c.want {
|
||||
t.Errorf("%s: subject %q (%v), want %q refused=%v", c.name, got, err, c.want, c.refused)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1064,7 +1064,7 @@ func TestIndexerWritesModulesAtAMerge(t *testing.T) { // 1239/AC9; I1, I3: the m
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if msg, err := events.GetLastMsgForSubject(ctx, "mesh.seat.mesh-catalog.event."+meshcatalog.EventCatalogRevision); err != nil ||
|
||||
if msg, err := events.GetLastMsgForSubject(ctx, meshcatalog.SubjectCatalogRevisionAll); err != nil ||
|
||||
!strings.Contains(string(msg.Data), fmt.Sprintf(`"revision":%d`, newest)) {
|
||||
t.Errorf("catalog-revision said: %v (%v): want revision %d", msg, err, newest)
|
||||
}
|
||||
|
||||
@@ -125,6 +125,16 @@ func (b *busObjects) Fill(ctx context.Context) (int64, int64, error) {
|
||||
return int64(st.Size()), info.CachedInfo().Config.MaxBytes, nil
|
||||
}
|
||||
|
||||
// catalogRevisionSubject is where an event says: the seat's catalog-revision.<branch> (the seat definition's subject), the
|
||||
// branch the event's own field names. An event with no branch is refused: the indexer names the branch of every revision it
|
||||
// keeps, and a bare subject is one the bus refuses.
|
||||
func catalogRevisionSubject(e meshcatalog.CatalogRevisionEvent) (string, error) {
|
||||
if e.Branch == "" {
|
||||
return "", fmt.Errorf("the catalog-revision of %s revision %d names no branch, so it has no subject", e.Kind, e.Revision)
|
||||
}
|
||||
return meshcatalog.SubjectCatalogRevision(e.Branch), nil
|
||||
}
|
||||
|
||||
// sayCatalogRevision publishes the seat mesh-catalog's event catalog-revision under the duplicate id of its kind and
|
||||
// number, so a revision said twice is heard once (design 47, Two graphs).
|
||||
func sayCatalogRevision(conn *nats.Conn, cred process.Account) func(context.Context, meshcatalog.CatalogRevisionEvent) error {
|
||||
@@ -133,7 +143,11 @@ func sayCatalogRevision(conn *nats.Conn, cred process.Account) func(context.Cont
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := nats.NewMsg(seatEventSubject(meshcatalog.EventCatalogRevision))
|
||||
subject, err := catalogRevisionSubject(e)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
msg := nats.NewMsg(subject)
|
||||
id := fmt.Sprintf("%s-%s-%d%s", meshcatalog.EventCatalogRevision, e.Kind, e.Revision, e.Heads)
|
||||
msg.Header.Set("x-event-id", id)
|
||||
msg.Header.Set("x-source", cred.Module)
|
||||
|
||||
Reference in New Issue
Block a user