The take-in sets an unknown manifest word aside at any depth and names it (H-A-808)
The indexer's take-in read set aside only an unknown top-level word and refused one inside a known word, so a manifest carrying a new nested word (H2b's tool-files in a process, race in a Go artifact) would get no fingerprint and nothing of its revision would deliver. The kind is fixed whole: ParseManifestForInputs now reads with the SDK's own decoder, which sets an unknown word aside at any depth and names it (SetAside), and holds the words it knows to every other rule, so the top-level case of H-A-465 is now named too. A manifest the decoder cannot read past is still refused, and the judgement's read (ParseManifest, Manifest) stays strict. Issue 1984. Builds: design 47 H2 H-A-808
This commit is contained in:
@@ -144,8 +144,8 @@ func TestAnArtifactOfNoToolchainHasNoLanguageAndNoLock(t *testing.T) { // 1450/A
|
|||||||
func TestAManifestTheParserRefusesLeavesNoInputsAndSaysWhy(t *testing.T) { // 1450/AC5
|
func TestAManifestTheParserRefusesLeavesNoInputsAndSaysWhy(t *testing.T) { // 1450/AC5
|
||||||
for name, raw := range map[string]string{
|
for name, raw := range map[string]string{
|
||||||
"not json": "not json",
|
"not json": "not json",
|
||||||
// A word inside a known one is still refused; a top-level word is set aside (below).
|
// A known word in a shape this SDK does not read; a word it does not know is set aside, at any depth (below).
|
||||||
"unknown field": strings.Replace(catalogueManifest(t, "avahi"), `"name": "tools",`, `"name": "tools", "a-field-from-later": "everything",`, 1),
|
"a field of another shape": strings.Replace(catalogueManifest(t, "avahi"), `"binary": "avahi-tools",`, `"binary": ["avahi-tools"],`, 1),
|
||||||
} {
|
} {
|
||||||
in := inputsOf("avahi", raw, "t", nil, noBases)
|
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: ") {
|
if in.Kept != nil || !strings.HasPrefix(in.None2, "the manifest cannot be read: ") || len(in.None2) <= len("the manifest cannot be read: ") {
|
||||||
@@ -160,9 +160,18 @@ func TestAManifestTheParserRefusesLeavesNoInputsAndSaysWhy(t *testing.T) { // 14
|
|||||||
without := inputsOf("avahi", catalogueManifest(t, "avahi"), "t", map[string]string{"go.sum": avahiGoSum}, noBases)
|
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),
|
with := inputsOf("avahi", strings.Replace(catalogueManifest(t, "avahi"), `"version": "1",`, `"version": "1", "class": "core",`, 1),
|
||||||
"t", map[string]string{"go.sum": avahiGoSum}, noBases)
|
"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 ||
|
// H-A-808: so is a word inside a known one, as at the top (as `race` in a Go artifact, which H2b adds; the word here is
|
||||||
!reflect.DeepEqual(with.Languages, without.Languages) || !reflect.DeepEqual(with.ArtifactPaths, without.ArtifactPaths) {
|
// one no SDK knows).
|
||||||
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)
|
raced := strings.Replace(catalogueManifest(t, "avahi"), `"name": "tools",`, `"name": "tools", "zzz-unknown-word": true,`, 1)
|
||||||
|
if raced == catalogueManifest(t, "avahi") {
|
||||||
|
t.Fatal("the fixture has no artifact named tools")
|
||||||
|
}
|
||||||
|
nested := inputsOf("avahi", raced, "t", map[string]string{"go.sum": avahiGoSum}, noBases)
|
||||||
|
for word, with := range map[string]moduleInputs{"top-level": with, "nested": nested} {
|
||||||
|
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 %s word: %+v (kept %+v), want the inputs without it %+v (kept %+v)", word, with, with.Kept, without, without.Kept)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// unreadableAvahi is avahi's manifest with a field the running parser refuses: the shape of a manifest an older SDK could
|
// unreadableAvahi is avahi's manifest with a field the running parser refuses: the shape of a manifest an older SDK could
|
||||||
// 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).
|
// not read. It is a known word in a shape the SDK does not read, since a word the take-in does not know is set aside, at
|
||||||
|
// any depth (H-A-465, H-A-808).
|
||||||
func unreadableAvahi(t *testing.T) string {
|
func unreadableAvahi(t *testing.T) string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
raw := strings.Replace(catalogueManifest(t, "avahi"), `"name": "tools",`, `"name": "tools", "a-field-from-later": "everything",`, 1)
|
raw := strings.Replace(catalogueManifest(t, "avahi"), `"binary": "avahi-tools",`, `"binary": ["avahi-tools"],`, 1)
|
||||||
if raw == catalogueManifest(t, "avahi") {
|
if raw == catalogueManifest(t, "avahi") {
|
||||||
t.Fatal("the fixture has no artifact named tools")
|
t.Fatal("the fixture has no artifact whose binary is avahi-tools")
|
||||||
}
|
}
|
||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2570,6 +2570,14 @@ func UnknownFields(raw []byte) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseManifest(raw []byte, predefined catalogue.PredefinedList) (catalogue.Manifest, error) {
|
func parseManifest(raw []byte, predefined catalogue.PredefinedList) (catalogue.Manifest, error) {
|
||||||
|
return parseManifestSettingAside(raw, predefined, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseManifestSettingAside is parseManifest, but where setAside says so (the take-in's read, ParseManifestForInputs):
|
||||||
|
// a word the SDK's manifest does not know, at any depth, is then set aside and named (SetAside), as the SDK's decoder
|
||||||
|
// sets it aside (design 47 H2 H-A-808), and every other rule is applied to the words it knows. A manifest the decoder
|
||||||
|
// could not read past (ReadNoFurther) holds its name and version alone, and is refused all the same.
|
||||||
|
func parseManifestSettingAside(raw []byte, predefined catalogue.PredefinedList, setAside bool) (catalogue.Manifest, error) {
|
||||||
var m catalogue.Manifest
|
var m catalogue.Manifest
|
||||||
// Strictly. **An unknown key is refused**, which is the discipline the host's declaration
|
// Strictly. **An unknown key is refused**, which is the discipline the host's declaration
|
||||||
// parser has and manifests lacked (novox/hq 04-ISSUES/003): a `scope:` key survived in five
|
// parser has and manifests lacked (novox/hq 04-ISSUES/003): a `scope:` key survived in five
|
||||||
@@ -2581,7 +2589,7 @@ func parseManifest(raw []byte, predefined catalogue.PredefinedList) (catalogue.M
|
|||||||
decoder := json.NewDecoder(bytes.NewReader(raw))
|
decoder := json.NewDecoder(bytes.NewReader(raw))
|
||||||
decoder.DisallowUnknownFields()
|
decoder.DisallowUnknownFields()
|
||||||
err := decoder.Decode(&m)
|
err := decoder.Decode(&m)
|
||||||
if err == nil && m.SetAside() != "" {
|
if err == nil && m.SetAside() != "" && (!setAside || m.ReadNoFurther()) {
|
||||||
// Kept aside by UnmarshalJSON for the stored catalogue's sake; registration refuses it.
|
// Kept aside by UnmarshalJSON for the stored catalogue's sake; registration refuses it.
|
||||||
err = errors.New(m.SetAside())
|
err = errors.New(m.SetAside())
|
||||||
}
|
}
|
||||||
@@ -4001,9 +4009,10 @@ var protectedRoots = []string{"/", "/bin", "/boot", "/dev", "/etc", "/home", "/l
|
|||||||
"/var/spool"}
|
"/var/spool"}
|
||||||
|
|
||||||
// ParseManifestForInputs reads a manifest for the inputs of its build and its fingerprint: the indexer's and the
|
// 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, and never of words: a top-level word the
|
// builder's read (novox/hq issue 1751). It is never a judge of config values, and never of words: a word the SDK's
|
||||||
// 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
|
// manifest does not know, at the top or inside a known one (a word a newer SDK adds, such as `class`, or `race` in a Go
|
||||||
// aside, and the inputs are taken from the words it knows (design 47 H, H-A-465), so a revision carrying a new word
|
// artifact), is set aside and named in the manifest it gives (SetAside), as the SDK's decoder sets it aside and names it,
|
||||||
|
// and the inputs are taken from the words it knows (design 47 H, H-A-465, H2 H-A-808), so a revision carrying a new word
|
||||||
// still gets its fingerprint from the running indexer. The judgement's read (Manifest, ParseManifest) stays strict: the
|
// 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
|
// 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);
|
// (ADR 0348 §7) is judged against the list the mesh published when this process holds one (PublishedPredefined);
|
||||||
@@ -4012,72 +4021,22 @@ var protectedRoots = []string{"/", "/bin", "/boot", "/dev", "/etc", "/home", "/l
|
|||||||
// the controller from what it published. No input of a fingerprint or a build comes from the list. Everything else
|
// 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.
|
// ParseManifest refuses is refused here too.
|
||||||
func ParseManifestForInputs(raw []byte) (catalogue.Manifest, error) {
|
func ParseManifestForInputs(raw []byte) (catalogue.Manifest, error) {
|
||||||
return parseManifestFallingBack(withoutUnknownWords(raw))
|
return parseManifestSettingAside(raw, fallbackList(raw), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseManifestFallingBack is the strict read judging each predefined key a value falls back to against the list the
|
// 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).
|
// mesh published, or, where this process holds none, as the value declares it (fallbacksOf).
|
||||||
func parseManifestFallingBack(raw []byte) (catalogue.Manifest, error) {
|
func parseManifestFallingBack(raw []byte) (catalogue.Manifest, error) {
|
||||||
list := catalogue.PublishedPredefined()
|
return parseManifest(raw, fallbackList(raw))
|
||||||
if list == nil {
|
|
||||||
list = fallbacksOf(raw)
|
|
||||||
}
|
|
||||||
return parseManifest(raw, list)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// withoutUnknownWords is raw without each top-level word the SDK's manifest does not know, the others in their order
|
// fallbackList is the list of predefined keys the mesh published, or, where this process holds none, each key a value of
|
||||||
// and their values as written; raw itself when it knows every word or is no JSON object (the strict read then says
|
// raw falls back to as the value declares it (fallbacksOf).
|
||||||
// what is wrong with it). A word inside a known one is not set aside here: the strict read refuses it.
|
func fallbackList(raw []byte) catalogue.PredefinedList {
|
||||||
func withoutUnknownWords(raw []byte) []byte {
|
if list := catalogue.PublishedPredefined(); list != nil {
|
||||||
decoder := json.NewDecoder(bytes.NewReader(raw))
|
return list
|
||||||
if t, err := decoder.Token(); err != nil || t != json.Delim('{') {
|
|
||||||
return raw
|
|
||||||
}
|
}
|
||||||
var out bytes.Buffer
|
return fallbacksOf(raw)
|
||||||
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
|
// fallbacksOf is the list of the predefined keys a manifest's config values fall back to, each as the value declares
|
||||||
|
|||||||
@@ -3093,6 +3093,26 @@ func caseAStoredManifestWithAnUnknownKeyIsSetAsideAndTheJudgeRefusesIt(t *testin
|
|||||||
if _, err := ParseManifest([]byte(raw)); err == nil || !strings.Contains(err.Error(), "a-field-from-later") {
|
if _, err := ParseManifest([]byte(raw)); err == nil || !strings.Contains(err.Error(), "a-field-from-later") {
|
||||||
t.Errorf("%s: the module check took it: %v", where, err)
|
t.Errorf("%s: the module check took it: %v", where, err)
|
||||||
}
|
}
|
||||||
|
// H-A-808: the take-in's read sets it aside and names it at any depth, as at the top, so the revision still gets
|
||||||
|
// its fingerprint from the words it knows; a rule the rest breaks (the backup's) still refuses, never the word.
|
||||||
|
if m, err := ParseManifestForInputs([]byte(raw)); err != nil && strings.Contains(err.Error(), "a-field-from-later") ||
|
||||||
|
err == nil && (m.Module != "later" || !strings.Contains(m.SetAside(), `"a-field-from-later"`)) {
|
||||||
|
t.Errorf("%s: the take-in's read gave %q, set aside %q: %v", where, m.Module, m.SetAside(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// A word inside a Go artifact (as H-A-808's `race`; the word here is one no SDK knows): set aside and named, and the
|
||||||
|
// artifact read as without it.
|
||||||
|
artifact := `{"name":"t","kind":"bundle","language":"go","system":"arch","from":"cmd/t","binary":"t","loads":["t"]}`
|
||||||
|
withWord := `{"module":"later","version":"2","build":{"artifacts":[` +
|
||||||
|
strings.Replace(artifact, `"binary":"t"`, `"binary":"t","zzz-unknown-word":true`, 1) + `]}}`
|
||||||
|
got, err := ParseManifestForInputs([]byte(withWord))
|
||||||
|
without, werr := ParseManifestForInputs([]byte(`{"module":"later","version":"2","build":{"artifacts":[` + artifact + `]}}`))
|
||||||
|
if err != nil || werr != nil || !strings.Contains(got.SetAside(), "build.artifacts[0].zzz-unknown-word") ||
|
||||||
|
without.SetAside() != "" || !reflect.DeepEqual(got.Build, without.Build) {
|
||||||
|
t.Errorf("a word inside a Go artifact: %v %v, set aside %q, build %+v, want %+v", err, werr, got.SetAside(), got.Build, without.Build)
|
||||||
|
}
|
||||||
|
if _, err := ParseManifest([]byte(withWord)); err == nil || !strings.Contains(err.Error(), "zzz-unknown-word") {
|
||||||
|
t.Errorf("the judgement took a word inside a Go artifact: %v", err)
|
||||||
}
|
}
|
||||||
var known catalogue.Manifest
|
var known catalogue.Manifest
|
||||||
if err := json.Unmarshal([]byte(`{"module": "now", "state": [{"name": "s"}]}`), &known); err != nil || known.UnknownField() != "" {
|
if err := json.Unmarshal([]byte(`{"module": "now", "state": [{"name": "s"}]}`), &known); err != nil || known.UnknownField() != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user