diff --git a/modules/mesh-delivery-indexer/internal/index/registered.go b/modules/mesh-delivery-indexer/internal/index/registered.go index 248bc81..2ed1f30 100644 --- a/modules/mesh-delivery-indexer/internal/index/registered.go +++ b/modules/mesh-delivery-indexer/internal/index/registered.go @@ -11,8 +11,8 @@ import ( // A module registered in the catalogue from its own repository (the operator registers it with the repository and the // path of its manifest) had no manifest here: the indexer learns a repository only from a merged message, and no merge // followed the registration. The controller's outcome records name each registered module's repository, directory and -// commit (builds.go Registered), so the indexer reads that module's manifest writes the -// same keys a merge writes. A later merge to the repository's trunk reaches the module through the forge bridge's merged +// commit (builds.go Registered), so the indexer reads that module's manifest at the repository's head (the gate's source names it) or, with none named, at the +// registered commit, and writes the same keys a merge writes. A later merge to the repository's trunk reaches the module through the forge bridge's merged // message as for every other repository. // RepoRead is a repository at a commit as the forge bridge reads it for a merged message: the root tree, the tree of each @@ -25,7 +25,7 @@ type RepoRead struct { } // IndexRegistered writes the module of a registration as a merge of its repository would, when the modules bucket holds -// none of that name. Its commit is the registration's; a repository the gate's source names is left to the merges. The +// none of that name. Its commit is the head the gate's source names for the repository, else the registration's. The // repository's other modules are neither written nor dropped: they are the merges'. A manifest that is not at the path or // names another module is said and left. func (ix *Indexer) IndexRegistered(ctx context.Context, r Registration) error { @@ -48,19 +48,15 @@ func (ix *Indexer) IndexRegistered(ctx context.Context, r Registration) error { if dir == delivery.RootPath { dir = "" } - // A repository the gate's source names is the merges': an unheld module there was removed by a merge, or its record is - // stale, and reading the repository for it would cost a forge call for each such module at every start. + // The head the gate's source names for the repository, when it names one, else the registration's commit. A module a + // merge removed is absent at the head and is said and left. ix.mu.Lock() - owned := false - for repo := range ix.source.heads { - if delivery.SameRepository(repo, r.Repository) { - owned = true + for repo, head := range ix.source.heads { + if delivery.SameRepository(repo, r.Repository) && head != "" { + commit = head } } ix.mu.Unlock() - if owned { - return nil - } if repository == "" || commit == "" { ix.logf("%s: registered with no repository or commit, so its manifest is not read", r.Module) return nil diff --git a/modules/mesh-delivery-indexer/internal/index/registered_test.go b/modules/mesh-delivery-indexer/internal/index/registered_test.go index a6bca70..9098816 100644 --- a/modules/mesh-delivery-indexer/internal/index/registered_test.go +++ b/modules/mesh-delivery-indexer/internal/index/registered_test.go @@ -41,7 +41,7 @@ func TestARegisteredModuleIsIndexedFromItsRepository(t *testing.T) { // the gran read: RepoRead{Root: "r0", Trees: map[string]string{"": "t1"}, Manifests: map[string]string{"": snake}}}, {name: "a record of another branch", path: "", ref: "feat/x", read: RepoRead{Root: "r0", Trees: map[string]string{"": "t1"}, Manifests: map[string]string{"": snake}}}, - {name: "a repository the gate's source names is the merges'", path: "", heads: map[string]string{"jschoubben/snake": h2}, + {wantRead: true, name: "a repository the source names, the module unheld and present at the head", path: "", want: true, heads: map[string]string{"jschoubben/snake": h2}, read: RepoRead{Root: "r0", Trees: map[string]string{"": "t1"}, Manifests: map[string]string{"": snake}}}, {wantRead: true, name: "a forge that cannot say", path: "", err: errors.New("down")}, } { @@ -74,6 +74,13 @@ func TestARegisteredModuleIsIndexedFromItsRepository(t *testing.T) { // the gran if (err != nil) != (tc.err != nil) { t.Fatalf("error = %v", err) } + wantCommit := "7a74cee83f88e6585a5511c3cc53bdf0f5303d20" // the record's + if tc.heads != nil { + wantCommit = h2 // the source's head + } + if tc.wantRead && asked.sha != wantCommit { + t.Errorf("the forge was asked at %s, want %s", asked.sha, wantCommit) + } wantReads := 1 if !tc.wantRead { wantReads = 0 @@ -86,7 +93,7 @@ func TestARegisteredModuleIsIndexedFromItsRepository(t *testing.T) { // the gran } m, ok := moduleOf(t, mods, "snake") if tc.want { - if !ok || m.Manifest == "" || m.Repository != "jschoubben/snake" || m.Commit != "7a74cee83f88e6585a5511c3cc53bdf0f5303d20" || m.Path != pathOf(dirOf(tc.path)) { + if !ok || m.Manifest == "" || m.Repository != "jschoubben/snake" || m.Commit != wantCommit || m.Path != pathOf(dirOf(tc.path)) { t.Fatalf("modules.snake = %+v, found %v", m, ok) } if len(ix.Manifests.(*memStore).vals) != 1 {