code-agent: implement issue 6

Approval-Correlation: e5da4592756fb704256d8737d31662e5
Plan-SHA256: 0fbe8b996656fb908c513b31e30706f7521cf76eeac60778a1c28f46bfc19b46
Bundle-SHA256: 29ce1ef1917864f79938459725201e6e74d67e21b1f817ac53d7b294eca8f1a2
Base-SHA: cabd354d71
This commit is contained in:
code-agent
2000-01-01 00:00:00 +00:00
parent cabd354d71
commit 14302a26f9
6 changed files with 526 additions and 117 deletions
+50 -6
View File
@@ -3,7 +3,12 @@ from unittest.mock import patch
from textual.widgets import Input, Label
from chat_tui.app import RESPONSE_MESSAGES, ChatApp
from chat_tui.app import (
RESPONSE_MESSAGES,
ChatApp,
ChatMessage,
MessageRole,
)
class ChatAppTest(unittest.IsolatedAsyncioTestCase):
@@ -28,21 +33,58 @@ class ChatAppTest(unittest.IsolatedAsyncioTestCase):
app.selected_responses,
[RESPONSE_MESSAGES[2], RESPONSE_MESSAGES[2]],
)
self.assertEqual(
app.messages,
[
ChatMessage(MessageRole.USER, "첫 번째 입력"),
ChatMessage(MessageRole.AGENT, RESPONSE_MESSAGES[2]),
ChatMessage(MessageRole.USER, "두 번째 입력"),
ChatMessage(MessageRole.AGENT, RESPONSE_MESSAGES[2]),
],
)
displayed = [
label.renderable
str(label.renderable)
for label in app.query("#conversation Label")
]
self.assertEqual(
displayed,
[
"첫 번째 입력",
RESPONSE_MESSAGES[2],
"두 번째 입력",
RESPONSE_MESSAGES[2],
"사용자: 첫 번째 입력",
f"에이전트: {RESPONSE_MESSAGES[2]}",
"사용자: 두 번째 입력",
f"에이전트: {RESPONSE_MESSAGES[2]}",
],
)
self.assertEqual(input_widget.value, "")
async def test_messages_have_explicit_roles_labels_and_structural_styles(
self,
) -> None:
app = ChatApp()
with patch("chat_tui.app.random.choice", return_value=RESPONSE_MESSAGES[0]):
async with app.run_test() as pilot:
input_widget = app.query_one("#user-input", Input)
input_widget.value = "역할 확인"
await pilot.press("enter")
await pilot.pause()
labels = list(app.query("#conversation Label"))
self.assertEqual(len(labels), 2)
self.assertEqual(
labels[0].classes,
frozenset({"chat-message", "user-message", "user-role"}),
)
self.assertEqual(
labels[1].classes,
frozenset({"chat-message", "response-message", "agent-role"}),
)
self.assertIn("사용자:", str(labels[0].renderable))
self.assertIn("에이전트:", str(labels[1].renderable))
self.assertIn("border-left", app.CSS)
self.assertIn("border-right", app.CSS)
self.assertIn("align: left middle", app.CSS)
self.assertIn("align: right middle", app.CSS)
async def test_response_selection_uses_standard_random_choice(self) -> None:
app = ChatApp()
with patch(
@@ -68,6 +110,7 @@ class ChatAppTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(app.submitted_inputs, [])
self.assertEqual(app.selected_responses, [])
self.assertEqual(app.messages, [])
self.assertEqual(len(app.query("#conversation Label")), 0)
choice_mock.assert_not_called()
@@ -79,6 +122,7 @@ class ChatAppTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(app.submitted_inputs, [])
self.assertEqual(app.selected_responses, [])
self.assertEqual(app.messages, [])
self.assertEqual(len(app.query("#conversation Label")), 0)
async def test_escape_requests_application_exit(self) -> None: