Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168package planparse_test
import ( "testing"
"git.sr.ht/~jcmuller/claude-plugins/internal/planparse" "github.com/stretchr/testify/assert")
func TestExtractRefs_BulletFormFromKnownPlanFixture(t *testing.T) { t.Parallel() body := []byte("# Plan\n\n" + "## Skills to load\n\n" + "- `code-quality-skills:general-code-style`\n" + "- `gh-code-quality:tdd`\n" + "- `gh-security:secure-by-design`\n" + "- `humanizer` (README, commit messages)\n" + "- `jujutsu-vcs` (all version control)\n" + "- `skill-creator` (plugin authoring reference)\n") skills, lsps := planparse.ExtractRefs(body) assert.Equal(t, []string{ "code-quality-skills:general-code-style", "gh-code-quality:tdd", "gh-security:secure-by-design", "humanizer", "jujutsu-vcs", "skill-creator", }, skills) assert.Empty(t, lsps)}
func TestExtractRefs_TableFormWithMixedLSPRow(t *testing.T) { t.Parallel() body := []byte("## Required skills and LSPs\n\n" + "| Skill / LSP | Why |\n" + "| -------------- | -------------------- |\n" + "| `humanizer` | Commit body |\n" + "| `jujutsu-vcs` | Branch + push |\n" + "| LSP: `gopls` | Go-symbol navigation |\n") skills, lsps := planparse.ExtractRefs(body) assert.Equal(t, []string{"humanizer", "jujutsu-vcs"}, skills) assert.Equal(t, []string{"gopls"}, lsps)}
func TestExtractRefs_EdgeCases(t *testing.T) { t.Parallel() cases := []struct { name string body string expectedSkills []string expectedLSPs []string }{ { name: "empty input", body: "", }, { name: "multi-skill cell with slash separators", body: "## Skills to load\n\n- `a` / `b` / `c`\n", expectedSkills: []string{"a", "b", "c"}, }, { name: "block ends at next heading", body: "## Skills to load\n\n- `humanizer`\n\n## Architecture\n\n- `should-not-leak`\n", expectedSkills: []string{"humanizer"}, }, { name: "deduplicates across two skills sections", body: "## Skills to load\n\n- `humanizer`\n\n## Required skills\n\n- `humanizer`\n- `tdd`\n", expectedSkills: []string{"humanizer", "tdd"}, }, { name: "depth-1 heading also matches", body: "# Skills to load\n\n- `humanizer`\n", expectedSkills: []string{"humanizer"}, }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { t.Parallel() skills, lsps := planparse.ExtractRefs([]byte(tc.body)) assert.Equal(t, tc.expectedSkills, skills) assert.Equal(t, tc.expectedLSPs, lsps) }) }}
func TestExtractRefs_HeadingVariantsFromCorpus(t *testing.T) { t.Parallel() matching := []string{ "Skills", "Skills to load", "Skills to Load", "Skills to load before coding", "Skills to load on execution", "Skills to Load for Implementation", "Skills to Load When Executing This Plan", "Skills to load (context clears will drop these)", "Skills loaded", "Skills in use", "Skills loaded (from [~/.claude/CLAUDE.md](~/.claude/CLAUDE.md))", "Required skills", "Required skills and LSPs", "Required Skills / LSPs", "Prerequisites", } for _, h := range matching { t.Run("matches/"+h, func(t *testing.T) { t.Parallel() body := []byte("## " + h + "\n\n- `humanizer`\n") skills, _ := planparse.ExtractRefs(body) assert.Equal(t, []string{"humanizer"}, skills, "heading %q must match", h) }) }
nonMatching := []string{ "Skills That Stay as Skills", "Skills to Migrate (19)", "Architecture", "Why a new plugin", } for _, h := range nonMatching { t.Run("rejects/"+h, func(t *testing.T) { t.Parallel() body := []byte("## " + h + "\n\n- `humanizer`\n") skills, lsps := planparse.ExtractRefs(body) assert.Empty(t, skills, "heading %q must not match", h) assert.Empty(t, lsps) }) }}
func TestExtractRefs_FencedCodeBlocksDoNotPolluteResults(t *testing.T) { t.Parallel() body := []byte("## Skills to load\n\n" + "```text\n" + "- `not-a-real-skill`\n" + "```\n\n" + "- `real-skill`\n") skills, _ := planparse.ExtractRefs(body) assert.Equal(t, []string{"real-skill"}, skills)}
func TestExtractRefs_LSPOnlyHeadingRoutesAllEntriesToLSPs(t *testing.T) { t.Parallel() body := []byte("## Required LSP\n\n- `gopls`\n- `nil`\n") skills, lsps := planparse.ExtractRefs(body) assert.Empty(t, skills) assert.Equal(t, []string{"gopls", "nil"}, lsps)}
func TestExtractRefs_FalsePositiveHeadings(t *testing.T) { t.Parallel() cases := map[string]string{ "Skills That Stay as Skills": "## Skills That Stay as Skills\n\n- `humanizer`\n", "Skills with arrow title": "# Skills → Agents: Conversion Plan\n\n- `humanizer`\n", "unrelated heading": "## Architecture\n\n- `humanizer`\n", } for name, body := range cases { t.Run(name, func(t *testing.T) { t.Parallel() skills, lsps := planparse.ExtractRefs([]byte(body)) assert.Empty(t, skills, "must not extract refs from a non-matching heading") assert.Empty(t, lsps) }) }}