I2: indexer_imports reads one module's import set

The tool answers the set the state imports keeps for a module, each package with its digest
and the reporting build's fingerprint and commit, or that none is kept, so the module moves
by its go.mod's requirements.

Builds: design 47 H2 H-A-527, H-A-528, H-A-532 DQ-3
This commit is contained in:
2026-11-23 11:08:22 +01:00
parent e2c3cea042
commit b89a65fde6
5 changed files with 46 additions and 3 deletions
@@ -232,7 +232,8 @@ func main() {
return err
}, 10*time.Second)...)
tools = append(tools, configReadersTool(watched, trunk.State("modules")), busStateTool(trunk.State), requirementsTool(keptSource),
packageUsersTool(trunk.State), seatDefinitionTool(keptSource), outOfStepTool(os.Getenv(stdio.ServedAs), keptSource))
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 {
fmt.Fprintf(os.Stderr, "[mesh-delivery-indexer-tools] %v\n", err)
os.Exit(1)
@@ -102,6 +102,14 @@ func TestImportsReportedMoveTheFingerprintOnlyWithAnImportedPackage(t *testing.T
set.Imports[0].Package != meshSDK || set.Imports[0].Digest != digestIn(pub, meshSDK) || set.Imports[1].Digest != digestIn(pub, meshSDK+"/announce") || set.Imports[1].Digest == "" {
t.Fatalf("imports.avahi = %+v, %v, %v; want the set at %s with each package's published digest %v", set, found, err, before.Fp2, pub.Packages)
}
// H-A-527: indexer_imports reads it for one module, and says so of a module with none.
tool := ImportsReadTool(ix.Imports)
if got, err := tool.Run(map[string]any{"module": "avahi"}); err != nil || got.(map[string]any)["kept"] != true || got.(map[string]any)["set"].(ImportSet).Fingerprint != before.Fp2 {
t.Fatalf("indexer_imports avahi = %+v, %v; want the kept set", got, err)
}
if got, err := tool.Run(map[string]any{"module": "feh"}); err != nil || got.(map[string]any)["kept"] != false || !strings.Contains(got.(map[string]any)["said"].(string), "go.mod's requirements") {
t.Fatalf("indexer_imports feh = %+v, %v; want none kept, said", got, err)
}
// mesh-sdk merges a change of buildstep only: avahi does not import it.
held, _ = ix.heldModules(ctx)
@@ -7,7 +7,9 @@ import (
"fmt"
"slices"
"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/nodebuildgo"
stdio "git.novox.be/novox/mesh-sdk/go"
)
// ImportsState is the indexer's state imports (design 47 H2 H-A-527, H-A-532 DQ-3): one key per module, the module's
@@ -16,6 +18,9 @@ import (
// module's modules key; the tool indexer_imports reads it.
const ImportsState = "imports"
// ImportsTool reads one module's import set (H-A-527, H-A-532 DQ-3).
const ImportsTool = "indexer_imports"
// ImportSet is a value of the state imports: the module, the fingerprint and commit of the build that reported the set,
// and each imported mesh package with its digest; a package no published module held when it was kept has none.
type ImportSet struct {
@@ -103,3 +108,31 @@ func (ix *Indexer) dropImportSet(ctx context.Context, key string) error {
}
return nil
}
// ImportsReadTool is indexer_imports (H-A-527): one module's import set from the state imports, each package with its
// digest and the fingerprint and commit of the build that reported it, or that none is kept, so it moves by its go.mod's
// requirements (H-A-528).
func ImportsReadTool(st Store) stdio.Tool {
return stdio.Tool{Name: ImportsTool,
Description: "One module's import set: the mesh packages its programs import, as the build of main's fingerprint reported " +
"them, each with its digest at that build, and that build's fingerprint and commit (design 47 H2 H-A-527); a module " +
"with none kept moves by its go.mod's requirements until its first report (H-A-528).",
Input: map[string]any{"type": "object", "required": []string{"module"}, "properties": map[string]any{
"module": map[string]any{"type": "string", "description": "the module, such as avahi"}}},
Run: func(args map[string]any) (any, error) {
module, _ := args["module"].(string)
key, err := meshcatalogclient.ModulesKey(module)
if module == "" || err != nil {
return nil, fmt.Errorf("%s names a module: %q is none", ImportsTool, module)
}
set, found, err := (&Indexer{Imports: st}).ImportSetOf(context.Background(), key)
if err != nil {
return nil, fmt.Errorf("the state %s cannot be read: %w", ImportsState, err)
}
if !found {
return map[string]any{"module": module, "kept": false,
"said": "no import set is kept for " + module + ": it moves by its go.mod's requirements until its first report"}, nil
}
return map[string]any{"module": module, "kept": true, "set": set}, nil
}}
}
@@ -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.PackageUsersTool, // 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.RequirementsTool, 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) != 46 || !slices.Contains(m.Tools, "modules") {
if !reflect.DeepEqual(m.Tools, want) || len(want) != 47 || !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.
@@ -48,6 +48,7 @@
"indexer_config_readers",
"indexer_bus_state",
"indexer_requirements",
"indexer_imports",
"indexer_package_users",
"indexer_seat_definition",
"indexer_seat_definitions_again",