package discovery import ( "strings" "testing" ) func TestHasDefinitionFrontmatter(t *testing.T) { cases := []struct { name string in string want bool }{ {name: "no frontmatter at all", in: "# Schema docs\nplain documentation\n", want: false}, {name: "empty fence", in: "---\n---\nbody\n", want: false}, {name: "only unknown keys", in: "---\ntitle: Schema\nlayout: docs\n---\n", want: false}, {name: "name key", in: "---\nname: Scout\n---\nbody\n", want: true}, {name: "description key", in: "---\ndescription: scouts things\n---\n", want: true}, {name: "mode key", in: "---\nmode: primary\n---\n", want: true}, {name: "model key", in: "---\nmodel: sonnet\n---\n", want: true}, {name: "argument-hint key", in: "---\nargument-hint: [msg]\n---\n", want: true}, {name: "temperature key", in: "---\ntemperature: 0.2\n---\n", want: true}, {name: "permission key", in: "---\npermission: edit\n---\n", want: true}, {name: "mixed unknown and known", in: "---\ntitle: X\ndescription: real agent\n---\n", want: true}, {name: "unclosed block still counts keys", in: "---\nname: Broken\n", want: true}, {name: "case-insensitive keys", in: "---\nDescription: Y\n---\n", want: true}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { if got := HasDefinitionFrontmatter([]byte(tc.in)); got != tc.want { t.Errorf("HasDefinitionFrontmatter(%q) = %v, want %v", tc.in, got, tc.want) } }) } } func TestScanSkipsDocMarkdownInFlatDirs(t *testing.T) { dir := t.TempDir() writeTree(t, dir, map[string]string{ "agents/scout.md": "---\ndescription: a real agent\n---\nbody\n", "agents/SCHEMA.md": "# Schema\npure documentation, no frontmatter\n", "commands/review.md": "---\nargument-hint: [files]\n---\nbody\n", "commands/README.md": "Documentation for the commands directory.\n", "commands/notes.md": "---\ntitle: Notes\n---\nunknown keys only\n", "skills/good/SKILL.md": "---\nname: Good\n---\n# Good\n", }) items, err := Scan(&FsTree{Root: dir}, Config{}) if err != nil { t.Fatal(err) } got := map[string]bool{} skippedWarnings := []string{} for _, it := range items { if it.Skipped { skippedWarnings = append(skippedWarnings, it.Warnings...) continue } got[it.Type+"/"+it.UpstreamID] = true } for _, want := range []string{"agents/scout", "commands/review", "skills/good"} { if !got[want] { t.Errorf("%s must still be discovered; got %v", want, got) } } for _, doc := range []string{"agents/SCHEMA", "commands/README", "commands/notes"} { if got[doc] { t.Errorf("%s is documentation and must be skipped; got %v", doc, got) } } joined := strings.Join(skippedWarnings, "\n") for _, want := range []string{ "agents/SCHEMA.md: no agent frontmatter, skipped", "commands/README.md: no command frontmatter, skipped", "commands/notes.md: no command frontmatter, skipped", } { if !strings.Contains(joined, want) { t.Errorf("skip warning %q missing; got %v", want, skippedWarnings) } } }