DLV-C3r3 (Node): mesh-build-node places a group's tagged version of the SDK from the registry

ADR 0607 §3, §5: the fetch's package argument also takes {name, version}; the version is placed from the registry in
each TypeScript member whatever its lock names, checked against the lock's integrity when the lock names it, else the
registry's; nothing is packed then, and a version the registry lacks fails naming it. The packed {repository, commit}
form stays for a checker that hands it. Rows in the placement and argument tests.

Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
2026-11-04 13:23:10 +01:00
parent cd66db54bf
commit ed7c6c4fb6
3 changed files with 106 additions and 21 deletions
@@ -25,6 +25,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"sort"
"strings"
"time"
@@ -219,8 +220,13 @@ func (m *Module) buildAndPack(ctx context.Context, root, dir, rel string, write
}
// groupPackage is the fetch's `package` argument: the group's package member (ADR 0500 §5), which the fetch packs and
// serves to its TypeScript members in place of the registry's version.
type groupPackage struct{ Repository, Commit, Ref string }
// serves to its TypeScript members in place of the registry's version, or, by Name and Version, the group's tagged
// version of the SDK, which the fetch places from the registry in each TypeScript member, whatever version its lock
// names (novox/hq ADR 0607 §3, §5; design 51 *Tagged versions*): nothing is packed then.
type groupPackage struct{ Repository, Commit, Ref, Name, Version string }
// tagged says whether the argument names a tagged version to take from the registry, not a member to pack.
func (g *groupPackage) tagged() bool { return g != nil && g.Version != "" }
func groupPackageArg(v any) (*groupPackage, error) {
if v == nil {
@@ -228,9 +234,20 @@ func groupPackageArg(v any) (*groupPackage, error) {
}
o, ok := v.(map[string]any)
if !ok {
return nil, fmt.Errorf("package is {repository, commit, ref}")
return nil, fmt.Errorf("package is {repository, commit, ref} or {name, version}")
}
g := &groupPackage{}
g.Name, _ = o["name"].(string)
g.Version, _ = o["version"].(string)
if g.Name != "" || g.Version != "" {
if g.Name != sdkPackage {
return nil, fmt.Errorf("package: %q is not %s, the one package the fetch places in a member", g.Name, sdkPackage)
}
if !npmVersionOK.MatchString(g.Version) {
return nil, fmt.Errorf("package: %q is not a version (0.1.15-feat-x.2)", g.Version)
}
return g, nil
}
g.Repository, _ = o["repository"].(string)
g.Commit, _ = o["commit"].(string)
g.Ref, _ = o["ref"].(string)
@@ -246,6 +263,9 @@ func groupPackageArg(v any) (*groupPackage, error) {
return g, nil
}
// npmVersionOK is a semantic version as npm names one, with an optional pre-release (a tagged version's).
var npmVersionOK = regexp.MustCompile(`^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$`)
// packGroup fetches the group's package member into the workspace, installs its dependencies, builds and packs it,
// publishing nothing (ADR 0500 §4).
func (m *Module) packGroup(ctx context.Context, root string, run forgekey.Runner, g *groupPackage) (packed, error) {
@@ -290,21 +310,45 @@ func sdkLocked(dir string) (version, integrity string, ok bool, err error) {
// placeSDK places in the module's node_modules the SDK version its lock names (the lead's decision L10): the group's
// packed package when it is that version (its integrity must be the lock's), else the registry's; a version neither
// holds is a wait (`waits for:`) when no group package was given, and a failure naming both when one was.
func (m *Module) placeSDK(ctx context.Context, dir, rel string, group *packed) error {
// holds is a wait (`waits for:`) when no group package was given, and a failure naming both when one was. Given the
// group's tagged version (tagged, ADR 0607 §3), that version is placed from the registry whatever the lock names, its
// integrity the lock's when the lock names it, else the registry's own; one the registry lacks fails naming it.
func (m *Module) placeSDK(ctx context.Context, dir, rel string, group *packed, tagged *groupPackage) error {
version, integrity, ok, err := sdkLocked(dir)
if err != nil || !ok {
return err
}
want := sdkPackage + "@" + version
var tgz []byte
switch {
case tagged.tagged():
if version != tagged.Version {
if m.Say != nil {
m.Say("%s: its lock names %s@%s; the group's tagged version %s is placed (ADR 0607 §3)", rel, sdkPackage, version, tagged.Version)
}
version, integrity = tagged.Version, ""
}
want := sdkPackage + "@" + version
got, registered, held, err := m.registryPackageChecked(ctx, sdkPackage, version)
if err != nil {
return err
}
if !held {
return fmt.Errorf("the registry holds no %s, the group's tagged version, so %s cannot be built against it", want, rel)
}
if integrity == "" {
integrity = registered
}
if integrity != "" && integrityOf(got) != integrity {
return fmt.Errorf("the registry's %s is %s, and %s names %s", want, integrityOf(got), rel, integrity)
}
tgz = got
case group != nil && group.Name == sdkPackage && group.Version == version:
if integrity != "" && integrity != group.Integrity {
return fmt.Errorf("the lock of %s names %s with the integrity %s, and the group's package packs to %s", rel, want, integrity, group.Integrity)
return fmt.Errorf("the lock of %s names %s with the integrity %s, and the group's package packs to %s", rel, sdkPackage+"@"+version, integrity, group.Integrity)
}
tgz = group.tgz
default:
want := sdkPackage + "@" + version
got, held, err := m.registryPackage(ctx, sdkPackage, version)
if err != nil {
return err
@@ -327,6 +371,16 @@ func (m *Module) placeSDK(ctx context.Context, dir, rel string, group *packed) e
return unpackPackage(tgz, into)
}
// registryPackageChecked is registryPackage with the integrity the registry's document names of name@version.
func (m *Module) registryPackageChecked(ctx context.Context, name, version string) (tgz []byte, integrity string, held bool, err error) {
_, integrity, held, err = m.registryVersion(ctx, name, version)
if err != nil || !held {
return nil, "", held, err
}
tgz, held, err = m.registryPackage(ctx, name, version)
return tgz, integrity, held, err
}
// httpClient is the client of the registry's reads and publishes: HTTP when a test set it.
func (m *Module) httpClient() *http.Client {
if m.HTTP != nil {