mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
Backend: - PATCH /api/targets/:name accepts agent_include/agent_exclude fields - POST /api/sync-matrix/preview returns agent entries with kind=agent - GET /api/overview returns agentsSource and extrasSource paths - Fix ResolveProjectTargets to resolve Agents sub-key (path + filters) - Add agent filter CLI flags: --add-agent-include, --add-agent-exclude, --remove-agent-include, --remove-agent-exclude, --agent-mode - Unify target list JSON/TUI to show agent info and filters Frontend: - FilterStudioPage: kind-driven single-context view (?kind=skill|agent) - KindBadge: use design system tokens (ss-badge + wobble in playful) - TargetsPage: link to Filter Studio with ?kind= param - ResourceDetailPage: capitalize type labels (Local, GitHub) - ResourcesPage: sync activeTab from URL searchParams on navigation - DashboardPage: show agents/extras source dirs, link skills card with ?tab=skills for reliable tab switching - API client: extend updateTarget and previewSyncMatrix for agent filters Tests: - Agent include/exclude round-trip persistence - Invalid agent pattern returns 400 - Preview with agent entries and kind field - No agent entries for targets without agent path - CLI target agent filter integration tests
124 lines
3.9 KiB
Go
124 lines
3.9 KiB
Go
package server
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"skillshare/internal/config"
|
|
"skillshare/internal/install"
|
|
)
|
|
|
|
// newTestServer creates an isolated Server for handler testing.
|
|
// It sets up a temp source directory and config file, returning the server
|
|
// and the source directory path for test setup.
|
|
func newTestServer(t *testing.T) (*Server, string) {
|
|
t.Helper()
|
|
tmp := t.TempDir()
|
|
sourceDir := filepath.Join(tmp, "skills")
|
|
os.MkdirAll(sourceDir, 0755)
|
|
t.Setenv("XDG_DATA_HOME", filepath.Join(tmp, "data"))
|
|
t.Setenv("XDG_STATE_HOME", filepath.Join(tmp, "state"))
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmp, "xdg-config"))
|
|
|
|
cfgPath := filepath.Join(tmp, "config", "config.yaml")
|
|
t.Setenv("SKILLSHARE_CONFIG", cfgPath)
|
|
os.MkdirAll(filepath.Dir(cfgPath), 0755)
|
|
|
|
raw := "source: " + sourceDir + "\nmode: merge\ntargets: {}\n"
|
|
os.WriteFile(cfgPath, []byte(raw), 0644)
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
t.Fatalf("failed to load config: %v", err)
|
|
}
|
|
|
|
s := New(cfg, "127.0.0.1:0", "", "")
|
|
return s, sourceDir
|
|
}
|
|
|
|
// newTestServerWithTargets creates a test server with pre-configured targets.
|
|
func newTestServerWithTargets(t *testing.T, targets map[string]string) (*Server, string) {
|
|
t.Helper()
|
|
tmp := t.TempDir()
|
|
sourceDir := filepath.Join(tmp, "skills")
|
|
os.MkdirAll(sourceDir, 0755)
|
|
t.Setenv("XDG_DATA_HOME", filepath.Join(tmp, "data"))
|
|
t.Setenv("XDG_STATE_HOME", filepath.Join(tmp, "state"))
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(tmp, "xdg-config"))
|
|
|
|
cfgPath := filepath.Join(tmp, "config", "config.yaml")
|
|
t.Setenv("SKILLSHARE_CONFIG", cfgPath)
|
|
os.MkdirAll(filepath.Dir(cfgPath), 0755)
|
|
|
|
raw := "source: " + sourceDir + "\nmode: merge\ntargets:\n"
|
|
for name, path := range targets {
|
|
os.MkdirAll(path, 0755)
|
|
raw += " " + name + ":\n path: " + path + "\n"
|
|
}
|
|
os.WriteFile(cfgPath, []byte(raw), 0644)
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
t.Fatalf("failed to load config: %v", err)
|
|
}
|
|
|
|
s := New(cfg, "127.0.0.1:0", "", "")
|
|
return s, sourceDir
|
|
}
|
|
|
|
// addSkill creates a skill directory with SKILL.md in the source directory.
|
|
func addSkill(t *testing.T, sourceDir, name string) {
|
|
t.Helper()
|
|
skillDir := filepath.Join(sourceDir, name)
|
|
os.MkdirAll(skillDir, 0755)
|
|
os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte("---\nname: "+name+"\n---\n# "+name), 0644)
|
|
}
|
|
|
|
func addTrackedRepo(t *testing.T, sourceDir, relPath string) {
|
|
t.Helper()
|
|
repoDir := filepath.Join(sourceDir, filepath.FromSlash(relPath))
|
|
if err := os.MkdirAll(filepath.Join(repoDir, ".git"), 0755); err != nil {
|
|
t.Fatalf("failed to create tracked repo: %v", err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(repoDir, "README.md"), []byte("tracked repo"), 0644); err != nil {
|
|
t.Fatalf("failed to seed tracked repo: %v", err)
|
|
}
|
|
}
|
|
|
|
// addSkillMeta writes a metadata entry into the centralized .metadata.json store.
|
|
func addSkillMeta(t *testing.T, sourceDir, name, source string) {
|
|
t.Helper()
|
|
store := install.LoadMetadataOrNew(sourceDir)
|
|
store.Set(name, &install.MetadataEntry{Source: source})
|
|
if err := store.Save(sourceDir); err != nil {
|
|
t.Fatalf("addSkillMeta: %v", err)
|
|
}
|
|
}
|
|
|
|
func addAgent(t *testing.T, agentsDir, relPath string) {
|
|
t.Helper()
|
|
agentPath := filepath.Join(agentsDir, filepath.FromSlash(relPath))
|
|
if err := os.MkdirAll(filepath.Dir(agentPath), 0o755); err != nil {
|
|
t.Fatalf("create agent dir: %v", err)
|
|
}
|
|
if err := os.WriteFile(agentPath, []byte("---\nname: "+strings.TrimSuffix(filepath.Base(relPath), ".md")+"\n---\n# agent"), 0o644); err != nil {
|
|
t.Fatalf("write agent: %v", err)
|
|
}
|
|
}
|
|
|
|
func addAgentMeta(t *testing.T, agentsDir, relPath, source string) {
|
|
t.Helper()
|
|
store := install.LoadMetadataOrNew(agentsDir)
|
|
key := strings.TrimSuffix(filepath.ToSlash(relPath), ".md")
|
|
store.Set(key, &install.MetadataEntry{
|
|
Source: source,
|
|
Kind: install.MetadataKindAgent,
|
|
Subdir: filepath.ToSlash(relPath),
|
|
})
|
|
if err := store.Save(agentsDir); err != nil {
|
|
t.Fatalf("addAgentMeta: %v", err)
|
|
}
|
|
}
|