@@ -83,11 +83,40 @@ describe('provider tool identities', () => {
8383
8484 assignProviderToolIdentities ( tools )
8585
86- expect ( tools [ 0 ] . id ) . toBe ( longId )
86+ expect ( tools [ 0 ] . id ) . toHaveLength ( 64 )
87+ expect ( tools [ 0 ] . id ) . toMatch ( / _ _ s i m _ 1 $ / )
88+ expect ( tools [ 0 ] . canonicalId ) . toBe ( longId )
8789 expect ( tools [ 1 ] . id ) . toHaveLength ( 64 )
8890 expect ( tools [ 1 ] . id ) . toMatch ( / _ _ s i m _ 2 $ / )
8991 } )
9092
93+ it ( 'preserves ids at the limit and aliases unique overlong ids without collisions' , ( ) => {
94+ const prefix = 'a' . repeat ( 57 )
95+ const longId = `${ prefix } ${ 'b' . repeat ( 8 ) } `
96+ const otherLongId = `${ prefix } ${ 'c' . repeat ( 8 ) } `
97+ const reservedId = `${ prefix } __sim_1`
98+ const tools = [
99+ providerTool ( longId , 'a' ) ,
100+ providerTool ( otherLongId , 'b' ) ,
101+ providerTool ( reservedId , 'reserved' ) ,
102+ providerTool ( 'd' . repeat ( 64 ) , 'at-limit' ) ,
103+ ]
104+
105+ const identities = assignProviderToolIdentities ( tools )
106+ const wireIds = tools . map ( ( tool ) => tool . id )
107+
108+ expect ( new Set ( wireIds ) . size ) . toBe ( 4 )
109+ expect ( wireIds . every ( ( id ) => id . length <= 64 ) ) . toBe ( true )
110+ expect ( tools [ 2 ] . id ) . toBe ( reservedId )
111+ expect ( tools [ 3 ] . id ) . toBe ( 'd' . repeat ( 64 ) )
112+ expect ( identities . toolIdByWireId . get ( tools [ 0 ] . id ) ) . toBe ( longId )
113+ expect ( identities . toolIdByWireId . get ( tools [ 1 ] . id ) ) . toBe ( otherLongId )
114+ expect ( tools [ 0 ] . params . oauthCredential ) . toBe ( 'a' )
115+
116+ assignProviderToolIdentities ( tools )
117+ expect ( tools . map ( ( tool ) => tool . id ) ) . toEqual ( wireIds )
118+ } )
119+
91120 it ( 'projects provider response names back to their canonical ids' , ( ) => {
92121 const tools = [ providerTool ( 'gmail_send' , 'a' ) , providerTool ( 'gmail_send' , 'b' ) ]
93122 const identities = assignProviderToolIdentities ( tools )
0 commit comments