From d14a6d301c6fb4e6ef9f1e8fb2d29de8af2b1314 Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 22 Oct 2026 17:30:25 +0200 Subject: [PATCH] =?UTF-8?q?Prove=20on=20real=20git=20that=20a=20Go-only=20?= =?UTF-8?q?commit=20leaves=20mesh-sdk's=20package=20tree=20equal=20(issue?= =?UTF-8?q?=201758,=20S5,=20ADR=200499=20=C2=A72=20check)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/buildstep/trees_integration_test.go | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 go/buildstep/trees_integration_test.go diff --git a/go/buildstep/trees_integration_test.go b/go/buildstep/trees_integration_test.go new file mode 100644 index 0000000..eb518c5 --- /dev/null +++ b/go/buildstep/trees_integration_test.go @@ -0,0 +1,63 @@ +//go:build integration + +package buildstep + +import ( + "context" + "strings" + "testing" + + "git.novox.be/novox/mesh-sdk/go/forgekey" +) + +// On a real repository shaped like mesh-sdk (novox/hq ADR 0499 clauses 2 and 6), a commit touching only the Go package +// leaves the TypeScript package's tree value equal, and a commit touching its source changes it; a module that names no +// path keeps its directory's tree id. +func TestAGoOnlyCommitLeavesTheNamedTreeEqualOnRealGit(t *testing.T) { + repo := t.TempDir() + realGit(t, repo, "init", "-q", "-b", "main") + writeFile(t, repo, "module.json", `{"module":"mesh-sdk","version":"1","build":{"artifacts":[`+ + `{"name":"lib","kind":"package","language":"typescript","paths":["src","test","package.json","package-lock.json","tsconfig.json"]}]}}`) + writeFile(t, repo, "src/index.ts", "export const a = 1\n") + writeFile(t, repo, "test/a.test.ts", "// a\n") + writeFile(t, repo, "package.json", "{}\n") + writeFile(t, repo, "package-lock.json", "{}\n") + writeFile(t, repo, "tsconfig.json", "{}\n") + writeFile(t, repo, "go/delivery/x.go", "package delivery\n") + writeFile(t, repo, "other/module.json", `{"module":"other","version":"1"}`) + writeFile(t, repo, "other/a.txt", "a\n") + commit := func(msg string) string { + realGit(t, repo, "add", "-A") + realGit(t, repo, "commit", "-q", "-m", msg) + return realGit(t, repo, "rev-parse", "HEAD") + } + trees := func(c string) map[string]ModuleTree { + got, err := ModuleTrees(context.Background(), forgekey.ExecRunner, nil, repo, c) + if err != nil { + t.Fatal(err) + } + return got + } + first := trees(commit("first")) + if !strings.HasPrefix(first["."].Tree, "named:") || len(first["."].Paths) != 5 { + t.Fatalf("the root module was not narrowed: %+v", first["."]) + } + if want := realGit(t, repo, "rev-parse", "HEAD:other"); first["other"].Tree != want || first["other"].Paths != nil { + t.Fatalf("a module naming no path: %+v, want its directory's tree %s", first["other"], want) + } + + writeFile(t, repo, "go/delivery/x.go", "package delivery\n\nconst B = 2\n") + goOnly := trees(commit("go only")) + if goOnly["."].Tree != first["."].Tree { + t.Fatalf("a Go-only commit changed the TypeScript package's tree: %s, was %s", goOnly["."].Tree, first["."].Tree) + } + + writeFile(t, repo, "src/index.ts", "export const a = 2\n") + src := trees(commit("src")) + if src["."].Tree == first["."].Tree { + t.Fatal("a commit to src/ left the TypeScript package's tree equal") + } + if src["."].Paths["src"] != realGit(t, repo, "rev-parse", "HEAD:src") { + t.Fatalf("the object of src is %s, git says %s", src["."].Paths["src"], realGit(t, repo, "rev-parse", "HEAD:src")) + } +}