Persist active run event history
This commit is contained in:
@@ -262,6 +262,43 @@ class GuiServerTests(unittest.TestCase):
|
||||
self.assertEqual(payload['status'], 'running')
|
||||
self.assertEqual(payload['current_stage'], 'first stage')
|
||||
|
||||
def test_latest_run_includes_runtime_event_history(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
client, state = _build_client(Path(d))
|
||||
record = state.run_manager.start('alice', 'thread-1')
|
||||
state.run_manager.update(record.run_id, status='running')
|
||||
state.run_manager.record_event(
|
||||
record.run_id,
|
||||
{
|
||||
'type': 'tool_start',
|
||||
'tool_name': 'python_exec',
|
||||
'tool_call_id': 'call-1',
|
||||
'arguments': {'code': 'print(1)'},
|
||||
'assistant_content': '我用 Python 分析一下。',
|
||||
},
|
||||
)
|
||||
state.run_manager.record_event(
|
||||
record.run_id,
|
||||
{
|
||||
'type': 'tool_result',
|
||||
'tool_name': 'python_exec',
|
||||
'tool_call_id': 'call-1',
|
||||
'ok': True,
|
||||
'metadata': {'output_preview': 'exit_code=0'},
|
||||
},
|
||||
)
|
||||
|
||||
latest = client.get(
|
||||
'/api/runs/latest',
|
||||
params={'account_id': 'alice', 'session_id': 'thread-1'},
|
||||
)
|
||||
|
||||
self.assertEqual(latest.status_code, 200)
|
||||
events = latest.json()['events']
|
||||
self.assertEqual([event['type'] for event in events], ['tool_start', 'tool_result'])
|
||||
self.assertEqual(events[0]['tool_name'], 'python_exec')
|
||||
self.assertEqual(events[1]['metadata']['output_preview'], 'exit_code=0')
|
||||
|
||||
def test_cancel_run_marks_streaming_session_tail_cancelled(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
root = Path(d)
|
||||
|
||||
Reference in New Issue
Block a user