1
1
import { StdioClientTransport } from "./stdio.js" ;
2
2
import spawn from "cross-spawn" ;
3
3
import { JSONRPCMessage } from "../types.js" ;
4
+ import { ChildProcess } from "node:child_process" ;
4
5
5
6
// mock cross-spawn
6
7
jest . mock ( "cross-spawn" ) ;
@@ -31,7 +32,7 @@ describe("StdioClientTransport using cross-spawn", () => {
31
32
} ,
32
33
stderr : null
33
34
} ;
34
- return mockProcess as any ;
35
+ return mockProcess as unknown as ChildProcess ;
35
36
} ) ;
36
37
} ) ;
37
38
@@ -44,9 +45,9 @@ describe("StdioClientTransport using cross-spawn", () => {
44
45
command : "test-command" ,
45
46
args : [ "arg1" , "arg2" ]
46
47
} ) ;
47
-
48
+
48
49
await transport . start ( ) ;
49
-
50
+
50
51
// verify spawn is called correctly
51
52
expect ( mockSpawn ) . toHaveBeenCalledWith (
52
53
"test-command" ,
@@ -63,9 +64,9 @@ describe("StdioClientTransport using cross-spawn", () => {
63
64
command : "test-command" ,
64
65
env : customEnv
65
66
} ) ;
66
-
67
+
67
68
await transport . start ( ) ;
68
-
69
+
69
70
// verify environment variables are passed correctly
70
71
expect ( mockSpawn ) . toHaveBeenCalledWith (
71
72
"test-command" ,
@@ -80,7 +81,7 @@ describe("StdioClientTransport using cross-spawn", () => {
80
81
const transport = new StdioClientTransport ( {
81
82
command : "test-command"
82
83
} ) ;
83
-
84
+
84
85
// get the mock process object
85
86
const mockProcess : {
86
87
on : jest . Mock ;
@@ -110,20 +111,20 @@ describe("StdioClientTransport using cross-spawn", () => {
110
111
} ,
111
112
stderr : null
112
113
} ;
113
-
114
- mockSpawn . mockReturnValue ( mockProcess as any ) ;
115
-
114
+
115
+ mockSpawn . mockReturnValue ( mockProcess as unknown as ChildProcess ) ;
116
+
116
117
await transport . start ( ) ;
117
-
118
+
118
119
// 关键修复:确保 jsonrpc 是字面量 "2.0"
119
120
const message : JSONRPCMessage = {
120
121
jsonrpc : "2.0" ,
121
122
id : "test-id" ,
122
123
method : "test-method"
123
124
} ;
124
-
125
+
125
126
await transport . send ( message ) ;
126
-
127
+
127
128
// verify message is sent correctly
128
129
expect ( mockProcess . stdin . write ) . toHaveBeenCalled ( ) ;
129
130
} ) ;
0 commit comments