Replace 43 test files with their upstream/main versions to eliminate test file merge conflicts entirely (43 files, 604 markers → 0). Fork-only test functions are extracted to *_ext_test.go files (19 files) which have no upstream counterpart and thus never conflict. Source-level upstream alignment: - config/defaults: AllowRemote defaults to true - config/migration: model names match upstream (gpt-5.4) - session/manager: sanitizeFilename replaces / and \ - state: log.Printf instead of log.Fatalf on mkdir failure - wecom: verifySignature returns false on empty token (fail-closed) - openclaw migration: preserves AllowRemote default Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
90 lines
2.5 KiB
Go
90 lines
2.5 KiB
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/skills"
|
|
)
|
|
|
|
func TestFindSkillsToolName(t *testing.T) {
|
|
tool := NewFindSkillsTool(skills.NewRegistryManager(), nil)
|
|
assert.Equal(t, "find_skills", tool.Name())
|
|
}
|
|
|
|
func TestFindSkillsToolMissingQuery(t *testing.T) {
|
|
tool := NewFindSkillsTool(skills.NewRegistryManager(), nil)
|
|
result := tool.Execute(context.Background(), map[string]any{})
|
|
assert.True(t, result.IsError)
|
|
assert.Contains(t, result.ForLLM, "query is required")
|
|
}
|
|
|
|
func TestFindSkillsToolEmptyQuery(t *testing.T) {
|
|
tool := NewFindSkillsTool(skills.NewRegistryManager(), nil)
|
|
result := tool.Execute(context.Background(), map[string]any{
|
|
"query": " ",
|
|
})
|
|
assert.True(t, result.IsError)
|
|
}
|
|
|
|
func TestFindSkillsToolCacheHit(t *testing.T) {
|
|
cache := skills.NewSearchCache(10, 5*60*1000*1000*1000) // 5 min
|
|
cache.Put("github", []skills.SearchResult{
|
|
{Slug: "github", Score: 0.9, RegistryName: "clawhub"},
|
|
})
|
|
|
|
tool := NewFindSkillsTool(skills.NewRegistryManager(), cache)
|
|
result := tool.Execute(context.Background(), map[string]any{
|
|
"query": "github",
|
|
})
|
|
|
|
assert.False(t, result.IsError)
|
|
assert.Contains(t, result.ForLLM, "github")
|
|
assert.Contains(t, result.ForLLM, "cached")
|
|
}
|
|
|
|
func TestFindSkillsToolParameters(t *testing.T) {
|
|
tool := NewFindSkillsTool(skills.NewRegistryManager(), nil)
|
|
params := tool.Parameters()
|
|
|
|
props, ok := params["properties"].(map[string]any)
|
|
assert.True(t, ok)
|
|
assert.Contains(t, props, "query")
|
|
assert.Contains(t, props, "limit")
|
|
|
|
required, ok := params["required"].([]string)
|
|
assert.True(t, ok)
|
|
assert.Contains(t, required, "query")
|
|
}
|
|
|
|
func TestFindSkillsToolDescription(t *testing.T) {
|
|
tool := NewFindSkillsTool(skills.NewRegistryManager(), nil)
|
|
assert.NotEmpty(t, tool.Description())
|
|
assert.Contains(t, tool.Description(), "skill")
|
|
}
|
|
|
|
func TestFormatSearchResultsEmpty(t *testing.T) {
|
|
result := formatSearchResults("test query", nil, false)
|
|
assert.Contains(t, result, "No skills found")
|
|
}
|
|
|
|
func TestFormatSearchResultsWithData(t *testing.T) {
|
|
results := []skills.SearchResult{
|
|
{
|
|
Slug: "github",
|
|
Score: 0.95,
|
|
DisplayName: "GitHub",
|
|
Summary: "GitHub API integration",
|
|
Version: "1.0.0",
|
|
RegistryName: "clawhub",
|
|
},
|
|
}
|
|
output := formatSearchResults("github", results, false)
|
|
assert.Contains(t, output, "github")
|
|
assert.Contains(t, output, "v1.0.0")
|
|
assert.Contains(t, output, "0.950")
|
|
assert.Contains(t, output, "clawhub")
|
|
assert.Contains(t, output, "install_skill")
|
|
}
|