ForcePilot/test/test_conversation_repository.py
肖泽涛 80cf6937ed fix: 修复新增对话时内容直接作为标题长度超出表字段长度限制问题, titile 字段长度限制为255
- 新增 MAX_CONVERSATION_TITLE_LENGTH 常量 (255 字符)
- 新增 _normalize_title() 方法用于截断和校验标题
- 防止创建和更新对话时数据库字段溢出
- 前端 AgentChatComponent 同步添加标题标准化处理
- 添加标题标准化的单元测试
2026-02-25 10:39:32 +08:00

23 lines
727 B
Python

from __future__ import annotations
from src.repositories.conversation_repository import ConversationRepository, MAX_CONVERSATION_TITLE_LENGTH
def test_normalize_title_truncates_when_too_long():
repo = ConversationRepository(None) # type: ignore[arg-type]
raw = "a" * (MAX_CONVERSATION_TITLE_LENGTH + 50)
normalized = repo._normalize_title(raw)
assert normalized is not None
assert len(normalized) == MAX_CONVERSATION_TITLE_LENGTH
assert normalized == "a" * MAX_CONVERSATION_TITLE_LENGTH
def test_normalize_title_trims_spaces():
repo = ConversationRepository(None) # type: ignore[arg-type]
normalized = repo._normalize_title(" hello world ")
assert normalized == "hello world"