返回 DeepSeek-Reasonix
effect_skill_invocation_test.go
根目录 / internal / boot / effect_skill_invocation_test.go
1 package boot
2
3 import (
4 "context"
5 "strings"
6 "testing"
7 "time"
8
9 "reasonix/internal/control"
10 "reasonix/internal/event"
11 "reasonix/internal/provider"
12 )
13
14 // A user-typed inline skill invocation must reach the provider in the same
15 // pinned form run_skill returns, on both the string and the structured submit path.
16 func TestEffectInlineSkillInvocationReachesProviderPinned(t *testing.T) {
17 const pinOpen = "<skill-pin name=\"probe\">\n# Skill: probe"
18 cases := []struct {
19 name string
20 submit func(*control.Controller)
21 tail string
22 raw string
23 }{
24 {"slash bare", func(c *control.Controller) { c.Submit("/probe") }, "PROBE BODY\nthen run /other\n</skill-pin>", "/probe"},
25 {"slash with task", func(c *control.Controller) { c.Submit("/probe tidy the notes") }, "PROBE BODY\nthen run /other\n\nArguments: tidy the notes\n</skill-pin>", "/probe tidy the notes"},
26 {"chip bare", func(c *control.Controller) {
27 c.SubmitInvocationDisplay("/probe", "", []control.InvocationRequest{{Name: "probe", Kind: "skill"}})
28 }, "PROBE BODY\nthen run /other\n</skill-pin>", ""},
29 {"chip with task", func(c *control.Controller) {
30 c.SubmitInvocationDisplay("/probe tidy the notes", "tidy the notes", []control.InvocationRequest{{Name: "probe", Kind: "skill"}})
31 }, "PROBE BODY\nthen run /other\n\nArguments: tidy the notes\n</skill-pin>", "tidy the notes"},
32 }
33 var rec *effectRecordingProvider
34 provider.Register("boot-effect-skill-invocation", func(provider.Config) (provider.Provider, error) { return rec, nil })
35 for _, tc := range cases {
36 t.Run(tc.name, func(t *testing.T) {
37 isolateConfigHome(t)
38 dir := robustTempDir(t)
39 t.Chdir(dir)
40 rec = &effectRecordingProvider{}
41 writeFile(t, dir, "reasonix.toml", `
42 default_model = "test-model"
43
44 [agent]
45 system_prompt = "BASE"
46
47 [environment]
48 enabled = false
49
50 [[providers]]
51 name = "test-model"
52 kind = "boot-effect-skill-invocation"
53 model = "x"
54 `)
55 approveWorkspace(t, dir)
56 writeFile(t, dir, ".reasonix/skills/probe/SKILL.md", "---\ndescription: probe skill\ntriggers: probe, tidy\nauto-use: require\n---\nPROBE BODY\nthen run /other")
57 writeFile(t, dir, ".reasonix/skills/other/SKILL.md", "---\ndescription: other skill\ntriggers: other\nauto-use: require\n---\nOTHER BODY")
58 ctrl, err := Build(context.Background(), Options{Sink: event.Discard})
59 if err != nil {
60 t.Fatalf("Build: %v", err)
61 }
62 defer ctrl.Close()
63
64 tc.submit(ctrl)
65 if done, running := ctrl.TurnIdleDone(); running {
66 select {
67 case <-done:
68 case <-time.After(30 * time.Second):
69 t.Fatal("turn did not finish")
70 }
71 }
72 reqs := rec.requests()
73 if len(reqs) == 0 {
74 t.Fatal("no request reached the provider boundary")
75 }
76 req := reqs[len(reqs)-1]
77 if raw := rec.rawUserInputs(); len(raw) == 0 || raw[len(raw)-1] != tc.raw {
78 t.Fatalf("provider raw user input = %q, want %q", raw, tc.raw)
79 }
80 var user string
81 for _, m := range req.Messages {
82 if m.Role == provider.RoleUser {
83 user = m.Content
84 }
85 }
86 if !strings.Contains(user, pinOpen) || !strings.Contains(user, tc.tail) {
87 t.Fatalf("user message is not the pinned invocation (want tail %q):\n%s", tc.tail, user)
88 }
89 if strings.Count(user, "tidy the notes") > 1 {
90 t.Fatalf("task delivered twice:\n%s", user)
91 }
92 if strings.Contains(systemMessage(req.Messages), "PROBE BODY") {
93 t.Fatal("invocation body leaked into the cache-stable prefix")
94 }
95 if strings.Contains(user, "skill:probe require") || strings.Contains(user, "skill:other require") {
96 t.Fatalf("inline skill already supplied to the model must not require another skill call:\n%s", user)
97 }
98 })
99 }
100 }
101
101 lines GO