- 03.4.1:per-persona 路由载体选 models.json(组内新增 personaModels/personaProviders + 校验 + PersonaRoute()), Router/RuntimeLLM 快照绑定、loop 流式路径按该 turn 的 persona 路由;主步用路由结果、降级步钉自己的模型 - 03.4.3:本地第三级降级链(LLM_LOCAL_*,Configured() 含 Enabled ⇒ **默认关**),warn 标注来源 - 14.4.4:capacity 接入 L3(分类器接口 + TTL 缓存 + 严格 JSON 解析),CAPACITY_L3_ENABLED **默认 false** - 14.4.1:语义修正 —— group.multimodal 才是「主模型能否收图」(env 路径不再臆断),LLM_VISION_MODEL 只配视觉工具; vision/OCR 可各用不同模型;runtime 不再因有图抢路由(vision.Router 是唯一分层权威) - 14.4.5:新增 image-crop 工具(工具数 5→6,策略默认 owner-only),schema 支持按区域裁切 - 组合根:wire_runtime 读 group.Multimodal;capacity 装配拆出 wire_capacity.go(守 500 行) - 复核:`go build`/`go vet`/各包 `go test -count=1` 全绿;**6 条变异反证**先红后还原(含作者自查出的 2 条假阳性变异) - 未落:按 provider 的 thinking 开关(需 openai_encode.go/openai.go 文件面)、persona awakening(需 loader 文件面)
108 lines
2.7 KiB
Go
108 lines
2.7 KiB
Go
package io
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/capability/registry"
|
|
"git.yeij.top/AskaEth/Cyrene_v2/internal/config"
|
|
"git.yeij.top/AskaEth/Cyrene_v2/pkg/plugins/sdk"
|
|
)
|
|
|
|
func TestTools_ReturnsEveryTool(t *testing.T) {
|
|
t.Parallel()
|
|
set, err := New(&config.Config{DataDir: t.TempDir()})
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
if len(set) != 6 {
|
|
t.Fatalf("expected 6 tools, got %d", len(set))
|
|
}
|
|
want := []string{"file", "image-crop", "http", "web-search", "web-fetch", "knowledge"}
|
|
seen := map[string]bool{}
|
|
for _, tool := range set {
|
|
seen[tool.Name()] = true
|
|
if tool.Description() == "" {
|
|
t.Errorf("tool %q has an empty description", tool.Name())
|
|
}
|
|
params, err := tool.Parameters()
|
|
if err != nil {
|
|
t.Errorf("tool %q Parameters error: %v", tool.Name(), err)
|
|
}
|
|
if params == nil {
|
|
t.Errorf("tool %q has nil parameters", tool.Name())
|
|
}
|
|
}
|
|
for _, name := range want {
|
|
if !seen[name] {
|
|
t.Errorf("missing tool %q", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNew_NilConfigErrors(t *testing.T) {
|
|
t.Parallel()
|
|
if _, err := New(nil); err == nil {
|
|
t.Fatal("expected error for nil config")
|
|
}
|
|
}
|
|
|
|
func TestRegister_RegistersEveryTool(t *testing.T) {
|
|
t.Parallel()
|
|
reg := registry.New()
|
|
if err := Register(reg); err != nil {
|
|
t.Fatalf("Register: %v", err)
|
|
}
|
|
for _, name := range []string{"file", "image-crop", "http", "web-search", "web-fetch", "knowledge"} {
|
|
c, err := reg.Get(name)
|
|
if err != nil {
|
|
t.Fatalf("Get(%q): %v", name, err)
|
|
}
|
|
if c.Kind != registry.KindTool {
|
|
t.Errorf("kind of %q = %q, want tool", name, c.Kind)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRegister_NilRegistrar(t *testing.T) {
|
|
t.Parallel()
|
|
if err := Register(nil); !errors.Is(err, sdk.ErrNilRegistrar) {
|
|
t.Fatalf("expected sdk.ErrNilRegistrar, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestRegister_DuplicateErrors(t *testing.T) {
|
|
t.Parallel()
|
|
reg := registry.New()
|
|
if err := Register(reg); err != nil {
|
|
t.Fatalf("first Register: %v", err)
|
|
}
|
|
if err := Register(reg); !errors.Is(err, registry.ErrDuplicate) {
|
|
t.Fatalf("expected registry.ErrDuplicate, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestTools_ConcurrentDescribe(t *testing.T) {
|
|
t.Parallel()
|
|
set, err := New(&config.Config{DataDir: t.TempDir()})
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
// Exercise the read-only contract concurrently to catch any shared-state
|
|
// mutation (the dispatcher may call Parameters from many goroutines).
|
|
for _, tool := range set {
|
|
tool := tool
|
|
t.Run(tool.Name(), func(t *testing.T) {
|
|
t.Parallel()
|
|
for i := 0; i < 10; i++ {
|
|
if _, err := tool.Parameters(); err != nil {
|
|
t.Fatalf("Parameters: %v", err)
|
|
}
|
|
if tool.Name() == "" || tool.Description() == "" {
|
|
t.Fatalf("empty identity for %v", tool)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|