diff --git a/checks/environment/main.go b/checks/environment/main.go index e8cd65a69..2ffb4b89a 100644 --- a/checks/environment/main.go +++ b/checks/environment/main.go @@ -77,6 +77,7 @@ func Check(root string) (map[string]map[string][]string, error) { } set := map[string]bool{} setBy(manifest, set) + settingWords(manifest, set) reads := map[string]map[string]bool{} consts := map[string]map[string]string{} // directory -> constant -> word var goFiles []string @@ -180,6 +181,17 @@ func setBy(v any, set map[string]bool) { } } +// settingWords collects the words the node-engine composes for every setting the manifest's `config` declares, +// MESH_CONFIG_, the key upper-cased with '-' and '.' as '_', into the module's processes and its tool runner slice +// alike (design 47 H2 §781; H-A-370, H-A-400 (2)). +func settingWords(v any, set map[string]bool) { + m, _ := v.(map[string]any) + config, _ := m["config"].(map[string]any) + for key := range config { + set["MESH_CONFIG_"+strings.NewReplacer("-", "_", ".", "_").Replace(strings.ToUpper(key))] = true + } +} + // Listed is the list's ` ` lines; a line starting with # and a blank line are not entries. func Listed(path string) (map[string]bool, error) { f, err := os.Open(path) diff --git a/checks/environment/main_test.go b/checks/environment/main_test.go index f79842cd1..fd69078e7 100644 --- a/checks/environment/main_test.go +++ b/checks/environment/main_test.go @@ -32,13 +32,14 @@ func module(t *testing.T, root, name, manifest string, files map[string]string) // not; tests, node_modules and dist are not read. func TestAWordReadThatNothingSetsIsFound(t *testing.T) { root := t.TempDir() - module(t, root, "reader", `{"module":"reader","build":{"artifacts":[{"name":"tools","env":{"MESH_SET":"x"}}]},`+ + module(t, root, "reader", `{"module":"reader","config":{"ask-taken-bound":{"type":"string"}},"build":{"artifacts":[{"name":"tools","env":{"MESH_SET":"x"}}]},`+ `"resources":[{"id":"p","type":"process","environment":{"variables":{"MESH_VARIABLE":"y"}}}]}`, map[string]string{ - "cmd/a/main.go": `package main; const reach = "MESH_REACH"; var _ = os.Getenv(reach); var _ = os.Getenv("MESH_SET")`, - "cmd/a/other.go": `package main; var _, _ = os.LookupEnv("MESH_LITERAL"); var _ = os.Getenv("MESH_MODULE")`, - "cmd/a/write.go": `package main; var _ = []string{"MESH_WRITTEN_FOR_A_CHILD=1"}`, - "cmd/a/a_test.go": `package main; var _ = os.Getenv("MESH_IN_A_TEST")`, - "client.ts": `const a = process.env.MESH_TS ?? "d"; const b = env["MESH_BRACKET"]; const c = env.MESH_VARIABLE;`, + "cmd/a/main.go": `package main; const reach = "MESH_REACH"; var _ = os.Getenv(reach); var _ = os.Getenv("MESH_SET")`, + "cmd/a/other.go": `package main; var _, _ = os.LookupEnv("MESH_LITERAL"); var _ = os.Getenv("MESH_MODULE")`, + "cmd/a/write.go": `package main; var _ = []string{"MESH_WRITTEN_FOR_A_CHILD=1"}`, + "cmd/a/a_test.go": `package main; var _ = os.Getenv("MESH_IN_A_TEST")`, + // 47 H2 §781, H-A-370: a declared setting's word, which the node-engine composes; one undeclared is set by nothing. + "client.ts": `const a = process.env.MESH_TS ?? "d"; const b = env["MESH_BRACKET"]; const c = env.MESH_VARIABLE; const d = env.MESH_CONFIG_ASK_TAKEN_BOUND; const e = env.MESH_CONFIG_UNDECLARED;`, "files/env": "MESH_FROM_FILE=${config:x}\n", "index.ts": `const f = env.MESH_FROM_FILE;`, "test/x.test.ts": `env.MESH_IN_A_TEST_DIR`, @@ -50,16 +51,17 @@ func TestAWordReadThatNothingSetsIsFound(t *testing.T) { t.Fatal(err) } want := map[string]map[string][]string{"reader": { - "MESH_REACH": {"cmd/a/main.go"}, - "MESH_LITERAL": {"cmd/a/other.go"}, - "MESH_TS": {"client.ts"}, - "MESH_BRACKET": {"client.ts"}, + "MESH_REACH": {"cmd/a/main.go"}, + "MESH_LITERAL": {"cmd/a/other.go"}, + "MESH_TS": {"client.ts"}, + "MESH_BRACKET": {"client.ts"}, + "MESH_CONFIG_UNDECLARED": {"client.ts"}, }} if !reflect.DeepEqual(got, want) { t.Fatalf("found %v, want %v", got, want) } refused, stale := Judge(got, map[string]bool{"reader MESH_REACH": true, "reader MESH_GONE": true}) - if !reflect.DeepEqual(refused, []string{"reader MESH_BRACKET", "reader MESH_LITERAL", "reader MESH_TS"}) || + if !reflect.DeepEqual(refused, []string{"reader MESH_BRACKET", "reader MESH_CONFIG_UNDECLARED", "reader MESH_LITERAL", "reader MESH_TS"}) || !reflect.DeepEqual(stale, []string{"reader MESH_GONE"}) { t.Errorf("refused %v, stale %v", refused, stale) }