Verify main-relative loading and evidence

This commit is contained in:
2026-11-09 20:44:32 +00:00
parent 08ea01921b
commit bc3fc91296
4 changed files with 210 additions and 0 deletions

View File

@@ -44,3 +44,43 @@ func TestMainRelativeStrictPeers(t *testing.T) {
}
t.Fatalf("diagnostics = %#v", err.(*configkit.LoadError).Diagnostics())
}
func TestMainRelativeOptionalResources(t *testing.T) {
for _, tc := range []struct {
name string
file, directory, empty bool
count int
}{
{"neither", false, false, false, 2}, {"file", true, false, false, 3},
{"directory", false, true, false, 3}, {"both", true, true, false, 4}, {"empty directory", false, false, true, 2},
} {
t.Run(tc.name, func(t *testing.T) {
root := t.TempDir()
if err := os.WriteFile(filepath.Join(root, "main.yml"), []byte("mode: main\n"), 0600); err != nil {
t.Fatal(err)
}
if tc.file {
if err := os.WriteFile(filepath.Join(root, "prompts.yml"), []byte("id: file\ntext: file\n"), 0600); err != nil {
t.Fatal(err)
}
}
if tc.directory || tc.empty {
if err := os.Mkdir(filepath.Join(root, "operator"), 0700); err != nil {
t.Fatal(err)
}
}
if tc.directory {
if err := os.WriteFile(filepath.Join(root, "operator", "item.yaml"), []byte("id: directory\ntext: directory\n"), 0600); err != nil {
t.Fatal(err)
}
}
result, err := consumers.LoadCompanionConfig(filepath.Join(root, "main.yml"), "")
if err != nil {
t.Fatalf("%v: %#v", err, err.(*configkit.LoadError).Diagnostics())
}
if len(result.Config.Prompts) != tc.count {
t.Fatalf("prompts = %#v", result.Config.Prompts)
}
})
}
}