Add two new Telegram commands so the user can manage monitoring without
restarting the process:
- /pause sets lifecycle.user_paused = True. The detection loop then
short-circuits via _should_skip without touching FSM / canary state.
- /resume clears user_paused. R2 decision: drift-pause is NOT lifted by
plain /resume (the drift may be legit and require recalibration).
"/resume force" (value=1) also calls canary.resume(). The response
message adapts to context:
- drift active + plain resume → explains force requirement
- force + drift → confirms override, warns about recurrence
- out-of-window → explains monitor will resume at next open
- otherwise → plain "Monitorizare reluată"
- /status now shows "Activ: <pause_reason | activ>" and window state.
commands.py: extend CommandAction literal and _parse_command to accept
pause, resume, and "resume force" (value=1 signal).
Tests: test_commands.py parse coverage;
test_pause_command_sets_user_paused_and_skips_detection,
test_resume_clears_user_paused_and_canary_when_forced,
test_resume_during_drift_keeps_canary_paused_without_force (R2 #21),
test_resume_out_of_window_responds_with_pending_message,
test_status_command_reports_pause_reason,
test_lifecycle_with_drift_then_resume_then_fire (E2E #16).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 lines
1.4 KiB
Python
46 lines
1.4 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_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)
|