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
This commit is contained in:
@@ -45,11 +45,15 @@ func AsksOf(e catalog.CatalogEntry) (Asks, error) {
|
||||
return Asks{}, fmt.Errorf("the manifest of %s is not readable: %w", e.Module, err)
|
||||
}
|
||||
state := m.BusState
|
||||
// The old sections' entries are asked for too (design 47 H H-A-229, H-A-230), every manifest's, named and capped as
|
||||
// the grants part composes them.
|
||||
m.Module = cmp.Or(m.Module, e.Module)
|
||||
old := keeper.OldPlansOf(m)
|
||||
if e.Verdict != "" && e.Verdict != "accepted" {
|
||||
state = nil
|
||||
state, old = nil, nil
|
||||
}
|
||||
sum := sha256.Sum256(mustJSON(state))
|
||||
out := Asks{Accepted: keeper.Accepted{Module: e.Module, Digest: hex.EncodeToString(sum[:]), BusState: state},
|
||||
out := Asks{Accepted: keeper.Accepted{Module: e.Module, Digest: hex.EncodeToString(sum[:]), BusState: state, Old: old},
|
||||
EmitsOwn: len(m.Emits) > 0 || len(e.Streams) > 0}
|
||||
for _, c := range m.Claims {
|
||||
out.Claims = append(out.Claims, c.Name)
|
||||
@@ -81,7 +85,7 @@ type Branch struct {
|
||||
// branches in its registration's order (order: the registration's branches; a branch it does not name comes after, in
|
||||
// the order given) whose entry asks it; another branch asking that local name with other settings is a drift naming
|
||||
// the branch, and plans nothing. The module sends when a branch's entry says so; it is a foundation part, and its old
|
||||
// sections' caps are read, from the first branch.
|
||||
// sections' caps and entries are read, from the first branch (design 47 H H-A-229).
|
||||
func ViewOf(branches []Branch, order func(module string) []string) (keeper.CatalogView, error) {
|
||||
modules := map[string]bool{}
|
||||
for _, b := range branches {
|
||||
@@ -117,8 +121,8 @@ func ViewOf(branches []Branch, order func(module string) []string) (keeper.Catal
|
||||
return keeper.CatalogView{}, fmt.Errorf("the branch %s: %w", b.Name, err)
|
||||
}
|
||||
if i == 0 {
|
||||
cm = keeper.CatalogModule{Accepted: keeper.Accepted{Module: module, Digest: b.Entries[module].ManifestDigest, Revision: uint64(max(b.Revision, 0))},
|
||||
Foundation: a.Foundation, OldBytes: a.OldBytes}
|
||||
cm = keeper.CatalogModule{Accepted: keeper.Accepted{Module: module, Digest: b.Entries[module].ManifestDigest, Revision: uint64(max(b.Revision, 0)),
|
||||
Old: a.Accepted.Old}, Foundation: a.Foundation, OldBytes: a.OldBytes}
|
||||
}
|
||||
cm.EmitsOwn = cm.EmitsOwn || a.EmitsOwn
|
||||
for _, c := range a.Claims {
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
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) {
|
||||
@@ -22,6 +27,42 @@ func TestAsksOf(t *testing.T) {
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
// newest revision lists, each local name from the first of its watched branches in its registration's order whose entry
|
||||
// asks it, another branch asking it with other settings a drift naming that branch; a branch the registration does not
|
||||
// name after; a verdict not accepted asks nothing; the claims of every branch; a foundation part and its old sections'
|
||||
// caps from the first branch.
|
||||
// caps and entries from the first branch (design 47 H H-A-229).
|
||||
func TestTheCatalogHalfIsReadPerWatchedBranch(t *testing.T) {
|
||||
entryOf := func(verdict string, manifest map[string]any) catalog.CatalogEntry {
|
||||
manifest["module"] = "m"
|
||||
@@ -44,17 +44,17 @@ func TestTheCatalogHalfIsReadPerWatchedBranch(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{"one branch", []Branch{{Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": main}}}, []string{"main"},
|
||||
"m 3 [drafts/key-value/state] [a] false 0;"},
|
||||
"m 3 [drafts/key-value/state] [a] false 0 0;"},
|
||||
{"a feature branch asking a local name with other settings drifts, its new one planned",
|
||||
[]Branch{{Name: "feature", Revision: 9, Entries: map[string]catalog.CatalogEntry{"m": feature}}, {Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": main}}},
|
||||
[]string{"main", "feature"}, "m 3 [drafts/key-value/state log/stream/log] [a b] false 0; drifted m drafts feature from main"},
|
||||
[]string{"main", "feature"}, "m 3 [drafts/key-value/state log/stream/log] [a b] false 0 0; drifted m drafts feature from main"},
|
||||
{"the registration's order decides", []Branch{{Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": main}}, {Name: "feature", Revision: 9, Entries: map[string]catalog.CatalogEntry{"m": feature}}},
|
||||
[]string{"feature"}, "m 9 [drafts/key-value/state log/stream/log] [b a] false 0; drifted m drafts main from feature"},
|
||||
[]string{"feature"}, "m 9 [drafts/key-value/state log/stream/log] [b a] false 0 0; drifted m drafts main from feature"},
|
||||
{"a verdict not accepted asks nothing", []Branch{{Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": entryOf("refused", map[string]any{"bus-state": []any{state("")}})}}}, []string{"main"},
|
||||
"m 3 [] [] false 0;"},
|
||||
"m 3 [] [] false 0 0;"},
|
||||
{"a foundation part, its old sections counted", []Branch{{Name: "main", Revision: 3, Entries: map[string]catalog.CatalogEntry{"m": entryOf("accepted", map[string]any{
|
||||
"objects": []any{map[string]any{"name": "sent-objects", "max-mib": 256}}, "logs": []any{map[string]any{"name": "l", "max-mib": 4}}, "streams": []any{map[string]any{"name": "s"}}})}}}, []string{"main"},
|
||||
"m 3 [] [] true 1284;"},
|
||||
"m 3 [] [] true 1284 3;"},
|
||||
} {
|
||||
t.Run(row.name, func(t *testing.T) {
|
||||
v, err := ViewOf(row.branches, func(string) []string { return row.order })
|
||||
@@ -67,7 +67,7 @@ func TestTheCatalogHalfIsReadPerWatchedBranch(t *testing.T) {
|
||||
for _, e := range m.BusState {
|
||||
es = append(es, e.Name+"/"+e.Storage+"/"+e.Template)
|
||||
}
|
||||
got += fmt.Sprintf("%s %d [%s] %v %v %d;", m.Module, m.Revision, strings.Join(es, " "), m.Claims, m.Foundation, m.OldBytes/keeper.MiB)
|
||||
got += fmt.Sprintf("%s %d [%s] %v %v %d %d;", m.Module, m.Revision, strings.Join(es, " "), m.Claims, m.Foundation, m.OldBytes/keeper.MiB, len(m.Old))
|
||||
}
|
||||
for _, d := range v.Drifts {
|
||||
got += fmt.Sprintf(" drifted %s %s %s from %s", d.Module, d.Local, d.Branch, d.From)
|
||||
|
||||
Reference in New Issue
Block a user