mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Phase 1 of caller migration: - projectRuntime: registry → skillsStore + agentsStore - globalInstallContext: reg → store - ReconcileGlobalSkills/ProjectSkills/ProjectAgents: take *MetadataStore - Server struct: registry → skillsStore + agentsStore - handler_install, handler_skills, handler_uninstall: use MetadataStore - install.go, search.go: post-install reconciliation via MetadataStore
102 lines
3.1 KiB
Go
102 lines
3.1 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"skillshare/internal/install"
|
|
)
|
|
|
|
func TestHandleSync_MergeMode(t *testing.T) {
|
|
tgtPath := filepath.Join(t.TempDir(), "claude-skills")
|
|
s, src := newTestServerWithTargets(t, map[string]string{"claude": tgtPath})
|
|
addSkill(t, src, "alpha")
|
|
|
|
body := `{"dryRun":false}`
|
|
req := httptest.NewRequest(http.MethodPost, "/api/sync", strings.NewReader(body))
|
|
rr := httptest.NewRecorder()
|
|
s.handler.ServeHTTP(rr, req)
|
|
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String())
|
|
}
|
|
|
|
var resp struct {
|
|
Results []map[string]any `json:"results"`
|
|
}
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if len(resp.Results) != 1 {
|
|
t.Fatalf("expected 1 sync result, got %d", len(resp.Results))
|
|
}
|
|
if resp.Results[0]["target"] != "claude" {
|
|
t.Errorf("expected target 'claude', got %v", resp.Results[0]["target"])
|
|
}
|
|
}
|
|
|
|
func TestHandleSync_IgnoredSkillNotPrunedFromRegistry(t *testing.T) {
|
|
tgtPath := filepath.Join(t.TempDir(), "claude-skills")
|
|
s, src := newTestServerWithTargets(t, map[string]string{"claude": tgtPath})
|
|
|
|
// Create a skill with install metadata (so it appears in registry)
|
|
addSkill(t, src, "kept-skill")
|
|
addSkillMeta(t, src, "kept-skill", "github.com/user/kept")
|
|
|
|
// Create another skill that will be ignored
|
|
addSkill(t, src, "ignored-skill")
|
|
addSkillMeta(t, src, "ignored-skill", "github.com/user/ignored")
|
|
|
|
// Add .skillignore to exclude the second skill
|
|
os.WriteFile(filepath.Join(src, ".skillignore"), []byte("ignored-skill\n"), 0644)
|
|
|
|
// Pre-populate store with both entries and persist to disk
|
|
// (server auto-reloads metadata from disk on each request)
|
|
s.skillsStore = install.NewMetadataStore()
|
|
s.skillsStore.Set("kept-skill", &install.MetadataEntry{Source: "github.com/user/kept"})
|
|
s.skillsStore.Set("ignored-skill", &install.MetadataEntry{Source: "github.com/user/ignored"})
|
|
if err := s.skillsStore.Save(src); err != nil {
|
|
t.Fatalf("failed to save metadata: %v", err)
|
|
}
|
|
|
|
// Run sync (non-dry-run)
|
|
body := `{"dryRun":false}`
|
|
req := httptest.NewRequest(http.MethodPost, "/api/sync", strings.NewReader(body))
|
|
rr := httptest.NewRecorder()
|
|
s.handler.ServeHTTP(rr, req)
|
|
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String())
|
|
}
|
|
|
|
// Both entries should survive — ignored skill still exists on disk
|
|
names := s.skillsStore.List()
|
|
if len(names) != 2 {
|
|
t.Fatalf("expected 2 metadata entries after sync, got %d: %v", len(names), names)
|
|
}
|
|
}
|
|
|
|
func TestHandleSync_NoTargets(t *testing.T) {
|
|
s, _ := newTestServer(t) // no targets configured
|
|
|
|
body := `{}`
|
|
req := httptest.NewRequest(http.MethodPost, "/api/sync", strings.NewReader(body))
|
|
rr := httptest.NewRecorder()
|
|
s.handler.ServeHTTP(rr, req)
|
|
|
|
if rr.Code != http.StatusOK {
|
|
t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String())
|
|
}
|
|
|
|
var resp struct {
|
|
Results []any `json:"results"`
|
|
}
|
|
json.Unmarshal(rr.Body.Bytes(), &resp)
|
|
if len(resp.Results) != 0 {
|
|
t.Errorf("expected 0 results for no targets, got %d", len(resp.Results))
|
|
}
|
|
}
|