views: wire the unhandled-event count once, and prove it on the bus

The hub's hook, the path the live fault took, had no test that failed
without it, and each Start appended it again, so a second Start counted
every event twice. Start now wires it once per hub and keeps the time of
the first start; the shared-durable integration test holds the reader's
finding of the one event nobody takes, counted once across two starts.

Builds: design 47 H H-A-169
This commit is contained in:
2026-11-20 17:52:48 +01:00
parent e568e6dc63
commit a5225dfac3
2 changed files with 54 additions and 3 deletions
+42 -1
View File
@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"slices"
"strings"
"testing"
"time"
@@ -157,7 +158,8 @@ func subTheViewsReaderAndTwoHandlersShareTheModulesOneDurable(t *testing.T) {
t.Fatal(err)
}
}
r := &views.ProcessReader{Module: "reader", Hub: hub, Logf: t.Logf,
found := &seenFindings{put: make(chan map[string]any, 8)}
r := &views.ProcessReader{Module: "reader", Hub: hub, Logf: t.Logf, Findings: func() views.WireWriter { return found },
Call: func(tool string, body any) (json.RawMessage, error) {
raw, _ := json.Marshal(body)
m, err := nc.Request("mesh.mod.o.call.o_read_modules.n0", raw, 5*time.Second)
@@ -235,6 +237,38 @@ func subTheViewsReaderAndTwoHandlersShareTheModulesOneDurable(t *testing.T) {
if info, err := cons.Info(ctx); err != nil || info.NumAckPending != 0 {
t.Fatalf("a message was left unacknowledged: %+v %v", info, err)
}
// H-A-169: the one event no handler takes is the module's finding event-unhandled, counted once, naming its subject,
// though the reader started twice.
r.Start(ctx, js, cred, nil)
select {
case f := <-found.put:
summary, _ := f["summary"].(string)
if f["kind"] != views.EventUnhandledKind || f["id"] != "reader" || !strings.Contains(summary, "took 1 events") ||
!strings.Contains(summary, "mesh.mod.z.event.nobody") {
t.Fatalf("the unhandled event's finding: %v", f)
}
case <-time.After(10 * time.Second):
t.Fatal("the unhandled event wrote no finding")
}
if _, err := js.Publish(ctx, "mesh.mod.z.event.nobody", []byte("{}")); err != nil {
t.Fatal(err)
}
if _, err := js.Publish(ctx, "mesh.mod.p.event.a", []byte("{}")); err != nil {
t.Fatal(err)
}
select {
case <-got["a"]: // the hub hands messages in order: every hook of the event before has run
case <-time.After(10 * time.Second):
t.Fatal("the handled event after the unhandled one was not heard")
}
select {
case f := <-found.put:
if summary, _ := f["summary"].(string); !strings.Contains(summary, "took 2 events") || len(found.put) != 0 {
t.Fatalf("after a second start one event is counted once: %v, and %d more", f, len(found.put))
}
default:
t.Fatal("the unhandled event after the second start wrote no finding")
}
// A hub started before the bus holds its durable says so, and binds at a later start: a module is not lost for the
// order in which the bus makes its consumer.
late := process.Account{Node: "n1", Module: "late"}
@@ -270,3 +304,10 @@ func TestAReaderHearsAnOwnersChangesAsOrdinaryEvents(t *testing.T) {
t.Run("TheViewsReaderAndTwoHandlersShareTheModulesOneDurable", subTheViewsReaderAndTwoHandlersShareTheModulesOneDurable)
t.Run("WriterSaysItsEventsAndHearsAsksOnTheBus", subWriterSaysItsEventsAndHearsAsksOnTheBus)
}
// seenFindings is a findings writer that hands each finding written to the test.
type seenFindings struct{ put chan map[string]any }
func (f *seenFindings) WriteWire(_ context.Context, w map[string]any) error { f.put <- w; return nil }
func (f *seenFindings) Clear(context.Context, string, string, string, string) error { return nil }
func (f *seenFindings) ModuleNode() (string, string) { return "reader", "n1" }