mesh-build-go: G6 reproducible-go, the kit's case over a bundle, an archive and a Go package
The build step builds a fixture of each kind it builds twice, in two workspace folders of other names and file times, and requires one digest per artifact. The case names nothing to fix: the recipe's -trimpath and -buildvcs=false, the epoch-timed sorted pack and the Go module zip give one digest (without -trimpath the case fails, naming the artifact and both digests). Builds: design 47 H2 H-A-591 (1) (5), H-A-593 (3)
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -46,7 +48,7 @@ func TestTheStartSweepEndsWhatAPreviousProcessLeft(t *testing.T) {
|
||||
// not answer as a transport fault, and a failure of the source (an unknown revision, a checksum) as none.
|
||||
func TestTheStepsSayAFailedNetworkAsATransportFault(t *testing.T) {
|
||||
// A step whose fetch or publish met its holder away is given again after the module's again-delays, 15 s after its
|
||||
// first run and 60 s after its second by default (design 47 H2 §799; H-A-390).
|
||||
// first run and 90 s after its second by default, a span past the tool runner's restart (design 47 H2 §799; H-A-390, H-A-603).
|
||||
t.Run("again-delays is declared and read", func(t *testing.T) {
|
||||
raw, err := os.ReadFile(filepath.Join("..", "..", "module.json"))
|
||||
if err != nil {
|
||||
@@ -65,7 +67,7 @@ func TestTheStepsSayAFailedNetworkAsATransportFault(t *testing.T) {
|
||||
decl, ok := m.Config[steprun.AgainDelaysSetting]
|
||||
_ = json.Unmarshal(decl, &c)
|
||||
delay, err := steprun.AgainDelays(c.Default)
|
||||
if !ok || !c.Runtime || err != nil || delay(1) != 15*time.Second || delay(2) != 60*time.Second {
|
||||
if !ok || !c.Runtime || err != nil || delay(1) != 15*time.Second || delay(2) != 90*time.Second {
|
||||
t.Fatalf("again-delays declared %v as %+v: %v", ok, c, err)
|
||||
}
|
||||
})
|
||||
@@ -121,3 +123,59 @@ func TestThePullerCountsRunsThatStarted(t *testing.T) {
|
||||
return m.Puller(nil, steprun.NewFakeAsks())
|
||||
})
|
||||
}
|
||||
|
||||
// H-A-591 (4), H-A-593 (3): the kit's `reproducible` case. The module's own build step builds a fixture of each kind it builds (a bundle with the real
|
||||
// go, an archive, a Go package) twice, in two workspace folders of other names and other file times, and the archive's digest is the same: nothing of
|
||||
// the folder, the clock or the commit is in the program or its archive.
|
||||
func TestTheBuildOfABundleIsOneDigestInAnyFolder(t *testing.T) {
|
||||
if _, err := exec.LookPath("go"); err != nil {
|
||||
t.Skip("NOT RUN: no go installed where this check runs")
|
||||
}
|
||||
fill := func(dir string) error {
|
||||
module := filepath.Join(dir, "ws1", "tree", "modules", "demo")
|
||||
files := map[string]string{
|
||||
"module.json": manifestWith(goBundle + `,{"name":"files","kind":"archive","from":"files"},` +
|
||||
`{"name":"lib","kind":"package","language":"go","paths":["lib"]}`),
|
||||
"files/a.txt": "a",
|
||||
"files/b/c.txt": "c",
|
||||
"lib/go.mod": "module git.example/demo/lib\n\ngo 1.26\n",
|
||||
"lib/lib.go": "package lib\n",
|
||||
"go.mod": "module demo\n\ngo 1.26\n",
|
||||
"cmd/demo-tools/main.go": "package main\n\nimport \"fmt\"\n\nvar meshVersion, builtFor string\n\nfunc main() { fmt.Println(\"demo\", meshVersion, builtFor) }\n",
|
||||
}
|
||||
for name, body := range files {
|
||||
if err := os.MkdirAll(filepath.Dir(filepath.Join(module, name)), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(module, name), []byte(body), 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
conformance.Reproducible(t, fill, func(dir string) (map[string]string, error) {
|
||||
states := newStates()
|
||||
m := moduleWith(states, "go1.27.1")
|
||||
m.Home, m.Work, m.Cache = t.TempDir(), dir, t.TempDir()
|
||||
m.Inside = true // the compile runs as itself: the kit's folders hold the whole difference
|
||||
run := StepRunner(m.Home)
|
||||
// no go.work of a folder above the kit's (a checker's, a placement's) takes the fixture into its workspace
|
||||
m.Run = func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran {
|
||||
return run(ctx, append(env, "GOWORK=off"), name, args...)
|
||||
}
|
||||
withStore(t, m)
|
||||
out := map[string]string{}
|
||||
for _, artifact := range []string{"tools", "files", "lib"} {
|
||||
args := map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": artifact, "version": askedVersion}
|
||||
if artifact == "lib" {
|
||||
args["seat"] = GoPackageSeat
|
||||
}
|
||||
res, st := runBuildArgs(t, m, states, args)
|
||||
if st.State != sdkstep.StepPassed {
|
||||
return nil, fmt.Errorf("the build step of %s ended %s: %s", artifact, st.State, st.Reason)
|
||||
}
|
||||
out[artifact] = res.Digest
|
||||
}
|
||||
return out, nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user