Files
mesh-catalog/modules/mesh-knowledge/cmd/mesh-knowledge/progress_bus_test.go
T
jschoubben df79ab8769 mesh-knowledge: the overview's delivery block and the progress verb's groups lines go
Review round 1, Must 3: the groups and group-ended are retired; the overview
showed the deliveries, another module's state, which the status view owns.
The overview keeps two sources (the tracker, the asks), consumes no merge,
transition or pipeline's end, and the progress verb asks no groups.

Builds: design 47 H §764 (the gate's verb groups; the runner's group-ended); H-A-28; H-A-125

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-20 06:04:16 +01:00

84 lines
3.3 KiB
Go

//go:build integration
package main
import (
"encoding/json"
"strconv"
"strings"
"testing"
"github.com/nats-io/nats.go"
)
// 1947/AC1: the knowledge base running whole, as the runtime launches it, answers progress over the bus: it reads
// design 47 through the records module, its milestones from the issue tracker (issue 1781), and asks the issue tracker and mesh-delivery on their seats' subjects,
// played here from what the live seats answered (testdata/progress).
func TestProgressOverTheBus(t *testing.T) {
w := newBusWorld(t)
seats := newSeatsWorld(t)
for _, key := range []string{"seat:issue-tracker.list", "seat:issue-tracker.get", MilestonesVerb, "seat:mesh-delivery.deliveries",
"seat:mesh-delivery.show"} {
key := key
if _, err := w.nc.Subscribe("ask."+key, func(m *nats.Msg) {
var body map[string]any
_ = json.Unmarshal(m.Data, &body)
out, err := seats.ask(key, body)
if err != nil {
_ = m.Respond([]byte(`{"error":` + strconv.Quote(err.Error()) + `}`))
return
}
raw, _ := json.Marshal(map[string]any{"result": json.RawMessage(out)})
_ = m.Respond(raw)
}); err != nil {
t.Fatal(err)
}
}
b, _ := w.start(t)
raw, err := b.call(Seat+".progress", map[string]any{"of": "design 47"})
if err != nil {
t.Fatal(err)
}
var p Progress
if err := json.Unmarshal(raw, &p); err != nil {
t.Fatal(err)
}
lines := strings.Split(p.Tree, "\n")
if len(raw) > DefaultBound || p.Detail != DetailMinimal || !strings.HasPrefix(lines[0], "✗ design 47 · Delivery: from a commit to delivered — ") ||
!strings.Contains(p.Tree, "✗ R6 4/7 1945 fixing since") || !strings.Contains(p.Source, "the issue tracker's milestone records of design 47") {
t.Fatalf("%d bytes:\n%s\n%v", len(raw), p.Tree, p.Warnings)
}
raw, err = b.call(Seat+".progress", map[string]any{"of": "milestone 47/R6", "detail": "detailed"})
if err != nil {
t.Fatal(err)
}
_ = json.Unmarshal(raw, &p)
for _, want := range []string{"✗ milestone 47/R6 · ", "▶ 1945 ", "jschoubben/car-hunter@cc4c8ce12901 ready since", "depends on 1943", "▶ 1946 "} {
if !strings.Contains(p.Tree, want) {
t.Errorf("detailed: no %q in\n%s", want, p.Tree)
}
}
// A window over the bus: since is taken and the answer says how many changes it holds (none moved in the captured rows).
raw, err = b.call(Seat+".progress", map[string]any{"of": "milestone 47/R6", "since": "60m"})
if err != nil {
t.Fatal(err)
}
_ = json.Unmarshal(raw, &p)
if !strings.HasPrefix(p.Tree, "0 changes in the last 60 min under milestone 47/R6 (since ") || p.Since != "1h0m0s" {
t.Errorf("since over the bus:\n%s", p.Tree)
}
if _, err := b.call(Seat+".progress", map[string]any{"of": "design 47", "since": "2d"}); err == nil {
t.Error("a window of two days was taken")
}
if _, err := b.call(Seat+".progress", map[string]any{"of": "design 47", "by": "someone@else"}); err == nil {
t.Error("an argument naming the caller was taken")
}
seats.mu.Lock()
defer seats.mu.Unlock()
// Each one more than progress asks: the bundle's overview page takes its first view once it is served (ServePage's
// Start, the tracker's list and milestones), whether or not it listens; nothing asks groups (design 47 H, H-A-125).
if seats.asked["seat:issue-tracker.list"] != 4 || seats.asked["seat:mesh-delivery.groups"] != 0 || seats.asked[MilestonesVerb] != 4 {
t.Fatalf("asked %v", seats.asked)
}
}