|
47 | 47 | load_session_activity, |
48 | 48 | load_session_messages_activity, |
49 | 49 | ) |
50 | | -from tracecat.agent.session.types import AgentSessionEntity |
| 50 | +from tracecat.agent.session.types import AgentSessionEntity, AgentSessionStatus |
51 | 51 | from tracecat.agent.skill.types import ResolvedSkillRef |
52 | 52 | from tracecat.agent.subagents import ResolvedAgentsConfig |
53 | 53 | from tracecat.agent.tools import BuildToolsResult |
@@ -394,6 +394,41 @@ async def test_idempotent_for_existing_session( |
394 | 394 | assert result.success is True |
395 | 395 | assert result.session_id == mock_session_id |
396 | 396 |
|
| 397 | + @pytest.mark.anyio |
| 398 | + @patch("tracecat.agent.session.activities.AgentSessionService.with_session") |
| 399 | + async def test_curr_run_id_does_not_mark_session_running( |
| 400 | + self, mock_with_session, mock_role: Role, mock_session_id: uuid.UUID |
| 401 | + ): |
| 402 | + """Create setup records the run token without taking the running lock.""" |
| 403 | + curr_run_id = uuid.uuid4() |
| 404 | + input = CreateSessionInput( |
| 405 | + role=mock_role, |
| 406 | + session_id=mock_session_id, |
| 407 | + entity_type=AgentSessionEntity.WORKFLOW, |
| 408 | + entity_id=uuid.uuid4(), |
| 409 | + curr_run_id=curr_run_id, |
| 410 | + ) |
| 411 | + |
| 412 | + mock_agent_session = MagicMock() |
| 413 | + mock_agent_session.agents_binding = None |
| 414 | + mock_agent_session.status = AgentSessionStatus.IDLE.value |
| 415 | + mock_service = AsyncMock() |
| 416 | + mock_service.get_or_create_session.return_value = (mock_agent_session, False) |
| 417 | + mock_service.session = MagicMock() |
| 418 | + mock_service.session.commit = AsyncMock() |
| 419 | + |
| 420 | + mock_ctx = AsyncMock() |
| 421 | + mock_ctx.__aenter__.return_value = mock_service |
| 422 | + mock_with_session.return_value = mock_ctx |
| 423 | + |
| 424 | + result = await create_session_activity(input) |
| 425 | + |
| 426 | + assert result.success is True |
| 427 | + assert mock_agent_session.curr_run_id == curr_run_id |
| 428 | + assert mock_agent_session.status == AgentSessionStatus.IDLE.value |
| 429 | + mock_service.session.add.assert_called_once_with(mock_agent_session) |
| 430 | + mock_service.session.commit.assert_awaited_once() |
| 431 | + |
397 | 432 | @pytest.mark.anyio |
398 | 433 | @patch("tracecat.agent.session.activities.AgentSessionService.with_session") |
399 | 434 | async def test_backfills_disabled_agents_binding_for_legacy_existing_session( |
|
0 commit comments