diff --git a/modules/mesh-delivery-sdk/buildstep/ask_test.go b/modules/mesh-delivery-sdk/buildstep/ask_test.go index 5467bf23..e996d4c2 100644 --- a/modules/mesh-delivery-sdk/buildstep/ask_test.go +++ b/modules/mesh-delivery-sdk/buildstep/ask_test.go @@ -87,6 +87,7 @@ func TestAskCheckAndRoundTrip(t *testing.T) { {"no path", func(a *StepAsk) { a.Build.Path = "" }, "names no directory"}, {"short commit", func(a *StepAsk) { a.Build.Fetch.Commit = "abc" }, "full commit"}, {"bad package pin", func(a *StepAsk) { a.Packages = PackageVersions{"m": "main"} }, "neither a full commit"}, + {"empty package pin", func(a *StepAsk) { a.Packages = PackageVersions{"m/x": ""} }, "neither a full commit"}, } { a := goodBuild() c.edit(&a) @@ -94,6 +95,27 @@ func TestAskCheckAndRoundTrip(t *testing.T) { t.Errorf("%s: %v, want %q", c.name, err, c.want) } } + // Design 47 H, S8 (H-A-204, H-A-165): a catalog entry's packages name a package with no version published yet by an + // empty version, which waits for its publish; the entry form allows it, an ask's pins never do (above). + for _, c := range []struct { + name string + p PackageVersions + entry string // what CheckEntry's refusal holds, "" for none + pinsToo bool // Check (an ask's pins) passes it as well + }{ + {name: "an empty version", p: PackageVersions{"m/x": "", "m/y": "v0.1.3"}}, + {name: "versions only", p: PackageVersions{"m/y": "v0.1.3", "m/z": testCommit}, pinsToo: true}, + {name: "a version that is no version", p: PackageVersions{"m/x": "main"}, entry: "neither a full commit"}, + {name: "no module path", p: PackageVersions{"": ""}, entry: "no module path"}, + } { + err := c.p.CheckEntry() + if (err == nil) != (c.entry == "") || (err != nil && !strings.Contains(err.Error(), c.entry)) { + t.Errorf("%s: CheckEntry answered %v, want %q", c.name, err, c.entry) + } + if err := c.p.Check(); (err == nil) != c.pinsToo { + t.Errorf("%s: Check answered %v, want a pass %v", c.name, err, c.pinsToo) + } + } // 1921 (B0, G): a run ask goes only on the Go seat's check stream, alone, builds a clean package at a full commit // over heads named once at full commits, and names its input on a seat's verb by a digest within its bound. for _, c := range []struct { diff --git a/modules/mesh-delivery-sdk/buildstep/steps.go b/modules/mesh-delivery-sdk/buildstep/steps.go index 84b4e0db..33a4fa3a 100644 --- a/modules/mesh-delivery-sdk/buildstep/steps.go +++ b/modules/mesh-delivery-sdk/buildstep/steps.go @@ -184,16 +184,27 @@ var ( ) // PackageVersions are the versions of the mesh packages a build or a check builds against, by package (a Go module's -// path): each a full commit or a Go semantic version. +// path): each a full commit or a Go semantic version. A catalog entry's packages may also name a package with an empty +// version, one of another repository with no version published yet in its series, which waits for its publish (design +// 47 H, S8, S9; H-A-204, H-A-165): CheckEntry allows it, Check (an ask's pins) never. type PackageVersions map[string]string // Check refuses a package that is no module path or a version that is neither a full commit nor a Go semantic -// version, naming it. -func (p PackageVersions) Check() error { +// version, naming it: an ask's pins, an empty version among them. +func (p PackageVersions) Check() error { return p.check(false) } + +// CheckEntry is Check for a catalog entry's packages: an empty version is allowed, and stands for a package not +// published yet, whose build waits for its publish (design 47 H, S8; H-A-204, H-A-165). +func (p PackageVersions) CheckEntry() error { return p.check(true) } + +func (p PackageVersions) check(emptyAllowed bool) error { for pkg, version := range p { if pkg == "" || strings.ContainsAny(pkg, " \t\n@") || strings.HasPrefix(pkg, "/") { return fmt.Errorf("buildstep: the package %q is no module path", pkg) } + if version == "" && emptyAllowed { + continue + } if !askCommitOK.MatchString(version) && !PackageSemver.MatchString(version) { return fmt.Errorf("buildstep: the package %s names the version %q, which is neither a full commit nor a Go semantic version (v0.1.15-feat-x.2)", pkg, version) }