selfcompose: hear catalog-revision on the contract's subject, consume it in the manifest, one test

Subscribe to meshcatalog.SubjectCatalogRevisionAll (no string of its own); module.json consumes
mesh-catalog.catalog-revision so the node account is granted it; the two new tests are folded into
TestTrunkAskBackoffAndCatalogRevision and wait on channels, not time.

Builds: design 47 G-22 A-487a, A-487c, principle 3
This commit is contained in:
2026-11-19 01:18:38 +01:00
parent 2057c9d304
commit cb6cd9d996
5 changed files with 32 additions and 79 deletions
+27 -71
View File
@@ -669,7 +669,7 @@ func TestOnlyWhatTheNodeNeedsOfAnotherNodesPlacementIsAsked(t *testing.T) {
// A-487a (A-461e): a trunk build the catalog gave none of is not asked again at every pass: it waits laterAgain's step for the module
// (5 s, then 15 s), and the seat's event catalog-revision ends the wait at once; an answer starts the steps again from 5 s. The
// event is heard through Env.Hear on the seat's subject, whatever its branch.
// event is heard through Env.Hear on the contract's subject; a refused subscription is said once and tried again.
func TestTrunkAskBackoffAndCatalogRevision(t *testing.T) {
old := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64)
now := time.Date(2026, 11, 19, 10, 0, 0, 0, time.UTC)
@@ -719,13 +719,24 @@ func TestTrunkAskBackoffAndCatalogRevision(t *testing.T) {
t.Errorf("an answer came and the backoff of the module stands: %+v", c.trunkRetry)
}
// The wiring: the composer hears the seat's event on its subject and clears the waits.
heard := make(chan []byte, 1)
// The wiring: the composer hears the seat's event on the contract's subject. A subscription Hear refuses is said once with the subject
// and the error, never refuses Watch, and is tried again (principle 3); once it holds, an event clears the waits.
setFor(t, &laterAgain, []time.Duration{time.Nanosecond})
b := newFakeBus()
env.Say = b.env().Say
attempts := make(chan struct{}, 8)
heard := make(chan []byte) // unbuffered: a second send returns only when the first event was handled
var tries int
env.Hear = func(subject string) (<-chan []byte, func(), error) {
if subject == CatalogRevisionEvents {
return heard, func() {}, nil
if subject != meshcatalog.SubjectCatalogRevisionAll {
return make(chan []byte), func() {}, nil
}
return make(chan []byte), func() {}, nil
tries++
attempts <- struct{}{}
if tries < 2 {
return nil, nil, errors.New("permissions violation")
}
return heard, func() {}, nil
}
answers = false
c = New(env)
@@ -734,64 +745,15 @@ func TestTrunkAskBackoffAndCatalogRevision(t *testing.T) {
c.mu.Unlock()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if _, err := c.Watch(ctx, "n1.>"); err != nil {
t.Fatal(err)
}
heard <- []byte(`{}`)
deadline := time.After(5 * time.Second)
for {
c.mu.Lock()
next := c.trunkRetry["postgres"].next
c.mu.Unlock()
if next.IsZero() {
break
}
select {
case <-deadline:
t.Fatal("catalog-revision was heard and the wait of the module stands")
case <-time.After(5 * time.Millisecond):
}
}
}
// A-487a, principle 3: a refused subscription to catalog-revision does not refuse Watch; it is said once with its subject and error, and
// tried again on laterAgain's steps until it holds, after which an event clears the waits.
func TestCatalogRevisionSubscriptionRefusedIsSaidAndRetried(t *testing.T) {
setFor(t, &laterAgain, []time.Duration{5 * time.Millisecond})
b := newFakeBus()
env := b.env()
heard := make(chan []byte, 1)
var tries atomic.Int64
env.Hear = func(subject string) (<-chan []byte, func(), error) {
if subject == CatalogRevisionEvents {
if tries.Add(1) < 3 {
return nil, nil, errors.New("permissions violation")
}
return heard, func() {}, nil
}
return make(chan []byte), func() {}, nil
}
c := New(env)
c.mu.Lock()
c.trunkRetry = map[string]trunkBackoff{"postgres": {tries: 1, next: time.Now().Add(time.Hour)}}
c.mu.Unlock()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if _, err := c.Watch(ctx, "n1.>"); err != nil {
t.Fatalf("a refused catalog-revision subscription refused Watch: %v", err)
}
deadline := time.After(5 * time.Second)
for tries.Load() < 3 {
select {
case <-deadline:
t.Fatal("the subscription was not tried again")
case <-time.After(2 * time.Millisecond):
}
}
<-attempts
<-attempts // the second attempt comes after the refusal was said
said := 0
b.mu.Lock()
for _, s := range b.said {
if strings.Contains(s, CatalogRevisionEvents) && strings.Contains(s, "permissions violation") {
for _, line := range b.said {
if strings.Contains(line, meshcatalog.SubjectCatalogRevisionAll) && strings.Contains(line, "permissions violation") {
said++
}
}
@@ -800,17 +762,11 @@ func TestCatalogRevisionSubscriptionRefusedIsSaidAndRetried(t *testing.T) {
t.Errorf("the refusal was said %d times, want once", said)
}
heard <- []byte(`{}`)
for {
c.mu.Lock()
z := c.trunkRetry["postgres"].next.IsZero()
c.mu.Unlock()
if z {
return
}
select {
case <-deadline:
t.Fatal("the event of the subscription that held did not clear the wait")
case <-time.After(2 * time.Millisecond):
}
heard <- []byte(`{}`)
c.mu.Lock()
next := c.trunkRetry["postgres"].next
c.mu.Unlock()
if !next.IsZero() {
t.Error("catalog-revision was heard and the wait of the module stands")
}
}
+2 -6
View File
@@ -161,10 +161,6 @@ type SeatGate interface {
// VaultSecretChanged is the vault's event that a secret changed: a name and its generation, never a value.
const VaultSecretChanged = "mesh.mod.mesh-vault.event.secret-changed"
// CatalogRevisionEvents is the seat mesh-catalog's event catalog-revision, whatever branch its subject names: a node-engine asks
// again the trunk builds the catalog gave none of at once, not at the end of their backoff (A-487a, design 47 G-12 line 317).
const CatalogRevisionEvents = "mesh.seat.mesh-catalog.event.catalog-revision.>"
// Composer composes the node and is the agent's watcher of its compositions (agent.Env.Composed).
type Composer struct {
// OnEngine is told the node-engine's own module each time a composing finds it (design 47 G §527, §634); set before the
@@ -717,7 +713,7 @@ func (c *Composer) Watch(ctx context.Context, _ string) (<-chan agent.Update, er
func (c *Composer) hearCatalogRevisions(ctx context.Context, wake func()) {
said := false
for try := 0; ; try++ {
revisions, stop, err := c.env.Hear(CatalogRevisionEvents)
revisions, stop, err := c.env.Hear(meshcatalog.SubjectCatalogRevisionAll)
if err == nil {
defer stop()
for {
@@ -735,7 +731,7 @@ func (c *Composer) hearCatalogRevisions(ctx context.Context, wake func()) {
}
if !said {
said = true
c.env.Say(fmt.Sprintf("the node cannot hear %s: %v; it asks the trunk builds again on a backoff alone and tries to hear it again", CatalogRevisionEvents, err))
c.env.Say(fmt.Sprintf("the node cannot hear %s: %v; it asks the trunk builds again on a backoff alone and tries to hear it again", meshcatalog.SubjectCatalogRevisionAll, err))
}
select {
case <-ctx.Done():
+1 -1
View File
@@ -249,7 +249,7 @@ func TestTheNodeComposesItsWantsFromTheBus(t *testing.T) {
}
secretChanged := make(chan []byte, 1)
env.Hear = func(subject string) (<-chan []byte, func(), error) {
if subject == CatalogRevisionEvents {
if subject == meshcatalog.SubjectCatalogRevisionAll {
return make(chan []byte), func() {}, nil
}
if subject != VaultSecretChanged {
+1
View File
@@ -53,6 +53,7 @@
"seat:oci-artifact-registry.versions"
],
"consumes": [
"mesh-catalog.catalog-revision",
"mesh-catalog.seat-definition-changed",
"mesh-catalog.seat-definition-removed",
"mesh-conditions.findings-asked",
+1 -1
View File
@@ -93,7 +93,7 @@ func TestTheManifestConsumesTheBackupEvent(t *testing.T) {
t.Errorf("config recovery-wait-minutes is %+v, want default 90", m.Config["recovery-wait-minutes"])
}
// The backup event, the status view's settled, and the two events of the seat that serves the seat list (ADR 0636 §4), the keeper's ask (design 47 G §387), the seat's running (§199) and the builder's build ends (A-293).
if want := []string{"mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-conditions.findings-asked", "mesh-delivery-builder.build.ended.**", "mesh-delivery-view.settled", "mesh-recovery.ended", "mesh-recovery.restored", "node-engine.running", "restic.backed-up"}; !slices.Equal(m.Consumes, want) {
if want := []string{"mesh-catalog.catalog-revision", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-conditions.findings-asked", "mesh-delivery-builder.build.ended.**", "mesh-delivery-view.settled", "mesh-recovery.ended", "mesh-recovery.restored", "node-engine.running", "restic.backed-up"}; !slices.Equal(m.Consumes, want) {
t.Fatalf("consumes %v, want %v", m.Consumes, want)
}
// 774: the acts bucket mesh-host_acts is not declared as state for now: a declared state of a module with no account