Files
Willie 18d6b11347 test: test each rule once, in the package that owns it
Many integration and handler tests re-checked rules that internal/
packages already test, duplicated each other, or ran no product code at
all (a few re-implemented the logic inline, two could never fail). They
slowed the suite without catching anything new.

Delete those, keeping tests for CLI wiring, JSON output, exit codes,
project/global mode and cmd-only logic. Move the agents/extras overlap
check into sync.AgentTargetPaths so the CLI and the server share one
implementation and it is covered by unit tests instead of seven
integration tests.
2026-10-08 16:41:09 +08:00

117 lines
3.1 KiB
Go

//go:build !online
package integration
import (
"os"
"path/filepath"
"strings"
"testing"
"skillshare/internal/testutil"
)
func TestDisable_AddsToSkillignore(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("my-skill", map[string]string{
"SKILL.md": "---\nname: my-skill\n---\n# My Skill",
})
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
result := sb.RunCLI("disable", "my-skill")
result.AssertSuccess(t)
result.AssertRowContains(t, "my-skill", "added to .skillignore")
result.AssertAnyOutputContains(t, "skillshare sync")
ignorePath := filepath.Join(sb.SourcePath, ".skillignore")
data, err := os.ReadFile(ignorePath)
if err != nil {
t.Fatalf("expected .skillignore to exist: %v", err)
}
if !strings.Contains(string(data), "my-skill") {
t.Errorf(".skillignore should contain my-skill, got: %q", string(data))
}
}
func TestDisable_AlreadyDisabled(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("my-skill", map[string]string{
"SKILL.md": "---\nname: my-skill\n---\n# My Skill",
})
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
sb.RunCLI("disable", "my-skill")
result := sb.RunCLI("disable", "my-skill")
result.AssertSuccess(t)
result.AssertAnyOutputContains(t, "already disabled")
}
func TestEnable_RemovesFromSkillignore(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("my-skill", map[string]string{
"SKILL.md": "---\nname: my-skill\n---\n# My Skill",
})
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
sb.RunCLI("disable", "my-skill")
result := sb.RunCLI("enable", "my-skill")
result.AssertSuccess(t)
result.AssertRowContains(t, "my-skill", "removed from .skillignore")
ignorePath := filepath.Join(sb.SourcePath, ".skillignore")
data, err := os.ReadFile(ignorePath)
if err != nil && !os.IsNotExist(err) {
t.Fatalf("unexpected error: %v", err)
}
if strings.Contains(string(data), "my-skill") {
t.Errorf(".skillignore should not contain my-skill after enable, got: %q", string(data))
}
}
func TestEnable_NotDisabled(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("my-skill", map[string]string{
"SKILL.md": "---\nname: my-skill\n---\n# My Skill",
})
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
result := sb.RunCLI("enable", "my-skill")
result.AssertSuccess(t)
result.AssertAnyOutputContains(t, "not disabled")
}
func TestDisable_DryRun(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.CreateSkill("my-skill", map[string]string{"SKILL.md": "# Skill"})
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
result := sb.RunCLI("disable", "my-skill", "--dry-run")
result.AssertSuccess(t)
result.AssertAnyOutputContains(t, "would be added to")
ignorePath := filepath.Join(sb.SourcePath, ".skillignore")
if _, err := os.Stat(ignorePath); err == nil {
t.Error(".skillignore should not exist after dry-run")
}
}
func TestDisable_NoArgs(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
result := sb.RunCLI("disable")
result.AssertFailure(t)
}