Command exited with code 1. Command output: ============================= test session starts ============================== platform linux -- Python 3.12.3, pytest-9.2.0, pluggy-1.7.0 -- /root/telegram-saas/.venv/bin/python3 cachedir: .pytest_cache rootdir: /root/telegram-saas configfile: pyproject.toml plugins: anyio-4.16.0, asyncio-1.5.0 asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function collecting ... collected 15 items tests/unit/test_bot_modular_engine.py::test_module_catalog_definitions PASSED [ 6%] tests/unit/test_bot_modular_engine.py::test_bot_module_lifecycle PASSED [ 13%] tests/unit/test_bot_modular_engine.py::test_force_join_gating_behavior PASSED [ 20%] tests/unit/test_bot_modular_engine.py::test_referrals_and_growth_attribution PASSED [ 26%] tests/unit/test_bot_modular_engine.py::test_auto_filter_keyword_and_blocked_words PASSED [ 33%] tests/unit/test_bot_modular_engine.py::test_redeem_code_lifecycle_and_redemption PASSED [ 40%] tests/unit/test_bot_modular_engine.py::test_three_way_triggers_and_menu_generation PASSED [ 46%] tests/unit/test_bot_modular_engine.py::test_captcha_and_daily_rewards_lifecycle PASSED [ 53%] tests/unit/test_bot_modular_engine.py::test_file_store_and_support_tickets_lifecycle PASSED [ 60%] tests/integration/test_bot_modular_api_and_execution.py::test_bot_modular_api_and_execution_lifecycle FAILED [ 66%] tests/unit/test_mcp_protocol.py::test_platform_mcp_tools_registry_integrity PASSED [ 73%] tests/unit/test_mcp_protocol.py::test_mcp_server_initialize_handshake PASSED [ 80%] tests/unit/test_mcp_protocol.py::test_mcp_server_ping_and_invalid_methods PASSED [ 86%] tests/integration/test_mcp_api.py::test_mcp_pro_full_lifecycle_and_tenant_isolation PASSED [ 93%] tests/integration/test_admin_platform_api.py::test_admin_platform_endpoints_and_superuser_guard PASSED [100%] =================================== FAILURES =================================== _________________ test_bot_modular_api_and_execution_lifecycle _________________ async_client = db_session = @pytest.mark.asyncio async def test_bot_modular_api_and_execution_lifecycle( async_client: AsyncClient, db_session: AsyncSession, ): # -------------------------------------------------------------------------- # 1. Setup Tenant, User, and Bot # -------------------------------------------------------------------------- user_email = f"mod_dev_{uuid.uuid4().hex[:6]}@example.com" reg_resp = await async_client.post( "/api/v1/auth/register", json={"email": user_email, "password": "PasswordM123!", "full_name": "Modular Dev"}, ) user_token = reg_resp.json()["data"]["access_token"] tenant_resp = await async_client.post( "/api/v1/tenants", headers={"Authorization": f"Bearer {user_token}"}, json={"name": "Modular Fleet Org", "slug": f"mod-{uuid.uuid4().hex[:6]}"}, ) tenant_id = uuid.UUID(tenant_resp.json()["data"]["id"]) headers = { "Authorization": f"Bearer {user_token}", "X-Tenant-ID": str(tenant_id), } # Register Bot bot_token = f"token_modular_{uuid.uuid4().hex[:8]}_test" bot_username = f"modular_bot_{uuid.uuid4().hex[:6]}" TelegramApiService.register_mock_bot(bot_token, bot_username, "Modular Bot") bot_reg_resp = await async_client.post( "/api/v1/bots", headers=headers, json={"token": bot_token, "name": "Nexus Modular Bot", "default_locale": "en"}, ) assert bot_reg_resp.status_code == 201 bot_data = bot_reg_resp.json()["data"] bot_id = uuid.UUID(bot_data["id"]) # -------------------------------------------------------------------------- # 2. Query Bot Modules API: GET /api/v1/bots/{bot_id}/modules # -------------------------------------------------------------------------- modules_resp = await async_client.get(f"/api/v1/bots/{bot_id}/modules", headers=headers) assert modules_resp.status_code == 200 mods = modules_resp.json()["data"] assert len(mods) == 18 assert "redeem_codes" in [m["id"] for m in mods] assert "captcha_gate" in [m["id"] for m in mods] assert "daily_rewards" in [m["id"] for m in mods] assert "file_store" in [m["id"] for m in mods] mod_map = {m["id"]: m for m in mods} # Auto-provisioned foundational modules should be active assert mod_map["welcome_message"]["is_enabled"] is True assert mod_map["broadcasts"]["is_enabled"] is True # Others installed on-demand assert mod_map["referrals"]["is_enabled"] is False # -------------------------------------------------------------------------- # 3. Install & Toggle Modules via API # -------------------------------------------------------------------------- # Activate Referrals toggle_ref = await async_client.post( f"/api/v1/bots/{bot_id}/modules/referrals/toggle", headers=headers, json={"is_enabled": True}, ) assert toggle_ref.status_code == 200 assert toggle_ref.json()["data"]["is_enabled"] is True # Activate Subscriptions toggle_sub = await async_client.post( f"/api/v1/bots/{bot_id}/modules/subscriptions/toggle", headers=headers, json={"is_enabled": True}, ) assert toggle_sub.status_code == 200 assert toggle_sub.json()["data"]["is_enabled"] is True # Update Auto Filter Config & Toggle cfg_resp = await async_client.patch( f"/api/v1/bots/{bot_id}/modules/auto_filter/config", headers=headers, json={ "config": { "rules": [{"trigger": "catalog", "match_type": "contains", "response": "📦 120 Products Available in Store."}], "blocked_words": ["malware"], "action_on_blocked": "warn", } }, ) assert cfg_resp.status_code == 200 await async_client.post( f"/api/v1/bots/{bot_id}/modules/auto_filter/toggle", headers=headers, json={"is_enabled": True}, ) # -------------------------------------------------------------------------- # 4. Verify Real Webhook Execution Against Modules # -------------------------------------------------------------------------- TelegramApiService.clear_sent_messages() # Query bot secret token to sign webhook requests bot_obj = await db_session.get(Bot, bot_id) webhook_obj = bot_obj.webhook # Use mock matching token secret_token = "valid_secret_for_webhook" webhook_obj.secret_hash = hash_webhook_secret(secret_token) await db_session.commit() webhook_headers = {"X-Telegram-Bot-Api-Secret-Token": secret_token} # 4.1 Test /referral command with Referrals active resp_ref = await async_client.post( f"/webhooks/telegram/{bot_id}", headers=webhook_headers, json={ "update_id": 10001, "message": { "from": {"id": 555111, "username": "testuser1"}, "chat": {"id": 555111}, "text": "/referral", }, }, ) assert resp_ref.status_code == 200 sent = TelegramApiService.get_sent_messages() > assert len(sent) >= 1 E assert 0 >= 1 E + where 0 = len([]) tests/integration/test_bot_modular_api_and_execution.py:142: AssertionError ----------------------------- Captured stdout call ----------------------------- 2026-11-19 08:30:29 [info ] dispatching_domain_event event_id=c9dc286b-5d14-4244-bf03-e479f0212846 event_type=TenantCreatedEvent handlers_count=1 2026-11-19 08:30:29 [info ] domain_event_recorded event_id=c9dc286b-5d14-4244-bf03-e479f0212846 event_type=TenantCreatedEvent tenant_id=6a1741d3-cbc6-4d06-9e55-d0b686dfaf74 user_id=None 2026-11-19 08:30:29 [info ] dispatching_domain_event event_id=1ec08311-a905-4374-8156-3c5c1b08b061 event_type=UserRegisteredEvent handlers_count=1 2026-11-19 08:30:29 [info ] domain_event_recorded event_id=1ec08311-a905-4374-8156-3c5c1b08b061 event_type=UserRegisteredEvent tenant_id=None user_id=f318acfa-dba3-4f4d-8b8d-3b8dd4a087a8 2026-11-19 08:30:29 [info ] dispatching_domain_event event_id=6f319dd1-9b74-4579-b059-5e9291b04f8a event_type=TenantCreatedEvent handlers_count=1 2026-11-19 08:30:29 [info ] domain_event_recorded event_id=6f319dd1-9b74-4579-b059-5e9291b04f8a event_type=TenantCreatedEvent tenant_id=33b112f8-58a6-4f25-a208-128cb5723dba user_id=None 2026-11-19 08:30:29 [info ] bot_registered_successfully bot_id=a4badfe3-7aa6-4b99-b9e2-f23f065f6ad4 tenant_id=33b112f8-58a6-4f25-a208-128cb5723dba username=modular_bot_c6271a =========================== short test summary info ============================ FAILED tests/integration/test_bot_modular_api_and_execution.py::test_bot_modular_api_and_execution_lifecycle ========================= 1 failed, 14 passed in 4.48s =========================