@@ -5,6 +5,10 @@ import * as path from 'node:path';
5
5
import * as os from 'node:os' ;
6
6
import * as fs from 'node:fs/promises' ;
7
7
import process from 'node:process' ;
8
+ import dotenv from 'dotenv' ;
9
+
10
+ // Load environment variables from .env file
11
+ dotenv . config ( ) ;
8
12
9
13
interface ToolResponse {
10
14
isError : boolean ;
@@ -285,4 +289,60 @@ describe('MCP Client Integration', () => {
285
289
expect ( finalizeResult . isError ) . toBeFalsy ( ) ;
286
290
console . log ( 'Project was successfully finalized after explicit task approval' ) ;
287
291
} ) ;
292
+
293
+ // Skip by default as it requires OpenAI API key
294
+ it . skip ( 'should generate a project plan using OpenAI' , async ( ) => {
295
+ console . log ( 'Testing project plan generation...' ) ;
296
+
297
+ // Skip if no OpenAI API key is set
298
+ const openaiApiKey = process . env . OPENAI_API_KEY ;
299
+ if ( ! openaiApiKey ) {
300
+ console . log ( 'Skipping test: OPENAI_API_KEY not set' ) ;
301
+ return ;
302
+ }
303
+
304
+ // Create a temporary requirements file
305
+ const requirementsPath = path . join ( tempDir , 'requirements.md' ) ;
306
+ const requirements = `# TODO App Requirements
307
+
308
+ - Use React for the frontend
309
+ - Include add, delete, and mark complete functionality
310
+ - Store todos in local storage
311
+ - Add basic styling` ;
312
+
313
+ await fs . writeFile ( requirementsPath , requirements , 'utf-8' ) ;
314
+ console . log ( 'Created temporary requirements file:' , requirementsPath ) ;
315
+
316
+ // Test prompt and context
317
+ const testPrompt = "Create a step-by-step project plan to build a simple TODO app with React" ;
318
+
319
+ // Generate project plan
320
+ const generateResult = await client . callTool ( {
321
+ name : "generate_project_plan" ,
322
+ arguments : {
323
+ prompt : testPrompt ,
324
+ provider : "openai" ,
325
+ model : "gpt-4-turbo" ,
326
+ attachments : [ requirementsPath ]
327
+ }
328
+ } ) as ToolResponse ;
329
+
330
+ expect ( generateResult . isError ) . toBeFalsy ( ) ;
331
+ const planData = JSON . parse ( ( generateResult . content [ 0 ] as { text : string } ) . text ) ;
332
+
333
+ // Verify the generated plan structure
334
+ expect ( planData ) . toHaveProperty ( 'data' ) ;
335
+ expect ( planData . data ) . toHaveProperty ( 'projectPlan' ) ;
336
+ expect ( planData . data ) . toHaveProperty ( 'tasks' ) ;
337
+ expect ( Array . isArray ( planData . data . tasks ) ) . toBe ( true ) ;
338
+ expect ( planData . data . tasks . length ) . toBeGreaterThan ( 0 ) ;
339
+
340
+ // Verify task structure
341
+ const firstTask = planData . data . tasks [ 0 ] ;
342
+ expect ( firstTask ) . toHaveProperty ( 'title' ) ;
343
+ expect ( firstTask ) . toHaveProperty ( 'description' ) ;
344
+
345
+ // The temporary file will be cleaned up by the afterAll hook that removes tempDir
346
+ console . log ( 'Successfully generated project plan with tasks' ) ;
347
+ } ) ;
288
348
} ) ;
0 commit comments