Improve replayed run status handling
This commit is contained in:
@@ -16,7 +16,12 @@ from pathlib import Path
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from backend.api.server import AgentState, create_app
|
||||
from backend.api.server import (
|
||||
AgentState,
|
||||
create_app,
|
||||
_runtime_event_stage,
|
||||
_sanitize_stored_session_for_resume,
|
||||
)
|
||||
from src.agent_types import AgentRunResult
|
||||
from src.session_store import StoredAgentSession, load_agent_session, save_agent_session
|
||||
|
||||
@@ -360,6 +365,52 @@ class GuiServerTests(unittest.TestCase):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json()['status'], 'interrupted')
|
||||
|
||||
def test_resume_sanitizer_removes_ui_run_status_messages(self) -> None:
|
||||
stored = StoredAgentSession(
|
||||
session_id='thread-1',
|
||||
model_config={'model': 'test-model'},
|
||||
runtime_config={},
|
||||
system_prompt_parts=('system prompt',),
|
||||
user_context={},
|
||||
system_context={},
|
||||
messages=(
|
||||
{'role': 'user', 'content': 'hello'},
|
||||
{
|
||||
'role': 'assistant',
|
||||
'content': '上一次任务已中断,后台没有正在执行的进程。',
|
||||
'state': 'final',
|
||||
'stop_reason': 'interrupted',
|
||||
'metadata': {'kind': 'run_status', 'status': 'interrupted'},
|
||||
},
|
||||
{'role': 'user', 'content': 'continue'},
|
||||
),
|
||||
turns=1,
|
||||
tool_calls=0,
|
||||
usage={},
|
||||
total_cost_usd=0.0,
|
||||
file_history=(),
|
||||
budget_state={'status': 'interrupted'},
|
||||
plugin_state={},
|
||||
)
|
||||
|
||||
sanitized = _sanitize_stored_session_for_resume(stored)
|
||||
|
||||
self.assertEqual(
|
||||
[message['content'] for message in sanitized.messages],
|
||||
['hello', 'continue'],
|
||||
)
|
||||
|
||||
def test_runtime_event_stage_names_long_running_work(self) -> None:
|
||||
self.assertEqual(
|
||||
_runtime_event_stage({'type': 'tool_start', 'tool_name': 'python_exec'}),
|
||||
'调用工具 python_exec',
|
||||
)
|
||||
self.assertEqual(
|
||||
_runtime_event_stage({'type': 'final_text_start'}),
|
||||
'正在整理回复',
|
||||
)
|
||||
self.assertEqual(_runtime_event_stage({'type': 'server_heartbeat'}), '')
|
||||
|
||||
def test_chat_uses_account_scoped_model_config(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
client, _ = _build_client(Path(d))
|
||||
|
||||
Reference in New Issue
Block a user