mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
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.
190 lines
6.1 KiB
Go
190 lines
6.1 KiB
Go
//go:build !online
|
|
|
|
package integration
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"skillshare/internal/testutil"
|
|
)
|
|
|
|
func TestInstall_SkillFlag_SelectsSpecific(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
gitRepoPath := createMultiSkillGitRepo(t, sb, "skill-flag-repo", []string{"skill-one", "skill-two", "skill-three"})
|
|
|
|
result := sb.RunCLI("install", "file://"+gitRepoPath, "-s", "skill-one")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "skill-one")
|
|
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-one", "SKILL.md")) {
|
|
t.Error("skill-one should be installed")
|
|
}
|
|
if sb.FileExists(filepath.Join(sb.SourcePath, "skill-two")) {
|
|
t.Error("skill-two should NOT be installed")
|
|
}
|
|
if sb.FileExists(filepath.Join(sb.SourcePath, "skill-three")) {
|
|
t.Error("skill-three should NOT be installed")
|
|
}
|
|
}
|
|
|
|
func TestInstall_SkillFlag_CommaSeparated(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
gitRepoPath := createMultiSkillGitRepo(t, sb, "comma-repo", []string{"skill-one", "skill-two", "skill-three"})
|
|
|
|
result := sb.RunCLI("install", "file://"+gitRepoPath, "-s", "skill-one,skill-two")
|
|
result.AssertSuccess(t)
|
|
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-one", "SKILL.md")) {
|
|
t.Error("skill-one should be installed")
|
|
}
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-two", "SKILL.md")) {
|
|
t.Error("skill-two should be installed")
|
|
}
|
|
if sb.FileExists(filepath.Join(sb.SourcePath, "skill-three")) {
|
|
t.Error("skill-three should NOT be installed")
|
|
}
|
|
}
|
|
|
|
func TestInstall_SkillFlag_NotFound(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
gitRepoPath := createMultiSkillGitRepo(t, sb, "notfound-repo", []string{"skill-one", "skill-two"})
|
|
|
|
result := sb.RunCLI("install", "file://"+gitRepoPath, "-s", "nonexistent")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "skills not found: nonexistent")
|
|
result.AssertAnyOutputContains(t, "Available:")
|
|
}
|
|
|
|
func TestInstall_AllFlag_InstallsAll(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
gitRepoPath := createMultiSkillGitRepo(t, sb, "all-flag-repo", []string{"skill-one", "skill-two", "skill-three"})
|
|
|
|
result := sb.RunCLI("install", "file://"+gitRepoPath, "--all")
|
|
result.AssertSuccess(t)
|
|
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-one", "SKILL.md")) {
|
|
t.Error("skill-one should be installed")
|
|
}
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-two", "SKILL.md")) {
|
|
t.Error("skill-two should be installed")
|
|
}
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-three", "SKILL.md")) {
|
|
t.Error("skill-three should be installed")
|
|
}
|
|
}
|
|
|
|
func TestInstall_AllFlag_ShowsAuditWarningsForFindingsBelowThreshold(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
gitRepoPath := filepath.Join(sb.Root, "all-flag-audit-warning-repo")
|
|
safeSkill := filepath.Join(gitRepoPath, "safe-skill")
|
|
highSkill := filepath.Join(gitRepoPath, "high-skill")
|
|
if err := os.MkdirAll(safeSkill, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(highSkill, 0755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(safeSkill, "SKILL.md"), []byte("# safe-skill"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(highSkill, "SKILL.md"), []byte("# high-skill\nsudo apt-get install -y jq"), 0644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
initGitRepo(t, gitRepoPath)
|
|
|
|
result := sb.RunCLI("install", "file://"+gitRepoPath, "--all")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "HIGH=1")
|
|
result.AssertAnyOutputContains(t, "findings below the active block threshold")
|
|
}
|
|
|
|
func TestInstall_YesFlag_InstallsAll(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
gitRepoPath := createMultiSkillGitRepo(t, sb, "yes-flag-repo", []string{"skill-one", "skill-two", "skill-three"})
|
|
|
|
result := sb.RunCLI("install", "file://"+gitRepoPath, "-y")
|
|
result.AssertSuccess(t)
|
|
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-one", "SKILL.md")) {
|
|
t.Error("skill-one should be installed")
|
|
}
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-two", "SKILL.md")) {
|
|
t.Error("skill-two should be installed")
|
|
}
|
|
if !sb.FileExists(filepath.Join(sb.SourcePath, "skill-three", "SKILL.md")) {
|
|
t.Error("skill-three should be installed")
|
|
}
|
|
}
|
|
|
|
func TestInstall_SkillFlag_DryRun(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
gitRepoPath := createMultiSkillGitRepo(t, sb, "dryrun-skill-repo", []string{"skill-one", "skill-two", "skill-three"})
|
|
|
|
result := sb.RunCLI("install", "file://"+gitRepoPath, "-s", "skill-one", "--dry-run")
|
|
result.AssertSuccess(t)
|
|
result.AssertOutputContains(t, "skill-one")
|
|
result.AssertOutputContains(t, "Would install 1 skill")
|
|
result.AssertOutputContains(t, "Dry run — nothing was written")
|
|
|
|
// skill-two and skill-three should NOT appear in output
|
|
result.AssertOutputNotContains(t, "skill-two")
|
|
result.AssertOutputNotContains(t, "skill-three")
|
|
|
|
// Nothing should be installed
|
|
if sb.FileExists(filepath.Join(sb.SourcePath, "skill-one")) {
|
|
t.Error("skill should not be installed in dry-run mode")
|
|
}
|
|
}
|
|
|
|
func TestInstall_SkillAndAllConflict(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
result := sb.RunCLI("install", "file:///some/repo", "-s", "x", "--all")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "--skill and --all cannot be used together")
|
|
}
|
|
|
|
func TestInstall_SkillAndTrackConflict(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
|
|
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
result := sb.RunCLI("install", "file:///some/repo", "-s", "x", "--track")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "--skill cannot be used with --track")
|
|
}
|