@@ -31,6 +31,16 @@ function expectToolNamesToContain(names: string[], toolNames: string[] = []) {
3131 toolNames . forEach ( ( name ) => expect ( names ) . toContain ( name ) ) ;
3232}
3333
34+ function extractJsonFromMarkdown ( text : string ) : any {
35+ // Handle markdown code blocks like ```json
36+ const jsonMatch = text . match ( / ` ` ` j s o n \n ( [ \s \S ] * ?) \n ` ` ` / ) ;
37+ if ( jsonMatch ) {
38+ return JSON . parse ( jsonMatch [ 1 ] ) ;
39+ }
40+ // If no markdown formatting, assume it's raw JSON
41+ return JSON . parse ( text ) ;
42+ }
43+
3444async function callPythonExampleActor ( client : Client , selectedToolName : string ) {
3545 const result = await client . callTool ( {
3646 name : selectedToolName ,
@@ -53,7 +63,7 @@ async function callPythonExampleActor(client: Client, selectedToolName: string)
5363 } ;
5464 // Parse the JSON to compare objects regardless of property order
5565 const actual = content [ 0 ] ;
56- expect ( JSON . parse ( actual . text ) ) . toEqual ( JSON . parse ( expected . text ) ) ;
66+ expect ( extractJsonFromMarkdown ( actual . text ) ) . toEqual ( JSON . parse ( expected . text ) ) ;
5767 expect ( actual . type ) . toBe ( expected . type ) ;
5868}
5969
@@ -836,7 +846,7 @@ export function createIntegrationTestsSuite(
836846
837847 expect ( outputResult . content ) . toBeDefined ( ) ;
838848 const outputContent = outputResult . content as { text : string ; type : string } [ ] ;
839- const output = JSON . parse ( outputContent [ 0 ] . text ) ;
849+ const output = extractJsonFromMarkdown ( outputContent [ 0 ] . text ) ;
840850 expect ( Array . isArray ( output ) ) . toBe ( true ) ;
841851 expect ( output . length ) . toBeGreaterThan ( 0 ) ;
842852 expect ( output [ 0 ] ) . toHaveProperty ( 'metadata.title' ) ;
@@ -894,7 +904,7 @@ export function createIntegrationTestsSuite(
894904 // Validate the output contains the expected structure with metadata.title
895905 expect ( outputResult . content ) . toBeDefined ( ) ;
896906 const outputContent = outputResult . content as { text : string ; type : string } [ ] ;
897- const output = JSON . parse ( outputContent [ 0 ] . text ) ;
907+ const output = extractJsonFromMarkdown ( outputContent [ 0 ] . text ) ;
898908 expect ( Array . isArray ( output ) ) . toBe ( true ) ;
899909 expect ( output . length ) . toBeGreaterThan ( 0 ) ;
900910 expect ( output [ 0 ] ) . toHaveProperty ( 'metadata.title' ) ;
@@ -935,7 +945,7 @@ export function createIntegrationTestsSuite(
935945
936946 expect ( outputResult . content ) . toBeDefined ( ) ;
937947 const outputContent = outputResult . content as { text : string ; type : string } [ ] ;
938- const output = JSON . parse ( outputContent [ 0 ] . text ) ;
948+ const output = extractJsonFromMarkdown ( outputContent [ 0 ] . text ) ;
939949 expect ( Array . isArray ( output ) ) . toBe ( true ) ;
940950 expect ( output . length ) . toBe ( 1 ) ;
941951 expect ( output [ 0 ] ) . toHaveProperty ( 'first_number' , input . first_number ) ;
0 commit comments