@@ -3,42 +3,11 @@ import {
33 processPartialToolCalls ,
44 processToolCalls ,
55 processText ,
6- sanitizeToolCallId ,
76 normalizeMessagesForBinding ,
87 prepareToolsAndToolChoice ,
98 createRun ,
109} from "../src/utils" ;
1110
12- // ---------------------------------------------------------------------------
13- // sanitizeToolCallId
14- // ---------------------------------------------------------------------------
15-
16- describe ( "sanitizeToolCallId" , ( ) => {
17- it ( "should strip non-alphanumeric characters and truncate to 9 chars" , ( ) => {
18- expect ( sanitizeToolCallId ( "chatcmpl-tool-875d3ec6179676ae" ) ) . toBe ( "chatcmplt" ) ;
19- } ) ;
20-
21- it ( "should pad short IDs with zeros" , ( ) => {
22- expect ( sanitizeToolCallId ( "abc" ) ) . toBe ( "abc000000" ) ;
23- } ) ;
24-
25- it ( "should pass through already-valid 9-char alphanumeric IDs" , ( ) => {
26- expect ( sanitizeToolCallId ( "abcdef123" ) ) . toBe ( "abcdef123" ) ;
27- } ) ;
28-
29- it ( "should handle empty string" , ( ) => {
30- expect ( sanitizeToolCallId ( "" ) ) . toBe ( "000000000" ) ;
31- } ) ;
32-
33- it ( "should handle IDs with only special characters" , ( ) => {
34- expect ( sanitizeToolCallId ( "---!!!---" ) ) . toBe ( "000000000" ) ;
35- } ) ;
36-
37- it ( "should handle mixed content" , ( ) => {
38- expect ( sanitizeToolCallId ( "call_abc_123" ) ) . toBe ( "callabc12" ) ;
39- } ) ;
40- } ) ;
41-
4211// ---------------------------------------------------------------------------
4312// normalizeMessagesForBinding
4413// ---------------------------------------------------------------------------
@@ -53,7 +22,18 @@ describe("normalizeMessagesForBinding", () => {
5322 expect ( result ) . toEqual ( messages ) ;
5423 } ) ;
5524
56- it ( "should sanitize tool_call_id on tool messages" , ( ) => {
25+ it ( "should convert null content to empty string" , ( ) => {
26+ const messages = [
27+ {
28+ role : "assistant" as const ,
29+ content : null as unknown as string ,
30+ } ,
31+ ] ;
32+ const result = normalizeMessagesForBinding ( messages ) ;
33+ expect ( result [ 0 ] ) . toHaveProperty ( "content" , "" ) ;
34+ } ) ;
35+
36+ it ( "should pass through tool_call_id unchanged" , ( ) => {
5737 const messages = [
5838 {
5939 role : "tool" as const ,
@@ -63,10 +43,10 @@ describe("normalizeMessagesForBinding", () => {
6343 } ,
6444 ] ;
6545 const result = normalizeMessagesForBinding ( messages ) ;
66- expect ( result [ 0 ] ) . toHaveProperty ( "tool_call_id" , "chatcmplt " ) ;
46+ expect ( result [ 0 ] ) . toHaveProperty ( "tool_call_id" , "chatcmpl-tool-875d3ec6179676ae " ) ;
6747 } ) ;
6848
69- it ( "should sanitize tool_calls[].id on assistant messages " , ( ) => {
49+ it ( "should pass through tool_calls[].id unchanged " , ( ) => {
7050 const messages = [
7151 {
7252 role : "assistant" as const ,
@@ -84,21 +64,18 @@ describe("normalizeMessagesForBinding", () => {
8464 const assistant = result [ 0 ] as {
8565 tool_calls ?: Array < { id : string } > ;
8666 } ;
87- expect ( assistant . tool_calls ?. [ 0 ] . id ) . toBe ( "chatcmplt " ) ;
67+ expect ( assistant . tool_calls ?. [ 0 ] . id ) . toBe ( "chatcmpl-tool-abc123def456 " ) ;
8868 } ) ;
8969
9070 it ( "should not mutate the original messages array" , ( ) => {
9171 const original = [
9272 {
93- role : "tool" as const ,
94- name : "fn" ,
95- content : "result" ,
96- tool_call_id : "chatcmpl-tool-abc" ,
73+ role : "assistant" as const ,
74+ content : null as unknown as string ,
9775 } ,
9876 ] ;
99- const originalId = original [ 0 ] . tool_call_id ;
10077 normalizeMessagesForBinding ( original ) ;
101- expect ( original [ 0 ] . tool_call_id ) . toBe ( originalId ) ;
78+ expect ( original [ 0 ] . content ) . toBeNull ( ) ;
10279 } ) ;
10380} ) ;
10481
0 commit comments