Coverage for src/copytrading_engine/diagnostics/telemetry/attributes.py: 80%
22 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"""Bounded, validated journal field values."""
3import re
5from copytrading_engine.host.self_test.model import Stage
6from copytrading_engine.shared.payload_capture import CaptureKind
9def stages() -> tuple[str, ...]:
10 return tuple(stage.value for stage in Stage)
13def bounded_label(value: str, allowed: tuple[str, ...]) -> str:
14 return value if value in allowed else "other"
17def validated_hex_id(value: str | None, size: int) -> str | None:
18 if value is None:
19 return None
20 candidate = value.replace("-", "").casefold()
21 if len(candidate) != size or not re.fullmatch(r"[0-9a-f]+", candidate): 21 ↛ 22line 21 didn't jump to line 22 because the condition on line 21 was never true
22 return None
23 if int(candidate, 16) == 0: 23 ↛ 24line 23 didn't jump to line 24 because the condition on line 23 was never true
24 return None
25 return candidate
28def bounded_opaque_id(value: str, maximum: int) -> str:
29 if len(value) <= maximum and re.fullmatch(r"[A-Za-z0-9._:-]+", value): 29 ↛ 31line 29 didn't jump to line 31 because the condition on line 29 was always true
30 return value
31 return "[REDACTED]"
34def capture_counter_keys(kind: CaptureKind) -> tuple[str | None, str | None]:
35 return {
36 "source_event": ("source_events", "source_event_gaps"),
37 "model_request": ("model_requests", "model_request_gaps"),
38 "model_response": ("model_responses", "model_response_gaps"),
39 "other": (None, None),
40 }[kind]