Design 47 H1: the graph skips a pending register, the seed's left-out, and reads the branch
Review round 1. A module with a register proposal pending is skipped (the operator's Approve registers it); a module the seed left out keeps seed-left-out and is not registered; the branch is the first watched branch the repository's registered modules hold alike, else its default branch read through the seat git, and a module whose default branch is not read is skipped and said, registered at the next kept trunk revision. One listing of the registrations finds the modules with none, so a revision whose modules are all registered reads no registration. Builds: design 47 H H-A-262, H-A-263, H-A-264, H-A-265, H-A-266
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
@@ -25,6 +26,9 @@ type GraphModule struct {
|
||||
Origin string
|
||||
Path string
|
||||
Artifacts []string
|
||||
// LeftOut says why the seed left the module out (its finding seed-left-out, A-324): such a module is not registered by
|
||||
// the graph (H-A-265 (2)). Empty: it is registered.
|
||||
LeftOut string
|
||||
}
|
||||
|
||||
// GraphModulesOf are the modules of a trunk revision's entries, sorted by module.
|
||||
@@ -73,23 +77,44 @@ func enteringPolicy(m GraphModule, siblings []meshcatalog.Registration) meshcata
|
||||
return p
|
||||
}
|
||||
|
||||
// RegisterEntering registers every module of mods that has no registration (design 47 H H-A-262, H-A-263; the operator,
|
||||
// 2026-11-14: a module in the module graph is a registration): origin its repository, path its manifest's, the first watched
|
||||
// branch, the policy of its repository's other registered modules (enteringPolicy), version 1 with no ask, said
|
||||
// registration-changed. A module already registered is left as it is; none is ever removed here. While no registration is
|
||||
// RegisterEntering registers every module of mods that has no registration (design 47 H H-A-262 to H-A-266; the operator,
|
||||
// 2026-11-14: a module in the module graph is a registration): origin its repository, path its manifest's, the branch its
|
||||
// repository's registered modules watch first alike, else the repository's default branch read through the seat git
|
||||
// (enteringBranch), the policy of its repository's other registered modules (enteringPolicy), version 1 with no ask, said
|
||||
// registration-changed. A module already registered is left as it is, and none is ever removed here. Skipped, each said in the
|
||||
// journal: a module with a register proposal pending (its ask stands, H-A-265 (1)), one the seed left out (LeftOut, H-A-265
|
||||
// (2)), and one whose default branch is not read (registered at the next kept revision, H-A-266). While no registration is
|
||||
// held it registers none: the seed writes the first (H-A-264 (2)). It answers the modules it registered, sorted.
|
||||
func (r *Registry) RegisterEntering(ctx context.Context, mods []GraphModule, by string) ([]string, error) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
held, err := r.RegistrationsAnswer(ctx, meshcatalog.RegistrationsInput{})
|
||||
// One listing finds the modules with no registration; the registrations themselves are read only when one has none.
|
||||
keys, err := r.Registrations.Keys(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the registrations are not read: %w", err)
|
||||
return nil, fmt.Errorf("the registrations are not listed: %w", err)
|
||||
}
|
||||
if len(held.Registrations) == 0 {
|
||||
if len(keys) == 0 {
|
||||
// With none held, the seed is the first and only writer: its policy reads the build seats' steps (H-A-264 (2)).
|
||||
r.logf("registrations: none is held, so no module entering the module graph is registered here: the seed writes the first (H-A-264)")
|
||||
return nil, nil
|
||||
}
|
||||
listed := map[string]bool{}
|
||||
for _, k := range keys {
|
||||
listed[k] = true
|
||||
}
|
||||
var entering []GraphModule
|
||||
for _, m := range mods {
|
||||
if m.Module != "" && !listed[RegistrationKey(m.Module)] {
|
||||
entering = append(entering, m)
|
||||
}
|
||||
}
|
||||
if len(entering) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
held, err := r.RegistrationsAnswer(ctx, meshcatalog.RegistrationsInput{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the registrations are not read: %w", err)
|
||||
}
|
||||
have := map[string]bool{}
|
||||
byOrigin := map[string][]meshcatalog.Registration{}
|
||||
for _, reg := range held.Registrations {
|
||||
@@ -98,11 +123,27 @@ func (r *Registry) RegisterEntering(ctx context.Context, mods []GraphModule, by
|
||||
}
|
||||
var written []string
|
||||
var errs []string
|
||||
for _, m := range mods {
|
||||
if m.Module == "" || have[m.Module] {
|
||||
for _, m := range entering {
|
||||
if have[m.Module] {
|
||||
continue
|
||||
}
|
||||
reg := meshcatalog.Registration{Module: m.Module, Origin: m.Origin, Path: m.Path, Branches: []string{TrunkBranch},
|
||||
if m.LeftOut != "" {
|
||||
r.logf("registrations: %s entered the module graph and is not registered: the seed left it out (%s), so it keeps seed-left-out (H-A-265)", m.Module, m.LeftOut)
|
||||
continue
|
||||
}
|
||||
if p, _, found, err := r.load(ctx, ProposalKey(verbRegister, m.Module, "")); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%s: its register proposal is not read: %v", m.Module, err))
|
||||
continue
|
||||
} else if found && p.State == ProposalOpen {
|
||||
r.logf("registrations: %s entered the module graph with a register proposal pending (ask %s): it is not registered here, the operator's Approve registers it (H-A-265)", m.Module, p.Ask)
|
||||
continue
|
||||
}
|
||||
branch, err := r.enteringBranch(m.Origin, byOrigin[m.Origin])
|
||||
if err != nil {
|
||||
r.logf("registrations: %s entered the module graph and is not registered now: %v; the next kept trunk revision registers it (H-A-266)", m.Module, err)
|
||||
continue
|
||||
}
|
||||
reg := meshcatalog.Registration{Module: m.Module, Origin: m.Origin, Path: m.Path, Branches: []string{branch},
|
||||
Policy: enteringPolicy(m, byOrigin[m.Origin])}
|
||||
p := Proposal{V: 1, Verb: verbRegister, Module: m.Module, Caller: by, At: r.now(), State: ProposalOpen,
|
||||
Lines: []string{fmt.Sprintf("%s: registered as it entered the module graph (%s, %s)", m.Module, m.Origin, m.Path)}}
|
||||
@@ -113,7 +154,7 @@ func (r *Registry) RegisterEntering(ctx context.Context, mods []GraphModule, by
|
||||
have[m.Module] = true
|
||||
written = append(written, m.Module)
|
||||
r.logf("registrations: %s entered the module graph of %s with no registration: registered as version 1 from %s (%s), watching %s (H-A-262)",
|
||||
m.Module, TrunkBranch, m.Origin, m.Path, TrunkBranch)
|
||||
m.Module, TrunkBranch, m.Origin, m.Path, branch)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return written, fmt.Errorf("the registrations of modules entering the module graph are not written: %s", strings.Join(errs, "; "))
|
||||
@@ -121,6 +162,35 @@ func (r *Registry) RegisterEntering(ctx context.Context, mods []GraphModule, by
|
||||
return written, nil
|
||||
}
|
||||
|
||||
// enteringBranch is the branch a module entering the graph watches (H-A-265 (3), H-A-266): the first watched branch every
|
||||
// registered module of its repository holds alike, else the repository's default branch as the seed reads it from the seat
|
||||
// git; an error when that is not read.
|
||||
func (r *Registry) enteringBranch(origin string, siblings []meshcatalog.Registration) (string, error) {
|
||||
first := ""
|
||||
alike := len(siblings) > 0
|
||||
for _, s := range siblings {
|
||||
if len(s.Branches) == 0 || (first != "" && s.Branches[0] != first) {
|
||||
alike = false
|
||||
break
|
||||
}
|
||||
first = s.Branches[0]
|
||||
}
|
||||
if alike && first != "" {
|
||||
return first, nil
|
||||
}
|
||||
if r.Branch == nil {
|
||||
return "", fmt.Errorf("the default branch of %s is not asked of the seat git", origin)
|
||||
}
|
||||
b, err := r.Branch(origin, "")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("the seat git does not answer the default branch of %s: %w", origin, err)
|
||||
}
|
||||
if b.Error != "" || b.Branch == "" {
|
||||
return "", fmt.Errorf("the default branch of %s is not read: %s", origin, b.Error)
|
||||
}
|
||||
return b.Branch, nil
|
||||
}
|
||||
|
||||
// registerEntering registers each module of a kept trunk revision's entries that has no registration (H-A-262, H-A-264 (1),
|
||||
// (3)): a module entering the trunk's graph, at any kind of kept trunk revision. A dry run, or an indexer with no
|
||||
// registrations, registers none. A failure is said in the journal: the revision is kept whatever it answers.
|
||||
@@ -128,7 +198,7 @@ func (ix *Indexer) registerEntering(ctx context.Context, entries []meshcatalog.C
|
||||
if ix.isDry || ix.Registry == nil || ix.Registry.Registrations == nil {
|
||||
return
|
||||
}
|
||||
written, err := ix.Registry.RegisterEntering(ctx, GraphModulesOf(entries), ix.Registry.Module)
|
||||
written, err := ix.Registry.RegisterEntering(ctx, ix.withLeftOut(GraphModulesOf(entries)), ix.Registry.Module)
|
||||
if len(written) > 0 {
|
||||
ix.logf("registrations: %d modules entering the module graph of %s registered: %s (H-A-262)", len(written), TrunkBranch, strings.Join(written, ", "))
|
||||
}
|
||||
@@ -150,5 +220,27 @@ func (ix *Indexer) RegisterTrunkGraph(ctx context.Context) ([]string, error) {
|
||||
if !found {
|
||||
return nil, nil
|
||||
}
|
||||
return ix.Registry.RegisterEntering(ctx, GraphModulesOf(entries), ix.Registry.Module)
|
||||
return ix.Registry.RegisterEntering(ctx, ix.withLeftOut(GraphModulesOf(entries)), ix.Registry.Module)
|
||||
}
|
||||
|
||||
// withLeftOut marks each module the indexer holds the finding seed-left-out of (A-324, H-A-265 (2)).
|
||||
func (ix *Indexer) withLeftOut(mods []GraphModule) []GraphModule {
|
||||
if ix.Findings == nil {
|
||||
return mods
|
||||
}
|
||||
left := map[string]string{}
|
||||
for _, f := range ix.Findings.Held() {
|
||||
if f.Kind == SeedLeftOutKind && f.Scope == mcc.ScopeModule {
|
||||
left[f.ID] = f.Summary
|
||||
}
|
||||
}
|
||||
for i := range mods {
|
||||
if why, ok := left[keyID(mods[i].Module)]; ok {
|
||||
if why == "" {
|
||||
why = "seed-left-out"
|
||||
}
|
||||
mods[i].LeftOut = why
|
||||
}
|
||||
}
|
||||
return mods
|
||||
}
|
||||
|
||||
@@ -2,18 +2,25 @@ package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
|
||||
|
||||
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
||||
)
|
||||
|
||||
// Design 47 H H-A-262, H-A-263, H-A-264 (ADR 0666 §2 read with the operator's rule of 2026-11-14): a module that enters a
|
||||
// watched trunk's module graph is registered as the revision is kept, before it is said, with no ask: origin its repository,
|
||||
// path its manifest's, the first watched branch, the module-wide steps its repository's other modules hold alike (else the
|
||||
// path its manifest's, the branch its repository's modules watch first alike (else its default branch), the module-wide steps its repository's other modules hold alike (else the
|
||||
// seed's) and a per-artifact status only where every sibling naming that artifact holds it identically, said
|
||||
// registration-changed. A module registered already is untouched, a branch that is not the trunk registers none, an indexer
|
||||
// registration-changed. A module registered already is untouched; one with a register proposal pending, one the seed left out
|
||||
// and one whose default branch is not read are skipped (H-A-265, H-A-266); a branch that is not the trunk registers none, an indexer
|
||||
// holding no registration leaves the first to the seed, and the start registers the current trunk graph's unregistered ones.
|
||||
func TestAModuleEnteringTheTrunkGraphIsRegistered(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
@@ -24,7 +31,19 @@ func TestAModuleEnteringTheTrunkGraphIsRegistered(t *testing.T) {
|
||||
order = append(order, "registration-changed "+e.Module)
|
||||
return say(ctx, e)
|
||||
}
|
||||
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), Now: g.r.Now}
|
||||
ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20), Findings: newFindings(), Now: g.r.Now}
|
||||
// The seat git's default branches: novox/new's is develop, novox/mixed's trunk, novox/broken's not read (H-A-266).
|
||||
g.r.Branch = func(repo, branch string) (gitseat.BranchAnswer, error) {
|
||||
switch repo {
|
||||
case "novox/new":
|
||||
return gitseat.BranchAnswer{Branch: "develop", Repository: repo}, nil
|
||||
case "novox/mixed":
|
||||
return gitseat.BranchAnswer{Branch: "trunk", Repository: repo}, nil
|
||||
case "novox/broken":
|
||||
return gitseat.BranchAnswer{}, errors.New("the forge does not answer")
|
||||
}
|
||||
return gitseat.BranchAnswer{Branch: "main", Repository: repo}, nil
|
||||
}
|
||||
ix.SayCatalogRevision = func(_ context.Context, e meshcatalog.CatalogRevisionEvent) error {
|
||||
order = append(order, "catalog-revision "+e.Branch)
|
||||
return nil
|
||||
@@ -63,7 +82,7 @@ func TestAModuleEnteringTheTrunkGraphIsRegistered(t *testing.T) {
|
||||
{Module: "tools", Origin: "novox/c", Path: "go/tools/module.json", Branches: []string{"main"}, Policy: meshcatalog.Policy{Steps: steps,
|
||||
Artifacts: map[string]meshcatalog.StepStatuses{"lib": {Integration: "bypass"}, "files": {Unit: "bypass"}}}},
|
||||
{Module: "x1", Origin: "novox/mixed", Path: "x1/module.json", Branches: []string{"main"}, Policy: meshcatalog.Policy{Steps: steps}},
|
||||
{Module: "x2", Origin: "novox/mixed", Path: "x2/module.json", Branches: []string{"main"}, Policy: meshcatalog.Policy{Steps: other}},
|
||||
{Module: "x2", Origin: "novox/mixed", Path: "x2/module.json", Branches: []string{"beta"}, Policy: meshcatalog.Policy{Steps: other}},
|
||||
}
|
||||
for _, reg := range held {
|
||||
if err := g.r.write(ctx, "", Proposal{V: 1, Verb: verbRegister, Module: reg.Module, Caller: "test", State: ProposalOpen}, reg, oc.Warrant{Ask: "test"}); err != nil {
|
||||
@@ -71,10 +90,19 @@ func TestAModuleEnteringTheTrunkGraphIsRegistered(t *testing.T) {
|
||||
}
|
||||
}
|
||||
g.events, order = nil, nil
|
||||
// pend has a register proposal pending (H-A-265 (1)); left was left out by the seed (A-324, H-A-265 (2)).
|
||||
pending, _ := json.Marshal(Proposal{V: 1, Verb: verbRegister, Module: "pend", Ask: "reg-1", State: ProposalOpen})
|
||||
if err := g.r.Proposals.Create(ctx, ProposalKey(verbRegister, "pend", ""), pending); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ix.Findings.Write(ctx, mcseat.Finding{Scope: mcc.ScopeModule, ID: keyID("left"), Kind: SeedLeftOutKind, Summary: "no build seat builds left:app"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// A take-in that lists three new modules beside a registered one.
|
||||
// A take-in that lists new modules beside a registered one.
|
||||
keep("main", 2, entry("core", "novox/c", "go/core", "lib"), entry("lib2", "novox/c", "go/lib2", "lib", "files", "bin"),
|
||||
entry("solo", "novox/new", "solo", "app"), entry("x3", "novox/mixed", "x3"))
|
||||
entry("solo", "novox/new", "solo", "app"), entry("x3", "novox/mixed", "x3"), entry("pend", "novox/c", "go/pend"),
|
||||
entry("left", "novox/c", "go/left", "app"), entry("lost", "novox/broken", "lost"))
|
||||
got := func(module string) meshcatalog.Registration {
|
||||
t.Helper()
|
||||
r, found, err := g.r.Registration(ctx, module)
|
||||
@@ -93,11 +121,16 @@ func TestAModuleEnteringTheTrunkGraphIsRegistered(t *testing.T) {
|
||||
if a := lib2.Policy.Artifacts; len(a) != 1 || a["lib"] != (meshcatalog.StepStatuses{Integration: "bypass"}) {
|
||||
t.Errorf("lib2's artifacts %+v, want lib alone, the one status its siblings hold identically (files differs, bin none)", a)
|
||||
}
|
||||
if solo := got("solo"); solo.Policy.Steps != seedSteps() || len(solo.Policy.Artifacts) != 0 {
|
||||
t.Errorf("solo, alone in its repository, has %+v, want the seed's default", solo.Policy)
|
||||
if solo := got("solo"); solo.Policy.Steps != seedSteps() || len(solo.Policy.Artifacts) != 0 || !slices.Equal(solo.Branches, []string{"develop"}) {
|
||||
t.Errorf("solo, alone in its repository, has %+v watching %v, want the seed's default, watching its default branch develop", solo.Policy, solo.Branches)
|
||||
}
|
||||
if x3 := got("x3"); x3.Policy.Steps != seedSteps() {
|
||||
t.Errorf("x3, whose siblings' steps differ, has %+v, want the seed's default", x3.Policy.Steps)
|
||||
if x3 := got("x3"); x3.Policy.Steps != seedSteps() || !slices.Equal(x3.Branches, []string{"trunk"}) {
|
||||
t.Errorf("x3, whose siblings' steps and branches differ, has %+v watching %v, want the seed's default, watching the default branch trunk", x3.Policy.Steps, x3.Branches)
|
||||
}
|
||||
for _, m := range []string{"pend", "left", "lost"} {
|
||||
if _, found, _ := g.r.Registration(ctx, m); found {
|
||||
t.Errorf("%s was registered, want it skipped: a pending proposal, the seed's left-out, a default branch not read", m)
|
||||
}
|
||||
}
|
||||
if core := got("core"); core.Version != 1 || core.By != "test" {
|
||||
t.Errorf("core, registered already, became %+v, want it untouched", core)
|
||||
|
||||
Reference in New Issue
Block a user