diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go index b0e113b1..b7826e25 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go @@ -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, diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/named.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/named.go index 41d4a90f..46f39a95 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/named.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/named.go @@ -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 + } +} diff --git a/modules/mesh-delivery-indexer/internal/index/candidates.go b/modules/mesh-delivery-indexer/internal/index/candidates.go index 784258f4..592107ab 100644 --- a/modules/mesh-delivery-indexer/internal/index/candidates.go +++ b/modules/mesh-delivery-indexer/internal/index/candidates.go @@ -55,6 +55,9 @@ const writeTries = 8 // Indexer writes candidates. 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). diff --git a/modules/mesh-delivery-indexer/internal/index/pending.go b/modules/mesh-delivery-indexer/internal/index/pending.go index c2f9af9c..eddb515d 100644 --- a/modules/mesh-delivery-indexer/internal/index/pending.go +++ b/modules/mesh-delivery-indexer/internal/index/pending.go @@ -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 diff --git a/modules/mesh-delivery-indexer/internal/index/pending_test.go b/modules/mesh-delivery-indexer/internal/index/pending_test.go index 43f3cbfb..3a57a0dc 100644 --- a/modules/mesh-delivery-indexer/internal/index/pending_test.go +++ b/modules/mesh-delivery-indexer/internal/index/pending_test.go @@ -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 diff --git a/modules/mesh-delivery-indexer/internal/index/registered.go b/modules/mesh-delivery-indexer/internal/index/registered.go index a2903d16..ee59138f 100644 --- a/modules/mesh-delivery-indexer/internal/index/registered.go +++ b/modules/mesh-delivery-indexer/internal/index/registered.go @@ -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 +} diff --git a/modules/mesh-delivery-indexer/manifest_test.go b/modules/mesh-delivery-indexer/manifest_test.go index fa439b68..367e8d78 100644 --- a/modules/mesh-delivery-indexer/manifest_test.go +++ b/modules/mesh-delivery-indexer/manifest_test.go @@ -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 {