Merge pull request 'Indexer: the take-in's manifest read sets an unknown top-level word aside (H-A-465)' (#323) from fix/takein-unknown-word into main

This commit was merged in pull request #323.
This commit is contained in:
2026-11-22 03:15:38 +00:00
5 changed files with 85 additions and 7 deletions
@@ -143,8 +143,9 @@ func TestAnArtifactOfNoToolchainHasNoLanguageAndNoLock(t *testing.T) { // 1450/A
func TestAManifestTheParserRefusesLeavesNoInputsAndSaysWhy(t *testing.T) { // 1450/AC5
for name, raw := range map[string]string{
"not json": "not json",
"unknown field": strings.Replace(catalogueManifest(t, "avahi"), `"version": "1",`, `"version": "1", "scope": "everything",`, 1),
"not json": "not json",
// A word inside a known one is still refused; a top-level word is set aside (below).
"unknown field": strings.Replace(catalogueManifest(t, "avahi"), `"name": "tools",`, `"name": "tools", "a-field-from-later": "everything",`, 1),
} {
in := inputsOf("avahi", raw, "t", nil, noBases)
if in.Kept != nil || !strings.HasPrefix(in.None2, "the manifest cannot be read: ") || len(in.None2) <= len("the manifest cannot be read: ") {
@@ -154,6 +155,15 @@ func TestAManifestTheParserRefusesLeavesNoInputsAndSaysWhy(t *testing.T) { // 14
if in := inputsOf("someone-else", catalogueManifest(t, "avahi"), "t", nil, noBases); in.Kept != nil || !strings.Contains(in.None2, "avahi") {
t.Errorf("a manifest of another module: kept %+v none2 %q", in.Kept, in.None2)
}
// H-A-465: a top-level word the running indexer's SDK does not know yet (`class`, which a newer SDK adds) is set
// aside, and the inputs are those of the same manifest without it.
without := inputsOf("avahi", catalogueManifest(t, "avahi"), "t", map[string]string{"go.sum": avahiGoSum}, noBases)
with := inputsOf("avahi", strings.Replace(catalogueManifest(t, "avahi"), `"version": "1",`, `"version": "1", "class": "core",`, 1),
"t", map[string]string{"go.sum": avahiGoSum}, noBases)
if with.Kept == nil || without.Kept == nil || !reflect.DeepEqual(*with.Kept, *without.Kept) || with.None2 != without.None2 ||
!reflect.DeepEqual(with.Languages, without.Languages) || !reflect.DeepEqual(with.ArtifactPaths, without.ArtifactPaths) {
t.Errorf("with an unknown top-level word: %+v (kept %+v), want the inputs without it %+v (kept %+v)", with, with.Kept, without, without.Kept)
}
}
func TestAContextIsNotPinned(t *testing.T) { // 1450 (the rule 1444 keeps: context not pinned, as today's form)
@@ -7,12 +7,12 @@ import (
)
// unreadableAvahi is avahi's manifest with a field the running parser refuses: the shape of a manifest an older SDK could
// not read.
// not read. The field is inside an artifact, since a top-level word the take-in does not know is set aside (H-A-465).
func unreadableAvahi(t *testing.T) string {
t.Helper()
raw := strings.Replace(catalogueManifest(t, "avahi"), `"version": "1",`, `"version": "1", "scope": "everything",`, 1)
raw := strings.Replace(catalogueManifest(t, "avahi"), `"name": "tools",`, `"name": "tools", "a-field-from-later": "everything",`, 1)
if raw == catalogueManifest(t, "avahi") {
t.Fatal("the fixture has no version line")
t.Fatal("the fixture has no artifact named tools")
}
return raw
}
+1 -1
View File
@@ -40,7 +40,7 @@ func Manifest(raw []byte, predefined catalogue.PredefinedList) (m catalogue.Mani
if predefined != nil {
m, err = ParseManifestWith(raw, predefined)
} else {
m, err = ParseManifestForInputs(raw)
m, err = parseManifestFallingBack(raw)
}
if err != nil {
return catalogue.Manifest{}, problemsOf(err)
@@ -27,6 +27,9 @@ func TestTheJudge(t *testing.T) {
want: map[string]string{"a": `secret-`}},
{name: "an unknown field", raws: map[string]string{"a": `{"module":"a","version":"1.0","a-field-from-later":1}`},
want: map[string]string{"a": `"a-field-from-later"`}},
// H-A-465: the take-in sets a top-level word it does not know aside (ForInputs); the judgement still refuses it.
{name: "a word a newer SDK adds", raws: map[string]string{"a": `{"module":"a","version":"1.0","class":"core"}`},
want: map[string]string{"a": `"class"`}},
// Design 47 G §23, §28: a step's status is kept in the registration and never in a manifest.
{name: "a manifest naming a step's status", raws: map[string]string{"a": `{"module":"a","version":"1.0","policy":{"lint":"bypass"}}`},
want: map[string]string{"a": `"policy"`}},
+66 -1
View File
@@ -3995,13 +3995,23 @@ var protectedRoots = []string{"/", "/bin", "/boot", "/dev", "/etc", "/home", "/l
"/var/spool"}
// ParseManifestForInputs reads a manifest for the inputs of its build and its fingerprint: the indexer's and the
// builder's read (novox/hq issue 1751). It is never a judge of config values. A value falling back to a predefined key
// builder's read (novox/hq issue 1751). It is never a judge of config values, and never of words: a top-level word the
// SDK's manifest does not know (a word a newer SDK adds, such as `class`) is set aside, as the SDK's decoder sets it
// aside, and the inputs are taken from the words it knows (design 47 H, H-A-465), so a revision carrying a new word
// still gets its fingerprint from the running indexer. The judgement's read (Manifest, ParseManifest) stays strict: the
// validator built from the revision's own indexer refuses what it does not know. A value falling back to a predefined key
// (ADR 0348 §7) is judged against the list the mesh published when this process holds one (PublishedPredefined);
// where it holds none, as in the indexer and the builder, each key a value names is taken as the value declares it (its
// type, trusted when it is), since the list is read where a manifest is judged: the merge gate from the tree's root,
// the controller from what it published. No input of a fingerprint or a build comes from the list. Everything else
// ParseManifest refuses is refused here too.
func ParseManifestForInputs(raw []byte) (catalogue.Manifest, error) {
return parseManifestFallingBack(withoutUnknownWords(raw))
}
// parseManifestFallingBack is the strict read judging each predefined key a value falls back to against the list the
// mesh published, or, where this process holds none, as the value declares it (fallbacksOf).
func parseManifestFallingBack(raw []byte) (catalogue.Manifest, error) {
list := catalogue.PublishedPredefined()
if list == nil {
list = fallbacksOf(raw)
@@ -4009,6 +4019,61 @@ func ParseManifestForInputs(raw []byte) (catalogue.Manifest, error) {
return parseManifest(raw, list)
}
// withoutUnknownWords is raw without each top-level word the SDK's manifest does not know, the others in their order
// and their values as written; raw itself when it knows every word or is no JSON object (the strict read then says
// what is wrong with it). A word inside a known one is not set aside here: the strict read refuses it.
func withoutUnknownWords(raw []byte) []byte {
decoder := json.NewDecoder(bytes.NewReader(raw))
if t, err := decoder.Token(); err != nil || t != json.Delim('{') {
return raw
}
var out bytes.Buffer
out.WriteByte('{')
kept, setAside := 0, false
for decoder.More() {
t, err := decoder.Token()
if err != nil {
return raw
}
word, _ := t.(string)
var value json.RawMessage
if err := decoder.Decode(&value); err != nil {
return raw
}
if !knownWord(word) {
setAside = true
continue
}
if kept > 0 {
out.WriteByte(',')
}
quoted, _ := json.Marshal(word)
out.Write(quoted)
out.WriteByte(':')
out.Write(value)
kept++
}
if !setAside {
return raw
}
out.WriteByte('}')
return out.Bytes()
}
// knownWord is whether the SDK's manifest knows a top-level word: a manifest of that word alone, valued null, is read
// with nothing set aside. A word the SDK reads by a rule of its own that refuses null is known.
func knownWord(word string) bool {
probe, err := json.Marshal(map[string]json.RawMessage{word: json.RawMessage("null")})
if err != nil {
return true
}
var m catalogue.Manifest
if err := json.Unmarshal(probe, &m); err != nil {
return true
}
return m.SetAside() == ""
}
// fallbacksOf is the list of the predefined keys a manifest's config values fall back to, each as the value declares
// it. A manifest that is not JSON gives an empty list, and the parser says what is wrong with it.
func fallbacksOf(raw []byte) catalogue.PredefinedList {