Files
magpie/internal/library/skillnew_place_test.go
T
yetone 77bda84a6f library: a check offers the skills a git repository or folder added since
refeccd (Discord): skills added from a repository or a folder only had
the existing ones updated; ones the source added later never reached
the library. GitHub sources already had this (findNew); git repositories
on other hosts and folders on this machine did not, and a folder install
didn't even remember the folder it came from.

- git: when ls-remote gives the ref a head, findNewGit reads the fetch
  the check shares and offers skills under newBase that the library
  doesn't have and hasn't offered. Once per head while its finds are
  kept (gitLooked). The address is kept as the library has it (.git and
  all), so an Add lands on the same repo@ref key.
- folder: an install from a folder now records "folder:<path>" in
  SeenSkills (offered), which is how the library knows where to look
  again. findNewFolder reads it as Add from folder does and skips a
  folder the library links, has offered, or has a skill by that name of.
- A check never adds or writes a skill: each is offered with Add and
  Ignore, as GitHub's are. A skill the user removed or set aside isn't
  offered again, and a folder edit is never written over.
- View.CheckFolders shows Check for updates with only linked skills and
  makes checkDue true; its title says it looks in folders too. A find's
  row shows its folder (pathLink) or git address. The old head note
  ("on GitHub beside skills you have…") is gone; the new title is in all
  five languages.
- docs/subsystems/library.md says so.

Old data: a folder added before this kept no folder: key, so it is
looked in only after the user adds from that folder once more (the
picker then lists the new skills, and the install records the folder).

Run (mote, at fcc0daa23 plus this change):
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...; go build ./... and the CGO_ENABLED=0
  nogui build: ok.
