スライム on Discord (#help, 10-22): taste-skills took some of its skills
out, Update all reported each of them as a failure, and the only way
out was to delete them one by one.
An update or a check that reads the source whole and finds the skill's
folder (or its SKILL.md) gone now calls it removed upstream, not a
failure. GitHub tarballs and other git repositories both work this way.
- UpdateSkill returns *GoneError.
- UpdateSkills and UpdateSomeSkills list it in Result.Gone, not
Unupdated.
- A check gives status "gone".
- Each marks Skill.Gone. The mark is cleared when a check or an update
finds the skill there again.
- A fetch that failed, a skill left out of a fetch as too big, and a
folder that can't be read stay unknown, never gone (goneFrom).
Nothing is deleted by itself. RemoveGoneSkills takes the named skills
out, or every marked one when none are named, through RemoveSkills, so
the folders go to the backups. A skill found in its source again is
kept and said so.
- GUI: a "Removed upstream" tag replaces Update available and the
update icon. Update all says gone skills apart from failures. "Clean
up N" sits in the group heading, or in the bar when there is one
group, and opens a sheet naming each skill. One changed here carries
"Changed here". Strings are in en, zh, zh-TW, ja and de.
- CLI: `magpie library skill rm --gone [--yes]` asks at a terminal and
refuses without --yes otherwise. It names the ones changed here.
update and status print the hint.
- TUI: the row says "removed from <repo> · d takes it out".
- API: POST /api/library/skills/remove-gone {names}.
- Docs: the Skill updates row and Verification in
docs/subsystems/library.md.
Record for this push: 13 commits on origin/main ca4a1cde0, head tree
539c84e92. Go 1.26.8, sandbox HOME, GOMODCACHE/GOCACHE pinned. The full Go
run and vet were at tree d6393dfc8, the same Go code as this head: only
app.js comments (cut under the core script budget) and one ja string
changed after it.
- gofmt -l: nothing. go build ./...; go vet ./... (darwin), GOOS=linux
go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./..., through tee, one suite on the machine:
68 packages ok. The one red was internal/gui's
TestCoreScriptBudget: app.js 1,335,314 > 1,335,000, since main grew
app.js under the stack. The autoscroll commit's own comments were cut
(to 1,334,629) rather than the budget raised, and go test -count=1
./internal/gui is ok at this head (113s). Packages the run took from
Go's test cache had the same inputs.
- GUI: the 18 files this stack touches or names, both engines,
202 of 204 pass (tree 068acf128, this push less the last commit). The
two reds: gui-ja, red on main since c2636b7b5 and fixed by this push's
last commit (gui-ja and i18n-keys 6 of 6 there), and usage-fold's
chromium "several accounts" (#2163, red on main the same way).
- skill-gone passes, chromium and webkit, en and zh, 860 and 400px.
- internal/library, internal/cli and internal/tui ok, the Gone tests and
TestLibrarySkillRm among them.
- The rebase onto main met c2636b7b5's Verification line in library.md;
both sides' tests are kept in it.
The whole GUI suite ran at 1c1fc7183 (this stack's first 12 commits on
0ddcf28a1): 11713 of 11769 pass. Each of the 21 red files was then run
alone at the stack and at origin/main 8278fd9b0. Eight are red the same
way on main: plugin-card-update (#3079), quota-count-wrap and
quota-name-translated (#2228), s3-sync (#2448), usage-agents-hide
(#2276), usage-checkin (#3091), usage-fold's chromium "several
accounts" (#2163), usage-ledger (#3104). The other 13 pass alone on both
and were red only under that run's load (50 to 335): currency #3101,
plugin-github #3218, provider-fetch-again #3292, rest-try-now #2564,
routing-auto-reset #3293, routing-keys-fold #1612, routing-steady #1804,
routing-wb-restricted #1905, sessions-folder-delete #2218,
sessions-manage #3294, switch-only #3295, text-size #1866, usage-pack
#3296.
Broken by hand, each red, then restored:
- prepare not returning GoneError
- apply not clearing Gone
- leftOutAt ignored
- every Stat error read as absent
- the git check not saying gone
- RemoveGoneSkills taking a skill that isn't marked
Not tried:
- the real taste-skills repo over the network
- the Windows box
- a skill CC Switch installed (Origin, adopt path), which still reports
as a failure
- a GitHub check with a known commit, which keeps an existing gone
mark but only marks gone after an update
255 lines
8.5 KiB
Go
255 lines
8.5 KiB
Go
package library
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"slices"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
// スライム on Discord: a repository took some of its skills out, and
|
|
// Update all said each of them failed, with no way to take them all out
|
|
// but one by one. An update that reads the repository and finds a skill
|
|
// gone says so apart from failures, marks it, and every skill so marked
|
|
// goes at once, asked for. A repository that couldn't be fetched says
|
|
// nothing of whether its skills are gone.
|
|
func TestUpdateFindsSkillsRemovedUpstream(t *testing.T) {
|
|
h := sandbox(t)
|
|
removed, down := false, false
|
|
var amu sync.Mutex
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
amu.Lock()
|
|
defer amu.Unlock()
|
|
if down && strings.Contains(r.URL.Path, "other") {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
files := map[string]string{
|
|
"skills/pdf/SKILL.md": "---\nname: pdf\ndescription: PDFs\n---\n",
|
|
"skills/pdf/forms.md": "forms",
|
|
"skills/docx/SKILL.md": "---\nname: docx\ndescription: Word\n---\n",
|
|
"skills/slides/SKILL.md": "---\nname: slides\ndescription: Slides\n---\n",
|
|
"x/SKILL.md": "---\nname: x\ndescription: X\n---\n",
|
|
}
|
|
if removed {
|
|
delete(files, "skills/docx/SKILL.md")
|
|
delete(files, "skills/slides/SKILL.md")
|
|
files["skills/pdf/forms.md"] = "forms two"
|
|
}
|
|
w.Write(tarball(t, files))
|
|
}))
|
|
defer srv.Close()
|
|
old := tarballURL
|
|
tarballURL = func(repo, ref string) string { return srv.URL + "/" + repo + "/" + ref }
|
|
defer func() { tarballURL = old }()
|
|
|
|
// repositories no other test probes: a probe is kept for an install
|
|
// from it, so another test's owner/repo would be installed from here
|
|
ok(t)(InstallSkills("owner/taken", []string{"skills/pdf", "skills/docx", "skills/slides"}, []string{"claude"}))
|
|
ok(t)(InstallSkills("owner/taken-other", []string{"x"}, []string{"claude"}))
|
|
if v, _ := Read(nil); len(v.Skills) != 4 {
|
|
t.Fatalf("installed %d skills, want 4", len(v.Skills))
|
|
}
|
|
// slides is changed here: it is still said to be gone, and the page
|
|
// says it was changed
|
|
write(t, filepath.Join(skillDir("slides"), "SKILL.md"), "---\nname: slides\ndescription: mine\n---\n")
|
|
amu.Lock()
|
|
removed, down = true, true
|
|
amu.Unlock()
|
|
|
|
res, err := UpdateSkills()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !slices.Equal(res.Updated, []string{"pdf"}) {
|
|
t.Errorf("updated %v", res.Updated)
|
|
}
|
|
if !slices.Equal(res.Gone, []string{"docx", "slides"}) {
|
|
t.Errorf("gone %v", res.Gone)
|
|
}
|
|
// x's repository couldn't be fetched: a failure, not gone
|
|
if len(res.Unupdated) != 1 || res.Unupdated[0].What != "skill:x" {
|
|
t.Errorf("unupdated %+v", res.Unupdated)
|
|
}
|
|
v, _ := Read(nil)
|
|
for _, s := range v.Skills {
|
|
gone := s.Name == "docx" || s.Name == "slides"
|
|
if (s.Gone != "") != gone {
|
|
t.Errorf("%s: gone %q", s.Name, s.Gone)
|
|
}
|
|
if gone && (s.Check == nil || s.Check.Status != "gone" || !strings.Contains(s.Check.Error, "owner/taken")) {
|
|
t.Errorf("%s: check %+v", s.Name, s.Check)
|
|
}
|
|
if s.Name == "slides" && !s.Edited {
|
|
t.Error("slides, changed here, isn't said to be")
|
|
}
|
|
}
|
|
// nothing is taken out by itself
|
|
for _, n := range []string{"docx", "slides"} {
|
|
if _, err := os.Stat(filepath.Join(skillDir(n), "SKILL.md")); err != nil {
|
|
t.Errorf("%s went by itself: %v", n, err)
|
|
}
|
|
}
|
|
|
|
// one named that isn't gone is kept, and said
|
|
if _, err := RemoveGoneSkills([]string{"pdf"}); err == nil || !strings.Contains(err.Error(), "in its source again") {
|
|
t.Errorf("pdf, still in its source: %v", err)
|
|
}
|
|
r := ok(t)(RemoveGoneSkills(nil))
|
|
if len(r.Unremoved) != 0 {
|
|
t.Errorf("unremoved %+v", r.Unremoved)
|
|
}
|
|
v, _ = Read(nil)
|
|
var left []string
|
|
for _, s := range v.Skills {
|
|
left = append(left, s.Name)
|
|
}
|
|
if !slices.Equal(left, []string{"pdf", "x"}) {
|
|
t.Errorf("left %v", left)
|
|
}
|
|
for _, n := range []string{"docx", "slides"} {
|
|
if _, err := os.Lstat(filepath.Join(h, ".claude/skills", n)); !os.IsNotExist(err) {
|
|
t.Errorf("claude still has %s", n)
|
|
}
|
|
}
|
|
// the changed one's folder is with the backups, as Remove keeps it
|
|
kept, _ := filepath.Glob(filepath.Join(BackupDir(), "*", "skills", "slides", "SKILL.md"))
|
|
if len(kept) != 1 || !strings.Contains(read(t, kept[0]), "mine") {
|
|
t.Errorf("slides in the backups: %v", kept)
|
|
}
|
|
if _, err := RemoveGoneSkills(nil); err == nil {
|
|
t.Error("with nothing gone, nothing to say")
|
|
}
|
|
}
|
|
|
|
// A skill marked gone that its repository has again is updated, and the
|
|
// mark goes.
|
|
func TestSkillBackUpstreamIsNotGone(t *testing.T) {
|
|
sandbox(t)
|
|
removed := false
|
|
var amu sync.Mutex
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
amu.Lock()
|
|
defer amu.Unlock()
|
|
files := map[string]string{"skills/a/SKILL.md": "---\nname: a\ndescription: A\n---\n", "skills/b/SKILL.md": "---\nname: b\ndescription: B\n---\n"}
|
|
if removed {
|
|
delete(files, "skills/b/SKILL.md")
|
|
}
|
|
w.Write(tarball(t, files))
|
|
}))
|
|
defer srv.Close()
|
|
old := tarballURL
|
|
tarballURL = func(repo, ref string) string { return srv.URL + "/" + repo + "/" + ref }
|
|
defer func() { tarballURL = old }()
|
|
|
|
ok(t)(InstallSkills("owner/back", []string{"skills/a", "skills/b"}, nil))
|
|
amu.Lock()
|
|
removed = true
|
|
amu.Unlock()
|
|
_, err := UpdateSkill("b", false)
|
|
var gone *GoneError
|
|
if !errors.As(err, &gone) || gone.Name != "b" || gone.Source != "owner/back" {
|
|
t.Fatalf("update of a skill removed there: %v", err)
|
|
}
|
|
if l, _ := load(); l.skill("b").Gone == "" {
|
|
t.Fatal("not marked")
|
|
}
|
|
amu.Lock()
|
|
removed = false
|
|
amu.Unlock()
|
|
ok(t)(UpdateSkill("b", false))
|
|
if l, _ := load(); l.skill("b").Gone != "" {
|
|
t.Error("still marked once its source has it again")
|
|
}
|
|
if c := lastCheck("b"); c != nil && c.Status == "gone" {
|
|
t.Errorf("check %+v", c)
|
|
}
|
|
if _, err := RemoveGoneSkills([]string{"b"}); err == nil {
|
|
t.Error("b, back in its source, was taken out")
|
|
}
|
|
}
|
|
|
|
// A skill of another git repository, removed there: an update and a check
|
|
// both say so, and it goes at once when asked.
|
|
func TestGitSkillRemovedUpstream(t *testing.T) {
|
|
sandbox(t)
|
|
addr, commit := gitRepo(t, map[string]string{
|
|
"skills/a/SKILL.md": "---\nname: a\ndescription: A\n---\nv1\n",
|
|
"skills/b/SKILL.md": "---\nname: b\ndescription: B\n---\n",
|
|
})
|
|
ok(t)(InstallSkills(addr, []string{"skills/a", "skills/b"}, []string{"claude"}))
|
|
commit(map[string]string{"skills/b": gitRemoved, "skills/a/SKILL.md": "---\nname: a\ndescription: A\n---\nv2\n"})
|
|
|
|
checks, err := CheckSkills()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, c := range checks {
|
|
want := map[string]string{"a": "update", "b": "gone"}[c.Name]
|
|
if c.Status != want {
|
|
t.Errorf("check of %s: %+v, want %s", c.Name, c, want)
|
|
}
|
|
}
|
|
if l, _ := load(); l.skill("b").Gone == "" {
|
|
t.Error("the check didn't mark b")
|
|
}
|
|
res := ok(t)(UpdateSkills())
|
|
if !slices.Equal(res.Updated, []string{"a"}) || !slices.Equal(res.Gone, []string{"b"}) || len(res.Unupdated) != 0 {
|
|
t.Errorf("updated %v, gone %v, unupdated %+v", res.Updated, res.Gone, res.Unupdated)
|
|
}
|
|
ok(t)(RemoveGoneSkills([]string{"b"}))
|
|
if l, _ := load(); l.skill("b") != nil || l.skill("a") == nil {
|
|
t.Errorf("after removing: %+v", l.Skills)
|
|
}
|
|
}
|
|
|
|
// Only a source read whole says a skill is gone: one left out of a fetch
|
|
// as too big is there, and a folder that can't be read is unknown.
|
|
func TestGoneFromNeedsTheSourceRead(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
write(t, filepath.Join(tmp, "skills/here/SKILL.md"), "---\nname: here\n---\n")
|
|
write(t, filepath.Join(tmp, "skills/file"), "not a folder")
|
|
if err := os.MkdirAll(filepath.Join(tmp, "skills/empty"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for path, want := range map[string]bool{
|
|
"skills/here": false,
|
|
"skills/missing": true,
|
|
"skills/file": true, // a file where the skill's folder was
|
|
"skills/empty": true, // a folder that is no skill any more
|
|
"nothing/at/all": true,
|
|
} {
|
|
if got := goneFrom(tmp, path); got != want {
|
|
t.Errorf("%s: gone %v, want %v", path, got, want)
|
|
}
|
|
}
|
|
leftOut.Lock()
|
|
leftOut.m[tmp] = []LeftOut{{Path: "skills/big", Size: 300 << 20}}
|
|
leftOut.Unlock()
|
|
t.Cleanup(func() { leftOut.Lock(); delete(leftOut.m, tmp); leftOut.Unlock() })
|
|
if goneFrom(tmp, "skills/big") {
|
|
t.Error("a skill left out as too big was called gone")
|
|
}
|
|
if len(leftOut.m[tmp]) != 1 {
|
|
t.Error("asking forgot what was left out")
|
|
}
|
|
if runtime.GOOS == "windows" || os.Getuid() == 0 {
|
|
return
|
|
}
|
|
locked := filepath.Join(tmp, "skills/locked")
|
|
write(t, filepath.Join(locked, "SKILL.md"), "x")
|
|
if err := os.Chmod(locked, 0o000); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { os.Chmod(locked, 0o755) })
|
|
if goneFrom(tmp, "skills/locked") {
|
|
t.Error("a folder that couldn't be read was called gone")
|
|
}
|
|
}
|