BM publish version: the build modules' bundle asks name the ask's version, as the SDK now refuses one without

A bundle publishes under the version its ask reserved, and the delivery SDK's
publish refuses an empty one loudly; the tests' bundle asks carry a version, a
bundle asked with none is shown refused, and an archive still publishes by its
digest alone.

Builds: design 47 H2 H-A-373, H-A-373 addendum
This commit is contained in:
2026-11-22 01:50:30 +01:00
parent d3d9ff5183
commit 22b92b827d
10 changed files with 56 additions and 31 deletions
@@ -61,6 +61,16 @@ func runBuild(t *testing.T, m *Module, states *keptStates, artifact string) (Bui
return runBuildArgs(t, m, states, map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": artifact})
}
// askedVersion is the version a test's bundle ask reserved: every bundle publishes under the ask's version, and the
// delivery SDK refuses one that names none (design 47 H, H-A-373); an archive may still publish by its digest alone.
const askedVersion = "1.4.3"
// runBundle runs the build tool for a bundle artifact under the ask's version, as the builder asks it.
func runBundle(t *testing.T, m *Module, states *keptStates, artifact string) (BuildResult, sdkstep.Step) {
t.Helper()
return runBuildArgs(t, m, states, map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": artifact, "version": askedVersion})
}
// runBuildArgs runs the build tool with args, such as an ask's version, and answers what its step ended with.
func runBuildArgs(t *testing.T, m *Module, states *keptStates, args map[string]any) (BuildResult, sdkstep.Step) {
t.Helper()
@@ -111,7 +121,7 @@ func goEntry(t *testing.T) (compile []string, linker []string, stamp string) {
// GOFLAGS=-trimpath -buildvcs=false, go build, -ldflags -s -w -X main.builtFor=<system>, -o <out>/<binary>, the package.
func TestTheBuildCommandCarriesTodaysFlagsAndEnvironment(t *testing.T) {
m, states, calls := buildModule(t, manifestWith(goBundle), "binary")
res, st := runBuild(t, m, states, "tools")
res, st := runBundle(t, m, states, "tools")
if st.State != sdkstep.StepPassed {
t.Fatalf("the step ended %s: %s", st.State, st.Reason)
}
@@ -135,7 +145,7 @@ func TestTheBuildCommandCarriesTodaysFlagsAndEnvironment(t *testing.T) {
}
dir := filepath.Join(m.Work, "ws1", "tree", "modules", "demo")
out := filepath.Join(dir, ".mesh-build", "tools")
want := "go -C " + dir + " build -ldflags " + strings.Join(linker, " ") + " -X " + stamp + "=arch -o " + filepath.Join(out, "demo-bin") + " ./cmd/demo-tools"
want := "go -C " + dir + " build -ldflags " + strings.Join(linker, " ") + " -X " + stamp + "=arch -X " + versionStamp + "=" + askedVersion + " -o " + filepath.Join(out, "demo-bin") + " ./cmd/demo-tools"
if c.line != want {
t.Errorf("command = %q\nwant %q", c.line, want)
}
@@ -148,8 +158,8 @@ func TestTheBuildCommandCarriesTodaysFlagsAndEnvironment(t *testing.T) {
// are one digest.
func TestTheArchiveHoldsOneExecutableAndTwoBuildsAreOneDigest(t *testing.T) {
m, states, _ := buildModule(t, manifestWith(goBundle), "the program")
first, _ := runBuild(t, m, states, "tools")
second, _ := runBuild(t, m, states, "tools")
first, _ := runBundle(t, m, states, "tools")
second, _ := runBundle(t, m, states, "tools")
if first.Digest != second.Digest || first.Reference != second.Reference {
t.Errorf("two builds: %+v and %+v", first, second)
}
@@ -182,7 +192,7 @@ func TestAnArtifactOfAnotherLanguageFailsTheStepNamingIt(t *testing.T) {
`{"name":"tools","kind":"image","from":"files"}`: "image",
} {
m, states, calls := buildModule(t, manifestWith(artifact), "x")
_, st := runBuild(t, m, states, "tools")
_, st := runBundle(t, m, states, "tools")
if st.State != sdkstep.StepFailed || !strings.Contains(st.Reason, "tools") || !strings.Contains(st.Reason, want) || len(*calls) != 0 {
t.Errorf("%s: the step ended %s: %q after %d commands", artifact, st.State, st.Reason, len(*calls))
}
@@ -202,7 +212,7 @@ func TestTheBinaryIsNamedAsTheBuildAgentNamesIt(t *testing.T) {
`{"name":"tools","kind":"bundle","language":"go","system":"arch","from":".","loads":["tools"]}`: "tools",
} {
m, states, _ := buildModule(t, manifestWith(artifact), "x")
if res, st := runBuild(t, m, states, "tools"); res.Binary != want {
if res, st := runBundle(t, m, states, "tools"); res.Binary != want {
t.Errorf("%s: binary %q, want %q (%s %s)", artifact, res.Binary, want, st.State, st.Reason)
}
}
@@ -235,7 +245,7 @@ func TestABuildOutputDirectoryLinkedOutsideTheModuleIsRefused(t *testing.T) {
if err := os.Symlink(outside, filepath.Join(m.Work, "ws1", "tree", "modules", "demo", ".mesh-build")); err != nil {
t.Fatal(err)
}
_, st := runBuild(t, m, states, "tools")
_, st := runBundle(t, m, states, "tools")
if st.State != sdkstep.StepFailed || !strings.Contains(st.Reason, "outside") || !strings.Contains(st.Reason, outside) || len(*calls) != 0 {
t.Errorf("the step ended %s: %q after %d commands", st.State, st.Reason, len(*calls))
}
@@ -253,7 +263,7 @@ func TestAManifestFallingBackToAPredefinedKeyBuilds(t *testing.T) {
t.Fatal("the captured manifest no longer falls back to a predefined key")
}
m, states, _ := buildModule(t, string(raw), "binary")
res, st := runBuild(t, m, states, "tools")
res, st := runBundle(t, m, states, "tools")
if st.State != sdkstep.StepPassed {
t.Fatalf("the step ended %s: %s", st.State, st.Reason)
}
@@ -274,8 +284,10 @@ func TestTheBuildGetsTheVersionTheAskCarriesAsMeshVersion(t *testing.T) {
}
}
}
if st := states.waitEnd(t); st.State != sdkstep.StepPassed {
t.Fatalf("the step ended %s: %s", st.State, st.Reason)
// A bundle asked with no version is built, stamped with none, and its publish refused loudly (H-A-373).
if st := states.waitEnd(t); (version != "") != (st.State == sdkstep.StepPassed) ||
version == "" && !strings.Contains(st.Reason, "names no version") {
t.Fatalf("ask version %q: the step ended %s: %s", version, st.State, st.Reason)
}
got := ""
for _, r := range *calls {
@@ -167,7 +167,7 @@ func TestABuildRunsShutOffAndOnlyATrunkBuildWritesTheCaches(t *testing.T) {
var seen []shutOff
m.Run = throughBubblewrap(t, m.Run, &seen)
run := stepTool(t, m, "build_go_build")
args := map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": "tools"}
args := map[string]any{"workspace": "ws1", "module": "modules/demo", "artifact": "tools", "version": askedVersion}
if publish {
args["publish"] = true
}
@@ -59,7 +59,7 @@ func TestRealFetchAndBuildOfAMemberAskedAPullHeadItsGoModDoesNotName(t *testing.
// The build runs shut off in bubblewrap (1309), which a build node has and build-agent's check container has not:
// there the build half is not run, said loudly; the fetch half above, the pin's own part (issue 1148), always is.
needTools(t, "the shut-off build of a member pinning a pull head", "bwrap")
built, err := m.build(context.Background(), map[string]any{"workspace": res.Workspace, "module": ".", "artifact": "tools"})
built, err := m.build(context.Background(), map[string]any{"workspace": res.Workspace, "module": ".", "artifact": "tools", "version": askedVersion})
if err != nil {
t.Fatal(fmt.Errorf("the build: %w", err))
}
@@ -136,13 +136,13 @@ func TestARefusedPushFailsTheStepNotStored(t *testing.T) {
m, states, _ := buildModule(t, manifestWith(goBundle), "the program")
store := withStore(t, m)
store.fail = errors.New("refused: the forge did not take it: disk full")
if _, st := runBuild(t, m, states, "tools"); st.State != sdkstep.StepFailed || !strings.HasPrefix(st.Reason, builds.NotStored+"tools: ") || !strings.Contains(st.Reason, "disk full") {
if _, st := runBundle(t, m, states, "tools"); st.State != sdkstep.StepFailed || !strings.HasPrefix(st.Reason, builds.NotStored+"tools: ") || !strings.Contains(st.Reason, "disk full") {
t.Errorf("the step ended %s: %q", st.State, st.Reason)
}
m.Call = func(string, any) (json.RawMessage, error) {
return nil, errors.New("nats: no responders available for request")
}
if _, st := runBuild(t, m, states, "tools"); st.State != sdkstep.StepFailed || !strings.HasPrefix(st.Reason, builds.NotStored+"tools: ") ||
if _, st := runBundle(t, m, states, "tools"); st.State != sdkstep.StepFailed || !strings.HasPrefix(st.Reason, builds.NotStored+"tools: ") ||
!strings.Contains(st.Reason, "oci-artifact-registry") {
t.Errorf("no holder: the step ended %s: %q", st.State, st.Reason)
}
@@ -151,7 +151,7 @@ func TestARefusedPushFailsTheStepNotStored(t *testing.T) {
m.Call = func(key string, _ any) (json.RawMessage, error) {
return nil, errors.New("nats: no responders available for request")
}
if _, st := runBuild(t, m, states, "tools"); st.State != sdkstep.StepFailed || !st.Passing || !strings.Contains(st.Reason, "publish: ") {
if _, st := runBundle(t, m, states, "tools"); st.State != sdkstep.StepFailed || !st.Passing || !strings.Contains(st.Reason, "publish: ") {
t.Errorf("the step ended %s: %q (passing %v)", st.State, st.Reason, st.Passing)
}
}
@@ -162,7 +162,7 @@ func TestThePackedFileLeavesTheNodeOnceItsPushAnswered(t *testing.T) {
for _, fail := range []error{nil, errors.New("refused")} {
m, states, _ := buildModule(t, manifestWith(goBundle), "the program")
withStore(t, m).fail = fail
runBuild(t, m, states, "tools")
runBundle(t, m, states, "tools")
var archives []string
filepath.WalkDir(m.Work, func(p string, d os.DirEntry, err error) error {
if err == nil && strings.HasSuffix(p, ".tar.gz") {
@@ -139,8 +139,13 @@ func TestADoneBuildsArtifactsResolveInARealArtifactStore(t *testing.T) {
m.Run = StepRunner(home)
addr := realStore(t, m)
done := builds.BuilderBuild{V: 1, State: builds.BuildDone, Manifest: strings.Repeat("0", 64)}
for _, a := range []struct{ name, kind string }{{"tools", "bundle"}, {"files", "archive"}} {
out, err := m.build(context.Background(), map[string]any{"workspace": "ws1", "module": ".", "artifact": a.name})
// The bundle publishes under the ask's version, the archive by its digest alone (H-A-373 and its addendum).
for _, a := range []struct{ name, kind, version string }{{"tools", "bundle", askedVersion}, {"files", "archive", ""}} {
args := map[string]any{"workspace": "ws1", "module": ".", "artifact": a.name}
if a.version != "" {
args["version"] = a.version
}
out, err := m.build(context.Background(), args)
if err != nil {
t.Fatalf("%s: %v", a.name, err)
}
@@ -206,7 +206,7 @@ func TestBuildTwiceGivesOneDigestAndOneExecutable(t *testing.T) {
m := &Module{Home: home, Work: work, Cache: t.TempDir()}
m.Run = StepRunner(home)
withStore(t, m)
args := map[string]any{"workspace": "ws1", "module": ".", "artifact": "tools"}
args := map[string]any{"workspace": "ws1", "module": ".", "artifact": "tools", "version": askedVersion} // a bundle publishes under the ask's version (H-A-373)
first, err := m.build(context.Background(), args)
if err != nil {
t.Fatal(err)
@@ -117,7 +117,7 @@ func TestTheFixturePassesTheUnitLevelAndBuildsTwiceToOneDigest(t *testing.T) {
}
var digests []string
for _, id := range []string{"w1", "w2"} {
out, err := m.build(context.Background(), map[string]any{"workspace": id, "module": "modules/m", "artifact": "tools"})
out, err := m.build(context.Background(), map[string]any{"workspace": id, "module": "modules/m", "artifact": "tools", "version": askedVersion})
if err != nil {
t.Fatal(err)
}
@@ -55,8 +55,13 @@ func esbuildEffect(t *testing.T) func(c call) {
}
}
// askedVersion is the version a test's bundle ask reserved: every bundle publishes under the ask's version, and the
// delivery SDK refuses one that names none (design 47 H, H-A-373).
const askedVersion = "1.4.3"
// buildArgs is a bundle's build ask, under the version the ask reserved.
func buildArgs() map[string]any {
return map[string]any{"workspace": "w1", "module": "modules/m", "artifact": "tools"}
return map[string]any{"workspace": "w1", "module": "modules/m", "artifact": "tools", "version": askedVersion}
}
func builtMachine(t *testing.T, extra string) (*Module, *fakeMachine, string) {
@@ -309,11 +314,13 @@ func TestTheBundleBuildGetsTheVersionTheAskCarriesAsMeshVersion(t *testing.T) {
for _, version := range []string{"1.4.3", ""} {
m, f, _ := builtMachine(t, "")
args := buildArgs()
if version != "" {
args["version"] = version
args["version"] = version
if version == "" {
delete(args, "version")
}
if _, err := m.build(context.Background(), args); err != nil {
t.Fatal(err)
// A bundle asked with no version is built with none, and its publish refused loudly (H-A-373).
if _, err := m.build(context.Background(), args); (err != nil) != (version == "") || err != nil && !strings.Contains(err.Error(), "names no version") {
t.Fatalf("ask version %q: %v", version, err)
}
for _, c := range f.calls {
got := ""
@@ -336,11 +343,13 @@ func TestTheBundleCarriesTheAsksVersionInItsPackageJSON(t *testing.T) {
m, f, work := builtMachine(t, "")
workspaceWith(t, work, map[string]string{"modules/m/package.json": `{"name":"m","version":"0.0.0"}`})
args := buildArgs()
if c.version != "" {
args["version"] = c.version
args["version"] = c.version
if c.version == "" {
delete(args, "version")
}
if _, err := m.build(context.Background(), args); err != nil {
t.Fatal(err)
// A bundle asked with no version keeps the package.json's, and its publish is refused loudly (H-A-373).
if _, err := m.build(context.Background(), args); (err != nil) != (c.version == "") || err != nil && !strings.Contains(err.Error(), "names no version") {
t.Fatalf("ask version %q: %v", c.version, err)
}
_ = f
raw, err := os.ReadFile(filepath.Join(work, "w1", "stage-tools", "modules", "module", "package.json"))
@@ -106,7 +106,6 @@ func TestADoneBundleAnswersTheReferenceOfTheArchiveItPushed(t *testing.T) {
m, _, _ := builtMachine(t, ``)
store := withStore(t, m)
args := buildArgs()
args["version"] = "1.4.3"
out, err := m.build(context.Background(), args)
if err != nil {
t.Fatal(err)
@@ -96,7 +96,7 @@ func TestADoneBundleResolvesInARealArtifactStore(t *testing.T) {
needBubblewrap(t)
m, _ := realMachine(t)
addr := realStore(t, m)
out, err := m.build(context.Background(), map[string]any{"workspace": "w1", "module": "modules/m", "artifact": "tools"})
out, err := m.build(context.Background(), map[string]any{"workspace": "w1", "module": "modules/m", "artifact": "tools", "version": askedVersion})
if err != nil {
t.Fatal(err)
}