diff --git a/go/buildstep/trees.go b/go/buildstep/trees.go index fc31c62..27d35ed 100644 --- a/go/buildstep/trees.go +++ b/go/buildstep/trees.go @@ -76,10 +76,10 @@ func ModuleTrees(ctx context.Context, run forgekey.Runner, env []string, dir, co // narrow sets mt's Paths and its named Tree when the module's manifest names paths on every artifact (novox/hq ADR 0499 // clause 2): one `git ls-tree -z` gives each named path's object at commit. The merge preview reads the manifest here, as -// the indexer does, and no other build step reads paths from one (ADR 0495 clause 1). A manifest that does not parse +// the indexer does, with catalogue.ParseManifestForInputs (issue 1751), and no other build step reads paths from one (ADR 0495 clause 1). A manifest that does not parse // is not narrowed: the indexer gives it none. A named path absent at commit fails, naming the module and the path. func narrow(ctx context.Context, run forgekey.Runner, env []string, dir, commit, mdir string, raw []byte, mt *ModuleTree) error { - m, err := catalogue.ParseManifest(raw) + m, err := catalogue.ParseManifestForInputs(raw) if err != nil { return nil } diff --git a/go/buildstep/trees_named_test.go b/go/buildstep/trees_named_test.go index 914f9d2..3fdf0ea 100644 --- a/go/buildstep/trees_named_test.go +++ b/go/buildstep/trees_named_test.go @@ -5,6 +5,7 @@ import ( "strings" "testing" + "git.novox.be/novox/mesh-sdk/go/catalogue" "git.novox.be/novox/mesh-sdk/go/delivery" "git.novox.be/novox/mesh-sdk/go/forgekey" ) @@ -73,3 +74,40 @@ func TestModuleTreesFailsNamingANamedPathAbsentAtTheCommit(t *testing.T) { t.Fatalf("an absent named path gave %v", err) } } + +// A manifest whose config value falls back to a predefined key is narrowed here as the indexer narrows it: both read it +// with catalogue.ParseManifestForInputs (issue 1751), so a build module holding no published list computes the same +// tree (ADR 0499 clause 2). +func TestModuleTreesNarrowsAManifestFallingBackToAPredefinedKey(t *testing.T) { + was := catalogue.ReplacePublished(nil) // the build modules' case: no published list + defer catalogue.ReplacePublished(was) + root := t.TempDir() + raw := `{"module":"xterm","version":"1","config":{"size":{"type":"number","description":"The text size.","predefined":"font-size","default":12,"runtime":true}},` + + `"build":{"artifacts":[{"name":"lib","kind":"package","language":"typescript","paths":["src"]}]}}` + if _, err := catalogue.ParseManifest([]byte(raw)); err == nil { + t.Fatal("ParseManifest reads the manifest with no list; the test proves nothing") + } + if _, err := catalogue.ParseManifestForInputs([]byte(raw)); err != nil { + t.Fatalf("the indexer's read refuses the manifest: %v", err) + } + writeTreeFile(t, root, "module.json", raw) + run := func(ctx context.Context, env []string, name string, args ...string) forgekey.Ran { + switch args[2] { + case "ls-files": + return forgekey.Ran{Stdout: "module.json\n"} + case "rev-parse": + return forgekey.Ran{Stdout: "whole\n"} + case "ls-tree": + return forgekey.Ran{Stdout: "040000 tree " + strings.Repeat("a", 40) + "\tsrc\x00"} + } + return forgekey.Ran{Status: 1} + } + got, err := ModuleTrees(context.Background(), run, nil, root, strings.Repeat("c", 40)) + if err != nil { + t.Fatal(err) + } + want, _ := delivery.NamedTree(hexOf(raw), map[string]string{"src": strings.Repeat("a", 40)}) + if g := got["."]; g.Tree != want || g.Paths["src"] == "" { + t.Fatalf("the module = %+v, want the named tree %s", g, want) + } +}