mora1n on Discord: anthropics/skills' skill-creator and openai/skills'
are two skills by one name, and only the first could be added; the
second was skipped as "another skill called skill-creator, left as it
is". The library keyed being had by name in every place that asked.
Now being had is decided by source (hadSkill): the same source under any
name here, or a skill with no source (taken in from an agent's folder)
by that name with the very same files. Another skill from GitHub or a
git repository whose name is taken goes in beside it as
<name>-<owner> (skill-creator-openai), then owner-repo, repo, a number,
at most 64 bytes (freeSkillName in skill_beside.go). The library's copy
of its SKILL.md gets that name in the front matter's top-level name:
line (nameSkill), so no agent sees two skills by one name; Skill.Called
keeps the name it came with, and the carried bundle carries it. Its hash
is of the renamed copy, and checks (GitHub and git) and updates compare
what they fetch renamed the same way (fetchedHash), so it doesn't read
as edited and an update keeps the name.
The class: probe (Candidate.Have now means this skill; Candidate.As is
the name it has or would get), installFrom (listed and unlisted folder
by that name), the new-skills check (no longer drops a skill because
its name is taken), the market's had check (by name only for a skill
with no repository: none or a folder), carry, the TUI's probe list and
the GUI's probe list ("adds as {name}" with why in its title, "In the
library as {name}"; zh, zh-TW, ja, de; the tag is cut short in its row).
Old data: nothing is renamed. A skill already in the library keeps its
name, folder, SKILL.md and agent links; library.json without "called"
reads as before. Only a skill added from now on can get another name.
Not changed: a folder of the user's own is linked as it is and its
SKILL.md can't be named apart, so one by a taken name is still skipped,
now saying to rename it in its SKILL.md; and an agent's own skills
folder still holds one skill per name (an agent's own skill by the
library's name is settled by Use library / Keep agent's as before).
Run (mote, at c6fd4b37c on origin/main 6a900e0d0, then rebased on
0fe9f97c1, which touches only claudetui, gui and provider):
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./..., go build ./..., go build -tags nogui:
clean.
- go test -tags nogui -count=1 -timeout 45m ./...: 82 packages ok,
internal/gui red only in TestSettingsSaveKeepsWhatItDoesNotSend
(SearchAll, #4514, open on main, not this change).
- After the rebase: internal/library and internal/tui ok.
- GUI, both engines: skill-install-beside (new), every skill-*,
library-*, found-skill-*, remove-found-*, mcp-*, i18n-keys, gui-ja,
gui-de, gui-zh-tw, font-cascade, inner-scroll-contain, win-fonts:
1427 tests, 1423 pass. The 4 reds fail the same at origin/main
3baf3b6df run alone: gui-ja (#4580), i18n-keys "Unmarked" (#4524),
library-row-remove chromium (#3099).
Red on the old code: the anthropics-then-openai install against
origin/main code fails with "the library already has another skill
called skill-creator, left as it is". Broken by hand: fetchedHash made
to hash the fetched files unrenamed turns
TestSameNameFromAnotherSourceGoesInBeside red (hash mismatch); the
.lib-pick > .lib-tag rule removed turns skill-install-beside red ("the
tag stays in its row") in both widths.
Not tried: real anthropics/skills and openai/skills installs in a
sandbox HOME (the tests serve both repositories' layouts as tarballs;
the fixtures put both at skills/skill-creator. The real openai/skills
keeps it under skills/.system, which a probe of the repository's top
doesn't walk into; that is how probing has been and isn't changed
here); Windows and Linux runs of the GUI.
160 lines
6.7 KiB
Go
160 lines
6.7 KiB
Go
package library
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// cavemanRepo serves a repository of three skills, as GitHub's tarball.
|
|
func cavemanRepo(t *testing.T) {
|
|
t.Helper()
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write(tarball(t, map[string]string{
|
|
"skills/caveman/SKILL.md": "---\nname: caveman\ndescription: Talk like caveman\n---\n",
|
|
"skills/caveman-commit/SKILL.md": "---\nname: caveman-commit\ndescription: Commit like caveman\n---\n",
|
|
"skills/caveman-review/SKILL.md": "---\nname: caveman-review\ndescription: Review like caveman\n---\n",
|
|
}))
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
old := tarballURL
|
|
tarballURL = func(repo, ref string) string { return srv.URL + "/" + repo + "/" + ref }
|
|
t.Cleanup(func() { tarballURL = old })
|
|
}
|
|
|
|
func skipped(r *Result) []string {
|
|
var out []string
|
|
for _, p := range r.Skipped {
|
|
out = append(out, strings.TrimPrefix(p.What, "skill:"))
|
|
}
|
|
return out
|
|
}
|
|
|
|
// lc on Discord (安装skills的时候,没有跳过已经安装的): installing a set
|
|
// of skills stopped at the first one the library's folder already had
|
|
// ("the library's folder already has a caveman-commit in it"), and none
|
|
// of the set was installed. The rest of the set is installed; the one in
|
|
// the way is skipped and said, its folder as the user left it.
|
|
func TestInstallSetSkipsOneInTheWay(t *testing.T) {
|
|
sandbox(t)
|
|
cavemanRepo(t)
|
|
// caveman installed before, then edited by the user
|
|
ok(t)(InstallSkills("owner/caveman", []string{"skills/caveman"}, []string{"claude"}))
|
|
edited := "---\nname: caveman\ndescription: mine now\n---\n"
|
|
write(t, filepath.Join(skillDir("caveman"), "SKILL.md"), edited)
|
|
// a caveman-commit of the user's own in the library's folder, not listed
|
|
mine := "---\nname: caveman-commit\ndescription: my own\n---\n"
|
|
write(t, filepath.Join(skillDir("caveman-commit"), "SKILL.md"), mine)
|
|
write(t, filepath.Join(skillDir("caveman-commit"), "notes.md"), "keep me")
|
|
|
|
r := ok(t)(InstallSkills("owner/caveman", []string{"skills/caveman", "skills/caveman-commit", "skills/caveman-review"}, []string{"claude"}))
|
|
// the repository's caveman-commit goes in beside the user's, by a
|
|
// name of its own (mora1n on Discord)
|
|
if !slices.Equal(r.Installed, []string{"caveman-commit-owner", "caveman-review"}) {
|
|
t.Errorf("installed %v", r.Installed)
|
|
}
|
|
if !slices.Equal(r.Had, []string{"caveman"}) {
|
|
t.Errorf("had %v", r.Had)
|
|
}
|
|
if len(r.Skipped) != 0 {
|
|
t.Errorf("skipped %+v", r.Skipped)
|
|
}
|
|
if got := read(t, filepath.Join(skillDir("caveman"), "SKILL.md")); got != edited {
|
|
t.Errorf("the user's edit to caveman was written over: %q", got)
|
|
}
|
|
if got := read(t, filepath.Join(skillDir("caveman-commit"), "SKILL.md")); got != mine {
|
|
t.Errorf("the user's caveman-commit was written over: %q", got)
|
|
}
|
|
if got := read(t, filepath.Join(skillDir("caveman-commit"), "notes.md")); got != "keep me" {
|
|
t.Errorf("the user's caveman-commit lost a file: %q", got)
|
|
}
|
|
l, _ := load()
|
|
if l.skill("caveman-review") == nil {
|
|
t.Error("caveman-review isn't in the library")
|
|
}
|
|
if l.skill("caveman-commit") != nil {
|
|
t.Error("the user's own caveman-commit was listed as the repository's")
|
|
}
|
|
if s := l.skill("caveman-commit-owner"); s == nil || s.Called != "caveman-commit" || s.Source.Path != "skills/caveman-commit" {
|
|
t.Errorf("the repository's caveman-commit is %+v", s)
|
|
}
|
|
|
|
// a set whose every skill is had already is no error
|
|
r = ok(t)(InstallSkills("owner/caveman", []string{"skills/caveman", "skills/caveman-review"}, []string{"claude"}))
|
|
if len(r.Installed) != 0 || len(r.Had) != 2 {
|
|
t.Errorf("again: installed %v had %v", r.Installed, r.Had)
|
|
}
|
|
// one skill alone that can't be installed still fails, saying why
|
|
if _, err := InstallSkills("owner/caveman", []string{"skills/nowhere"}, nil); err == nil || !strings.Contains(err.Error(), "no skill at") {
|
|
t.Errorf("alone: %v", err)
|
|
}
|
|
// the market's install of one the library has is had, not an error
|
|
r = ok(t)(InstallMarketSkill("owner/caveman", "caveman", []string{"claude"}))
|
|
if !slices.Equal(r.Had, []string{"caveman"}) {
|
|
t.Errorf("market: had %v", r.Had)
|
|
}
|
|
}
|
|
|
|
// An install that copied a skill and then stopped before the library was
|
|
// saved left its folder unlisted, in the way of every later try. A folder
|
|
// holding exactly the skill's files is listed where it is; nothing in it
|
|
// is written.
|
|
func TestInstallListsItsOwnLeftoverFolder(t *testing.T) {
|
|
sandbox(t)
|
|
cavemanRepo(t)
|
|
p, err := ProbeSkills("owner/caveman")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := copyDir(filepath.Join(p.root, "skills", "caveman-commit"), skillDir("caveman-commit")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := ok(t)(InstallSkills("owner/caveman", []string{"skills/caveman-commit", "skills/caveman-review"}, []string{"claude"}))
|
|
if !slices.Equal(r.Installed, []string{"caveman-review"}) || !slices.Equal(r.Had, []string{"caveman-commit"}) || len(r.Skipped) != 0 {
|
|
t.Errorf("installed %v had %v skipped %+v", r.Installed, r.Had, r.Skipped)
|
|
}
|
|
l, _ := load()
|
|
s := l.skill("caveman-commit")
|
|
if s == nil || s.Source == nil || s.Source.Repo != "owner/caveman" || s.Source.Path != "skills/caveman-commit" || s.Hash == "" {
|
|
t.Fatalf("caveman-commit: %+v", s)
|
|
}
|
|
if !ours(filepath.Join(os.Getenv("HOME"), ".claude/skills/caveman-commit"), "caveman-commit") {
|
|
t.Error("claude wasn't given caveman-commit")
|
|
}
|
|
}
|
|
|
|
// A skill by that name the library lists from somewhere else is another
|
|
// skill: it stays as it is, and the repository's goes in beside it by a
|
|
// name of its own (mora1n on Discord).
|
|
func TestInstallSetPutsAnotherByTheSameNameBeside(t *testing.T) {
|
|
h := sandbox(t)
|
|
cavemanRepo(t)
|
|
src := filepath.Join(h, "src")
|
|
skill(t, filepath.Join(src, "caveman"), "caveman", "Another caveman")
|
|
ok(t)(InstallSkills(src, []string{"caveman"}, []string{"claude"}))
|
|
|
|
r := ok(t)(InstallSkills("owner/caveman", []string{"skills/caveman", "skills/caveman-review"}, []string{"claude"}))
|
|
if !slices.Equal(r.Installed, []string{"caveman-owner", "caveman-review"}) || len(r.Skipped) != 0 {
|
|
t.Errorf("installed %v skipped %+v", r.Installed, r.Skipped)
|
|
}
|
|
l, _ := load()
|
|
if s := l.skill("caveman"); s == nil || s.Source == nil || s.Source.Kind != "folder" {
|
|
t.Errorf("caveman is now %+v", s)
|
|
}
|
|
if got := read(t, filepath.Join(skillDir("caveman"), "SKILL.md")); !strings.Contains(got, "Another caveman") {
|
|
t.Errorf("caveman's SKILL.md is now %q", got)
|
|
}
|
|
if got := read(t, filepath.Join(skillDir("caveman-owner"), "SKILL.md")); !strings.HasPrefix(got, "---\nname: caveman-owner\n") || !strings.Contains(got, "Talk like caveman") {
|
|
t.Errorf("caveman-owner's SKILL.md is %q", got)
|
|
}
|
|
for _, n := range []string{"caveman", "caveman-owner"} {
|
|
if !ours(filepath.Join(h, ".claude/skills", n), n) {
|
|
t.Errorf("claude wasn't given %s", n)
|
|
}
|
|
}
|
|
}
|