mesh/delivery merged: source.main moved to novox/mesh-catalog@7cc81512a389
mesh/check checking 4a3914ee1ce7 on 3c0b4d29a8ea
go mod download loads only the module graph a go.mod names; a vet, a test or a build then loads packages shut off from the network and failed far from the fetch, in fewer words (the builder's "pull_drop.go:11:2: module lookup disabled by GOPROXY=off"). After each directory's download the fetch loads its packages with their tests shut off and fails naming each package whose load would reach the network. The graph of a sibling laid beside is loaded once with the network first, so a go.mod the composer's build reads and the graph's download skipped is fetched, then proven the same way. 1966/AC178-2: a row of TestAVerifyThatFailsEndsTheStepNamingTheDirectoryAndTheLine; the beside case in TestTheFetchDownloadsTheGraphOfASiblingModuleLaidWithTheTreesItRequires. Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
121 lines
6.4 KiB
Go
121 lines
6.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/forgekey"
|
|
)
|
|
|
|
// Issue 1921 (the fourth group try): a workspace whose members require each other at the zero version loads its module
|
|
// graph with no lookup, so with nothing fetched (GOPROXY=off), as a composer built beside the group's heads does.
|
|
func TestAWorkspaceOfTheGroupResolvesTheZeroVersionWithNoLookup(t *testing.T) {
|
|
root := t.TempDir()
|
|
mod := func(name, body string) string {
|
|
dir := filepath.Join(root, name)
|
|
if err := os.MkdirAll(dir, 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte(body), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return dir
|
|
}
|
|
a := mod("a", "module git.novox.be/novox/mesh-host\n\ngo 1.26.0\n\nrequire git.novox.be/novox/mesh-contracts/go/x "+zeroVersion+"\n")
|
|
b := mod("b", "module git.novox.be/novox/mesh-contracts/go/x\n\ngo 1.26.0\n")
|
|
// The group check of 8a80e8e86858: a module beside requiring one no tree holds is not laid, so nothing looks it up.
|
|
c := mod("c", "module git.novox.be/novox/mesh-delivery/modules/g\n\ngo 1.26.0\n\nrequire (\n\tgit.novox.be/novox/mesh-catalog/modules/d "+zeroVersion+"\n)\n")
|
|
work, err := workspaceOf(a, []string{b, c, b})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(work, c) {
|
|
t.Errorf("the workspace lays %s, which the composer does not require:\n%s", c, work)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(root, "go.work"), []byte(work), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cmd := exec.Command("go", "list", "-m", "all")
|
|
cmd.Dir = a
|
|
cmd.Env = append(os.Environ(), "GOWORK="+filepath.Join(root, "go.work"), "GOPROXY=off", "GOFLAGS=", "GOTOOLCHAIN=local")
|
|
if out, err := cmd.CombinedOutput(); err != nil || !strings.Contains(string(out), "git.novox.be/novox/mesh-contracts/go/x") {
|
|
t.Fatalf("the workspace's module graph does not load with nothing fetched: %v\n%s\n%s", err, out, work)
|
|
}
|
|
// A requirement at the zero version no tree holds is said before Go looks it up, naming it.
|
|
if _, err := workspaceOf(c, []string{a, b}); err == nil || !strings.Contains(err.Error(), "mesh-catalog/modules/d") {
|
|
t.Errorf("a requirement no tree holds: %v, want an error naming it", err)
|
|
}
|
|
}
|
|
|
|
// Issue 1921 (the group check of c5d32074c945): the integration level has no network, so the fetch, which has, downloads
|
|
// the graph the composer test builds: a sibling that is a Go module at its root, laid with what it requires at the zero
|
|
// version, found among the fetched tree and the other siblings. A failed download fails the fetch, naming the sibling.
|
|
func TestTheFetchDownloadsTheGraphOfASiblingModuleLaidWithTheTreesItRequires(t *testing.T) {
|
|
root := t.TempDir()
|
|
put := func(dir, body string) string {
|
|
if err := os.MkdirAll(dir, 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte(body), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return dir
|
|
}
|
|
tree := filepath.Join(root, "tree")
|
|
put(filepath.Join(tree, "modules", "x"), "module git.novox.be/novox/mesh-catalog/modules/x\n\ngo 1.26.0\n")
|
|
host := put(filepath.Join(root, "beside", "mesh-host"), "module github.com/novox/mesh-host\n\ngo 1.26.0\n\nrequire (\n\tgit.novox.be/novox/mesh-catalog/modules/x "+zeroVersion+"\n\tgit.novox.be/novox/mesh-sdk/go "+zeroVersion+"\n)\n")
|
|
put(filepath.Join(root, "beside", "mesh-sdk", "go"), "module git.novox.be/novox/mesh-sdk/go\n\ngo 1.26.0\n")
|
|
var said []string
|
|
var lines, envs []string
|
|
fail, lost := false, ""
|
|
m := &Module{Say: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }}
|
|
m.Run = func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran {
|
|
lines = append(lines, name+" "+strings.Join(args, " "))
|
|
envs = append(envs, strings.Join(env, "\n"))
|
|
if fail {
|
|
return forgekey.Ran{Status: 1, Stderr: "dial tcp: network is unreachable"}
|
|
}
|
|
if slices.Contains(env, "GOPROXY=off") {
|
|
return forgekey.Ran{Stdout: lost}
|
|
}
|
|
return forgekey.Ran{}
|
|
}
|
|
if err := m.downloadBeside(context.Background(), root, tree, []string{"modules/x"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// The graph's download, the packages' load with the network, then the same load shut off (issue 1966).
|
|
load := "go -C " + host + " list -e -deps -test -f " + shutOffLoadFormat + " ./..."
|
|
if len(lines) != 3 || lines[0] != "go -C "+host+" mod download" || lines[1] != load || lines[2] != load ||
|
|
!strings.Contains(envs[0], "GOWORK="+filepath.Join(root, "beside-0.work")) || strings.HasSuffix(envs[1], "GOPROXY=off") || !strings.HasSuffix(envs[2], "GOPROXY=off") {
|
|
t.Fatalf("commands %q env %q, want go mod download of the node-engine's module over its workspace, then its packages loaded with the network and shut off", lines, envs)
|
|
}
|
|
// 1966/AC178-3 (its unit half): the shut-off load misses a go.mod the composer's build reads: the fetch fails naming it.
|
|
lines, lost = nil, "github.com/nats-io/nkeys: github.com/nats-io/nkeys@v0.4.16 requires golang.org/x/crypto@v0.52.0: module lookup disabled by GOPROXY=off\n"
|
|
if err := m.downloadBeside(context.Background(), root, tree, []string{"modules/x"}); err == nil || !strings.Contains(err.Error(), "beside mesh-host") || !strings.Contains(err.Error(), "golang.org/x/crypto@v0.52.0: module lookup disabled") {
|
|
t.Errorf("a shut-off load that would reach the network = %v, want the fetch failed naming it", err)
|
|
}
|
|
lost = ""
|
|
work, _ := os.ReadFile(filepath.Join(root, "beside-0.work"))
|
|
for _, want := range []string{filepath.Join(tree, "modules", "x"), filepath.Join(root, "beside", "mesh-sdk", "go"), host} {
|
|
if !strings.Contains(string(work), want) {
|
|
t.Errorf("the workspace lays no %s:\n%s", want, work)
|
|
}
|
|
}
|
|
fail = true
|
|
if err := m.downloadBeside(context.Background(), root, tree, []string{"modules/x"}); err == nil || !strings.Contains(err.Error(), "mesh-host") || !strings.Contains(err.Error(), "network is unreachable") {
|
|
t.Errorf("a failed download = %v, want it named", err)
|
|
}
|
|
// A requirement no tree holds is said and the sibling left out; the test that builds it fails naming the module.
|
|
put(filepath.Join(root, "beside", "mesh-host"), "module github.com/novox/mesh-host\n\ngo 1.26.0\n\nrequire git.novox.be/novox/nobody/go "+zeroVersion+"\n")
|
|
lines, said = nil, nil
|
|
if err := m.downloadBeside(context.Background(), root, tree, nil); err != nil || len(lines) != 0 || len(said) != 1 || !strings.Contains(said[0], "nobody/go") {
|
|
t.Errorf("an unheld requirement: err %v, commands %q, said %q", err, lines, said)
|
|
}
|
|
}
|