@@ -299,13 +299,13 @@ describe('CodeModeUtcpClient', () => {
299299
300300 test ( 'should execute simple code with basic operations' , async ( ) => {
301301 const code = `
302- const x = 10 ;
303- const y = 20 ;
304- return { sum: x + y, product: x * y } ;
302+ const x = 5 ;
303+ const y = 10 ;
304+ return x + y;
305305 ` ;
306306
307- const result = await client . callToolChain ( code ) ;
308- expect ( result ) . toEqual ( { sum : 30 , product : 200 } ) ;
307+ const { result } = await client . callToolChain ( code ) ;
308+ expect ( result ) . toBe ( 15 ) ;
309309 } ) ;
310310
311311 test ( 'should execute code that calls a simple tool' , async ( ) => {
@@ -317,7 +317,7 @@ describe('CodeModeUtcpClient', () => {
317317 return result;
318318 ` ;
319319
320- const result = await client . callToolChain ( code ) ;
320+ const { result } = await client . callToolChain ( code ) ;
321321 expect ( result . result ) . toBe ( 40 ) ;
322322 expect ( result . operation ) . toBe ( 'addition' ) ;
323323
@@ -343,7 +343,7 @@ describe('CodeModeUtcpClient', () => {
343343 };
344344 ` ;
345345
346- const result = await client . callToolChain ( code ) ;
346+ const { result } = await client . callToolChain ( code ) ;
347347 expect ( result . math . result ) . toBe ( 15 ) ;
348348 expect ( result . greeting . greeting ) . toBe ( "Good day, Alice" ) ;
349349 expect ( result . greeting . isFormal ) . toBe ( true ) ;
@@ -374,7 +374,7 @@ describe('CodeModeUtcpClient', () => {
374374 return result;
375375 ` ;
376376
377- const result = await client . callToolChain ( code ) ;
377+ const { result } = await client . callToolChain ( code ) ;
378378 expect ( result . processedData . processed ) . toBe ( true ) ;
379379 expect ( result . processedData . users ) . toBeDefined ( ) ;
380380 expect ( result . metadata . itemCount ) . toBe ( 1 ) ;
@@ -400,7 +400,7 @@ describe('CodeModeUtcpClient', () => {
400400 };
401401 ` ;
402402
403- const result = await client . callToolChain ( code ) ;
403+ const { result } = await client . callToolChain ( code ) ;
404404 expect ( result . statistics . sum ) . toBe ( 25 ) ;
405405 expect ( result . statistics . count ) . toBe ( 6 ) ;
406406 expect ( result . statistics . average ) . toBe ( 25 / 6 ) ;
@@ -422,7 +422,7 @@ describe('CodeModeUtcpClient', () => {
422422 };
423423 ` ;
424424
425- const result = await client . callToolChain ( code ) ;
425+ const { result } = await client . callToolChain ( code ) ;
426426 expect ( result . timeData . timestamp ) . toBeDefined ( ) ;
427427 expect ( result . timeData . iso ) . toBeDefined ( ) ;
428428 expect ( result . isRecent ) . toBe ( true ) ;
@@ -445,7 +445,7 @@ describe('CodeModeUtcpClient', () => {
445445 }
446446 ` ;
447447
448- const result = await client . callToolChain ( code ) ;
448+ const { result } = await client . callToolChain ( code ) ;
449449 expect ( result . error ) . toBe ( true ) ;
450450 expect ( result . caught ) . toBe ( true ) ;
451451 expect ( result . message ) . toContain ( "Test error message" ) ;
@@ -483,7 +483,7 @@ describe('CodeModeUtcpClient', () => {
483483 };
484484 ` ;
485485
486- const result = await client . callToolChain ( code ) ;
486+ const { result } = await client . callToolChain ( code ) ;
487487 expect ( result . mathPi ) . toBe ( Math . PI ) ;
488488 expect ( typeof result . dateNow ) . toBe ( 'number' ) ;
489489 expect ( result . arrayMethods ) . toBe ( true ) ;
@@ -502,7 +502,7 @@ describe('CodeModeUtcpClient', () => {
502502 };
503503 ` ;
504504
505- const result = await client . callToolChain ( code ) ;
505+ const { result } = await client . callToolChain ( code ) ;
506506 expect ( result . hasInterfaces ) . toBe ( true ) ;
507507 expect ( result . interfacesContainNamespace ) . toBe ( true ) ;
508508 expect ( result . canGetSpecificInterface ) . toBe ( true ) ;
@@ -558,11 +558,11 @@ describe('CodeModeUtcpClient', () => {
558558 const result = await client . callToolChain ( code , 15000 ) ;
559559
560560 // Verify the chain worked correctly
561- expect ( result . steps . arrayProcessing . sum ) . toBe ( 50 ) ;
562- expect ( result . steps . addition . result ) . toBe ( 150 ) ;
563- expect ( result . steps . greeting . greeting ) . toBe ( "Hey CodeMode!" ) ;
564- expect ( result . steps . finalProcessing . processedData . processed ) . toBe ( true ) ;
565- expect ( result . summary . chainCompleted ) . toBe ( true ) ;
561+ expect ( result . result . steps . arrayProcessing . sum ) . toBe ( 50 ) ;
562+ expect ( result . result . steps . addition . result ) . toBe ( 150 ) ;
563+ expect ( result . result . steps . greeting . greeting ) . toBe ( "Hey CodeMode!" ) ;
564+ expect ( result . result . steps . finalProcessing . processedData . processed ) . toBe ( true ) ;
565+ expect ( result . result . summary . chainCompleted ) . toBe ( true ) ;
566566
567567 // Verify all tools were called in the correct order
568568 expect ( testResults . sumArrayCalled ) . toBeDefined ( ) ;
@@ -576,6 +576,64 @@ describe('CodeModeUtcpClient', () => {
576576 expect ( testResults . greetCalled . name ) . toBe ( "CodeMode" ) ;
577577 expect ( testResults . greetCalled . formal ) . toBe ( false ) ;
578578 } ) ;
579+
580+ test ( 'should provide agent prompt template' , ( ) => {
581+ const promptTemplate = CodeModeUtcpClient . AGENT_PROMPT_TEMPLATE ;
582+
583+ expect ( typeof promptTemplate ) . toBe ( 'string' ) ;
584+ expect ( promptTemplate . length ) . toBeGreaterThan ( 0 ) ;
585+ expect ( promptTemplate ) . toContain ( 'Tool Discovery Phase' ) ;
586+ expect ( promptTemplate ) . toContain ( 'Interface Introspection' ) ;
587+ expect ( promptTemplate ) . toContain ( 'Code Execution Guidelines' ) ;
588+ expect ( promptTemplate ) . toContain ( 'await manual.tool' ) ;
589+ expect ( promptTemplate ) . toContain ( '__interfaces' ) ;
590+ expect ( promptTemplate ) . toContain ( '__getToolInterface' ) ;
591+ expect ( promptTemplate ) . toContain ( 'Discover first, code second' ) ;
592+ } ) ;
593+
594+ test ( 'should capture console.log output with callToolChain' , async ( ) => {
595+ const code = `
596+ console.log('First log message');
597+ console.log('Number:', 42);
598+ console.log('Object:', { name: 'test', value: 123 });
599+
600+ const addResult = await test_tools.add({ a: 10, b: 20 });
601+ console.log('Addition result:', addResult);
602+
603+ return addResult.result;
604+ ` ;
605+
606+ const { result, logs } = await client . callToolChain ( code ) ;
607+
608+ expect ( result ) . toBe ( 30 ) ;
609+ expect ( logs ) . toHaveLength ( 4 ) ;
610+ expect ( logs [ 0 ] ) . toBe ( 'First log message' ) ;
611+ expect ( logs [ 1 ] ) . toBe ( 'Number: 42' ) ;
612+ expect ( logs [ 2 ] ) . toContain ( '"name": "test"' ) ;
613+ expect ( logs [ 2 ] ) . toContain ( '"value": 123' ) ;
614+ expect ( logs [ 3 ] ) . toContain ( 'Addition result:' ) ;
615+ expect ( logs [ 3 ] ) . toContain ( '"result": 30' ) ;
616+ } ) ;
617+
618+ test ( 'should capture console error and warn with callToolChain' , async ( ) => {
619+ const code = `
620+ console.log('Regular log');
621+ console.error('This is an error');
622+ console.warn('This is a warning');
623+ console.info('This is info');
624+
625+ return 'done';
626+ ` ;
627+
628+ const { result, logs } = await client . callToolChain ( code ) ;
629+
630+ expect ( result ) . toBe ( 'done' ) ;
631+ expect ( logs ) . toHaveLength ( 4 ) ;
632+ expect ( logs [ 0 ] ) . toBe ( 'Regular log' ) ;
633+ expect ( logs [ 1 ] ) . toBe ( '[ERROR] This is an error' ) ;
634+ expect ( logs [ 2 ] ) . toBe ( '[WARN] This is a warning' ) ;
635+ expect ( logs [ 3 ] ) . toBe ( '[INFO] This is info' ) ;
636+ } ) ;
579637} ) ;
580638
581639// Export for potential manual testing
0 commit comments