Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion packages/web/src/lib/server/events.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -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)
})
})
12 changes: 12 additions & 0 deletions pr_description.txt
Original file line number Diff line number Diff line change
@@ -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.
Loading