I3 needs-rules: each revision carries judge.NeedsRules, a take-in at a higher number derives the unmoved entries' needs from their manifests again

Builds: design 47 H2 H-A-569 (2), H-A-605 (4), H-A-586
This commit is contained in:
2026-11-25 17:21:35 +01:00
parent ca91d4e85b
commit 7f67e209e6
3 changed files with 66 additions and 1 deletions
@@ -2,10 +2,12 @@ package index
import (
"context"
"slices"
"testing"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"mesh-delivery-indexer/judge"
)
// Design 47 G A-85, §291, H §743, H-A-32: the indexer keeps a catalog revision per watched branch, <branch>.<source> (the
@@ -117,3 +119,37 @@ func TestTheRevisionAnswersEveryCaller(t *testing.T) {
t.Errorf("an unproven caller answered %+v, %v; want the revision", a, err)
}
}
// H-A-569 (2), H-A-605 (4): a take-in whose needs-rules equals its base revision's derives nothing for unmoved entries, and
// one with a higher number derives each from the manifest the entry carries, keeping its fingerprint.
func TestAHigherNeedsRulesDerivesTheUnmovedEntriesNeedsAgain(t *testing.T) {
ctx := context.Background()
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20)}
entry := meshcatalog.CatalogEntry{Module: "web", Repository: "novox/w", Commit: "c1", Fp: "src2:aa",
Manifest: map[string]any{"module": "web", "version": "1", "runs-as": "web"}}
if err := ix.KeepBranchEntries(ctx, "main", 1, map[string]meshcatalog.CatalogEntry{"web": entry}, nil); err != nil {
t.Fatal(err)
}
needsOf := func(source int64) ([]string, int64) {
a, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: "main", Source: source})
if err != nil || len(a.Entries) != 1 {
t.Fatalf("source %d answered %+v (%v)", source, a, err)
}
if a.Entries[0].Fp != "src2:aa" {
t.Errorf("the entry's fingerprint moved to %q", a.Entries[0].Fp)
}
return a.Entries[0].Needs, a.Revision.NeedsRules
}
if needs, rules := needsOf(1); rules != judge.NeedsRules || !slices.Contains(needs, "directory-contents-owner") {
t.Errorf("the first revision holds needs %v at rules %d, want the runs-as need at rules %d", needs, rules, judge.NeedsRules)
}
// The base was written at the same rules: the needs an entry carries are kept as they are.
kept := entry
kept.Needs = []string{"word:module"}
if err := ix.KeepBranchEntries(ctx, "main", 2, map[string]meshcatalog.CatalogEntry{"web": kept}, nil); err != nil {
t.Fatal(err)
}
if needs, _ := needsOf(2); !slices.Equal(needs, []string{"word:module"}) {
t.Errorf("a take-in at unchanged rules derived needs again: %v", needs)
}
}
@@ -20,6 +20,7 @@ import (
"git.novox.be/novox/mesh-sdk/go/keys"
"git.novox.be/novox/mesh-sdk/go/process"
"git.novox.be/novox/mesh-sdk/go/views"
"mesh-delivery-indexer/judge"
)
// The indexer's object bucket catalog-revisions (design 47, Two graphs; novox/hq ADR 0619 §2: declared in the old
@@ -379,9 +380,12 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
}
number := newest.Revision + 1
entries = WithEdges(ix.withActs(ctx, entries)) // the acting rules and the edges between artifact references are written here, once, for every reader (A-208)
if judge.NeedsRules > newest.NeedsRules {
entries = withRuleNeeds(entries, movers) // H-A-605 (4): the rules moved since the base, so each unmoved entry is read again
}
at := ix.now().UTC()
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: number, Kind: "trunk", Branch: branch, Source: src, Call: call.Call,
CallKind: call.Kind, Module: call.Module, Version: call.Version, Repository: call.Repository, At: &at}, entries)
NeedsRules: judge.NeedsRules, CallKind: call.Kind, Module: call.Module, Version: call.Version, Repository: call.Repository, At: &at}, entries)
if err != nil {
return 0, err
}
@@ -461,6 +465,26 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
return number, nil
}
// withRuleNeeds is entries with each unmoved entry's needs derived again from the manifest the entry carries whole, the
// manifest validator's rules as they stand (design 47 H2, H-A-569 (2), H-A-605 (4)): an entry gains the need a rule names
// now, keeps the ones it had and keeps its fingerprint, which no need moves. A mover's needs were derived at its take-in.
func withRuleNeeds(entries map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) map[string]meshcatalog.CatalogEntry {
moved := map[string]bool{}
for _, m := range movers {
moved[m.Module] = true
}
out := make(map[string]meshcatalog.CatalogEntry, len(entries))
for name, e := range entries {
if raw, err := json.Marshal(e.Manifest); !moved[name] && len(e.Manifest) > 0 && err == nil {
if derived, err := judge.ManifestNeeds(raw); err == nil {
e.Needs = slices.Compact(slices.Sorted(slices.Values(append(slices.Clone(e.Needs), derived...))))
}
}
out[name] = e
}
return out
}
// revisionCall is what made a catalog revision (design 47 H-A-213 (3), H-A-215): call, the words for a person; Kind, one of the
// seat mesh-catalog's three call kinds, which a reader reads instead of the words; Module and Version for a release, Repository
// for a take-in again. The zero value names no call (a revision kept by hand or a test).
@@ -19,6 +19,11 @@ import (
// manifest is read field by field through catalogue.Manifest, and a key is a word only where catalogue.ManifestReads()
// names its path; a unit test holds the two equal, so a difference fails.
// NeedsRules is the version of the validator's need rules (design 47 H2, H-A-569 (2), H-A-605 (4)): raised with every
// change of the rules that derive a need from a manifest. Each catalog revision the indexer writes carries it, and a
// take-in derives the rule needs of unmoved entries again only when its own is higher than its base revision's.
const NeedsRules = 1
// requirementLong is one entry of `requires` in its long form, as catalogue reads it.
type requirementLong struct {
Name string `json:"name"`