fix: tests and cubic feedback

This commit is contained in:
Dallin Romney 2026-01-09 16:07:33 -08:00
parent 5d7327f8e0
commit d7b91f884c
3 changed files with 51 additions and 5 deletions

View file

@ -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 () => {

View file

@ -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 = [
{

View file

@ -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;