Merge branch 'fix/47-G-start-2-index' into fix/47-G-start-2

This commit is contained in:
2026-11-13 20:45:59 +01:00
8 changed files with 86 additions and 8 deletions
@@ -462,7 +462,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
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),
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,
OwnBuild: ownBuildFirst(process.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,
Revisions: revisions, EntryIndex: awaitedStore{b: process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.EntryIndexState), "no entry is found by its fingerprint", logger.Printf)}, // Message a kept call: a read, called again through a transport fault (ADR 0668 §1)
// Each catalog revision may bring another holder of a build seat: the build modules are found again (buildmodules.go).
@@ -7,6 +7,7 @@ import (
"fmt"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner"
"git.novox.be/novox/mesh-sdk/go/process"
"mesh-delivery-indexer/internal/index"
"slices"
"strings"
@@ -125,6 +126,25 @@ func TestTheTrunkIsTheDirectoriesTheForgeListsTrees(t *testing.T) { // 1900/AC3
t.Errorf("%s: own build = %q %v, want %q", row.name, fp, err, row.want)
}
}
// Design 47 G A-366: a process started with a fingerprint takes it and asks no engine; one started without asks the engine.
for _, row := range []struct {
name string
started process.Build
want string
wantAsked bool
}{
{"started with a fingerprint", process.Build{Fingerprint: "src2:env"}, "src2:env", false},
{"started without one", process.Build{Unknown: process.OwnBuildUnknown}, "src2:abc", true},
} {
called := false
ask := func(string, any) (json.RawMessage, error) {
called = true
return json.RawMessage(`{"runs":{"fp":"src2:abc"}}`), nil
}
if fp, err := ownBuildFirst(row.started, ownBuildVia(ask, "acme-indexer", "n1"))(context.Background()); err != nil || fp != row.want || called != row.wantAsked {
t.Errorf("%s: own build = %q %v, engine asked %v, want %q asked %v", row.name, fp, err, called, row.want, row.wantAsked)
}
}
none := func(string, any) (json.RawMessage, error) { return json.RawMessage(`{}`), nil }
if _, err := ownBuildVia(none, "acme-indexer", "n1")(context.Background()); err == nil {
t.Error("an engine that says nothing runs gave a build")
@@ -5,6 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"git.novox.be/novox/mesh-sdk/go/process"
)
// compositionVerb is the node-engine seat's read verb that says what runs of a module on a machine (its Runs.FP), asked of
@@ -12,6 +14,17 @@ import (
// from the trunk's value of itself or the haves bucket.
const compositionVerb = "seat:node-engine.composition"
// ownBuildFirst is the build the process was started with (mesh-sdk process.OwnBuild: MESH_FINGERPRINT, set by the node-engine
// and by a unit started by hand); only when it is unset does it ask the engine through ask (design 47 G A-366).
func ownBuildFirst(started process.Build, ask func(ctx context.Context) (string, error)) func(ctx context.Context) (string, error) {
return func(ctx context.Context) (string, error) {
if started.Fingerprint != "" {
return started.Fingerprint, nil
}
return ask(ctx)
}
}
// ownBuildVia asks the engine of node which fingerprint of the indexer runs there.
func ownBuildVia(call toolCaller, module, node string) func(ctx context.Context) (string, error) {
return func(context.Context) (string, error) {
@@ -7,6 +7,7 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
"mesh-delivery-indexer/internal/fingerprint"
)
@@ -32,12 +33,14 @@ type form struct {
// another repository its go.sum names, read as the indexer always read it (fingerprint.HeldVersionsOf), and the
// content of each mesh Go module of its own repository its go.mod replaces by a directory (fingerprint.VersionLine),
// so a change of that directory alone moves it (review finding 2). Its versions are the other repositories' alone.
// A package of another repository none of them publishes takes the commit the gate's source names for its repository
// (heads, design 47 G A-365).
// - **An accepted series** (DLV-I6): published and pins come from acceptedSeries, so a mesh Go module of another
// repository whose series the module accepts enters, in either form, by its series' newest published version and the
// digests of that version's commit.
//
// It sets kept.ImportForm when it writes the import form.
func formOf(module, repository string, kept *meshcatalog.ModulesByModuleValueInputs2, toolchains map[string]meshcatalogclient.Toolchain2, prev meshcatalog.ModulesByModuleValue, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, logf func(string, ...any)) form {
func formOf(module, repository string, kept *meshcatalog.ModulesByModuleValueInputs2, toolchains map[string]meshcatalogclient.Toolchain2, prev meshcatalog.ModulesByModuleValue, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, heads map[string]string, logf func(string, ...any)) form {
in := inputsFrom(module, *kept, toolchains)
if len(kept.Imports) > 0 {
r := fingerprint.Resolve(repository, kept.Imports, published)
@@ -71,6 +74,19 @@ func formOf(module, repository string, kept *meshcatalog.ModulesByModuleValueInp
unpublished = slices.DeleteFunc(unpublished, func(u string) bool { return u == p })
}
}
// A mesh Go package no module the indexer holds publishes is built at the commit the gate's source names for its
// repository, as an import of the same repository is; once a version is published, the version applies (design 47 G A-365).
for _, p := range slices.Clone(unpublished) {
if repo, _, ok := trunk.PackageRepository(p); ok {
if head := heads[repo]; len(head) == 40 {
if versions == nil {
versions = sdkstep.PackageVersions{}
}
versions[p] = head
unpublished = slices.DeleteFunc(unpublished, func(u string) bool { return u == p })
}
}
}
if len(unpublished) > 0 && logf != nil {
logf("%s: no module the indexer holds publishes %s, so its fingerprint takes no version of it", module, strings.Join(unpublished, ", "))
}
@@ -372,13 +372,35 @@ func anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain(t *
t.Fatalf("fingerprints again of a module not held answered stored: %+v", r)
}
})
t.Run("formOf builds a package no module publishes at the source's commit of its repository", func(t *testing.T) { // design 47 G A-365
head := strings.Repeat("c", 40)
contracts := "git.novox.be/novox/mesh-contracts/go/seats/findings"
held := map[string]meshcatalog.ModulesByModuleValue{"other": {Repository: "novox/mesh-sdk", Commit: strings.Repeat("d", 40), Path: "go"}}
for _, c := range []struct {
name string
heads map[string]string
held map[string]meshcatalog.ModulesByModuleValue
want string
}{
{"the source names its repository", map[string]string{"novox/mesh-contracts": head}, held, head},
{"the source names another repository only", map[string]string{"novox/mesh-sdk": head}, held, ""},
{"a module the indexer holds publishes it", map[string]string{"novox/mesh-contracts": head},
map[string]meshcatalog.ModulesByModuleValue{"c": {Repository: "novox/mesh-contracts", Commit: strings.Repeat("e", 40), Path: "go/seats/findings"}}, strings.Repeat("e", 40)},
} {
kept := meshcatalog.ModulesByModuleValueInputs2{Tree: "t", Packages: []string{contracts}}
f := formOf("avahi", "novox/mesh-catalog", &kept, nil, meshcatalog.ModulesByModuleValue{}, c.held, nil, nil, c.heads, nil)
if got := f.versions[contracts]; got != c.want {
t.Errorf("%s: version of %s = %q, want %q", c.name, contracts, got, c.want)
}
}
})
t.Run("formOf clears the import form when it writes the version line", func(t *testing.T) {
for _, c := range []struct {
name string
imports []string
}{{"an import no package holds", []string{meshSDK + "/announce"}}, {"no import reported", nil}} {
kept := meshcatalog.ModulesByModuleValueInputs2{Tree: "t", Imports: c.imports, ImportForm: "src2:" + strings.Repeat("a", 64)}
f := formOf("avahi", "novox/mesh-catalog", &kept, nil, meshcatalog.ModulesByModuleValue{}, nil, nil, nil, nil)
f := formOf("avahi", "novox/mesh-catalog", &kept, nil, meshcatalog.ModulesByModuleValue{}, nil, nil, nil, nil, nil)
if kept.ImportForm != "" {
t.Errorf("%s: kept import form %q after the version line %q", c.name, kept.ImportForm, f.fp)
}
@@ -319,7 +319,7 @@ func (ix *Indexer) candidateModule(ctx context.Context, m, dir string, pv meshde
published, pins = acceptedSeries(series, man, pv.Repository, published)
}
if len(inputs.Imports) > 0 && len(fingerprint.Resolve(pv.Repository, inputs.Imports, published).Missing) == 0 {
f := formOf(m, pv.Repository, &inputs, toolchains, trunkMod, held, published, pins, nil)
f := formOf(m, pv.Repository, &inputs, toolchains, trunkMod, held, published, pins, ix.sourceHeads(), nil)
fp, none, versions = f.fp, f.none, f.versions
} else {
inputs.Imports, inputs.ImportForm = nil, ""
@@ -39,6 +39,13 @@ func (ix *Indexer) srcOf(repository, merge string) uint64 {
return 0
}
// sourceHeads is the head the latest source seen names for each repository (a copy), nil while none has been seen.
func (ix *Indexer) sourceHeads() map[string]string {
ix.mu.Lock()
defer ix.mu.Unlock()
return maps.Clone(ix.source.heads)
}
// ApplySource takes the source revision the verb source answered in. An older revision than the latest seen is left. For each
// repository the source names, each module built from it whose fingerprint was computed at the head the source names, and
// that carries no Src yet, is written again with Src the revision (once: a later revision leaves it); a module computed at another commit is left (a merge heard later is stamped
@@ -288,11 +288,11 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
r.none = strings.Join(missing, "; ")
case noToolchain != "":
r.none = noToolchain
if fp, pkgs, ok := stillComputed(module, kept, k, toolchains, held, pub, pins); ok {
if fp, pkgs, ok := stillComputed(module, kept, k, toolchains, held, pub, pins, ix.sourceHeads()); ok {
r = result{fp: fp, tcs: k.held.Toolchains, pkgs: pkgs}
}
default:
f := formOf(module, k.cur.Repository, &kept, toolchains, k.held, held, pub, pins, ix.logf)
f := formOf(module, k.cur.Repository, &kept, toolchains, k.held, held, pub, pins, ix.sourceHeads(), ix.logf)
r.fp, r.none = f.fp, f.none
if r.fp != "" {
r.tcs, r.pkgs = toolchainsUsed(toolchains), f.versions
@@ -503,7 +503,7 @@ func hasContext(m catalogue.Manifest) bool {
// with the toolchains it was computed with in place of the languages agreed on none, give it again, in its form. Any
// other input that moved (a merge, a base, an agreed toolchain, an imported package) gives another fingerprint, and the
// module has none until they agree.
func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2, k *known, agreed map[string]meshcatalogclient.Toolchain2, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions) (string, sdkstep.PackageVersions, bool) {
func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2, k *known, agreed map[string]meshcatalogclient.Toolchain2, held map[string]meshcatalog.ModulesByModuleValue, published map[string]meshcatalog.PackagesByModuleValue, pins sdkstep.PackageVersions, heads map[string]string) (string, sdkstep.PackageVersions, bool) {
if k.held.Fp2 == "" {
return "", nil, false
}
@@ -519,7 +519,7 @@ func stillComputed(module string, kept meshcatalog.ModulesByModuleValueInputs2,
}
toolchains[artifact] = meshcatalogclient.Toolchain2{Language: language, Version: used.Version, Recipe: used.Recipe}
}
f := formOf(module, k.held.Repository, &kept, toolchains, k.held, held, published, pins, nil)
f := formOf(module, k.held.Repository, &kept, toolchains, k.held, held, published, pins, heads, nil)
return f.fp, f.versions, f.none == "" && f.fp == k.held.Fp2
}