135 lines
4.2 KiB
Python
Executable File
135 lines
4.2 KiB
Python
Executable File
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 (
|
|
limpar_command,
|
|
load_user_profile,
|
|
load_all_contexts,
|
|
ensure_contexts_dir,
|
|
save_user_profile,
|
|
)
|
|
|
|
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_limpar_command():
|
|
print("=== Testando /limpar ===")
|
|
|
|
profile = load_user_profile()
|
|
profile["name"] = "Teste"
|
|
profile["age"] = "30"
|
|
profile["monica_visual_preferences"] = ["item1", "item2"]
|
|
profile["monica_sexual_preferences"] = ["item3"]
|
|
profile["relationship_dynamics"] = ["item4"]
|
|
save_user_profile(profile)
|
|
|
|
ensure_contexts_dir()
|
|
from pathlib import Path
|
|
from monica_agent import CONTEXTS_DIR
|
|
test_context_file = Path(CONTEXTS_DIR) / "2026-08-22.json"
|
|
test_context_file.write_text('[{"role": "user", "content": "teste", "timestamp": "2026-08-22T12:00:00"}]', encoding="utf-8")
|
|
|
|
print(f"Antes do /limpar:")
|
|
print(f" Nome no perfil: {load_user_profile().get('name')}")
|
|
print(f" Contextos: {len(load_all_contexts())} mensagens")
|
|
print(f" Arquivos de contexto: {len(list(Path(CONTEXTS_DIR).glob('*.json')))}")
|
|
|
|
update = FakeUpdate("/limpar")
|
|
context = FakeContext()
|
|
|
|
try:
|
|
await limpar_command(update, context)
|
|
print("✅ limpar_command executou sem erros")
|
|
except Exception as e:
|
|
print(f"❌ Erro: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return
|
|
|
|
profile = load_user_profile()
|
|
contexts = load_all_contexts()
|
|
context_files = list(Path(CONTEXTS_DIR).glob("*.json"))
|
|
|
|
print(f"\nDepois do /limpar:")
|
|
print(f" Nome no perfil: '{profile.get('name')}'")
|
|
print(f" Idade: '{profile.get('age')}'")
|
|
print(f" Visual prefs: {profile.get('monica_visual_preferences', [])}")
|
|
print(f" Contextos: {len(contexts)} mensagens")
|
|
print(f" Arquivos de contexto: {len(context_files)}")
|
|
|
|
assert profile.get("name") == "", f"Nome deveria estar vazio, está: {profile.get('name')}"
|
|
assert profile.get("age") == "", f"Idade deveria estar vazia, está: {profile.get('age')}"
|
|
assert profile.get("monica_visual_preferences") == [], f"Visual prefs deveria estar vazia"
|
|
assert len(contexts) == 0, f"Contextos deveriam estar vazios, tem: {len(contexts)}"
|
|
assert len(context_files) == 0, f"Arquivos de contexto deveriam estar vazios, tem: {len(context_files)}"
|
|
|
|
print("✅ Todos os dados foram limpos corretamente")
|
|
|
|
async def test_help_contains_limpar():
|
|
print("\n=== Verificando /help contém /limpar ===")
|
|
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 "/limpar" in help_text:
|
|
print("✅ /help menciona /limpar")
|
|
else:
|
|
print("❌ /help não menciona /limpar")
|
|
finally:
|
|
FakeMessage.reply_text = original_reply
|
|
|
|
async def main():
|
|
await test_limpar_command()
|
|
await test_help_contains_limpar()
|
|
print("\n=== Todos os testes concluídos ===")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|