@@ -72,19 +72,18 @@ describe('serializeOutputForFile (json / txt / md)', () => {
7272} )
7373
7474describe ( 'extractTabularData' , ( ) => {
75- it ( 'extracts rows from function_execute { result: [...] } via unwrap' , ( ) => {
76- const rows = extractTabularData ( {
77- result : [ { a : 1 } , { a : 2 } ] ,
78- stdout : '' ,
79- } )
80- expect ( rows ) . toEqual ( [ { a : 1 } , { a : 2 } ] )
75+ it ( 'extracts rows directly from an array input' , ( ) => {
76+ expect ( extractTabularData ( [ { a : 1 } , { a : 2 } ] ) ) . toEqual ( [ { a : 1 } , { a : 2 } ] )
8177 } )
8278
83- it ( 'returns null when function_execute result is a non-tabular string' , ( ) => {
84- expect ( extractTabularData ( { result : 'name,age\nAlice,30' , stdout : '' } ) ) . toBeNull ( )
79+ it ( 'does NOT unwrap function_execute envelopes on its own (callers must pre-unwrap)' , ( ) => {
80+ // Caller is responsible for unwrapping { result, stdout } envelopes first.
81+ // Keeping that concern out of this function prevents a double unwrap when
82+ // the user's payload itself happens to have matching keys.
83+ expect ( extractTabularData ( { result : [ { a : 1 } ] , stdout : '' } ) ) . toBeNull ( )
8584 } )
8685
87- it ( 'still extracts rows from the user_table query_rows shape' , ( ) => {
86+ it ( 'extracts rows from the user_table query_rows shape' , ( ) => {
8887 const rows = extractTabularData ( {
8988 data : {
9089 rows : [
@@ -96,4 +95,10 @@ describe('extractTabularData', () => {
9695 } )
9796 expect ( rows ) . toEqual ( [ { name : 'Alice' } , { name : 'Bob' } ] )
9897 } )
98+
99+ it ( 'returns null for non-tabular inputs' , ( ) => {
100+ expect ( extractTabularData ( 'plain string' ) ) . toBeNull ( )
101+ expect ( extractTabularData ( null ) ) . toBeNull ( )
102+ expect ( extractTabularData ( { foo : 'bar' } ) ) . toBeNull ( )
103+ } )
99104} )
0 commit comments