/rebase capturează + propune phash nou (screenshot adnotat cu red rect pe canary.roi, old/new hash, distance, TTL 180s). /rebase confirm rescrie baseline_phash în TOML-ul activ (regex line-match, păstrează comentariile), mirror în cfg live via object.__setattr__ (CanaryRegion e frozen), clear user_paused + drift_paused într-un singur shot — similar /resume. Fix adiacent: _dispatch_ctx / _mock_config_class setează cfg.window_title=None explicit; 5 teste _dispatch_command pre-existente eșuau pe MagicMock auto- truthy care propaga în _focus_window_by_title. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
"""Tests for atm.commands — /pause /resume parsing (Commit 5)."""
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
from atm.commands import Command, TelegramPoller
|
|
|
|
|
|
def _make_poller() -> TelegramPoller:
|
|
cfg = MagicMock()
|
|
cfg.bot_token = "tok"
|
|
cfg.chat_id = "123"
|
|
cfg.allowed_chat_ids = ("123",)
|
|
cfg.poll_timeout_s = 1
|
|
return TelegramPoller(cfg, MagicMock(), MagicMock())
|
|
|
|
|
|
def test_parse_pause():
|
|
p = _make_poller()
|
|
assert p._parse_command("pause") == Command(action="pause")
|
|
assert p._parse_command("/pause") == Command(action="pause")
|
|
|
|
|
|
def test_parse_resume_plain():
|
|
p = _make_poller()
|
|
assert p._parse_command("resume") == Command(action="resume")
|
|
assert p._parse_command("/resume") == Command(action="resume")
|
|
|
|
|
|
def test_parse_resume_force():
|
|
p = _make_poller()
|
|
# "resume force" → value=1 signals force-resume of canary drift
|
|
cmd = p._parse_command("resume force")
|
|
assert cmd is not None
|
|
assert cmd.action == "resume"
|
|
assert cmd.value == 1
|
|
|
|
|
|
def test_parse_rebase_plain():
|
|
p = _make_poller()
|
|
assert p._parse_command("rebase") == Command(action="rebase")
|
|
assert p._parse_command("/rebase") == Command(action="rebase")
|
|
|
|
|
|
def test_parse_rebase_confirm():
|
|
p = _make_poller()
|
|
cmd = p._parse_command("rebase confirm")
|
|
assert cmd is not None
|
|
assert cmd.action == "rebase"
|
|
assert cmd.value == 1
|
|
|
|
|
|
def test_parse_help():
|
|
p = _make_poller()
|
|
assert p._parse_command("h") == Command(action="help")
|
|
assert p._parse_command("/h") == Command(action="help")
|
|
assert p._parse_command("help") == Command(action="help")
|
|
assert p._parse_command("/help") == Command(action="help")
|
|
|
|
|
|
def test_parse_existing_commands_still_work():
|
|
"""Regression: adding pause/resume must not break stop/status/ss/interval."""
|
|
p = _make_poller()
|
|
assert p._parse_command("stop") == Command(action="stop")
|
|
assert p._parse_command("status") == Command(action="status")
|
|
assert p._parse_command("ss") == Command(action="ss")
|
|
assert p._parse_command("3") == Command(action="set_interval", value=180)
|