fix(P-079): Modal-Puls Cache-Skip — rot fest statt pulsierend
This commit is contained in:
@@ -437,7 +437,7 @@ class _Mediator:
|
||||
)
|
||||
self._modal_pulse_timer.daemon = True
|
||||
self._modal_pulse_timer.start()
|
||||
logger.debug(
|
||||
logger.info(
|
||||
"[presence-v10] Modal-Puls-Timer gestartet (%.1fs, adaptiv=%.1fs)",
|
||||
interval, self._modal_pulse_current_interval_s,
|
||||
)
|
||||
@@ -685,8 +685,21 @@ class _Mediator:
|
||||
message = self._phase_status_message_locked()
|
||||
is_pulse = self.current_phase in (Phase.GREEN_PULSE, Phase.RED_PULSE)
|
||||
|
||||
# ── P-041b: 3-Schichten-Cache ─────────────────────────────────────
|
||||
if is_pulse:
|
||||
# ── P-079: Modal-Puls Cache-Skip ──────────────────────────────────
|
||||
# Beim Clarify-Modal toggelt nur der Status (busy↔offline), Phase und
|
||||
# Message bleiben gleich. Der P-041b-Cache prüft aber nur Phase+Message
|
||||
# (P1/P2) bzw. Phase+Message+Status (P3/P4 bei ddp_healthy=False) —
|
||||
# beim Modal-Puls würde jeder Tick gecacht → rot fest statt pulsierend.
|
||||
# Konsistent mit P-052 (Cooldown-Override für Modal): Modal ist
|
||||
# zeitlich begrenzt, das 429-Risiko ist akzeptabel.
|
||||
if self._clarify_modal:
|
||||
logger.debug(
|
||||
"[presence-v10] P-079: Modal-Puls Cache-Skip — "
|
||||
"phase=%s, status=%s (immer senden)",
|
||||
self.current_phase.name, status,
|
||||
)
|
||||
# Fall through — Cache wird übersprungen, immer senden
|
||||
elif is_pulse:
|
||||
# P3/P4: Cache-Entscheidung hängt von ddp_healthy ab
|
||||
ddp_healthy = self._is_ddp_healthy()
|
||||
if ddp_healthy:
|
||||
|
||||
@@ -315,6 +315,81 @@ class TestCacheLockerung:
|
||||
assert rest_sender.call_count == 1
|
||||
|
||||
|
||||
class TestModalPulseCacheSkip:
|
||||
"""P-079: Modal-Puls muss den P1/P2-Cache überspringen (rot fest → pulsierend)."""
|
||||
|
||||
def _make_modal_mediator(self):
|
||||
"""Erzeuge Mediator mit aktivem Clarify-Modal (RED_STATIC-Phase)."""
|
||||
rest_sender = MagicMock(return_value=True)
|
||||
mediator = _Mediator(rest_sender=rest_sender)
|
||||
mediator.current_phase = Phase.RED_STATIC
|
||||
mediator._clarify_modal = True
|
||||
mediator._clarify_modal_message = "Hauptagent wartet auf Antwort"
|
||||
return mediator, rest_sender
|
||||
|
||||
def test_modal_pulse_bypasses_cache(self):
|
||||
"""Modal aktiv → Cache wird übersprungen (jeder Tick sendet)."""
|
||||
mediator, rest_sender = self._make_modal_mediator()
|
||||
|
||||
# Erster Tick (busy)
|
||||
with mediator._mediator_lock:
|
||||
mediator._send_phase_status_locked()
|
||||
assert rest_sender.call_count == 1
|
||||
|
||||
# Zweiter Tick — Phase + Message unverändert, nur Status toggelt.
|
||||
# Ohne P-079-Fix würde der P1/P2-Cache hier greifen (Phase+Message
|
||||
# gleich) und den Call unterdrücken.
|
||||
mediator._modal_pulse_toggle = True # busy → offline
|
||||
with mediator._mediator_lock:
|
||||
mediator._send_phase_status_locked()
|
||||
assert rest_sender.call_count == 2, (
|
||||
"Modal-Puls wurde gecacht — P-079-Fix greift nicht"
|
||||
)
|
||||
|
||||
def test_modal_pulse_sends_status_toggle(self):
|
||||
"""busy→offline→busy wird tatsächlich gesendet (Status-Toggle sichtbar)."""
|
||||
mediator, rest_sender = self._make_modal_mediator()
|
||||
|
||||
# Tick 1: busy
|
||||
with mediator._mediator_lock:
|
||||
mediator._send_phase_status_locked()
|
||||
# Tick 2: offline
|
||||
mediator._modal_pulse_toggle = True
|
||||
with mediator._mediator_lock:
|
||||
mediator._send_phase_status_locked()
|
||||
# Tick 3: busy (zurück)
|
||||
mediator._modal_pulse_toggle = False
|
||||
with mediator._mediator_lock:
|
||||
mediator._send_phase_status_locked()
|
||||
|
||||
assert rest_sender.call_count == 3
|
||||
|
||||
# Status-Sequenz muss busy → offline → busy sein
|
||||
sent_statuses = [c.args[0] for c in rest_sender.call_args_list]
|
||||
assert sent_statuses == ["busy", "offline", "busy"], (
|
||||
f"Status-Toggle falsch: {sent_statuses}"
|
||||
)
|
||||
|
||||
def test_non_modal_respects_cache(self):
|
||||
"""Ohne Modal → Cache funktioniert normal (P1/P2 unverändert)."""
|
||||
rest_sender = MagicMock(return_value=True)
|
||||
mediator = _Mediator(rest_sender=rest_sender)
|
||||
mediator.current_phase = Phase.RED_STATIC
|
||||
# Kein Modal aktiv
|
||||
|
||||
# Erster Call
|
||||
with mediator._mediator_lock:
|
||||
mediator._send_phase_status_locked()
|
||||
assert rest_sender.call_count == 1
|
||||
|
||||
# Zweiter Call — gleiche Phase + Message → Cache greift
|
||||
with mediator._mediator_lock:
|
||||
mediator._send_phase_status_locked()
|
||||
assert rest_sender.call_count == 1, (
|
||||
"Ohne Modal muss der P1/P2-Cache weiterhin greifen"
|
||||
)
|
||||
|
||||
|
||||
class TestPulseLockE3:
|
||||
"""P-041b E3: pulse_lock serialisiert Pulse-Ticks."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user