78 lines
3.7 KiB
Go
78 lines
3.7 KiB
Go
//go:build integration
|
|
|
|
package buildstep
|
|
|
|
import (
|
|
"context"
|
|
sdkstep "git.novox.be/novox/mesh-sdk/go/buildstep"
|
|
"reflect"
|
|
"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 named objects equal, and a commit touching its source changes them; the answer is raw
|
|
// (Tree is always the directory's git tree, the indexer computes the named one: ADR 0593 §2).
|
|
func TestAGoOnlyCommitLeavesTheNamedObjectsEqualOnRealGit(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]sdkstep.ModuleTree {
|
|
got, err := ModuleTrees(context.Background(), forgekey.ExecRunner, nil, repo, c)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return got
|
|
}
|
|
first := trees(commit("first"))
|
|
if want := realGit(t, repo, "rev-parse", "HEAD^{tree}"); first["."].Tree != want || strings.HasPrefix(first["."].Tree, "named:") || len(first["."].Paths) != 5 {
|
|
t.Fatalf("the root module: %+v, want its git tree %s and five named objects", first["."], want)
|
|
}
|
|
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 !reflect.DeepEqual(goOnly["."].Paths, first["."].Paths) {
|
|
t.Fatalf("a Go-only commit changed the TypeScript package's objects: %v, were %v", goOnly["."].Paths, first["."].Paths)
|
|
}
|
|
|
|
writeFile(t, repo, "src/index.ts", "export const a = 2\n")
|
|
src := trees(commit("src"))
|
|
if reflect.DeepEqual(src["."].Paths, first["."].Paths) {
|
|
t.Fatal("a commit to src/ left the TypeScript package's objects 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"))
|
|
}
|
|
|
|
// A manifest naming a path and a path inside it (mesh-contracts' "go" and "go/seats/meshvault"; issue 1966): each
|
|
// gets its own object, not git ls-tree's listing of the outer one's children.
|
|
writeFile(t, repo, "nested/module.json", `{"module":"nested","version":"1","build":{"artifacts":[`+
|
|
`{"name":"go","kind":"package","language":"go","paths":["go"]},`+
|
|
`{"name":"go-seat","kind":"package","language":"go","paths":["go/seats/a"]}]}}`)
|
|
writeFile(t, repo, "nested/go/go.mod", "module x\n")
|
|
writeFile(t, repo, "nested/go/seats/a/a.go", "package a\n")
|
|
nested := trees(commit("nested"))["nested"]
|
|
if nested.Paths["go"] != realGit(t, repo, "rev-parse", "HEAD:nested/go") || nested.Paths["go/seats/a"] != realGit(t, repo, "rev-parse", "HEAD:nested/go/seats/a") {
|
|
t.Fatalf("a path and a path inside it: %v", nested.Paths)
|
|
}
|
|
}
|