@@ -10,56 +10,62 @@ describe("parseStandalonePlainTextToolCallBlocks", () => {
1010 '[get_weather]\n{"city":"NYC"}\n[END_TOOL_REQUEST]' ,
1111 ) ;
1212 expect ( result ) . not . toBeNull ( ) ;
13- expect ( result ) . toHaveLength ( 1 ) ;
14- expect ( result ! [ 0 ] ! . name ) . toBe ( "get_weather" ) ;
15- expect ( result ! [ 0 ] ! . arguments ) . toEqual ( { city : "NYC" } ) ;
13+ const blocks = result ! ;
14+ expect ( blocks ) . toHaveLength ( 1 ) ;
15+ expect ( blocks [ 0 ] ! . name ) . toBe ( "get_weather" ) ;
16+ expect ( blocks [ 0 ] ! . arguments ) . toEqual ( { city : "NYC" } ) ;
1617 } ) ;
1718
1819 it ( "parses multiple bracket-style tool calls" , ( ) => {
1920 const result = parseStandalonePlainTextToolCallBlocks (
2021 '[get_weather]\n{"city":"NYC"}\n[END_TOOL_REQUEST]\n[search]\n{"q":"hello"}\n[/search]' ,
2122 ) ;
2223 expect ( result ) . not . toBeNull ( ) ;
23- expect ( result ) . toHaveLength ( 2 ) ;
24- expect ( result ! [ 0 ] ! . name ) . toBe ( "get_weather" ) ;
25- expect ( result ! [ 1 ] ! . name ) . toBe ( "search" ) ;
24+ const blocks = result ! ;
25+ expect ( blocks ) . toHaveLength ( 2 ) ;
26+ expect ( blocks [ 0 ] ! . name ) . toBe ( "get_weather" ) ;
27+ expect ( blocks [ 1 ] ! . name ) . toBe ( "search" ) ;
2628 } ) ;
2729
2830 it ( "parses tool: prefix bracket opening (no newline or closing marker required)" , ( ) => {
2931 const result = parseStandalonePlainTextToolCallBlocks (
3032 '[tool:get_weather]{"city":"NYC"}' ,
3133 ) ;
3234 expect ( result ) . not . toBeNull ( ) ;
33- expect ( result ) . toHaveLength ( 1 ) ;
34- expect ( result ! [ 0 ] ! . name ) . toBe ( "get_weather" ) ;
35- expect ( result ! [ 0 ] ! . arguments ) . toEqual ( { city : "NYC" } ) ;
35+ const blocks = result ! ;
36+ expect ( blocks ) . toHaveLength ( 1 ) ;
37+ expect ( blocks [ 0 ] ! . name ) . toBe ( "get_weather" ) ;
38+ expect ( blocks [ 0 ] ! . arguments ) . toEqual ( { city : "NYC" } ) ;
3639 } ) ;
3740
3841 it ( "parses harmony-style tool call with channel marker" , ( ) => {
3942 const result = parseStandalonePlainTextToolCallBlocks (
4043 '<|channel|>commentary to=get_weather code {"city":"NYC"}<|call|>' ,
4144 ) ;
4245 expect ( result ) . not . toBeNull ( ) ;
43- expect ( result ) . toHaveLength ( 1 ) ;
44- expect ( result ! [ 0 ] ! . name ) . toBe ( "get_weather" ) ;
46+ const blocks = result ! ;
47+ expect ( blocks ) . toHaveLength ( 1 ) ;
48+ expect ( blocks [ 0 ] ! . name ) . toBe ( "get_weather" ) ;
4549 } ) ;
4650
4751 it ( "parses harmony-style tool call without channel marker" , ( ) => {
4852 const result = parseStandalonePlainTextToolCallBlocks (
4953 'analysis to=search code {"q":"test"}<|call|>' ,
5054 ) ;
5155 expect ( result ) . not . toBeNull ( ) ;
52- expect ( result ) . toHaveLength ( 1 ) ;
53- expect ( result ! [ 0 ] ! . name ) . toBe ( "search" ) ;
56+ const blocks = result ! ;
57+ expect ( blocks ) . toHaveLength ( 1 ) ;
58+ expect ( blocks [ 0 ] ! . name ) . toBe ( "search" ) ;
5459 } ) ;
5560
5661 it ( "parses harmony-style with optional message marker" , ( ) => {
5762 const result = parseStandalonePlainTextToolCallBlocks (
5863 'final to=summarize code <|message|> {"text":"hello"}<|call|>' ,
5964 ) ;
6065 expect ( result ) . not . toBeNull ( ) ;
61- expect ( result ) . toHaveLength ( 1 ) ;
62- expect ( result ! [ 0 ] ! . name ) . toBe ( "summarize" ) ;
66+ const blocks = result ! ;
67+ expect ( blocks ) . toHaveLength ( 1 ) ;
68+ expect ( blocks [ 0 ] ! . name ) . toBe ( "summarize" ) ;
6369 } ) ;
6470
6571 it ( "respects allowedToolNames filter" , ( ) => {
@@ -151,9 +157,10 @@ describe("parseStandalonePlainTextToolCallBlocks", () => {
151157 '[tool:search]{"q":"hello"}[tool:weather]{"city":"NYC"}' ,
152158 ) ;
153159 expect ( result ) . not . toBeNull ( ) ;
154- expect ( result ) . toHaveLength ( 2 ) ;
155- expect ( result ! [ 0 ] ! . name ) . toBe ( "search" ) ;
156- expect ( result ! [ 1 ] ! . name ) . toBe ( "weather" ) ;
160+ const blocks = result ! ;
161+ expect ( blocks ) . toHaveLength ( 2 ) ;
162+ expect ( blocks [ 0 ] ! . name ) . toBe ( "search" ) ;
163+ expect ( blocks [ 1 ] ! . name ) . toBe ( "weather" ) ;
157164 } ) ;
158165
159166 it ( "rejects bracket style missing newline before JSON" , ( ) => {
@@ -175,9 +182,10 @@ describe("parseStandalonePlainTextToolCallBlocks", () => {
175182 const text = '[get_weather]\n{"city":"NYC"}\n[END_TOOL_REQUEST]' ;
176183 const result = parseStandalonePlainTextToolCallBlocks ( text ) ;
177184 expect ( result ) . not . toBeNull ( ) ;
178- expect ( result ! [ 0 ] ! . start ) . toBe ( 0 ) ;
179- expect ( result ! [ 0 ] ! . end ) . toBe ( text . length ) ;
180- expect ( result ! [ 0 ] ! . raw ) . toBe ( text ) ;
185+ const blocks = result ! ;
186+ expect ( blocks [ 0 ] ! . start ) . toBe ( 0 ) ;
187+ expect ( blocks [ 0 ] ! . end ) . toBe ( text . length ) ;
188+ expect ( blocks [ 0 ] ! . raw ) . toBe ( text ) ;
181189 } ) ;
182190} ) ;
183191
0 commit comments