I4 set-aside-needs: the take-in names the need word:<path> of each word its read set aside, and NeedsRules is 2

Builds: design 47 H2b §872
This commit is contained in:
2026-11-27 03:06:12 +01:00
parent 5162465293
commit 388626ac82
2 changed files with 63 additions and 2 deletions
+55 -1
View File
@@ -22,7 +22,7 @@ import (
// NeedsRules is the version of the validator's need rules (design 47 H2, H-A-569 (2), H-A-605 (4)): raised with every
// change of the rules that derive a need from a manifest. Each catalog revision the indexer writes carries it, and a
// take-in derives the rule needs of unmoved entries again only when its own is higher than its base revision's.
const NeedsRules = 1
const NeedsRules = 2
// requirementLong is one entry of `requires` in its long form, as catalogue reads it.
type requirementLong struct {
@@ -123,9 +123,63 @@ func ManifestNeeds(raw []byte) ([]string, error) {
for _, s := range seatNamesUsed(top) {
used[catalogue.ReadSeat+s] = true
}
// A word the take-in's read set aside (design 47 H2b §872, H-A-813): the need of a word this reader does not know,
// in the form catalogue.ManifestReads() gives one, so a node-engine whose words lack it is held off the entry.
for _, path := range UnknownFields(raw) {
if word := readWordOf(path); word != "" {
used[catalogue.ReadWord+word] = true
}
}
return sortedSet(used), nil
}
// readWordOf is the path SetAside names for a word, `build.artifacts[0].race`, in the form catalogue.ManifestReads() gives
// a word: no list index, and no key of a map of the module's own names (a setting's, a requirement's), so
// `build.artifacts.race`. Where a path leaves the shape the contract knows, the keys after it are kept as they are.
func readWordOf(path string) string {
var segments []string
for _, seg := range strings.Split(path, ".") {
if i := strings.IndexByte(seg, '['); i >= 0 {
seg = seg[:i]
}
if seg != "" {
segments = append(segments, seg)
}
}
var t reflect.Type = reflect.TypeOf(catalogue.Manifest{})
var out []string
for _, seg := range segments {
for t != nil {
t = deref(t)
if k := t.Kind(); k == reflect.Slice || k == reflect.Array {
t = t.Elem()
continue
}
break
}
switch {
case t == nil:
out = append(out, seg)
case t.Kind() == reflect.Map:
t = t.Elem() // a key of the module's own names
case t.Kind() == reflect.Struct:
if _, custom := wireKeys[t]; custom {
out, t = append(out, seg), nil
continue
}
out = append(out, seg)
if f, known := structFields(t)[seg]; known {
t = f.Type
} else {
t = nil
}
default:
out, t = append(out, seg), nil
}
}
return strings.Join(out, ".")
}
// ModuleNeeds is ManifestNeeds of a module whose files take their text from templates: what the manifest needs and
// what each template's text writes, sorted. A template named and not given is no need.
func ModuleNeeds(raw []byte, templates map[string]string) ([]string, error) {
@@ -19,7 +19,14 @@ func TestManifestNeeds(t *testing.T) {
{"a module with no account of its own", `{"module":"g","version":"1"}`, nil,
[]string{"word:module"}, []string{"directory-contents-owner"}},
{"a word the contract does not know", `{"module":"u","version":"1","newer-word":{"inside":1}}`, nil,
[]string{"word:module"}, []string{"word:newer-word"}},
[]string{"word:module", "word:newer-word"}, nil},
// design 47 H2b §872, 1984/AC-872a: a nested word set aside has its need in the reads' form, without the list index.
{"a nested word the contract does not know", `{"module":"u","version":"1","build":{"artifacts":[{"name":"p","language":"go","race":true}]}}`, nil,
[]string{"word:module", "word:build.artifacts.race"}, []string{"word:build.artifacts[0].race"}},
{"a word beneath a setting's own name", `{"module":"u","version":"1","settings":{"mine":{"type":"string","newer":1}}}`, nil,
[]string{"word:settings.newer"}, []string{"word:settings.mine.newer"}},
{"every word known", `{"module":"u","version":"1","build":{"artifacts":[{"name":"p","language":"go"}]}}`, nil,
[]string{"word:module"}, []string{"word:build.artifacts.race", "word:race"}},
{"a template naming a seat's reach", `{"module":"z","version":"1","resources":[{"id":"f","type":"file","template":"files/d.json"}]}`,
map[string]string{"files/d.json": `{"x":"${seat:container-image-registry:reach}"}`},
[]string{"form:seat-reach"}, nil},