Files
atm/tests/test_config.py
Claude Agent 840c23f74c feat(run): screenshot attach, Telegram ok:false fix, post-FIRE catchup guard
Three bundled fixes on the dispatch + FSM + notifier triangle:

1. Telegram silent-success bug: parse JSON body after 200 OK, raise on
   ok:false so FanoutNotifier retries + DLQs + stats surface the failure.
   Previously Discord succeeded while Telegram silently dropped.

2. Per-kind screenshot attach: new AlertsCfg dataclass with per-kind toggle
   (late_start, catchup, arm, prime, trigger). _save_annotated_frame helper
   extracted from inline FIRE block, threaded via Snapshot closure into
   _handle_tick. Failures audit-logged, never silent.

3. Post-FIRE catchup regression (d7305fb): residual dark_green/dark_red dots
   after a FIRE cycle look like startup-catchup from (color, state) alone.
   New fsm.fired_in_session(direction) gate suppresses synth-arm after a
   cycle already fired in that direction. Opposite direction unaffected.

Also: queue-overflow on_drop audit callback, periodic + shutdown heartbeat
stats per-backend, config back-compat (bool or dict for attach_screenshots).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 22:40:17 +00:00

100 lines
3.7 KiB
Python

"""Tests for atm.config — focused on attach_screenshots parsing (legacy bool vs new dict)."""
from __future__ import annotations
from atm.config import AlertsCfg, Config
_BASE = {
"window_title": "X",
"dot_roi": {"x": 0, "y": 0, "w": 10, "h": 10},
"chart_roi": {"x": 0, "y": 0, "w": 100, "h": 100},
"colors": {
"turquoise": {"rgb": [64, 224, 208], "tolerance": 30.0},
"yellow": {"rgb": [255, 215, 0], "tolerance": 30.0},
"dark_green": {"rgb": [0, 100, 0], "tolerance": 30.0},
"dark_red": {"rgb": [139, 0, 0], "tolerance": 30.0},
"light_green": {"rgb": [0, 230, 118], "tolerance": 30.0},
"light_red": {"rgb": [255, 82, 82], "tolerance": 30.0},
"gray": {"rgb": [128, 128, 128], "tolerance": 25.0},
},
"y_axis": {"p1_y": 100, "p1_price": 485.0, "p2_y": 200, "p2_price": 484.0},
"canary": {
"roi": {"x": 0, "y": 0, "w": 10, "h": 10},
"baseline_phash": "0" * 16,
"drift_threshold": 8,
},
"discord": {"webhook_url": "https://example.com/hook"},
"telegram": {"bot_token": "tok", "chat_id": "123"},
}
def _with_opts(opts: dict) -> dict:
d = {k: v for k, v in _BASE.items()}
d["options"] = opts
return d
def test_attach_screenshots_default_all_true() -> None:
"""Missing attach_screenshots → all fields True."""
cfg = Config._from_dict(_with_opts({}))
assert cfg.attach_screenshots == AlertsCfg(
late_start=True, catchup=True, arm=True, prime=True, trigger=True,
)
def test_attach_screenshots_legacy_bool_true() -> None:
"""Legacy: attach_screenshots = true → all fields True."""
cfg = Config._from_dict(_with_opts({"attach_screenshots": True}))
assert cfg.attach_screenshots.arm is True
assert cfg.attach_screenshots.catchup is True
assert cfg.attach_screenshots.trigger is True
def test_attach_screenshots_legacy_bool_false() -> None:
"""Legacy: attach_screenshots = false → all fields False."""
cfg = Config._from_dict(_with_opts({"attach_screenshots": False}))
assert cfg.attach_screenshots.arm is False
assert cfg.attach_screenshots.catchup is False
assert cfg.attach_screenshots.trigger is False
assert cfg.attach_screenshots.late_start is False
def test_attach_screenshots_partial_dict() -> None:
"""Dict form with only some keys → specified False, others default True."""
cfg = Config._from_dict(_with_opts({
"attach_screenshots": {"arm": False, "prime": False},
}))
assert cfg.attach_screenshots.arm is False
assert cfg.attach_screenshots.prime is False
# Unspecified → dataclass default True
assert cfg.attach_screenshots.trigger is True
assert cfg.attach_screenshots.catchup is True
assert cfg.attach_screenshots.late_start is True
def test_attach_screenshots_full_dict() -> None:
"""Dict form with all keys specified."""
cfg = Config._from_dict(_with_opts({
"attach_screenshots": {
"late_start": False,
"catchup": True,
"arm": False,
"prime": True,
"trigger": True,
},
}))
assert cfg.attach_screenshots.late_start is False
assert cfg.attach_screenshots.catchup is True
assert cfg.attach_screenshots.arm is False
assert cfg.attach_screenshots.prime is True
assert cfg.attach_screenshots.trigger is True
def test_attach_screenshots_unknown_keys_ignored() -> None:
"""Unknown keys are silently dropped (dataclass won't accept them)."""
cfg = Config._from_dict(_with_opts({
"attach_screenshots": {"arm": False, "nonexistent_knob": True},
}))
assert cfg.attach_screenshots.arm is False
# Should not raise even with unknown key