From 3fffe7e2dd97728228ead2a43a05ee6d0ca4b7ec Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 11:26:47 +0100 Subject: [PATCH] S2: the step runner checks only that an import set is sorted and each once Nothing in a path or name tells a mesh package apart: mesh Go modules come from the Go package registry, not the forge. The per-language form check and its settings go (CheckGoImports, CheckNpmImports, DefaultNpmScope, AskSteps.ImportPrefix and ImportScope); CheckImports judges every seat's set sorted and each once, and the indexer keeps of it the packages a module of the module graph publishes. Builds: design 47 H2 H-A-539 (withdraws H-A-534's form check and H-A-535's settings) --- modules/mesh-delivery-sdk/steprun/askrun.go | 19 ++------ .../mesh-delivery-sdk/steprun/askrun_test.go | 17 ++++--- modules/mesh-delivery-sdk/trunk/packages.go | 47 ++----------------- modules/mesh-delivery-sdk/trunk/trunk_test.go | 32 ++++--------- 4 files changed, 24 insertions(+), 91 deletions(-) diff --git a/modules/mesh-delivery-sdk/steprun/askrun.go b/modules/mesh-delivery-sdk/steprun/askrun.go index ab4d93e39..90d3a6aa4 100644 --- a/modules/mesh-delivery-sdk/steprun/askrun.go +++ b/modules/mesh-delivery-sdk/steprun/askrun.go @@ -66,10 +66,6 @@ type AskSteps struct { // fingerprint main's modules state holds (design 47 H2 H-A-517, H-A-532 DQ-2, DMC-2). A say that fails leaves the // build's answer standing and is said in the journal. Nil says none. SayImports func(nodebuildgo.ImportsReported) error - // ImportPrefix and ImportScope are the forms an import set is judged by, read from the build module's settings - // (design 47 H2 H-A-534): a Go build's imports are Go module paths under ImportPrefix, the forge's module prefix - // (trunk.ForgeModulePrefix when empty); a Node build's are npm names in ImportScope (trunk.DefaultNpmScope when empty). - ImportPrefix, ImportScope string // Outputs are the holder's outputs objects (OutputsStore), where a test step keeps its run's output as `.` (design 47 H2 §791, H-A-412), which the seat's verb output reads (OutputTool). Nil keeps none, said in the journal. Outputs OutputObjects @@ -94,7 +90,7 @@ func RunAsk(ctx context.Context, steps AskSteps, ask sdkstep.StepAsk) (any, erro if ask.Build != nil { job := *ask.Build job.Fetch = withPackages(job.Fetch, ask.Packages) - out, err := steps.build(ctx, job, ask.Version, ask.Language) + out, err := steps.build(ctx, job, ask.Version) var dec *Declining if err != nil && !sdkstep.IsPassing(err) && !errors.As(err, &dec) && ctx.Err() == nil { // A failed build keeps its error text, as the build module bounded it, as the ask's output object, header and @@ -212,7 +208,7 @@ func (s AskSteps) onToolchain(ctx context.Context, want *sdkstep.ToolchainUsed) // build runs a build job; version is the version the ask carries (design 47 G §573), which each artifact's build is given // as its argument version, the build's MESH_VERSION (§370), unless the artifact names its own. -func (s AskSteps) build(ctx context.Context, job sdkstep.BuildJob, version, language string) (any, error) { +func (s AskSteps) build(ctx context.Context, job sdkstep.BuildJob, version string) (any, error) { answer := sdkstep.BuildAnswer{} tc, err := s.onToolchain(ctx, job.Toolchain) if err != nil { @@ -330,7 +326,7 @@ func (s AskSteps) build(ctx context.Context, job sdkstep.BuildJob, version, lang if err := json.Unmarshal(r, &read); err != nil { return nil, fmt.Errorf("the imports of %s answered what is not a list: %s", job.Module, r) } - if err := s.checkImports(language, read.Imports); err != nil { + if err := trunk.CheckImports(read.Imports); err != nil { // sorted and each once only (design 47 H2 H-A-539) return nil, err } answer.Imports = read.Imports @@ -339,15 +335,6 @@ func (s AskSteps) build(ctx context.Context, job sdkstep.BuildJob, version, lang return answer, nil } -// checkImports judges a build's import set by the form of the language its build seat serves (design 47 H2 H-A-534): npm -// names in the mesh's scope for a Node build, Go module paths under the forge's prefix for every other. -func (s AskSteps) checkImports(language string, imports []string) error { - if language == sdkstep.AskNode { - return trunk.CheckNpmImports(imports, s.ImportScope) - } - return trunk.CheckGoImports(imports, s.ImportPrefix) -} - // sayImports says the import set a done build read (design 47 H2 H-A-517, H-A-532 DQ-2): the module, the fingerprint // it was asked for, its commit and the imports, an empty list when its programs import no mesh package. A failed say is // said in the journal and never fails the build (principle 3: loud, not lost). diff --git a/modules/mesh-delivery-sdk/steprun/askrun_test.go b/modules/mesh-delivery-sdk/steprun/askrun_test.go index 634058b67..51c997b83 100644 --- a/modules/mesh-delivery-sdk/steprun/askrun_test.go +++ b/modules/mesh-delivery-sdk/steprun/askrun_test.go @@ -141,16 +141,19 @@ imports {"module":"modules/m","workspace":"/w/1"}` t.Errorf("a failed say: said %q, journal %q; want it said in the journal", said, journal) } said, sayErr = nil, nil - // Design 47 H2 H-A-534: an import set is judged by its build seat's form: npm names on the Node seat, Go paths on the Go seat. + // Design 47 H2 H-A-539: an import set is judged only sorted and each once, whatever its entries name, on every seat: + // a Go build's set naming an npm name and a module of another host is taken; an unsorted one is refused. steps.Imports = func(context.Context, map[string]any) (any, error) { - return map[string]any{"imports": []string{"@novox/mesh-sdk"}}, nil + return map[string]any{"imports": []string{"@novox/mesh-sdk", "github.com/x/y"}}, nil } - if _, err := RunAsk(context.Background(), steps, a); err == nil || !strings.Contains(err.Error(), "@novox/mesh-sdk") { - t.Errorf("an npm set on the Go seat: %v, want it refused", err) + if out, err := RunAsk(context.Background(), steps, a); err != nil || !slices.Equal(out.(sdkstep.BuildAnswer).Imports, []string{"@novox/mesh-sdk", "github.com/x/y"}) { + t.Errorf("a set of any names on the Go seat: %v, %v; want it taken", out, err) } - a.Language = sdkstep.AskNode - if out, err := RunAsk(context.Background(), steps, a); err != nil || !slices.Equal(out.(sdkstep.BuildAnswer).Imports, []string{"@novox/mesh-sdk"}) { - t.Errorf("an npm set on the Node seat: %v, %v; want it taken", out, err) + steps.Imports = func(context.Context, map[string]any) (any, error) { + return map[string]any{"imports": []string{"github.com/x/y", "@novox/mesh-sdk"}}, nil + } + if _, err := RunAsk(context.Background(), steps, a); err == nil || !strings.Contains(err.Error(), "sorted") { + t.Errorf("an unsorted set: %v, want it refused", err) } said = nil diff --git a/modules/mesh-delivery-sdk/trunk/packages.go b/modules/mesh-delivery-sdk/trunk/packages.go index 53df9f615..fd36260d7 100644 --- a/modules/mesh-delivery-sdk/trunk/packages.go +++ b/modules/mesh-delivery-sdk/trunk/packages.go @@ -28,53 +28,12 @@ func PackageRepository(pkg string) (repository, dir string, ok bool) { return "novox/" + name, dir, true } -// DefaultNpmScope is the npm scope of the mesh's npm packages when a build module's setting names none (design 47 H2 -// H-A-534): a TypeScript import set names each mesh npm package by its name in it, such as @novox/mesh-sdk. -const DefaultNpmScope = "@novox" - // CheckImports refuses an import set (the imports of a module's kept inputs, of a build's answer and of a build log entry) -// that holds a path that is no mesh package's, or is not sorted and each once. +// that is not sorted and each once. Nothing in a path or a name tells a mesh package apart (design 47 H2 H-A-539, which +// withdraws H-A-534's forms): a build module reports every module path or package name its build resolved but the +// language's standard library, and the indexer keeps of it the packages a module of the module graph publishes. func CheckImports(imports []string) error { - return CheckGoImports(imports, ForgeModulePrefix) -} - -// CheckGoImports refuses a Go import set holding a path that is no Go module path under prefix, the forge's module prefix -// a build module's setting names (design 47 H2 H-A-534), or that is not sorted and each once. -func CheckGoImports(imports []string, prefix string) error { - if prefix == "" { - prefix = ForgeModulePrefix - } - return checkSorted(imports, func(pkg string) error { - rest, found := strings.CutPrefix(pkg, prefix) - if name, _, _ := strings.Cut(rest, "/"); !found || name == "" || strings.ContainsAny(pkg, " \t\n@") { - return fmt.Errorf("trunk: the import %q is no mesh package's path (it starts with %s)", pkg, prefix) - } - return nil - }) -} - -// CheckNpmImports refuses a TypeScript import set holding an entry that is no npm package name in scope (such as -// @novox/mesh-sdk, never a sub-path of it: one package, one digest, H-A-532 DQ-6), or that is not sorted and each once -// (design 47 H2 H-A-534). -func CheckNpmImports(imports []string, scope string) error { - if scope == "" { - scope = DefaultNpmScope - } - return checkSorted(imports, func(pkg string) error { - name, found := strings.CutPrefix(pkg, scope+"/") - if !found || name == "" || strings.ContainsAny(name, "/@ \t\n") { - return fmt.Errorf("trunk: the import %q is no mesh npm package's name (%s/)", pkg, scope) - } - return nil - }) -} - -// checkSorted refuses imports holding an entry one refuses, or not sorted and each once. -func checkSorted(imports []string, one func(string) error) error { for i, pkg := range imports { - if err := one(pkg); err != nil { - return err - } if i > 0 && imports[i-1] >= pkg { return fmt.Errorf("trunk: the imports are not sorted and each once (%s after %s)", pkg, imports[i-1]) } diff --git a/modules/mesh-delivery-sdk/trunk/trunk_test.go b/modules/mesh-delivery-sdk/trunk/trunk_test.go index b565fe5f8..39b9ffc34 100644 --- a/modules/mesh-delivery-sdk/trunk/trunk_test.go +++ b/modules/mesh-delivery-sdk/trunk/trunk_test.go @@ -35,33 +35,17 @@ func TestSameRepository(t *testing.T) { // 1281/AC1 } func TestAnImportSetHoldsMeshPackagesSortedAndEachOnce(t *testing.T) { + // Design 47 H2 H-A-539: an import set is judged only sorted and each once, whatever forge, prefix or scope its entries name. a, b := ForgeModulePrefix+"mesh-sdk/go", ForgeModulePrefix+"mesh-delivery/modules/mesh-delivery-sdk" - if err := CheckImports([]string{b, a}); err != nil { - t.Errorf("a sorted set is refused: %v", err) - } - for name, bad := range map[string][]string{"unsorted": {a, b}, "twice": {a, a}, "not a mesh package": {"github.com/x/y"}, "a version": {a + "@v1"}} { - if CheckImports(bad) == nil { - t.Errorf("%s: %v is taken", name, bad) + for name, good := range map[string][]string{"Go module paths": {b, a}, "another host": {"example.org/x/y", "github.com/x/y"}, + "npm names": {"@novox/mesh-sdk", "@other/x", "left-pad"}, "none": nil} { + if err := CheckImports(good); err != nil { + t.Errorf("%s: %v is refused: %v", name, good, err) } } - // Design 47 H2 H-A-534: a Go set is judged under the prefix the build module's setting names, a TypeScript set by npm - // names in the mesh's scope, each package once (no sub-path, H-A-532 DQ-6). - if err := CheckGoImports([]string{"git.example.org/o/r/go"}, "git.example.org/o/"); err != nil { - t.Errorf("a Go set under another prefix is refused: %v", err) - } - if CheckGoImports([]string{a}, "git.example.org/o/") == nil { - t.Error("a Go set outside the prefix set is taken") - } - if err := CheckNpmImports([]string{"@novox/mesh-contracts-node-build-go", "@novox/mesh-sdk"}, ""); err != nil { - t.Errorf("an npm set in the default scope is refused: %v", err) - } - if err := CheckNpmImports([]string{"@acme/sdk"}, "@acme"); err != nil { - t.Errorf("an npm set in another scope is refused: %v", err) - } - for name, bad := range map[string][]string{"a Go path": {a}, "a sub-path": {"@novox/mesh-sdk/stdio"}, "another scope": {"@other/x"}, - "no scope": {"mesh-sdk"}, "unsorted": {"@novox/mesh-sdk", "@novox/a"}, "a version": {"@novox/mesh-sdk@1"}} { - if CheckNpmImports(bad, "") == nil { - t.Errorf("npm %s: %v is taken", name, bad) + for name, bad := range map[string][]string{"unsorted": {a, b}, "twice": {a, a}, "npm unsorted": {"@novox/mesh-sdk", "@novox/a"}} { + if CheckImports(bad) == nil { + t.Errorf("%s: %v is taken", name, bad) } } }