forked from Rockachopa/Timmy-time-dashboard
refactor: Phase 2b — consolidate 28 modules into 14 packages
Complete the module consolidation planned in REFACTORING_PLAN.md: Modules merged: - work_orders/ + task_queue/ → swarm/ (subpackages) - self_modify/ + self_tdd/ + upgrades/ → self_coding/ (subpackages) - tools/ → creative/tools/ - chat_bridge/ + telegram_bot/ + shortcuts/ + voice/ → integrations/ (new) - ws_manager/ + notifications/ + events/ + router/ → infrastructure/ (new) - agents/ + agent_core/ + memory/ → timmy/ (subpackages) Updated across codebase: - 66 source files: import statements rewritten - 13 test files: import + patch() target strings rewritten - pyproject.toml: wheel includes (28→14), entry points updated - CLAUDE.md: singleton paths, module map, entry points table - AGENTS.md: file convention updates - REFACTORING_PLAN.md: execution status, success metrics Extras: - Module-level CLAUDE.md added to 6 key packages (Phase 6.2) - Zero test regressions: 1462 tests passing https://claude.ai/code/session_01JNjWfHqusjT3aiN4vvYgUk
This commit is contained in:
@@ -14,9 +14,9 @@ class TestTelegramBotTokenHelpers:
|
||||
def test_save_and_load_token(self, tmp_path, monkeypatch):
|
||||
"""save_token persists to disk; load_token reads it back."""
|
||||
state_file = tmp_path / "telegram_state.json"
|
||||
monkeypatch.setattr("telegram_bot.bot._STATE_FILE", state_file)
|
||||
monkeypatch.setattr("integrations.telegram_bot.bot._STATE_FILE", state_file)
|
||||
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
|
||||
bot.save_token("test-token-123")
|
||||
@@ -30,28 +30,28 @@ class TestTelegramBotTokenHelpers:
|
||||
def test_load_token_missing_file(self, tmp_path, monkeypatch):
|
||||
"""load_token returns None when no state file and no env var."""
|
||||
state_file = tmp_path / "missing_telegram_state.json"
|
||||
monkeypatch.setattr("telegram_bot.bot._STATE_FILE", state_file)
|
||||
monkeypatch.setattr("integrations.telegram_bot.bot._STATE_FILE", state_file)
|
||||
|
||||
# Ensure settings.telegram_token is empty
|
||||
mock_settings = MagicMock()
|
||||
mock_settings.telegram_token = ""
|
||||
with patch("telegram_bot.bot._load_token_from_file", return_value=None):
|
||||
with patch("integrations.telegram_bot.bot._load_token_from_file", return_value=None):
|
||||
with patch("config.settings", mock_settings):
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
result = bot.load_token()
|
||||
assert result is None
|
||||
|
||||
def test_token_set_property(self):
|
||||
"""token_set reflects whether a token has been applied."""
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
assert not bot.token_set
|
||||
bot._token = "tok"
|
||||
assert bot.token_set
|
||||
|
||||
def test_is_running_property(self):
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
assert not bot.is_running
|
||||
bot._running = True
|
||||
@@ -63,9 +63,9 @@ class TestTelegramBotLifecycle:
|
||||
async def test_start_no_token_returns_false(self, tmp_path, monkeypatch):
|
||||
"""start() returns False and stays idle when no token is available."""
|
||||
state_file = tmp_path / "telegram_state.json"
|
||||
monkeypatch.setattr("telegram_bot.bot._STATE_FILE", state_file)
|
||||
monkeypatch.setattr("integrations.telegram_bot.bot._STATE_FILE", state_file)
|
||||
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
with patch.object(bot, "load_token", return_value=None):
|
||||
result = await bot.start()
|
||||
@@ -74,7 +74,7 @@ class TestTelegramBotLifecycle:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_already_running_returns_true(self):
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
bot._running = True
|
||||
result = await bot.start(token="any")
|
||||
@@ -83,7 +83,7 @@ class TestTelegramBotLifecycle:
|
||||
@pytest.mark.asyncio
|
||||
async def test_start_import_error_returns_false(self):
|
||||
"""start() returns False gracefully when python-telegram-bot absent."""
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
|
||||
with patch.object(bot, "load_token", return_value="tok"), \
|
||||
@@ -94,7 +94,7 @@ class TestTelegramBotLifecycle:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_when_not_running_is_noop(self):
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
# Should not raise
|
||||
await bot.stop()
|
||||
@@ -102,7 +102,7 @@ class TestTelegramBotLifecycle:
|
||||
@pytest.mark.asyncio
|
||||
async def test_stop_calls_shutdown(self):
|
||||
"""stop() invokes the Application shutdown sequence."""
|
||||
from telegram_bot.bot import TelegramBot
|
||||
from integrations.telegram_bot.bot import TelegramBot
|
||||
bot = TelegramBot()
|
||||
bot._running = True
|
||||
|
||||
@@ -125,7 +125,7 @@ class TestTelegramBotLifecycle:
|
||||
class TestTelegramRoutes:
|
||||
def test_status_not_running(self, client):
|
||||
"""GET /telegram/status returns running=False when bot is idle."""
|
||||
from telegram_bot.bot import telegram_bot
|
||||
from integrations.telegram_bot.bot import telegram_bot
|
||||
telegram_bot._running = False
|
||||
telegram_bot._token = None
|
||||
|
||||
@@ -137,7 +137,7 @@ class TestTelegramRoutes:
|
||||
|
||||
def test_status_running(self, client):
|
||||
"""GET /telegram/status returns running=True when bot is active."""
|
||||
from telegram_bot.bot import telegram_bot
|
||||
from integrations.telegram_bot.bot import telegram_bot
|
||||
telegram_bot._running = True
|
||||
telegram_bot._token = "tok"
|
||||
|
||||
@@ -161,7 +161,7 @@ class TestTelegramRoutes:
|
||||
|
||||
def test_setup_success(self, client):
|
||||
"""POST /telegram/setup with valid token starts bot and returns ok."""
|
||||
from telegram_bot.bot import telegram_bot
|
||||
from integrations.telegram_bot.bot import telegram_bot
|
||||
|
||||
telegram_bot._running = False
|
||||
with patch.object(telegram_bot, "save_token") as mock_save, \
|
||||
@@ -175,7 +175,7 @@ class TestTelegramRoutes:
|
||||
|
||||
def test_setup_failure(self, client):
|
||||
"""POST /telegram/setup returns error dict when bot fails to start."""
|
||||
from telegram_bot.bot import telegram_bot
|
||||
from integrations.telegram_bot.bot import telegram_bot
|
||||
|
||||
telegram_bot._running = False
|
||||
with patch.object(telegram_bot, "save_token"), \
|
||||
@@ -189,7 +189,7 @@ class TestTelegramRoutes:
|
||||
|
||||
def test_setup_stops_running_bot_first(self, client):
|
||||
"""POST /telegram/setup stops any running bot before starting new one."""
|
||||
from telegram_bot.bot import telegram_bot
|
||||
from integrations.telegram_bot.bot import telegram_bot
|
||||
telegram_bot._running = True
|
||||
|
||||
with patch.object(telegram_bot, "save_token"), \
|
||||
@@ -207,5 +207,5 @@ class TestTelegramRoutes:
|
||||
|
||||
def test_module_singleton_exists():
|
||||
"""telegram_bot module exposes a singleton TelegramBot instance."""
|
||||
from telegram_bot.bot import telegram_bot, TelegramBot
|
||||
from integrations.telegram_bot.bot import telegram_bot, TelegramBot
|
||||
assert isinstance(telegram_bot, TelegramBot)
|
||||
|
||||
Reference in New Issue
Block a user