Files
agent-lib/internal/e2e/skip_docs_test.go
T

87 lines
3.0 KiB
Go
Raw Normal View History

package e2e
import (
"os"
"path/filepath"
"strings"
"testing"
)
func docFixture(h *harness, t *testing.T) {
t.Helper()
h.write(t, "skills/good-skill/SKILL.md", "---\nname: Good Skill\ndescription: works\n---\n# Good\n")
h.write(t, "agents/scout.md", "---\ndescription: a real agent\n---\nbody\n")
h.write(t, "agents/SCHEMA.md", "# Schema\npure documentation, no frontmatter\n")
h.write(t, "commands/review.md", "---\nargument-hint: [files]\n---\nbody\n")
h.write(t, "commands/README.md", "Documentation for the commands directory.\n")
h.commitUpstream(t, "fixture with documentation files")
}
func TestVendorAddSkipsDocMarkdownWithWarning(t *testing.T) {
h := newHarness(t)
docFixture(h, t)
out := h.mustRun(t, "vendor", "add", "superpowers", h.upstreamDir)
if !contains(out, "agents/SCHEMA.md: no agent frontmatter, skipped") {
t.Errorf("add report must warn about skipped SCHEMA.md:\n%s", out)
}
if !contains(out, "commands/README.md: no command frontmatter, skipped") {
t.Errorf("add report must warn about skipped README.md:\n%s", out)
}
lock := readFile(t, filepath.Join(h.workDir, "agent-lib.lock.json"))
if !contains(lock, "agents/SCHEMA.md: no agent frontmatter, skipped") {
t.Errorf("lockfile warnings must record the skip:\n%s", lock)
}
for _, dir := range []string{"agents", "commands"} {
entries, err := os.ReadDir(filepath.Join(h.workDir, "external", "superpowers", dir))
if err != nil {
t.Fatalf("external %s area must exist: %v", dir, err)
}
for _, e := range entries {
name := e.Name()
if (dir == "agents" && name == "SCHEMA.md") || (dir == "commands" && name == "README.md") {
t.Errorf("documentation file %s/%s must not be materialized", dir, name)
}
}
}
if !contains(out, "1 agents") || !contains(out, "1 commands") {
t.Errorf("counts must reflect real items only:\n%s", out)
}
h.mustRun(t, "validate")
}
func TestVendorAddIncludeErrorOmitsSkippedDocs(t *testing.T) {
h := newHarness(t)
docFixture(h, t)
out, err := h.run(t, "vendor", "add", "superpowers", h.upstreamDir, "--include", "typo")
if err == nil {
t.Fatalf("include with typo must fail:\n%s", out)
}
if contains(out, "SCHEMA") || contains(out, "README") {
t.Errorf("skipped documentation must not appear as available ids:\n%s", out)
}
for _, want := range []string{"scout", "review", "good-skill"} {
if !contains(out, want) {
t.Errorf("real ids must still be listed as available (missing %s):\n%s", want, out)
}
}
}
func TestVendorUpdateSelectKeepSkippingDocs(t *testing.T) {
h := newHarness(t)
docFixture(h, t)
h.mustRun(t, "vendor", "add", "superpowers", h.upstreamDir, "--include", "scout,review")
out := h.mustRun(t, "vendor", "select", "superpowers", "--add", "good-skill")
if contains(out, "SCHEMA") {
t.Errorf("select report must not surface skipped docs:\n%s", out)
}
lock := readFile(t, filepath.Join(h.workDir, "agent-lib.lock.json"))
if got := strings.Count(lock, "no agent frontmatter, skipped"); got != 1 {
t.Errorf("warning must stay recorded exactly once in the lockfile, got %d", got)
}
h.mustRun(t, "validate")
}