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)
This commit is contained in:
@@ -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 `<node>.<ask
|
||||
// id>` (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).
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user