返回 DeepSeek-Reasonix
taskpolicy_external_test.go
根目录 / internal / agent / taskpolicy_external_test.go
1 package agent
2
3 import (
4 "encoding/json"
5 "testing"
6 )
7
8 func TestExternalActionClassifierRecognizesStaticCommandVariants(t *testing.T) {
9 tests := []struct {
10 name string
11 command string
12 want bool
13 }{
14 {name: "git push", command: "git push origin HEAD", want: true},
15 {name: "git global directory", command: "git -C ../repo push origin HEAD", want: true},
16 {name: "git global config", command: "git -c credential.helper= push origin HEAD", want: true},
17 {name: "npm workspace publish", command: "npm --workspace pkg publish", want: true},
18 {name: "pnpm directory deploy", command: "pnpm --dir pkg deploy", want: true},
19 {name: "kubectl namespace apply", command: "kubectl -n production apply -f deploy.yaml", want: true},
20 {name: "kubectl impersonation apply", command: "kubectl --as deployer apply -f deploy.yaml", want: true},
21 {name: "docker context push", command: "docker --context production push image:tag", want: true},
22 {name: "gh release create", command: "gh --repo owner/repo release create v1.2.3", want: true},
23 {name: "env wrapper", command: "env CI=1 git -C ../repo push origin HEAD", want: true},
24 {name: "shell wrapper", command: "bash -lc 'git -C ../repo push origin HEAD'", want: true},
25 {name: "package script", command: "npm run deploy", want: true},
26 {name: "task runner", command: "make publish", want: true},
27 {name: "chained push", command: "git status && git -C ../repo push origin HEAD", want: true},
28 {name: "git dynamic subcommand fails closed", command: `git "$action" origin HEAD`, want: true},
29 {name: "git status", command: "git status --short"},
30 {name: "npm view", command: "npm --workspace pkg view"},
31 {name: "kubectl get", command: "kubectl -n production get pods"},
32 {name: "gh release view", command: "gh --repo owner/repo release view v1.2.3"},
33 {name: "ordinary local command", command: "go fmt ./..."},
34 {name: "action word as data", command: "echo deploy"},
35 }
36 for _, tt := range tests {
37 t.Run(tt.name, func(t *testing.T) {
38 args, err := json.Marshal(map[string]string{"command": tt.command})
39 if err != nil {
40 t.Fatal(err)
41 }
42 if got := isExternalActionTool("bash", "bash", args); got != tt.want {
43 t.Fatalf("isExternalActionTool(%q) = %v, want %v", tt.command, got, tt.want)
44 }
45 })
46 }
47 }
48
49 func TestExternalActionClassifierRecognizesResolvedToolNames(t *testing.T) {
50 tests := []struct {
51 name string
52 want bool
53 }{
54 {name: "publish", want: true},
55 {name: "mcp__vercel__deploy_project", want: true},
56 {name: "mcp__registry__push_image", want: true},
57 {name: "github_create_release", want: true},
58 {name: "get_deployment_status"},
59 {name: "list_releases"},
60 {name: "read_file"},
61 }
62 for _, tt := range tests {
63 t.Run(tt.name, func(t *testing.T) {
64 if got := isExternalActionTool(tt.name, tt.name, nil); got != tt.want {
65 t.Fatalf("isExternalActionTool(%q) = %v, want %v", tt.name, got, tt.want)
66 }
67 })
68 }
69 }
70
70 lines GO