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:
@@ -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/<name>)", 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])
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user