71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package targets
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"sgg-ai-skill-manager/internal/domain"
|
|
)
|
|
|
|
func TestInstallCreatesJunctionAndUninstallKeepsSource(t *testing.T) {
|
|
root := t.TempDir()
|
|
source := filepath.Join(root, "repo", "demo")
|
|
if err := os.MkdirAll(source, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(source, "SKILL.md"), []byte("# Demo\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
manager := New(map[string]Target{
|
|
"codex": {ID: "codex", Name: "Codex", SkillsDir: filepath.Join(root, "codex", "skills")},
|
|
})
|
|
skill := domain.SkillState{Org: "skills", Repo: "demo", LocalPath: source, InstalledTargets: map[string]domain.InstalledTarget{}}
|
|
|
|
installed, err := manager.Install(skill, "codex")
|
|
if err != nil {
|
|
t.Fatalf("Install returned error: %v", err)
|
|
}
|
|
link := filepath.Join(root, "codex", "skills", "demo")
|
|
if _, err := os.Stat(filepath.Join(link, "SKILL.md")); err != nil {
|
|
t.Fatalf("junction does not expose SKILL.md: %v", err)
|
|
}
|
|
if installed.InstalledTargets["codex"].TargetPath != source {
|
|
t.Fatalf("installed target = %+v", installed.InstalledTargets["codex"])
|
|
}
|
|
|
|
uninstalled, err := manager.Uninstall(installed, "codex")
|
|
if err != nil {
|
|
t.Fatalf("Uninstall returned error: %v", err)
|
|
}
|
|
if _, err := os.Stat(source); err != nil {
|
|
t.Fatalf("source should remain after uninstall: %v", err)
|
|
}
|
|
if _, err := os.Lstat(link); !os.IsNotExist(err) {
|
|
t.Fatalf("link should be removed, err=%v", err)
|
|
}
|
|
if _, ok := uninstalled.InstalledTargets["codex"]; ok {
|
|
t.Fatal("codex install record should be removed")
|
|
}
|
|
}
|
|
|
|
func TestInstallRejectsExistingOrdinaryDirectory(t *testing.T) {
|
|
root := t.TempDir()
|
|
source := filepath.Join(root, "repo", "demo")
|
|
link := filepath.Join(root, "codex", "skills", "demo")
|
|
if err := os.MkdirAll(source, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.MkdirAll(link, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
manager := New(map[string]Target{
|
|
"codex": {ID: "codex", Name: "Codex", SkillsDir: filepath.Join(root, "codex", "skills")},
|
|
})
|
|
skill := domain.SkillState{Org: "skills", Repo: "demo", LocalPath: source, InstalledTargets: map[string]domain.InstalledTarget{}}
|
|
|
|
if _, err := manager.Install(skill, "codex"); err == nil {
|
|
t.Fatal("Install returned nil error for ordinary directory conflict")
|
|
}
|
|
}
|