so add the ghost mode for bot
This commit is contained in:
6 files changed
+69
-10
No files matched your search
@@ -89,7 +89,7 @@ async def test_send_guest_reply_truncates_oversized_text():
|
||||
async def test_guest_message_handling_general_query(tmp_path):
|
||||
settings = Settings(
|
||||
GHOST_MODE_ENABLED=True,
|
||||
ALLOWED_TELEGRAM_USER_IDS=[111], # Whitelist with only 111
|
||||
ALLOWED_TELEGRAM_USER_IDS=[111], # Authorized user 111
|
||||
)
|
||||
agent = MagicMock()
|
||||
agent.chat = AsyncMock(return_value="Answer from Ghost Agent!")
|
||||
@@ -105,8 +105,8 @@ async def test_guest_message_handling_general_query(tmp_path):
|
||||
bot.answer_guest_query = AsyncMock()
|
||||
bot.send_chat_action = AsyncMock()
|
||||
|
||||
# User 999 is NOT in whitelist! Should still be allowed in ghost mode per user instructions.
|
||||
caller_user = User(id=999, is_bot=False, first_name="Stranger", username="stranger")
|
||||
# User 111 is in whitelist
|
||||
caller_user = User(id=111, is_bot=False, first_name="Owner", username="owner")
|
||||
chat = Chat(id=-100123456, type="supergroup", title="External Group")
|
||||
guest_msg = Message(
|
||||
message_id=1,
|
||||
@@ -136,9 +136,47 @@ async def test_guest_message_handling_general_query(tmp_path):
|
||||
assert result.input_message_content.rich_message.markdown == "Answer from Ghost Agent!"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_guest_message_blocks_unauthorized_user(tmp_path):
|
||||
settings = Settings(
|
||||
GHOST_MODE_ENABLED=True,
|
||||
ALLOWED_TELEGRAM_USER_IDS=[111], # Only 111 is allowed
|
||||
)
|
||||
agent = MagicMock()
|
||||
skill_manager = SkillManager(tmp_path / "skills")
|
||||
tool_registry = ToolRegistry()
|
||||
|
||||
router = create_bot_router(settings, agent, skill_manager, tool_registry)
|
||||
dp = Dispatcher()
|
||||
dp.include_router(router)
|
||||
|
||||
bot = MagicMock(spec=Bot)
|
||||
bot.answer_guest_query = AsyncMock()
|
||||
|
||||
# Unauthorized user 999
|
||||
unauthorized_user = User(id=999, is_bot=False, first_name="Stranger", username="stranger")
|
||||
chat = Chat(id=-100123456, type="supergroup", title="External Group")
|
||||
guest_msg = Message(
|
||||
message_id=2,
|
||||
date=datetime.now(),
|
||||
chat=chat,
|
||||
from_user=unauthorized_user,
|
||||
text="@homeagent_bot привет",
|
||||
guest_query_id="gq_unauthorized",
|
||||
guest_bot_caller_user=unauthorized_user,
|
||||
)
|
||||
guest_msg._bot = bot
|
||||
|
||||
upd = Update(update_id=101, guest_message=guest_msg)
|
||||
await dp.feed_update(bot, upd)
|
||||
|
||||
agent.chat.assert_not_called()
|
||||
bot.answer_guest_query.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_guest_message_handling_with_reply_to_message(tmp_path):
|
||||
settings = Settings(GHOST_MODE_ENABLED=True)
|
||||
settings = Settings(GHOST_MODE_ENABLED=True, ALLOWED_TELEGRAM_USER_IDS=[777])
|
||||
agent = MagicMock()
|
||||
agent.chat = AsyncMock(return_value="Analysis of the replied message")
|
||||
skill_manager = SkillManager(tmp_path / "skills")
|
||||
@@ -174,7 +212,7 @@ async def test_guest_message_handling_with_reply_to_message(tmp_path):
|
||||
)
|
||||
guest_msg._bot = bot
|
||||
|
||||
upd = Update(update_id=101, guest_message=guest_msg)
|
||||
upd = Update(update_id=102, guest_message=guest_msg)
|
||||
await dp.feed_update(bot, upd)
|
||||
|
||||
agent.chat.assert_awaited_once()
|
||||
@@ -189,7 +227,7 @@ async def test_guest_message_handling_with_reply_to_message(tmp_path):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_guest_message_commands(tmp_path):
|
||||
settings = Settings(GHOST_MODE_ENABLED=True)
|
||||
settings = Settings(GHOST_MODE_ENABLED=True, ALLOWED_TELEGRAM_USER_IDS=[1])
|
||||
agent = MagicMock()
|
||||
skill_manager = SkillManager(tmp_path / "skills")
|
||||
tool_registry = ToolRegistry()
|
||||
|
||||
Reference in new issue
Block a user