@@ -34,8 +34,16 @@ if (existsSync(envPath)) {
3434 console . log ( '✅ Loaded .env file from:' , envPath ) ;
3535}
3636
37- // Helper function to delay
38- const delay = ( ms ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
37+ async function waitForToolList ( client , timeoutMs = 5000 ) {
38+ return Promise . race ( [
39+ client . listTools ( ) ,
40+ new Promise ( ( _ , reject ) => {
41+ setTimeout ( ( ) => {
42+ reject ( new Error ( `MCP server did not become ready within ${ timeoutMs } ms` ) ) ;
43+ } , timeoutMs ) ;
44+ } ) ,
45+ ] ) ;
46+ }
3947
4048// Detect if real CloudBase credentials are available
4149function hasCloudBaseCredentials ( ) {
@@ -48,16 +56,19 @@ function hasCloudBaseCredentials() {
4856describe ( 'Runtime Validation - Event Function Multi-Language Support' , ( ) => {
4957 let testClient = null ;
5058 let testTransport = null ;
51- const testFunctionsDir = join ( __dirname , '../temp-runtime-test' ) ;
5259 const timestamp = Date . now ( ) ;
60+ const testFunctionsDir = join ( __dirname , `../temp-runtime-test-${ timestamp } ` ) ;
5361
5462 beforeAll ( async ( ) => {
5563 if ( ! hasCloudBaseCredentials ( ) ) {
5664 console . log ( '⚠️ No CloudBase credentials, skipping runtime validation tests' ) ;
5765 return ;
5866 }
5967
60- // Create test client
68+ if ( ! existsSync ( testFunctionsDir ) ) {
69+ mkdirSync ( testFunctionsDir , { recursive : true } ) ;
70+ }
71+
6172 const client = new Client ( {
6273 name : 'runtime-validation-client' ,
6374 version : '1.0.0' ,
@@ -67,35 +78,33 @@ describe('Runtime Validation - Event Function Multi-Language Support', () => {
6778
6879 const serverPath = join ( __dirname , '../mcp/dist/cli.cjs' ) ;
6980 const transport = new StdioClientTransport ( {
70- command : 'node' ,
81+ command : process . execPath ,
7182 args : [ serverPath ] ,
7283 env : {
7384 ...process . env ,
7485 }
7586 } ) ;
7687
77- await client . connect ( transport ) ;
78- await delay ( 2000 ) ;
79-
80- testClient = client ;
81- testTransport = transport ;
82-
83- // Create test functions directory
84- if ( ! existsSync ( testFunctionsDir ) ) {
85- mkdirSync ( testFunctionsDir , { recursive : true } ) ;
88+ try {
89+ await client . connect ( transport ) ;
90+ await waitForToolList ( client , 5000 ) ;
91+ testClient = client ;
92+ testTransport = transport ;
93+ } catch ( error ) {
94+ await transport . close ( ) . catch ( ( ) => { } ) ;
95+ throw error ;
8696 }
87- } ) ;
97+ } , 30000 ) ;
8898
8999 afterAll ( async ( ) => {
90100 if ( testTransport ) {
91101 await testTransport . close ( ) ;
92102 }
93103
94- // Clean up test directory
95104 if ( existsSync ( testFunctionsDir ) ) {
96105 rmSync ( testFunctionsDir , { recursive : true , force : true } ) ;
97106 }
98- } ) ;
107+ } , 10000 ) ;
99108
100109 // Helper function to create a simple Python Event function
101110 function createPythonFunction ( functionName ) {
0 commit comments