package main import ( "context" "path/filepath" "slices" "testing" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/seatgen" ) // F7 (ADR 0625 §5, ADR 0634 §8): a package the seat generator wrote, with its dependency-free lock and no script, is // installed from that lock (npm ci) and packed (npm pack) with no build script run, as any package artifact is. func TestAGeneratedSeatPackageIsInstalledFromItsLockAndPackedWithoutABuild(t *testing.T) { m, f, work := newMachine(t) seat := `{"format":1,"seat":"one-store","scope":"mesh","grain":"whole","domain":"Module","decision":"ADR 1","verbs":[{"name":"query","input":{"type":"object"},"answer":{"type":"object"}}]}` src := t.TempDir() write(t, filepath.Join(src, "seats", "one-store", "seat.json"), seat, 0o644) g, err := seatgen.Load(src, "example.org/c/go", "@example/c") if err != nil { t.Fatal(err) } files, err := seatgen.Generate(g) if err != nil { t.Fatal(err) } dir := filepath.Join(work, "w1", "tree", "ts", "seats", "onestore") for _, name := range []string{"package.json", "package-lock.json"} { body, ok := files["ts/seats/onestore/"+name] if !ok { t.Fatalf("the generator wrote no %s for the seat's package", name) } write(t, filepath.Join(dir, name), string(body), 0o644) } f.effect = func(c call) { if c.name == "npm" && len(c.args) > 0 && c.args[0] == "pack" { dest := c.args[slices.Index(c.args, "--pack-destination")+1] write(t, filepath.Join(dest, "example-c-one-store-0.1.0.tgz"), "tgz", 0o644) } } ctx := context.Background() if err := m.installDev(ctx, work, dir, "ts/seats/onestore"); err != nil { t.Fatal(err) } p, err := m.buildAndPack(ctx, work, dir, "ts/seats/onestore", false, "") if err != nil { t.Fatal(err) } if p.Name != "@example/c-one-store" || p.Version != "0.1.0" { t.Errorf("packed %s@%s", p.Name, p.Version) } var ran []string for _, c := range f.calls { if c.name == "npm" { ran = append(ran, c.args[0]) } } if !slices.Equal(ran, []string{"ci", "pack"}) { t.Errorf("npm ran %v, want ci then pack and no build script", ran) } }