package compose import ( "encoding/json" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" engcomp "github.com/novox/mesh-host/internal/compositions" "slices" "sort" "strconv" "strings" "testing" "git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go/overlay" "git.novox.be/novox/mesh-sdk/go/catalogue" "github.com/novox/mesh-host/internal/compose/resolution" ) func fpFor(c byte) string { return meshcatalogclient.SourcePrefix2 + strings.Repeat(string(c), 64) } // 1943/AC5: a node's compositions are its declaration as Compose gives it, split by the module each resource belongs // to: every resource once, each in its module's composition at the fingerprint given, the module's ownership said on // it; a module given no fingerprint is named as skipped and composed nowhere. func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) { t.Run("a held tool runner keeps its program for the modules of their own account", aHeldToolRunnerKeepsItsProgramForTheModulesOfTheirOwnAccount) t.Run("a held module's share of the holders' words is what runs", aHeldModulesShareOfTheHoldersWordsIsWhatRuns) in := aSmallMesh(t) d, _, err := Compose(in, "laptop") if err != nil { t.Fatal(err) } var want []string for _, r := range d.Resources { want = append(want, r["type"].(string)+":"+r["id"].(string)) } sort.Strings(want) fps := map[string]string{"mesh-wireguard": fpFor('a'), "files": fpFor('b')} // A-481a: the composition names the digest of the templates archive its module was rendered from. templated := in.Catalogue["files"] templated.TemplatesDigest = "sha256:" + strings.Repeat("e", 64) in.Catalogue["files"] = templated out, skipped, err := Compositions(in, "laptop", fps, Foreseeing) if err != nil || len(skipped) != 0 { t.Fatalf("Compositions = %v, skipped %v", err, skipped) } for _, c := range out { if want := map[string][]string{"files": {templated.TemplatesDigest}}[c.Module]; !slices.Equal(c.Templates, want) { t.Errorf("%s names the templates %v, want %v", c.Module, c.Templates, want) } } var got []string for key, c := range out { node, module, fp, isNode, err := engcomp.ParseKey(key) if err != nil || node != "laptop" || module != c.Module || fp != c.FP || (isNode != (module == "")) { t.Errorf("key %s holds %s at %s (%v)", key, c.Module, c.FP, err) } if !isNode && fp != fps[module] { t.Errorf("%s is composed at %s, given %s", module, fp, fps[module]) } if _, err := engcomp.Encode(c); err != nil { t.Errorf("%s: %v", key, err) } for _, raw := range c.Resources { var r struct{ ID, Type, Module string } _ = json.Unmarshal(raw, &r) if r.Module != module { t.Errorf("%s holds %s of %q", key, r.ID, r.Module) } got = append(got, r.Type+":"+r.ID) } } sort.Strings(got) if strings.Join(got, " ") != strings.Join(want, " ") { t.Errorf("the compositions hold %v, the declaration %v", got, want) } one, skipped, err := Compositions(in, "laptop", map[string]string{"mesh-wireguard": fpFor('a')}, Foreseeing) if err != nil || strings.Join(skipped, ",") != "files" { t.Fatalf("one module: %v, skipped %v", err, skipped) } for _, c := range one { if c.Module == "files" { t.Errorf("a module given no fingerprint was composed") } } // Issue 1126: a module the node runs inside its own composition (Node.InOwn), and the private network's always, // given no fingerprint of the new form, is folded into the node's own as the controller's composed writer folds it: // every resource in its place, its module taken off, its id still naming it, nothing skipped. folding := in folding.Nodes = append([]Node(nil), in.Nodes...) for i := range folding.Nodes { if folding.Nodes[i].Name == "laptop" { folding.Nodes[i].InOwn = map[string]bool{"files": true} } } all, skipped, err := Compositions(folding, "laptop", nil, Foreseeing) nodeKey, _ := engcomp.NodeKey("laptop") if err != nil || len(skipped) != 0 || len(all) != 1 || len(all[nodeKey].Resources) != len(want) { t.Fatalf("folded: %v, skipped %v, %d compositions, %d of %d resources in the node's own", err, skipped, len(all), len(all[nodeKey].Resources), len(want)) } for i, raw := range all[nodeKey].Resources { var r map[string]any _ = json.Unmarshal(raw, &r) if _, says := r["module"]; says || r["id"] != d.Resources[i]["id"] { t.Errorf("folded resource %d is %v, the declaration's %v", i, r["id"], d.Resources[i]["id"]) } } if _, err := engcomp.Encode(all[nodeKey]); err != nil { t.Errorf("the node's own with the folded modules: %v", err) } if _, _, err := Compositions(in, "nowhere", fps, Foreseeing); err == nil { t.Errorf("a node the mesh does not have was composed") } // Issue 1126, 2026-10-29: a module composed as what runs of it (folded at a build of the old form, or held) still // contributes to the runtime what the runtime serves of it as it runs (Node.RunsTools): its manifest at the // indexer's commit has no bundles (shanks's runtime lost the folded systemd-resolved, novox's the folded nats), and a // held module's new build's bundles are not delivered. dg := func(c byte) string { return "sha256:" + strings.Repeat(string(c), 64) } runtime := catalogue.Manifest{Module: "node-tools", Version: "1", ToolRunner: true, OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh/node-tools/broker"}}, Bundles: []catalogue.Bundle{{Name: "runtime", Source: catalogue.ArtifactStoreScheme + "node-tools/runtime/blobs/" + dg('a'), Digest: dg('a'), Language: "go", Binary: "node-tools"}}} store := catalogue.Manifest{Module: "artifacts", Version: "1", Claims: []catalogue.Claim{{Name: "container-image-registry", Scope: catalogue.ScopeMesh}}, Listens: []catalogue.Listening{{Name: "registry", Port: 5100, From: catalogue.FromMesh}}} lamp := catalogue.Manifest{Module: "lamp", Version: "1", Tools: []string{"on"}, Resources: []map[string]any{{"id": "state", "type": "directory", "path": "/var/lib/lamp", "mode": "0700"}}, Build: &catalogue.Build{Artifacts: []catalogue.Artifact{{Name: "tools", Kind: catalogue.ArtifactBundle, Language: "go", System: "arch", From: "cmd/lamp-tools", Env: map[string]string{"LAMP_CONF": "/var/lib/lamp/conf"}}}}} newLamp, err := lamp.Resolve([]catalogue.Built{{Name: "tools", Kind: catalogue.ArtifactBundle, Reference: catalogue.ArtifactStoreScheme + "lamp/tools/blobs/" + dg('c'), Digest: dg('c')}}) if err != nil { t.Fatal(err) } served := "lamp=" + resolution.BundlePath("lamp", "tools") + "/lamp-tools" runtimeRuns := func(dropped bool, ran string) engcomp.Composed { env := `"MESH_TOOL_MODULES":"` + served + `","MESH_TOOL_ENV":"{\"lamp\":{\"LAMP_CONF\":\"/var/lib/lamp/conf\"}}"` if dropped { env = `"MESH_TOOL_MODULES":""` // the drop already applied (shanks, 2026-10-29) } if ran != "" { env = ran } return engcomp.Composed{Node: "anchor", Module: "node-tools", Resources: []json.RawMessage{json.RawMessage( `{"id":"node-tools.runtime","module":"node-tools","type":"process","name":"node-tools","env":{` + env + `}}`)}} } lampRuns := `{"id":"lamp.bundle-tools","type":"archive","source":"` + catalogue.ArtifactStoreScheme + `lamp/tools/blobs/` + dg('b') + `","digest":"` + dg('b') + `","path":"` + resolution.BundlePath("lamp", "tools") + `"}` // H-A-303, H-A-306: what runs of lamp in the runtime, its fingerprint and the paths it owns among its words, at a load // its new build no longer names. ranServed := "lamp=" + resolution.BundlePath("lamp", "tools") + "/lamp-tools-old" ranWords := `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf","MESH_FINGERPRINT":"` + fpFor('0') + `","MESH_OWNED_PATHS":"/var/lib/lamp"}}` ranEnv := `"MESH_TOOL_MODULES":"` + ranServed + `","MESH_TOOL_ENV":` + strconv.Quote(ranWords) held := func(n *Node) engcomp.Composed { n.Held = map[string]bool{"lamp": true} lr := engcomp.Composed{Node: "anchor", Module: "lamp", Resources: []json.RawMessage{json.RawMessage( strings.Replace(lampRuns, `"type"`, `"module":"lamp","type"`, 1))}} n.Kept = map[string]catalogue.Manifest{"lamp": Carried(newLamp, "lamp", &lr)} return lr } for _, row := range []struct { name string set func(n *Node) engcomp.Composed // and what runs of lamp fps map[string]string dropped bool ran string // the runtime's env as it runs, when not served's // What the runtime is composed to serve of lamp, and its words, when not served and its manifest's words. wantServed, wantWords string }{ {"folded at a build of the old form", func(n *Node) engcomp.Composed { n.InOwn = map[string]bool{"lamp": true} n.RunsOwn = &engcomp.Composed{Node: "anchor", Resources: []json.RawMessage{json.RawMessage(lampRuns)}} return *n.RunsOwn }, map[string]string{}, false, "", "", ""}, {"folded, the runtime already dropped it", func(n *Node) engcomp.Composed { n.InOwn = map[string]bool{"lamp": true} n.RunsOwn = &engcomp.Composed{Node: "anchor", Resources: []json.RawMessage{json.RawMessage(lampRuns)}} return *n.RunsOwn }, map[string]string{}, true, "", "", ""}, // H-A-477: a setting's word the runtime runs with is the mesh's, composed again, never the bundle's own word. {"folded, a setting's word it runs with is not its own", func(n *Node) engcomp.Composed { n.InOwn = map[string]bool{"lamp": true} n.RunsOwn = &engcomp.Composed{Node: "anchor", Resources: []json.RawMessage{json.RawMessage(lampRuns)}} return *n.RunsOwn }, map[string]string{}, false, `"MESH_TOOL_MODULES":"` + served + `","MESH_TOOL_ENV":` + strconv.Quote(`{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf","MESH_CONFIG_PUBLISH_TRIES":"8"}}`), "", ""}, // H-A-306: a held module's slice is what runs of it, verbatim: no fingerprint of its want where none runs. {"held, its new build not delivered", held, map[string]string{"lamp": fpFor('1')}, false, "", served, `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf"}}`}, // H-A-303, H-A-306: held for a part withheld, its load, its fingerprint and its files words are what runs. {"held for a part withheld, its slice as it runs", held, map[string]string{"lamp": fpFor('1')}, false, ranEnv, ranServed, ranWords}, // H-A-306 (3): a module whose parts answered and changed is composed from its build, not from what runs. {"read, its build changed", func(n *Node) engcomp.Composed { n.Kept = map[string]catalogue.Manifest{"lamp": newLamp} return engcomp.Composed{Node: "anchor", Module: "lamp", Resources: []json.RawMessage{json.RawMessage( strings.Replace(lampRuns, `"type"`, `"module":"lamp","type"`, 1))}} }, map[string]string{"lamp": fpFor('1')}, false, ranEnv, "", ""}, } { tools := aMesh(t) tools.Catalogue["node-tools"], tools.Catalogue["artifacts"], tools.Catalogue["lamp"] = runtime, store, lamp anchor := nodeOf(t, &tools, "anchor") anchor.Assigned = append(anchor.Assigned, "artifacts", "node-tools", "lamp") tools.BusMinted = []string{"anchor." + "node-tools"} anchor.SealingKey = keyOf(t, "anchor") ran := []engcomp.Composed{runtimeRuns(row.dropped, row.ran), row.set(anchor)} anchor.RunsTools, anchor.RunsRuntime = ToolsRunning(ran), RuntimeRunning(ran) row.fps[overlay.Name], row.fps["artifacts"], row.fps["node-tools"] = fpFor('a'), fpFor('5'), fpFor('e') var digests []string var env map[string]any for range 2 { // two passes over the same input compose the same runtime (H-A-303) out, _, _, err := CompositionsIn(tools, "anchor", row.fps, Foreseeing) if err != nil { t.Fatalf("%s: %v", row.name, err) } for _, c := range out { for _, raw := range c.Resources { var r struct { ID string `json:"id"` Env map[string]any `json:"env"` } if json.Unmarshal(raw, &r) == nil && r.ID == "node-tools.runtime" { env = r.Env dig, err := engcomp.DigestOf(c) if err != nil { t.Fatal(err) } digests = append(digests, dig) } } } } if len(digests) != 2 || digests[0] != digests[1] { t.Errorf("%s: two passes composed the runtime at %v", row.name, digests) } // §519: the words each bundle's module is given hold the fingerprint of the want it applies, where there is one. wantServed, words := served, `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf"}}` if fp := row.fps["lamp"]; fp != "" { words = `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf","MESH_FINGERPRINT":"` + fp + `"}}` } if row.wantServed != "" { wantServed, words = row.wantServed, row.wantWords } if env[catalogue.RuntimeToolModules] != wantServed || env[catalogue.RuntimeToolEnv] != words { t.Errorf("%s: the runtime serves %v with %v, want %s with %s", row.name, env[catalogue.RuntimeToolModules], env[catalogue.RuntimeToolEnv], wantServed, words) } } // Design 47 H2 §813 (12), H-A-416 (2), H-A-419: a node's declaration is written at the lower of the composer's Version // and the one its engine states it reads: one stating 1, or none, gets Version 1 and no drain-bound; one stating 2 // gets Version 2 with it. t.Run("a declaration is written at the Version the node's engine reads", func(t *testing.T) { process := json.RawMessage(`{"id":"node-tools.runtime","type":"process","drain-bound":30}`) for _, row := range []struct { reads, version int drain bool }{{0, 1, false}, {1, 1, false}, {2, 2, true}, {3, 2, true}} { got, err := AtDeclarationVersion(process, row.reads) if err != nil || DeclarationVersionFor(row.reads) != row.version || strings.Contains(string(got), "drain-bound") != row.drain { t.Errorf("an engine reading %d: Version %d, %s (%v)", row.reads, DeclarationVersionFor(row.reads), got, err) } } }) } // lead-47 2026-11-16: a held tool runner keeps the program it runs (Carried, runningProgram) after what the runtime serves // is laid on the stubs (Node.RunsTools), so a module of its own account on its node is run by that program, not held // "the tool runner is not here to run it from" (novox, the new indexer). func aHeldToolRunnerKeepsItsProgramForTheModulesOfTheirOwnAccount(t *testing.T) { dg := "sha256:" + strings.Repeat("d", 64) source := catalogue.ArtifactStoreScheme + "node-tools/runtime/blobs/" + dg runtime := catalogue.Manifest{Module: "node-tools", Version: "1", ToolRunner: true, OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh/node-tools/broker"}}} own := catalogue.Manifest{Module: "mesh-self-check", Version: "1", RunsAs: "mesh-self-check", OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh/mesh-self-check/broker", Taken: catalogue.TakenAtStart}}, Bundles: []catalogue.Bundle{{Name: "tools", Source: catalogue.ArtifactStoreScheme + "mesh-self-check/tools/blobs/" + dg, Digest: dg, Language: "go", Loads: []string{"mesh-self-check-tools"}}}} store := catalogue.Manifest{Module: "artifacts", Version: "1", Claims: []catalogue.Claim{{Name: "container-image-registry", Scope: catalogue.ScopeMesh}}, Listens: []catalogue.Listening{{Name: "registry", Port: 5100, From: catalogue.FromMesh}}} runs := engcomp.Composed{Node: "anchor", Module: "node-tools", Resources: []json.RawMessage{json.RawMessage( `{"id":"node-tools.runtime","module":"node-tools","type":"process","name":"node-tools","source":"` + source + `","digest":"` + dg + `","run":["./node-tools"],"env":{"MESH_TOOL_MODULES":""}}`)}} in := aMesh(t) in.Catalogue["node-tools"], in.Catalogue["artifacts"], in.Catalogue["mesh-self-check"] = runtime, store, own anchor := nodeOf(t, &in, "anchor") anchor.Assigned = append(anchor.Assigned, "artifacts", "node-tools", "mesh-self-check") in.BusMinted = []string{"anchor.node-tools", "anchor.mesh-self-check"} anchor.SealingKey = keyOf(t, "anchor") anchor.Held = map[string]bool{"node-tools": true} anchor.Kept = map[string]catalogue.Manifest{"node-tools": Carried(runtime, "node-tools", &runs)} anchor.RunsTools = ToolsRunning([]engcomp.Composed{runs}) fps := map[string]string{overlay.Name: fpFor('a'), "artifacts": fpFor('5'), "node-tools": fpFor('e'), "mesh-self-check": fpFor('6')} out, _, _, err := CompositionsIn(in, "anchor", fps, Foreseeing) if err != nil { t.Fatalf("a module of its own account beside a held tool runner: %v", err) } ran := false for _, c := range out { for _, raw := range c.Resources { var r struct { Type string `json:"type"` Digest string `json:"digest"` Run []string `json:"run"` User string `json:"user"` } if json.Unmarshal(raw, &r) == nil && r.Type == "process" && r.User == "mesh-self-check" { ran = r.Digest == dg && len(r.Run) == 1 && r.Run[0] == "./node-tools" } } } if !ran { t.Errorf("mesh-self-check is not run by the program node-tools runs: %v", out) } } // H-A-335, H-A-337, H-A-306: the holder of node-reads (a runtime of its own) and the holder of node-files (in the tool // runner's) are told the node's secret places and owned paths, to which every module gives a share. While a module is // held its share is what runs, never its stub's, so two passes with the same held set compose both runtimes the same // whatever its stub says (ace, 2026-11-21 21:54: the reads runtime restarted twice in two minutes for MESH_SECRET_PLACES); // a module that answered and changed is composed from its build. func aHeldModulesShareOfTheHoldersWordsIsWhatRuns(t *testing.T) { dg := func(c byte) string { return "sha256:" + strings.Repeat(string(c), 64) } runtime := catalogue.Manifest{Module: "node-tools", Version: "1", ToolRunner: true, OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh/node-tools/broker"}}, Bundles: []catalogue.Bundle{{Name: "runtime", Source: catalogue.ArtifactStoreScheme + "node-tools/runtime/blobs/" + dg('a'), Digest: dg('a'), Language: "go", Binary: "node-tools"}}} tools := func(module string) []catalogue.Bundle { return []catalogue.Bundle{{Name: "tools", Source: catalogue.ArtifactStoreScheme + module + "/tools/blobs/" + dg('d'), Digest: dg('d'), Language: "go", Loads: []string{module + "-tools"}}} } reads := catalogue.Manifest{Module: "mesh-reads", Version: "1", RunsAs: "mesh-reads", SecretsOwner: "mesh-reads", Claims: []catalogue.Claim{{Name: catalogue.ReadsSeat}}, OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh-reads/broker", Taken: catalogue.TakenAtStart}}, Bundles: tools("mesh-reads")} files := catalogue.Manifest{Module: "files", Version: "1", Claims: []catalogue.Claim{{Name: catalogue.FilesSeat}}, Bundles: tools("files")} store := catalogue.Manifest{Module: "artifacts", Version: "1", Claims: []catalogue.Claim{{Name: "container-image-registry", Scope: catalogue.ScopeMesh}}, Listens: []catalogue.Listening{{Name: "registry", Port: 5100, From: catalogue.FromMesh}}} // lamp as it ran (its secret under /var/lib/lamp/old, its state at /var/lib/lamp-old), and its new build. lampAt := func(secret, state string) catalogue.Manifest { return catalogue.Manifest{Module: "lamp", Version: "1", OwnSecrets: catalogue.OwnSecrets{"token": {Path: secret}}, Resources: []map[string]any{{"id": "state", "type": "directory", "path": state, "mode": "0700"}}} } oldLamp, newLamp := lampAt("/var/lib/lamp/old/token", "/var/lib/lamp-old"), lampAt("/var/lib/lamp/new/token", "/var/lib/lamp-new") ranPlaces := `["/var/lib/lamp/old","/var/lib/mesh-reads","/var/lib/mesh/node-tools"]` // The resolver, held, and the uplink: by the rules between modules the resolver's file is the resolver's (it steps // back for node-resolver here), the uplink's only without the resolver (the review of 94a2e6ed). resolver := catalogue.Manifest{Module: "resolver", Version: "1", Claims: []catalogue.Claim{{Name: catalogue.ResolverSeat}}, Resources: []map[string]any{{"id": "stub", "type": "file", "path": catalogue.ResolverFile, "content": "nameserver 127.0.0.53\n"}}} uplink := catalogue.Manifest{Module: "uplink", Version: "1", Claims: []catalogue.Claim{{Name: "node-uplink"}}, Resources: []map[string]any{{"id": "resolv", "type": "file", "path": catalogue.ResolverFile, "content": "nameserver 192.0.2.1\n"}}} resolverOwns := `"` + catalogue.ResolverFile + `":"resolver (` + catalogue.ResolverSeat + `)"` ranOwned := `{"/var/lib/lamp-old":"lamp (its own tools)",` + resolverOwns + `}` process := func(id, module string, words map[string]map[string]string) json.RawMessage { body, _ := json.Marshal(words) env, _ := json.Marshal(map[string]string{catalogue.RuntimeToolEnv: string(body)}) return json.RawMessage(`{"id":"` + id + `","module":"` + module + `","type":"process","env":` + string(env) + `}`) } ran := []engcomp.Composed{ {Node: "anchor", Module: "node-tools", Resources: []json.RawMessage{process("node-tools.runtime", "node-tools", map[string]map[string]string{"files": {catalogue.ReadsSecretPlaces: ranPlaces, catalogue.FilesOwnedPaths: ranOwned}})}}, {Node: "anchor", Module: "mesh-reads", Resources: []json.RawMessage{process("mesh-reads."+catalogue.OwnRuntimeID(), "mesh-reads", map[string]map[string]string{"mesh-reads": {catalogue.ReadsSecretPlaces: ranPlaces}})}}, } for _, row := range []struct { name string held bool // The stub lamp is held as at each of two passes: what a withheld part gives it differs pass by pass. stubs []catalogue.Manifest // What lamp gives of the places and owned paths, and what it no longer gives. wantPlace, gonePlace, wantOwned, goneOwned string resolvers bool // the resolver held and the uplink beside lamp }{ {"held, its stub differing pass by pass", true, []catalogue.Manifest{Stub(newLamp), Stub(catalogue.Manifest{Module: "lamp", Version: "1"})}, "/var/lib/lamp/old", "/var/lib/lamp/new", "/var/lib/lamp-old", "/var/lib/lamp-new", false}, {"answered, its build changed", false, []catalogue.Manifest{newLamp, newLamp}, "/var/lib/lamp/new", "/var/lib/lamp/old", "/var/lib/lamp-new", "/var/lib/lamp-old", false}, {"held, a path another module owns only without it", true, []catalogue.Manifest{Stub(newLamp), Stub(newLamp)}, "/var/lib/lamp/old", "/var/lib/lamp/new", "/var/lib/lamp-old", "/var/lib/lamp-new", true}, } { in := aMesh(t) in.Catalogue["node-tools"], in.Catalogue["artifacts"], in.Catalogue["mesh-reads"] = runtime, store, reads in.Catalogue["files"], in.Catalogue["lamp"] = files, oldLamp anchor := nodeOf(t, &in, "anchor") anchor.Assigned = append(anchor.Assigned, "artifacts", "node-tools", "mesh-reads", "files", "lamp") in.BusMinted = []string{"anchor.node-tools", "anchor.mesh-reads"} anchor.SealingKey = keyOf(t, "anchor") if row.held { anchor.Held = map[string]bool{"lamp": true} } if row.resolvers { in.Catalogue["resolver"], in.Catalogue["uplink"] = resolver, uplink anchor.Assigned = append(anchor.Assigned, "resolver", "uplink") anchor.Held["resolver"] = true } anchor.RunsRuntime, anchor.RunsRuntimes = RuntimeRunning(ran), RuntimesRunning(ran) fps := map[string]string{overlay.Name: fpFor('a'), "artifacts": fpFor('5'), "node-tools": fpFor('e'), "mesh-reads": fpFor('6'), "files": fpFor('7'), "lamp": fpFor('8'), "resolver": fpFor('9'), "uplink": fpFor('b')} digests := map[string][]string{} said := map[string]string{} for _, stub := range row.stubs { anchor.Kept = map[string]catalogue.Manifest{"lamp": stub} if row.resolvers { anchor.Kept["resolver"] = Stub(resolver) } out, _, _, err := CompositionsIn(in, "anchor", fps, Foreseeing) if err != nil { t.Fatalf("%s: %v", row.name, err) } for _, c := range out { for _, raw := range c.Resources { var r struct { ID string `json:"id"` Env map[string]string `json:"env"` } if json.Unmarshal(raw, &r) != nil { continue } holder := map[string]string{"node-tools.runtime": "files", "mesh-reads." + catalogue.OwnRuntimeID(): "mesh-reads"}[r.ID] if holder == "" { continue } dig, err := engcomp.DigestOf(c) if err != nil { t.Fatal(err) } digests[r.ID] = append(digests[r.ID], dig) var words map[string]map[string]string _ = json.Unmarshal([]byte(r.Env[catalogue.RuntimeToolEnv]), &words) said[r.ID+" places"] = words[holder][catalogue.ReadsSecretPlaces] if holder == "files" { said[r.ID+" owned"] = words[holder][catalogue.FilesOwnedPaths] } } } } for _, id := range []string{"node-tools.runtime", "mesh-reads." + catalogue.OwnRuntimeID()} { if d := digests[id]; len(d) != 2 || d[0] != d[1] { t.Errorf("%s: two passes composed %s at %v", row.name, id, d) } } for what, words := range said { want, gone := row.wantPlace, row.gonePlace if strings.HasSuffix(what, " owned") { want, gone = row.wantOwned, row.goneOwned } if !strings.Contains(words, `"`+want+`"`) || strings.Contains(words, `"`+gone+`"`) { t.Errorf("%s: %s are %s, want %s among them and not %s", row.name, what, words, want, gone) } } if owned := said["node-tools.runtime owned"]; row.resolvers && !strings.Contains(owned, resolverOwns) { t.Errorf("%s: the owned paths are %s, want %s among them", row.name, owned, resolverOwns) } if len(said) != 3 { t.Errorf("%s: the holders are told %v", row.name, said) } } }