mesh-build-go: a real-git test that a root module's source leaves out its nested module folders and a folder module is narrowed like a root one (D-I4, ADR 0634 §8; issue 1966)
Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -75,3 +75,44 @@ func TestAGoOnlyCommitLeavesTheNamedObjectsEqualOnRealGit(t *testing.T) {
|
||||
t.Fatalf("a path and a path inside it: %v", nested.Paths)
|
||||
}
|
||||
}
|
||||
|
||||
// D-I4 (ADR 0634 §8) on a real repository shaped like mesh-contracts: a root module naming the paths of each of its
|
||||
// artifacts has the folders of the modules nested in it left out of its source, and a module in a folder is narrowed
|
||||
// like a root one, its paths read from its own directory. A commit to a folder changes that folder's objects and
|
||||
// none of the root's; a commit to the root's own package changes none of the folder's.
|
||||
func TestARootModulesSourceLeavesOutItsNestedModuleFolders(t *testing.T) {
|
||||
repo := t.TempDir()
|
||||
realGit(t, repo, "init", "-q", "-b", "main")
|
||||
writeFile(t, repo, "module.json", `{"module":"root","version":"1","build":{"artifacts":[{"name":"go-core","kind":"package","language":"go","paths":["go/seats/core"]}]}}`)
|
||||
writeFile(t, repo, "go/seats/core/go.mod", "module example.org/c/go/seats/core\n")
|
||||
writeFile(t, repo, "domain/module.json", `{"module":"domain","version":"1","build":{"artifacts":[{"name":"go-one","kind":"package","language":"go","paths":["go/seats/one"]},{"name":"go-oneclient","kind":"package","language":"go","paths":["go/clients/oneclient"]}]}}`)
|
||||
writeFile(t, repo, "domain/seats/one/seat.json", "{}\n")
|
||||
writeFile(t, repo, "domain/go/seats/one/go.mod", "module example.org/c/domain/go/seats/one\n")
|
||||
writeFile(t, repo, "domain/go/clients/oneclient/go.mod", "module example.org/c/domain/go/clients/oneclient\n")
|
||||
commit := func(msg string) map[string]sdkstep.ModuleTree {
|
||||
realGit(t, repo, "add", "-A")
|
||||
realGit(t, repo, "commit", "-q", "-m", msg)
|
||||
got, err := ModuleTrees(context.Background(), forgekey.ExecRunner, nil, repo, realGit(t, repo, "rev-parse", "HEAD"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return got
|
||||
}
|
||||
first := commit("first")
|
||||
if got := len(first["."].Paths); got != 1 {
|
||||
t.Fatalf("the root names %v: only its own package, never a nested module's folder", first["."].Paths)
|
||||
}
|
||||
if got := first["domain"].Paths; len(got) != 2 || got["go/seats/one"] == "" || got["go/clients/oneclient"] == "" {
|
||||
t.Fatalf("the folder module's named objects %v, want its two packages read from its own directory", got)
|
||||
}
|
||||
writeFile(t, repo, "domain/go/seats/one/one.go", "package one\n")
|
||||
folder := commit("folder")
|
||||
if !reflect.DeepEqual(folder["."].Paths, first["."].Paths) || reflect.DeepEqual(folder["domain"].Paths, first["domain"].Paths) {
|
||||
t.Fatalf("a commit to the folder: root %v (was %v), folder %v (was %v)", folder["."].Paths, first["."].Paths, folder["domain"].Paths, first["domain"].Paths)
|
||||
}
|
||||
writeFile(t, repo, "go/seats/core/core.go", "package core\n")
|
||||
root := commit("root")
|
||||
if reflect.DeepEqual(root["."].Paths, folder["."].Paths) || !reflect.DeepEqual(root["domain"].Paths, folder["domain"].Paths) {
|
||||
t.Fatalf("a commit to the root's package: root %v (was %v), folder %v (was %v)", root["."].Paths, folder["."].Paths, root["domain"].Paths, folder["domain"].Paths)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user