diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog.go index f516fa98c..b8d573b6b 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/catalog.go @@ -186,7 +186,8 @@ func (w sweepWiring) AdoptEvent(seat, event string, hear func(context.Context, [ AdoptEvent(seat, event string, hear func(context.Context, []byte) error) error }) if !ok { - return nil + // Said, not passed over: the event would be registered by none, so it would be heard by none (design 47 H2b §836 3.). + return fmt.Errorf("the events %q of the seat %s are not registered: the builder's reader cannot adopt an event before its start", event, seat) } return ew.AdoptEvent(seat, event, hear) } diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go index 39e7d98f8..7fbf764aa 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go @@ -32,6 +32,7 @@ import ( "github.com/nats-io/nats.go" "github.com/nats-io/nats.go/jetstream" + "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" sweep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshartifactsweep" @@ -583,11 +584,14 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro reader.Start(ctx, js, cred, process.AwaitBucket(ctx, js, conn, builds.StateBucket(cred.Module, views.StatusState), "builder_first_views reads nothing and builder_first_view_again is not heard", logger.Printf)) // Every part has registered: the hub pulls the module's durable. Where the consumer is not there yet the builder says so // and binds it at a later change (heard.Writer; ADR 0615 §5). - _ = notHeard.Bind(eventsStream, sweep.EventArtifactsGone+", the registry seats' words, the views and manifest-reads-changed are not heard until the builder starts again", func() error { - // One Start binds every pattern's stream, the kept seat events' too (the build seats' toolchain-reported, the seat - // mesh-catalog's version-released) (design 47 H2b §836 1.). - return hub.Start(ctx, js, cred) - }) + // Start's nil says the hub started, never that anything is heard: EVENTS is heard when the hub's unheard list names no EVENTS + // entry, else not heard with the hub's reason (design 47 H2b H-A-877). One Start binds every pattern's stream, the kept seat + // events' too (the build seats' toolchain-reported, the seat mesh-catalog's version-released) (§836 1.). + eventsConsequence := sweep.EventArtifactsGone + ", the registry seats' words, the views and manifest-reads-changed are not heard until the builder starts again" + hub.OnUnheard(eventsUnheard(notHeard, eventsConsequence)) + if err := hub.Start(ctx, js, cred); err != nil { + notHeard.NotHeard(eventsStream, eventsConsequence, err) + } go func() { <-ctx.Done(); hub.Stop() }() // A person asks a key's build again with builder_ask_again, which writes the reasks state (issue 1945): watched, as // every other input. The builder asks again by itself without it. @@ -687,3 +691,17 @@ func toolchainWaitOf(path string) (time.Duration, error) { } return time.Duration(n) * time.Minute, nil } + +// eventsUnheard is the hub's word of what it does not hear, as the builder's finding family-not-heard of EVENTS: heard when the +// list names no EVENTS entry, else not heard with the hub's reason (design 47 H2b H-A-877; Start's nil says only that it started). +func eventsUnheard(w heard.Writer, consequence string) func([]process.Unheard) { + return func(list []process.Unheard) { + for _, u := range list { + if u.Stream == eventsStream { + w.NotHeard(eventsStream, consequence, errors.New(u.Why)) + return + } + } + w.Heard(eventsStream) + } +} diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/refused_test.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/refused_test.go index ee11565bd..3179203e7 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/refused_test.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/refused_test.go @@ -396,6 +396,26 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) { if _, ok := st.vals[unheardKey]; ok { t.Error("a consumer bound leaves family-not-heard") } + // H-A-877: the hub's Start answers nil once started; EVENTS is heard only when the hub's unheard list names no EVENTS entry. + hubSays := eventsUnheard(notHeard, "a branch's end is not heard") + for _, row := range []struct { + name string + list []process.Unheard + finding bool + }{ + {"EVENTS unbound", []process.Unheard{{Pattern: "mesh.seat.x.event.>", Stream: "EVENTS", Why: "consumer not found"}}, true}, + {"a kept stream only", []process.Unheard{{Pattern: "mesh.seat.y.event.z", Stream: "SEAT_y_z", Why: "refused"}}, false}, + {"all heard", nil, false}, + } { + hubSays(row.list) + got, err := decodeFinding(st.vals[unheardKey]) + if row.finding && (err != nil || !strings.Contains(got.Summary, "consumer not found")) { + t.Errorf("%s: the finding = %+v, %v", row.name, got, err) + } + if _, ok := st.vals[unheardKey]; ok != row.finding { + t.Errorf("%s: finding present = %v, want %v", row.name, ok, row.finding) + } + } // DLV-B9, the old form's window: one counted node reading only the first form holds it; seven days on it is // old-form-held about that node; the node stating the newest form closes it, said once, the finding cleared; a // retired node dropped by hand leaves the count. diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/builtparts.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/builtparts.go index 488d80363..957a5bf87 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/builtparts.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/builtparts.go @@ -4,6 +4,8 @@ import ( "context" "encoding/json" "fmt" + "maps" + "strings" "sync" "git.novox.be/novox/mesh-sdk/go/catalogue" @@ -55,6 +57,21 @@ func (b *builtParts) made(module, fingerprint string) map[string]string { return b.parts[module+"@"+fingerprint] } +// madeBy is the fingerprint of module's done build that made exactly parts, empty when none heard did; of several the least, so the +// journal line says the same each time. +func (b *builtParts) madeBy(module string, parts map[string]string) string { + b.mu.Lock() + defer b.mu.Unlock() + var found string + for key, made := range b.parts { + mod, fp, _ := strings.Cut(key, "@") + if mod == module && len(made) > 0 && maps.Equal(made, parts) && (found == "" || fp < found) { + found = fp + } + } + return found +} + // hearBuilds reads the builder's stream of build ends whole at the start and then follows it, as the assigner does (design 47 G // A-181): what was built survives the runner's restart. A stream it cannot hear is said, and no release matches a mover until the // runner starts again. diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/builtparts_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/builtparts_test.go index da23c4ffa..63205b1b2 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/builtparts_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/builtparts_test.go @@ -26,6 +26,12 @@ func TestABuildEndedGivesThePartsOfItsFingerprint(t *testing.T) { if got := b.made("app", "src2:zz"); got != nil { t.Errorf("a build not heard made %v, want none", got) } + if got := b.madeBy("app", map[string]string{"app:program": "sha256:aa"}); got != "src2:aa" { + t.Errorf("the build that made app's parts = %q, want src2:aa", got) + } + if got := b.madeBy("app", map[string]string{"app:program": "sha256:zz"}); got != "" { + t.Errorf("the build that made parts no build made = %q, want none", got) + } if err := b.put([]byte(`{"module":"app"}`)); err == nil { t.Error("an end naming no fingerprint was kept") } diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go index acca63de0..9966d6229 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -148,6 +148,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro // A release matches a mover only by the parts its own build made, heard on the builder's build.ended (design 47 H §835 1., H-A-849). var built builtParts hearer.Made = built.made + hearer.MadeBy = built.madeBy hearBuilds(ctx, js, cred, &built, logger.Printf) hearer.Ager = newAger(ctx, js, cred, store, kept, aged, logger.Printf) // The stores' fill is said before a store is full, and a full one refuses a start (§366). diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go index 190849353..a6e4dac89 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go @@ -2,6 +2,7 @@ package pipeline import ( "errors" + "fmt" "maps" "slices" "strings" @@ -196,9 +197,29 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) { // A release of a rebuild at the same source (AC-835a): its parts are not what the mover's own build made, so it writes no // version onto the mover of any pipeline of that source. rebuild := catalog.VersionReleasedEvent{Module: "app", Version: "0.4.0", Source: 5, Artifacts: []catalog.VersionArtifact{{Artifact: "app:program", Digest: "sha256:cc"}}} + // Its journal line names the two fingerprints: the mover's and the one whose heard build made the release's parts, or says no + // build was heard at the mover's (design 47 H §835 1.). + var journal []string + h.Logf = func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) } + h.MadeBy = func(module string, parts map[string]string) string { + if module == "app" && parts["app:program"] == "sha256:cc" { + return "src2:cc" + } + return "" + } if n, err := h.Released(rebuild, ""); n != 0 || err != nil || len(*order) != 0 { t.Fatalf("a rebuild's release wrote %d (%v) and said %v, want nothing", n, err, *order) } + if got := strings.Join(journal, "\n"); !strings.Contains(got, "src2:cc made") || !strings.Contains(got, "src2:aa") { + t.Errorf("a rebuild's release journal = %q, want both fingerprints", got) + } + journal = nil + madeAt := h.Made + h.Made = func(string, string) map[string]string { return nil } + if n, _ := h.Released(rebuild, ""); n != 0 || !strings.Contains(strings.Join(journal, "\n"), "no build was heard at the mover's fingerprint src2:aa") { + t.Errorf("a release with no build heard at the mover wrote %d, journal %q, want it said", n, journal) + } + h.Made, journal = madeAt, nil if m, _ := MoverOf(store[pkey].p, "app"); m.Version != "" { t.Fatalf("app's mover = %+v, want no version from a rebuild's release", m) } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/released.go b/modules/mesh-delivery-pipeline/internal/pipeline/released.go index 29f440b66..e7621d54a 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/released.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/released.go @@ -56,8 +56,8 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int, // A release of another build of the same source is no version of this mover (design 47 H §835 1., H-A-490, H-A-849): its // parts must be what the mover's own build made at its fingerprint. if !h.madeRelease(p.Movers[i], ev) { - h.logf("%s: the version %s of %s is not the mover's: its release's parts are not what the build at %s made (the mover keeps no version from it)", - key, ev.Version, ev.Module, p.Movers[i].Fingerprint) + h.logf("%s: the version %s of %s is not the mover's: %s (the mover keeps no version from it)", + key, ev.Version, ev.Module, h.notMade(p.Movers[i], ev)) break } if p.Movers[i].Version == ev.Version { @@ -89,6 +89,38 @@ func (h *Hearer) Released(ev catalog.VersionReleasedEvent, branch string) (int, return wrote, nil } +// notMade says why a release is no mover's, naming the two fingerprints (design 47 H §835 1.): the mover's, and the one whose heard +// build made the release's parts, or that no build was heard at the mover's, or at any. +func (h *Hearer) notMade(m seat.Mover, ev catalog.VersionReleasedEvent) string { + var by string + if h.MadeBy != nil { + by = h.MadeBy(ev.Module, releasedParts(ev)) + } + switch { + case h.Made == nil || len(h.Made(m.Module, m.Fingerprint)) == 0: + if by != "" { + return fmt.Sprintf("no build was heard at the mover's fingerprint %s; its release's parts are what the build at %s made", m.Fingerprint, by) + } + return fmt.Sprintf("no build was heard at the mover's fingerprint %s, nor at another that made its release's parts", m.Fingerprint) + case by != "": + return fmt.Sprintf("its release's parts are what the build at %s made, not the build at the mover's fingerprint %s", by, m.Fingerprint) + } + return fmt.Sprintf("its release's parts are not what the build at the mover's fingerprint %s made, nor what any build heard made", m.Fingerprint) +} + +// releasedParts are the release's parts, each artifact's digest by `:`. +func releasedParts(ev catalog.VersionReleasedEvent) map[string]string { + parts := map[string]string{} + for _, a := range ev.Artifacts { + ref := string(a.Artifact) + if !strings.Contains(ref, ":") { + ref = ev.Module + ":" + ref + } + parts[ref] = a.Digest + } + return parts +} + // madeRelease says whether the release's parts, each artifact's digest by `:`, are exactly what the build at the // mover's fingerprint made, as the assigner matches a release to a build (H-A-490): none known on either side matches nothing. func (h *Hearer) madeRelease(m seat.Mover, ev catalog.VersionReleasedEvent) bool { @@ -99,15 +131,7 @@ func (h *Hearer) madeRelease(m seat.Mover, ev catalog.VersionReleasedEvent) bool if len(made) == 0 { return false } - parts := map[string]string{} - for _, a := range ev.Artifacts { - ref := string(a.Artifact) - if !strings.Contains(ref, ":") { - ref = ev.Module + ":" + ref - } - parts[ref] = a.Digest - } - return maps.Equal(parts, made) + return maps.Equal(releasedParts(ev), made) } // sayEndedAgain says p's pipeline-ended again when p ended passed (H-A-270 (2), H-A-277 (2)): only a passed end writes a want, diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index 16c0ef7a8..62d7184cc 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -167,6 +167,9 @@ type Hearer struct { // Made is what a done build of module at fingerprint made, each artifact's digest by `:`, as the builder's // build.ended says it (design 47 H §835 1., H-A-849); nil, or no part, when no such end is heard: a release then matches no mover. Made func(module, fingerprint string) map[string]string + // MadeBy is the fingerprint whose heard done build of module made exactly parts (`:` to digest), empty when + // none did: the journal line of a release that is no mover's names it (design 47 H §835 1.). + MadeBy func(module string, parts map[string]string) string // KeptRevision says whether the catalog still keeps a branch's revision, as Verbs.RevisionHeld does: nil when it does, an error // wrapping ErrRevisionGone when it answers it gone (H-A-599); nil reads none and leaves a held step waiting. KeptRevision func(branch string, revision int64) error diff --git a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go index 819a5facc..b6d2a574e 100644 --- a/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go +++ b/modules/mesh-delivery-teller/cmd/mesh-delivery-teller/integration_test.go @@ -530,10 +530,19 @@ func TestTellerCarriesAnAskAndWritesTheAnswer(t *testing.T) { // 1343/AC1, AC2 case <-time.After(15 * time.Second): t.Fatalf("no widening was told after a pipeline-ended carrying one\n%s", logs.String()) } + // Once, shown without waiting: a second, different widening is published; the next message told is the second one's, so the + // first was not told twice (a duplicate would be in the channel before it). + end2, _ := json.Marshal(mpr.PipelineEnded{Branch: "release", Movers: []mpr.MoverEnded{{Module: "plex", Commit: "fedcba9876543210", Widens: []mpr.Widening{{What: "grant", Name: "seat:mesh-grants.input"}}}}}) + if _, err := b.js.Publish(b.ctx, "mesh.seat."+mpr.Seat+".event."+mpr.EventPipelineEnded+".release.8", end2); err != nil { + t.Fatal(err) + } select { case body := <-told: - t.Errorf("a second message was told: %v", body) - case <-time.After(500 * time.Millisecond): + if s, _ := body["summary"].(string); !strings.Contains(s, "plex fedcba9 on release widens grant seat:mesh-grants.input") { + t.Errorf("the next message told was %v, want the second widening's", body) + } + case <-time.After(15 * time.Second): + t.Fatalf("the second widening was not told\n%s", logs.String()) } } diff --git a/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/consumes.go b/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/consumes.go index 55c41ca6e..277c5e61c 100644 --- a/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/consumes.go +++ b/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/consumes.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" "git.novox.be/novox/mesh-contracts/go/seats/meshbroker" "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" @@ -99,6 +100,7 @@ func hearConsumed(ctx context.Context, js jetstream.JetStream, cred process.Acco w.NotHeard("EVENTS", "the seats' events cannot be handled", err) } } + hub.OnUnheard(eventsUnheard(w, "what it carries is heard once the grants part has made the consumer "+cred.EventConsumerName())) var mu sync.Mutex opened := map[string]bool{} open := func(stream, name string) { @@ -110,11 +112,11 @@ func hearConsumed(ctx context.Context, js jetstream.JetStream, cred process.Acco // Not bound, the stream is the finding family-not-heard (ADR 0615 §5) until it is, at a later change of the // membership or a later start. if stream == "EVENTS" { + // Start's nil says the hub started, never that EVENTS is heard: the hub's unheard list says it (H-A-877). if err := hub.Start(ctx, js, cred); err != nil { w.NotHeard(stream, "what it carries is heard once the grants part has made the consumer "+name, err) return } - w.Heard(stream) opened[stream] = true return } @@ -265,3 +267,17 @@ func buildSeatSubject(w *watch.Watchman, subject string, body []byte) bool { } return true } + +// eventsUnheard is the hub's word of what it does not hear, as the watchman's finding family-not-heard of EVENTS: heard when the +// list names no EVENTS entry, else not heard with the hub's reason (design 47 H2b H-A-877). +func eventsUnheard(w *watch.Watchman, consequence string) func([]process.Unheard) { + return func(list []process.Unheard) { + for _, u := range list { + if u.Stream == "EVENTS" { + w.NotHeard("EVENTS", consequence, errors.New(u.Why)) + return + } + } + w.Heard("EVENTS") + } +} diff --git a/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/main_test.go b/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/main_test.go index df5489742..793a093be 100644 --- a/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/main_test.go +++ b/modules/mesh-delivery-watchman/cmd/mesh-delivery-watchman/main_test.go @@ -53,6 +53,25 @@ func TestRunNeedsItsCredential(t *testing.T) { // 1135/AC6 } } }) + t.Run("H-A-877: EVENTS is heard from the hub's unheard list, never from Start's nil", func(t *testing.T) { + out := &findingsOut{findings: map[string]bool{}} + hubSays := eventsUnheard(watch.New(watchmanModule, out, time.Now), "x is not heard") + for _, row := range []struct { + name string + list []process.Unheard + want int + }{ + {"EVENTS unbound", []process.Unheard{{Pattern: "mesh.seat.a.event.>", Stream: "EVENTS", Why: "consumer not found"}}, 1}, + {"a kept stream only", []process.Unheard{{Pattern: "mesh.seat.b.event.c", Stream: "SEAT_b_c", Why: "refused"}}, 0}, + {"EVENTS unbound again", []process.Unheard{{Pattern: "p", Stream: "EVENTS", Why: "w"}}, 1}, + {"all heard", nil, 0}, + } { + hubSays(row.list) + if len(out.findings) != row.want { + t.Errorf("%s: findings %v, want %d", row.name, out.findings, row.want) + } + } + }) t.Run("DLV-W1: the consumed events reach the watchman by their subjects", func(t *testing.T) { out := &findingsOut{findings: map[string]bool{}} w := watch.New(watchmanModule, out, time.Now)