返回 DeepSeek-Reasonix
usecapability_skillargs_test.go
根目录 / internal / agent / usecapability_skillargs_test.go
1 package agent
2
3 import (
4 "context"
5 "encoding/json"
6 "testing"
7
8 "reasonix/internal/capability"
9 "reasonix/internal/skill"
10 "reasonix/internal/tool"
11 )
12
13 func TestUseCapabilitySkillCallAcceptsStringArgumentsPayload(t *testing.T) {
14 var ran string
15 runner := func(_ context.Context, sk skill.Skill, task string, _ skill.SubagentRunOptions) (string, error) {
16 ran = sk.Name + ":" + task
17 return "ok", nil
18 }
19 store := skill.New(skill.Options{HomeDir: t.TempDir()})
20 reg := tool.NewRegistry()
21 reg.Add(skill.NewRunSkillTool(store, runner))
22 tl := NewUseCapabilityTool(context.Background(), nil, nil, reg, capability.NewLedger(), nil, nil)
23
24 out, err := tl.Execute(context.Background(), json.RawMessage(`{"action":"call","capability_id":"skill:explore","arguments":"{\"task\":\"map PicAnnotateCenter\"}"}`))
25 if err != nil {
26 t.Fatalf("execute: %v", err)
27 }
28 if out != "ok" {
29 t.Fatalf("output = %q, want ok", out)
30 }
31 if ran != "explore:map PicAnnotateCenter" {
32 t.Fatalf("runner = %q, want explore task", ran)
33 }
34 }
35
36 func TestUseCapabilitySkillCallAcceptsDedicatedTaskPayload(t *testing.T) {
37 var ran string
38 var gotOpts skill.SubagentRunOptions
39 runner := func(_ context.Context, sk skill.Skill, task string, opts skill.SubagentRunOptions) (string, error) {
40 ran = sk.Name + ":" + task
41 gotOpts = opts
42 return "ok", nil
43 }
44 store := skill.New(skill.Options{HomeDir: t.TempDir()})
45 reg := tool.NewRegistry()
46 reg.Add(skill.NewRunSkillTool(store, runner))
47 tl := NewUseCapabilityTool(context.Background(), nil, nil, reg, capability.NewLedger(), nil, nil)
48
49 if _, err := tl.Execute(context.Background(), json.RawMessage(`{"action":"call","capability_id":"skill:explore","arguments":{"task":"map the loop","continue_from":"sa_prev"}}`)); err != nil {
50 t.Fatalf("execute: %v", err)
51 }
52 if ran != "explore:map the loop" {
53 t.Fatalf("runner = %q, want explore task", ran)
54 }
55 if gotOpts.ContinueFrom != "sa_prev" {
56 t.Fatalf("continue_from = %q, want sa_prev", gotOpts.ContinueFrom)
57 }
58 }
59
59 lines GO