v0.3.0 761f038

bundled_test.go RawHistoryFolder

1package skills
2
3import (
4	"os"
5	"path/filepath"
6	"runtime"
7	"testing"
8)
9
10func TestLoadBundledLoadsDeclaredDirectoriesInOrder(t *testing.T) {
11	tmp := t.TempDir()
12	collectionA := filepath.Join(tmp, "extension-a", "skills")
13	collectionB := filepath.Join(tmp, "extension-b", "skills")
14	direct := filepath.Join(tmp, "extension-c", "one-skill")
15
16	writeSkill := func(dir, name, description string) {
17		t.Helper()
18		if err := os.MkdirAll(dir, 0o755); err != nil {
19			t.Fatal(err)
20		}
21		body := "---\nname: " + name + "\ndescription: " + description + "\n---\nbody\n"
22		if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte(body), 0o644); err != nil {
23			t.Fatal(err)
24		}
25	}
26
27	writeSkill(filepath.Join(collectionA, "shared"), "shared", "first declaration")
28	writeSkill(filepath.Join(collectionA, "alpha"), "alpha", "from a")
29	writeSkill(filepath.Join(collectionB, "shared"), "shared", "later declaration")
30	writeSkill(filepath.Join(collectionB, "beta"), "beta", "from b")
31	writeSkill(direct, "direct", "from a direct skill directory")
32
33	got, errs := LoadBundled([]BundledSkillDir{
34		{Dir: collectionA, Source: "extension alpha"},
35		{Dir: collectionB, Source: "extension beta"},
36		{Dir: direct, Source: "extension direct"},
37	})
38	if len(errs) != 0 {
39		t.Fatalf("LoadBundled() errors = %v", errs)
40	}
41
42	if len(got) != 4 {
43		t.Fatalf("LoadBundled() returned %d skills, want 4: %#v", len(got), got)
44	}
45	if shared := FindByName(got, "shared"); shared == nil {
46		t.Fatal("shared skill was not loaded")
47	} else {
48		if shared.Description != "first declaration" || shared.Source != "extension alpha" {
49			t.Fatalf("shared skill = %#v, want first declaration and source label", shared)
50		}
51	}
52	if beta := FindByName(got, "beta"); beta == nil || beta.Source != "extension beta" {
53		t.Fatalf("beta skill = %#v, want extension beta source", beta)
54	}
55	if directSkill := FindByName(got, "direct"); directSkill == nil {
56		t.Fatal("direct skill directory was not loaded")
57	} else if directSkill.Path != filepath.Join(direct, "SKILL.md") {
58		t.Fatalf("direct skill path = %q, want %q", directSkill.Path, filepath.Join(direct, "SKILL.md"))
59	}
60}
61
62func TestLoadBundledRejectsSkillFilesOutsideRoot(t *testing.T) {
63	tmp := t.TempDir()
64	root := filepath.Join(tmp, "extension")
65	bundle := filepath.Join(root, "skills")
66	outside := filepath.Join(tmp, "outside", "SKILL.md")
67	if err := os.MkdirAll(bundle, 0o755); err != nil {
68		t.Fatal(err)
69	}
70	if err := os.MkdirAll(filepath.Dir(outside), 0o755); err != nil {
71		t.Fatal(err)
72	}
73	if err := os.WriteFile(outside, []byte("---\nname: escape\ndescription: outside\n---\nbody\n"), 0o644); err != nil {
74		t.Fatal(err)
75	}
76	got, errs := LoadBundled([]BundledSkillDir{{Dir: filepath.Dir(outside), Root: root, Source: "extension test"}})
77	if len(errs) == 0 || len(got) != 0 {
78		t.Fatalf("outside bundle was accepted: skills=%#v errors=%v", got, errs)
79	}
80	if runtime.GOOS == "windows" {
81		return
82	}
83	if err := os.Symlink(outside, filepath.Join(bundle, "SKILL.md")); err != nil {
84		t.Fatal(err)
85	}
86
87	got, errs = LoadBundled([]BundledSkillDir{{Dir: bundle, Root: root, Source: "extension test"}})
88	if len(errs) == 0 || len(got) != 0 {
89		t.Fatalf("outside skill was accepted: skills=%#v errors=%v", got, errs)
90	}
91}
92
93func TestLoadBundledDoesNotIncludeUserOrBuiltinSkills(t *testing.T) {
94	tmp := t.TempDir()
95	dir := filepath.Join(tmp, "skills", "declared")
96	if err := os.MkdirAll(dir, 0o755); err != nil {
97		t.Fatal(err)
98	}
99	content := "---\nname: declared\ndescription: declared only\n---\nbody\n"
100	if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte(content), 0o644); err != nil {
101		t.Fatal(err)
102	}
103
104	got, errs := LoadBundled([]BundledSkillDir{{Dir: filepath.Dir(dir), Source: "extension test"}})
105	if len(errs) != 0 {
106		t.Fatalf("LoadBundled() errors = %v", errs)
107	}
108	if FindByName(got, "declared") == nil {
109		t.Fatalf("declared skill missing from %#v", got)
110	}
111	for _, skill := range got {
112		if skill.Builtin {
113			t.Fatalf("LoadBundled() returned builtin skill %q", skill.Name)
114		}
115		if skill.Name != "declared" {
116			t.Fatalf("LoadBundled() returned unexpected skill %q", skill.Name)
117		}
118	}
119}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 477

↑↓ moveenter openesc close