Files
lobehub__lobehub/packages/utils/src/clampToolIdentifier.test.ts
Arvin Xu 5512942ba4 🐛 fix: clamp message plugin identifier/apiName to 255 chars at every write path (#19002)
* 🐛 fix: clamp message plugin identifier/apiName to 255 chars at every write path

Hallucinated tool calls have written multi-KB values (artifact XML, shell
commands) into message_plugins.identifier / api_name. With those columns now
btree-indexed, any value past the index tuple size limit fails the whole row
insert, so every write path clamps before hitting the database.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* ✅ test: cover message plugin identifier clamping

* ✅ test: include plugin arguments in clamp fixture

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-04 22:57:51 +08:00

26 lines
871 B
TypeScript

import { describe, expect, it } from 'vitest';
import { clampToolIdentifier, MAX_TOOL_IDENTIFIER_LENGTH } from './clampToolIdentifier';
describe('clampToolIdentifier', () => {
it('passes through short values untouched', () => {
expect(clampToolIdentifier('lobe-agent')).toBe('lobe-agent');
expect(clampToolIdentifier('')).toBe('');
});
it('passes through null and undefined', () => {
expect(clampToolIdentifier(null)).toBeNull();
expect(clampToolIdentifier(undefined)).toBeUndefined();
});
it('keeps a value exactly at the limit', () => {
const value = 'a'.repeat(MAX_TOOL_IDENTIFIER_LENGTH);
expect(clampToolIdentifier(value)).toBe(value);
});
it('truncates oversized values to the limit', () => {
const value = 'x'.repeat(40_000);
expect(clampToolIdentifier(value)).toHaveLength(MAX_TOOL_IDENTIFIER_LENGTH);
});
});