BM3: the Node build module installs a module's npm tree and publishes it as <module>:node-modules
An install ask's body runs npm ci from the lock with no install script and no link, packs the tree alone under modules/<module>/node_modules, publishes it to the artifact store as the archive <module>:node-modules under the ask's version and answers its reference, which the step's end carries. The package.json npm ci needs is written from the lock's root entry, a lock without one refused. The integration level's setup bound in code goes: half of the level's bound, which each level's script gets as MESH_TEST_LEVEL_BOUND. Builds: design 47 H2 §800; H-A-399 (2), H-A-403, H-A-427
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
@@ -9,6 +12,8 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -18,6 +23,7 @@ import (
|
||||
builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds"
|
||||
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
|
||||
"git.novox.be/novox/mesh-sdk/go/forgekey"
|
||||
)
|
||||
|
||||
// pushed are the blobs the fake holder took, by digest, for the tests that read an archive back.
|
||||
@@ -51,7 +57,7 @@ func withStore(t *testing.T, m *Module) *fakeStore {
|
||||
case "publish":
|
||||
var in registry.PublishInput
|
||||
_ = json.Unmarshal(raw, &in)
|
||||
if (seat == steprun.ArtifactSeat) != (in.Kind == "bundle") || in.Transfer == "" || strings.ContainsAny(in.Transfer, "/. *>") {
|
||||
if (seat == steprun.ArtifactSeat) != (in.Kind == "bundle" || in.Kind == "archive") || in.Transfer == "" || strings.ContainsAny(in.Transfer, "/. *>") {
|
||||
t.Errorf("publish on %s of kind %q, transfer %q", seat, in.Kind, in.Transfer)
|
||||
}
|
||||
s.open[in.Transfer] = in
|
||||
@@ -115,6 +121,72 @@ func TestADoneBundleAnswersTheReferenceOfTheArchiveItPushed(t *testing.T) {
|
||||
if len(store.published) != 1 || store.published[0].Version != "1.4.3" {
|
||||
t.Errorf("the bundle was published as %+v, want the ask's version 1.4.3", store.published)
|
||||
}
|
||||
// Design 47 H2 §800, H-A-403, H-A-427: an install runs no script and makes no link; its tree alone, under the module's
|
||||
// directory, is published as the archive <module>:node-modules under the ask's version, and the end names its reference.
|
||||
t.Run("an install runs no script", func(t *testing.T) {
|
||||
m := &Module{Work: t.TempDir(), Toolchain: &Toolchain{Paths: Paths{Home: t.TempDir(), Cache: t.TempDir()},
|
||||
Registry: func() (Registry, error) { return Registry{}, nil }}}
|
||||
store := withStore(t, m)
|
||||
var ran []string
|
||||
var written map[string]any
|
||||
m.Run = func(_ context.Context, _ []string, name string, args ...string) forgekey.Ran {
|
||||
ran = append([]string{name}, args...)
|
||||
dir := args[slices.Index(args, "--prefix")+1]
|
||||
raw, _ := os.ReadFile(filepath.Join(dir, "package.json"))
|
||||
_ = json.Unmarshal(raw, &written)
|
||||
os.MkdirAll(filepath.Join(dir, "node_modules", "left-pad"), 0o755)
|
||||
os.WriteFile(filepath.Join(dir, "node_modules", "left-pad", "index.js"), []byte("module.exports = 1\n"), 0o644)
|
||||
return forgekey.Ran{}
|
||||
}
|
||||
lock := `{"lockfileVersion": 3, "packages": {"": {"name": "@novox/module-gitea", "scripts": {"install": "touch ran"},
|
||||
"dependencies": {"left-pad": "^1.3.0"}}, "node_modules/left-pad": {"version": "1.3.0", "hasInstallScript": true}}}`
|
||||
install := func(lock string) (any, error) {
|
||||
return m.installTreeStep(context.Background(), map[string]any{"module": "gitea", "commit": strings.Repeat("a", 40), "fingerprint": "fp",
|
||||
"pipeline": "p1", "lock": lock, "artifact": sdkstep.InstallArtifact("gitea"), "version": "0.4.2"})
|
||||
}
|
||||
out, err := install(lock)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !slices.Contains(ran, "--ignore-scripts") || !slices.Contains(ran, "--no-bin-links") || ran[0] != "npm" || ran[1] != "ci" {
|
||||
t.Errorf("the install ran %v, want npm ci --ignore-scripts --no-bin-links", ran)
|
||||
}
|
||||
if _, scripts := written["scripts"]; scripts || written["name"] != "@novox/module-gitea" {
|
||||
t.Errorf("the package.json beside the lock is %v, want the lock's root with no script", written)
|
||||
}
|
||||
if len(store.published) != 1 || store.published[0].Name != "gitea/node-modules" || store.published[0].Kind != "archive" || store.published[0].Version != "0.4.2" {
|
||||
t.Fatalf("published %+v, want gitea/node-modules of kind archive at 0.4.2", store.published)
|
||||
}
|
||||
digest := store.published[0].Digest
|
||||
if want := map[string]any{"archive": "oci-artifact-registry/gitea/node-modules@" + digest}; !reflect.DeepEqual(out, want) {
|
||||
t.Errorf("the install answered %v, want %v", out, want)
|
||||
}
|
||||
if names := archiveNames(t, store.blobs["gitea/node-modules@"+digest]); !slices.Equal(names, []string{"modules/gitea/node_modules/left-pad/index.js"}) {
|
||||
t.Errorf("the archive holds %v, want the tree alone under the module's directory", names)
|
||||
}
|
||||
if _, err := install(`{"lockfileVersion": 1, "dependencies": {}}`); err == nil {
|
||||
t.Error("a lock with no root package was installed")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// archiveNames are the file names a packed archive holds (steprun.Pack: tar in gzip).
|
||||
func archiveNames(t *testing.T, archive []byte) []string {
|
||||
t.Helper()
|
||||
z, err := gzip.NewReader(bytes.NewReader(archive))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var names []string
|
||||
r := tar.NewReader(z)
|
||||
for {
|
||||
h, err := r.Next()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
names = append(names, h.Name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// 1587-S7 and S8 (ADR 0498 §2, the lead's decision L9): a publish the holder refuses fails the step `not stored:
|
||||
|
||||
Reference in New Issue
Block a user