The indexer's take-in sets an unknown manifest word aside at any depth and says it (H-A-808, H-A-809) #372
@@ -144,8 +144,8 @@ 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",
|
||||
// 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),
|
||||
// A known word in a shape this SDK does not read; a word it does not know is set aside, at any depth (below).
|
||||
"a field of another shape": strings.Replace(catalogueManifest(t, "avahi"), `"binary": "avahi-tools",`, `"binary": ["avahi-tools"],`, 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: ") {
|
||||
@@ -160,9 +160,18 @@ func TestAManifestTheParserRefusesLeavesNoInputsAndSaysWhy(t *testing.T) { // 14
|
||||
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)
|
||||
// 1984/AC-808a (H-A-808): so is a word inside a known one, as at the top, with the same fingerprint inputs (as `race` in
|
||||
// a Go artifact, which H2b adds; the word here is one no SDK knows).
|
||||
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
|
||||
// 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 {
|
||||
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") {
|
||||
t.Fatal("the fixture has no artifact named tools")
|
||||
t.Fatal("the fixture has no artifact whose binary is avahi-tools")
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
@@ -369,6 +369,7 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
|
||||
}
|
||||
}
|
||||
finals[key] = final
|
||||
ix.saySetAside(k.manifest, r.fp, k.held.Fp2)
|
||||
continue
|
||||
}
|
||||
if !stale[key] && k.cur.Fp2 == r.fp && k.cur.None2 == r.none && sameUsed(k.cur, r.tcs, r.pkgs) {
|
||||
@@ -398,6 +399,7 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
|
||||
}
|
||||
if wrote {
|
||||
w.wrote(key)
|
||||
ix.saySetAside(k.manifest, r.fp, k.held.Fp2)
|
||||
}
|
||||
}
|
||||
if err := ix.writeOverlay(ctx, overlay, finals, w); err != nil {
|
||||
@@ -409,6 +411,17 @@ func (ix *Indexer) recomputeLocked(ctx context.Context, overlay map[string]meshc
|
||||
return nil // only a take-in keeps a catalog revision (design 47 H §743, H-A-49)
|
||||
}
|
||||
|
||||
// saySetAside says, in one journal line, each word the take-in's read set aside of a module's manifest, with its path
|
||||
// (SetAside), once per module and fingerprint: when a pass gives the module a fingerprint other than the one the bucket
|
||||
// held (design 47 H2 H-A-809). It is not a finding: a word set aside is the normal state while a newer manifest form
|
||||
// reaches an older indexer, and it ends when the indexer that reads the word runs.
|
||||
func (ix *Indexer) saySetAside(m catalogue.Manifest, fp, held string) {
|
||||
if fp == "" || fp == held || m.SetAside() == "" {
|
||||
return
|
||||
}
|
||||
ix.logf("%s: its fingerprint %s is taken from the words of its manifest this indexer knows; set aside: %s", m.Module, fp, m.SetAside())
|
||||
}
|
||||
|
||||
// writeOverlay writes the records of a merge, each once and only if it differs from what the bucket holds; finals has
|
||||
// the ones that were computed, the others are written as the merge gave them.
|
||||
//
|
||||
|
||||
@@ -685,22 +685,53 @@ func TestModulesThatStandOnEachOtherAreNamedAsACycle(t *testing.T) { // 1444 (th
|
||||
}
|
||||
}
|
||||
|
||||
// 1984/AC-809 (H-A-809): a manifest with a word set aside inside a known one says one journal line naming the module, its
|
||||
// fingerprint and the word with its path, once per module and fingerprint: none at a second take-in of the same
|
||||
// fingerprint, and none for a manifest with nothing set aside.
|
||||
func TestAMergeWritesEachModuleOnceWithItsFinalValueAndAReplayWritesNothing(t *testing.T) { // 1444 (review finding 8)
|
||||
ctx := context.Background()
|
||||
ix, mods, f := newFormIndexerUnmerged(t, mod{"avahi", catalogueManifest(t, "avahi")})
|
||||
reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1") // agreed before the merge is heard
|
||||
if err := ix.Apply(ctx, f); err != nil {
|
||||
t.Fatal(err)
|
||||
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")
|
||||
}
|
||||
m, _ := moduleOf(t, mods, "avahi")
|
||||
if mods.writes != 1 || m.Fp2 == "" {
|
||||
t.Errorf("writes = %d fp2 = %q after one merge, want one write with its fingerprint", mods.writes, m.Fp2)
|
||||
}
|
||||
if err := ix.Apply(ctx, f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mods.writes != 1 {
|
||||
t.Errorf("writes = %d after the same merge again, want still 1", mods.writes)
|
||||
for _, row := range []struct {
|
||||
name, manifest, aside string // aside: the path the take-in says it set aside, "" for none
|
||||
}{
|
||||
{"every word known", catalogueManifest(t, "avahi"), ""},
|
||||
{"a word set aside inside a Go artifact", raced, "build.artifacts[0].zzz-unknown-word"},
|
||||
} {
|
||||
ctx := context.Background()
|
||||
ix, mods, f := newFormIndexerUnmerged(t, mod{"avahi", row.manifest})
|
||||
var aside []string // the journal lines saying what was set aside
|
||||
ix.Logf = func(format string, args ...any) {
|
||||
if line := fmt.Sprintf(format, args...); strings.Contains(line, "set aside") {
|
||||
aside = append(aside, line)
|
||||
}
|
||||
}
|
||||
reportToolchain(t, ix, "mesh-build-go", "novox", "go", "go1.27.1") // agreed before the merge is heard
|
||||
if err := ix.Apply(ctx, f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
m, _ := moduleOf(t, mods, "avahi")
|
||||
if mods.writes != 1 || m.Fp2 == "" {
|
||||
t.Errorf("%s: writes = %d fp2 = %q after one merge, want one write with its fingerprint", row.name, mods.writes, m.Fp2)
|
||||
}
|
||||
switch {
|
||||
case row.aside == "" && len(aside) > 0:
|
||||
t.Errorf("%s: said %q, want nothing set aside", row.name, aside)
|
||||
case row.aside != "" && (len(aside) != 1 || !strings.HasPrefix(aside[0], "avahi: ") || !strings.Contains(aside[0], m.Fp2) ||
|
||||
!strings.Contains(aside[0], row.aside)):
|
||||
t.Errorf("%s: said %q, want one line naming avahi, its fingerprint %s and %s", row.name, aside, m.Fp2, row.aside)
|
||||
}
|
||||
said := len(aside)
|
||||
if err := ix.Apply(ctx, f); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mods.writes != 1 {
|
||||
t.Errorf("%s: writes = %d after the same merge again, want still 1", row.name, mods.writes)
|
||||
}
|
||||
if len(aside) != said {
|
||||
t.Errorf("%s: the second take-in of the same fingerprint said %q", row.name, aside[said:])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2570,6 +2570,14 @@ func UnknownFields(raw []byte) []string {
|
||||
}
|
||||
|
||||
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
|
||||
// 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
|
||||
@@ -2581,7 +2589,7 @@ func parseManifest(raw []byte, predefined catalogue.PredefinedList) (catalogue.M
|
||||
decoder := json.NewDecoder(bytes.NewReader(raw))
|
||||
decoder.DisallowUnknownFields()
|
||||
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.
|
||||
err = errors.New(m.SetAside())
|
||||
}
|
||||
@@ -4001,9 +4009,10 @@ 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, 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
|
||||
// builder's read (novox/hq issue 1751). It is never a judge of config values, and never of words: a word the SDK's
|
||||
// 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
|
||||
// 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
|
||||
// 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);
|
||||
@@ -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
|
||||
// ParseManifest refuses is refused here too.
|
||||
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
|
||||
// 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)
|
||||
}
|
||||
return parseManifest(raw, list)
|
||||
return parseManifest(raw, fallbackList(raw))
|
||||
}
|
||||
|
||||
// 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
|
||||
// fallbackList is the list of predefined keys the mesh published, or, where this process holds none, each key a value of
|
||||
// raw falls back to as the value declares it (fallbacksOf).
|
||||
func fallbackList(raw []byte) catalogue.PredefinedList {
|
||||
if list := catalogue.PublishedPredefined(); list != nil {
|
||||
return list
|
||||
}
|
||||
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() == ""
|
||||
return fallbacksOf(raw)
|
||||
}
|
||||
|
||||
// fallbacksOf is the list of the predefined keys a manifest's config values fall back to, each as the value declares
|
||||
|
||||
@@ -3090,9 +3090,32 @@ func caseAStoredManifestWithAnUnknownKeyIsSetAsideAndTheJudgeRefusesIt(t *testin
|
||||
if where != "the top" && !strings.Contains(m.UnknownField(), ": json: unknown field") {
|
||||
t.Errorf("%s: the block's decoder did not say it: %q", where, m.UnknownField())
|
||||
}
|
||||
// 1984/AC-808b at every depth: the judgement's read still refuses it.
|
||||
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)
|
||||
}
|
||||
// 1984/AC-808a (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)
|
||||
}
|
||||
}
|
||||
// 1984/AC-808a: a word inside a Go artifact (as H-A-808's `race`; the word here is one no SDK knows) is 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)
|
||||
}
|
||||
// 1984/AC-808b: the judgement's read still refuses it.
|
||||
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
|
||||
if err := json.Unmarshal([]byte(`{"module": "now", "state": [{"name": "s"}]}`), &known); err != nil || known.UnknownField() != "" {
|
||||
|
||||
Reference in New Issue
Block a user