Files
mesh-catalog/modules/nats/cmd/nats-tools/catalogview_test.go
T
jschoubben ec305f08e6 Design 47 H1: the bus module counts every manifest's old-section entries as asked for (H-A-229)
The keeper read only a manifest's new-form asks, so the entries it had made for the artifact
registry and the forge, now declared in their old sections, stood as orphans with live data: a
rebuild refused, a drop offered. The keeper now reads every manifest's old sections (state,
objects, logs, streams) by the SDK's naming per section, as the grants part composes them. An
entry it made under one of those bus names is no orphan, is compared and grown to the declared
cap and rebuilt on request; it creates none of them and says no created for one, and counts a
kept one's cap once, in the old sections' sum.

Builds: design 47 H H-A-229, H-A-230, H-A-231
2026-11-21 02:26:20 +01:00

70 lines
3.1 KiB
Go

package main
import (
"encoding/json"
"fmt"
"slices"
"testing"
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"nats-tools/internal/keeper"
)
func TestAsksOf(t *testing.T) {
m := map[string]any{"module": "m", "claims": []any{map[string]any{"name": "seat-a"}}, "emits": []any{"done"}}
a, err := AsksOf(catalog.CatalogEntry{Module: "m", Verdict: "accepted", Manifest: m})
if err != nil {
t.Fatal(err)
}
if len(a.Claims) != 1 || a.Claims[0] != "seat-a" || !a.EmitsOwn || a.Accepted.Module != "m" || a.Accepted.Digest == "" {
t.Errorf("read %+v", a)
}
b, _ := AsksOf(catalog.CatalogEntry{Module: "m", Manifest: map[string]any{"module": "m"}})
if b.EmitsOwn || len(b.Claims) != 0 {
t.Errorf("an entry with neither: %+v", b)
}
if b.Accepted.Digest != a.Accepted.Digest {
t.Errorf("the digest is of the bus-state asked alone: %s vs %s", b.Accepted.Digest, a.Accepted.Digest)
}
// Design 47 H H-A-229, H-A-230: the old sections of the artifact registry and the forge, as their manifests declare
// them, are asked for under the bus names the grants part gives them, the names the live orphans of 2026-11-21 hold;
// a manifest not accepted asks none.
for _, row := range []struct{ module, sections, want string }{
{"distribution", `{"state": ["transfers", {"name": "idle", "key-ttl": true}, "holds", "windows", "mirrors", "findings"],
"streams": [{"name": "distribution-events", "events": ["old-name-closed"], "max-age-days": 7, "max-mib": 16}],
"objects": [{"name": "incoming", "max-mib": 8192}]}`,
"[KV_distribution_transfers KV_distribution_idle KV_distribution_holds KV_distribution_windows KV_distribution_mirrors KV_distribution_findings OBJ_distribution_incoming DISTRIBUTION_EVENTS]"},
{"gitea", `{"state": ["bound", {"name": "idle", "key-ttl": true}, "transfers"], "objects": [{"name": "incoming", "max-mib": 2048}],
"logs": [{"name": "calls", "max-mib": 8}]}`,
"[KV_gitea_bound KV_gitea_idle KV_gitea_transfers OBJ_gitea_incoming LOG_gitea_calls]"},
} {
var m map[string]any
if err := json.Unmarshal([]byte(row.sections), &m); err != nil {
t.Fatal(err)
}
m["module"] = row.module
a, err := AsksOf(catalog.CatalogEntry{Module: row.module, Verdict: "accepted", Manifest: m})
if err != nil {
t.Fatal(err)
}
var names []string
for _, p := range a.Accepted.Old {
names = append(names, p.Objects[0].Stream())
}
if fmt.Sprint(names) != row.want {
t.Errorf("%s asks %v of its old sections, want %s", row.module, names, row.want)
}
i := slices.IndexFunc(a.Accepted.Old, func(p keeper.Plan) bool { return p.Local == "incoming" })
if i < 0 || a.Accepted.Old[i].Objects[0].Settings.MaxBytes != int64(m["objects"].([]any)[0].(map[string]any)["max-mib"].(float64))*keeper.MiB {
t.Errorf("%s's incoming is not capped as declared: %+v", row.module, a.Accepted.Old)
}
if n, _ := AsksOf(catalog.CatalogEntry{Module: row.module, Verdict: "refused", Manifest: m}); len(n.Accepted.Old) != 0 {
t.Errorf("a refused manifest of %s asks %v", row.module, n.Accepted.Old)
}
}
if _, err := AsksOf(catalog.CatalogEntry{}); err == nil {
t.Error("an entry with no module was read")
}
}