diff --git a/packages/web/src/lib/server/events.test.ts b/packages/web/src/lib/server/events.test.ts index 33f9842..9cef457 100644 --- a/packages/web/src/lib/server/events.test.ts +++ b/packages/web/src/lib/server/events.test.ts @@ -1,5 +1,33 @@ import { describe, expect, it } from 'vitest' -import { deriveFields } from './events' +import { deriveFields, truncateToolResponse } from './events' + + +describe('truncateToolResponse', () => { + it('returns undefined when input is undefined', () => { + expect(truncateToolResponse(undefined)).toBeUndefined() + }) + + it('returns undefined when input is empty string', () => { + expect(truncateToolResponse('')).toBeUndefined() + }) + + it('returns original string when length is exactly 2000', () => { + const str = 'a'.repeat(2000) + expect(truncateToolResponse(str)).toBe(str) + }) + + it('returns original string when length is less than 2000', () => { + const str = 'hello world' + expect(truncateToolResponse(str)).toBe(str) + }) + + it('truncates string to exactly 2000 characters when length is greater than 2000', () => { + const longStr = 'a'.repeat(2500) + const result = truncateToolResponse(longStr) + expect(result).toHaveLength(2000) + expect(result).toBe('a'.repeat(2000)) + }) +}) describe('deriveFields', () => { it('marks normalized slash commands as skill calls', () => { diff --git a/pr_desc.md b/pr_desc.md new file mode 100644 index 0000000..a825dcb --- /dev/null +++ b/pr_desc.md @@ -0,0 +1,10 @@ +🎯 **What:** Adds unit tests for the previously untested `truncateToolResponse` function in `packages/web/src/lib/server/events.ts`. This closes a testing gap for a small, pure string manipulation function. + +📊 **Coverage:** Covered the following scenarios: +- Undefined input (returns undefined) +- Empty string input (returns undefined) +- String length exactly 2000 (returns original string) +- String length < 2000 (returns original string) +- String length > 2000 (returns truncated string of exactly 2000 characters) + +✨ **Result:** Improved test coverage and reliability. Future refactors around payload truncations will be safe.