diff --git a/pyrightconfig.json b/pyrightconfig.json index b4be9b72..706fb332 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,5 +1,9 @@ { - "extraPaths": ["src", "src/aipass/memory/.venv/lib/python3.12/site-packages"], + "extraPaths": [ + "src", + ".venv/lib/python3.12/site-packages", + "src/aipass/memory/.venv/lib/python3.12/site-packages" + ], "pythonVersion": "3.10", "reportMissingImports": "error", "reportAttributeAccessIssue": "error", diff --git a/src/aipass/skills/.aipass/skills/telegram/tests/conftest.py b/src/aipass/skills/.aipass/skills/telegram/tests/conftest.py index de4161ba..7da8e307 100644 --- a/src/aipass/skills/.aipass/skills/telegram/tests/conftest.py +++ b/src/aipass/skills/.aipass/skills/telegram/tests/conftest.py @@ -18,6 +18,7 @@ import os import shutil import sys import tempfile +import types from pathlib import Path from typing import Generator @@ -37,6 +38,38 @@ if str(_skill_root) not in sys.path: sys.path.insert(0, str(_skill_root)) +# Telethon stub — telethon is an OPTIONAL runtime dependency (MTProto client), +# deliberately NOT in pyproject so the core stays lightweight (botfather_client.py +# guards it with TELETHON_AVAILABLE). The botfather_client tests mock all Telethon +# classes (patch("telethon.TelegramClient"), etc.), but unittest.mock.patch must +# IMPORT the target's parent module to set the attribute — which raises +# ModuleNotFoundError when telethon isn't installed (e.g. in CI). Register a minimal +# stub so those patch targets resolve. The guard never clobbers a real telethon if +# one is installed. Real FloodWaitError/RPCError classes are required for the +# success/timeout tests, where _send_and_wait imports them but does not patch them. +if "telethon" not in sys.modules: + _telethon_stub = types.ModuleType("telethon") + _telethon_errors = types.ModuleType("telethon.errors") + + class StubFloodWaitError(Exception): + def __init__(self, *args: object, seconds: int = 0, **kwargs: object) -> None: + self.seconds = seconds + super().__init__(*args) + + class StubRPCError(Exception): + pass + + # ModuleType attributes are dynamic — assign via setattr so the type checker + # does not flag assignment to "unknown" module attributes. + setattr(_telethon_stub, "TelegramClient", type("TelegramClient", (), {})) # patched per-test + setattr(_telethon_errors, "FloodWaitError", StubFloodWaitError) + setattr(_telethon_errors, "RPCError", StubRPCError) + setattr(_telethon_stub, "errors", _telethon_errors) + + sys.modules["telethon"] = _telethon_stub + sys.modules["telethon.errors"] = _telethon_errors + + @pytest.fixture(autouse=True, scope="session") def _redirect_prax_logs(tmp_path_factory): """Redirect Prax logger output to temp dir during tests.