Files
magpie/internal/library/skill_manual_test.go
T
yetone adcb69107c library: a skill set to disable-model-invocation is marked Manual only
sunset3279 on Discord asked to see which skills set
disable-model-invocation: true in their SKILL.md, the ones Claude Code
runs only when the user types /name. parseMeta reads the field into
meta.Manual; the library's rows (SkillView.Manual) and the agents' own
(FoundSkill.Manual) carry it, and the page puts a quiet "Manual only"
tag after the name, its tooltip naming /name and the field. A front
matter that doesn't parse, or a value that isn't a bool, is not known
to be manual: no tag. Translated in zh, zh-TW, ja and de.

Run (mote, through mote-run):
- go test -run 'TestSkillManualFromFrontMatter|TestSkillsFromFolder|TestFoundInLibraryFolder' ./internal/library: ok
- node --test internal/gui/tests/skill-manual.test.cjs: 22 pass, 0 fail
  (en, zh, zh-TW, ja, de at 420 and 1180 px, Chromium and WebKit)
- go test ./internal/library: ok (692s)
- go vet ./internal/library for darwin, windows and linux (nogui): ok
- node --test i18n-keys and i18n-en-no-cjk: 7 pass, 1 fail. The fail is
  "a plugin's words are its own", the same three entries on origin/main
  fe61503e6 (#5327, #5426, #5482); none is a word of this change.

Broken by hand:
- the Manual assignments in sync.go and skills.go taken out:
  TestSkillManualFromFrontMatter red ("deploy: manual false, want
  true", "crlf: …", "release: {…Manual:false…}").
- the manualTag calls in client.js taken out: all 22 GUI cases red
  (null, want 'Manual only').
- an explicit error branch in parseMeta was tried and left out: the test
  passed with and without it, since yaml.v3 decodes nothing on a syntax
  error and leaves a wrong-typed field zero.

Not tried: the real app with the user's own skills; the TUI and CLI show
no mark. A long name clips its tag in a narrow window, as every name tag
in the row does (.row .name is nowrap; #5512); the test uses short names.

Reported-by: sunset3279 (Discord)
2026-11-06 22:22:20 +08:00

64 lines
2.5 KiB
Go

package library
import (
"path/filepath"
"testing"
)
// sunset3279 on Discord: a skill whose SKILL.md sets
// disable-model-invocation is one Claude Code runs only when the user types
// /name. The page marks it, in the library and among the agents' own; one
// whose front matter doesn't parse is not known to be, so it isn't marked,
// and its name and description are read as before.
func TestSkillManualFromFrontMatter(t *testing.T) {
h := sandbox(t)
src := filepath.Join(h, "src/skills")
front := map[string]string{
"deploy": "---\nname: deploy\ndescription: Ship it\ndisable-model-invocation: true\n---\n",
"lint": "---\nname: lint\ndescription: Lint\ndisable-model-invocation: false\n---\n",
"plain": "---\nname: plain\ndescription: Plain\n---\n",
"crlf": "---\r\nname: crlf\r\ndescription: Windows\r\ndisable-model-invocation: true\r\n---\r\n",
"broken": "---\nname: broken\ndescription: Broken\ndisable-model-invocation: true\nallowed-tools: [a\n---\n",
"notbool": "---\nname: notbool\ndescription: Odd\ndisable-model-invocation: sometimes\n---\n",
}
for name, md := range front {
write(t, filepath.Join(src, name, "SKILL.md"), md)
}
// one Claude Code has of its own, not in the library
write(t, filepath.Join(h, ".claude/skills/release/SKILL.md"), "---\nname: release\ndescription: Cut a release\ndisable-model-invocation: true\n---\n")
write(t, filepath.Join(h, ".claude/skills/notes/SKILL.md"), "---\nname: notes\ndescription: Notes\n---\n")
ok(t)(InstallSkills(src, []string{"deploy", "lint", "plain", "crlf", "broken", "notbool"}, []string{"codex"}))
v, err := Read(nil)
if err != nil {
t.Fatal(err)
}
want := map[string]bool{"deploy": true, "lint": false, "plain": false, "crlf": true, "broken": false, "notbool": false}
got := map[string]bool{}
for _, s := range v.Skills {
got[s.Name] = s.Manual
if w, ok := want[s.Name]; ok && s.Manual != w {
t.Errorf("%s: manual %v, want %v", s.Name, s.Manual, w)
}
}
for name := range want {
if _, ok := got[name]; !ok {
t.Errorf("%s isn't in the library: %+v", name, v.Skills)
}
}
found := map[string]FoundSkill{}
for _, f := range v.FoundSkills {
found[f.Name] = f
}
if f, ok := found["release"]; !ok || !f.Manual {
t.Errorf("release: %+v", f)
}
if f, ok := found["notes"]; !ok || f.Manual {
t.Errorf("notes: %+v", f)
}
// a front matter that does not parse is not known to be manual
if m := parseMeta([]byte(front["broken"])); m.Manual {
t.Errorf("broken: %+v", m)
}
}