diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/main.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/main.go index d0abc2afe..35b00ae57 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/main.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/main.go @@ -231,7 +231,7 @@ func main() { _, err := acts.Record(meshhandactsclient.Request{What: what, Why: why, Cause: index.FingerprintsAgainTool, Verb: "fingerprints-again"}) return err }, 10*time.Second)...) - tools = append(tools, configReadersTool(watched, trunk.State("modules")), busStateTool(trunk.State), requirementsTool(keptSource), + tools = append(tools, configReadersTool(watched, trunk.State("modules")), busStateTool(trunk.State), packageUsersTool(trunk.State), seatDefinitionTool(keptSource), outOfStepTool(os.Getenv(stdio.ServedAs), keptSource), index.ImportsReadTool(keptRead{stdio.State(index.ImportsState)})) if err := stdio.Serve("", tools); err != nil { diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/views.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/views.go index e1a041ac1..f7922ec81 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/views.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/views.go @@ -88,37 +88,6 @@ func busStateTool(state func(string) views.Source) stdio.Tool { }} } -// requirementsTool is indexer_requirements (REG S15; DLV-I7): the versions of one mesh Go module its consumers' go.sum -// files require, from the indexer's requirements state, kept at each merge. The builder's floor numbers no version below -// the highest. -func requirementsTool(state func(string) views.Source) stdio.Tool { - return stdio.Tool{Name: index.RequirementsTool, - Description: "The versions of one mesh Go module (its module path, as go.sum names it) that the trunk's consumers require: " + - "the highest each consumer's go.sum names, distinct, highest last, kept by the indexer at each merge. The builder " + - "numbers no version of the package below the highest.", - Input: map[string]any{"type": "object", "required": []string{"package"}, "properties": map[string]any{ - "package": map[string]any{"type": "string", "description": "the mesh Go module's path, such as git.novox.be/novox/mesh-sdk/go"}}}, - Run: func(args map[string]any) (any, error) { - pkg, _ := args["package"].(string) - if pkg == "" { - return nil, fmt.Errorf("%s names the package", index.RequirementsTool) - } - e, found, err := state(index.RequirementsState).Get(pkg) - if err != nil { - return nil, fmt.Errorf("the requirements state cannot be read: %w", err) - } - var value []byte - if found { - value = e.Value - } - versions, err := index.RequirementsOf(value, found) - if err != nil { - return nil, err - } - return map[string]any{"package": pkg, "requirements": versions}, nil - }} -} - // packageUsersTool is indexer_package_users (design 32 *A package, its series, and the series its users accept*; DLV-I8): // per package, its users and the series each accepts, read from the indexer's own states. func packageUsersTool(state func(string) views.Source) stdio.Tool { diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/floor_integration_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/floor_integration_test.go deleted file mode 100644 index 1f84a7417..000000000 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/floor_integration_test.go +++ /dev/null @@ -1,120 +0,0 @@ -//go:build integration - -package main - -import ( - "context" - "encoding/json" - "strings" - "sync/atomic" - "testing" - "time" - - "github.com/nats-io/nats.go" - "github.com/nats-io/nats.go/jetstream" - - "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/meshcatalog" - "git.novox.be/novox/mesh-sdk/go/busretry" - - "mesh-delivery-indexer/internal/index" -) - -// TestIndexerFillsTheFloorOfAModuleWithTags (design 47 G §412 as A-490c to A-490h amend it): the whole indexer on a real bus, the -// seat git and the package holders stood in. A module of the trunk with a Go package and no version in `versions` stays unfilled -// while the forge does not answer, and is filled from the highest of its tags and the holder's versions once the forge answers, -// with no restart and no catalog revision: the kept call gives up after its bound (one second here, so that it is spent before the -// forge answers) and the fill asks it again at once (A-490i, ADR 0668 §3). The finding after five minutes is in the unit tests (the -// five minutes are not waited for here). -func TestIndexerFillsTheFloorOfAModuleWithTags(t *testing.T) { - t.Cleanup(busretry.Waits(time.Second, 50*time.Millisecond, 200*time.Millisecond)) // the form gives up after one second - const pkg = "git.novox.be/novox/mesh-delivery/modules/" + testIndexer - var serveTags func() - var prefix atomic.Value - js, ctx, _, _ := startIndexer(t, func(context.Context, buildLog) {}, func(ctx context.Context, js jetstream.JetStream) { - for _, bucket := range []string{index.Bucket(testIndexer, index.VersionsState), index.Bucket(testIndexer, index.HeardState)} { - if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: bucket, History: 1}); err != nil { - t.Fatal(err) - } - } - // the module's artifacts are Go packages here, so that the indexer's own entries carry their names (read from go.mod, §676) - e := trunkIndexerEntryOf(t, ctx, js, func(raw []byte) []byte { - var m map[string]any - if err := json.Unmarshal(raw, &m); err != nil { - t.Fatal(err) - } - m["build"] = map[string]any{"artifacts": []any{map[string]any{"name": "go", "kind": "package", "language": "go"}}} - out, _ := json.Marshal(m) - return out - }) - for i := range e.Artifacts { - e.Artifacts[i].Package = &meshcatalog.ArtifactPackage{Ecosystem: index.EcosystemGo, Name: pkg} - } - seedBuildModules(t, ctx, js, map[string]meshcatalog.CatalogEntry{testIndexer: e}) - reply := func(m *nats.Msg, body map[string]any) { - body["node"] = "n0" - raw, _ := json.Marshal(body) - _ = m.Respond(raw) - } - serve := func(subject string, h func(m *nats.Msg)) { - if _, err := js.Conn().Subscribe(subject, h); err != nil { - t.Fatal(err) - } - } - // the forge answers no one until the test lets it (nobody serves the verb: a transport fault, which the kept call asks again) - serveTags = func() { - serve("mesh.seat.git.tool.tags", func(m *nats.Msg) { - var in git.TagsInput - _ = json.Unmarshal(m.Data, &in) - prefix.Store(in.Prefix) - reply(m, map[string]any{"result": git.TagsAnswer{Repository: in.Repository, Tags: []git.Tag{{Tag: in.Prefix + "0.4.2", Commit: strings.Repeat("a", 40)}, {Tag: in.Prefix + "0.4.10", Commit: strings.Repeat("b", 40)}, {Tag: "unrelated", Commit: strings.Repeat("c", 40)}}}}) - }) - } - // the package's name is read from the revision's own files (§676): its go.mod - serve("mesh.seat.git.tool.file", func(m *nats.Msg) { - var in git.FileInput - _ = json.Unmarshal(m.Data, &in) - if strings.HasSuffix(in.Path, "go.mod") { - reply(m, map[string]any{"result": git.FileAnswer{Path: in.Path, Ref: in.Ref, Content: "module " + pkg + "\n\ngo 1.26\n"}}) - return - } - reply(m, map[string]any{"result": git.FileAnswer{Path: in.Path, Ref: in.Ref, Absent: true}}) - }) - serve("mesh.seat.go-package-registry.tool.versions", func(m *nats.Msg) { - reply(m, map[string]any{"result": map[string]any{"name": pkg, "versions": []any{}}}) - }) - }) - versions, err := js.KeyValue(ctx, index.Bucket(testIndexer, index.VersionsState)) - if err != nil { - t.Fatal(err) - } - // the forge is asked at the start and does not answer: the form gives up and the module's clock is kept in the state heard - heard, err := js.KeyValue(ctx, index.Bucket(testIndexer, index.HeardState)) - if err != nil { - t.Fatal(err) - } - for deadline := time.Now().Add(30 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) { - if _, err := heard.Get(ctx, index.FloorSinceKey(testIndexer)); err == nil { - break - } - } - if _, err := heard.Get(ctx, index.FloorSinceKey(testIndexer)); err != nil { - t.Fatalf("the unanswered floor read of the module is not kept within 30 s: %v", err) - } - if keys, _ := versions.Keys(ctx); len(keys) != 0 { - t.Fatalf("versions holds %v while the forge does not answer, want nothing", keys) - } - serveTags() - var got []string - for deadline := time.Now().Add(30 * time.Second); time.Now().Before(deadline); time.Sleep(100 * time.Millisecond) { - if got, _ = versions.Keys(ctx); len(got) > 0 { - break - } - } - if len(got) != 1 || !strings.Contains(got[0], "0.4.10") { - t.Fatalf("versions holds %v within 30 s of the forge answering, want the floor 0.4.10 of its tags", got) - } - if p, _ := prefix.Load().(string); p != "modules/"+testIndexer+"/v" { - t.Errorf("the tags were read with the prefix %q, want the package's directory and /v", p) - } -} 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 2a9b11597..0bd5ff053 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go @@ -288,9 +288,6 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro // How many modules use each old section (issue 1966 D4): a state this delivery brings, bound when it appears; until then // the judge refuses no use of an old section. oldSections := process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.OldSectionsState), "the count of the old sections is not kept, so the judge refuses no use of one", logger.Printf) - // What each consumer's go.sum requires of each mesh Go module (DLV-I7): a state this delivery brings, bound when it - // appears; until then indexer_requirements answers none, and the builder's floor waits on its answer. - requirements := process.AwaitBucket(ctx, js, conn, index.Bucket(cred.Module, index.RequirementsState), "what consumers require is not kept", logger.Printf) // The module graph (ADR 0603 §2) is held in memory, read with the view: each revision's entries carry its nodes. // The state heard (A-80): the forge messages handled (key forge) and what the indexer heard and compares later (the time a call is // unanswered since, the newest toolchain-agreed, the artifacts published so far of a version). @@ -357,10 +354,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro logger.Printf("the state %s is not cleared at this start: %v", index.DryRunsState, err) } }) - ix := &index.Indexer{Module: cred.Module, TakeIns: awaitedStore{b: takeIns}, DryRuns: awaitedStore{b: dryRuns}, NamedSets: named, Findings: writer, OldSections: awaitedStore{b: oldSections}, Requirements: awaitedStore{b: requirements}, Store: kvStore{candidates}, Modules: modules, Manifests: kvStore{manifests}, Taken: awaitedStore{b: taken}, Builds: known, + ix := &index.Indexer{Module: cred.Module, TakeIns: awaitedStore{b: takeIns}, DryRuns: awaitedStore{b: dryRuns}, NamedSets: named, Findings: writer, OldSections: awaitedStore{b: oldSections}, Store: kvStore{candidates}, Modules: modules, Manifests: kvStore{manifests}, Taken: awaitedStore{b: taken}, Builds: known, Predefined: awaitedStore{b: predefined}, Logf: logger.Printf, Named: namedVia(calls.Call), Trunk: trunkVia(calls.Call), BranchHead: branchHeadVia(calls.Call), Contains: containsVia(calls.Call), Read: readVia(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), + Packages: awaitedStore{b: packages, js: js, name: index.Bucket(cred.Module, index.PackagesState)}, Files: filesVia(calls.Call), GoMod: goModVia(calls.Call), Heard: heardStore, Runs: awaitedStore{b: runs}, Graph: graph, // How long a reservation is kept and how long its gathering waits at most (design 47 H2 §805, H-A-424). ReservedKeep: durationSetting("reserved-keep", index.DefaultReservedKeep, logger.Printf), @@ -397,7 +394,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro defer sources.stop() named.Changed = ix.RemoveUnlisted // The first fill of the versions (design 47 G §372): at the start, and again at each catalog revision kept until it is made. - fill := &versionsFill{ix: ix, ctx: ctx, ask: versionsVia(calls.CallKeptWhileOpen, ix.ModuleInNewestView, logger.Printf), floor: index.FloorSources{Tags: tagsVia(calls.CallKept), Holder: holderVia(calls.CallKept)}, logf: logger.Printf} + fill := &versionsFill{ix: ix, ctx: ctx, ask: versionsVia(calls.CallKeptWhileOpen, ix.ModuleInNewestView, logger.Printf), logf: logger.Printf} fillFollow.Store(fill) fill.kick() ix.SeedModules = func(ctx context.Context) ([]index.SeedModule, error) { 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 98f5c2067..59dbf1c93 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/named.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/named.go @@ -137,13 +137,7 @@ func filesVia(call toolCaller) func(ctx context.Context, repository, sha string, } } -// goSumVia reads a module directory's go.sum at a commit: the version line's packages of a module whose build reported -// no imports (ADR 0593 §2). A directory with no go.sum answers nothing. -func goSumVia(call toolCaller) func(ctx context.Context, repository, sha, dir string) ([]byte, error) { - return goFileVia(call, "go.sum") -} - -// goModVia reads a module directory's go.mod at a commit, as goSumVia reads its go.sum: the directory replaces of its own +// goModVia reads a module directory's go.mod at a commit: the directory replaces of its own // repository the version line takes by their content (fingerprint.ReplacedSiblings). func goModVia(call toolCaller) func(ctx context.Context, repository, sha, dir string) ([]byte, error) { return goFileVia(call, "go.mod") diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/versions.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/versions.go index af3069a1f..2ecb27560 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/versions.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/versions.go @@ -5,21 +5,16 @@ import ( "encoding/json" "errors" "fmt" - "strings" "sync/atomic" "time" "github.com/nats-io/nats.go" "github.com/nats-io/nats.go/jetstream" - "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/gopackageregistry" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/npmpackageregistry" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk" "git.novox.be/novox/mesh-sdk/go/process" "mesh-delivery-indexer/internal/index" @@ -227,11 +222,10 @@ func versionsVia(call openCaller, inView func(ctx context.Context, module string // versionsFill is the first fill of the versions in the background (design 47 G §372): started at the start and at each // catalog revision kept, until it is made; one runs at a time, and a fill that fails is said and made again at the next. type versionsFill struct { - ix *index.Indexer - ctx context.Context - ask index.VersionsAsker - floor index.FloorSources // what the floor reads (A-490g); a nil reader fills none - logf func(string, ...any) + ix *index.Indexer + ctx context.Context + ask index.VersionsAsker + logf func(string, ...any) } func (f *versionsFill) kick() { @@ -240,28 +234,6 @@ func (f *versionsFill) kick() { f.logf("versions: the first fill waits: %v", err) } }() - go f.fillFloors() -} - -// fillFloors fills the floor of each module the versions hold none of, each on its own so that one unanswered read holds no other -// module's (A-490d, A-490f, A-490i): at every start and every revision, not waiting for the builder's half. A read is a kept call -// asked again until it answers, and the indexer holds no timer of its own (ADR 0437 §8). -func (f *versionsFill) fillFloors() { - if f.floor.Tags == nil && f.floor.Holder == nil { - return - } - modules, err := f.ix.FloorModules(f.ctx) - if err != nil { - f.logf("versions: the floor waits: %v", err) - return - } - for _, m := range modules { - go func() { - if err := f.ix.FillFloor(f.ctx, m, f.floor); err != nil { - f.logf("versions: the floor of %s waits for the next start or revision: %v", m, err) - } - }() - } } // afterRevision runs the fill's kick after each catalog revision kept, once the fill is set. @@ -274,51 +246,3 @@ func afterRevision(say func(context.Context, meshcatalog.CatalogRevisionEvent) e return err } } - -// tagsVia reads every tag of a repository that starts with a prefix from the seat git's verb tags as a kept call, page by -// page until none is more (design 47 G §412, A-490c: protected or not). -func tagsVia(call toolCaller) index.TagsReader { - return func(_ context.Context, repository, prefix string) ([]string, error) { - var out []string - for page := int64(1); ; page++ { - var a git.TagsAnswer - in := git.TagsInput{Repository: trunk.RepositoryName(repository), Prefix: prefix, Page: page} - if !strings.Contains(in.Repository, "/") { - return nil, fmt.Errorf("%q is not /", repository) - } - if err := askGit(call, git.VerbTags, in, &a); err != nil { - return nil, err - } - for _, t := range a.Tags { - out = append(out, t.Tag) - } - if !a.More { - return out, nil - } - } - } -} - -// holderVia reads the versions a package holder answers for a package: the seat npm-package-registry's or go-package-registry's -// verb versions (A-490g), as a kept call. -func holderVia(call toolCaller) index.HolderReader { - return func(_ context.Context, ecosystem, name string) ([]string, error) { - seat := npmpackageregistry.Seat - if ecosystem == index.EcosystemGo { - seat = gopackageregistry.Seat - } - raw, err := call("seat:"+seat+"."+npmpackageregistry.VerbVersions, npmpackageregistry.VersionsInput{Name: name, Kind: npmpackageregistry.ArtifactKindPackage}) - if err != nil { - return nil, err - } - var a npmpackageregistry.VersionsAnswer - if err := json.Unmarshal(raw, &a); err != nil { - return nil, fmt.Errorf("the answer of %s.versions is not a package's versions: %w", seat, err) - } - var out []string - for _, v := range a.Versions { - out = append(out, v.Version) - } - return out, nil - } -} diff --git a/modules/mesh-delivery-indexer/internal/index/candidates.go b/modules/mesh-delivery-indexer/internal/index/candidates.go index bb9ebb0f4..49fc716fb 100644 --- a/modules/mesh-delivery-indexer/internal/index/candidates.go +++ b/modules/mesh-delivery-indexer/internal/index/candidates.go @@ -61,11 +61,6 @@ type Indexer struct { // OldSections is the state of how many accepted modules use each old section (oldsections.go, issue 1966 D4); nil keeps no // count and the judge refuses no use of an old section. OldSections Store - // Requirements is the requirements state (requirements.go, DLV-I7): what each consumer's go.sum requires of each mesh - // Go module, kept at each merge; nil keeps none. - Requirements Store - reqMu sync.Mutex - reqKept map[string]bool // consumers whose go.sum this process kept (requirementsKept) // JudgeID names the judge a verdict says made it; empty is judge.Identity, the running program's. JudgeID string // Findings is the indexer's finding writer (design 47 G A-29), where a manifest-accepted whose publish failed twice is kept @@ -118,9 +113,6 @@ type Indexer struct { // with its git object id (the seat git's trees with files): the listing a package's digest is computed from. // Nil publishes no package. Files func(ctx context.Context, repository, sha string, dirs []string) (map[string]map[string]string, error) - // GoSum reads a module directory's go.sum at a commit (the seat git's file): the mesh Go modules a module with no - // reported import set takes the version line of. Nil reads none: such a module keeps what it held. - GoSum func(ctx context.Context, repository, sha, dir string) ([]byte, error) // GoMod reads a module directory's go.mod at a commit (the seat git's file): the mesh Go modules of its own // repository it replaces by a directory (fingerprint.ReplacedSiblings), which the version line takes by their // content; nil reads none. @@ -153,7 +145,6 @@ type Indexer struct { source sourceNow toolchains map[string]map[string]nodebuildgo.Toolchain // language, then node (toolchains.go) buildModules map[string]BuildModule // by language: the build modules whose toolchains are taken in (buildmodules.go) - floors sync.Map // the modules whose floor FillFloor reads now (tag_floor.go), one fill each versionsFilling atomic.Bool // a FillVersions runs (versions_fill.go) stepsSince map[string]time.Time // by build seat: since when its steps is unanswered (seed_steps.go) moving map[string]whole // by modules key: a merge naming a module another repository holds, waiting for that trunk to drop it (moves.go) diff --git a/modules/mesh-delivery-indexer/internal/index/control_records_test.go b/modules/mesh-delivery-indexer/internal/index/control_records_test.go index 2a16ce13a..a98fb8b47 100644 --- a/modules/mesh-delivery-indexer/internal/index/control_records_test.go +++ b/modules/mesh-delivery-indexer/internal/index/control_records_test.go @@ -74,33 +74,6 @@ func TestTheControlRecords(t *testing.T) { t.Errorf("indexer_bus_state = %+v (%v); want bad and cache, at the modules mark", got, err) } }) - // DLV-I7 (REG S15, the lead's ruling): the requirements state keeps, per mesh Go module, the highest version each - // consumer's go.sum names; a consumer no longer naming it leaves; indexer_requirements answers the distinct versions, - // highest last, a pseudo-version below the release it precedes. - t.Run("indexer_requirements", func(t *testing.T) { - ctx := context.Background() - ix := &Indexer{Module: testSelf, Requirements: newMem()} - sdk := "git.novox.be/novox/mesh-sdk/go" - sum := func(lines ...string) []byte { return []byte(strings.Join(lines, "\n")) } - ix.keepRequirements(ctx, "novox/a", "modules/x", sum( - sdk+" v0.1.14-0.20261103221822-85ba0a9a70d8 h1:x=", sdk+" v0.1.13/go.mod h1:y=", "github.com/other v1.0.0 h1:z=")) - ix.keepRequirements(ctx, "novox/b", ".", sum(sdk+" v0.1.14 h1:x=")) - ix.keepRequirements(ctx, "novox/c", ".", sum(sdk+" v0.1.14 h1:x=")) - value, _, found, _ := ix.Requirements.Get(ctx, sdk) - got, err := RequirementsOf(value, found) - if err != nil || !reflect.DeepEqual(got, []string{"v0.1.14-0.20261103221822-85ba0a9a70d8", "v0.1.14"}) { - t.Errorf("requirements = %v (%v)", got, err) - } - ix.keepRequirements(ctx, "novox/a", "modules/x", sum("github.com/other v1.0.0 h1:z=")) - ix.keepRequirements(ctx, "novox/b", ".", nil) - ix.keepRequirements(ctx, "novox/c", ".", nil) - if _, _, found, _ := ix.Requirements.Get(ctx, sdk); found { - t.Error("a package no consumer requires is still kept") - } - if got, _ := RequirementsOf(nil, false); got == nil || len(got) != 0 { - t.Errorf("none = %#v, want an empty list", got) - } - }) // DLV-I5 (milestone § 2 item 1, design 51 *The versions*): a package's series key keeps the newest trunk version the // builder numbered and the newest a seat published; an older one, a tagged one and one of another series move neither; // the per-module digests never read a series key. diff --git a/modules/mesh-delivery-indexer/internal/index/dryrun.go b/modules/mesh-delivery-indexer/internal/index/dryrun.go index 784501f81..3739de47a 100644 --- a/modules/mesh-delivery-indexer/internal/index/dryrun.go +++ b/modules/mesh-delivery-indexer/internal/index/dryrun.go @@ -50,7 +50,7 @@ func (ix *Indexer) dry(branch, call string) *dryRun { } else if packages != nil { packages = newOverlay(ix.Packages) } - x := &Indexer{Module: ix.Module, Manifests: ix.Manifests, Packages: packages, DryRuns: nil, JudgeID: ix.JudgeID, Files: ix.Files, GoSum: ix.GoSum, + x := &Indexer{Module: ix.Module, Manifests: ix.Manifests, Packages: packages, DryRuns: nil, JudgeID: ix.JudgeID, Files: ix.Files, GoMod: ix.GoMod, Now: ix.Now, Bound: ix.Bound, // A dry run keeps no waiting-on: the take-in it computes for says its waits through the live indexer (H-A-409). TakeIns: nil, Builds: ix.Builds, Named: ix.Named, Trunk: ix.Trunk, BranchHead: ix.BranchHead, Read: ix.Read, Contains: ix.Contains, @@ -58,7 +58,7 @@ func (ix *Indexer) dry(branch, call string) *dryRun { // 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 // requirements, findings, seat definitions, holds and their bounds are not overlaid, nothing is said, and no hold is // weighed (Holds and Counted nil hold nothing); ReadFile only reads. - Requirements: nil, Findings: nil, SeatDefinitions: nil, ReadFile: ix.ReadFile, SaySeatDefinition: nil, + Findings: nil, SeatDefinitions: nil, ReadFile: ix.ReadFile, SaySeatDefinition: nil, Heard: nil, underSeats: true, isDry: true, // A dry run keeps no catalog graph revision (catalog_revisions.go): its revision is the take-in's to keep. Revisions: nil, SayCatalogRevision: nil, SayFill: nil, EntryIndex: nil, NamedSets: nil, Versions: nil, SayVersionReleased: nil, SayVersionsFilled: nil, Inputs: nil, InputObjects: nil, Pins: nil, PinsPending: nil, diff --git a/modules/mesh-delivery-indexer/internal/index/finding_kinds_test.go b/modules/mesh-delivery-indexer/internal/index/finding_kinds_test.go index 070fc772a..ac1185369 100644 --- a/modules/mesh-delivery-indexer/internal/index/finding_kinds_test.go +++ b/modules/mesh-delivery-indexer/internal/index/finding_kinds_test.go @@ -193,7 +193,7 @@ func TestFindingKindsHoldEveryKindTheCodeRaises(t *testing.T) { } return false } - for _, id := range []string{keyID("node-build-go." + StepsVerb), keyID("node-build-image." + StepsVerb), keyID(floorKey("mesh-tools")), + for _, id := range []string{keyID("node-build-go." + StepsVerb), keyID("node-build-image." + StepsVerb), keyID("mesh-catalog.versions-floor.mesh-tools"), keyID(BuilderVersionsCall)} { if !covers(mcc.ScopeCall, id) { t.Errorf("the retired call-unanswered does not cover the indexer's id %s", id) diff --git a/modules/mesh-delivery-indexer/internal/index/findings.go b/modules/mesh-delivery-indexer/internal/index/findings.go index 05bc623be..5650469f0 100644 --- a/modules/mesh-delivery-indexer/internal/index/findings.go +++ b/modules/mesh-delivery-indexer/internal/index/findings.go @@ -32,7 +32,7 @@ var FindingKinds = []string{TakeInWaitingKind, PinMissingKind, OutOfStepKind, Pa // the seed's .steps (every build seat is named node-build-), the floor's mesh-catalog.versions-floor. // and the versions fill's mesh-delivery-builder.builder_versions. var RetiredFindingKinds = []views.RetiredKind{{Kind: "merge-untaken"}, {Kind: mcc.KindCallUnanswered, Scope: mcc.ScopeCall, - IDs: []string{keyID(BuilderVersionsCall)}, Prefixes: []string{"node-build-", keyID(FloorCall) + "."}}} + IDs: []string{keyID(BuilderVersionsCall)}, Prefixes: []string{"node-build-", keyID("mesh-catalog.versions-floor") + "."}}} // the floor went at design 47 H §756 // FindingWriter is the indexer's finding writer, mesh-sdk's held writer of the seat mesh-conditions' generated finding (design // 47 G A-29, A-38): Write raises a finding, Clear clears one, Held answers the findings it holds, so the indexer reads what diff --git a/modules/mesh-delivery-indexer/internal/index/modules.go b/modules/mesh-delivery-indexer/internal/index/modules.go index 7547cf191..a8cb0cec2 100644 --- a/modules/mesh-delivery-indexer/internal/index/modules.go +++ b/modules/mesh-delivery-indexer/internal/index/modules.go @@ -392,7 +392,6 @@ func (ix *Indexer) goPackages(ctx context.Context, f whole, dir string, cur mesh if f.Locks[dir]["go.sum"] == "" && len(f.Packages[dir]) == 0 { return nil } - ix.requirementsOf(ctx, f, dir, cur, has) goMod, read := ix.goModOf(ctx, f, dir) others := fingerprint.OtherPackages(f.Packages[dir], f.Repository) // carried: what the go.mod requires, read with the tree switch { @@ -431,26 +430,3 @@ func (ix *Indexer) goModOf(ctx context.Context, f whole, dir string) ([]byte, bo } return raw, true } - -// requirementsOf keeps what the go.sum of the merge's directory dir requires in the requirements state -// (keepRequirements): read from the forge (GoSum) when its hash moved, or this process has not kept it yet, whatever -// packages the reader carried. It gives no package: those are the go.mod's (H-A-157). -func (ix *Indexer) requirementsOf(ctx context.Context, f whole, dir string, cur meshcatalog.ModulesByModuleValue, has bool) { - hash := f.Locks[dir]["go.sum"] - if hash == "" || ix.GoSum == nil { - return - } - if has && cur.Inputs2 != nil && trunk.SameRepository(cur.Repository, f.Repository) && ix.requirementsKept(f.Repository, dir) { - for _, h := range cur.Inputs2.Locks { - if h == hash { - return - } - } - } - raw, err := waited(ctx, "git", "file", func() ([]byte, error) { return ix.GoSum(ctx, f.Repository, f.Merge, dir) }) - if err != nil { - ix.logf("%s at %s: the go.sum of %q cannot be read, so what it requires is not kept: %v", f.Repository, f.Merge, dir, err) - return - } - ix.keepRequirements(ctx, f.Repository, dir, raw) -} diff --git a/modules/mesh-delivery-indexer/internal/index/modules_test.go b/modules/mesh-delivery-indexer/internal/index/modules_test.go index 4851c23cd..e5748ce63 100644 --- a/modules/mesh-delivery-indexer/internal/index/modules_test.go +++ b/modules/mesh-delivery-indexer/internal/index/modules_test.go @@ -403,17 +403,13 @@ func TestARootModuleHasTheDirectoryDot(t *testing.T) { // 1615/AC3: empty means func TestAMergeAddingAModuleDirectoryWritesItsValueWithNoBuildRecordAnywhere(t *testing.T) { // I1: issue 1851, ADR 0501 clause 6 avahi := catalogueManifest(t, "avahi") // Its go.mod requires mesh-sdk at the zero version (ADR 0573 §2): the go.mod's require lines are its mesh packages, with - // no build, carried by the reader or read through GoMod (design 47 H-A-157). Its go.sum is still read for the - // requirements state, carried packages or not, so an older version it names is kept there (and cleared when gone). + // no build, carried by the reader or read through GoMod (design 47 H-A-157). No requirements state keeps its go.sum + // any more (design 47 H §756, H2 H-A-532 DQ-9). for _, carried := range [][]string{nil, {meshSDK}} { ix, mods, _ := manifestsIndexer(t) - ix.Requirements = newMem() ix.GoMod = func(context.Context, string, string, string) ([]byte, error) { return []byte("module avahi\n\nrequire " + meshSDK + " v0.0.0-00010101000000-000000000000\n"), nil } - ix.GoSum = func(context.Context, string, string, string) ([]byte, error) { - return []byte(meshSDK + " v0.1.14 h1:x=\n"), nil - } f := withManifests(mergedMsg(catalogueRepo, map[string]string{"modules/avahi": "newtree"}), map[string]string{"modules/avahi": avahi}, map[string]map[string]string{"modules/avahi": {"go.sum": avahiGoSum}}) if carried != nil { @@ -426,9 +422,6 @@ func TestAMergeAddingAModuleDirectoryWritesItsValueWithNoBuildRecordAnywhere(t * if m.Inputs2 == nil || !slices.Equal(m.Inputs2.Packages, []string{meshSDK}) { t.Errorf("carried %v: mesh packages %+v, want mesh-sdk, which its go.mod requires at the zero version", carried, m.Inputs2) } - if _, kept := ix.Requirements.(*memStore).vals[meshSDK]; !kept { - t.Errorf("carried %v: the requirements state holds no %s, which the go.sum names", carried, meshSDK) - } } ix, mods, _ := manifestsIndexer(t) // no build record of any module f := withManifests(mergedMsg(catalogueRepo, map[string]string{"modules/avahi": "newtree"}), map[string]string{"modules/avahi": avahi}, diff --git a/modules/mesh-delivery-indexer/internal/index/requirements.go b/modules/mesh-delivery-indexer/internal/index/requirements.go deleted file mode 100644 index f1b2ff04c..000000000 --- a/modules/mesh-delivery-indexer/internal/index/requirements.go +++ /dev/null @@ -1,228 +0,0 @@ -package index - -import ( - "context" - "encoding/json" - "fmt" - "maps" - "slices" - "strconv" - "strings" - - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk" - "git.novox.be/novox/mesh-sdk/go/keys" -) - -// The requirements state (DLV-I7, the lead's ruling on I7; REG S15, ADR 0606 §1): per mesh Go module, the highest -// version of it each consumer's go.sum names, filled at each merge from the directories whose go.sum the indexer reads. -// The builder's floor asks it through indexer_requirements, so a version is never numbered below what a consumer -// already requires. -const ( - RequirementsState = "requirements" - RequirementsTool = "indexer_requirements" -) - -// Requirement is the value of one package's key in the requirements state: By maps each consumer, ":", -// to the highest version of Package its go.sum names. -type Requirement struct { - V int `json:"v"` - Package string `json:"package"` - By map[string]string `json:"by"` -} - -// Versions are the distinct versions consumers require, highest last (CompareVersions). -func (r Requirement) Versions() []string { - seen := map[string]bool{} - for _, v := range r.By { - seen[v] = true - } - out := slices.Collect(maps.Keys(seen)) - slices.SortFunc(out, CompareVersions) - return out -} - -// RequiredOf is, per mesh Go module a go.sum names (a line under trunk.ForgeModulePrefix whose path names a repository), the highest version it -// names, its module line or its go.mod line alike. -func RequiredOf(goSum []byte) map[string]string { - out := map[string]string{} - for _, line := range strings.Split(string(goSum), "\n") { - f := strings.Fields(line) - if len(f) < 2 || !strings.HasPrefix(f[0], trunk.ForgeModulePrefix) { - continue - } - if _, _, ok := trunk.PackageRepository(f[0]); !ok { - continue - } - v := strings.TrimSuffix(f[1], "/go.mod") - if cur, ok := out[f[0]]; !ok || CompareVersions(cur, v) < 0 { - out[f[0]] = v - } - } - return out -} - -// CompareVersions orders two Go module versions as semantic versions (vMAJOR.MINOR.PATCH[-pre][+build]); a -// pseudo-version is a pre-release, so it sorts below the release it precedes. One that does not read sorts first. -func CompareVersions(a, b string) int { - pa, oka := semverParts(a) - pb, okb := semverParts(b) - switch { - case !oka || !okb: - if oka != okb { - if oka { - return 1 - } - return -1 - } - return strings.Compare(a, b) - } - for i := 0; i < 3; i++ { - if c := cmpNum(pa.core[i], pb.core[i]); c != 0 { - return c - } - } - switch { - case pa.pre == "" && pb.pre == "": - return 0 - case pa.pre == "": - return 1 - case pb.pre == "": - return -1 - } - xa, xb := strings.Split(pa.pre, "."), strings.Split(pb.pre, ".") - for i := 0; i < len(xa) && i < len(xb); i++ { - na, ea := strconv.ParseUint(xa[i], 10, 64) - nb, eb := strconv.ParseUint(xb[i], 10, 64) - switch { - case ea == nil && eb == nil: - if na != nb { - return cmpNum(na, nb) - } - case ea == nil: - return -1 - case eb == nil: - return 1 - default: - if c := strings.Compare(xa[i], xb[i]); c != 0 { - return c - } - } - } - return cmpNum(uint64(len(xa)), uint64(len(xb))) -} - -type semver struct { - core [3]uint64 - pre string -} - -func semverParts(v string) (semver, bool) { - var s semver - if !strings.HasPrefix(v, "v") { - return s, false - } - v, _, _ = strings.Cut(v[1:], "+") - core, pre, _ := strings.Cut(v, "-") - parts := strings.Split(core, ".") - if len(parts) != 3 { - return s, false - } - for i, p := range parts { - n, err := strconv.ParseUint(p, 10, 64) - if err != nil { - return s, false - } - s.core[i] = n - } - s.pre = pre - return s, true -} - -func cmpNum(a, b uint64) int { - switch { - case a < b: - return -1 - case a > b: - return 1 - } - return 0 -} - -// keepRequirements writes what the go.sum of repository's directory dir requires into the requirements state: each -// package it names gets the consumer's version, and a package it no longer names loses the consumer. nil -// Requirements keeps nothing. A write that fails is said in the log; the next merge of the directory writes it again. -func (ix *Indexer) keepRequirements(ctx context.Context, repository, dir string, goSum []byte) { - if ix.Requirements == nil { - return - } - consumer := repository + ":" + dir - ix.reqMu.Lock() - if ix.reqKept == nil { - ix.reqKept = map[string]bool{} - } - ix.reqKept[consumer] = true - ix.reqMu.Unlock() - required := RequiredOf(goSum) - held, err := ix.Requirements.Keys(ctx) - if err != nil { - ix.logf("requirements: the state cannot be listed, so what %s requires is not kept: %v", consumer, err) - return - } - for _, pkg := range slices.Sorted(maps.Keys(required)) { - if !slices.Contains(held, pkg) { - held = append(held, pkg) - } - } - for _, pkg := range held { - version, names := required[pkg] - err := write(ctx, ix.Requirements, pkg, func(value []byte, found bool) ([]byte, bool, error) { - r := Requirement{V: keys.Version, Package: pkg, By: map[string]string{}} - if found && json.Unmarshal(value, &r) != nil { - r = Requirement{V: keys.Version, Package: pkg, By: map[string]string{}} - } - if r.By == nil { - r.By = map[string]string{} - } - if cur, has := r.By[consumer]; names && cur == version || !names && !has { - return nil, false, nil - } - if names { - r.By[consumer] = version - } else { - delete(r.By, consumer) - } - if len(r.By) == 0 { - return nil, true, nil - } - next, err := json.Marshal(r) - return next, false, err - }) - if err != nil { - ix.logf("requirements: %s for %s is not kept: %v", pkg, consumer, err) - } - } -} - -// RequirementsOf answers indexer_requirements for one package from the state's value: the distinct versions its -// consumers require, highest last; none is an empty list. -func RequirementsOf(value []byte, found bool) ([]string, error) { - if !found { - return []string{}, nil - } - var r Requirement - if err := json.Unmarshal(value, &r); err != nil { - return nil, fmt.Errorf("the requirements value does not read: %w", err) - } - return r.Versions(), nil -} - -// requirementsKept says this process has kept what the directory's go.sum requires: until it has, the go.sum is read -// even where its hash is unchanged, so a consumer not merged since the state appeared is still kept at its next message. -func (ix *Indexer) requirementsKept(repository, dir string) bool { - if ix.Requirements == nil { - return true - } - ix.reqMu.Lock() - defer ix.reqMu.Unlock() - return ix.reqKept[repository+":"+dir] -} diff --git a/modules/mesh-delivery-indexer/internal/index/semver.go b/modules/mesh-delivery-indexer/internal/index/semver.go new file mode 100644 index 000000000..b3ae9f0aa --- /dev/null +++ b/modules/mesh-delivery-indexer/internal/index/semver.go @@ -0,0 +1,93 @@ +package index + +import ( + "strconv" + "strings" +) + +// CompareVersions orders two Go module versions as semantic versions (vMAJOR.MINOR.PATCH[-pre][+build]); a +// pseudo-version is a pre-release, so it sorts below the release it precedes. One that does not read sorts first. +func CompareVersions(a, b string) int { + pa, oka := semverParts(a) + pb, okb := semverParts(b) + switch { + case !oka || !okb: + if oka != okb { + if oka { + return 1 + } + return -1 + } + return strings.Compare(a, b) + } + for i := 0; i < 3; i++ { + if c := cmpNum(pa.core[i], pb.core[i]); c != 0 { + return c + } + } + switch { + case pa.pre == "" && pb.pre == "": + return 0 + case pa.pre == "": + return 1 + case pb.pre == "": + return -1 + } + xa, xb := strings.Split(pa.pre, "."), strings.Split(pb.pre, ".") + for i := 0; i < len(xa) && i < len(xb); i++ { + na, ea := strconv.ParseUint(xa[i], 10, 64) + nb, eb := strconv.ParseUint(xb[i], 10, 64) + switch { + case ea == nil && eb == nil: + if na != nb { + return cmpNum(na, nb) + } + case ea == nil: + return -1 + case eb == nil: + return 1 + default: + if c := strings.Compare(xa[i], xb[i]); c != 0 { + return c + } + } + } + return cmpNum(uint64(len(xa)), uint64(len(xb))) +} + +type semver struct { + core [3]uint64 + pre string +} + +func semverParts(v string) (semver, bool) { + var s semver + if !strings.HasPrefix(v, "v") { + return s, false + } + v, _, _ = strings.Cut(v[1:], "+") + core, pre, _ := strings.Cut(v, "-") + parts := strings.Split(core, ".") + if len(parts) != 3 { + return s, false + } + for i, p := range parts { + n, err := strconv.ParseUint(p, 10, 64) + if err != nil { + return s, false + } + s.core[i] = n + } + s.pre = pre + return s, true +} + +func cmpNum(a, b uint64) int { + switch { + case a < b: + return -1 + case a > b: + return 1 + } + return 0 +} diff --git a/modules/mesh-delivery-indexer/internal/index/tag_floor.go b/modules/mesh-delivery-indexer/internal/index/tag_floor.go deleted file mode 100644 index 33f454d84..000000000 --- a/modules/mesh-delivery-indexer/internal/index/tag_floor.go +++ /dev/null @@ -1,228 +0,0 @@ -package index - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "slices" - "strings" - "time" - - mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" - "git.novox.be/novox/mesh-sdk/go/busretry" - "git.novox.be/novox/mesh-sdk/go/keys" -) - -// The floor of the catalog's versions (design 47 G §412 as A-490c to A-490h amend it): for every module the state versions -// holds no version of, the highest version among every package its catalog entry names is its first version: the Go -// package's tags in the repository the entry was taken in from, read from the seat git's verb tags, protected or not -// (A-490c, A-490e), and what each package holder answers for the package through its seat's verb versions (A-490g). It is -// filled per module whenever the indexer starts and at each catalog revision kept, not once (A-490d, A-490f): the key -// versions-filled closes only the builder's half of the fill. - -// FloorCall is the id of the finding indexer-call-unanswered when a floor read (the forge's tags or a package holder's versions) is -// unanswered five minutes after the first (A-490h). -const FloorCall = "mesh-catalog.versions-floor" - -// TagsReader reads every tag of a repository that starts with prefix, all pages (the seat git's verb tags). -type TagsReader func(ctx context.Context, repository, prefix string) ([]string, error) - -// HolderReader reads the versions a package holder answers for a package of an ecosystem (EcosystemGo, EcosystemNpm) -// through its seat's verb versions (A-490g). -type HolderReader func(ctx context.Context, ecosystem, name string) ([]string, error) - -// FloorSources are what the floor reads: the forge's tags and each package holder's versions. -type FloorSources struct { - Tags TagsReader - Holder HolderReader -} - -// tagPrefixOf is the prefix Go gives the tags of a Go package in its repository (A-490e): the package's directory in the -// repository followed by "/v" ("go/v" for the sdk, whose Go module lives in go/), "v" at the root; none when the package's -// name does not lie in the repository. -func tagPrefixOf(repository string, a meshcatalog.Artifact) (string, bool) { - if a.Package == nil || a.Package.Ecosystem != EcosystemGo || repository == "" { - return "", false - } - i := strings.Index(a.Package.Name, "/"+repository) - if i < 0 { - return "", false - } - switch rest := a.Package.Name[i+1+len(repository):]; { - case rest == "": - return "v", true - case strings.HasPrefix(rest, "/"): - return rest[1:] + "/v", true - } - return "", false -} - -// FloorModules are the modules of the newest trunk revision the versions hold none of and that name a package a floor can be read -// of; each is filled by its own FillFloor, so one unanswered read holds no other module's floor (A-490i). -func (ix *Indexer) FloorModules(ctx context.Context) ([]string, error) { - if ix.Versions == nil || ix.Revisions == nil { - return nil, errors.New("the state versions or the catalog graph is not kept here") - } - _, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch) - if err != nil { - return nil, err - } - if !found { - return nil, errors.New("the indexer keeps no trunk revision yet: the floor waits for its first") - } - var out []string - for _, e := range entries { - if !slices.ContainsFunc(e.Artifacts, func(a meshcatalog.Artifact) bool { - return a.Package != nil && (a.Package.Ecosystem == EcosystemGo || a.Package.Ecosystem == EcosystemNpm) - }) { - continue - } - if have, err := ModuleVersions(ctx, ix.Versions, e.Module); err != nil { - return nil, err - } else if len(have) == 0 { - out = append(out, e.Module) - } - } - return out, nil -} - -// FillFloor fills one module's floor, the highest version among its packages' tags and holders' versions (A-490g). Its reads are -// kept calls made through mesh-sdk's form, which asks again through every transport fault; a read it gives up on (its own -// pause spent) is asked again at once, never given up, so the read has no bound (A-490i). The first unanswered try starts the -// module's clock: five minutes later the finding indexer-call-unanswered is written, and cleared when a read answers. A read the -// callee answered with a failure ends the fill, left for the next start or revision. One fill of a module runs at a time. -func (ix *Indexer) FillFloor(ctx context.Context, module string, src FloorSources) error { - if _, running := ix.floors.LoadOrStore(module, true); running { - return nil - } - defer ix.floors.Delete(module) - // Whatever way the fill ends but by the end of ctx, the module's call is no longer unanswered: it answered, or it left the - // trunk, or a release gave it a version, or the callee answered with a failure (ADR 0668 §3: the finding clears when the call - // is answered), and FloorModules never picks the module again to clear it. - defer func() { - if ctx.Err() == nil { - ix.floorAnswered(ctx, module) - } - }() - for ctx.Err() == nil { - entry, found, err := ix.newestEntry(ctx, module) - if err != nil || !found { - return err - } - if have, err := ModuleVersions(ctx, ix.Versions, module); err != nil || len(have) > 0 { - return err - } - first := ix.now() // the clock of the module's unanswered call starts at its try, not when the form gives up - top, err := ix.floorOf(ctx, entry, src) - if err == nil { - return ix.keepFloor(ctx, module, top) - } - if !busretry.Undelivered(err) && !busretry.TimedOut(err) { - return err // answered with a failure: the fill ends, said by the caller - } - ix.floorUnanswered(ctx, module, first, err) - } - return ctx.Err() -} - -func (ix *Indexer) newestEntry(ctx context.Context, module string) (meshcatalog.CatalogEntry, bool, error) { - _, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch) - if err != nil || !found { - return meshcatalog.CatalogEntry{}, false, err - } - for _, e := range entries { - if e.Module == module { - return e, true, nil - } - } - return meshcatalog.CatalogEntry{}, false, nil -} - -// floorOf reads the highest version of the entry's packages; "" when none is held. -func (ix *Indexer) floorOf(ctx context.Context, e meshcatalog.CatalogEntry, src FloorSources) (string, error) { - top := "" - take := func(vs []string, prefix string) { - for _, t := range vs { - if !strings.HasPrefix(t, prefix) { - continue - } - if v := strings.TrimPrefix(t, prefix); versionOK(v) && (top == "" || compareVersions(v, top) > 0) { - top = v - } - } - } - for _, a := range e.Artifacts { - if a.Package == nil { - continue - } - if prefix, ok := tagPrefixOf(e.Repository, a); ok && src.Tags != nil { - tags, err := src.Tags(ctx, e.Repository, prefix) - if err != nil { - return "", fmt.Errorf("the tags of %s: %w", e.Repository, err) - } - take(tags, prefix) - } - if (a.Package.Ecosystem == EcosystemGo || a.Package.Ecosystem == EcosystemNpm) && src.Holder != nil { - vs, err := src.Holder(ctx, a.Package.Ecosystem, a.Package.Name) - if err != nil { - return "", fmt.Errorf("the versions of %s %s: %w", a.Package.Ecosystem, a.Package.Name, err) - } - take(vs, "") - } - } - return top, nil -} - -func (ix *Indexer) keepFloor(ctx context.Context, module, top string) error { - if top == "" { - return nil - } - now := ix.now().UTC() - data, err := json.Marshal(meshcatalog.VersionEntry{V: int64(keys.Version), Module: module, Version: top, At: &now}) - if err != nil { - return err - } - if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey(module, top), data); err != nil && !errors.Is(err, ErrConflict) { - return fmt.Errorf("the floor %s %s is not kept: %w", module, top, err) - } - ix.logf("versions: %s has none, filled with %s, the highest of its packages' tags and holders' versions", module, top) - return nil -} - -func floorKey(module string) string { return FloorCall + "." + module } - -// FloorSinceKey is the key of the state heard that holds when a module's floor call was first unanswered. -func FloorSinceKey(module string) string { return floorSinceKey(module) } - -func floorSinceKey(module string) string { return "call-since." + keys.EscapeName(floorKey(module)) } - -// floorUnanswered writes indexer-call-unanswered once the module's floor read is unanswered five minutes (the time kept in the own state). -func (ix *Indexer) floorUnanswered(ctx context.Context, module string, first time.Time, cause error) { - now := ix.now() - since := ix.unansweredSince(ctx, floorSinceKey(module), first) - if ix.Findings == nil || now.Sub(since) < mcc.CallUnansweredAfter { - return - } - at := since.UTC().Format(time.RFC3339) - f := ix.observed(mcc.ScopeCall, floorKey(module), CallUnansweredKind, - fmt.Sprintf("the floor of %s's versions is unanswered since %s", module, at), - "A call whose answer is kept is not answered", - fmt.Sprintf("The floor of %s's versions reads the forge's tags and the package holders' versions; a read is not answered since %s (%v), so it has no version.", module, at, cause), - "indexer."+CallUnansweredKind) - if err := ix.Findings.Write(ctx, f); err != nil { - ix.logf("floor: the finding %s is not written: %v", floorKey(module), err) - } -} - -func (ix *Indexer) floorAnswered(ctx context.Context, module string) { - ix.answered(ctx, floorSinceKey(module)) - if ix.Findings != nil { - if err := ix.clearFinding(ctx, mcc.ScopeCall, floorKey(module), CallUnansweredKind, "the floor's reads answer"); err != nil { - ix.logf("floor: the finding %s is not cleared: %v", floorKey(module), err) - } - } -} - -func versionOK(v string) bool { _, ok := versionParts(v); return ok } diff --git a/modules/mesh-delivery-indexer/internal/index/versions_test.go b/modules/mesh-delivery-indexer/internal/index/versions_test.go index 8e7e2e663..9d1c14b7c 100644 --- a/modules/mesh-delivery-indexer/internal/index/versions_test.go +++ b/modules/mesh-delivery-indexer/internal/index/versions_test.go @@ -529,99 +529,9 @@ func TestAnInputIsDeletedAtTheStepEndedOfItsAsk(t *testing.T) { } } -// Design 47 G §412 as A-490c, A-490d and A-490e amend it: a module the versions hold none of is filled from the highest tag of its -// Go package in the repository it was taken in from, per module and not once; a forge that does not answer fills nothing and -// raises indexer-call-unanswered after five minutes. -func TestTheTagFloorFillsAModuleWithNoVersionFromItsGoTags(t *testing.T) { - ctx := context.Background() - now := time.Date(2026, 11, 19, 17, 0, 0, 0, time.UTC) - w := newFindings() - ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Findings: w, Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now }} - entries := map[string]meshcatalog.CatalogEntry{ - "mesh-sdk": {Module: "mesh-sdk", Repository: "novox/mesh-sdk", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{ - {Ref: "mesh-sdk:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}}, - {Ref: "mesh-sdk:ts", Package: &meshcatalog.ArtifactPackage{Ecosystem: "npm", Name: "@novox/mesh-sdk"}}}}, - "root": {Module: "root", Repository: "novox/root", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{ - {Ref: "root:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/root"}}}}, - "held": {Module: "held", Repository: "novox/held", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "held:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/held"}}}}, - "image": {Module: "image", Repository: "novox/image", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "image:image", Kind: "image"}}}, - } - rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 3, Kind: "trunk"}, entries) - if err != nil { - t.Fatal(err) - } - if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil { - t.Fatal(err) - } - if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey("held", "0.2.0"), []byte(`{"v":1,"module":"held","version":"0.2.0"}`)); err != nil { - t.Fatal(err) - } - tries := 0 - var asked []string - read := func(_ context.Context, repo, prefix string) ([]string, error) { - asked = append(asked, repo+" "+prefix) - if repo == "novox/mesh-sdk" { - // the forge does not answer the sdk's tags for six minutes, a minute at a time: the fill asks again, never gives up - tries++ - now = now.Add(time.Minute) - if tries == 5 && len(w.Held()) != 0 { - t.Error("the finding is written before five minutes from the first unanswered try") - } - if tries <= 6 { - return nil, errors.New("no responders available for request") - } - if len(w.Held()) != 1 || w.Held()[0].ID != FloorCall+".mesh-sdk" { - t.Errorf("the findings after six minutes: %+v", w.Held()) - } - return []string{"go/v0.1.9", "go/v0.1.16", "go/v0.1.12", "go/vnext"}, nil - } - if repo == "novox/root" { - return []string{"v1.2.3", "vendor-x"}, nil - } - return nil, nil - } - holder := func(_ context.Context, eco, name string) ([]string, error) { - if eco == "npm" && name == "@novox/mesh-sdk" { - return []string{"0.1.18", "0.1.17"}, nil // A-490g: the npm holder is above the Go tags - } - return nil, nil - } - src := FloorSources{Tags: read, Holder: holder} - modules, err := ix.FloorModules(ctx) - if err != nil { - t.Fatal(err) - } - if !slices.Equal(modules, []string{"mesh-sdk", "root"}) { - t.Fatalf("the modules with a floor to read: %v (held has a version, image no package)", modules) - } - // each module's floor is read on its own: root is filled whatever the sdk's read waits for - if err := ix.FillFloor(ctx, "root", src); err != nil { - t.Fatal(err) - } - if err := ix.FillFloor(ctx, "mesh-sdk", src); err != nil { - t.Fatal(err) - } - if len(w.Held()) != 0 { - t.Errorf("the finding stands after the forge answered: %+v", w.Held()) - } - if v, _ := ModuleVersions(ctx, ix.Versions, "mesh-sdk"); len(v) != 1 || v[0].Version != "0.1.18" { - t.Errorf("mesh-sdk's floor: %+v (the highest of its Go tags 0.1.16 and the npm holder's 0.1.18)", v) - } - if v, _ := ModuleVersions(ctx, ix.Versions, "root"); len(v) != 1 || v[0].Version != "1.2.3" { - t.Errorf("a root module's floor: %+v", v) - } - if v, _ := ModuleVersions(ctx, ix.Versions, "held"); len(v) != 1 || v[0].Version != "0.2.0" { - t.Errorf("a module with a version is filled: %+v", v) - } - for _, a := range asked { - if strings.HasPrefix(a, "novox/held") || strings.HasPrefix(a, "novox/image") { - t.Errorf("tags read for a module with a version or no Go package: %s", a) - } - } -} - // Design 47 G A-490h: a floor entry holds no artifacts, so the package-published heard later at its version is that version's -// release (the entry takes its artifacts and version-released is said), never dropped as released already. +// release (the entry takes its artifacts and version-released is said), never dropped as released already. The tag floor that +// wrote such entries is gone (design 47 H §756, H2 H-A-532 DQ-9); an entry it kept before is still read so. func TestAFloorEntryIsReplacedByThePublishHeardAtItsVersion(t *testing.T) { ctx := context.Background() now := time.Date(2026, 11, 19, 17, 0, 0, 0, time.UTC) @@ -640,8 +550,8 @@ func TestAFloorEntryIsReplacedByThePublishHeardAtItsVersion(t *testing.T) { if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil { t.Fatal(err) } - src := FloorSources{Tags: func(context.Context, string, string) ([]string, error) { return []string{"v0.3.0"}, nil }} - if err := ix.FillFloor(ctx, "mod", src); err != nil { + floor, _ := json.Marshal(meshcatalog.VersionEntry{V: 1, Module: "mod", Version: "0.3.0", At: &now}) + if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey("mod", "0.3.0"), floor); err != nil { t.Fatal(err) } if err := ix.HearPackagePublished(ctx, meshbuilds.PackagePublished{Module: "mod", Artifact: "mod:go", Version: "0.3.0", Digest: "sha256:aa", Branch: "main", Source: 5}); err != nil { @@ -652,63 +562,3 @@ func TestAFloorEntryIsReplacedByThePublishHeardAtItsVersion(t *testing.T) { t.Fatalf("the floor 0.3.0 and its publish: versions %+v, version-released said %d", v, len(said)) } } - -// ADR 0668 §3, design 47 G A-490i: the finding indexer-call-unanswered of a module's floor clears, with its call-since key, on every way the -// fill ends but the end of its context: a release gave the module a version, the module left the trunk, or the callee answered with a -// failure (FloorModules never picks the module again to clear it). -func TestTheFloorFindingClearsOnEveryExitOfTheFill(t *testing.T) { - for name, exit := range map[string]func(ctx context.Context, t *testing.T, ix *Indexer) error{ - "a release gave it a version": func(ctx context.Context, t *testing.T, ix *Indexer) error { - if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey("mod", "0.5.0"), []byte(`{"v":1,"module":"mod","version":"0.5.0","artifacts":[{"artifact":"mod:go"}]}`)); err != nil { - t.Fatal(err) - } - return errors.New("no responders available for request") - }, - "it left the trunk": func(ctx context.Context, t *testing.T, ix *Indexer) error { - rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 2, Kind: "trunk"}, map[string]meshcatalog.CatalogEntry{}) - if err != nil { - t.Fatal(err) - } - if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil { - t.Fatal(err) - } - return errors.New("no responders available for request") - }, - "the callee answered with a failure": func(context.Context, *testing.T, *Indexer) error { return errors.New("the forge refused") }, - } { - t.Run(name, func(t *testing.T) { - ctx := context.Background() - now := time.Date(2026, 11, 19, 17, 0, 0, 0, time.UTC) - w := newFindings() - ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Findings: w, Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now }} - entries := map[string]meshcatalog.CatalogEntry{"mod": {Module: "mod", Repository: "novox/mod", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{ - {Ref: "mod:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mod"}}}}} - rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 1, Kind: "trunk"}, entries) - if err != nil { - t.Fatal(err) - } - if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil { - t.Fatal(err) - } - tries := 0 - read := func(context.Context, string, string) ([]string, error) { - tries++ - now = now.Add(time.Minute) - if tries <= 6 { - return nil, errors.New("no responders available for request") - } - if len(w.Held()) != 1 { - t.Fatalf("the finding is not written before the exit: %+v", w.Held()) - } - return nil, exit(ctx, t, ix) - } - _ = ix.FillFloor(ctx, "mod", FloorSources{Tags: read}) - if h := w.Held(); len(h) != 0 { - t.Errorf("the finding stands after the fill ended: %+v", h) - } - if _, _, found, _ := ix.Heard.Get(ctx, FloorSinceKey("mod")); found { - t.Error("the call-since key stands after the fill ended") - } - }) - } -} diff --git a/modules/mesh-delivery-indexer/manifest_test.go b/modules/mesh-delivery-indexer/manifest_test.go index 6ee02a8ff..a48676375 100644 --- a/modules/mesh-delivery-indexer/manifest_test.go +++ b/modules/mesh-delivery-indexer/manifest_test.go @@ -146,7 +146,7 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build // manifests 5.21 MiB, seat-definitions 4.19 MiB and heard 4.44 MiB at 32. if want := []state{{Name: "candidates", History: 10, MaxMiB: 16}, {Name: "heard", History: 64, MaxMiB: 32, KeyTTL: true}, {Name: "manifests", History: 1, MaxMiB: 32}, {Name: "predefined", History: 5, MaxMiB: 8}, {Name: "taken", History: 1, MaxMiB: 8}, {Name: "takeins", History: 1, MaxMiB: 8}, {Name: "oldsections", History: 1, MaxMiB: 8}, {Name: index.RunsState, History: 1, MaxMiB: 8}, {Name: index.PackagesState, History: index.PackagesHistory, MaxMiB: 8}, {Name: views.MarksState, History: 1, MaxMiB: 8}, {Name: index.FindingsState, History: 5, MaxMiB: 8}, {Name: views.StatusState, History: 1, MaxMiB: 8}, - {Name: index.RequirementsState, History: 5, MaxMiB: 8}, {Name: index.SeatDefinitionsState, History: 5, MaxMiB: 32}, + {Name: index.SeatDefinitionsState, History: 5, MaxMiB: 32}, {Name: index.EntryIndexState, History: 1, MaxMiB: 8}, {Name: index.NamedState, History: 1, MaxMiB: 4}, // design 47 G §695 {Name: index.RegistrationsState, History: 1, MaxMiB: 8}, {Name: index.ProposalsState, History: 1, MaxMiB: 4}, {Name: index.VersionsState, History: 1, MaxMiB: 64}, {Name: index.BuildEdgesState, History: 1, MaxMiB: 8}, {Name: index.InputsState, History: 1, MaxMiB: 8}, {Name: index.PinsState, History: 1, MaxMiB: index.PinsCapMiB}, {Name: index.HeldState, History: 1, MaxMiB: 8}, {Name: index.ImportsState, History: 1, MaxMiB: 8}, // H-A-532 DQ-3 @@ -199,7 +199,7 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build // Three invokes: the file of a registered module's manifest and lock files (registered.go), the forge's trees (the named paths' objects, since the indexer is the one reader of a manifest's paths: // ADR 0499 clauses 2 and 3, ADR 0495 clause 1; and the module directories of the trunk, issue 1900) and whether a // commit is in another (issue 1900). - if want := []string{"seat:git.trees", "seat:git.tags", "seat:go-package-registry.versions", "seat:npm-package-registry.versions", "seat:git.file", "seat:git.contains", "seat:git.branch", "seat:mesh-delivery.source", "seat:mesh-module-assigner.assignments", "seat:mesh-module-assigner.placement", "seat:mesh-hand-acts.hand-act", "seat:mesh-watchdogs.presence", "seat:node-build-go.steps", + if want := []string{"seat:git.trees", "seat:git.file", "seat:git.contains", "seat:git.branch", "seat:mesh-delivery.source", "seat:mesh-module-assigner.assignments", "seat:mesh-module-assigner.placement", "seat:mesh-hand-acts.hand-act", "seat:mesh-watchdogs.presence", "seat:node-build-go.steps", "seat:node-build-node.steps", "seat:node-build-image.steps", "mesh-delivery-builder.builder_versions"}; !reflect.DeepEqual(m.Invokes, want) { t.Errorf("invokes = %v, want %v", m.Invokes, want) } @@ -215,7 +215,7 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build t.Errorf("%s answers the state %s, which the views family does not say", v.Tool, v.State) } } - want = append(want, "indexer_first_views", "indexer_first_view_again", index.ConfigReadersTool, index.BusStateTool, index.RequirementsTool, index.ImportsTool, index.PackageUsersTool, // H-A-527; DLV-F3r, DLV-I10, DLV-I11, DLV-I7, DLV-I8, DLV-I9c + want = append(want, "indexer_first_views", "indexer_first_view_again", index.ConfigReadersTool, index.BusStateTool, index.ImportsTool, index.PackageUsersTool, // H-A-527; DLV-F3r, DLV-I10, DLV-I11, DLV-I7, DLV-I8, DLV-I9c index.SeatDefinitionTool, index.SeatDefinitionsAgainTool, index.OutOfStepTool, // DLV-I19 index.FingerprintsAgainTool, // issue 1966 // milestone 47/G W4.12 (design 47, the indexer's tools): the catalog graph revisions read and steered. @@ -223,7 +223,7 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build index.EntryIndexTool, index.EntryPinsTool, index.NamedDropTool, // design 47 G §675, H-A-204 index.ProposalsTool, index.ProposalDropTool, index.SeedAgainTool, index.InputsTool, index.PinsTool, index.PinDropTool, index.PendingTool, index.TakeInPendingTool, index.TakeInAgainTool, index.TakeInSkipTool, index.RunsTool, index.RunDropTool, // design 47 G §667, §8, §579, §64 (A-194) index.DryRunsTool, index.RegistrationsTool) // design 47 H2 §804, §806 - if !reflect.DeepEqual(m.Tools, want) || len(want) != 47 || !slices.Contains(m.Tools, "modules") { + if !reflect.DeepEqual(m.Tools, want) || len(want) != 46 || !slices.Contains(m.Tools, "modules") { t.Errorf("tools = %v, want %v", m.Tools, want) } // Design 47 G §2, §9: every version of every registration is kept with no age limit, 64 MiB, on the old streams section. diff --git a/modules/mesh-delivery-indexer/module.json b/modules/mesh-delivery-indexer/module.json index 5599a0277..596edfdf6 100644 --- a/modules/mesh-delivery-indexer/module.json +++ b/modules/mesh-delivery-indexer/module.json @@ -47,7 +47,6 @@ "indexer_first_view_again", "indexer_config_readers", "indexer_bus_state", - "indexer_requirements", "indexer_imports", "indexer_package_users", "indexer_seat_definition", @@ -162,7 +161,6 @@ { "name": "view-marks", "history": 1, "max-mib": 8 }, { "name": "findings", "history": 5, "max-mib": 8 }, { "name": "first-views", "history": 1, "max-mib": 8 }, - { "name": "requirements", "history": 5, "max-mib": 8 }, { "name": "seat-definitions", "history": 5, "max-mib": 32 }, { "name": "entry-index", "history": 1, "max-mib": 8 }, { "name": "named", "history": 1, "max-mib": 4 }, @@ -205,9 +203,6 @@ ], "invokes": [ "seat:git.trees", - "seat:git.tags", - "seat:go-package-registry.versions", - "seat:npm-package-registry.versions", "seat:git.file", "seat:git.contains", "seat:git.branch",