First Commit

This commit is contained in:
marco
2026-09-03 15:34:28 -03:00
commit f97819e551
3005 changed files with 487818 additions and 0 deletions
+136
View File
@@ -0,0 +1,136 @@
import asyncio
import sys
import os
sys.path.insert(0, "/home/marco/MonicaAgentIA/app")
os.environ["TELEGRAM_BOT_TOKEN"] = "test"
os.environ["TELEGRAM_CHAT_ID"] = "123"
from monica_agent import (
cancelar_command,
message_handler,
is_onboarding,
is_config_agent_profile,
is_shutting_down,
proactive_task,
app_instance,
)
class FakeMessage:
def __init__(self, text):
self.text = text
self.chat_id = 7889499475
async def reply_text(self, text, **kwargs):
print(f"BOT RESPONSE: {text[:300]}")
class FakeUpdate:
def __init__(self, text):
self.message = FakeMessage(text)
self.effective_chat = self
self.effective_user = self
self.effective_message = self.message
@property
def id(self):
return self.message.chat_id
@property
def username(self):
return "test_user"
@property
def first_name(self):
return "Marco"
class FakeContext:
def __init__(self):
self.bot = self
async def send_message(self, **kwargs):
print(f"BOT SEND: {kwargs.get('text', '')[:300]}")
async def test_cancelar_command():
print("=== Testando /cancelar ===")
# Simulate being in onboarding state
import monica_agent
monica_agent.is_onboarding = True
monica_agent.onboarding_step = 3
monica_agent.onboarding_answers = {"name": "Test"}
monica_agent.is_config_agent_profile = True
monica_agent.config_agent_step = 2
monica_agent.config_agent_field = "monica_visual_preferences"
update = FakeUpdate("/cancelar")
context = FakeContext()
try:
await cancelar_command(update, context)
print("✅ cancelar_command executou sem erros")
except Exception as e:
print(f"❌ Erro: {e}")
import traceback
traceback.print_exc()
return
# Verify state was reset
print(f" is_onboarding={monica_agent.is_onboarding}")
print(f" onboarding_step={monica_agent.onboarding_step}")
print(f" onboarding_answers={monica_agent.onboarding_answers}")
print(f" is_config_agent_profile={monica_agent.is_config_agent_profile}")
print(f" config_agent_step={monica_agent.config_agent_step}")
print(f" config_agent_field={monica_agent.config_agent_field}")
print(f" is_shutting_down={monica_agent.is_shutting_down}")
assert monica_agent.is_onboarding == False
assert monica_agent.onboarding_step == 0
assert monica_agent.onboarding_answers == {}
assert monica_agent.is_config_agent_profile == False
assert monica_agent.config_agent_step == 0
assert monica_agent.config_agent_field == ""
assert monica_agent.is_shutting_down == True
print("✅ Estado resetado corretamente")
# Verify that after cancelar, normal messages are handled
print("\n=== Verificando que mensagens normais funcionam após /cancelar ===")
update = FakeUpdate("Olá Mônica!")
context = FakeContext()
try:
await message_handler(update, context)
print("✅ message_handler funciona após /cancelar")
except Exception as e:
print(f"❌ message_handler falhou após /cancelar: {e}")
async def test_help_contains_cancelar():
print("\n=== Verificando /help contém /cancelar ===")
from monica_agent import help_command
update = FakeUpdate("/help")
context = FakeContext()
responses = []
original_reply = FakeMessage.reply_text
async def capture_reply(self, text, **kwargs):
responses.append(text)
print(f"BOT RESPONSE: {text[:300]}")
FakeMessage.reply_text = capture_reply
try:
await help_command(update, context)
help_text = responses[0] if responses else ""
if "/cancelar" in help_text:
print("✅ /help menciona /cancelar")
else:
print("❌ /help não menciona /cancelar")
finally:
FakeMessage.reply_text = original_reply
async def main():
await test_cancelar_command()
await test_help_contains_cancelar()
print("\n=== Todos os testes concluídos ===")
if __name__ == "__main__":
asyncio.run(main())