Merge commit 'cdf16870' into fix/47-G-start-merge
This commit is contained in:
@@ -260,7 +260,7 @@ func (m *Module) digestHere(ctx context.Context, workspace, level string, names
|
||||
namesHeader = []string{"node-names " + strings.Join(sortedNames, ",")}
|
||||
}
|
||||
|
||||
dirs, err := m.goModDirs(ctx, tree)
|
||||
dirs, err := m.testDirs(ctx, tree)
|
||||
if err != nil {
|
||||
return DigestResult{}, err
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mod/modfile"
|
||||
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
dforgekey "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/forgekey"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
@@ -106,6 +108,8 @@ func (m *Module) fetch(ctx context.Context, args map[string]any) (res any, err e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// A fetch with no dir (the checker's check of a pull request, until G removes the checker; A-447e) fetches the tree
|
||||
// whole: every go.mod of it.
|
||||
siblings, err := siblingsArg(args["beside"])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -165,6 +169,20 @@ func (m *Module) fetchInto(ctx context.Context, req sdkstep.FetchRequest, id str
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dir := cleanDir(req.Dir); dir != "" {
|
||||
// A fetch asked with a module's directory is of that Go module and what its go.mod replaces with a local path,
|
||||
// never another Go module of the tree (design 47 G, A-447). Said beside the tree, so every later step lists the
|
||||
// same modules.
|
||||
if dirs, err = scopedDirs(tree, dir, dirs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, scopeMark), []byte(strings.Join(dirs, "\n")), 0o600); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, moduleDirMark), []byte(dir), 0o600); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
res.Modules = dirs
|
||||
if base != "" && res.Merge == "" {
|
||||
return res, nil // a conflict: the tree is at the trunk, nothing of the head is built or tested
|
||||
@@ -434,7 +452,11 @@ func (m *Module) downloadAndVerify(ctx context.Context, dir, d string) error {
|
||||
}
|
||||
|
||||
// goModDirs are the directories of the tree that hold a go.mod, relative to it, in order.
|
||||
// When the fetch was asked with a module's directory (scopeMark), the steps after it see only the directories it chose.
|
||||
func (m *Module) goModDirs(ctx context.Context, tree string) ([]string, error) {
|
||||
if b, err := os.ReadFile(filepath.Join(filepath.Dir(tree), scopeMark)); err == nil {
|
||||
return strings.Fields(string(b)), nil
|
||||
}
|
||||
r := m.Run(ctx, nil, "git", "-C", tree, "ls-files", "--", "go.mod", "*/go.mod")
|
||||
if r.Status != 0 || r.Err != "" {
|
||||
return nil, fmt.Errorf("git ls-files: %s", dforgekey.Said(r.Err+"\n"+r.Stderr))
|
||||
@@ -454,6 +476,27 @@ func (m *Module) goModDirs(ctx context.Context, tree string) ([]string, error) {
|
||||
return dirs, nil
|
||||
}
|
||||
|
||||
// testDirs are the directories the unit and integration steps and the digest take: the chosen go.mod directories at or
|
||||
// under the module's own directory. A directory the module's go.mod replaces from outside its own stays for download and
|
||||
// resolution alone; its tests are another module's (design 47 G, A-447c). A workspace fetched with no dir keeps every go.mod.
|
||||
func (m *Module) testDirs(ctx context.Context, tree string) ([]string, error) {
|
||||
all, err := m.goModDirs(ctx, tree)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
own, ok := moduleDirOf(tree)
|
||||
if !ok || own == "." || own == "" {
|
||||
return all, nil
|
||||
}
|
||||
out := []string{}
|
||||
for _, d := range all {
|
||||
if d == own || strings.HasPrefix(d, own+"/") {
|
||||
out = append(out, d)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// inTestdata says a path lies under a directory named testdata, whose go.mod files are fixtures Go ignores, not modules
|
||||
// of the tree (issue 1810).
|
||||
func inTestdata(path string) bool {
|
||||
@@ -608,3 +651,85 @@ func narrowed(tree string) bool {
|
||||
_, err := os.Stat(filepath.Join(filepath.Dir(tree), narrowedMark))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// scopeMark is the file beside a workspace's tree naming the Go module directories a fetch asked with a module's
|
||||
// directory chose, one to a line (empty: none).
|
||||
const scopeMark = "gomodules"
|
||||
|
||||
// moduleDirMark is the file beside a workspace's tree naming the module directory the fetch was asked with: the one
|
||||
// module.json a step compares generated files for (design 47 G, A-447c).
|
||||
const moduleDirMark = "moduledir"
|
||||
|
||||
// moduleDirOf is the module directory the workspace of tree was fetched for, ok false for a workspace with none.
|
||||
func moduleDirOf(tree string) (string, bool) {
|
||||
b, err := os.ReadFile(filepath.Join(filepath.Dir(tree), moduleDirMark))
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
return string(b), true
|
||||
}
|
||||
|
||||
// cleanDir is a request's module directory in the form goModDirs lists, "" for none.
|
||||
func cleanDir(dir string) string {
|
||||
if strings.TrimSpace(dir) == "" {
|
||||
return ""
|
||||
}
|
||||
return strings.Trim(filepath.ToSlash(filepath.Clean(dir)), "/")
|
||||
}
|
||||
|
||||
// scopedDirs are the go.mod directories of all that a module directory dir chooses: dir itself and each directory its
|
||||
// go.mod replaces with a local path, followed through their own replaces (design 47 G, A-447), in order. A directory
|
||||
// the tree holds no go.mod for is left out. A directory holding no go.mod chooses every go.mod under it, and one that
|
||||
// chooses no Go module at all is an error naming it (A-447a).
|
||||
func scopedDirs(tree, dir string, all []string) ([]string, error) {
|
||||
have := map[string]bool{}
|
||||
for _, d := range all {
|
||||
have[d] = true
|
||||
}
|
||||
chosen := map[string]bool{}
|
||||
todo := []string{dir}
|
||||
if !have[dir] {
|
||||
// A directory with no go.mod of its own (a module whose Go code lies in go/, a contracts module with a go.mod per
|
||||
// seat) is every go.mod under it; the tree is already narrowed to the module's paths (A-447a).
|
||||
todo = nil
|
||||
for _, d := range all {
|
||||
if dir == "." || strings.HasPrefix(d, dir+"/") {
|
||||
todo = append(todo, d)
|
||||
}
|
||||
}
|
||||
}
|
||||
for len(todo) > 0 {
|
||||
d := todo[0]
|
||||
todo = todo[1:]
|
||||
if chosen[d] || !have[d] {
|
||||
continue
|
||||
}
|
||||
chosen[d] = true
|
||||
file := filepath.Join(tree, filepath.FromSlash(d), "go.mod")
|
||||
body, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := modfile.Parse(file, body, nil) // not ParseLax: that one ignores the replaces
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", file, err)
|
||||
}
|
||||
for _, r := range f.Replace {
|
||||
if !modfile.IsDirectoryPath(r.New.Path) {
|
||||
continue
|
||||
}
|
||||
target := filepath.ToSlash(filepath.Clean(filepath.Join(filepath.FromSlash(d), filepath.FromSlash(r.New.Path))))
|
||||
todo = append(todo, target)
|
||||
}
|
||||
}
|
||||
out := []string{}
|
||||
for _, d := range all {
|
||||
if chosen[d] {
|
||||
out = append(out, d)
|
||||
}
|
||||
}
|
||||
if len(out) == 0 {
|
||||
return nil, fmt.Errorf("the module directory %q holds no Go module (no go.mod in it or under it)", dir)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -61,6 +61,13 @@ func (f *fakeStep) run(ctx context.Context, env []string, name string, args ...s
|
||||
os.MkdirAll(filepath.Dir(filepath.Join(args[i+1], name)), 0o755)
|
||||
os.WriteFile(filepath.Join(args[i+1], name), []byte(text), 0o644)
|
||||
}
|
||||
// Every go.mod the fake lists exists, since a fetch asked with a directory reads its go.mod (A-447).
|
||||
for _, l := range strings.Fields(f.gomods) {
|
||||
if _, err := os.Stat(filepath.Join(args[i+1], l)); err != nil && f.files[l] == "" {
|
||||
os.MkdirAll(filepath.Dir(filepath.Join(args[i+1], l)), 0o755)
|
||||
os.WriteFile(filepath.Join(args[i+1], l), []byte("module fake\n"), 0o644)
|
||||
}
|
||||
}
|
||||
for _, v := range f.vendors {
|
||||
os.MkdirAll(filepath.Join(args[i+1], v, "vendor"), 0o755)
|
||||
os.WriteFile(filepath.Join(args[i+1], v, "vendor", "modules.txt"), nil, 0o644)
|
||||
@@ -91,7 +98,24 @@ func fetchModule(t *testing.T, f *fakeStep) (*Module, *keptStates) {
|
||||
return m, states
|
||||
}
|
||||
|
||||
// fetchTool is the fetch tool as a build module is asked, always with its module's directory (A-447b): the root of the
|
||||
// tree unless the args name one. rawFetchTool is the tool as it is.
|
||||
func fetchTool(t *testing.T, m *Module) func(map[string]any) (any, error) {
|
||||
t.Helper()
|
||||
raw := rawFetchTool(t, m)
|
||||
return func(args map[string]any) (any, error) {
|
||||
if _, ok := args["dir"]; !ok {
|
||||
named := map[string]any{"dir": "."}
|
||||
for k, v := range args {
|
||||
named[k] = v
|
||||
}
|
||||
args = named
|
||||
}
|
||||
return raw(args)
|
||||
}
|
||||
}
|
||||
|
||||
func rawFetchTool(t *testing.T, m *Module) func(map[string]any) (any, error) {
|
||||
t.Helper()
|
||||
for _, tool := range m.Tools(m.StepTools()) {
|
||||
if tool.Name == "build_go_fetch" {
|
||||
@@ -107,7 +131,9 @@ var fetchArgs = map[string]any{"repository": "novox/mesh-sdk", "commit": commitS
|
||||
// 1485/AC1: git is asked through FetchCommit with the ssh remote, and go mod download and verify run in each go.mod
|
||||
// directory (not in one that vendors) with GOTOOLCHAIN=local, GOFLAGS=-mod=mod and the module's cache paths.
|
||||
func TestFetchAsksGitForTheSshRemoteAndDownloadsEachModule(t *testing.T) {
|
||||
f := &fakeStep{gomods: "go.mod\nsub/dir/go.mod\nvend/go.mod\n", vendors: []string{"vend"}}
|
||||
// The root go.mod replaces the other two by directory: a fetch asked with a module's directory chooses what it replaces.
|
||||
f := &fakeStep{gomods: "go.mod\nsub/dir/go.mod\nvend/go.mod\n", vendors: []string{"vend"},
|
||||
files: map[string]string{"go.mod": "module fake\nreplace a => ./sub/dir\nreplace b => ./vend\n"}}
|
||||
m, states := fetchModule(t, f)
|
||||
if _, err := fetchTool(t, m)(fetchArgs); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -270,7 +296,8 @@ func TestAVerifyThatFailsEndsTheStepNamingTheDirectoryAndTheLine(t *testing.T) {
|
||||
return forgekey.Ran{}
|
||||
}}
|
||||
m, states := fetchModule(t, f)
|
||||
if _, err := fetchTool(t, m)(fetchArgs); err != nil {
|
||||
// Asked for the module of tools, as a build is for one module (A-447b).
|
||||
if _, err := fetchTool(t, m)(map[string]any{"repository": "novox/mesh-sdk", "commit": commitSHA, "dir": "tools"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := states.waitEnd(t)
|
||||
|
||||
@@ -2,9 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-sdk/go/forgekey"
|
||||
)
|
||||
|
||||
@@ -25,3 +29,123 @@ func TestGoModDirsLeaveOutTheFixturesUnderTestdata(t *testing.T) {
|
||||
t.Fatalf("go.mod directories = %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// A-447: a fetch asked with a module's directory chooses that Go module and the directories its go.mod replaces with a
|
||||
// local path, through their own replaces; the later steps list the same. The takein module of the indexer is no module
|
||||
// of the assigner's build (live, 2026-11-16).
|
||||
func TestAFetchAskedWithADirectoryChoosesItsModuleAndWhatItReplacesAlone(t *testing.T) {
|
||||
all := []string{".", "modules/assigner", "modules/indexer", "modules/indexer/takein", "modules/lib", "modules/lib/deep", "modules/other", "rootless/x/go", "seats/a", "seats/b"}
|
||||
mods := map[string]string{
|
||||
"modules/assigner": "module a\nreplace x => ../lib\nreplace (\n\ty => ../../outside\n\tz v1.0.0 => z v1.1.0\n)\n",
|
||||
"modules/indexer": "module i\nreplace t => ./takein\n",
|
||||
"modules/indexer/takein": "module t\n",
|
||||
"modules/lib": "module l\nreplace d => ./deep\n",
|
||||
"modules/lib/deep": "module d\n",
|
||||
"modules/other": "module o\n",
|
||||
".": "module r\n",
|
||||
"seats/a": "module sa\nreplace q => ../q\n",
|
||||
"seats/b": "module sb\n",
|
||||
"rootless/x/go": "module rx\n",
|
||||
}
|
||||
for _, c := range []struct {
|
||||
dir string
|
||||
want []string
|
||||
}{
|
||||
{"modules/assigner", []string{"modules/assigner", "modules/lib", "modules/lib/deep"}},
|
||||
{"modules/indexer", []string{"modules/indexer", "modules/indexer/takein"}},
|
||||
{"modules/other/", []string{"modules/other"}},
|
||||
{"modules/lib/deep/", []string{"modules/lib/deep"}},
|
||||
{"seats", []string{"seats/a", "seats/b"}}, // a go.mod per seat, none in seats itself
|
||||
{".", []string{"."}}, // the root holds a go.mod
|
||||
{"rootless/x", []string{"rootless/x/go"}}, // Go code lies in go/
|
||||
{"modules/none", nil}, // chooses no Go module: an error naming it
|
||||
} {
|
||||
tree := t.TempDir()
|
||||
for d, body := range mods {
|
||||
if err := os.MkdirAll(filepath.Join(tree, d), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(tree, d, "go.mod"), []byte(body), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
got, err := scopedDirs(tree, cleanDir(c.dir), all)
|
||||
if c.want == nil {
|
||||
if err == nil || !strings.Contains(err.Error(), c.dir) {
|
||||
t.Errorf("dir %q chose %v, %v; want an error naming it", c.dir, got, err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil || !reflect.DeepEqual(got, c.want) {
|
||||
t.Errorf("dir %q chooses %v, %v; want %v", c.dir, got, err, c.want)
|
||||
}
|
||||
}
|
||||
// What the steps after the fetch list is what the fetch chose, beside the tree.
|
||||
root := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(root, scopeMark), []byte("modules/assigner\nmodules/lib"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m := &Module{}
|
||||
got, err := m.goModDirs(context.Background(), filepath.Join(root, "tree"))
|
||||
if err != nil || !reflect.DeepEqual(got, []string{"modules/assigner", "modules/lib"}) {
|
||||
t.Errorf("the later steps list %v, %v", got, err)
|
||||
}
|
||||
if cleanDir("") != "" || cleanDir(".") != "." {
|
||||
t.Errorf("cleanDir of nothing = %q, of . = %q", cleanDir(""), cleanDir("."))
|
||||
}
|
||||
}
|
||||
|
||||
// A-447e: a fetch with no dir (the checker's check of a pull request, until G removes the checker) fetches the tree whole:
|
||||
// it chooses every go.mod of it.
|
||||
func TestAFetchWithNoDirectoryChoosesEveryGoModOfTheTree(t *testing.T) {
|
||||
f := &fakeStep{gomods: "go.mod\nsub/go.mod\n"}
|
||||
m, states := fetchModule(t, f)
|
||||
if _, err := rawFetchTool(t, m)(map[string]any{"repository": "novox/mesh-sdk", "commit": commitSHA}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st := states.waitEnd(t)
|
||||
if st.State != sdkstep.StepPassed || !strings.Contains(string(st.Result), `"modules":[".","sub"]`) {
|
||||
t.Fatalf("a fetch with no dir ended %s: %q %s", st.State, st.Reason, st.Result)
|
||||
}
|
||||
}
|
||||
|
||||
// A-447c: the unit level of a module whose go.mod replaces ../lib tests the module alone; lib is downloaded and resolved
|
||||
// for it, and its tests are another module's.
|
||||
func TestTheUnitLevelTestsOnlyTheModulesOwnDirectoriesNotWhatItReplaces(t *testing.T) {
|
||||
f := &fakeStep{}
|
||||
m, _ := fetchModule(t, f)
|
||||
root := filepath.Join(m.Work, "ws1")
|
||||
tree := filepath.Join(root, "tree")
|
||||
for d, body := range map[string]string{"mod": "module example.org/mod\nreplace example.org/lib => ../lib\n", "lib": "module example.org/lib\n"} {
|
||||
if err := os.MkdirAll(filepath.Join(tree, d), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(tree, d, "go.mod"), []byte(body), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for name, body := range map[string]string{scopeMark: "lib\nmod", moduleDirMark: "mod"} {
|
||||
if err := os.WriteFile(filepath.Join(root, name), []byte(body), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
dirs, err := m.testDirs(context.Background(), tree)
|
||||
if err != nil || !reflect.DeepEqual(dirs, []string{"mod"}) {
|
||||
t.Fatalf("the test directories = %v, %v; want mod alone", dirs, err)
|
||||
}
|
||||
if _, err := m.runLevel(context.Background(), tree, levelOpts{workspace: "ws1", level: LevelUnit}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, l := range f.lines() {
|
||||
if strings.Contains(l, "/tree/lib test") {
|
||||
t.Errorf("the module's unit level tested lib: %s", l)
|
||||
}
|
||||
}
|
||||
// No dir asked: every go.mod of the tree stays.
|
||||
if err := os.Remove(filepath.Join(root, moduleDirMark)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if dirs, _ = m.testDirs(context.Background(), tree); len(dirs) != 2 {
|
||||
t.Errorf("a workspace with no module directory tests %v, want every go.mod", dirs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func (m *Module) integrationHere(ctx context.Context, workspace, tree string, pa
|
||||
defer os.RemoveAll(run)
|
||||
|
||||
began := m.clock()
|
||||
dirs, err := m.goModDirs(ctx, tree)
|
||||
dirs, err := m.testDirs(ctx, tree)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -176,6 +176,10 @@ func TestTheWorkspaceIsSelfContainedAfterAFetchThroughTheMirror(t *testing.T) {
|
||||
return strings.TrimSpace(string(out))
|
||||
}
|
||||
git(src, "init", "-q")
|
||||
// A fetch is for one module (A-447b): the repository holds a module at its root.
|
||||
if err := os.WriteFile(filepath.Join(src, "go.mod"), []byte("module example.org/x\n\ngo 1.26\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(src, "f.txt"), []byte("one\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func TestAFetchWithNamedPathsNarrowsTheWorkspace(t *testing.T) {
|
||||
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"}})
|
||||
_, st = fetched(t, m, states, map[string]any{"repository": "novox/narrow", "commit": head, "dir": "", "paths": []any{"cmd"}})
|
||||
if st.State != sdkstep.StepFailed || !strings.Contains(st.Reason, "no module directory") {
|
||||
t.Errorf("paths without a directory: %s %q", st.State, st.Reason)
|
||||
}
|
||||
|
||||
@@ -50,7 +50,15 @@ func newPinHarness(t *testing.T, gomod string, vendor bool, pulls string) (*pinH
|
||||
for _, g := range strings.Fields(f.gomods) {
|
||||
d := filepath.Join(args[i+1], filepath.Dir(g))
|
||||
os.MkdirAll(d, 0o755)
|
||||
os.WriteFile(filepath.Join(d, "go.mod"), []byte(gomod), 0o644)
|
||||
body := gomod
|
||||
if g == "go.mod" { // the root replaces the other directories, so a fetch asked with it chooses them (A-447)
|
||||
for _, o := range strings.Fields(f.gomods) {
|
||||
if o != "go.mod" {
|
||||
body += "\nreplace local/" + filepath.Dir(o) + " => ./" + filepath.Dir(o) + "\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
os.WriteFile(filepath.Join(d, "go.mod"), []byte(body), 0o644)
|
||||
os.WriteFile(filepath.Join(d, "go.sum"), []byte("sum\n"), 0o644)
|
||||
}
|
||||
if vendor {
|
||||
|
||||
@@ -36,7 +36,7 @@ func (m *Module) run(ctx context.Context, fetch steprun.StepFunc, a sdkstep.Step
|
||||
return nil, err
|
||||
}
|
||||
key := sdkstep.RunKey(job.Program, sdkstep.ToolchainUsed{Version: installed, Recipe: m.Recipe.Version()}, a.Packages)
|
||||
fetchArgs := sdkstep.FetchRequest{Repository: job.Program.Repository, Commit: job.Program.Commit, Packages: a.Packages}.Args()
|
||||
fetchArgs := sdkstep.FetchRequest{Repository: job.Program.Repository, Commit: job.Program.Commit, Dir: job.Program.Dir, Packages: a.Packages}.Args()
|
||||
exe, built, err := m.programOf(ctx, fetch, "programs", "checking program", key, fetchArgs, job.Program.Dir, job.Program.Package)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -109,18 +109,22 @@ func (m *Module) test(ctx context.Context, args map[string]any) (any, error) {
|
||||
}
|
||||
|
||||
// compareGenerated regenerates the generated Go files of each contracts module in the tree (every module.json in the tree, in
|
||||
// any folder: ADR 0634 §8; CAT-BG5) and fails the level on any out of step, Why naming each path.
|
||||
// any folder: ADR 0634 §8; CAT-BG5; for a workspace fetched for a module's directory, that module's own alone) and fails the level on any out of step, Why naming each path.
|
||||
func compareGenerated(tree string, res *TestResult) error {
|
||||
dirs, err := steprun.ModuleDirs(tree)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, dir := range dirs {
|
||||
// A step for a module compares its own module.json alone, never another module's of the repository (A-447c).
|
||||
rel, _ := filepath.Rel(tree, dir)
|
||||
if own, ok := moduleDirOf(tree); ok && filepath.ToSlash(rel) != own {
|
||||
continue
|
||||
}
|
||||
paths, err := steprun.OutOfStep(dir, steprun.GeneratedRootGo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rel, _ := filepath.Rel(tree, dir)
|
||||
for _, p := range paths {
|
||||
res.OutOfStep = append(res.OutOfStep, filepath.ToSlash(filepath.Join(rel, p)))
|
||||
}
|
||||
@@ -252,7 +256,7 @@ type levelOpts struct {
|
||||
|
||||
// runLevel runs `go test -json` in each go.mod directory of the tree and judges the whole against the bounds.
|
||||
func (m *Module) runLevel(ctx context.Context, tree string, o levelOpts) (*TestResult, error) {
|
||||
dirs, err := m.goModDirs(ctx, tree)
|
||||
dirs, err := m.testDirs(ctx, tree)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -340,3 +340,36 @@ func TestADirectoryThatVendorsIsReadFromItsVendorDirectory(t *testing.T) {
|
||||
t.Errorf("the last GOFLAGS of go test in a vendoring directory is %q", flags)
|
||||
}
|
||||
}
|
||||
|
||||
// A-447c: a workspace fetched for a module's directory compares the generated files of that module's own module.json
|
||||
// alone, never another module's of the repository.
|
||||
func TestUnitLevelComparesOnlyTheOwnModulesGeneratedFiles(t *testing.T) {
|
||||
m, states, ws, _ := workspaceFor(t, "empty")
|
||||
tree := filepath.Join(m.Work, ws, "tree")
|
||||
for _, folder := range []string{"domain", "other"} {
|
||||
for p, text := range map[string]string{
|
||||
"module.json": `{"module":"c","build":{"artifacts":[{"name":"go","kind":"package","language":"go","paths":["go"],"generated-from":"."}]}}`,
|
||||
"seats/one-store/seat.json": `{"format":1,"seat":"one-store","scope":"mesh","grain":"seat-list","domain":"Module","decision":"ADR 1","verbs":[{"name":"query","input":{"type":"object"}}]}`,
|
||||
"go/go.mod": "module example.org/c/go\n",
|
||||
"go/stray.go": "package stray\n",
|
||||
} {
|
||||
full := filepath.Join(tree, folder, filepath.FromSlash(p))
|
||||
_ = os.MkdirAll(filepath.Dir(full), 0o755)
|
||||
if err := os.WriteFile(full, []byte(text), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(m.Work, ws, moduleDirMark), []byte("domain"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res, _ := runUnit(t, m, states, ws)
|
||||
if len(res.OutOfStep) == 0 {
|
||||
t.Fatalf("nothing out of step: %+v", res)
|
||||
}
|
||||
for _, p := range res.OutOfStep {
|
||||
if !strings.HasPrefix(p, "domain/") {
|
||||
t.Errorf("out of step = %v, want the module's own files under domain/ alone", res.OutOfStep)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestGoModVerifyRunsOncePerGoModAndGoSumDigest(t *testing.T) {
|
||||
|
||||
// Without bubblewrap the module cache is not read-only to a step: a pass is never reused.
|
||||
func TestAPassOfVerifyIsNotReusedWhenStepsAreNotShutOff(t *testing.T) {
|
||||
f := &fakeStep{gomods: "a/go.mod\nb/go.mod\n", files: map[string]string{"a/go.mod": "m\n", "b/go.mod": "m\n"}}
|
||||
f := &fakeStep{gomods: "a/go.mod\nb/go.mod\n", files: map[string]string{"a/go.mod": "module m\n", "b/go.mod": "module m\n"}}
|
||||
m, states := fetchModule(t, f) // no Bubblewrap
|
||||
fetchOnce(t, m, states, fetchArgs)
|
||||
fetchOnce(t, m, states, fetchArgs)
|
||||
@@ -65,7 +65,7 @@ func TestAPassOfVerifyIsNotReusedWhenStepsAreNotShutOff(t *testing.T) {
|
||||
// A verify that fails leaves no mark: the next fetch verifies again.
|
||||
func TestAFailedVerifyLeavesNoMark(t *testing.T) {
|
||||
fail := true
|
||||
f := &fakeStep{gomods: "go.mod\n", files: map[string]string{"go.mod": "m\n"}}
|
||||
f := &fakeStep{gomods: "go.mod\n", files: map[string]string{"go.mod": "module m\n"}}
|
||||
f.goRule = func(line string) forgekey.Ran {
|
||||
if strings.HasSuffix(line, " mod verify") && fail {
|
||||
return forgekey.Ran{Status: 1, Stdout: "x v1: dir has been modified\n"}
|
||||
@@ -88,7 +88,7 @@ func TestDownloadsRunSideBySideUpToTheBound(t *testing.T) {
|
||||
running, most := 0, 0
|
||||
release := make(chan struct{}) // closed once two run at once: they overlap however slowly the machine starts them
|
||||
f := &fakeStep{gomods: "a/go.mod\nb/go.mod\nc/go.mod\nd/go.mod\n", files: map[string]string{
|
||||
"a/go.mod": "a\n", "b/go.mod": "b\n", "c/go.mod": "c\n", "d/go.mod": "d\n"}}
|
||||
"a/go.mod": "module a\n", "b/go.mod": "module b\n", "c/go.mod": "module c\n", "d/go.mod": "module d\n"}}
|
||||
f.goRule = func(line string) forgekey.Ran {
|
||||
if strings.HasSuffix(line, " mod download") {
|
||||
mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user