Files
mesh-delivery/modules/mesh-delivery-sdk/trunk/trunk_test.go
T
jschoubben c0b3e4ad08 S2: the step runner judges an import set by its build seat's language form
A Node build's imports are npm names in the mesh's scope (@novox/mesh-sdk, one package, no
sub-path), a Go build's Go module paths under the forge's prefix; AskSteps.ImportScope and
ImportPrefix carry the build module's settings, trunk.DefaultNpmScope and ForgeModulePrefix
when they name none (trunk.CheckNpmImports, CheckGoImports).

Builds: design 47 H2 H-A-534, H-A-532 DQ-6
2026-11-23 11:10:25 +01:00

79 lines
3.4 KiB
Go

package trunk
import (
"testing"
)
func TestSameRepository(t *testing.T) { // 1281/AC1
const forge = "novox/mesh-catalog"
for _, c := range []struct {
a, b string
same bool
}{
// the clone URL as a build record carries it (mesh-controller.command builds, 2026-10-19 ~21:20 local)
{forge, "http://novox.internal:20000/novox/mesh-catalog.git", true},
{forge, "http://novox.internal:20000/novox/mesh-catalog", true},
{forge, "http://novox.internal:20000/novox/mesh-catalog.git/", true},
{"http://novox.internal:20000/novox/mesh-catalog.git/", forge, true},
{forge, "novox/mesh-catalog", true},
{forge, "Novox/Mesh-Catalog", true},
{forge, "http://novox.internal:20000/novox/mesh-catalog-x.git", false},
{forge, "novox/mesh-catalog-x", false},
{forge, "http://novox.internal:20000/other/mesh-catalog.git", false},
{forge, "other/mesh-catalog", false},
{forge, "http://novox.internal:20000/novox/mesh-media-catalog.git", false},
{forge, "", false},
{"", "", false},
} {
if got := SameRepository(c.a, c.b); got != c.same {
t.Errorf("SameRepository(%q, %q) = %v, want %v", c.a, c.b, got, c.same)
}
}
if got := RepositoryName("http://novox.internal:20000/novox/mesh-catalog.git"); got != "novox/mesh-catalog" {
t.Errorf("RepositoryName = %q", got)
}
}
func TestAnImportSetHoldsMeshPackagesSortedAndEachOnce(t *testing.T) {
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)
}
}
// 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)
}
}
}
// A repository keys the indexer's taken and the view's reach by its forge name, in lower case, from either spelling (ADR 0556).
func TestARepositoryIsKeyedByItsLowerCaseForgeName(t *testing.T) {
for in, want := range map[string]string{"novox/Mesh-SDK": "novox/mesh-sdk", "http://h:3000/novox/mesh-sdk.git": "novox/mesh-sdk",
"a/b.c": "a/b=2ec", "": "", "nope": "", "/x": ""} {
got, err := RepositoryKey(in)
if (want == "") != (err != nil) || got != want {
t.Errorf("RepositoryKey(%q) = %q, %v; want %q", in, got, err, want)
}
}
}