- go test ./internal/library: ok. go test ./internal/gui: ok except
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322) and
  TestMainWindowCorners (#3949), both red the same on origin/main
  19c45d5d4 run alone.
- GUI, both engines: every library-*, skill-*, github-token,
  plugin-check-*, plugin-git, i18n-keys, i18n-en-no-cjk, gui-de,
  gui-ja, gui-zh-tw file: 1526 of 1529. Reds: i18n-keys "a plugin's
  words are its own" (#5332, #5426, #5482, red on origin/main) and
  skill-where "the switch scrolls nothing", flaky on origin/main
  19c45d5d4 too (1, 0 and 2 reds in three runs; noted on #5154).
  skill-new-in-repo's new folder case runs en and zh at 860 and 440px.

At the pushed head (rebased on origin/main 94d4866b5), again on mote:
go vet of internal/library and internal/gui, go test ./internal/library
ok, internal/gui's Budget/Size tests ok, skill-new-in-repo 4 of 4 and
i18n-keys with only the known red above.

Broken by hand: with the git branch of CheckSkills and lookInFolders
off, TestCheckSkillsFindsNewInGitRepo and TestCheckSkillsFindsNewInFolder
fail ("new: []"); with offered() not recording the picker's shown
skills, both fail offering what the picker showed ([review], [xlsx]).

Not tried: a real GitLab or intranet repository (the test uses a local
file:// bare repo with the real git); the CLI and TUI, which don't list
new skills; the Windows and Linux boxes.

Reported-by: refeccd (Discord)
2026-11-06 19:50:40 +08:00

145 lines
5.0 KiB
Go

package library
import (
"os"
"path/filepath"
"slices"
"testing"
)
// refeccd (Discord): skills added from a git repository or a folder were
// only ever updated in place; ones the repository or folder added since
// never reached the library. A check now offers them, as it does GitHub's.
func TestCheckSkillsFindsNewInGitRepo(t *testing.T) {
sandbox(t)
addr, commit := gitRepo(t, map[string]string{
"skills/pdf/SKILL.md": "---\nname: pdf\ndescription: PDFs\n---\n",
"skills/review/SKILL.md": "---\nname: review\ndescription: Reviews\n---\n",
"README.md": "hi",
})
// pdf picked, review shown and left
ok(t)(InstallSkills(addr, []string{"skills/pdf"}, []string{"claude", "codex"}))
check(t)
if got := newNames(t); len(got) != 0 {
t.Fatalf("offered what the picker showed already: %v", got)
}
commit(map[string]string{
"skills/slides/SKILL.md": "---\nname: slides\ndescription: Slides\n---\n",
"skills/notes/SKILL.md": "---\nname: notes\ndescription: Notes\n---\n",
})
check(t)
if got := newNames(t); !slices.Equal(got, []string{"notes", "slides"}) {
t.Fatalf("new: %v", got)
}
v, _ := Read(nil)
n := v.NewSkills[1]
if n.Kind != "git" || n.Repo != addr || n.Path != "skills/slides" || n.Description != "Slides" ||
!slices.Equal(n.Agents, []string{"claude", "codex"}) {
t.Errorf("new skill: %+v", n)
}
// added from the same repository, by the same address and key
ok(t)(AddNewSkills([]string{n.ID}))
l, _ := load()
s := l.skill("slides")
if s == nil || s.Source.Kind != "git" || s.Source.Repo != addr || s.Source.Path != "skills/slides" || len(s.Commit) != 40 {
t.Fatalf("added: %+v", s)
}
if !slices.Equal(s.Agents, []string{"claude", "codex"}) {
t.Errorf("added for %v", s.Agents)
}
if got := newNames(t); !slices.Equal(got, []string{"notes"}) {
t.Errorf("after adding one: %v", got)
}
// the other set aside, and one removed: neither offered again
if err := IgnoreNewSkills([]string{v.NewSkills[0].ID}); err != nil {
t.Fatal(err)
}
ok(t)(RemoveSkills([]string{"slides"}))
commit(map[string]string{"README.md": "changed"})
check(t)
if got := newNames(t); len(got) != 0 {
t.Errorf("a set-aside or removed skill offered again: %v", got)
}
l, _ = load()
if l.skill("slides") != nil || l.skill("notes") != nil {
t.Error("a check added a skill by itself")
}
}
func TestCheckSkillsFindsNewInFolder(t *testing.T) {
h := sandbox(t)
src := filepath.Join(h, "src/skills")
skill(t, filepath.Join(src, "pdf"), "pdf", "Read PDFs")
skill(t, filepath.Join(src, "xlsx"), "xlsx", "Sheets")
checkedAt.Store(0) // no check since magpie started
t.Cleanup(func() { checkedAt.Store(0) })
if v, _ := Read(nil); v.CheckFolders || checkDue(mustLoad(t)) {
t.Fatal("a check is offered with nothing to look at")
}
// pdf picked, xlsx shown and left
ok(t)(InstallSkills(src, []string{"pdf"}, []string{"claude"}))
v, _ := Read(nil)
if !v.CheckFolders || !checkDue(mustLoad(t)) {
t.Fatalf("no check offered for the folder: %v", v.CheckFolders)
}
check(t)
if got := newNames(t); len(got) != 0 {
t.Fatalf("offered what the picker showed already: %v", got)
}
// the user puts two more there (a git pull, say), and edits pdf
skill(t, filepath.Join(src, "slides"), "slides", "Slides")
skill(t, filepath.Join(src, "team/notes"), "notes", "Notes")
write(t, filepath.Join(src, "pdf/SKILL.md"), "---\nname: pdf\ndescription: Mine\n---\n")
check(t)
if got := newNames(t); !slices.Equal(got, []string{"notes", "slides"}) {
t.Fatalf("new: %v", got)
}
v, _ = Read(nil)
n := v.NewSkills[1]
if n.Kind != "folder" || n.Repo != src || n.Path != "slides" || n.ID != filepath.Join(src, "slides") ||
!slices.Equal(n.Agents, []string{"claude"}) {
t.Errorf("new skill: %+v", n)
}
ok(t)(AddNewSkills([]string{n.ID}))
l, _ := load()
s := l.skill("slides")
if s == nil || s.Source.Kind != "folder" || realDir(s.Source.Dir) != realDir(filepath.Join(src, "slides")) {
t.Fatalf("added: %+v", s)
}
if b, _ := os.ReadFile(filepath.Join(src, "pdf/SKILL.md")); string(b) != "---\nname: pdf\ndescription: Mine\n---\n" {
t.Errorf("the user's edit was written over: %q", b)
}
// set aside, removed, or a folder by a name the library has: none
// offered again
if err := IgnoreNewSkills([]string{v.NewSkills[0].ID}); err != nil {
t.Fatal(err)
}
ok(t)(RemoveSkills([]string{"slides"}))
skill(t, filepath.Join(src, "other/pdf"), "pdf", "Another pdf")
check(t)
if got := newNames(t); len(got) != 0 {
t.Errorf("offered again: %v", got)
}
// one put there later is offered; with no skill linked from the
// folder any more, nothing is, and no check is offered for it
skill(t, filepath.Join(src, "late"), "late", "Late")
check(t)
if got := newNames(t); !slices.Equal(got, []string{"late"}) {
t.Fatalf("new: %v", got)
}
ok(t)(RemoveSkills([]string{"pdf"}))
if got := newNames(t); len(got) != 0 {
t.Errorf("offered from a folder the library has no skill from: %v", got)
}
if v, _ := Read(nil); v.CheckFolders {
t.Error("a check offered with no linked skill left")
}
}