Indexer: take a registered module in at the head of its first watched branch when no build record names it: f1-circuits (master), link2pay and photos (nox-mesh) could not be held, so the assigner refused every proposal (design 47 G A-85)

This commit is contained in:
2026-11-14 21:45:27 +01:00
parent c9f70c9287
commit 5b0925ce3a
7 changed files with 79 additions and 8 deletions
@@ -460,7 +460,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
ix := &index.Indexer{Module: cred.Module, NamedSets: named, Findings: writer, OldSections: awaitedStore{b: oldSections}, Unjudged: awaitedStore{b: unjudged}, Requirements: awaitedStore{b: requirements}, Store: kvStore{candidates}, Modules: modules, Manifests: kvStore{manifests}, Taken: awaitedStore{b: taken}, Builds: known,
Verdicts: awaitedStore{b: verdicts}, SayRefused: sayRefused(conn, cred, logger.Printf), SayAccepted: sayAccepted(conn, cred),
Predefined: awaitedStore{b: predefined}, ConfigCandidates: awaitedStore{b: configCandidates}, Logf: logger.Printf,
Named: namedVia(calls.Call), Trunk: trunkVia(calls.Call), Contains: containsVia(calls.Call), Read: readVia(calls.Call),
Named: namedVia(calls.Call), Trunk: trunkVia(calls.Call), BranchHead: branchHeadVia(calls.Call), Contains: containsVia(calls.Call), Read: readVia(calls.Call),
ReadOpen: openVia(calls.Call), Packages: awaitedStore{b: packages, js: js, name: index.Bucket(cred.Module, index.PackagesState)}, Files: filesVia(calls.Call), GoSum: goSumVia(calls.Call), GoMod: goModVia(calls.Call),
OwnBuild: ownBuildVia(calls.Call, cred.Module, cred.Node), OwnBuildState: awaitedStore{b: ownBuildState}, Heard: heardStore, Placement: placementVia(calls.CallKept), RunningWhole: runningWholeVia(js), Runs: awaitedStore{b: runs}, Graph: graph,
SeatDefinitions: awaitedStore{b: seatDefs}, ReadFile: readFileVia(calls.Call), SaySeatDefinition: saySeats,
@@ -260,3 +260,14 @@ func openVia(call toolCaller) func(ctx context.Context) ([]forgemsg.OpenPull, er
return out, nil
}
}
// branchHeadVia is the head of a repository's branch through the seat git's verb branch.
func branchHeadVia(call toolCaller) func(ctx context.Context, repository, branch string) (string, error) {
return func(_ context.Context, repository, branch string) (string, error) {
var a git.BranchAnswer
if err := askGit(call, git.VerbBranch, git.BranchInput{Repository: repository, Branch: branch}, &a); err != nil {
return "", err
}
return a.Head, nil
}
}
@@ -55,6 +55,9 @@ const writeTries = 8
// Indexer writes candidates.<group> from the forge bridge's messages.
type Indexer struct {
// BranchHead is the head of a repository's branch, asked of the seat git's verb branch: TakeIn reads a module a
// registration names at its first watched branch's head (design 47 G A-85: the trunk is the first watched branch's).
BranchHead func(ctx context.Context, repository, branch string) (string, error)
// keptView replaces KeepView for a test that counts the writes of the view; nil in the program.
keptView func(context.Context) error
// Module is the indexer's own module, the credential's: the observer of its findings and the key of its own entry (design 47 G A-296).
@@ -948,7 +948,7 @@ func (ix *Indexer) dry() *dryRun {
}
d := &dryRun{}
x := &Indexer{Module: ix.Module, Manifests: ix.Manifests, Packages: ix.Packages, JudgeID: ix.JudgeID, Files: ix.Files, GoSum: ix.GoSum,
GoMod: ix.GoMod, Now: ix.Now, Builds: ix.Builds, Named: ix.Named, Trunk: ix.Trunk, Read: ix.Read, Contains: ix.Contains,
GoMod: ix.GoMod, Now: ix.Now, Builds: ix.Builds, Named: ix.Named, Trunk: ix.Trunk, BranchHead: ix.BranchHead, Read: ix.Read, Contains: ix.Contains,
ReadOpen: nil, OwnBuild: nil, Message: ix.Message, SayRefused: nil, SayAccepted: nil, SayTakeIn: nil, Pending: nil,
ValidationAsks: nil, AskVerb: nil, // a dry run asks no validation (§713)
// The registry milestone's fields: what a take-in would write on the bus stays out of a dry run, so the states of the
@@ -1150,11 +1150,32 @@ func TestTakeIn(t *testing.T) { // 1585/T3-T13 (ADR 0633)
}
}
})
t.Run("a registration is read at the head of its first watched branch", func(t *testing.T) {
// Design 47 G A-85: the trunk is the first watched branch's; photos is watched on nox-mesh alone (2026-11-14).
ctx := context.Background()
ix := &Indexer{Module: testSelf, Registry: &Registry{Registrations: MemoryStore()}, Logf: func(string, ...any) {}}
raw, _ := json.Marshal(meshcatalog.Registration{Module: "photos", Origin: "novox/photos", Path: "module.json", Branches: []string{"nox-mesh", "main"}})
if err := ix.Registry.Registrations.Create(ctx, RegistrationKey("photos"), raw); err != nil {
t.Fatal(err)
}
var asked string
ix.BranchHead = func(_ context.Context, repository, branch string) (string, error) {
asked = repository + "@" + branch
return strings.Repeat("a", 40), nil
}
r, why, ok := ix.registeredAtBranch(ctx, "photos")
if !ok || why != "" || asked != "novox/photos@nox-mesh" || r.Commit != strings.Repeat("a", 40) || r.Repository != "novox/photos" || r.Path != "." {
t.Errorf("registeredAtBranch(photos) = %+v %q %v, asked %s; want novox/photos at nox-mesh's head, at its root", r, why, ok, asked)
}
if _, why, ok := ix.registeredAtBranch(ctx, "unregistered"); ok || why != "" {
t.Errorf("an unregistered module answered %q %v, want neither", why, ok)
}
})
t.Run("the dry run names every field of the indexer", func(t *testing.T) {
// dry (pending.go) builds an indexer field by field: a field added to Indexer is named there, or this fails.
named := map[string]bool{}
for _, f := range []string{"Module", "Store", "Modules", "Manifests", "Predefined", "ConfigCandidates", "Taken", "Verdicts", "OldSections", "Unjudged",
"JudgeID", "SayRefused", "SayAccepted", "Packages", "Graph", "Files", "GoSum", "GoMod", "Now", "Builds", "Named", "Trunk",
"JudgeID", "SayRefused", "SayAccepted", "Packages", "Graph", "Files", "GoSum", "GoMod", "Now", "Builds", "Named", "Trunk", "BranchHead",
"Read", "Contains", "Logf", "ReadOpen", "OwnBuild", "Message", "Pending", "SayTakeIn",
"Requirements", "Findings", "SeatDefinitions", "ReadFile", "SaySeatDefinition", "Runs", "OwnBuildState", "Heard", "Placement", "RunningWhole", "Revisions", "SayCatalogRevision", "SayFill", "EntryIndex", "NamedSets", "Registry", "SeedModules", "Versions", "SayVersionReleased", "SayVersionsFilled", "Inputs", "InputObjects", "BuildEdges", "Pins", "PinsPending", "ValidationAsks", "AskVerb"} {
named[f] = true
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"maps"
"path"
"slices"
"strings"
@@ -237,11 +238,19 @@ func (ix *Indexer) TakeIn(ctx context.Context, module string) TakenIn {
if again, ok := ix.takeInHeld(ctx, module); ok {
return again
}
if ix.Builds == nil {
out.Answer = "the indexer reads no controller's build records, so it knows no registration"
return out
var regs []Registration
if ix.Builds != nil {
regs = ix.Builds.RegistrationsOf(module)
}
if len(regs) == 0 {
if r, why, ok := ix.registeredAtBranch(ctx, module); ok {
regs = []Registration{r}
} else if why != "" {
ix.logf("take-in of %s: %s", module, why)
out.Answer = why
return out
}
}
regs := ix.Builds.RegistrationsOf(module)
if len(regs) == 0 {
if key, err := meshcatalogclient.ModulesKey(module); err == nil && ix.Modules != nil {
if _, _, found, err := ix.Modules.Get(ctx, key); err == nil && found {
@@ -430,3 +439,30 @@ func (ix *Indexer) TakeInRepository(ctx context.Context, repository string) Take
out.Answer = fmt.Sprintf("%s at %.12s holds no module.json: taken in as a merge that leaves none; handed over %v, dropped %v", repository, head, out.Handed, out.Dropped)
return out
}
// registeredAtBranch is the module's registration (the seat mesh-catalog's, ADR 0666) read at the head of its first watched
// branch, which is its trunk (design 47 G A-85): a module from outside the indexed repositories, watched on main, master or
// a branch its owner chose (nox-mesh), is taken in from there when the controller's build records name none. why says what
// stopped it; none and not ok is no registration.
func (ix *Indexer) registeredAtBranch(ctx context.Context, module string) (Registration, string, bool) {
if ix.Registry == nil || ix.Registry.Registrations == nil || ix.BranchHead == nil {
return Registration{}, "", false
}
reg, found, err := ix.Registry.Registration(ctx, module)
if err != nil {
return Registration{}, fmt.Sprintf("the registration of %s cannot be read: %v", module, err), false
}
if !found {
return Registration{}, "", false
}
if len(reg.Branches) == 0 || reg.Origin == "" {
return Registration{}, fmt.Sprintf("the registration of %s names no repository or watched branch", module), false
}
branch := reg.Branches[0]
head, err := ix.BranchHead(ctx, reg.Origin, branch)
if err != nil || head == "" {
return Registration{}, fmt.Sprintf("the head of %s's branch %s cannot be read: %v", reg.Origin, branch, err), false
}
ix.logf("take-in of %s: registered from %s, read at the head %s of its first watched branch %s", module, reg.Origin, head, branch)
return Registration{Module: module, Repository: reg.Origin, Path: path.Dir(reg.Path), Commit: head, Ref: branch}, "", true
}
@@ -419,7 +419,7 @@ func TestEveryGiteaToolTheCodeCallsIsInInvokes(t *testing.T) {
if err != nil || len(files) == 0 {
t.Fatalf("no program files: %v", err)
}
verbs := map[string]string{"VerbTrees": git.VerbTrees, "VerbFile": git.VerbFile, "VerbContains": git.VerbContains, "VerbOpenPulls": git.VerbOpenPulls}
verbs := map[string]string{"VerbTrees": git.VerbTrees, "VerbFile": git.VerbFile, "VerbContains": git.VerbContains, "VerbOpenPulls": git.VerbOpenPulls, "VerbBranch": git.VerbBranch}
forge, asked := regexp.MustCompile(`gitea\.gitea_[a-z_]+`), regexp.MustCompile(`git\.Verb[A-Za-z]+`)
seen := 0
for _, f := range files {