11import { StdioClientTransport } from "./stdio.js" ;
22import spawn from "cross-spawn" ;
33import { JSONRPCMessage } from "../types.js" ;
4+ import { ChildProcess } from "node:child_process" ;
45
56// mock cross-spawn
67jest . mock ( "cross-spawn" ) ;
@@ -31,7 +32,7 @@ describe("StdioClientTransport using cross-spawn", () => {
3132 } ,
3233 stderr : null
3334 } ;
34- return mockProcess as any ;
35+ return mockProcess as unknown as ChildProcess ;
3536 } ) ;
3637 } ) ;
3738
@@ -44,9 +45,9 @@ describe("StdioClientTransport using cross-spawn", () => {
4445 command : "test-command" ,
4546 args : [ "arg1" , "arg2" ]
4647 } ) ;
47-
48+
4849 await transport . start ( ) ;
49-
50+
5051 // verify spawn is called correctly
5152 expect ( mockSpawn ) . toHaveBeenCalledWith (
5253 "test-command" ,
@@ -63,9 +64,9 @@ describe("StdioClientTransport using cross-spawn", () => {
6364 command : "test-command" ,
6465 env : customEnv
6566 } ) ;
66-
67+
6768 await transport . start ( ) ;
68-
69+
6970 // verify environment variables are passed correctly
7071 expect ( mockSpawn ) . toHaveBeenCalledWith (
7172 "test-command" ,
@@ -80,7 +81,7 @@ describe("StdioClientTransport using cross-spawn", () => {
8081 const transport = new StdioClientTransport ( {
8182 command : "test-command"
8283 } ) ;
83-
84+
8485 // get the mock process object
8586 const mockProcess : {
8687 on : jest . Mock ;
@@ -110,20 +111,20 @@ describe("StdioClientTransport using cross-spawn", () => {
110111 } ,
111112 stderr : null
112113 } ;
113-
114- mockSpawn . mockReturnValue ( mockProcess as any ) ;
115-
114+
115+ mockSpawn . mockReturnValue ( mockProcess as unknown as ChildProcess ) ;
116+
116117 await transport . start ( ) ;
117-
118+
118119 // 关键修复:确保 jsonrpc 是字面量 "2.0"
119120 const message : JSONRPCMessage = {
120121 jsonrpc : "2.0" ,
121122 id : "test-id" ,
122123 method : "test-method"
123124 } ;
124-
125+
125126 await transport . send ( message ) ;
126-
127+
127128 // verify message is sent correctly
128129 expect ( mockProcess . stdin . write ) . toHaveBeenCalled ( ) ;
129130 } ) ;
0 commit comments