diff --git a/packages/web/src/lib/server/events.test.ts b/packages/web/src/lib/server/events.test.ts index 33f9842..2cfe5a1 100644 --- a/packages/web/src/lib/server/events.test.ts +++ b/packages/web/src/lib/server/events.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { deriveFields } from './events' +import { deriveFields, truncateToolResponse } from './events' describe('deriveFields', () => { it('marks normalized slash commands as skill calls', () => { @@ -67,3 +67,31 @@ describe('deriveFields', () => { }) }) }) + + +describe('truncateToolResponse', () => { + it('returns undefined if response is undefined', () => { + expect(truncateToolResponse(undefined)).toBeUndefined() + }) + + it('returns undefined if response is empty string', () => { + expect(truncateToolResponse('')).toBeUndefined() + }) + + it('returns the same string if length is less than 2000', () => { + const shortString = 'Hello, world!' + expect(truncateToolResponse(shortString)).toBe(shortString) + }) + + it('returns the same string if length is exactly 2000', () => { + const exactString = 'a'.repeat(2000) + expect(truncateToolResponse(exactString)).toBe(exactString) + }) + + it('truncates the string to 2000 characters if length is greater than 2000', () => { + const longString = 'a'.repeat(2500) + const truncated = truncateToolResponse(longString) + expect(truncated).toBe('a'.repeat(2000)) + expect(truncated?.length).toBe(2000) + }) +}) diff --git a/pr_description.txt b/pr_description.txt new file mode 100644 index 0000000..8d30ce6 --- /dev/null +++ b/pr_description.txt @@ -0,0 +1,12 @@ +🎯 **What:** The testing gap addressed +Added tests for the `truncateToolResponse` function in `packages/web/src/lib/server/events.ts`. + +📊 **Coverage:** What scenarios are now tested +- `undefined` input. +- Empty string input. +- Strings shorter than the 2000 character limit. +- Strings exactly 2000 characters long. +- Strings longer than the 2000 character limit, confirming they are correctly truncated. + +✨ **Result:** The improvement in test coverage +The `truncateToolResponse` function is now fully tested, ensuring that responses are appropriately truncated without causing errors across various edge cases and standard input sizes.