add a history command

This commit is contained in:
2026-05-24 00:20:42 -04:00
parent 4eea8583de
commit 833927c66e
4 changed files with 244 additions and 4 deletions
+99
View File
@@ -536,3 +536,102 @@ def test_talkforme_invalid_limit(
asyncio.run(main_module.talkforme(mock_ctx, message="bot1 bot2 abc topic"))
call_args = mock_ctx.send.call_args[0][0]
assert "must be an integer" in call_args
def test_history_bot_not_found(
mock_ctx: MagicMock,
mock_custom_bot_manager: MagicMock,
) -> None:
"""Test history command when bot doesn't exist."""
import asyncio
import vibe_bot.main as main_module
mock_custom_bot_manager.get_custom_bot.return_value = None
asyncio.run(main_module.history(mock_ctx, bot_name="nonexistent"))
call_args = mock_ctx.send.call_args[0][0]
assert "not found" in call_args
def test_history_no_history(
mock_ctx: MagicMock,
mock_custom_bot_manager: MagicMock,
mock_database: MagicMock,
) -> None:
"""Test history command when bot has no chat history."""
import asyncio
import vibe_bot.main as main_module
mock_custom_bot_manager.get_custom_bot.return_value = (
"alfred",
"british butler",
"user-123",
"2024-01-01",
)
mock_database.get_bot_history.return_value = []
asyncio.run(main_module.history(mock_ctx, bot_name="alfred"))
call_args = mock_ctx.send.call_args[0][0]
assert "No chat history" in call_args
assert "**alfred**" in call_args
def test_history_with_data(
mock_ctx: MagicMock,
mock_custom_bot_manager: MagicMock,
mock_database: MagicMock,
) -> None:
"""Test history command when bot has chat history."""
import asyncio
import vibe_bot.main as main_module
mock_custom_bot_manager.get_custom_bot.return_value = (
"alfred",
"british butler",
"user-123",
"2024-01-01",
)
mock_database.get_bot_history.return_value = [
("hello", "yes master?"),
("what time is it", "it is currently 3pm"),
]
asyncio.run(main_module.history(mock_ctx, bot_name="alfred"))
assert mock_ctx.send.call_count >= 1
first_call = mock_ctx.send.call_args_list[0][0][0]
assert "Chat History for **alfred**" in first_call
assert "hello" in first_call
assert "alfred: yes master?" in first_call
assert "what time is it" in first_call
assert "alfred: it is currently 3pm" in first_call
def test_history_long_response_chunked(
mock_ctx: MagicMock,
mock_custom_bot_manager: MagicMock,
mock_database: MagicMock,
) -> None:
"""Test that long history responses are sent in chunks."""
import asyncio
import vibe_bot.main as main_module
mock_custom_bot_manager.get_custom_bot.return_value = (
"alfred",
"british butler",
"user-123",
"2024-01-01",
)
long_user = "x" * 500
long_bot = "y" * 500
mock_database.get_bot_history.return_value = [
(long_user, long_bot),
]
asyncio.run(main_module.history(mock_ctx, bot_name="alfred"))
assert mock_ctx.send.call_count >= 1