From cdfd2f513db89e2c440bf7fd4c4f7ffb221a6b45 Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Wed, 10 Jun 2026 13:58:55 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20tests=20for=20truncateTool?= =?UTF-8?q?Response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/web/src/lib/server/events.test.ts | 30 +++++++++++++++++++++- pr_desc.md | 10 ++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 pr_desc.md 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.