Files
skillshare/tests/integration/install_agent_test.go
T
Willie cb55ffe55c feat(agents): add positional kind filter and wire agents into list, sync, update, uninstall, collect, trash
Phase 1 — Foundation:
- parseKindArg() defaults to kindSkills, adds "all" keyword
- list: discover agents via resource.AgentKind, populate Kind field in JSON/TUI
- sync agents / sync all: new sync_agents.go handles agent sync to targets
- uninstall: migrate from --kind flag to positional ("uninstall agents <name>")

Phase 2 — Core CRUD:
- update agents: check status, enrich with remote, reinstall from source
- uninstall agents: move .md + sidecar to agent trash with confirmation
- collect agents: CollectAgents from agent-capable targets to source
- trash agents: list/restore/delete/empty for agent trash directory
- trash.RestoreAgent(): file-level restore (vs directory-level for skills)

Behavior: all commands default to skills-only (no breaking change).
"cmd agents" = agents only, "cmd all" = skills + agents.

Fix: TestLog_SyncPartialStatus uses dangling symlink instead of chmod
(root ignores permissions in devcontainer).

25 new integration tests, all passing.
2026-04-07 18:05:40 +08:00

131 lines
3.3 KiB
Go

//go:build !online
package integration
import (
"os"
"path/filepath"
"testing"
"skillshare/internal/testutil"
)
func TestInstall_AgentFlag_ParsesCorrectly(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// --kind with invalid value should error
result := sb.RunCLI("install", "--kind", "invalid", "test")
result.AssertFailure(t)
result.AssertAnyOutputContains(t, "must be 'skill' or 'agent'")
}
func TestInstall_AgentFlagShort_ParsesCorrectly(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// -a without value should error
result := sb.RunCLI("install", "-a")
result.AssertFailure(t)
result.AssertAnyOutputContains(t, "requires agent name")
}
func TestCheck_Agents_EmptyDir(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Create agents source dir
agentsDir := filepath.Join(filepath.Dir(sb.SourcePath), "agents")
os.MkdirAll(agentsDir, 0755)
result := sb.RunCLI("check", "agents")
result.AssertSuccess(t)
result.AssertAnyOutputContains(t, "No agents found")
}
func TestCheck_Agents_LocalAgent(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Create agents source dir with a local agent
agentsDir := filepath.Join(filepath.Dir(sb.SourcePath), "agents")
os.MkdirAll(agentsDir, 0755)
os.WriteFile(filepath.Join(agentsDir, "tutor.md"), []byte("# Tutor agent"), 0644)
result := sb.RunCLI("check", "agents")
result.AssertSuccess(t)
result.AssertAnyOutputContains(t, "tutor")
result.AssertAnyOutputContains(t, "local")
}
func TestCheck_Agents_JsonOutput(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
agentsDir := filepath.Join(filepath.Dir(sb.SourcePath), "agents")
os.MkdirAll(agentsDir, 0755)
os.WriteFile(filepath.Join(agentsDir, "tutor.md"), []byte("# Tutor"), 0644)
result := sb.RunCLI("check", "agents", "--json")
result.AssertSuccess(t)
result.AssertAnyOutputContains(t, `"name"`)
result.AssertAnyOutputContains(t, `"status"`)
}
func TestEnable_KindAgent_ParsesCorrectly(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Create agents source dir
agentsDir := filepath.Join(filepath.Dir(sb.SourcePath), "agents")
os.MkdirAll(agentsDir, 0755)
// Disable an agent — --kind goes after -g (mode flag)
result := sb.RunCLI("disable", "-g", "--kind", "agent", "tutor")
result.AssertSuccess(t)
result.AssertAnyOutputContains(t, ".agentignore")
// Verify .agentignore was created
agentIgnorePath := filepath.Join(agentsDir, ".agentignore")
if !sb.FileExists(agentIgnorePath) {
t.Error(".agentignore should be created")
}
}
func TestUninstall_AgentsPositional_ParsesCorrectly(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
sb.WriteConfig(`source: ` + sb.SourcePath + `
targets: {}
`)
// Positional "agents" with nonexistent agent — should parse correctly (no "unknown option")
result := sb.RunCLI("uninstall", "-g", "agents", "nonexistent")
result.AssertOutputNotContains(t, "unknown option")
}