Files
Willie f9be84c0f5 feat(projects): manage project folders from the global config
People with many repositories had to choose between listing every
project skills folder as a custom target or running project mode in
each repo. A `projects:` key in the global config now declares a folder
once with the tools used there, and sync treats each one as a
`<project>@<tool>` target with its own mode and filters.

- Expand `projects:` into virtual targets at load time and strip them
  on save; tools that share a project skills folder are written once
- Skip a project whose folder is missing with a warning instead of
  failing the whole sync; `collect` and `target` ignore project targets
- Add /api/projects (list, save, remove, convert) and detect ordinary
  targets that already point inside a project so they can be converted
- Add a Projects page to the dashboard with Skills, Agents and MCP tabs
  per project, replacing the Projects tab on the MCP page
- Extend Select with a multi-select mode for picking a project's targets

Refs #286
2026-09-21 01:52:34 +08:00

73 lines
2.4 KiB
Go

//go:build !online
package integration
import (
"os"
"path/filepath"
"testing"
"skillshare/internal/testutil"
)
// projectsSandbox has two skills, one agent and a project folder declared in the
// global config under projects.
func projectsSandbox(t *testing.T, project string) (*testutil.Sandbox, string) {
t.Helper()
sb := testutil.NewSandbox(t)
sb.CreateSkill("team-lint", map[string]string{"SKILL.md": "---\nname: team-lint\n---\n# Lint"})
sb.CreateSkill("draft", map[string]string{"SKILL.md": "---\nname: draft\n---\n# Draft"})
sb.WriteFile(filepath.Join(filepath.Dir(sb.SourcePath), "agents", "reviewer.md"), "# Reviewer")
root := filepath.Join(sb.Home, "work", "app")
if err := os.MkdirAll(root, 0755); err != nil {
t.Fatal(err)
}
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\nprojects:\n " + root + ":\n" + project)
return sb, root
}
func TestProjects_SyncWritesSkillsAndAgentsIntoTheFolder(t *testing.T) {
sb, root := projectsSandbox(t, " targets: [claude, codex]\n skills:\n mode: copy\n include: [team-*]\n agents: {}\n")
defer sb.Cleanup()
sb.RunCLI("sync", "--all").AssertSuccess(t)
for _, path := range []string{".claude/skills/team-lint/SKILL.md", ".agents/skills/team-lint/SKILL.md", ".claude/agents/reviewer.md"} {
if !sb.FileExists(filepath.Join(root, path)) {
t.Errorf("%s was not written", path)
}
}
if sb.FileExists(filepath.Join(root, ".claude", "skills", "draft")) {
t.Error("draft is not included but was written")
}
if sb.FileExists(filepath.Join(root, ".skillshare")) {
t.Error("the project folder got a .skillshare/")
}
}
func TestProjects_CollectLeavesAProjectsOwnSkills(t *testing.T) {
sb, root := projectsSandbox(t, " targets: [claude]\n skills: {}\n")
defer sb.Cleanup()
sb.RunCLI("sync").AssertSuccess(t)
sb.WriteFile(filepath.Join(root, ".claude", "skills", "local-only", "SKILL.md"), "---\nname: local-only\n---\n")
sb.RunCLI("collect", "--all", "--force")
if sb.FileExists(filepath.Join(sb.SourcePath, "local-only")) {
t.Error("collect pulled a skill out of a project")
}
}
func TestProjects_TargetCommandDoesNotSeeProjectTargets(t *testing.T) {
sb, _ := projectsSandbox(t, " targets: [claude]\n skills: {}\n")
defer sb.Cleanup()
result := sb.RunCLI("target", "remove", "app@claude")
result.AssertFailure(t)
if !sb.FileExists(sb.ConfigPath) {
t.Fatal("config is gone")
}
sb.RunCLI("status").AssertAnyOutputContains(t, "app@claude")
}