File tree Expand file tree Collapse file tree 3 files changed +51
-5
lines changed
Expand file tree Collapse file tree 3 files changed +51
-5
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ describe("fetchTool", () => {
4848 ) ;
4949 } ) ;
5050
51- it ( "should handle truncation warnings from core implementation" , async ( ) => {
51+ it ( "should filter out truncation warnings from core implementation" , async ( ) => {
5252 const mockContextItems : ContextItem [ ] = [
5353 {
5454 name : "Long Page" ,
@@ -68,9 +68,8 @@ describe("fetchTool", () => {
6868
6969 const result = await fetchTool . run ( { url : "https://example.com" } ) ;
7070
71- expect ( result ) . toBe (
72- "This is the main content that was truncated.\n\nThe content from https://example.com was truncated because it exceeded the 20000 character limit." ,
73- ) ;
71+ // Truncation warnings are filtered out - only the main content is returned
72+ expect ( result ) . toBe ( "This is the main content that was truncated." ) ;
7473 } ) ;
7574
7675 it ( "should handle multiple content items" , async ( ) => {
Original file line number Diff line number Diff line change @@ -488,6 +488,53 @@ describe("tokenizer", () => {
488488 expect ( tokensWithEnum ) . toBeGreaterThan ( tokensWithoutEnum ) ;
489489 } ) ;
490490
491+ it ( "should handle empty enum array without negative token count" , ( ) => {
492+ const toolsWithEmptyEnum = [
493+ {
494+ type : "function" as const ,
495+ function : {
496+ name : "set_mode" ,
497+ parameters : {
498+ type : "object" ,
499+ properties : {
500+ mode : {
501+ type : "string" ,
502+ description : "The mode to set" ,
503+ enum : [ ] ,
504+ } ,
505+ } ,
506+ } ,
507+ } ,
508+ } ,
509+ ] ;
510+
511+ const toolsWithoutEnum = [
512+ {
513+ type : "function" as const ,
514+ function : {
515+ name : "set_mode" ,
516+ parameters : {
517+ type : "object" ,
518+ properties : {
519+ mode : {
520+ type : "string" ,
521+ description : "The mode to set" ,
522+ } ,
523+ } ,
524+ } ,
525+ } ,
526+ } ,
527+ ] ;
528+
529+ const tokensWithEmptyEnum = countToolDefinitionTokens ( toolsWithEmptyEnum ) ;
530+ const tokensWithoutEnum = countToolDefinitionTokens ( toolsWithoutEnum ) ;
531+
532+ // Empty enum should not subtract tokens - should be equal to no enum
533+ expect ( tokensWithEmptyEnum ) . toBe ( tokensWithoutEnum ) ;
534+ // Token count should always be positive
535+ expect ( tokensWithEmptyEnum ) . toBeGreaterThan ( 0 ) ;
536+ } ) ;
537+
491538 it ( "should count tokens for multiple parameters" , ( ) => {
492539 const toolWithOneParam = [
493540 {
Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ function countParameterFieldTokens(
223223 tokens += encode ( fieldDesc ) . length ;
224224 }
225225
226- if ( fieldEnum && Array . isArray ( fieldEnum ) ) {
226+ if ( fieldEnum && Array . isArray ( fieldEnum ) && fieldEnum . length > 0 ) {
227227 tokens -= 3 ;
228228 for ( const e of fieldEnum ) {
229229 tokens += 3 ;
You can’t perform that action at this time.
0 commit comments