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,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', () => {
Expand Down
10 changes: 10 additions & 0 deletions pr_desc.md
Original file line number Diff line number Diff line change
@@ -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.
Loading