A-285: the Node fetch packs each of the group's packages and places it by name
The fetch takes `group-packages` (a member's repository, commit, ref and the package's directory there) in place of the single `package` and its tagged form; it packs each package a module of the tree takes, publishing nothing, and places it in every module whose package.json names it, the SDK in every module, in place of the registry's whatever the lock names. Builds: design 47 G A-284, A-285 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -108,7 +108,7 @@ func TestAMemberGetsTheLatestPublishedSDKWhateverItsLockNames(t *testing.T) {
|
||||
{name: "a lock naming the latest with another integrity", locks: "0.1.15", integrity: "sha512-another", fails: "sha512-another"},
|
||||
} {
|
||||
dir := memberLocking(t, c.locks, c.integrity)
|
||||
err := m.placeSDK(context.Background(), dir, "modules/m", nil, nil)
|
||||
err := m.placeSDK(context.Background(), dir, "modules/m", nil)
|
||||
switch {
|
||||
case c.fails == "" && (err != nil || placedVersion(dir) != "0.1.15"):
|
||||
t.Errorf("%s: %v, placed %q, want the latest release 0.1.15", c.name, err, placedVersion(dir))
|
||||
@@ -117,89 +117,69 @@ func TestAMemberGetsTheLatestPublishedSDKWhateverItsLockNames(t *testing.T) {
|
||||
}
|
||||
}
|
||||
fakeRegistry(t, m, map[string][]byte{"0.1.16-feat-x.1": pre})
|
||||
if err := m.placeSDK(context.Background(), memberLocking(t, "0.1.15", ""), "modules/m", nil, nil); err == nil || err.Error() != builds.WaitsFor+"@novox/mesh-sdk" {
|
||||
if err := m.placeSDK(context.Background(), memberLocking(t, "0.1.15", ""), "modules/m", nil); err == nil || err.Error() != builds.WaitsFor+"@novox/mesh-sdk" {
|
||||
t.Errorf("a registry with no release answered %v, want %s@novox/mesh-sdk", err, builds.WaitsFor)
|
||||
}
|
||||
held = tgzOf(t, sdkPackage, "0.1.15")
|
||||
fakeRegistry(t, m, map[string][]byte{"0.1.15": held})
|
||||
var dir string
|
||||
// ADR 0607 §3, §5 (design 51 *Tagged versions*): given the group's tagged version, the fetch places it from the
|
||||
// registry whatever the lock names, against the lock's integrity when the lock names it, else the registry's; one the
|
||||
// registry lacks fails naming it, no wait (the check waited for its published).
|
||||
tagged := pre
|
||||
fakeRegistry(t, m, map[string][]byte{"0.1.15": held, "0.1.16-feat-x.1": tagged})
|
||||
group := &groupPackage{Name: sdkPackage, Version: "0.1.16-feat-x.1"}
|
||||
for _, c := range []struct {
|
||||
name, locks, integrity, fails string
|
||||
}{
|
||||
{name: "a lock naming another version", locks: "0.1.15", integrity: integrityOf(held)},
|
||||
{name: "a lock naming the tagged version", locks: "0.1.16-feat-x.1", integrity: integrityOf(tagged)},
|
||||
{name: "a lock naming it with another integrity", locks: "0.1.16-feat-x.1", integrity: "sha512-other", fails: "sha512-other"},
|
||||
} {
|
||||
dir = memberLocking(t, c.locks, c.integrity)
|
||||
err := m.placeSDK(context.Background(), dir, "modules/m", nil, group)
|
||||
switch {
|
||||
case c.fails == "" && (err != nil || placedVersion(dir) != "0.1.16-feat-x.1"):
|
||||
t.Errorf("%s: %v, placed %q, want the group's tagged version", c.name, err, placedVersion(dir))
|
||||
case c.fails != "" && (err == nil || !strings.Contains(err.Error(), c.fails)):
|
||||
t.Errorf("%s: %v, want it to fail naming %s", c.name, err, c.fails)
|
||||
}
|
||||
}
|
||||
dir = memberLocking(t, "0.1.15", integrityOf(held))
|
||||
missing := &groupPackage{Name: sdkPackage, Version: "0.1.16-feat-x.9"}
|
||||
if err := m.placeSDK(context.Background(), dir, "modules/m", nil, missing); err == nil || !strings.Contains(err.Error(), "0.1.16-feat-x.9") || strings.HasPrefix(err.Error(), builds.WaitsFor) {
|
||||
t.Errorf("a tagged version the registry lacks answered %v, want it named and no wait", err)
|
||||
}
|
||||
}
|
||||
|
||||
// ADR 0500 §5 (S3, S4): the group's packed package is served in place of the registry's when the member's lock names its
|
||||
// version with its integrity; another integrity fails naming both. A member locking another version, or none, gets the
|
||||
// registry's latest release (ADR 0573 §2); with no release in the registry it fails naming the group's, no wait.
|
||||
func TestTheGroupsPackageIsServedToAMemberLockingItsVersion(t *testing.T) {
|
||||
// design 47 G A-284, A-285 (ADR 0500 §5): the group's packed SDK is placed in place of the registry's whatever the
|
||||
// member's lock names, its version, its integrity or none, and the registry is not asked.
|
||||
func TestTheGroupsSDKIsPlacedInPlaceOfTheRegistrys(t *testing.T) {
|
||||
m, _, _ := newMachine(t)
|
||||
asked := fakeRegistry(t, m, map[string][]byte{"0.1.14": tgzOf(t, sdkPackage, "0.1.14")})
|
||||
tgz := tgzOf(t, sdkPackage, "0.1.15")
|
||||
group := &packed{Name: sdkPackage, Version: "0.1.15", Integrity: integrityOf(tgz), Digest: digestOf(tgz), tgz: tgz}
|
||||
dir := memberLocking(t, "0.1.15", group.Integrity)
|
||||
if err := m.placeSDK(context.Background(), dir, "modules/m", group, nil); err != nil || placedVersion(dir) != "0.1.15" || asked.Load() != 0 {
|
||||
t.Errorf("the group's own version: %v, placed %q, the registry asked %d times", err, placedVersion(dir), asked.Load())
|
||||
}
|
||||
dir = memberLocking(t, "0.1.15", "sha512-other")
|
||||
if err := m.placeSDK(context.Background(), dir, "modules/m", group, nil); err == nil || !strings.Contains(err.Error(), "sha512-other") || !strings.Contains(err.Error(), group.Integrity) {
|
||||
t.Errorf("another integrity answered %v, want both named", err)
|
||||
}
|
||||
dir = memberLocking(t, "0.1.14", integrityOf(tgzOf(t, sdkPackage, "0.1.14")))
|
||||
if err := m.placeSDK(context.Background(), dir, "modules/m", group, nil); err != nil || placedVersion(dir) != "0.1.14" {
|
||||
t.Errorf("a member locking the registry's 0.1.14 in a group: %v, placed %q", err, placedVersion(dir))
|
||||
}
|
||||
for _, locks := range []string{"0.1.13", ""} {
|
||||
dir = memberLocking(t, locks, "sha512-x")
|
||||
if err := m.placeSDK(context.Background(), dir, "modules/m", group, nil); err != nil || placedVersion(dir) != "0.1.14" {
|
||||
t.Errorf("a member in a group locking %q: %v, placed %q, want the registry's latest 0.1.14", locks, err, placedVersion(dir))
|
||||
for _, lock := range [][2]string{{"0.1.15", group.Integrity}, {"0.1.15", "sha512-other"}, {"0.1.14", integrityOf(tgzOf(t, sdkPackage, "0.1.14"))}, {"0.1.13", "sha512-x"}, {"", ""}} {
|
||||
dir := memberLocking(t, lock[0], lock[1])
|
||||
if err := m.placeSDK(context.Background(), dir, "modules/m", group); err != nil || placedVersion(dir) != "0.1.15" {
|
||||
t.Errorf("a member locking %q %q: %v, placed %q, want the group's 0.1.15", lock[0], lock[1], err, placedVersion(dir))
|
||||
}
|
||||
}
|
||||
fakeRegistry(t, m, nil)
|
||||
if err := m.placeSDK(context.Background(), memberLocking(t, "0.1.13", "sha512-x"), "modules/m", group, nil); err == nil || !strings.Contains(err.Error(), "0.1.15") || strings.HasPrefix(err.Error(), builds.WaitsFor) {
|
||||
t.Errorf("no release and a group answered %v, want the group's named and no wait", err)
|
||||
if asked.Load() != 0 {
|
||||
t.Errorf("the registry was asked %d times", asked.Load())
|
||||
}
|
||||
}
|
||||
|
||||
// The fetch's `package` argument is a repository and a full commit, with a pull request's head at most; anything else is
|
||||
// refused before anything is fetched.
|
||||
func TestTheGroupPackageArgumentIsRefusedWhenItIsNotOne(t *testing.T) {
|
||||
for _, bad := range []any{"novox/mesh-sdk", map[string]any{"repository": "novox/mesh-sdk", "commit": "main"},
|
||||
map[string]any{"repository": "../x", "commit": strings.Repeat("a", 40)},
|
||||
map[string]any{"repository": "novox/mesh-sdk", "commit": strings.Repeat("a", 40), "ref": "refs/heads/main"},
|
||||
map[string]any{"name": "left-pad", "version": "1.0.0"}, map[string]any{"name": sdkPackage, "version": "latest"}} {
|
||||
if _, err := groupPackageArg(bad); err == nil {
|
||||
// design 47 G A-285: each of the group's packages is placed by its package.json name in a module that names it, in
|
||||
// place of what the install put there; one it does not name, the module itself and the SDK (placeSDK's) are not.
|
||||
func TestTheGroupsPackagesArePlacedInEveryModuleThatNamesThem(t *testing.T) {
|
||||
served := map[string]*packed{}
|
||||
for _, name := range []string{sdkPackage, "@novox/mesh-delivery-contracts-git", "@novox/mesh-delivery-contracts-mesh-catalog", "@novox/mesh-contracts-x", "@novox/module-m"} {
|
||||
served[name] = &packed{Name: name, Version: "0.2.0", tgz: tgzOf(t, name, "0.2.0")}
|
||||
}
|
||||
dir := t.TempDir()
|
||||
write(t, filepath.Join(dir, "package.json"), `{"name":"@novox/module-m","version":"0.1.0","dependencies":{"@novox/mesh-delivery-contracts-git":"^0.1.0","@novox/mesh-sdk":"^0.1.19","@novox/module-m":"0.1.0"},"devDependencies":{"@novox/mesh-delivery-contracts-mesh-catalog":"^0.1.0"}}`, 0o644)
|
||||
write(t, filepath.Join(dir, "node_modules", "@novox", "mesh-delivery-contracts-git", "package.json"), `{"name":"@novox/mesh-delivery-contracts-git","version":"0.1.0"}`, 0o644)
|
||||
if err := placeGroup(dir, served); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, want := range map[string]string{"@novox/mesh-delivery-contracts-git": "0.2.0", "@novox/mesh-delivery-contracts-mesh-catalog": "0.2.0",
|
||||
"@novox/mesh-contracts-x": "", sdkPackage: "", "@novox/module-m": ""} {
|
||||
p, _ := readPackageJSON(filepath.Join(dir, "node_modules", filepath.FromSlash(name)))
|
||||
if p.Version != want {
|
||||
t.Errorf("%s placed at %q, want %q", name, p.Version, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The fetch's `group-packages` is a list of a repository and a full commit, with a pull request's head at most and a
|
||||
// directory inside the member; anything else is refused before anything is fetched.
|
||||
func TestTheGroupPackagesArgumentIsRefusedWhenItIsNotOne(t *testing.T) {
|
||||
full := strings.Repeat("a", 40)
|
||||
for _, bad := range []any{"novox/mesh-sdk", map[string]any{"repository": "novox/mesh-sdk", "commit": full},
|
||||
[]any{map[string]any{"repository": "novox/mesh-sdk", "commit": "main"}},
|
||||
[]any{map[string]any{"repository": "../x", "commit": full}},
|
||||
[]any{map[string]any{"repository": "novox/mesh-sdk", "commit": full, "ref": "refs/heads/main"}},
|
||||
[]any{map[string]any{"repository": "novox/mesh-delivery", "commit": full, "path": "../x"}},
|
||||
[]any{map[string]any{"repository": "novox/mesh-delivery", "commit": full, "path": "/abs"}},
|
||||
[]any{map[string]any{"name": sdkPackage, "version": "0.1.16-feat-x.1"}}} {
|
||||
if _, err := groupPackagesArg(bad); err == nil {
|
||||
t.Errorf("%v was taken", bad)
|
||||
}
|
||||
}
|
||||
g, err := groupPackageArg(map[string]any{"repository": "novox/mesh-sdk", "commit": strings.Repeat("a", 40), "ref": "refs/pull/9/head"})
|
||||
if err != nil || g.Ref != "refs/pull/9/head" {
|
||||
t.Errorf("a pull request's head: %+v %v", g, err)
|
||||
}
|
||||
if g, err := groupPackageArg(map[string]any{"name": sdkPackage, "version": "0.1.16-feat-x.1"}); err != nil || !g.tagged() {
|
||||
t.Errorf("the group's tagged version: %+v %v", g, err)
|
||||
gs, err := groupPackagesArg([]any{map[string]any{"repository": "novox/mesh-sdk", "commit": full, "ref": "refs/pull/9/head"},
|
||||
map[string]any{"repository": "novox/mesh-delivery", "commit": full, "path": "modules/mesh-delivery-contracts/ts/seats/git/"}})
|
||||
if err != nil || len(gs) != 2 || gs[0].Ref != "refs/pull/9/head" || gs[0].Path != "" || gs[1].Path != "modules/mesh-delivery-contracts/ts/seats/git" {
|
||||
t.Errorf("a member's root and a member's directory: %+v %v", gs, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user