Coverage for src/copytrading_engine/parsing/readiness.py: 96%
24 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-16 16:55 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-16 16:55 +0000
1"""Provider readiness observations; a delayed probe cannot overwrite a newer alert result."""
3import time
4from dataclasses import dataclass, field
6from copytrading_engine.parsing.extraction import DecodeError, Decoder, Route
7from copytrading_engine.shared.reading import Chatter, Commentary
10@dataclass
11class ModelReadiness:
12 ready: bool = False
13 checked_at: float | None = None
14 error: str | None = None
15 revision: int = field(default=0, init=False)
17 def record(self, error: str | None = None) -> None:
18 self.ready = error is None
19 self.error = error
20 self.checked_at = time.time()
21 self.revision += 1
24async def probe_model(decoder: Decoder, health: ModelReadiness) -> None:
25 revision = health.revision
26 try:
27 result = (await decoder.answer("Market commentary only. No trade action.", Route())).reading
28 # Either way it reads as nothing to trade: a model may fairly take the line for chat.
29 error = None if isinstance(result, Commentary | Chatter) else "unexpected_probe_output"
30 except DecodeError as exc:
31 error = exc.reason
32 # Real extraction is stronger evidence than a probe started before that extraction.
33 if health.revision == revision: 33 ↛ exitline 33 didn't return from function 'probe_model' because the condition on line 33 was always true
34 health.record(error)