48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package builtin
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"nub/internal/skill"
|
|
)
|
|
|
|
func TestReadSkillTool_LoadsBodyByName(t *testing.T) {
|
|
skills := []skill.Skill{
|
|
{Name: "refactoring", Description: "d1", Body: "full refactoring body"},
|
|
{Name: "testing", Description: "d2", Body: "full testing body"},
|
|
}
|
|
rt := NewReadSkillTool(skills)
|
|
env := testEnv(t)
|
|
|
|
in, _ := json.Marshal(map[string]string{"name": "refactoring"})
|
|
res, err := rt.Run(context.Background(), in, env)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if res.IsError {
|
|
t.Fatalf("unexpected error: %s", res.ForModel)
|
|
}
|
|
if res.ForModel != "full refactoring body" {
|
|
t.Errorf("ForModel = %q", res.ForModel)
|
|
}
|
|
}
|
|
|
|
func TestReadSkillTool_UnknownNameListsAvailable(t *testing.T) {
|
|
skills := []skill.Skill{{Name: "refactoring", Body: "x"}}
|
|
rt := NewReadSkillTool(skills)
|
|
env := testEnv(t)
|
|
|
|
in, _ := json.Marshal(map[string]string{"name": "does-not-exist"})
|
|
res, err := rt.Run(context.Background(), in, env)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !res.IsError {
|
|
t.Fatal("expected error for unknown skill name")
|
|
}
|
|
if !contains(res.ForModel, "refactoring") {
|
|
t.Errorf("expected available skills listed in error, got: %q", res.ForModel)
|
|
}
|
|
}
|