Files
magpie/internal/cli/library_rm_gone_test.go
T
yetone c417b1f4e3 library: a skill removed from its source is said so, and every such skill goes in one click, asked first
スライム 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
2026-10-23 01:58:00 +08:00

115 lines
3.7 KiB
Go

package cli
import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/yetone/magpie/internal/library"
)
// magpie library skill rm --gone (スライム on Discord): an update says the
// skills its source no longer has apart from failures, and rm --gone takes
// every one of them out, asked first; with nobody at a terminal, only with
// --yes. A skill still in its source stays.
func TestLibrarySkillRmGone(t *testing.T) {
git, err := exec.LookPath("git")
if err != nil {
t.Skip("git isn't installed")
}
h := t.TempDir()
for k, v := range map[string]string{"HOME": h, "USERPROFILE": h, "XDG_CONFIG_HOME": filepath.Join(h, ".config"), "CLAUDE_CONFIG_DIR": "", "CODEX_HOME": "", "APPDATA": "", "LOCALAPPDATA": "",
"GIT_CONFIG_NOSYSTEM": "1", "GIT_CONFIG_GLOBAL": filepath.Join(h, "gitconfig")} {
t.Setenv(k, v)
}
write := func(p, s string) {
if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(p, []byte(s), 0o644); err != nil {
t.Fatal(err)
}
}
write(filepath.Join(h, ".claude/settings.json"), "")
bare, work := filepath.Join(h, "skills.git"), filepath.Join(h, "work")
run := func(dir string, args ...string) {
t.Helper()
cmd := exec.Command(git, append([]string{"-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "init.defaultBranch=main", "-c", "commit.gpgsign=false"}, args...)...)
cmd.Dir = dir
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("git %v: %v\n%s", args, err, out)
}
}
run(h, "init", "-q", "--bare", bare)
run(h, "init", "-q", work)
for _, n := range []string{"pdf", "docx"} {
write(filepath.Join(work, "skills", n, "SKILL.md"), "---\nname: "+n+"\ndescription: "+n+"\n---\n")
}
push := func() {
run(work, "add", "-A")
run(work, "commit", "-q", "-m", "skills")
run(work, "push", "-q", bare, "HEAD:refs/heads/main")
}
push()
addr := filepath.ToSlash(bare)
if !strings.HasPrefix(addr, "/") {
addr = "/" + addr
}
if _, err := library.InstallSkills("file://"+addr, []string{"skills/pdf", "skills/docx"}, []string{"claude"}); err != nil {
t.Fatal(err)
}
if err := os.RemoveAll(filepath.Join(work, "skills", "docx")); err != nil {
t.Fatal(err)
}
push()
if err := libraryCmd([]string{"library", "skill", "update"}); err != nil {
t.Fatal(err)
}
gone := func() (out []string) {
v, _ := library.Read(nil)
for _, s := range v.Skills {
if s.Gone != "" {
out = append(out, s.Name)
}
}
return out
}
if g := gone(); len(g) != 1 || g[0] != "docx" {
t.Fatalf("marked gone after update: %v", g)
}
// one asked for by name is said, not failed
if err := libraryCmd([]string{"library", "skill", "update", "docx"}); err != nil {
t.Errorf("update of a skill removed upstream: %v", err)
}
err = libraryCmd([]string{"library", "skill", "rm", "--gone"})
if err == nil || !strings.Contains(err.Error(), "--yes") {
t.Fatalf("with no terminal and no --yes: %v", err)
}
if v, _ := library.Read(nil); len(v.Skills) != 2 {
t.Fatalf("taken without asking: %d left", len(v.Skills))
}
if err := libraryCmd([]string{"library", "skill", "rm", "--gone", "--nope"}); err == nil {
t.Error("an unknown flag was taken")
}
if err := libraryCmd([]string{"library", "skill", "rm", "--gone", "--yes"}); err != nil {
t.Fatal(err)
}
v, _ := library.Read(nil)
if len(v.Skills) != 1 || v.Skills[0].Name != "pdf" {
t.Errorf("left: %+v", v.Skills)
}
if _, err := os.Lstat(filepath.Join(h, ".claude/skills/docx")); !os.IsNotExist(err) {
t.Error("claude still has docx")
}
if _, err := os.Lstat(filepath.Join(h, ".claude/skills/pdf")); err != nil {
t.Errorf("pdf, still in its source, went: %v", err)
}
if err := libraryCmd([]string{"library", "skill", "rm", "--gone", "--yes"}); err != nil {
t.Errorf("nothing gone: %v", err)
}
}