|
3 | 3 |
|
4 | 4 | from agent_chat_cli.app import AgentChatCLIApp |
5 | 5 | from agent_chat_cli.components.chat_history import ChatHistory |
| 6 | +from agent_chat_cli.components.messages import ( |
| 7 | + MessageType, |
| 8 | + SystemMessage, |
| 9 | + UserMessage, |
| 10 | + AgentMessage, |
| 11 | +) |
6 | 12 | from agent_chat_cli.components.tool_permission_prompt import ToolPermissionPrompt |
7 | 13 | from agent_chat_cli.utils.enums import ControlCommand |
8 | 14 |
|
@@ -30,6 +36,90 @@ def mock_config(): |
30 | 36 | yield mock |
31 | 37 |
|
32 | 38 |
|
| 39 | +class TestActionsAddMessageToChat: |
| 40 | + async def test_adds_user_message(self, mock_agent_loop, mock_config): |
| 41 | + app = AgentChatCLIApp() |
| 42 | + async with app.run_test(): |
| 43 | + chat_history = app.query_one(ChatHistory) |
| 44 | + |
| 45 | + await app.actions.add_message_to_chat(MessageType.USER, "Hello") |
| 46 | + |
| 47 | + widgets = chat_history.query(UserMessage) |
| 48 | + assert len(widgets) == 1 |
| 49 | + assert widgets.first().message == "Hello" |
| 50 | + |
| 51 | + async def test_adds_system_message(self, mock_agent_loop, mock_config): |
| 52 | + app = AgentChatCLIApp() |
| 53 | + async with app.run_test(): |
| 54 | + chat_history = app.query_one(ChatHistory) |
| 55 | + |
| 56 | + await app.actions.add_message_to_chat(MessageType.SYSTEM, "System alert") |
| 57 | + |
| 58 | + widgets = chat_history.query(SystemMessage) |
| 59 | + assert len(widgets) == 1 |
| 60 | + assert widgets.first().message == "System alert" |
| 61 | + |
| 62 | + async def test_adds_agent_message(self, mock_agent_loop, mock_config): |
| 63 | + app = AgentChatCLIApp() |
| 64 | + async with app.run_test(): |
| 65 | + chat_history = app.query_one(ChatHistory) |
| 66 | + |
| 67 | + await app.actions.add_message_to_chat(MessageType.AGENT, "I can help") |
| 68 | + |
| 69 | + widgets = chat_history.query(AgentMessage) |
| 70 | + assert len(widgets) == 1 |
| 71 | + assert widgets.first().message == "I can help" |
| 72 | + |
| 73 | + async def test_raises_for_unsupported_type(self, mock_agent_loop, mock_config): |
| 74 | + app = AgentChatCLIApp() |
| 75 | + async with app.run_test(): |
| 76 | + with pytest.raises(ValueError, match="Unsupported message type"): |
| 77 | + await app.actions.add_message_to_chat(MessageType.TOOL, "tool content") |
| 78 | + |
| 79 | + |
| 80 | +class TestActionsPostSystemMessage: |
| 81 | + async def test_adds_system_message_to_chat(self, mock_agent_loop, mock_config): |
| 82 | + app = AgentChatCLIApp() |
| 83 | + async with app.run_test(): |
| 84 | + chat_history = app.query_one(ChatHistory) |
| 85 | + |
| 86 | + await app.actions.post_system_message("Connection established") |
| 87 | + |
| 88 | + widgets = chat_history.query(SystemMessage) |
| 89 | + assert len(widgets) == 1 |
| 90 | + assert widgets.first().message == "Connection established" |
| 91 | + |
| 92 | + |
| 93 | +class TestActionsSubmitUserMessage: |
| 94 | + async def test_adds_user_message_to_chat(self, mock_agent_loop, mock_config): |
| 95 | + app = AgentChatCLIApp() |
| 96 | + async with app.run_test(): |
| 97 | + chat_history = app.query_one(ChatHistory) |
| 98 | + |
| 99 | + await app.actions.submit_user_message("Hello agent") |
| 100 | + |
| 101 | + widgets = chat_history.query(UserMessage) |
| 102 | + assert len(widgets) == 1 |
| 103 | + assert widgets.first().message == "Hello agent" |
| 104 | + |
| 105 | + async def test_starts_thinking_indicator(self, mock_agent_loop, mock_config): |
| 106 | + from agent_chat_cli.components.thinking_indicator import ThinkingIndicator |
| 107 | + |
| 108 | + app = AgentChatCLIApp() |
| 109 | + async with app.run_test(): |
| 110 | + await app.actions.submit_user_message("Hello agent") |
| 111 | + |
| 112 | + thinking_indicator = app.query_one(ThinkingIndicator) |
| 113 | + assert thinking_indicator.is_thinking is True |
| 114 | + |
| 115 | + async def test_queues_message_to_agent_loop(self, mock_agent_loop, mock_config): |
| 116 | + app = AgentChatCLIApp() |
| 117 | + async with app.run_test(): |
| 118 | + await app.actions.submit_user_message("Hello agent") |
| 119 | + |
| 120 | + mock_agent_loop.query_queue.put.assert_called_with("Hello agent") |
| 121 | + |
| 122 | + |
33 | 123 | class TestActionsInterrupt: |
34 | 124 | async def test_sets_interrupting_flag(self, mock_agent_loop, mock_config): |
35 | 125 | app = AgentChatCLIApp() |
|
0 commit comments