Repository navigation
Expand file tree
/
Copy pathskill_runtime_test.go
More file actions
108 lines (92 loc) · 2.11 KB
/
Copy pathskill_runtime_test.go
File metadata and controls
108 lines (92 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package agent
import (
"context"
"testing"
)
func TestSkillRoutingBuildsActiveToolScope(t *testing.T) {
r := NewSkillRegistry()
if err := r.Register(SkillDefinition{
Skill: Skill{
Name: "github-review",
Instructions: "Review GitHub changes",
},
Version: "2",
Triggers: []string{"review"},
Tools: []string{"github.get_diff", "github.create_review"},
Enabled: true,
}); err != nil {
t.Fatal(err)
}
if err := r.Register(SkillDefinition{
Skill: Skill{
Name: "git",
Instructions: "Git basics",
},
Version: "2",
Dependencies: []string{"github-review"},
Enabled: true,
}); err != nil {
t.Fatal(err)
}
matches := r.Match("review this PR", 3)
if len(matches) != 1 || matches[0].Skill.Name != "github-review" {
t.Fatalf("unexpected matches: %+v", matches)
}
skills, err := r.ResolveDependencies([]string{"github-review"})
if err != nil {
t.Fatal(err)
}
routing := SkillRouting{
Matches: matches,
Skills: skills,
Tools: map[string]struct{}{
"github.get_diff": {},
"github.create_review": {},
},
}
if len(routing.ActiveSkillNames()) != 1 ||
routing.ActiveSkillNames()[0] != "github-review" {
t.Fatal(routing.ActiveSkillNames())
}
if got := SkillPrompt(routing); got == "" {
t.Fatal("expected active skill prompt")
}
_ = context.Background()
}
func TestSkillPromptIncludesDependenciesInOrder(t *testing.T) {
routing := SkillRouting{
Skills: []SkillDefinition{
{
Skill: Skill{
Name: "base",
Instructions: "base instructions",
},
Version: "2",
},
{
Skill: Skill{
Name: "review",
Instructions: "review instructions",
},
Version: "2",
},
},
}
prompt := SkillPrompt(routing)
base := "### Skill: base"
review := "### Skill: review"
if len(prompt) == 0 ||
indexOf(prompt, base) < 0 ||
indexOf(prompt, review) < 0 ||
indexOf(prompt, base) > indexOf(prompt, review) {
t.Fatalf("unexpected prompt: %s", prompt)
}
}
func indexOf(s, sub string) int {
for i := 0; i+len(sub) <= len(s); i++ {
if s[i:i+len(sub)] == sub {
return i
}
}
return -1
}