diff --git a/extensions/cli/src/tools/fetch.test.ts b/extensions/cli/src/tools/fetch.test.ts index 9a1aec105..cbb19e38b 100644 --- a/extensions/cli/src/tools/fetch.test.ts +++ b/extensions/cli/src/tools/fetch.test.ts @@ -48,7 +48,7 @@ describe("fetchTool", () => { ); }); - it("should handle truncation warnings from core implementation", async () => { + it("should filter out truncation warnings from core implementation", async () => { const mockContextItems: ContextItem[] = [ { name: "Long Page", @@ -68,9 +68,8 @@ describe("fetchTool", () => { const result = await fetchTool.run({ url: "https://example.com" }); - expect(result).toBe( - "This is the main content that was truncated.\n\nThe content from https://example.com was truncated because it exceeded the 20000 character limit.", - ); + // Truncation warnings are filtered out - only the main content is returned + expect(result).toBe("This is the main content that was truncated."); }); it("should handle multiple content items", async () => { diff --git a/extensions/cli/src/util/tokenizer.test.ts b/extensions/cli/src/util/tokenizer.test.ts index 2ac81bdc9..f1361732e 100644 --- a/extensions/cli/src/util/tokenizer.test.ts +++ b/extensions/cli/src/util/tokenizer.test.ts @@ -488,6 +488,53 @@ describe("tokenizer", () => { expect(tokensWithEnum).toBeGreaterThan(tokensWithoutEnum); }); + it("should handle empty enum array without negative token count", () => { + const toolsWithEmptyEnum = [ + { + type: "function" as const, + function: { + name: "set_mode", + parameters: { + type: "object", + properties: { + mode: { + type: "string", + description: "The mode to set", + enum: [], + }, + }, + }, + }, + }, + ]; + + const toolsWithoutEnum = [ + { + type: "function" as const, + function: { + name: "set_mode", + parameters: { + type: "object", + properties: { + mode: { + type: "string", + description: "The mode to set", + }, + }, + }, + }, + }, + ]; + + const tokensWithEmptyEnum = countToolDefinitionTokens(toolsWithEmptyEnum); + const tokensWithoutEnum = countToolDefinitionTokens(toolsWithoutEnum); + + // Empty enum should not subtract tokens - should be equal to no enum + expect(tokensWithEmptyEnum).toBe(tokensWithoutEnum); + // Token count should always be positive + expect(tokensWithEmptyEnum).toBeGreaterThan(0); + }); + it("should count tokens for multiple parameters", () => { const toolWithOneParam = [ { diff --git a/extensions/cli/src/util/tokenizer.ts b/extensions/cli/src/util/tokenizer.ts index cfacac1e8..68f10c5f0 100644 --- a/extensions/cli/src/util/tokenizer.ts +++ b/extensions/cli/src/util/tokenizer.ts @@ -223,7 +223,7 @@ function countParameterFieldTokens( tokens += encode(fieldDesc).length; } - if (fieldEnum && Array.isArray(fieldEnum)) { + if (fieldEnum && Array.isArray(fieldEnum) && fieldEnum.length > 0) { tokens -= 3; for (const e of fieldEnum) { tokens += 3;