package main import ( "bytes" "os" "path/filepath" "strings" "testing" "github.com/novox/mesh-controller/internal/catalogue" ) // ADR 0326 ยง3 is judged where a definition is written (novox/hq issue 574): `module check`, and // namesNoInstallation, which `module add`, a build taken in and the merge gate's registration run. func TestWhereADefinitionIsWrittenADeclaringModuleNamesItsFilesKeys(t *testing.T) { const silent = `{"module":"mail-client","version":"1", "settings":{"prefs":{"kind":"preference","default":"// none","why":"its own defaults until a machine names one"}}, "resources":[ {"id":"user-js","type":"file","path":"/var/lib/mail-client/user.js","mode":"0644","content":"${setting:prefs}\n"}, {"id":"accounts","type":"file","path":"/var/lib/mail-client/accounts.json","mode":"0600","merge":"json", "content":"{}\n"%s}]}` dir := t.TempDir() bad := filepath.Join(dir, "bad.json") good := filepath.Join(dir, "good.json") os.WriteFile(bad, []byte(strings.Replace(silent, "%s", "", 1)), 0o600) os.WriteFile(good, []byte(strings.Replace(silent, "%s", `,"takes-settings":["accounts"]`, 1)), 0o600) var out bytes.Buffer if err := moduleCheck([]string{bad}, &out); err == nil || !strings.Contains(out.String(), "mergeable accounts names no takes-settings") { t.Fatalf("module check passed a declaring module's silent mergeable file: %v\n%s", err, out.String()) } out.Reset() if err := moduleCheck([]string{good}, &out); err != nil { t.Fatalf("the file naming its keys was refused: %v\n%s", err, out.String()) } raw, _ := os.ReadFile(bad) m, err := catalogue.ParseManifest(raw) if err != nil { t.Fatalf("reading it is not where it is judged: %v", err) } if err := namesNoInstallation(m); err == nil || !strings.Contains(err.Error(), "names no takes-settings") { t.Fatalf("registration passed it: %v", err) } }