返回 DeepSeek-Reasonix
skill_health_registry_test.go
根目录 / internal / doctor / skill_health_registry_test.go
1 package doctor
2
3 import (
4 "context"
5 "encoding/json"
6 "os"
7 "os/exec"
8 "strings"
9 "testing"
10
11 "reasonix/internal/skill"
12 "reasonix/internal/tool"
13 )
14
15 type registryProbeTool struct{}
16
17 func (registryProbeTool) Name() string { return "doctor_registry_probe" }
18 func (registryProbeTool) Description() string { return "probe" }
19 func (registryProbeTool) Schema() json.RawMessage { return json.RawMessage(`{"type":"object"}`) }
20 func (registryProbeTool) ReadOnly() bool { return true }
21 func (registryProbeTool) Execute(context.Context, json.RawMessage) (string, error) { return "", nil }
22
23 // Adapted from PR #9686: isolate registration so repeated and parallel suite
24 // runs cannot mutate the parent process's compile-time registry.
25 func TestAllowedToolsAcceptsAnyRegisteredBuiltin(t *testing.T) {
26 const marker = "REASONIX_DOCTOR_REGISTRY_PROBE"
27 if os.Getenv(marker) != "1" {
28 exe, err := os.Executable()
29 if err != nil {
30 t.Fatal(err)
31 }
32 cmd := exec.Command(exe, "-test.run=^TestAllowedToolsAcceptsAnyRegisteredBuiltin$")
33 cmd.Env = append(os.Environ(), marker+"=1")
34 if out, err := cmd.CombinedOutput(); err != nil {
35 t.Fatalf("isolated registry check: %v\n%s", err, out)
36 }
37 return
38 }
39 tool.RegisterBuiltin(registryProbeTool{})
40 warnings := CollectSkillHealthWarnings(SkillHealthOptions{Skills: []skill.Skill{{Name: "probe", Description: "ok", AllowedTools: []string{"doctor_registry_probe"}}}})
41 for _, warning := range warnings {
42 if strings.Contains(warning, "doctor_registry_probe") {
43 t.Fatal(warning)
44 }
45 }
46 }
47
48 func TestAllowedToolsStillWarnsOnAnUnknownName(t *testing.T) {
49 warnings := CollectSkillHealthWarnings(SkillHealthOptions{Skills: []skill.Skill{{Name: "probe", Description: "ok", AllowedTools: []string{"definitely_not_a_tool"}}}})
50 for _, warning := range warnings {
51 if strings.Contains(warning, "definitely_not_a_tool") {
52 return
53 }
54 }
55 t.Fatal("unknown allowed-tools name did not warn")
56 }
57
57 lines GO