diff --git a/internal/compose/composed_test.go b/internal/compose/composed_test.go index b28bade1..595d38f2 100644 --- a/internal/compose/composed_test.go +++ b/internal/compose/composed_test.go @@ -326,7 +326,14 @@ func aHeldModulesShareOfTheHoldersWordsIsWhatRuns(t *testing.T) { } 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"]` - ranOwned := `{"/var/lib/lamp-old":"lamp (its own 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)}) @@ -345,11 +352,14 @@ func aHeldModulesShareOfTheHoldersWordsIsWhatRuns(t *testing.T) { 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"}, + "/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"}, + "/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 @@ -361,13 +371,21 @@ func aHeldModulesShareOfTheHoldersWordsIsWhatRuns(t *testing.T) { 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')} + "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) @@ -413,6 +431,9 @@ func aHeldModulesShareOfTheHoldersWordsIsWhatRuns(t *testing.T) { 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) } diff --git a/internal/compose/resolution/files.go b/internal/compose/resolution/files.go index 835ede27..85fcefeb 100644 --- a/internal/compose/resolution/files.go +++ b/internal/compose/resolution/files.go @@ -86,15 +86,21 @@ func resolutionFilesWords(r mcat.Resolution, m mcat.Manifest, words map[string]s } // heldOwnedPaths is ownedPaths with a held module's entries as they run (design 47 H, H-A-335, H-A-337): while any module -// is held and the holder's words as it runs (ran) say the owned paths, the entries the modules not held compose, and each -// running entry whose owner is a held module where those name no owner of its path (a module that answered applies, -// H-A-306 (3)). Else ownedPaths. +// is held and the holder's words as it runs (ran) say the owned paths, ownedPaths over the whole resolution, so the rules +// between modules (a seat path over a module's own tools, a seat path stepping back) read every module as before, less +// each entry a held module owns, and each running entry whose owner is a held module where no entry left names its path +// (a module that answered applies, H-A-306 (3)). Else ownedPaths. func heldOwnedPaths(r mcat.Resolution, held map[string]bool, ran map[string]string) map[string]string { + owned := resolutionOwnedPaths(r) var running map[string]string if body, says := ran[mcat.FilesOwnedPaths]; !says || json.Unmarshal([]byte(body), &running) != nil { - return resolutionOwnedPaths(r) + return owned + } + for p, entry := range owned { + if held[ownerOf(entry)] { + delete(owned, p) + } } - owned := resolutionOwnedPaths(notHeld(r, held)) for p, entry := range running { if _, composed := owned[p]; !composed && held[ownerOf(entry)] { owned[p] = entry