The node-engine held 1,707 top-level unit tests against the budget of 500 a module. Each unit test file with two or more tests now runs them as subtests of one test named for the file, each named as its function was, in the same order: every check is kept, and the check counts 383. Files with a TestMain, a re-run of a test by its name, or the integration tag are left. Four files of this branch's earlier commits are formatted. Builds: design 47 H2 §819; H-A-349 DQ-14
488 lines
25 KiB
Go
488 lines
25 KiB
Go
package resolution
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
)
|
|
|
|
var bundleDigest = "sha256:" + strings.Repeat("b", 64)
|
|
|
|
// aToolsModule is a module whose tools come as a compiled bundle and nothing else — the shape every
|
|
// module takes once its tool container goes (to-be 38 WP4).
|
|
func aToolsModule(t *testing.T, name string, entrypoints ...string) mcat.Manifest {
|
|
t.Helper()
|
|
m := mcat.Manifest{Module: name, Version: "1", Tools: []string{"status"},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{
|
|
{Name: "tools", Kind: mcat.ArtifactBundle, Language: "typescript", Entrypoints: entrypoints},
|
|
}}}
|
|
resolved, err := m.Resolve([]mcat.Built{{Name: "tools", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + name + "/tools/blobs/" + bundleDigest, Digest: bundleDigest}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return resolved
|
|
}
|
|
|
|
// theRuntime is the runtime module as the catalogue holds it: its own bundle, run rather than
|
|
// loaded, and its broker secret to receive the node's credential in.
|
|
func theRuntime(t *testing.T) mcat.Manifest {
|
|
t.Helper()
|
|
m := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
|
OwnSecrets: mcat.OwnSecrets{"broker": {Path: "/var/lib/mesh/" + "node-tools" + "/broker"}},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "runtime", Kind: mcat.ArtifactBundle, Language: "typescript",
|
|
Entrypoints: []string{"src/main.js"}}}}}
|
|
resolved, err := m.Resolve([]mcat.Built{{Name: "runtime", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + "node-tools" + "/runtime/blobs/" + bundleDigest, Digest: bundleDigest}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return resolved
|
|
}
|
|
|
|
func testEveryToolsBundleIsDeliveredWhereTheRuntimeRuns(t *testing.T) {
|
|
store := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
|
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}}}
|
|
nftables := aToolsModule(t, "nftables", "tools/index.js")
|
|
zsh := aToolsModule(t, "zsh", "tools/index.js", "tools/more.js")
|
|
|
|
t.Run("with the runtime, one archive per tools bundle", func(t *testing.T) {
|
|
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{nftables, zsh, theRuntime(t)}}
|
|
out, err := Declaration(r, store)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
archive := fileNamed(out, "nftables."+BundleID("tools"))
|
|
if archive == nil {
|
|
t.Fatalf("nftables' tools bundle was not delivered: %v", ids(out))
|
|
}
|
|
if archive["type"] != "archive" || archive["digest"] != bundleDigest ||
|
|
archive["path"] != mcat.BundleRoot+"/nftables/tools" {
|
|
t.Errorf("delivered as %v", archive)
|
|
}
|
|
if archive["source"] != "http://anchor.internal:5101/v2/nftables/tools/blobs/"+bundleDigest {
|
|
t.Errorf("fetched from %v, not through the store as this network reaches it", archive["source"])
|
|
}
|
|
if fileNamed(out, "zsh."+BundleID("tools")) == nil {
|
|
t.Errorf("zsh's tools bundle was not delivered: %v", ids(out))
|
|
}
|
|
// The runtime's own bundle is run, not loaded: its process delivers it, not an archive.
|
|
if fileNamed(out, "node-tools"+"."+BundleID("runtime")) != nil {
|
|
t.Error("the runtime's own bundle was delivered as an archive beside its process")
|
|
}
|
|
})
|
|
|
|
t.Run("without the runtime, nothing changes", func(t *testing.T) {
|
|
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{nftables, zsh}}
|
|
out, err := Declaration(r, store)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, id := range ids(out) {
|
|
if strings.Contains(id, BundleID("")) {
|
|
t.Errorf("%s was delivered to a machine running no runtime to load it", id)
|
|
}
|
|
}
|
|
// The tool runner is what says it is one, never a name (issue 774): node-tools saying nothing is no runner.
|
|
silent := theRuntime(t)
|
|
silent.ToolRunner = false
|
|
out, err = Declaration(mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{nftables, zsh, silent}}, store)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, id := range ids(out) {
|
|
if strings.Contains(id, BundleID("")) || strings.HasSuffix(id, "."+RuntimeProcessID()) {
|
|
t.Errorf("%s was composed for a module that does not say it is the tool runner", id)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
func ids(out []map[string]any) []string {
|
|
var names []string
|
|
for _, r := range out {
|
|
names = append(names, r["id"].(string))
|
|
}
|
|
return names
|
|
}
|
|
|
|
// One process per machine runs the runtime from its own bundle, told what it serves and from where,
|
|
// where its credential is, and who the operator is — restarted when any of that changes.
|
|
func testTheMachineRunsOneRuntimeLoadingEveryDeliveredBundle(t *testing.T) {
|
|
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
|
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}}}
|
|
nftables := aToolsModule(t, "nftables", "tools/index.js")
|
|
// A bundle carrying a daemon beside its tools says which files the runtime loads.
|
|
showcase := mcat.Manifest{Module: "showcase", Version: "1", Tools: []string{"greet"},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "code", Kind: mcat.ArtifactBundle, Language: "typescript",
|
|
Entrypoints: []string{"daemon/index.js", "tools/index.js"}, Loads: []string{"tools/index.js"}}}}}
|
|
showcase, err := showcase.Resolve([]mcat.Built{{Name: "code", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + "showcase/code/blobs/" + bundleDigest, Digest: bundleDigest}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Design 47 H2 §781, H-A-370: a module's settings reach its slice of the runtime's words, and the runtime's own its process.
|
|
showcase.Settings = map[string]mcat.SettingDeclaration{"greeting": {Kind: mcat.KindPreference, Default: "hello", Why: "polite"}}
|
|
runner := theRuntime(t)
|
|
runner.Settings = map[string]mcat.SettingDeclaration{DrainBoundSetting: {Kind: mcat.KindPreference, Default: "30s", Why: "a call's length"}}
|
|
r := mcat.Resolution{Node: "anchor", Account: "ops", Modules: []mcat.Manifest{nftables, showcase, runner}}
|
|
out, err := Declaration(r, with)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
process := fileNamed(out, "node-tools"+"."+RuntimeProcessID())
|
|
if process == nil {
|
|
t.Fatalf("no runtime process was composed: %v", ids(out))
|
|
}
|
|
if process["type"] != "process" || process["name"] != "node-tools" || process["digest"] != bundleDigest ||
|
|
process["source"] != "http://anchor.internal:5101/v2/"+"node-tools"+"/runtime/blobs/"+bundleDigest {
|
|
t.Errorf("the runtime's process is %v", process)
|
|
}
|
|
if fmt.Sprint(process["run"]) != "[node src/main.js]" {
|
|
t.Errorf("the runtime is run as %v; its bundle's one entrypoint, by its language's interpreter", process["run"])
|
|
}
|
|
env := process["env"].(map[string]string)
|
|
if env[mcat.RuntimeToolModules] != "nftables="+mcat.BundleRoot+"/nftables/tools/tools/index.js,"+
|
|
"showcase="+mcat.BundleRoot+"/showcase/code/tools/index.js" {
|
|
t.Errorf("the runtime is told to serve %q: every loaded file, by module, and nothing a bundle runs", env[mcat.RuntimeToolModules])
|
|
}
|
|
if env["MESH_CONFIG_DRAIN_BOUND"] != "30s" || env[mcat.RuntimeToolEnv] != `{"showcase":{"MESH_CONFIG_GREETING":"hello"}}` {
|
|
t.Errorf("the settings reach the runtime as %q and its served modules as %s", env["MESH_CONFIG_DRAIN_BOUND"], env[mcat.RuntimeToolEnv])
|
|
}
|
|
if env[mcat.RuntimeBrokerFile] != "/var/lib/mesh/"+"node-tools"+"/broker" {
|
|
t.Errorf("the runtime reads its credential at %q, not where the module's own secret is placed", env[mcat.RuntimeBrokerFile])
|
|
}
|
|
if env[mcat.RuntimeOperatorAccount] != "ops" || env[mcat.RuntimeOperatorHome] != "/home/ops" || process["user"] != "ops" {
|
|
t.Errorf("the operator is not handed to the runtime: %v as %v", env, process["user"])
|
|
}
|
|
// The credential the process reads belongs to the account it runs as, or it could not read it
|
|
// (to-be 38 WP3); other modules' secrets are left as their manifests say.
|
|
if credential := fileNamed(out, "node-tools"+"."+mcat.NeedID("broker")); credential == nil || credential["owner"] != "ops" {
|
|
t.Errorf("the runtime's credential is not the account's to read: %v", credential)
|
|
}
|
|
restarts := fmt.Sprint(process["restart-on"])
|
|
for _, want := range []string{"nftables." + BundleID("tools"), "showcase." + BundleID("code"), "node-tools" + "." + mcat.NeedID("broker")} {
|
|
if !strings.Contains(restarts, want) {
|
|
t.Errorf("the runtime is not restarted when %s changes: %s", want, restarts)
|
|
}
|
|
}
|
|
// After every bundle and the credential, so both exist before it starts.
|
|
names := ids(out)
|
|
if names[len(names)-1] != "node-tools"+"."+RuntimeProcessID() {
|
|
t.Errorf("the runtime's process is not last: %v", names)
|
|
}
|
|
// Design 47 H2 §813 (12), H-A-358, H-A-377: the runtime's process carries the module's drain bound in whole seconds, 30
|
|
// where no layer sets it, the Go duration a layer sets (part of a second a whole one), and a value that is no duration
|
|
// above zero is refused by name.
|
|
if process["drain-bound"] != 30 {
|
|
t.Errorf("the runtime's process drains for %v, not the default 30 s", process["drain-bound"])
|
|
}
|
|
for _, row := range []struct {
|
|
value any
|
|
want int
|
|
words string
|
|
}{{"45s", 45, ""}, {"1500ms", 2, ""}, {"60", 0, "Go duration"}, {float64(45), 0, "Go duration"}, {"0s", 0, "above zero"}} {
|
|
set := with
|
|
set.Settings = mcat.SettingsBy{"node-tools": {{From: "mesh", Values: map[string]any{DrainBoundSetting: row.value}}}}
|
|
out, err := Declaration(r, set)
|
|
if row.words != "" {
|
|
if err == nil || !strings.Contains(err.Error(), row.words) {
|
|
t.Errorf("drain-bound %v was composed: %v", row.value, err)
|
|
}
|
|
continue
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := fileNamed(out, "node-tools."+RuntimeProcessID())["drain-bound"]; got != row.want {
|
|
t.Errorf("drain-bound %v composed the runtime's process with %v", row.value, got)
|
|
}
|
|
}
|
|
|
|
t.Run("a machine with no account runs it as root without the operator words", func(t *testing.T) {
|
|
out, err := Declaration(mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{nftables, theRuntime(t)}}, with)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
process := fileNamed(out, "node-tools"+"."+RuntimeProcessID())
|
|
env := process["env"].(map[string]string)
|
|
if _, set := env[mcat.RuntimeOperatorAccount]; set {
|
|
t.Error("an operator account was named on a machine that has none")
|
|
}
|
|
if _, set := process["user"]; set {
|
|
t.Error("a user was set on a machine with no account")
|
|
}
|
|
if credential := fileNamed(out, "node-tools"+"."+mcat.NeedID("broker")); credential == nil || credential["owner"] != nil {
|
|
t.Errorf("the runtime's credential was given an owner on a machine with no account: %v", credential)
|
|
}
|
|
})
|
|
|
|
t.Run("a runtime module built wrong is refused by name", func(t *testing.T) {
|
|
two := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true, OwnSecrets: mcat.OwnSecrets{"broker": {Path: "/b"}},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "runtime", Kind: mcat.ArtifactBundle, Language: "typescript",
|
|
Entrypoints: []string{"a.js", "b.js"}}}}}
|
|
resolved, err := two.Resolve([]mcat.Built{{Name: "runtime", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + "x/runtime/blobs/" + bundleDigest, Digest: bundleDigest}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = Declaration(mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{resolved}}, with)
|
|
if err == nil || !strings.Contains(err.Error(), "entrypoint") {
|
|
t.Errorf("a runtime bundle with two entrypoints was composed: %v", err)
|
|
}
|
|
})
|
|
}
|
|
|
|
// novox/hq ADR 0193: the runtime is told the launcher a build wrote, and the entrypoint itself for a
|
|
// build from before launchers — so the move needs no flag day.
|
|
func testTheRuntimeStartsTheLauncherWhereTheBuildWroteOne(t *testing.T) {
|
|
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
|
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}}}
|
|
launched := mcat.Manifest{Module: "dash", Version: "1", Tools: []string{"status"},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "tools", Kind: mcat.ArtifactBundle, Language: "typescript",
|
|
Entrypoints: []string{"tools/index.js"}}}}}
|
|
launched, err := launched.Resolve([]mcat.Built{{Name: "tools", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + "dash/tools/blobs/" + bundleDigest, Digest: bundleDigest,
|
|
Launchers: map[string]string{"tools/index.js": "tools/index.serve.mjs"}}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
older := aToolsModule(t, "nftables", "tools/index.js")
|
|
out, err := Declaration(mcat.Resolution{Node: "anchor", Account: "ops", Modules: []mcat.Manifest{launched, older, theRuntime(t)}}, with)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
env := fileNamed(out, "node-tools"+"."+RuntimeProcessID())["env"].(map[string]string)
|
|
want := "dash=" + mcat.BundleRoot + "/dash/tools/tools/index.serve.mjs,nftables=" + mcat.BundleRoot + "/nftables/tools/tools/index.js"
|
|
if env[mcat.RuntimeToolModules] != want {
|
|
t.Errorf("the runtime is told %q, want %q", env[mcat.RuntimeToolModules], want)
|
|
}
|
|
}
|
|
|
|
// novox/hq ADR 0193: a runtime compiled to a binary runs itself from its own unpacked bundle.
|
|
func testARuntimeCompiledToABinaryRunsItself(t *testing.T) {
|
|
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
|
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}}}
|
|
goRuntime := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
|
OwnSecrets: mcat.OwnSecrets{"broker": {Path: "/var/lib/mesh/" + "node-tools" + "/broker"}},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "runtime", Kind: mcat.ArtifactBundle, Language: "go",
|
|
System: "arch", From: "cmd/node-tools"}}}}
|
|
goRuntime, err := goRuntime.Resolve([]mcat.Built{{Name: "runtime", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + "node-tools" + "/runtime/blobs/" + bundleDigest, Digest: bundleDigest}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out, err := Declaration(mcat.Resolution{Node: "anchor", Account: "ops", Modules: []mcat.Manifest{aToolsModule(t, "nftables", "tools/index.js"), goRuntime}}, with)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
process := fileNamed(out, "node-tools"+"."+RuntimeProcessID())
|
|
if fmt.Sprint(process["run"]) != "[./node-tools]" {
|
|
t.Errorf("a Go runtime is run as %v, want its own binary", process["run"])
|
|
}
|
|
env := process["env"].(map[string]string)
|
|
if env[mcat.RuntimeToolModules] == "" || process["user"] != "ops" {
|
|
t.Errorf("the Go runtime is not told what to serve or whose it is: %v %v", env, process["user"])
|
|
}
|
|
}
|
|
|
|
// novox/hq ADR 0259 §8: a module of its own account is served by a runtime of its own — the machine's
|
|
// runtime program, as that account, on that module's own credential — and never by the machine's runtime,
|
|
// which runs as the operator's account and is given none of its words.
|
|
func testAModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn(t *testing.T) {
|
|
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
|
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}, "telegram": {"broker": "own"}}}
|
|
goRuntime := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
|
OwnSecrets: mcat.OwnSecrets{"broker": {Path: "/var/lib/mesh/" + "node-tools" + "/broker"}},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "runtime", Kind: mcat.ArtifactBundle, Language: "go",
|
|
System: "arch", From: "cmd/node-tools"}}}}
|
|
goRuntime, err := goRuntime.Resolve([]mcat.Built{{Name: "runtime", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + "node-tools" + "/runtime/blobs/" + bundleDigest, Digest: bundleDigest}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
telegram := aToolsModule(t, "telegram", "tools/index.js")
|
|
telegram.RunsAs, telegram.SecretsOwner = "telegram", "telegram"
|
|
telegram.OwnSecrets = mcat.OwnSecrets{"broker": {Path: "/var/lib/telegram/broker"}}
|
|
out, err := Declaration(mcat.Resolution{Node: "anchor", Account: "ops",
|
|
Modules: []mcat.Manifest{aToolsModule(t, "nftables", "tools/index.js"), telegram, goRuntime}}, with)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
machine := fileNamed(out, "node-tools"+"."+RuntimeProcessID())
|
|
if served := machine["env"].(map[string]string)[mcat.RuntimeToolModules]; strings.Contains(served, "telegram") || !strings.Contains(served, "nftables") {
|
|
t.Errorf("the machine's runtime serves %q", served)
|
|
}
|
|
own := fileNamed(out, "telegram."+mcat.OwnRuntimeID())
|
|
if own == nil {
|
|
t.Fatalf("telegram has no runtime of its own: %v", ids(out))
|
|
}
|
|
env := own["env"].(map[string]string)
|
|
if own["user"] != "telegram" || fmt.Sprint(own["run"]) != "[./node-tools]" ||
|
|
env[mcat.RuntimeBrokerFile] != "/var/lib/telegram/broker" ||
|
|
env[mcat.RuntimeToolModules] != "telegram="+mcat.BundleRoot+"/telegram/tools/tools/index.js" {
|
|
t.Errorf("its own runtime: user %v run %v env %v", own["user"], own["run"], env)
|
|
}
|
|
if _, told := env[mcat.RuntimeOperatorAccount]; told {
|
|
t.Error("a runtime of a module's own account is told the operator's account")
|
|
}
|
|
if _, yields := own["yields"]; yields {
|
|
t.Errorf("telegram holds no build seat and yields: %v", own["yields"])
|
|
}
|
|
// The build seats' holders yield (ADR 0553): idle, under the node's one share from the node-engine's build-cpu-share,
|
|
// and their steps are told it.
|
|
builder := func(name, seat string) mcat.Manifest {
|
|
b := aToolsModule(t, name, "tools/index.js")
|
|
b.RunsAs, b.SecretsOwner = name, name
|
|
b.OwnSecrets = mcat.OwnSecrets{"broker": {Path: "/var/lib/" + name + "/broker"}}
|
|
b.Claims = []mcat.Claim{{Name: seat}}
|
|
return b
|
|
}
|
|
gob, img := builder("gob", "node-build-go"), builder("img", "node-build-image")
|
|
with.Needed["gob"], with.Needed["img"] = map[string]string{"broker": "own"}, map[string]string{"broker": "own"}
|
|
// The node-engine's module is the one whose entry claims its seat (design 47 G §527), whatever it is called; with none in
|
|
// the resolution its settings are not found and the default stands.
|
|
engine := mcat.Manifest{Module: "mesh-host", Claims: []mcat.Claim{{Name: "node-engine"}}}
|
|
for _, c := range []struct {
|
|
settings mcat.SettingsBy
|
|
share string
|
|
noEngine bool
|
|
}{
|
|
{nil, "50", false},
|
|
{mcat.SettingsBy{"mesh-host": {{From: "anchor", Values: map[string]any{"build-cpu-share": float64(75)}}}}, "75", false},
|
|
{mcat.SettingsBy{"mesh-host": {{From: "anchor", Values: map[string]any{"build-cpu-share": float64(0)}}}}, "50", false},
|
|
{mcat.SettingsBy{"mesh-host": {{From: "anchor", Values: map[string]any{"build-cpu-share": float64(75)}}}}, "50", true},
|
|
} {
|
|
with.Settings = c.settings
|
|
modules := []mcat.Manifest{gob, img, telegram, goRuntime, engine}
|
|
if c.noEngine {
|
|
modules = modules[:4]
|
|
}
|
|
runtimes, err := resolutionOwnRuntimes(mcat.Resolution{Node: "anchor", Modules: modules}, with, Holding{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(runtimes) != 3 {
|
|
t.Fatalf("%d runtimes of their own, want gob's, img's and telegram's", len(runtimes))
|
|
}
|
|
for _, p := range runtimes {
|
|
name := fmt.Sprint(p["name"])
|
|
words := map[string]map[string]string{}
|
|
_ = json.Unmarshal([]byte(p["env"].(map[string]string)[mcat.RuntimeToolEnv]), &words)
|
|
mod := strings.TrimSuffix(name, "-runtime")
|
|
if mod == "telegram" {
|
|
if p["yields"] != nil || words[mod]["MESH_BUILD_CPU_SHARE"] != "" {
|
|
t.Errorf("telegram yields under %v: %v %v", c.settings, p["yields"], words)
|
|
}
|
|
continue
|
|
}
|
|
if got := fmt.Sprint(p["yields"]); got != "map[cpu-share:"+c.share+" priority:idle]" ||
|
|
words[mod]["MESH_BUILD_CPU_SHARE"] != c.share {
|
|
t.Errorf("%s under %v yields %s with words %v; want share %s", name, c.settings, got, words[mod], c.share)
|
|
}
|
|
}
|
|
}
|
|
with.Settings = nil
|
|
// Without the machine's runtime to run it from, it is refused in words.
|
|
if _, err := resolutionOwnRuntimes((mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{telegram}}), with, Holding{}); err == nil {
|
|
t.Error("a module of its own account composed without a runtime program")
|
|
}
|
|
}
|
|
|
|
// The review of 2026-10-09 (L4): a module of its own account never runs as the node's operator account, nor
|
|
// as the account agents run as there — either would hand what it holds back to the accounts it is kept from.
|
|
func testAModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount(t *testing.T) {
|
|
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
|
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}, "telegram": {"broker": "own"}}}
|
|
goRuntime := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
|
OwnSecrets: mcat.OwnSecrets{"broker": {Path: "/var/lib/mesh/" + "node-tools" + "/broker"}},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "runtime", Kind: mcat.ArtifactBundle, Language: "go",
|
|
System: "arch", From: "cmd/node-tools"}}}}
|
|
goRuntime, err := goRuntime.Resolve([]mcat.Built{{Name: "runtime", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + "node-tools" + "/runtime/blobs/" + bundleDigest, Digest: bundleDigest}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, account := range []string{"ops", "agent"} {
|
|
telegram := aToolsModule(t, "telegram", "tools/index.js")
|
|
telegram.RunsAs, telegram.SecretsOwner = account, account
|
|
telegram.OwnSecrets = mcat.OwnSecrets{"broker": {Path: "/var/lib/telegram/broker"}}
|
|
_, err := resolutionOwnRuntimes(mcat.Resolution{Node: "anchor", Account: "ops", AgentAccount: "agent",
|
|
Modules: []mcat.Manifest{telegram, goRuntime}}, with, Holding{})
|
|
if err == nil || !strings.Contains(err.Error(), account) {
|
|
t.Errorf("telegram running as %s was composed: %v", account, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Issue 723: the vault runs as its own account, so what the mesh writes for it — the export it keeps, the grant
|
|
// files it holds for its consumers, and what its words name — belongs to that account, never the operator's.
|
|
func testWhatAModuleOfItsOwnAccountReadsIsItsAccounts(t *testing.T) {
|
|
with := mcat.Rendering{ArtifactStore: "anchor.internal:5101",
|
|
Needed: map[string]map[string]string{"node-tools": {"broker": "sealed-credential"}, "vault": {"broker": "own"}},
|
|
Kept: &mcat.KeptExport{Export: 1, OperatorKey: "k"},
|
|
Grants: []mcat.Grant{{Provision: "secret", Consumer: "anchor", From: "telegram", Sealed: "sealed-to-anchor",
|
|
Values: map[string]any{"name": "telegram"}}}}
|
|
goRuntime := mcat.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
|
OwnSecrets: mcat.OwnSecrets{"broker": {Path: "/var/lib/mesh/" + "node-tools" + "/broker"}},
|
|
Build: &mcat.Build{Artifacts: []mcat.Artifact{{Name: "runtime", Kind: mcat.ArtifactBundle, Language: "go",
|
|
System: "arch", From: "cmd/node-tools"}}}}
|
|
goRuntime, err := goRuntime.Resolve([]mcat.Built{{Name: "runtime", Kind: mcat.ArtifactBundle,
|
|
Reference: mcat.ArtifactStoreScheme + "node-tools" + "/runtime/blobs/" + bundleDigest, Digest: bundleDigest}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
vault := aToolsModule(t, "vault", "tools/index.js")
|
|
vault.RunsAs, vault.SecretsOwner = "vault", "vault"
|
|
vault.OwnSecrets = mcat.OwnSecrets{"broker": {Path: "/var/lib/vault/broker"}}
|
|
vault.Keeps = "/var/lib/vault/root"
|
|
vault.Grants = map[string]string{"secret": "/var/lib/vault/grants"}
|
|
vault.Receives = map[string]string{"secret": "/var/lib/vault/grants/mesh.json"}
|
|
vault.Bundles[0].Env = map[string]string{"MESH_RECEIVES": "/var/lib/vault/grants/mesh.json"}
|
|
out, err2 := Declaration(mcat.Resolution{Node: "anchor", Account: "ops", Modules: []mcat.Manifest{vault, goRuntime}}, with)
|
|
if err = err2; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
seen := 0
|
|
for _, r := range out {
|
|
path := fmt.Sprint(r["path"])
|
|
if !strings.HasPrefix(path, "/var/lib/vault/") || r["type"] != "file" {
|
|
continue
|
|
}
|
|
seen++
|
|
if r["owner"] != "vault" {
|
|
t.Errorf("%s (%v) belongs to %v, not the vault's own account", path, r["id"], r["owner"])
|
|
}
|
|
}
|
|
if seen < 4 {
|
|
t.Errorf("only %d of the vault's files were composed: %v", seen, ids(out))
|
|
}
|
|
// Carried by the machine's runtime instead, nothing of it changes: the operator's account reads them.
|
|
carried := vault
|
|
carried.RunsAs, carried.SecretsOwner = "", ""
|
|
out, err = Declaration(mcat.Resolution{Node: "anchor", Account: "ops", Modules: []mcat.Manifest{carried, goRuntime}}, with)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, r := range out {
|
|
if path := fmt.Sprint(r["path"]); strings.HasPrefix(path, "/var/lib/vault/") && r["owner"] == "vault" {
|
|
t.Errorf("%s belongs to the vault's account though it runs as none", path)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestRuntime runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
|
|
func TestRuntime(t *testing.T) {
|
|
t.Run("EveryToolsBundleIsDeliveredWhereTheRuntimeRuns", testEveryToolsBundleIsDeliveredWhereTheRuntimeRuns)
|
|
t.Run("TheMachineRunsOneRuntimeLoadingEveryDeliveredBundle", testTheMachineRunsOneRuntimeLoadingEveryDeliveredBundle)
|
|
t.Run("TheRuntimeStartsTheLauncherWhereTheBuildWroteOne", testTheRuntimeStartsTheLauncherWhereTheBuildWroteOne)
|
|
t.Run("ARuntimeCompiledToABinaryRunsItself", testARuntimeCompiledToABinaryRunsItself)
|
|
t.Run("AModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn", testAModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn)
|
|
t.Run("AModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount", testAModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount)
|
|
t.Run("WhatAModuleOfItsOwnAccountReadsIsItsAccounts", testWhatAModuleOfItsOwnAccountReadsIsItsAccounts)
|
|
}
|