返回 DeepSeek-Reasonix
approval_identity_test.go
根目录 / internal / installsource / approval_identity_test.go
1 package installsource
2
3 import (
4 "context"
5 "encoding/json"
6 "path/filepath"
7 "testing"
8 )
9
10 func testPlanID(t *testing.T, req request, actions []action) string {
11 t.Helper()
12 id, err := computePlanID(req, actions)
13 if err != nil {
14 t.Fatal(err)
15 }
16 return id
17 }
18
19 func TestImportedExecutionInputsInvalidateApproval(t *testing.T) {
20 for _, field := range []string{"env", "headers"} {
21 t.Run(field, func(t *testing.T) {
22 t.Setenv("REASONIX_HOME", t.TempDir())
23 root := t.TempDir()
24 src := filepath.Join(root, ".mcp.json")
25 tl := NewTool(Options{ProjectRoot: root, HomeDir: t.TempDir()})
26 write := func(value string) {
27 writeFile(t, src, `{"mcpServers":{"demo":{"command":"node","args":["server.js"],"`+field+`":{"REVIEW_VALUE":"`+value+`"}}}}`)
28 }
29 write("approved")
30 args := map[string]any{"source": src, "kind": "mcp", "scope": "project"}
31 before := execInstall(t, tl, args)
32 write("changed")
33 after := execInstall(t, tl, args)
34 if before.PlanID == after.PlanID {
35 t.Fatal("changed execution inputs retained approval identity")
36 }
37 args["apply"], args["planId"] = true, before.PlanID
38 raw, _ := json.Marshal(args)
39 if _, err := tl.Execute(context.Background(), raw); err == nil {
40 t.Fatal("stale approval accepted")
41 }
42 })
43 }
44 }
45
45 lines GO