From a2272916a0e5eea39f9e0f7cd3e858d2839081f1 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 5 Nov 2026 13:25:09 +0100 Subject: [PATCH] =?UTF-8?q?mesh-build-go:=20a=20real-git=20test=20that=20a?= =?UTF-8?q?=20root=20module's=20source=20leaves=20out=20its=20nested=20mod?= =?UTF-8?q?ule=20folders=20and=20a=20folder=20module=20is=20narrowed=20lik?= =?UTF-8?q?e=20a=20root=20one=20(D-I4,=20ADR=200634=20=C2=A78;=20issue=201?= =?UTF-8?q?966)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig --- .../buildstep/trees_integration_test.go | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/modules/mesh-build-go/buildstep/trees_integration_test.go b/modules/mesh-build-go/buildstep/trees_integration_test.go index 6bf462db6..2b9f458f0 100644 --- a/modules/mesh-build-go/buildstep/trees_integration_test.go +++ b/modules/mesh-build-go/buildstep/trees_integration_test.go @@ -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) + } +}