Design 47 H1: a module entering the trunk's graph is registered at its take-in; the runner says registration-missing (H-A-262) #311
@@ -17,6 +17,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -380,7 +381,16 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
logger.Printf("start: %s", name)
|
||||
return func() { logger.Printf("start: %s done in %s", name, time.Since(began).Round(time.Millisecond)) }
|
||||
}
|
||||
done := step("reading the build log")
|
||||
// A module of the current trunk graph with no registration is registered once at the start, as a kept trunk revision
|
||||
// registers one entering the graph (design 47 H H-A-262, H-A-264 (1)); said loudly, whatever it answers.
|
||||
done := step("registering the trunk graph's modules that have no registration")
|
||||
if written, err := ix.RegisterTrunkGraph(ctx); err != nil {
|
||||
logger.Printf("start: the trunk graph's modules with no registration are not all registered (%d were): %v", len(written), err)
|
||||
} else {
|
||||
logger.Printf("start: %d modules of the trunk graph had no registration and are registered now: %s", len(written), strings.Join(written, ", "))
|
||||
}
|
||||
done()
|
||||
done = step("reading the build log")
|
||||
// The log's entries at the start are read before any fingerprint is computed (below).
|
||||
var started atomic.Bool
|
||||
var startEnds []stdio.LogEntry // the log's entries read at the start, whose imports are kept once the packages are published
|
||||
|
||||
@@ -446,6 +446,11 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int
|
||||
ix.sayFill(ctx, meshcatalog.EventFilling, fmt.Sprintf("%d", rev.Revision), meshcatalog.Fill{Bytes: after, Cap: capacity})
|
||||
}
|
||||
ix.logf("catalog graph: revision %d of source revision %d kept (%s), %d entries, %d changed", rev.Revision, src, call.Call, len(rev.Entries), len(changed))
|
||||
// A module entering the trunk's graph is registered before the revision is said, at every kind of kept trunk revision
|
||||
// (design 47 H H-A-262, H-A-264).
|
||||
if isTrunkBranch(branch) {
|
||||
ix.registerEntering(ctx, slices.Collect(maps.Values(entries)))
|
||||
}
|
||||
if ix.SayCatalogRevision != nil {
|
||||
if err := ix.SayCatalogRevision(ctx, meshcatalog.CatalogRevisionEvent{V: CatalogEntryLayout, Revision: rev.Revision, Kind: rev.Kind,
|
||||
Branch: keys.EscapeName(branch), Source: src, Call: call.Call, CallKind: call.Kind, Module: call.Module, Version: call.Version,
|
||||
|
||||
@@ -0,0 +1,246 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"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"
|
||||
)
|
||||
|
||||
// seedSteps are the seed's module-wide statuses (§8, design 47 H §745): the statuses the check judged until then, lint, unit
|
||||
// tests, integration tests, composition and validate required, code review optional, approval bypass.
|
||||
func seedSteps() meshcatalog.StepStatuses {
|
||||
return meshcatalog.StepStatuses{Lint: "required", Unit: "required", Integration: "required",
|
||||
Composition: "required", Review: "optional", Approval: "bypass", Validate: "required"}
|
||||
}
|
||||
|
||||
// GraphModule is a module of a trunk revision's module graph as its registration is composed when it enters the graph
|
||||
// (design 47 H H-A-262): its repository, the path of its manifest and the names of its artifacts.
|
||||
type GraphModule struct {
|
||||
Module string
|
||||
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.
|
||||
func GraphModulesOf(entries []meshcatalog.CatalogEntry) []GraphModule {
|
||||
out := make([]GraphModule, 0, len(entries))
|
||||
for _, e := range entries {
|
||||
m := GraphModule{Module: e.Module, Origin: e.Repository, Path: path.Join(e.Path, ModuleManifest)}
|
||||
for _, a := range e.Artifacts {
|
||||
m.Artifacts = append(m.Artifacts, artifactName(a.Ref))
|
||||
}
|
||||
out = append(out, m)
|
||||
}
|
||||
slices.SortFunc(out, func(a, b GraphModule) int { return strings.Compare(a.Module, b.Module) })
|
||||
return out
|
||||
}
|
||||
|
||||
// enteringPolicy is the policy of a module entering the graph (H-A-262, H-A-263): the module-wide steps every other
|
||||
// registered module of its repository holds alike, else the seed's; a per-artifact status only for an artifact name the module
|
||||
// has that every sibling naming it holds identically; nothing else.
|
||||
func enteringPolicy(m GraphModule, siblings []meshcatalog.Registration) meshcatalog.Policy {
|
||||
p := meshcatalog.Policy{Steps: seedSteps()}
|
||||
if len(siblings) > 0 {
|
||||
alike := true
|
||||
for _, s := range siblings[1:] {
|
||||
alike = alike && s.Policy.Steps == siblings[0].Policy.Steps
|
||||
}
|
||||
if alike {
|
||||
p.Steps = siblings[0].Policy.Steps
|
||||
}
|
||||
}
|
||||
for _, a := range m.Artifacts {
|
||||
var held []meshcatalog.StepStatuses
|
||||
for _, s := range siblings {
|
||||
if st, ok := s.Policy.Artifacts[a]; ok {
|
||||
held = append(held, st)
|
||||
}
|
||||
}
|
||||
if len(held) == 0 || slices.ContainsFunc(held[1:], func(st meshcatalog.StepStatuses) bool { return st != held[0] }) {
|
||||
continue
|
||||
}
|
||||
if p.Artifacts == nil {
|
||||
p.Artifacts = map[string]meshcatalog.StepStatuses{}
|
||||
}
|
||||
p.Artifacts[a] = held[0]
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// 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()
|
||||
// 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 listed: %w", err)
|
||||
}
|
||||
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 {
|
||||
have[reg.Module] = true
|
||||
byOrigin[reg.Origin] = append(byOrigin[reg.Origin], reg)
|
||||
}
|
||||
var written []string
|
||||
var errs []string
|
||||
for _, m := range entering {
|
||||
if have[m.Module] {
|
||||
continue
|
||||
}
|
||||
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)}}
|
||||
if err := r.write(ctx, "", p, reg, oc.Warrant{Ask: "module-graph"}); err != nil {
|
||||
errs = append(errs, fmt.Sprintf("%s: %v", m.Module, err))
|
||||
continue
|
||||
}
|
||||
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, branch)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return written, fmt.Errorf("the registrations of modules entering the module graph are not written: %s", strings.Join(errs, "; "))
|
||||
}
|
||||
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.
|
||||
func (ix *Indexer) registerEntering(ctx context.Context, entries []meshcatalog.CatalogEntry) {
|
||||
if ix.isDry || ix.Registry == nil || ix.Registry.Registrations == nil {
|
||||
return
|
||||
}
|
||||
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, ", "))
|
||||
}
|
||||
if err != nil {
|
||||
ix.logf("registrations: %v (H-A-262)", err)
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterTrunkGraph registers, once at the indexer's start, each module of the current trunk graph that has no registration
|
||||
// (H-A-264 (1)), as a kept trunk revision does; it answers the modules it registered.
|
||||
func (ix *Indexer) RegisterTrunkGraph(ctx context.Context) ([]string, error) {
|
||||
if ix.isDry || ix.Registry == nil || ix.Registry.Registrations == nil || ix.Revisions == nil {
|
||||
return nil, nil
|
||||
}
|
||||
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the newest trunk revision is not read: %w", err)
|
||||
}
|
||||
if !found {
|
||||
return nil, nil
|
||||
}
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
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 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; 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()
|
||||
g := newRegRig()
|
||||
var order []string
|
||||
say := g.r.Say
|
||||
g.r.Say = func(ctx context.Context, e meshcatalog.RegistrationChangedEvent) error {
|
||||
order = append(order, "registration-changed "+e.Module)
|
||||
return say(ctx, e)
|
||||
}
|
||||
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
|
||||
}
|
||||
entry := func(module, repo, dir string, artifacts ...string) meshcatalog.CatalogEntry {
|
||||
e := meshcatalog.CatalogEntry{Module: module, Repository: repo, Path: dir, Commit: "c1", Manifest: map[string]any{}}
|
||||
for _, a := range artifacts {
|
||||
e.Artifacts = append(e.Artifacts, meshcatalog.Artifact{Ref: module + ":" + a})
|
||||
}
|
||||
return e
|
||||
}
|
||||
keep := func(branch string, src int64, entries ...meshcatalog.CatalogEntry) {
|
||||
t.Helper()
|
||||
m := map[string]meshcatalog.CatalogEntry{}
|
||||
for _, e := range entries {
|
||||
m[e.Module] = e
|
||||
}
|
||||
if err := ix.KeepBranchEntries(ctx, branch, src, m, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// No registration held: the seed is the first writer, so a kept trunk revision registers nothing (H-A-264 (2)).
|
||||
ix.Registry = g.r
|
||||
keep("main", 1, entry("core", "novox/c", "go/core", "lib"))
|
||||
if regs, _ := g.r.RegistrationsAnswer(ctx, meshcatalog.RegistrationsInput{}); len(regs.Registrations) != 0 {
|
||||
t.Fatalf("with no registration held a trunk revision registered %v, want none: the seed writes the first", regs.Registrations)
|
||||
}
|
||||
|
||||
steps := meshcatalog.StepStatuses{Lint: "required", Unit: "required", Integration: "required", Composition: "required", Review: "optional", Approval: "bypass"}
|
||||
other := steps
|
||||
other.Lint = "optional"
|
||||
held := []meshcatalog.Registration{
|
||||
{Module: "core", Origin: "novox/c", Path: "go/core/module.json", Branches: []string{"stable"}, Policy: meshcatalog.Policy{Steps: steps,
|
||||
Artifacts: map[string]meshcatalog.StepStatuses{"lib": {Integration: "bypass"}, "files": {Lint: "bypass", Unit: "bypass"}}}},
|
||||
{Module: "tools", Origin: "novox/c", Path: "go/tools/module.json", Branches: []string{"stable"}, 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{"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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
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 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("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)
|
||||
if err != nil || !found {
|
||||
t.Fatalf("%s is not registered (%v)", module, err)
|
||||
}
|
||||
return r
|
||||
}
|
||||
lib2 := got("lib2")
|
||||
if lib2.Version != 1 || lib2.Origin != "novox/c" || lib2.Path != "go/lib2/module.json" || !slices.Equal(lib2.Branches, []string{"stable"}) {
|
||||
t.Errorf("lib2 registered as %+v, want version 1 from novox/c, go/lib2/module.json, watching stable, the branch its siblings watch first alike (H-A-266), not its default branch main", lib2)
|
||||
}
|
||||
if lib2.Policy.Steps != steps {
|
||||
t.Errorf("lib2's steps %+v, want its repository's modules' alike steps %+v (H-A-263)", lib2.Policy.Steps, steps)
|
||||
}
|
||||
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 || !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() || !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)
|
||||
}
|
||||
if len(g.asks) != 0 {
|
||||
t.Errorf("registering modules entering the graph asked %v, want no ask", g.asks)
|
||||
}
|
||||
wantOrder := []string{"registration-changed lib2", "registration-changed solo", "registration-changed x3", "catalog-revision main"}
|
||||
if !slices.Equal(order, wantOrder) {
|
||||
t.Errorf("said %v, want %v: each registration said before the revision", order, wantOrder)
|
||||
}
|
||||
|
||||
// A branch that is not the trunk registers none (H-A-264 (3)); a module that leaves the graph keeps its registration.
|
||||
keep("feature", 3, entry("feat", "novox/c", "go/feat", "lib"))
|
||||
keep("main", 4, entry("core", "novox/c", "go/core", "lib"))
|
||||
if _, found, _ := g.r.Registration(ctx, "feat"); found {
|
||||
t.Error("a revision of the branch feature registered feat, want only the trunk's")
|
||||
}
|
||||
got("lib2")
|
||||
|
||||
// At the start, a module of the current trunk graph with no registration is registered (H-A-264 (1)); again, none.
|
||||
ix.Registry = nil
|
||||
keep("main", 5, entry("core", "novox/c", "go/core", "lib"), entry("late", "novox/c", "go/late"))
|
||||
ix.Registry = g.r
|
||||
if written, err := ix.RegisterTrunkGraph(ctx); err != nil || !slices.Equal(written, []string{"late"}) {
|
||||
t.Fatalf("the start registered %v (%v), want late", written, err)
|
||||
}
|
||||
if written, err := ix.RegisterTrunkGraph(ctx); err != nil || len(written) != 0 {
|
||||
t.Errorf("a second start registered %v (%v), want none", written, err)
|
||||
}
|
||||
}
|
||||
@@ -74,9 +74,7 @@ func (r *Registry) ComposeSeed(modules []SeedModule) (SeedProposal, error) {
|
||||
return out, fmt.Errorf("the default branch of %s is not read: %s", m.Origin, b.Error)
|
||||
}
|
||||
reg := meshcatalog.Registration{Module: m.Module, Origin: m.Origin, Path: m.Path, Branches: []string{b.Branch},
|
||||
Policy: meshcatalog.Policy{Steps: meshcatalog.StepStatuses{Lint: "required", Unit: "required", Integration: "required",
|
||||
Composition: "required", Review: "optional", Approval: "bypass",
|
||||
Validate: "required"}}} // design 47 H §745: the step validate is required in every policy by default
|
||||
Policy: meshcatalog.Policy{Steps: seedSteps()}} // design 47 H §745: the step validate is required in every policy by default
|
||||
for _, a := range m.Artifacts {
|
||||
var s meshcatalog.StepStatuses
|
||||
if !slices.Contains(a.Steps, "lint") {
|
||||
|
||||
@@ -159,8 +159,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
|
||||
starter := &pipeline.Starter{Pipelines: store, Logf: logger.Printf, Say: say,
|
||||
Registration: rv.Registrations.Registration, Steps: busStepAsker{ctx: ctx, js: js, cred: cred}, Name: cred.Module,
|
||||
Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains),
|
||||
Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing}
|
||||
Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing,
|
||||
Findings: rv.Findings, Observer: cred.Module} // a mover waiting on its registration is registration-missing (H-A-262)
|
||||
hearer.AskSteps = starter.AskSteps
|
||||
hearer.RegistrationWaits = func() { starter.JudgeRegistrationMissing(store) } // at every end (H-A-265 (4))
|
||||
// Every ask but a test run's is bounded until its holder's first word (H-A-235, H-A-238), its bounds keys of the state
|
||||
// bounds.
|
||||
askBound, err := askUnansweredBound(getenv)
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
|
||||
condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
// RegistrationMissingKind is the runner's finding of a mover that waits on its module's registration (design 47 H H-A-262,
|
||||
// G A-327): scope module, id the module, raised while a mover of a running pipeline has no registration to place its steps
|
||||
// from, cleared when the registration arrives or no running pipeline still waits on it (H-A-265 (4)).
|
||||
const RegistrationMissingKind = "registration-missing"
|
||||
|
||||
// registrationMissingID is the finding's id: the module, escaped as a key's name is.
|
||||
func registrationMissingID(module string) string { return keys.EscapeName(module) }
|
||||
|
||||
// registrationMissing raises registration-missing of module, waited on by the pipeline key (H-A-262).
|
||||
func (s *Starter) registrationMissing(module, key string) {
|
||||
if s.Findings == nil {
|
||||
return
|
||||
}
|
||||
id := registrationMissingID(module)
|
||||
err := s.Findings.Write(context.Background(), condseat.Finding{Scope: mcc.ScopeModule, ID: id, Kind: RegistrationMissingKind,
|
||||
Severity: condseat.FindingSeverityWarning,
|
||||
Summary: fmt.Sprintf("%s has no registration: the pipeline %s waits on it for its steps", module, key),
|
||||
Headline: "A pipeline waits on a module's registration",
|
||||
Explanation: fmt.Sprintf("The pipeline %s moves %s, which has no registration, so none of its steps is placed (A-327). The indexer registers a module the take-in first lists (H-A-262); this is cleared when the registration of %s arrives.",
|
||||
key, module, module),
|
||||
Needs: "the registration of " + module,
|
||||
Source: "pipeline-runner." + RegistrationMissingKind, Observer: s.Observer, At: s.now(),
|
||||
Subject: condseat.Subject{Scope: mcc.ScopeModule, ID: id}})
|
||||
if err != nil {
|
||||
s.logf("the finding %s of %s is not written: %v", RegistrationMissingKind, module, err)
|
||||
}
|
||||
}
|
||||
|
||||
// registrationArrived clears registration-missing of module, saying why, when the findings hold it (H-A-262, H-A-265 (4)).
|
||||
func (s *Starter) registrationArrived(module, why string) {
|
||||
if s.Findings == nil {
|
||||
return
|
||||
}
|
||||
id := registrationMissingID(module)
|
||||
for _, f := range s.Findings.Held() {
|
||||
if f.Scope != mcc.ScopeModule || f.ID != id || f.Kind != RegistrationMissingKind {
|
||||
continue
|
||||
}
|
||||
if err := s.Findings.Clear(context.Background(), mcc.ScopeModule, id, RegistrationMissingKind, why); err != nil {
|
||||
s.logf("the finding %s of %s is not cleared: %v", RegistrationMissingKind, module, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// JudgeRegistrationMissing clears registration-missing of every module the registrations held now name, and of every module
|
||||
// no running pipeline still has an unplaced mover of (H-A-265 (4)): a pipeline that ended, failed (H-A-163) or cancelled,
|
||||
// with the mover still waiting leaves no finding behind. It is judged at a pipeline's end and in Waiting.
|
||||
func (s *Starter) JudgeRegistrationMissing(store Updater) {
|
||||
if s.Findings == nil {
|
||||
return
|
||||
}
|
||||
var modules []string
|
||||
for _, f := range s.Findings.Held() {
|
||||
if f.Scope != mcc.ScopeModule || f.Kind != RegistrationMissingKind {
|
||||
continue
|
||||
}
|
||||
module, err := keys.UnescapeName(f.ID)
|
||||
if err != nil {
|
||||
module = f.ID
|
||||
}
|
||||
if s.Registration != nil {
|
||||
if _, ok := s.Registration(module); ok {
|
||||
s.registrationArrived(module, "the registration of "+module+" arrived")
|
||||
continue
|
||||
}
|
||||
}
|
||||
modules = append(modules, module)
|
||||
}
|
||||
if len(modules) == 0 || store == nil {
|
||||
return
|
||||
}
|
||||
pkeys, err := allKeys(store)
|
||||
if err != nil {
|
||||
s.logf("the finding %s is not judged: the pipelines are not listed: %v", RegistrationMissingKind, err)
|
||||
return
|
||||
}
|
||||
waiting := map[string]bool{}
|
||||
for _, key := range pkeys {
|
||||
p, _, err := store.Get(key)
|
||||
if err != nil {
|
||||
s.logf("the finding %s is not judged: the pipeline %s is not read: %v", RegistrationMissingKind, key, err)
|
||||
return
|
||||
}
|
||||
if p.Outcome != seat.PipelineOutcomeRunning {
|
||||
continue
|
||||
}
|
||||
for _, m := range modules {
|
||||
if Moves(p, m) && !placed(p, m) {
|
||||
waiting[m] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, m := range modules {
|
||||
if !waiting[m] {
|
||||
s.registrationArrived(m, "no running pipeline still waits on the registration of "+m)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,6 +188,10 @@ type Starter struct {
|
||||
// RunTurn places a run on request whose turn in the queue came, from its candidate's newest revision (A-222); nil places
|
||||
// it at the runner's next start.
|
||||
RunTurn func(UnplacedRun)
|
||||
// Findings is the runner's finding writer, through which a mover waiting on its registration raises
|
||||
// registration-missing (H-A-262); Observer is the runner's own module name. nil raises none.
|
||||
Findings Findings
|
||||
Observer string
|
||||
}
|
||||
|
||||
// holderless ends at once, as it is placed, a pipeline with a build step whose seat the seat mesh-module-assigner's view
|
||||
@@ -528,6 +532,7 @@ func (s *Starter) Start(b Begin) (bool, error) {
|
||||
asks, unregistered, ended, notAsked = s.placeMovers(&p, s.Registration, b.Entries, now)
|
||||
for _, m := range unregistered {
|
||||
s.logf("%s: %s has no registration yet: its steps wait on its registration, which places them (A-327)", key, m)
|
||||
s.registrationMissing(m, key)
|
||||
}
|
||||
}
|
||||
if err := s.create(key, p); err != nil {
|
||||
@@ -667,6 +672,7 @@ func (s *Starter) Registered(store Updater, reg catalog.Registration, view func(
|
||||
if reg.Module == "" {
|
||||
return 0, nil
|
||||
}
|
||||
defer s.registrationArrived(reg.Module, "the registration of "+reg.Module+" arrived") // the finding of a mover that waited on it goes (H-A-262)
|
||||
return s.placeWaiting(store, func(p seat.Pipeline) bool { return Moves(p, reg.Module) && !placed(p, reg.Module) },
|
||||
func(module string) (catalog.Registration, bool) { return reg, module == reg.Module },
|
||||
view, "the registration of "+reg.Module+", which arrived after the pipeline started")
|
||||
@@ -680,6 +686,7 @@ func (s *Starter) Waiting(store Updater, branch string, view func(branch string)
|
||||
if s.Registration == nil {
|
||||
return 0, nil
|
||||
}
|
||||
defer s.JudgeRegistrationMissing(store) // the finding of a mover registered now, or no longer waited on, goes (H-A-262, H-A-265 (4))
|
||||
return s.placeWaiting(store, func(p seat.Pipeline) bool {
|
||||
if branch != "" && p.Branch != branch {
|
||||
return false
|
||||
@@ -732,6 +739,7 @@ func (s *Starter) placeWaiting(store Updater, due func(seat.Pipeline) bool, reg
|
||||
// and it holds the pipeline's end only while every placed mover's required steps passed (H-A-163, H-A-171).
|
||||
for _, m := range unregistered {
|
||||
s.logf("%s: %s has no registration yet: its steps wait on its registration, which places them (A-327)", key, m)
|
||||
s.registrationMissing(m, key)
|
||||
}
|
||||
if len(p.Steps) == before {
|
||||
continue
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
condseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -203,6 +204,8 @@ func TestAPipelineStartedBeforeItsRegistrationIsPlacedWhenItArrives(t *testing.T
|
||||
var said []string
|
||||
s := &Starter{Pipelines: store, Steps: asks, Name: "the-runner", Say: func(subject string, _ any) error { said = append(said, subject); return nil },
|
||||
Registration: func(m string) (catalog.Registration, bool) { return reg, registered && m == "app" }}
|
||||
findings := newHeld()
|
||||
s.Findings, s.Observer = findings, "the-runner"
|
||||
view := func(string) (Half, bool) { return Half{Entries: entries}, true }
|
||||
taken := catalog.TakeInTaken{Branch: "main", Source: 4, Entries: []catalog.TakeInEntry{{Module: "app", Commit: "c1", Fingerprint: "src2:aa"}}}
|
||||
if n, err := s.TakenIn(taken, view); n != 1 || err != nil {
|
||||
@@ -211,8 +214,15 @@ func TestAPipelineStartedBeforeItsRegistrationIsPlacedWhenItArrives(t *testing.T
|
||||
if p, _, _ := store.Get("main.4"); len(p.Steps) != 0 || len(asks.asks) != 0 {
|
||||
t.Fatalf("before its registration the pipeline has %d steps and %d asks, want none", len(p.Steps), len(asks.asks))
|
||||
}
|
||||
// H-A-262: the mover waiting on its registration is the finding registration-missing, scope module, id the module.
|
||||
if f, ok := findings.held["module.app."+RegistrationMissingKind]; !ok || f.Observer != "the-runner" || !strings.Contains(f.Summary, "main.4") {
|
||||
t.Fatalf("the mover waiting on its registration raised %v, want registration-missing of app naming main.4", findings.held)
|
||||
}
|
||||
registered = true
|
||||
n, err := s.Registered(store.memStore, reg, view)
|
||||
if _, ok := findings.held["module.app."+RegistrationMissingKind]; ok {
|
||||
t.Errorf("the registration of app arrived and its registration-missing is still held")
|
||||
}
|
||||
p, _, _ := store.Get("main.4")
|
||||
if n != 1 || err != nil || len(p.Steps) == 0 || len(asks.asks) == 0 || p.Outcome != seat.PipelineOutcomeRunning {
|
||||
t.Fatalf("the registration placed %d (%v): %d steps, %d asks, want the pipeline's steps placed and asked", n, err, len(p.Steps), len(asks.asks))
|
||||
@@ -303,6 +313,41 @@ func TestAPipelineStartedBeforeItsRegistrationIsPlacedWhenItArrives(t *testing.T
|
||||
if !slices.ContainsFunc(logged, func(l string) bool { return strings.Contains(l, "next.8: contracts has no registration yet") }) {
|
||||
t.Errorf("placing next.8 said %q, want that contracts waits on its registration (A-327)", logged)
|
||||
}
|
||||
// H-A-262: the mover still waiting is raised from the placing too, and cleared once the registrations held name it.
|
||||
if _, ok := findings.held["module.contracts."+RegistrationMissingKind]; !ok {
|
||||
t.Errorf("placing next.8 raised %v, want registration-missing of contracts", findings.held)
|
||||
}
|
||||
// H-A-265 (4): a pipeline that ends with the mover still waiting (failed, H-A-163) leaves no finding: judged at its end
|
||||
// (the hearer's said) and in Waiting, it clears once no running pipeline has an unplaced mover of the module.
|
||||
next8, rev8, _ := store.Get("next.8")
|
||||
next8.Outcome = seat.PipelineOutcomeFailed
|
||||
if _, err := store.Update("next.8", next8, rev8); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h := &Hearer{Store: store.memStore, Say: func(string, any) error { return nil }, RegistrationWaits: func() { s.JudgeRegistrationMissing(store.memStore) }}
|
||||
if err := h.said(next8, nil, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := findings.held["module.contracts."+RegistrationMissingKind]; ok {
|
||||
t.Errorf("next.8 ended with contracts unplaced and no other pipeline waits on it, yet its registration-missing is held")
|
||||
}
|
||||
// Still waited on by a running pipeline, it stays at an end; the registrations held naming it clear it in Waiting.
|
||||
findings.held["module.contracts."+RegistrationMissingKind] = condseat.Finding{Scope: "module", ID: "contracts", Kind: RegistrationMissingKind}
|
||||
taken = catalog.TakeInTaken{Branch: "next", Source: 9, Entries: []catalog.TakeInEntry{{Module: "contracts", Commit: "c5", Fingerprint: "src2:ff"}}}
|
||||
if n, err := s.TakenIn(taken, late); n != 1 || err != nil {
|
||||
t.Fatalf("the take-in of contracts started %d (%v)", n, err)
|
||||
}
|
||||
s.JudgeRegistrationMissing(store.memStore)
|
||||
if _, ok := findings.held["module.contracts."+RegistrationMissingKind]; !ok {
|
||||
t.Errorf("next.9 still waits on contracts' registration, yet its registration-missing was cleared")
|
||||
}
|
||||
s.Registration = func(string) (catalog.Registration, bool) { return reg, true }
|
||||
if _, err := s.Waiting(store.memStore, "", late); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := findings.held["module.contracts."+RegistrationMissingKind]; ok {
|
||||
t.Errorf("the registrations held name contracts and its registration-missing is still held")
|
||||
}
|
||||
}
|
||||
|
||||
// R1/AC1 (design 47 H §747): a start names an event, never a sweep. A take-in starts the pipelines of its own entries
|
||||
|
||||
@@ -147,6 +147,9 @@ type Hearer struct {
|
||||
Now func() time.Time
|
||||
// Failures says a failed head as the finding pipeline-failed (§33); nil says none.
|
||||
Failures *Failures
|
||||
// RegistrationWaits judges, at every pipeline's end, the finding registration-missing of the modules no running pipeline
|
||||
// still waits on (Starter.JudgeRegistrationMissing, H-A-265 (4)); nil judges none.
|
||||
RegistrationWaits func()
|
||||
// Ager ages the runner's own kept data at each step's end (§330); nil ages none.
|
||||
Ager *Ager
|
||||
// Fills says the stores' fill at each step's end (§366); nil says none.
|
||||
@@ -466,6 +469,9 @@ func (h *Hearer) said(p seat.Pipeline, asked []int, ended bool) error {
|
||||
}
|
||||
if ended {
|
||||
h.Failures.Ended(p)
|
||||
if h.RegistrationWaits != nil {
|
||||
h.RegistrationWaits()
|
||||
}
|
||||
err := h.say(seat.EventPipelineEnded, p, nil)
|
||||
// Every end, a cancel's alike, places the next waiting (§748, H-A-53), said or not.
|
||||
if h.Turn != nil {
|
||||
|
||||
Reference in New Issue
Block a user