Files
mesh-catalog/modules/mesh-build-go/cmd/mesh-build-go/narrow_integration_test.go
T

53 lines
2.2 KiB
Go

//go:build integration
package main
import (
"os"
"path/filepath"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/delivery"
)
// ADR 0499 §4 (issue 1758): a fetch asked with the module's directory and its named paths leaves the workspace holding
// only those, the manifest and the lock files; the rest of the commit is gone before any run step; a request naming
// paths without a directory is refused before anything is fetched. go.mod is kept only when named among the paths
// (mesh-sdk's narrowKept is the manifest and the lock files, review finding S1), as a Go build that names its paths does.
func TestAFetchWithNamedPathsNarrowsTheWorkspace(t *testing.T) {
f := newForge(t)
_, head := f.repo("novox/narrow", map[string]string{
"README.md": "the repository\n",
"lib/go.mod": "module fixture/lib\n\ngo 1.25.0\n",
"lib/module.json": `{"module":"lib","version":"1"}`,
"lib/cmd/x/x.go": "package main\n\nfunc main() {}\n",
"lib/docs/a.md": "not named\n",
"other/go.mod": "module fixture/other\n\ngo 1.25.0\n",
"other/o.go": "package other\n",
})
m, states := f.module(t)
res, st := fetched(t, m, states, map[string]any{"repository": "novox/narrow", "commit": head, "dir": "lib", "paths": []any{"cmd", "go.mod"}})
if st.State != delivery.StepPassed {
t.Fatalf("the fetch ended %s: %s", st.State, st.Reason)
}
tree := filepath.Join(m.Work, res.Workspace, "tree")
for _, kept := range []string{"lib/go.mod", "lib/module.json", "lib/cmd/x/x.go"} {
if _, err := os.Stat(filepath.Join(tree, kept)); err != nil {
t.Errorf("%s was narrowed away: %v", kept, err)
}
}
for _, gone := range []string{"README.md", "lib/docs/a.md", "other/o.go"} {
if _, err := os.Stat(filepath.Join(tree, gone)); err == nil {
t.Errorf("%s is still in the workspace", gone)
}
}
if strings.Join(res.Modules, ",") != "lib" {
t.Errorf("the fetch answered the modules %v, want lib alone", res.Modules)
}
_, st = fetched(t, m, states, map[string]any{"repository": "novox/narrow", "commit": head, "paths": []any{"cmd"}})
if st.State != delivery.StepFailed || !strings.Contains(st.Reason, "no module directory") {
t.Errorf("paths without a directory: %s %q", st.State, st.Reason)
}
}