返回 DeepSeek-Reasonix
mcp_project_decision_test.go
根目录 / internal / cli / mcp_project_decision_test.go
1 package cli
2
3 import (
4 "os"
5 "path/filepath"
6 "strings"
7 "testing"
8
9 "reasonix/internal/config"
10 )
11
12 // The CLI reads and records decisions for the workspace a session started in
13 // the same directory would use, and shows which project servers await one.
14 func TestMCPListAndEnableUseTheSessionWorkspace(t *testing.T) {
15 isolateCLIConfigHome(t)
16 repo := t.TempDir()
17 sub := filepath.Join(repo, "pkg", "inner")
18 if err := os.MkdirAll(filepath.Join(repo, ".git"), 0o755); err != nil {
19 t.Fatal(err)
20 }
21 if err := os.MkdirAll(sub, 0o755); err != nil {
22 t.Fatal(err)
23 }
24 if err := os.WriteFile(filepath.Join(repo, "reasonix.toml"), []byte("[[plugins]]\nname = \"repo-mcp\"\ncommand = \"repo-server\"\nargs = [\"--serve\"]\n"), 0o644); err != nil {
25 t.Fatal(err)
26 }
27 t.Chdir(sub)
28
29 list := func() string {
30 return captureStdout(t, func() {
31 if rc := Run([]string{"mcp", "list"}, "test-version"); rc != 0 {
32 t.Fatalf("mcp list rc = %d", rc)
33 }
34 })
35 }
36 if out := list(); !strings.Contains(out, "repo-mcp") || !strings.Contains(out, "[awaiting_user_decision]") {
37 t.Fatalf("mcp list from a subdirectory:\n%s", out)
38 }
39 out := captureStdout(t, func() {
40 if rc := mcpEnableCLI([]string{"repo-mcp"}, true); rc != 0 {
41 t.Fatalf("mcp enable rc = %d", rc)
42 }
43 })
44 if !strings.Contains(out, "repo-server --serve") {
45 t.Fatalf("mcp enable did not show what it approved:\n%s", out)
46 }
47 cfg, err := config.LoadForRoot(repo)
48 if err != nil {
49 t.Fatal(err)
50 }
51 if d := config.MCPServerDecision(cfg.Plugins[0], repo); d != config.MCPDecisionOn {
52 t.Fatalf("decision at the session workspace = %s, want enabled", d.Code())
53 }
54 if out := list(); !strings.Contains(out, "[enabled]") {
55 t.Fatalf("mcp list after enable:\n%s", out)
56 }
57 }
58
58 lines GO