fix(chat): 修改智能体列表

This commit is contained in:
sophie committed 2026-06-29 15:26:11 +08:00
1 parent cafce5cfa9
commit 7e4a2037d8
8 files changed
+71 -17

No files matched your search

+27 -1
View File
@@ -1,5 +1,5 @@
import pytest
from app.models import Agent, User, PermissionRequest
from app.models import Agent, ChatLog, User, PermissionRequest
from app import db
def test_agent_lifecycle(client, admin_headers):
@@ -278,3 +278,29 @@ def test_reports(client, admin_headers):
data = response.json
assert 'avg_score' in data
assert 'distribution' in data
def test_chat_logs_report_filters_by_real_name(client, app, admin_headers):
"""聊天日志报表真实姓名筛选:real_name 是 User 关联字段,列表与计数必须使用同一过滤条件。"""
with app.app_context():
agent = Agent(name='HR Assistant', type='api', dify_app_id='hr-app', dify_api_key='hr-key')
sophie = User(username='26030025', email='sophie@example.com', real_name='sophie', role='user')
admin = User(username='admin-user', email='admin-user@example.com', real_name='admin', role='user')
db.session.add_all([agent, sophie, admin])
db.session.flush()
db.session.add_all([
ChatLog(user_id=sophie.id, agent_id=agent.id, query='人事规章', answer='A', tokens_used=1),
ChatLog(user_id=admin.id, agent_id=agent.id, query='上班时间', answer='B', tokens_used=1),
])
db.session.commit()
response = client.get('/api/admin/database/chat_logs?real_name=sophie', headers=admin_headers)
assert response.status_code == 200
rows = response.json
assert len(rows) == 1
assert rows[0]['real_name'] == 'sophie'
assert rows[0]['username'] == '26030025'
count_response = client.get('/api/admin/database/chat_logs/count?real_name=sophie', headers=admin_headers)
assert count_response.status_code == 200
assert count_response.json['total'] == 1