biubiu8802 (X, 2119602075864903924) downloaded a skill from GitHub and put it in the Library from its folder, so it had nothing to update from and no way to link it to GitHub. Installing it from its GitHub link now links the two, the way an update of a CC Switch skill already does: the library's skill by that name takes GitHub's files and GitHub as its source. A check and an update cover it from then on, and the agents' links keep pointing at it. When its own files aren't GitHub's, they go to the backups like UpdateSkill's replace does, and the result says so. A folder of the user's it was linked to stays as it is. followsHere (skill_link.go) decides it. It links only a skill with no remote source that wasn't renamed and is that skill: it traces to this repository (CC Switch, the skills CLI's lock, a git checkout, From), or it traces nowhere and its SKILL.md has the same description as GitHub's, as an older download of it does. One traced to another repository, or an untraced one that describes something else (mora1n's case, TestInstallSetPutsAnotherByTheSameNameBeside), still goes in beside it (skill_beside.go). A had skill with the same files and no source is bound to the GitHub source it was found in, so a later install of another repository's skill by that name goes beside it, not over it (TestSameFilesByNameAreHad). The probe marks such a candidate links:true. The GUI's Add list tags it "links to GitHub" with a tooltip, and the report names "updates from GitHub now" and "files of their own kept with the backups". The TUI's probe list and result line say the same. The new strings are in zh, zh-TW, ja and de. Run on mote (macOS), on64ecd0f69, then rebased on8a58c0e30, whose new commits touch none of internal/library, the TUI's library or the library page: - gofmt -l clean; go vet ./..., GOOS=windows go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=linux go build -tags nogui ./..., GOOS=windows go build ./... all ok - go test ./internal/library/... ok at this tree; ./internal/tui/..., ./internal/cli/... and ./internal/gui/ ok at the tree before the description check (that change touches internal/library only) - GUI (chromium + webkit, 5 languages, wide and narrow): skill-install-link (new), skill-install-beside, skill-install-skip, skill-install-agents-all, skill-git-source, skill-too-big, provider-discovery, i18n-en-no-cjk pass. i18n-keys' "a plugin's words are its own" is red on main for three strings this change doesn't touch, already filed: #5332/#5327 ("View routing"), #5482 ("Use the library's"), #5426 ("No session ID"). Broken by hand: without the description check (the first version), TestInstallSetPutsAnotherByTheSameNameBeside is red (caveman taken over). followsHere returning false always turns TestFolderSkillFollowsGitHub red (probed As:pdf-pro-biubiu) and TestOwnSkillFollowsGitHubKeepsItsFiles red (linked [] kept []). Not run: the full go test ./... suite. mote's suite lock had a queue waiting up to 16h, so this change ran the packages it touches. No real GitHub install either: the tests use a fake tarball server. Not tried on Windows or Linux. The market's had-check (haveSkill) is unchanged: a market skill with a folder copy by that name still counts as had.
133 lines
5.1 KiB
Go
133 lines
5.1 KiB
Go
package library
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// biubiuRepo serves biubiu/skills with a pdf-pro skill in skills/, as
|
|
// GitHub has it now.
|
|
func biubiuRepo(t *testing.T) {
|
|
t.Helper()
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if !strings.HasPrefix(r.URL.Path, "/biubiu/skills/") {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
w.Write(tarball(t, map[string]string{
|
|
"skills/pdf-pro/SKILL.md": "---\nname: pdf-pro\ndescription: Fill and read PDFs\n---\nv2\n",
|
|
"skills/pdf-pro/forms.md": "forms v2",
|
|
}))
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
old := tarballURL
|
|
tarballURL = func(repo, ref string) string { return srv.URL + "/" + repo + "/" + ref }
|
|
t.Cleanup(func() { tarballURL = old })
|
|
}
|
|
|
|
// linkedToGitHub checks that the library's pdf-pro is the one from
|
|
// biubiu/skills now, with GitHub's files in its own folder, and that
|
|
// it's the only pdf-pro: none went in beside it.
|
|
func linkedToGitHub(t *testing.T, h string) {
|
|
t.Helper()
|
|
l, _ := load()
|
|
s := l.skill("pdf-pro")
|
|
if s == nil || s.Source == nil || s.Source.Kind != "github" || s.Source.Repo != "biubiu/skills" || s.Source.Path != "skills/pdf-pro" {
|
|
t.Fatalf("the library's pdf-pro is %+v", s)
|
|
}
|
|
if len(l.Skills) != 1 {
|
|
t.Errorf("the library has %d skills", len(l.Skills))
|
|
}
|
|
if fi, err := os.Lstat(skillDir("pdf-pro")); err != nil || linkEntry(fi) {
|
|
t.Errorf("the library's pdf-pro is a link still: %v", err)
|
|
}
|
|
if got := read(t, filepath.Join(skillDir("pdf-pro"), "forms.md")); got != "forms v2" {
|
|
t.Errorf("the library's forms.md: %q", got)
|
|
}
|
|
// the agent's link goes on pointing at it
|
|
if got := read(t, filepath.Join(h, ".claude/skills/pdf-pro/SKILL.md")); !strings.Contains(got, "v2") {
|
|
t.Errorf("claude's pdf-pro: %q", got)
|
|
}
|
|
// and it updates from GitHub like one installed from there
|
|
ok(t)(UpdateSkill("pdf-pro", false))
|
|
}
|
|
|
|
// biubiu8802 on X: a skill downloaded from GitHub and added to the
|
|
// library from its folder couldn't follow GitHub. Installing it from
|
|
// GitHub links the library's to it: GitHub's files take its place and it
|
|
// updates from there, and the user's folder is left as it is.
|
|
func TestFolderSkillFollowsGitHub(t *testing.T) {
|
|
h := sandbox(t)
|
|
biubiuRepo(t)
|
|
dl := filepath.Join(h, "Downloads", "pdf-pro")
|
|
write(t, filepath.Join(dl, "SKILL.md"), "---\nname: pdf-pro\ndescription: Fill and read PDFs\n---\nv1\n")
|
|
ok(t)(InstallSkills(dl, []string{""}, []string{"claude"}))
|
|
|
|
p, err := ProbeSkills("biubiu/skills")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(p.Candidates) != 1 || !p.Candidates[0].Links || p.Candidates[0].Have || p.Candidates[0].As != "" {
|
|
t.Fatalf("probed as %+v", p.Candidates)
|
|
}
|
|
r := ok(t)(InstallSkills("biubiu/skills", []string{"skills/pdf-pro"}, []string{"claude"}))
|
|
if !slices.Equal(r.Linked, []string{"pdf-pro"}) || len(r.LinkedKept) != 0 || len(r.Installed) != 0 || len(r.Skipped) != 0 {
|
|
t.Fatalf("linked %v kept %v installed %v skipped %+v", r.Linked, r.LinkedKept, r.Installed, r.Skipped)
|
|
}
|
|
linkedToGitHub(t, h)
|
|
if got := read(t, filepath.Join(dl, "SKILL.md")); !strings.Contains(got, "v1") {
|
|
t.Errorf("the user's folder changed: %q", got)
|
|
}
|
|
}
|
|
|
|
// One taken into the library from an agent's folder is the library's own
|
|
// copy: linked to GitHub, its files that aren't GitHub's go to the
|
|
// backups, and the result says so.
|
|
func TestOwnSkillFollowsGitHubKeepsItsFiles(t *testing.T) {
|
|
h := sandbox(t)
|
|
biubiuRepo(t)
|
|
write(t, filepath.Join(h, ".claude/skills/pdf-pro/SKILL.md"), "---\nname: pdf-pro\ndescription: Fill and read PDFs\n---\nmy edit\n")
|
|
ok(t)(ImportSkill("pdf-pro"))
|
|
|
|
r := ok(t)(InstallSkills("biubiu/skills", []string{"skills/pdf-pro"}, nil))
|
|
if !slices.Equal(r.Linked, []string{"pdf-pro"}) || !slices.Equal(r.LinkedKept, []string{"pdf-pro"}) {
|
|
t.Fatalf("linked %v kept %v", r.Linked, r.LinkedKept)
|
|
}
|
|
linkedToGitHub(t, h)
|
|
kept, _ := filepath.Glob(filepath.Join(BackupDir(), "*", "library", "skills", "pdf-pro", "SKILL.md"))
|
|
if len(kept) != 1 || !strings.Contains(read(t, kept[0]), "my edit") {
|
|
t.Errorf("the user's own version wasn't kept: %v", kept)
|
|
}
|
|
}
|
|
|
|
// One known to come from another repository is another skill by that
|
|
// name, even when it says it does the same: it is left as it is, and
|
|
// GitHub's goes in beside it. One traced nowhere that describes something
|
|
// else is TestInstallSetPutsAnotherByTheSameNameBeside's.
|
|
func TestSkillFromElsewhereIsNotLinked(t *testing.T) {
|
|
h := sandbox(t)
|
|
biubiuRepo(t)
|
|
dl := filepath.Join(h, "Downloads", "pdf-pro")
|
|
write(t, filepath.Join(dl, "SKILL.md"), "---\nname: pdf-pro\ndescription: Fill and read PDFs\n---\nsomeone else's\n")
|
|
ok(t)(InstallSkills(dl, []string{""}, nil))
|
|
mu.Lock()
|
|
l, _ := load()
|
|
l.skill("pdf-pro").From = "acme/skills"
|
|
l.save()
|
|
mu.Unlock()
|
|
|
|
r := ok(t)(InstallSkills("biubiu/skills", []string{"skills/pdf-pro"}, nil))
|
|
if len(r.Linked) != 0 || !slices.Equal(r.Installed, []string{"pdf-pro-biubiu"}) {
|
|
t.Fatalf("linked %v installed %v", r.Linked, r.Installed)
|
|
}
|
|
l, _ = load()
|
|
if s := l.skill("pdf-pro"); s.Source == nil || s.Source.Kind != "folder" {
|
|
t.Errorf("the folder's pdf-pro is %+v", s.Source)
|
|
}
|
|
}
|