feat(file-check): 增加文件检核进度展示功能及相关配置
This commit is contained in:
1 parent
d3cfd24d6f
commit
9b36ced288
11 files changed
+361
-13
No files matched your search
@@ -2,13 +2,17 @@
|
||||
services/file_check_tools/chat_log_run_resolver.py
|
||||
|
||||
用途:按 ChatLog.run_id 解析文件检核进度(按轮问答)。
|
||||
依赖:ChatLog、ScheduleRun。
|
||||
逻辑:由 for-log API 调用;run_id 在 message_end 写入 chat_logs 表。
|
||||
依赖:ChatLog、ScheduleRun、chat_log_run_binding、chat_turn_registry。
|
||||
逻辑:for-log API 调用;优先读 chat_logs.run_id,缺失时按 session/query 兜底匹配并懒回写。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from app import db
|
||||
from app.models import ChatLog, ScheduleRun
|
||||
from app.services.file_check_tools.chat_log_run_binding import (
|
||||
resolve_run_id_for_chat_log,
|
||||
update_chat_log_run_id,
|
||||
)
|
||||
|
||||
|
||||
def find_run_for_chat_log(
|
||||
@@ -30,10 +34,24 @@ def find_run_for_chat_log(
|
||||
return None
|
||||
|
||||
log = db.session.get(ChatLog, chat_log_id)
|
||||
if not log or not log.run_id:
|
||||
if not log:
|
||||
return None
|
||||
|
||||
run = db.session.get(ScheduleRun, log.run_id)
|
||||
run_id = int(log.run_id) if log.run_id else None
|
||||
if not run_id:
|
||||
# [STEP 1] message_end 可能早于 Tool 启动完成,按 session/query 从注册表或 ScheduleRun 兜底
|
||||
resolved = resolve_run_id_for_chat_log(
|
||||
session_id=log.session_id,
|
||||
query=log.query,
|
||||
)
|
||||
if resolved:
|
||||
update_chat_log_run_id(chat_log_id, resolved)
|
||||
run_id = resolved
|
||||
|
||||
if not run_id:
|
||||
return None
|
||||
|
||||
run = db.session.get(ScheduleRun, run_id)
|
||||
if run and run.schedule_task_id == task_id:
|
||||
return run
|
||||
return None
|
||||
|
||||
@@ -653,6 +653,51 @@ def test_workspace_file_check_run_for_log_returns_null_when_unbound(app, client)
|
||||
assert payload.get('match_source') is None
|
||||
|
||||
|
||||
def test_workspace_file_check_run_for_log_lazy_binds_via_session_query(app, client):
|
||||
"""chat_log 尚无 run_id 时,for-log 应按 session/query 兜底匹配并回写。"""
|
||||
with app.app_context():
|
||||
admin = _mk_admin()
|
||||
db.session.commit()
|
||||
task = _mk_check_task(admin.id)
|
||||
run = ScheduleRun(
|
||||
run_no='RUN-ROHS-LAZY',
|
||||
schedule_task_id=task.id,
|
||||
status='running',
|
||||
trigger_type='dify_chatflow',
|
||||
api_request_json={
|
||||
'bind_session_id': 'sess-lazy-bind',
|
||||
'bind_user_message': '立即执行文件检核',
|
||||
},
|
||||
)
|
||||
db.session.add(run)
|
||||
db.session.commit()
|
||||
log = ChatLog(
|
||||
user_id=admin.id,
|
||||
agent_id=1,
|
||||
query='立即执行文件检核',
|
||||
answer='检核已启动',
|
||||
session_id='sess-lazy-bind',
|
||||
)
|
||||
db.session.add(log)
|
||||
db.session.commit()
|
||||
task_id = task.id
|
||||
chat_log_id = log.id
|
||||
run_id = run.id
|
||||
|
||||
res = client.get(
|
||||
f'/api/workspace/file-check/runs/for-log?task_id={task_id}&chat_log_id={chat_log_id}',
|
||||
headers={'X-Username': 'admin'},
|
||||
)
|
||||
assert res.status_code == 200
|
||||
payload = res.get_json()
|
||||
assert payload['run']['run_id'] == run_id
|
||||
assert payload['match_source'] == 'chat_log'
|
||||
|
||||
with app.app_context():
|
||||
rebound = db.session.get(ChatLog, chat_log_id)
|
||||
assert rebound.run_id == run_id
|
||||
|
||||
|
||||
def test_workspace_file_check_run_for_log_reads_bound_run_id(app, client):
|
||||
with app.app_context():
|
||||
admin = _mk_admin()
|
||||
|
||||
Reference in new issue
Block a user