mirror of
https://github.com/lobehub/lobehub.git
synced 2026-09-20 04:56:13 +08:00
5512942ba4
* 🐛 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>
26 lines
871 B
TypeScript
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);
|
|
});
|
|
});
|