diff --git a/go/catalogue/manifest_reads.go b/go/catalogue/manifest_reads.go index e6dc9b34..dd7ef0c0 100644 --- a/go/catalogue/manifest_reads.go +++ b/go/catalogue/manifest_reads.go @@ -1,12 +1,8 @@ package catalogue import ( - "bytes" _ "embed" - "encoding/json" "reflect" - "regexp" - "slices" "sort" "strings" ) @@ -23,9 +19,8 @@ import ( // - `seat:`, a seat of the contract's seat table, as a manifest names one in a claim, a use, an invoke or a // bucket's share. // -// ManifestReads is what this contract reads; ManifestNeeds what one manifest's own words, forms and seat names need; -// BaselineManifestReads what a node-engine that states none is read as stating. What a module's build reads once it -// runs is never asked. +// ManifestReads is what this contract reads; what one manifest needs of it is the indexer's judge's to say (design 47 H2 +// H-A-622, H-A-639). What a module's build reads once it runs is never asked. const ( ReadWord = "word:" ReadForm = "form:" @@ -41,10 +36,6 @@ var referenceForms = []string{"access", "backup", "bound", "collected", "config" // ifConfigWord is the reader capability for a resource's `if-config` (IfConfigField). const ifConfigWord = ReadWord + "resources." + IfConfigField -// configJSONToken is the reference form `${config-json}` whole: it holds no colon, so textNeeds's search for `${
:` -// does not find it (design 42 zfs-owns-zfs, answer A-25). -const configJSONToken = "${config-json}" - // ReferenceFormSeat names the reference form a registry seat answers for a build's artifact, // `//@sha256:` (novox/hq ADR 0605 §9; the registry clients' reference forms), as the reader capability // `form:seat-reference` a node-engine built with this contract states (ADR 0618 §1, ADR 0624 §1): the builder writes it @@ -60,39 +51,9 @@ var artifactReferenceForms = []string{ReferenceFormSeat} // opens to the mesh, the store's three seats among them, never from a module serving the retired provision // artifact-store. An engine before it filled the store's reach only from that provision, so a manifest naming a seat's // reach, and the store holder's own manifest, need it and are held from a node whose engine does not state it -// (ManifestNeeds). +// (the indexer's judge reads it). const ReferenceFormSeatReach = "seat-reach" -// storeHolderSeat is the seat whose holder's own manifest needs form:seat-reach (novox/hq ADR 0632 §2): the one seat -// name this contract reads a rule by, and the one seat name of the package-list test's exceptions (S-8). -const storeHolderSeat = "container-image-registry" - -// claimsAtMesh says whether a manifest claims seat at the mesh's scope (a claim with no scope is the seat's own). The -// store holder's own manifest, a claim of storeHolderSeat, needs form:seat-reach this way (ADR 0632 §2): read -// on every node, it leaves an engine before the reading without the old way to find the store, so it is held from every -// node whose engine does not state it. -func claimsAtMesh(top map[string]any, seat string) bool { - for _, c := range asList(top["claims"]) { - obj, _ := c.(map[string]any) - name, _ := obj["name"].(string) - scope, _ := obj["scope"].(string) - if hs, ok := SeatNamed(name); ok && hs.Name == seat && (scope == "" || scope == ScopeMesh) { - return true - } - } - return false -} - -// ReadDirectoryContentsOwner is the reader capability of a node-engine that, when a directory's owner changes, gives its -// contents the new owner too (novox/hq design 47 H2, H-A-545 (2), H-A-550, H-A-556): an engine before it changes the -// directory alone, and a module moved to an account of its own then cannot read what it wrote before. A manifest that -// declares runs-as needs it (ManifestNeeds), so the module graph orders such a module's move after that engine runs on -// its node (ADR 0614 §4). The engine states it itself; this contract does not (ManifestReads). -const ReadDirectoryContentsOwner = "directory-contents-owner" - -// ofSeatReach is a manifest's value naming a seat's reach, `${seat::reach}`. -var ofSeatReach = regexp.MustCompile(`\$\{seat:[a-z0-9][a-z0-9-]*:reach\}`) - // manifestTopWords are the top-level keys Manifest.UnmarshalJSON reads apart from the fields of manifestFields: each // read whole, its inside a map of the module's own names (requirements, local names) and values, no words of the // contract's beneath it. `requires` and `config` are read as their fields are (manifestNeeds). @@ -127,161 +88,6 @@ func ManifestReads() []string { return sortedSet(set) } -// baselineManifestReads is the baseline, generated once from mesh-sdk f02f142 (the contract every node-engine ran -// before any stated what it reads) by ManifestReads as this file computes it: one reader capability a line. -// -//go:embed manifest_reads_baseline.txt -var baselineManifestReads string - -// BaselineManifestReads is what a node-engine that states no reader capability is read as stating (novox/hq ADR 0614 -// §4): the words, forms and seat names of the shared contract as it stood before any node-engine stated them. -func BaselineManifestReads() []string { - var out []string - for _, line := range strings.Split(baselineManifestReads, "\n") { - if line = strings.TrimSpace(line); line != "" { - out = append(out, line) - } - } - return out -} - -// StatedManifestReads is what a node-engine's statement is read as: stated itself, or the baseline when it states none -// (an engine built before the statement existed). -func StatedManifestReads(stated []string) []string { - if len(stated) == 0 { - return BaselineManifestReads() - } - return stated -} - -// MissingManifestReads is each of needs that stated, read as StatedManifestReads reads it, lacks: sorted, nil when it -// lacks none. -func MissingManifestReads(needs, stated []string) []string { - have := map[string]bool{} - for _, s := range StatedManifestReads(stated) { - have[s] = true - } - var missing []string - for _, n := range needs { - if !have[n] { - missing = append(missing, n) - } - } - sort.Strings(missing) - return slices.Compact(missing) -} - -// ManifestNeeds is every reader capability a manifest's own words, forms and seat names need, sorted, read as the -// lenient decoder walks the manifest: only what this contract knows is named, since what it does not know is set aside -// (Manifest.SetAside). An error is only bytes that are no JSON object. -func ManifestNeeds(raw []byte) ([]string, error) { - var top map[string]any - dec := json.NewDecoder(bytes.NewReader(raw)) - dec.UseNumber() - if err := dec.Decode(&top); err != nil { - return nil, err - } - used := map[string]bool{} - textNeeds(raw, used) - if claimsAtMesh(top, storeHolderSeat) { - used[ReadForm+ReferenceFormSeatReach] = true - } - if runsAs, _ := top["runs-as"].(string); runsAs != "" { - used[ReadDirectoryContentsOwner] = true - } - for _, r := range asList(top["resources"]) { - if obj, ok := r.(map[string]any); ok { - if _, has := obj[IfConfigField]; has { - used[ifConfigWord] = true - } - } - } - if _, has := top[ConfigField]; has || takesConfigKey.Match(raw) { - used[ReadForm+"config"] = true - } - words := map[string]bool{} - fields := structFields(reflect.TypeOf(manifestFields{})) - for _, k := range sortedAnyKeys(top) { - v := top[k] - switch { - case k == ConfigField: - // The config form is the settings form's words under another key (config.go). - words[SettingsField] = true - walkValue(v, fields[SettingsField].Type, SettingsField, words) - case k == "requires": - words[k] = true - for _, e := range asList(v) { - obj, isObj := e.(map[string]any) - if !isObj { - continue - } - if _, bus := obj["storage"]; bus { - // A bus-state entry of `requires` (BusStateEntry): the stored form's `bus-state`. - words[BusStateField] = true - walkValue(obj, reflect.TypeOf(BusStateEntry{}), BusStateField, words) - continue - } - walkValue(obj, reflect.TypeOf(requirementForm{}), k, words) - } - case slices.Contains(manifestTopWords, k): - words[k] = true - default: - if f, known := fields[k]; known { - words[k] = true - walkValue(v, f.Type, k, words) - } - } - } - for w := range words { - used[ReadWord+w] = true - } - for _, s := range seatNamesUsed(top) { - used[ReadSeat+s] = true - } - return sortedSet(used), nil -} - -// seatNamesUsed is each seat of the contract's table the manifest names: in a claim, a use, an invoke of a seat's verb, -// and a bucket's share with a seat. -func seatNamesUsed(top map[string]any) []string { - known := map[string]bool{} - for _, s := range Seats() { - known[s.Name] = true - } - set := map[string]bool{} - add := func(name string) { - if known[name] { - set[name] = true - } - } - for _, c := range asList(top["claims"]) { - if obj, ok := c.(map[string]any); ok { - name, _ := obj["name"].(string) - add(name) - } - } - for _, u := range asList(top["uses"]) { - name, _ := u.(string) - add(name) - } - for _, i := range asList(top["invokes"]) { - text, _ := i.(string) - if seat, _, ok := SeatInvoke(text); ok { - add(seat) - } - } - for _, r := range asList(top["requires"]) { - obj, _ := r.(map[string]any) - for _, share := range asList(obj["shares"]) { - text, _ := share.(string) - if seat, ok := strings.CutPrefix(text, "seat:"); ok { - add(seat) - } - } - } - return sortedSet(set) -} - // contractWords is every word of this contract, by path (ReadWord): the fields of manifestFields, the keys the // manifest's own decoder reads beside them, and the long form of a requirement. func contractWords() []string { @@ -325,49 +131,6 @@ func walkType(t reflect.Type, path string, set map[string]bool, onPath map[refle } } -// walkValue adds to used every word of t that v, a value decoded from JSON, has at path. -func walkValue(v any, t reflect.Type, path string, used map[string]bool) { - t = deref(t) - if keys, custom := wireKeys[t]; custom { - obj, _ := v.(map[string]any) - for _, k := range keys { - if _, has := obj[k]; has { - used[joinWord(path, k)] = true - } - } - return - } - switch t.Kind() { - case reflect.Struct: - obj, isObj := v.(map[string]any) - if !isObj { - return // a short form (a name for an offer): no words inside it - } - fields := structFields(t) - for _, k := range sortedAnyKeys(obj) { - f, known := fields[k] - if !known { - continue // set aside by the decoder, so no word of this contract - } - word := joinWord(path, k) - used[word] = true - walkValue(obj[k], f.Type, word, used) - } - case reflect.Slice, reflect.Array: - if t.Elem().Kind() == reflect.Uint8 { - return - } - for _, item := range asList(v) { - walkValue(item, t.Elem(), path, used) - } - case reflect.Map: - obj, _ := v.(map[string]any) - for _, k := range sortedAnyKeys(obj) { - walkValue(obj[k], t.Elem(), path, used) - } - } -} - // structFields are a struct's fields by the key the JSON decoder reads each by: its tag's name, else its own name; an // untagged embedded struct's fields as the struct's own; never one tagged "-" or unexported. func structFields(t reflect.Type) map[string]reflect.StructField { @@ -454,42 +217,6 @@ func asList(v any) []any { return list } -// textNeeds adds the reference forms a manifest's or a template's text writes to used: a form the engine fills in a -// file's text is read there whether the text is inline or in a template file. -func textNeeds(text []byte, used map[string]bool) { - for _, f := range referenceForms { - if bytes.Contains(text, []byte("${"+f+":")) { - used[ReadForm+f] = true - } - } - if bytes.Contains(text, []byte(configJSONToken)) { - used[ReadForm+"config-json"] = true - } - if ofSeatReach.Match(text) { - used[ReadForm+ReferenceFormSeatReach] = true - } -} - -// ModuleNeeds is ManifestNeeds of a module whose files take their text from templates (template.go): what the manifest -// needs and what each template's text writes, by template path (TemplatePaths), sorted. A module's needs are both: an -// engine renders the template's text as it renders inline content, so a template naming ${seat:x:reach} needs the -// reading as the same content inline does, though the manifest itself is unchanged (novox/hq ADR 0632 §2). A template -// named and not given is no need; the reader of the files says it could not read one. -func ModuleNeeds(raw []byte, templates map[string]string) ([]string, error) { - needs, err := ManifestNeeds(raw) - if err != nil || len(templates) == 0 { - return needs, err - } - used := map[string]bool{} - for _, n := range needs { - used[n] = true - } - for _, text := range templates { - textNeeds([]byte(text), used) - } - return sortedSet(used), nil -} - func sortedSet(set map[string]bool) []string { out := make([]string, 0, len(set)) for k := range set { diff --git a/go/catalogue/manifest_reads_baseline.txt b/go/catalogue/manifest_reads_baseline.txt deleted file mode 100644 index 68c7239f..00000000 --- a/go/catalogue/manifest_reads_baseline.txt +++ /dev/null @@ -1,334 +0,0 @@ -form:access -form:backup -form:bound -form:collected -form:config -form:consumer -form:consumers -form:contribution -form:dir -form:machine -form:port -form:seat -form:secret -form:setting -seat:git -seat:mesh-artifact-store -seat:mesh-artifact-sweep -seat:mesh-broker -seat:mesh-catalog -seat:mesh-conditions -seat:mesh-config -seat:mesh-delivery -seat:mesh-dns-resolver -seat:mesh-enrolment -seat:mesh-hand-acts -seat:mesh-healers -seat:mesh-placement -seat:mesh-provisioner -seat:mesh-self-check -seat:mesh-store -seat:mesh-vault -seat:mesh-wants -seat:mesh-watchdogs -seat:node-backup -seat:node-bar -seat:node-build-go -seat:node-build-image -seat:node-build-node -seat:node-clipboard -seat:node-compositor -seat:node-container-runtime -seat:node-display-server -seat:node-display-session -seat:node-engine -seat:node-environment -seat:node-files -seat:node-hostname -seat:node-hotkeys -seat:node-intrusion-prevention -seat:node-launcher -seat:node-lock-screen -seat:node-login-manager -seat:node-login-shell -seat:node-message-bus -seat:node-mounts -seat:node-nfs-server -seat:node-notifier -seat:node-package-manager -seat:node-packet-filter -seat:node-power -seat:node-provisioner -seat:node-reads -seat:node-resolver -seat:node-secret-service -seat:node-service-manager -seat:node-terminal-emulator -seat:node-uplink -seat:npm-package-registry -seat:the-private-network -word:accesses -word:accesses.id -word:accesses.mode -word:accesses.path -word:binds -word:build -word:build.artifacts -word:build.artifacts.binary -word:build.artifacts.bus -word:build.artifacts.bus.asks -word:build.artifacts.bus.emits -word:build.artifacts.bus.invokes -word:build.artifacts.bus.queues -word:build.artifacts.bus.removes -word:build.artifacts.bus.state -word:build.artifacts.compiles -word:build.artifacts.context -word:build.artifacts.context.ref -word:build.artifacts.context.repository -word:build.artifacts.context.seat -word:build.artifacts.entrypoints -word:build.artifacts.env -word:build.artifacts.external -word:build.artifacts.file -word:build.artifacts.from -word:build.artifacts.kind -word:build.artifacts.language -word:build.artifacts.loads -word:build.artifacts.name -word:build.artifacts.names-on-purpose -word:build.artifacts.paths -word:build.artifacts.sha256 -word:build.artifacts.system -word:build.artifacts.target -word:build.artifacts.url -word:build.artifacts.version -word:build.artifacts.within -word:build.on -word:build.on.arg -word:build.on.artifact -word:build.on.image -word:build.on.module -word:bundles -word:bundles.binary -word:bundles.bus -word:bundles.bus.asks -word:bundles.bus.emits -word:bundles.bus.invokes -word:bundles.bus.queues -word:bundles.bus.removes -word:bundles.bus.state -word:bundles.digest -word:bundles.entrypoints -word:bundles.env -word:bundles.language -word:bundles.launchers -word:bundles.loads -word:bundles.name -word:bundles.source -word:bus-users -word:capabilities -word:certificate -word:certificate.authority -word:certificate.into -word:claims -word:claims.capabilities -word:claims.kind -word:claims.name -word:claims.renders -word:claims.scope -word:claims.serves -word:collections -word:collections.comment -word:collections.name -word:computed -word:consumes -word:contributes -word:contributions -word:contributions.content -word:contributions.data -word:contributions.if-capability -word:contributions.kind -word:contributions.seat -word:data -word:data.consumers -word:data.consumers.class -word:data.consumers.in -word:data.consumers.why -word:data.kept-by -word:data.kept-by.class -word:data.kept-by.why -word:data.own -word:data.own.active -word:data.own.backup -word:data.own.backup.dump -word:data.own.backup.into -word:data.own.class -word:data.own.id -word:data.own.measure -word:data.own.path -word:data.own.redundancy -word:data.own.why -word:data.own.within -word:emits -word:environment -word:environment.path -word:environment.path.at -word:environment.path.entry -word:environment.variables -word:facts -word:facts.home -word:facts.path -word:facts.shared -word:facts.template -word:filtering -word:filtering.into -word:grants -word:guards -word:handed -word:handed.digest -word:handed.items -word:handed.source -word:handed.templates -word:instances -word:invokes -word:items -word:items.attributes -word:items.collection -word:items.content -word:items.if-capability -word:items.name -word:items.template -word:jailing -word:jailing.filter-into -word:jailing.into -word:jails -word:jails.failregex -word:jails.jail -word:jails.name -word:keeps -word:listens -word:listens.fixed -word:listens.from -word:listens.name -word:listens.port -word:listens.protocol -word:listens.why -word:logs -word:logs.max-age-days -word:logs.max-mib -word:logs.name -word:module -word:moved -word:objects -word:objects.grant -word:objects.grant.config -word:objects.max-mib -word:objects.name -word:optional-requires -word:own-secrets -word:own-secrets.issued-by -word:own-secrets.owner -word:own-secrets.path -word:own-secrets.prompt -word:own-secrets.taken -word:prepares -word:provides -word:provides.answered-by -word:provides.credential -word:provides.credential.form -word:provides.credential.issued-by -word:provides.credential.own -word:provides.credential.tool -word:provides.identity -word:provides.identity.in -word:provides.identity.max -word:provides.keeps-consumer-data -word:provides.name -word:provides.reach -word:provides.scope -word:reads -word:receives -word:replaces -word:requires -word:requires-shares -word:requires.name -word:requires.optional -word:requires.shares -word:requires.shares.methods -word:requires.shares.to -word:resources -word:runs-as -word:runtime-health -word:seats -word:seats.accepts -word:seats.by-caller -word:seats.emits -word:seats.kinded -word:seats.name -word:seats.needs -word:seats.paths -word:seats.proofs -word:seats.records -word:seats.retain-seconds -word:seats.scope -word:seats.serves -word:seats.serves.description -word:seats.serves.input -word:seats.serves.name -word:seats.serves.output -word:seats.serves.replaces -word:secrets -word:secrets-owner -word:serves -word:settings -word:settings.default -word:settings.description -word:settings.enum -word:settings.kind -word:settings.maximum -word:settings.minimum -word:settings.pattern -word:settings.predefined -word:settings.required -word:settings.runtime -word:settings.trusted -word:settings.type -word:settings.why -word:shell -word:shell.code -word:shell.for -word:shell.slot -word:slug -word:state -word:state.history -word:state.key-ttl -word:state.max-mib -word:state.name -word:state.per-machine -word:state.ttl-seconds -word:streams -word:streams.duplicates -word:streams.events -word:streams.grant -word:streams.grant.config -word:streams.grant.events -word:streams.max-age-days -word:streams.max-deliveries -word:streams.max-mib -word:streams.name -word:streams.retention -word:templates -word:tools -word:unhealthy -word:unhealthy.severity -word:unhealthy.why -word:upgrade -word:upgrade.policy -word:upgrade.why -word:uses -word:version -word:waits -word:zone -word:zone.listen -word:zone.name diff --git a/go/catalogue/own_manifest_test.go b/go/catalogue/own_manifest_test.go index ceffe063..49189a2e 100644 --- a/go/catalogue/own_manifest_test.go +++ b/go/catalogue/own_manifest_test.go @@ -1,7 +1,6 @@ package catalogue import ( - "maps" "os" "slices" "testing" @@ -47,24 +46,8 @@ func TestOwnManifestUsesNoWordTheRunningControllerRefuses(t *testing.T) { t.Errorf("mesh-sdk's TypeScript package is %+v, want lib built from package.json, package-lock.json, tsconfig.json and src", l) } - // What a reader reads (novox/hq ADR 0614 §4): the baseline is the contract of mesh-sdk f02f142, which every running - // node-engine was built with, and this contract reads all of it; the words added since are the only ones it lacks. - reads, baseline := ManifestReads(), BaselineManifestReads() - var added []string - for _, r := range reads { - if !slices.Contains(baseline, r) { - added = append(added, r) - } - } - // The two seats the milestone renamed (ADR 0634 §9) are read by their new names; a node-engine built with the baseline - // reads the old ones, and a manifest of the new names is the milestone's to deliver after the engines. The word - // `waits` is no longer read: novox/hq ADR 0670 §2 retired it. - renamed := []string{"seat:mesh-enrolment", "seat:mesh-placement", "word:waits"} - for _, b := range baseline { - if !slices.Contains(reads, b) && !slices.Contains(renamed, b) { - t.Errorf("the baseline's %s is no reader capability of this contract", b) - } - } + // What a reader reads (novox/hq ADR 0614 §4): the words, forms and seat names this contract reads. + reads := ManifestReads() for _, want := range []string{"word:tool-runner", "word:core-credentials", "word:bus-state", "word:bus-state.storage", // The reference form a registry seat answers (ADR 0605 §9), and the seats the registry milestone adds. ReadForm + ReferenceFormSeat, ReadForm + ReferenceFormSeatReach, "seat:go-package-registry", "seat:container-image-registry", "seat:oci-artifact-registry", @@ -72,107 +55,18 @@ func TestOwnManifestUsesNoWordTheRunningControllerRefuses(t *testing.T) { "word:declaration-reads", "word:declaration-writes", // H-A-394: a module's class, core or leaf. "word:class"} { - if !slices.Contains(added, want) { - t.Errorf("%s is in the baseline, or not read: added since it are %v", want, added) + if !slices.Contains(reads, want) { + t.Errorf("%s is not read by this contract: %v", want, reads) } } for _, want := range []string{"word:claims.serves", "word:settings.default", "form:config", "form:setting", "seat:mesh-catalog", // H-A-383: every node-engine reads a state's max-mib, so a manifest naming it needs no newer engine. "word:state.max-mib"} { - if !slices.Contains(baseline, want) { - t.Errorf("the baseline lacks %s", want) + if !slices.Contains(reads, want) { + t.Errorf("this contract does not read %s", want) } } if blocks := untaggedBlocks(); len(blocks) != 0 { t.Errorf("blocks whose words are their Go names, no decoder's keys: %v (name their keys in wireKeys)", blocks) } - // What a manifest's own words, forms and seat names need, beyond the baseline. - for _, row := range []struct { - why, raw string - needs []string // among its needs - missing []string // what the baseline lacks of them - }{ - {"a tool runner", `{"module":"r","version":"1","tool-runner":true}`, []string{"word:tool-runner"}, []string{"word:tool-runner"}}, - {"a manifest of the baseline's words", `{"module":"a","version":"1","claims":[{"name":"mesh-catalog","scope":"mesh",` + - `"serves":["modules"]}],"invokes":["seat:mesh-delivery.show"],"config":{"x":{"type":"string","default":""}},` + - `"resources":[{"id":"f","type":"file","content":"${config:x} ${count:-0}"}],"provides":["plain",{"name":"p",` + - `"identity":{"max":20,"in":"x"}}]}`, - []string{"word:claims.serves", "word:settings.type", "form:config", "seat:mesh-catalog", "seat:mesh-delivery", - "word:provides.identity.max", "word:resources"}, nil}, - {"a bus-state entry of requires", `{"module":"b","version":"1","requires":["mesh-bus",{"name":"jobs","storage":"kv"}]}`, - []string{"word:requires", "word:bus-state.storage"}, []string{"word:bus-state", "word:bus-state.name", "word:bus-state.storage"}}, - // A seat's reach, filled from the seat holder's listen (ADR 0632 §1): an engine before it lacks the reading. - {"a seat's reach", `{"module":"s","version":"1","resources":[{"id":"f","type":"file","content":"${seat:container-image-registry:reach}"}]}`, - []string{"form:seat", "form:seat-reach"}, []string{"form:seat-reach"}}, - // The store holder's manifest, distribution's as ADR 0632 leaves it: no reach written, no provision served; an engine - // stating only the baseline lacks the reading that finds the store by it (ADR 0632 §2). - {"the store's holder", `{"module":"distribution","version":"1","claims":[{"name":"container-image-registry",` + - `"scope":"mesh","serves":["list"]}],"listens":[{"name":"registry","port":5000,"from":"mesh"}]}`, - []string{"form:seat-reach", "seat:container-image-registry"}, []string{"form:seat-reach", "seat:container-image-registry"}}, - // docker's daemon file as ADR 0632 leaves it: the manifest unchanged, its template naming the image seat's reach; - // TemplatePaths names the template a reader of the files reads. - {"a template naming a seat's reach", `{"module":"d","version":"1","resources":[{"id":"daemon","type":"file",` + - `"path":"/etc/d.json","template":"files/daemon.json"}]}`, []string{"form:seat", "form:seat-reach"}, - []string{"form:seat-reach"}}, - // A resource under a config condition (design 42 zfs-owns-zfs §4, A-13). - {"a resource under if-config", `{"module":"z","version":"1","config":{"k":{"type":"string"}},"resources":[{"id":"f","type":"file",` + - `"if-config":["k"]}]}`, []string{"word:resources.if-config"}, []string{"word:resources.if-config"}}, - {"a resource without if-config", `{"module":"z","version":"1","resources":[{"id":"f","type":"file"}]}`, - []string{"word:resources"}, nil}, - // The template forms of the config file and the option lines (design 42 zfs-owns-zfs §3, §9; A-13, A-15, A-25). - {"a template writing config lines", `{"module":"z","version":"1","resources":[{"id":"f","type":"file","template":"files/o.conf"}]}`, - []string{"form:config-lines"}, []string{"form:config-lines"}}, - {"a template writing the config as json", `{"module":"z","version":"1","resources":[{"id":"f","type":"file","template":"files/c.json"}]}`, - []string{"form:config-json"}, []string{"form:config-json"}}, - {"a template of the config form alone", `{"module":"z","version":"1","resources":[{"id":"f","type":"file","template":"files/k"}]}`, - []string{"form:config"}, nil}, - // A module of its own account needs an engine that gives a directory's contents its new owner (H-A-556). - {"a module of its own account", `{"module":"g","version":"1","runs-as":"g"}`, - []string{"directory-contents-owner", "word:runs-as"}, []string{"directory-contents-owner"}}, - {"a word this contract does not know", `{"module":"u","version":"1","newer-word":{"inside":1}}`, []string{"word:module"}, nil}, - } { - templates := map[string]map[string]string{ // the templates' text a row's module names - "a template naming a seat's reach": {"files/daemon.json": `{"x":"${seat:container-image-registry:reach}"}`}, - "a template writing config lines": {"files/o.conf": "${config-lines:arc-max:options zfs zfs_arc_max=:mib-bytes}"}, - "a template writing the config as json": {"files/c.json": "${config-json}"}, - "a template of the config form alone": {"files/k": "${config:k}"}, - }[row.why] - needs, err := ModuleNeeds([]byte(row.raw), templates) - if err != nil { - t.Fatalf("%s: %v", row.why, err) - } - if templates != nil { - m, err := Decode([]byte(row.raw)) - if paths := TemplatePaths(m); err != nil || !slices.Equal(paths, slices.Sorted(maps.Keys(templates))) { - t.Errorf("%s: TemplatePaths = %v (%v), want %v", row.why, paths, err, slices.Sorted(maps.Keys(templates))) - } - } - for _, n := range row.needs { - if !slices.Contains(needs, n) { - t.Errorf("%s: needs %v, not %s", row.why, needs, n) - } - } - if slices.ContainsFunc(needs, func(n string) bool { return n == "word:newer-word" || n == "form:count" }) { - t.Errorf("%s: needs %v, naming what the contract does not read", row.why, needs) - } - for _, f := range []string{"form:config-lines", "form:config-json"} { - if slices.Contains(needs, f) != (row.why == map[string]string{"form:config-lines": "a template writing config lines", - "form:config-json": "a template writing the config as json"}[f]) { - t.Errorf("%s: needs %v, %s read wrongly", row.why, needs, f) - } - } - if slices.Contains(needs, "word:resources.if-config") != (row.why == "a resource under if-config") { - t.Errorf("%s: needs %v, if-config read wrongly", row.why, needs) - } - if got := MissingManifestReads(needs, nil); !slices.Equal(got, row.missing) { - t.Errorf("%s: an engine stating nothing lacks %v, want %v", row.why, got, row.missing) - } - // The node-engine states directory-contents-owner itself, beside this contract's reads (H-A-556). - if got := MissingManifestReads(needs, append(slices.Clone(reads), ReadDirectoryContentsOwner)); len(got) != 0 { - t.Errorf("%s: this contract lacks %v", row.why, got) - } - } - if got := MissingManifestReads([]string{"seat:mesh-catalog", "word:module"}, []string{"word:module"}); !slices.Equal(got, []string{"seat:mesh-catalog"}) { - t.Errorf("an engine stating its own reads is read by them alone: lacks %v", got) - } } diff --git a/go/catalogue/terminal_keys.go b/go/catalogue/terminal_keys.go index 02d7ad88..a78bef53 100644 --- a/go/catalogue/terminal_keys.go +++ b/go/catalogue/terminal_keys.go @@ -15,7 +15,7 @@ const TrustedField = "trusted" // IfConfigField is the key any resource may carry to be declared only while a config value of its module holds // (novox/hq design 42 zfs-owns-zfs §2, §4): a list of conditions, `` or `=`. Said in the catalogue and // read by the node-engine, which states it as the reader capability `word:resources.if-config` (ManifestReads); a -// manifest whose resource carries it needs that capability (ManifestNeeds). +// manifest whose resource carries it needs that capability (the indexer's judge reads it). const IfConfigField = "if-config" // TerminalKeys are the settings keys of a module that are set at the controller's terminal alone: places and diff --git a/go/packages_list_test.go b/go/packages_list_test.go index b17136a1..423b8810 100644 --- a/go/packages_list_test.go +++ b/go/packages_list_test.go @@ -72,7 +72,12 @@ var untilTheJoin = []string{ // computesNot are the functions whose computation is one owner's alone (ADR 0593 §2, §7): the indexer computes a // fingerprint, its named tree and a package's version; the node-engine composes. var computesNot = []string{"SourceFingerprint", "SourceFingerprint2", "NamedTree", "MeshPackagesOf", "PackageVersionsOf", - "OtherPackages", "Compose", "CompositionsShadow", "JudgeMove", "Run"} + "OtherPackages", "Compose", "CompositionsShadow", "JudgeMove", "Run", + // The reading of a manifest's needs is the indexer's judge's alone (design 47 H2 H-A-622, H-A-639, H-A-671). + "ManifestNeeds", "ModuleNeeds", "BaselineManifestReads", "StatedManifestReads", "MissingManifestReads"} + +// movedConsts are the constants that left mesh-sdk with the reader capabilities (design 47 H2 H-A-622, H-A-671). +var movedConsts = []string{"ReadDirectoryContentsOwner"} // composesNot are the methods of the composition, the node-engine's alone since its rules moved there (ADR 0593 §7): // mesh-sdk renders no declaration and refuses no composition. @@ -196,6 +201,17 @@ func TestMeshSDKHoldsOnlyWhatEveryModuleShares(t *testing.T) { } } for _, decl := range file.Decls { + if gen, isGen := decl.(*ast.GenDecl); isGen { + for _, spec := range gen.Specs { + if v, isValue := spec.(*ast.ValueSpec); isValue { + for _, name := range v.Names { + if slices.Contains(movedConsts, name.Name) { + t.Errorf("%s: %s is the node-engine's and the indexer's alone (design 47 H2 H-A-622, H-A-671)", path, name.Name) + } + } + } + } + } fn, ok := decl.(*ast.FuncDecl) if !ok { continue diff --git a/go/testdata/seat-names.txt b/go/testdata/seat-names.txt index cf329454..1a14b461 100644 --- a/go/testdata/seat-names.txt +++ b/go/testdata/seat-names.txt @@ -14,7 +14,6 @@ catalogue/graphical_session.go: node-login-manager catalogue/graphical_session.go: node-notifier catalogue/graphical_session.go: node-secret-service catalogue/graphical_session.go: node-terminal-emulator -catalogue/manifest_reads.go: container-image-registry catalogue/node_resolver.go: node-resolver catalogue/reads.go: node-reads catalogue/seat_contributions.go: node-backup