fcfbc29284
- Puls-Intervall: 3s → 5s (PULSE_INTERVAL_S = 5.0) - REST-Call nur jeden 2. Puls-Tick (alle 10s) via PULSE_REST_EVERY_N_TICKS=2 - 429-Circuit-Breaker: exponentieller Backoff (30s/60s/120s) - Strike 1-3: Puls pausiert, nach Backoff resumed - Strike 4+: Puls stoppt komplett (bis subagent_start erneut feuert) - Erfolgreicher REST-Call → Strikes zurückgesetzt - 4 neue Tests: TestPulse429CircuitBreaker, TestPulse429ThreeStrikes, TestPulseInterval5s, TestPulseRestCallEvery10s - Alle 72 bestehenden Tests weiterhin PASSED
1350 lines
50 KiB
Python
1350 lines
50 KiB
Python
"""
|
|
V9: PresenceEngine — Schachuhr-Architektur Tests.
|
|
|
|
Tests für die ereignisgesteuerte V9 PresenceEngine:
|
|
- 6 Hook-Trigger-Tests (jeder Hook feuert, Counter korrekt)
|
|
- 4 Counter-Tests (inkrement, dekrement, sum, transition)
|
|
- 3 Race-Tests (parallel Hooks, last-wins, away-grace cancel)
|
|
|
|
V9.0.1: Alle Tests sind SYNCHRON — invoke_hook() ruft Callbacks synchron auf.
|
|
Kein asyncio, kein loop.run_until_complete(), kein await.
|
|
|
|
V8.x-Tests sind am Ende als skipped markiert (V8.x removed in V9).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import os
|
|
import time
|
|
import threading
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
# Ensure the plugin package is importable
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# Hilfsfunktionen
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
def _make_mock_rest():
|
|
"""Erzeuge einen Mock-REST-Client für Tests."""
|
|
rest = MagicMock()
|
|
rest.auth_token = "test-token"
|
|
rest.user_id = "test-user"
|
|
rest._request = MagicMock()
|
|
return rest
|
|
|
|
|
|
def _make_engine(rest=None, enabled=True, away_grace_s=0.1):
|
|
"""Erzeuge eine PresenceEngine V9 für Tests (mit kurzem away-grace).
|
|
|
|
V9.0.1: Kein asyncio-Loop nötig — Hooks sind synchron.
|
|
"""
|
|
from plugin.archivar.presence_engine import PresenceEngine
|
|
if rest is None:
|
|
rest = _make_mock_rest()
|
|
engine = PresenceEngine(rest=rest, enabled=enabled, away_grace_s=away_grace_s)
|
|
return engine
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# 1. Hook-Trigger-Tests (6 Tests)
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
class TestHookPreGatewayDispatch:
|
|
"""pre_gateway_dispatch → main_agent += 1 (ROT Start)."""
|
|
|
|
def test_pre_gateway_dispatch_increments_main_agent(self):
|
|
"""Hook feuert → main_agent-Counter steigt auf 1."""
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
counters = engine.get_counters()
|
|
assert counters["main_agent"] == 1
|
|
assert counters["delegate_subagent"] == 0
|
|
assert counters["chat_profile"] == 0
|
|
assert counters["background_term"] == 0
|
|
assert engine.get_status() == "BUSY"
|
|
|
|
def test_pre_gateway_dispatch_disabled_engine_noop(self):
|
|
"""Deaktivierte Engine → Hook ist No-Op."""
|
|
engine = _make_engine(enabled=False)
|
|
engine.on_pre_gateway_dispatch()
|
|
counters = engine.get_counters()
|
|
assert counters["main_agent"] == 0
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
|
|
class TestHookPostLlmCall:
|
|
"""post_llm_call → main_agent -= 1 (ROT Ende)."""
|
|
|
|
def test_post_llm_call_decrements_main_agent(self):
|
|
"""Nach pre_gateway_dispatch + post_llm_call → Counter wieder 0."""
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_post_llm_call()
|
|
# away-grace abwarten
|
|
time.sleep(engine._away_grace_s + 0.05)
|
|
counters = engine.get_counters()
|
|
assert counters["main_agent"] == 0
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
def test_post_llm_call_without_pre_gateway_no_negative(self):
|
|
"""post_llm_call ohne vorheriges pre_gateway → Counter bleibt 0 (kein negativ)."""
|
|
engine = _make_engine()
|
|
engine.on_post_llm_call()
|
|
counters = engine.get_counters()
|
|
assert counters["main_agent"] == 0
|
|
|
|
|
|
class TestHookSubagentStartStop:
|
|
"""subagent_start/stop → delegate_subagent += 1 / -= 1 (GELB)."""
|
|
|
|
def test_subagent_start_increments_delegate(self):
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
counters = engine.get_counters()
|
|
assert counters["delegate_subagent"] == 1
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
def test_subagent_start_stop_balanced(self):
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
engine.on_subagent_stop()
|
|
time.sleep(engine._away_grace_s + 0.05)
|
|
counters = engine.get_counters()
|
|
assert counters["delegate_subagent"] == 0
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
def test_multiple_subagents_counter_accurate(self):
|
|
"""3 Subagenten starten, 2 stoppen → Counter = 1, Status = AWAY."""
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
engine.on_subagent_start()
|
|
engine.on_subagent_start()
|
|
engine.on_subagent_stop()
|
|
engine.on_subagent_stop()
|
|
counters = engine.get_counters()
|
|
assert counters["delegate_subagent"] == 1
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
|
|
class TestHookSessionStartEnd:
|
|
"""on_session_start/end → chat_profile += 1 / -= 1 (GELB)."""
|
|
|
|
def test_session_start_increments_chat_profile(self):
|
|
engine = _make_engine()
|
|
engine.on_session_start()
|
|
counters = engine.get_counters()
|
|
assert counters["chat_profile"] == 1
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
def test_session_start_end_balanced(self):
|
|
engine = _make_engine()
|
|
engine.on_session_start()
|
|
engine.on_session_end()
|
|
time.sleep(engine._away_grace_s + 0.05)
|
|
counters = engine.get_counters()
|
|
assert counters["chat_profile"] == 0
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
|
|
class TestHookBackgroundTerminal:
|
|
"""pre/post_tool_call → background_term += 1 / -= 1 (O-1 Workaround)."""
|
|
|
|
def test_pre_tool_call_terminal_bg_increments(self):
|
|
"""pre_tool_call mit tool_name='terminal' + background=True → Counter steigt."""
|
|
engine = _make_engine()
|
|
engine.on_pre_tool_call(
|
|
tool_name="terminal",
|
|
args={"background": True, "command": "sleep 10"},
|
|
)
|
|
counters = engine.get_counters()
|
|
assert counters["background_term"] == 1
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
def test_pre_tool_call_non_terminal_noop(self):
|
|
"""pre_tool_call mit tool_name='read_file' → kein Counter-Change."""
|
|
engine = _make_engine()
|
|
engine.on_pre_tool_call(
|
|
tool_name="read_file",
|
|
args={"path": "/tmp/test"},
|
|
)
|
|
counters = engine.get_counters()
|
|
assert counters["background_term"] == 0
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
def test_pre_tool_call_terminal_no_background_noop(self):
|
|
"""pre_tool_call mit terminal aber background=False → kein Counter-Change."""
|
|
engine = _make_engine()
|
|
engine.on_pre_tool_call(
|
|
tool_name="terminal",
|
|
args={"background": False, "command": "echo hi"},
|
|
)
|
|
counters = engine.get_counters()
|
|
assert counters["background_term"] == 0
|
|
|
|
def test_post_tool_call_terminal_bg_decrements(self):
|
|
engine = _make_engine()
|
|
engine.on_pre_tool_call(
|
|
tool_name="terminal",
|
|
args={"background": True, "command": "sleep 10"},
|
|
)
|
|
engine.on_post_tool_call(
|
|
tool_name="terminal",
|
|
args={"background": True, "command": "sleep 10"},
|
|
)
|
|
time.sleep(engine._away_grace_s + 0.05)
|
|
counters = engine.get_counters()
|
|
assert counters["background_term"] == 0
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# 2. Counter-Tests (4 Tests)
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
class TestCounterIncrement:
|
|
"""Counter-Inkrement: +1 auf jeden Counter-Typ."""
|
|
|
|
def test_main_agent_increment(self):
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_counters()["main_agent"] == 1
|
|
|
|
def test_delegate_subagent_increment(self):
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
assert engine.get_counters()["delegate_subagent"] == 1
|
|
|
|
def test_chat_profile_increment(self):
|
|
engine = _make_engine()
|
|
engine.on_session_start()
|
|
assert engine.get_counters()["chat_profile"] == 1
|
|
|
|
def test_background_term_increment(self):
|
|
engine = _make_engine()
|
|
engine.on_pre_tool_call(
|
|
tool_name="terminal",
|
|
args={"background": True},
|
|
)
|
|
assert engine.get_counters()["background_term"] == 1
|
|
|
|
|
|
class TestCounterDecrement:
|
|
"""Counter-Dekrement: -1, kein negativ."""
|
|
|
|
def test_decrement_to_zero(self):
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_post_llm_call()
|
|
time.sleep(engine._away_grace_s + 0.05)
|
|
assert engine.get_counters()["main_agent"] == 0
|
|
|
|
def test_decrement_below_zero_clamped(self):
|
|
"""Dekrement ohne vorheriges Inkrement → bleibt 0 (kein negativ)."""
|
|
engine = _make_engine()
|
|
engine.on_post_llm_call()
|
|
assert engine.get_counters()["main_agent"] == 0
|
|
|
|
|
|
class TestCounterSum:
|
|
"""Summe aller Counter bestimmt Status."""
|
|
|
|
def test_sum_zero_means_online(self):
|
|
engine = _make_engine()
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
def test_sum_positive_means_busy(self):
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_status() == "BUSY"
|
|
|
|
def test_mixed_counters_sum_correct(self):
|
|
"""main_agent=1 + delegate_subagent=2 → sum=3 → AWAY (subagent hat Vorrang)."""
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_subagent_start()
|
|
engine.on_subagent_start()
|
|
total = sum(engine.get_counters().values())
|
|
assert total == 3
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
|
|
class TestCounterTransition:
|
|
"""Transition ONLINE↔BUSY bei Counter-Änderungen."""
|
|
|
|
def test_online_to_busy_transition(self):
|
|
engine = _make_engine()
|
|
assert engine.get_status() == "ONLINE"
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_status() == "BUSY"
|
|
|
|
def test_busy_to_online_transition_after_away_grace(self):
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_status() == "BUSY"
|
|
engine.on_post_llm_call()
|
|
# away-grace abwarten
|
|
time.sleep(engine._away_grace_s + 0.05)
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
def test_busy_stays_busy_during_away_grace(self):
|
|
"""Während away-grace läuft, ist interner Status ONLINE, REST-Call verzögert.
|
|
|
|
Architektur 3.3: Status wechselt SOFORT auf ONLINE wenn total=0.
|
|
Der away-grace verzögert nur den REST-Call, nicht den internen State.
|
|
"""
|
|
engine = _make_engine(away_grace_s=0.5)
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_post_llm_call()
|
|
# away-grace läuft noch (0.5s), interner Status ist bereits ONLINE
|
|
time.sleep(0.1)
|
|
# Interner Status ist ONLINE (total=0), REST-Call folgt nach away-grace
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# 3. Race-Tests (3 Tests)
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
class TestRaceParallelHooks:
|
|
"""Parallele Hooks — Counter unter Lock konsistent."""
|
|
|
|
def test_parallel_increments_consistent(self):
|
|
"""10 parallele pre_gateway_dispatch → main_agent == 10."""
|
|
engine = _make_engine()
|
|
threads = []
|
|
for _ in range(10):
|
|
t = threading.Thread(target=engine.on_pre_gateway_dispatch)
|
|
threads.append(t)
|
|
t.start()
|
|
for t in threads:
|
|
t.join()
|
|
assert engine.get_counters()["main_agent"] == 10
|
|
|
|
def test_parallel_mixed_operations_consistent(self):
|
|
"""Parallel inkrement + dekrement → Counter konsistent."""
|
|
engine = _make_engine()
|
|
threads = []
|
|
# 5 Starts
|
|
for _ in range(5):
|
|
t = threading.Thread(target=engine.on_subagent_start)
|
|
threads.append(t)
|
|
t.start()
|
|
# 3 Stops
|
|
for _ in range(3):
|
|
t = threading.Thread(target=engine.on_subagent_stop)
|
|
threads.append(t)
|
|
t.start()
|
|
for t in threads:
|
|
t.join()
|
|
assert engine.get_counters()["delegate_subagent"] == 2 # 5 - 3 = 2
|
|
|
|
|
|
class TestRaceLastWins:
|
|
"""Last-wins: schedule_transition überschreibt vorherige Transition."""
|
|
|
|
def test_last_wins_overwrites_pending_transition(self):
|
|
"""Schnelle aufeinanderfolgende Hooks → nur letzter Status wird gesendet."""
|
|
rest = _make_mock_rest()
|
|
engine = _make_engine(rest=rest, away_grace_s=0.05)
|
|
|
|
# Schnell: BUSY → ONLINE → BUSY
|
|
engine.on_pre_gateway_dispatch() # BUSY
|
|
engine.on_post_llm_call() # ONLINE (away-grace startet)
|
|
engine.on_pre_gateway_dispatch() # BUSY (away-grace gecancelt)
|
|
# Warten bis Transition gesendet
|
|
time.sleep(0.2)
|
|
assert engine.get_status() == "BUSY"
|
|
# REST sollte mindestens einmal aufgerufen worden sein
|
|
assert rest._request.call_count >= 1
|
|
|
|
|
|
class TestRaceAwayGraceCancel:
|
|
"""away-grace wird gecancelt wenn neuer BUSY-Hook feuert."""
|
|
|
|
def test_away_grace_cancelled_by_busy_hook(self):
|
|
"""away-grace läuft → neuer Hook feuert → away-grace gecancelt → Status AWAY."""
|
|
engine = _make_engine(away_grace_s=0.5)
|
|
engine.on_pre_gateway_dispatch() # BUSY
|
|
engine.on_post_llm_call() # away-grace startet (0.5s)
|
|
time.sleep(0.1) # away-grace läuft noch
|
|
engine.on_subagent_start() # neuer AWAY-Hook → cancel away-grace
|
|
time.sleep(0.6) # away-grace wäre abgelaufen
|
|
# Sollte AWAY sein weil subagent_start den away-grace gecancelt hat
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
def test_away_grace_completes_when_no_interrupt(self):
|
|
"""away-grace läuft durch → Status wird ONLINE."""
|
|
engine = _make_engine(away_grace_s=0.1)
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_post_llm_call()
|
|
time.sleep(0.3) # away-grace (0.1s) + Transition
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# 4. Zusätzliche Tests: Telemetrie, Caching, Busy-Message
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
class TestTelemetry:
|
|
"""Telemetrie: REST-Calls, Erfolg, 429, Fehler."""
|
|
|
|
def test_telemetry_initial_zero(self):
|
|
engine = _make_engine()
|
|
t = engine.get_telemetry()
|
|
assert t["rest_calls"] == 0
|
|
assert t["rest_success"] == 0
|
|
assert t["rest_429"] == 0
|
|
assert t["rest_errors"] == 0
|
|
|
|
|
|
class TestBusyMessage:
|
|
"""_build_busy_message: korrekte Status-Messages."""
|
|
|
|
def test_single_counter_message(self):
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
msg = engine._build_busy_message()
|
|
assert "Hauptagent" in msg
|
|
|
|
def test_multiple_counters_message(self):
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_subagent_start()
|
|
msg = engine._build_busy_message()
|
|
assert "2 Aufgaben" in msg
|
|
|
|
|
|
class TestEnableDisable:
|
|
"""enable()/disable() — korrektes Verhalten."""
|
|
|
|
def test_disable_stops_processing(self):
|
|
engine = _make_engine()
|
|
engine.disable()
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_counters()["main_agent"] == 0
|
|
|
|
def test_enable_re_enables_processing(self):
|
|
engine = _make_engine()
|
|
engine.disable()
|
|
engine.enable()
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_counters()["main_agent"] == 1
|
|
|
|
|
|
class TestShutdown:
|
|
"""shutdown() — sauberes Aufräumen."""
|
|
|
|
def test_shutdown_cancels_away_grace(self):
|
|
engine = _make_engine(away_grace_s=10.0)
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_post_llm_call()
|
|
# away-grace läuft (10s)
|
|
engine.shutdown()
|
|
# Kein Fehler, kein hängender Task
|
|
assert True
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# F2.1: 429-Tests (Rainer Quality Gate)
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
class TestHttp429Handling:
|
|
"""HTTP 429 von users.setStatus — kein Crash, Status bleibt, Telemetrie."""
|
|
|
|
def test_429_no_crash_status_unchanged(self):
|
|
"""429-Antwort → kein Crash, interner Status bleibt unverändert."""
|
|
rest = _make_mock_rest()
|
|
# Simuliere 429: _request wirft Exception mit "429" im Text
|
|
rest._request.side_effect = Exception("HTTP 429 Too Many Requests")
|
|
engine = _make_engine(rest=rest, away_grace_s=0.05)
|
|
|
|
# Setze Status auf BUSY
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_status() == "BUSY"
|
|
# Warte auf Transition (REST-Call schlägt fehl mit 429)
|
|
time.sleep(0.2)
|
|
# Status bleibt BUSY — Counter wurde nicht zurückgesetzt
|
|
assert engine.get_status() == "BUSY"
|
|
assert engine.get_counters()["main_agent"] == 1
|
|
|
|
def test_429_retry_on_next_hook(self):
|
|
"""Nach 429 wird bei nächstem Hook-Ereignis erneut gesendet."""
|
|
rest = _make_mock_rest()
|
|
# Erster Call: 429, zweiter Call: Erfolg
|
|
call_count = [0]
|
|
|
|
def _side_effect(*args, **kwargs):
|
|
call_count[0] += 1
|
|
if call_count[0] == 1:
|
|
raise Exception("HTTP 429 Too Many Requests")
|
|
return {"success": True}
|
|
|
|
rest._request.side_effect = _side_effect
|
|
engine = _make_engine(rest=rest, away_grace_s=0.05)
|
|
|
|
# Erster Hook: BUSY → REST-Call schlägt fehl (429)
|
|
engine.on_pre_gateway_dispatch()
|
|
time.sleep(0.15)
|
|
# Zweiter Hook: post_llm_call → Counter=0 → ONLINE-Transition
|
|
# Der REST-Call sollte jetzt erfolgreich sein
|
|
engine.on_post_llm_call()
|
|
time.sleep(0.2)
|
|
# Nach post_llm_call ist Counter=0, away-grace läuft durch,
|
|
# ONLINE-Transition wird gesendet (zweiter REST-Call, erfolgreich)
|
|
assert engine.get_status() == "ONLINE"
|
|
assert call_count[0] >= 2 # Mindestens 2 REST-Calls (429 + success)
|
|
|
|
def test_429_telemetry_counted(self):
|
|
"""Telemetrie zählt 429 korrekt."""
|
|
rest = _make_mock_rest()
|
|
rest._request.side_effect = Exception("HTTP 429 Too Many Requests")
|
|
engine = _make_engine(rest=rest, away_grace_s=0.05)
|
|
|
|
engine.on_pre_gateway_dispatch()
|
|
time.sleep(0.2)
|
|
telemetry = engine.get_telemetry()
|
|
assert telemetry["rest_429"] >= 1
|
|
assert telemetry["rest_calls"] >= 1
|
|
# Kein success weil 429
|
|
assert telemetry["rest_success"] == 0
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# 5. GELB-Logik Tests (V9.1)
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
class TestGelbLogic:
|
|
"""V9.1: GELB-Logik — Subagent aktiv → AWAY (GELB), nicht BUSY (ROT)."""
|
|
|
|
def test_main_agent_only_busy(self):
|
|
"""Nur main_agent > 0 → BUSY (ROT)."""
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_status() == "BUSY"
|
|
assert engine.get_counters()["main_agent"] == 1
|
|
|
|
def test_delegate_subagent_only_away(self):
|
|
"""Nur delegate_subagent > 0 → AWAY (GELB)."""
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
assert engine.get_status() == "AWAY"
|
|
assert engine.get_counters()["delegate_subagent"] == 1
|
|
|
|
def test_main_agent_plus_delegate_subagent_away(self):
|
|
"""main_agent + delegate_subagent → AWAY (GELB — subagent hat Vorrang)."""
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_subagent_start()
|
|
assert engine.get_status() == "AWAY"
|
|
assert engine.get_counters()["main_agent"] == 1
|
|
assert engine.get_counters()["delegate_subagent"] == 1
|
|
|
|
def test_all_zero_online(self):
|
|
"""Alle Counter 0 → ONLINE (GRÜN)."""
|
|
engine = _make_engine()
|
|
assert engine.get_status() == "ONLINE"
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_post_llm_call()
|
|
time.sleep(engine._away_grace_s + 0.05)
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
def test_chat_profile_away(self):
|
|
"""chat_profile > 0 → AWAY (GELB)."""
|
|
engine = _make_engine()
|
|
engine.on_session_start()
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
def test_background_term_away(self):
|
|
"""background_term > 0 → AWAY (GELB)."""
|
|
engine = _make_engine()
|
|
engine.on_pre_tool_call(
|
|
tool_name="terminal",
|
|
args={"background": True, "command": "sleep 10"},
|
|
)
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
def test_subagent_to_online_transition(self):
|
|
"""Subagent start → AWAY, Subagent stop → ONLINE (nach away-grace)."""
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
assert engine.get_status() == "AWAY"
|
|
engine.on_subagent_stop()
|
|
time.sleep(engine._away_grace_s + 0.05)
|
|
assert engine.get_status() == "ONLINE"
|
|
|
|
def test_busy_to_away_transition(self):
|
|
"""main_agent BUSY → Subagent start → AWAY (GELB überschreibt ROT)."""
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
assert engine.get_status() == "BUSY"
|
|
engine.on_subagent_start()
|
|
assert engine.get_status() == "AWAY"
|
|
|
|
def test_away_to_busy_transition(self):
|
|
"""Subagent AWAY → Subagent stop, main_agent noch aktiv → BUSY."""
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch()
|
|
engine.on_subagent_start()
|
|
assert engine.get_status() == "AWAY"
|
|
engine.on_subagent_stop()
|
|
# main_agent ist noch aktiv → BUSY
|
|
assert engine.get_status() == "BUSY"
|
|
|
|
def test_determine_status_static_method(self):
|
|
"""_determine_status() als @staticmethod korrekt."""
|
|
from plugin.archivar.presence_engine import PresenceEngine
|
|
|
|
# Alle 0 → online
|
|
status, msg = PresenceEngine._determine_status({
|
|
"main_agent": 0, "delegate_subagent": 0,
|
|
"chat_profile": 0, "background_term": 0,
|
|
})
|
|
assert status == "online"
|
|
assert msg == ""
|
|
|
|
# Nur main_agent → busy
|
|
status, msg = PresenceEngine._determine_status({
|
|
"main_agent": 1, "delegate_subagent": 0,
|
|
"chat_profile": 0, "background_term": 0,
|
|
})
|
|
assert status == "busy"
|
|
assert "Hauptagent" in msg
|
|
|
|
# delegate_subagent → away
|
|
status, msg = PresenceEngine._determine_status({
|
|
"main_agent": 0, "delegate_subagent": 1,
|
|
"chat_profile": 0, "background_term": 0,
|
|
})
|
|
assert status == "away"
|
|
assert "Subagent" in msg
|
|
|
|
# chat_profile → away
|
|
status, msg = PresenceEngine._determine_status({
|
|
"main_agent": 0, "delegate_subagent": 0,
|
|
"chat_profile": 1, "background_term": 0,
|
|
})
|
|
assert status == "away"
|
|
|
|
# background_term → away
|
|
status, msg = PresenceEngine._determine_status({
|
|
"main_agent": 0, "delegate_subagent": 0,
|
|
"chat_profile": 0, "background_term": 1,
|
|
})
|
|
assert status == "away"
|
|
|
|
# main_agent + subagent → away (subagent hat Vorrang)
|
|
status, msg = PresenceEngine._determine_status({
|
|
"main_agent": 1, "delegate_subagent": 1,
|
|
"chat_profile": 0, "background_term": 0,
|
|
})
|
|
assert status == "away"
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# V9.2 Tests — Pulsieren + Version
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
class TestPulseRotGelb:
|
|
"""V9.2: subagent_active + main_agent>0 → pulsiert zwischen BUSY und AWAY."""
|
|
|
|
def test_pulse_starts_when_subagent_becomes_active(self):
|
|
"""Subagent wird aktiv → Puls-Timer startet."""
|
|
engine = _make_engine()
|
|
assert not engine.is_pulse_active()
|
|
|
|
# Simuliere: subagent_start Hook
|
|
engine.on_subagent_start()
|
|
assert engine.is_pulse_active()
|
|
|
|
def test_pulse_stops_when_subagent_done(self):
|
|
"""Subagent wird inaktiv → Puls-Timer stoppt."""
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
assert engine.is_pulse_active()
|
|
|
|
engine.on_subagent_stop()
|
|
assert not engine.is_pulse_active()
|
|
|
|
def test_pulse_rot_gelb_with_main_agent(self):
|
|
"""main_agent>0 + subagent_active → Puls-Phase wechselt ROT↔GELB."""
|
|
engine = _make_engine()
|
|
engine.on_pre_gateway_dispatch() # main_agent=1
|
|
engine.on_subagent_start() # subagent aktiv
|
|
|
|
assert engine.is_pulse_active()
|
|
# Start-Phase ist "away" → Status sollte AWAY sein
|
|
# (Der erste Tick setzt auf AWAY, dann wechselt er)
|
|
# Wir testen die Phasen-Logik direkt
|
|
assert engine._pulse_phase == "away"
|
|
|
|
def test_pulse_gelb_gruen_without_main_agent(self):
|
|
"""main_agent=0 + subagent_active → Puls-Phase wechselt GELB↔GRÜN."""
|
|
engine = _make_engine()
|
|
engine.on_subagent_start() # subagent aktiv, main_agent=0
|
|
|
|
assert engine.is_pulse_active()
|
|
assert engine._pulse_phase == "away"
|
|
|
|
def test_pulse_no_rest_call_on_same_status(self):
|
|
"""Puls-Tick sendet keinen REST-Call wenn Status unverändert (Caching)."""
|
|
rest = _make_mock_rest()
|
|
engine = _make_engine(rest=rest)
|
|
|
|
# Setze den Cache so dass der nächste AWAY-Status als "bereits gesendet" gilt
|
|
engine._last_sent_status = "away"
|
|
engine._last_sent_message = "beschaeftigt — Subagent aktiv"
|
|
|
|
# Rufe _schedule_transition direkt mit demselben Status auf
|
|
# → sollte gecached werden, kein REST-Call
|
|
engine._schedule_transition("away", "beschaeftigt — Subagent aktiv")
|
|
|
|
# schedule_transition cached identische Calls — kein Thread gestartet
|
|
# → _telemetry_rest_calls bleibt 0
|
|
assert engine._telemetry_rest_calls == 0
|
|
|
|
# Jetzt mit anderem Status → sollte REST-Call triggern
|
|
engine._schedule_transition("busy", "beschaeftigt — Hauptagent arbeitet")
|
|
# Warte kurz dass der Daemon-Thread den REST-Call macht
|
|
time.sleep(0.2)
|
|
assert engine._telemetry_rest_calls >= 1
|
|
|
|
def test_pulse_stops_automatically_when_subagent_counter_zero(self):
|
|
"""Puls-Timer erkennt subagent=0 beim Tick und stoppt sich selbst."""
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
assert engine.is_pulse_active()
|
|
|
|
# Setze counter manuell auf 0 (simuliert subagent_stop ohne Hook)
|
|
engine.counters["delegate_subagent"] = 0
|
|
engine._on_pulse_tick()
|
|
|
|
assert not engine.is_pulse_active()
|
|
|
|
def test_pulse_respects_away_grace(self):
|
|
"""Puls-Tick überspringt Status-Wechsel wenn away-grace läuft."""
|
|
engine = _make_engine(away_grace_s=10.0)
|
|
engine.on_subagent_start()
|
|
|
|
# Starte away-grace manuell
|
|
engine._schedule_away_grace()
|
|
assert engine._away_grace_timer is not None
|
|
|
|
# Puls-Tick sollte keinen Status-Wechsel machen
|
|
old_status = engine._status
|
|
engine._on_pulse_tick()
|
|
# Status sollte unverändert sein (away-grace blockt)
|
|
# Aber der Timer sollte den nächsten Tick planen
|
|
assert engine._pulse_active # Puls läuft weiter
|
|
|
|
# Cleanup
|
|
engine._cancel_away_grace()
|
|
|
|
def test_pulse_shutdown_cleans_up(self):
|
|
"""shutdown() stoppt Puls-Timer."""
|
|
engine = _make_engine()
|
|
engine.on_subagent_start()
|
|
assert engine.is_pulse_active()
|
|
|
|
engine.shutdown()
|
|
assert not engine.is_pulse_active()
|
|
assert engine._pulse_timer is None
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# V9.2.1 Tests — 429-Circuit-Breaker + 5s-Intervall + REST-Throttling
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
class TestPulse429CircuitBreaker:
|
|
"""V9.2.1: 429 → Puls pausiert 30s → resumed."""
|
|
|
|
def test_429_triggers_circuit_breaker(self):
|
|
"""429-Antwort → Circuit-Breaker aktiviert, Puls pausiert."""
|
|
rest = _make_mock_rest()
|
|
rest._request.side_effect = Exception("HTTP 429 Too Many Requests")
|
|
engine = _make_engine(rest=rest)
|
|
|
|
# Starte Puls manuell (ohne on_subagent_start, der Daemon-Thread startet)
|
|
engine._pulse_active = True
|
|
engine._pulse_phase = "away"
|
|
engine.counters["delegate_subagent"] = 1
|
|
|
|
# Simuliere REST-Call der 429 zurückgibt
|
|
engine._rest_set_status("away", "test")
|
|
time.sleep(0.1)
|
|
|
|
# Circuit-Breaker sollte aktiviert sein
|
|
assert engine.is_circuit_breaker_paused()
|
|
assert engine.get_circuit_breaker_strikes() == 1
|
|
|
|
# Puls-Timer sollte gecancelt sein (war nie gesetzt, also None)
|
|
# Aber _pulse_active bleibt True (Puls ist pausiert, nicht gestoppt)
|
|
assert engine._pulse_active
|
|
|
|
def test_circuit_breaker_resumes_after_backoff(self):
|
|
"""Nach Backoff-Zeit → Puls resumed."""
|
|
rest = _make_mock_rest()
|
|
# Erster Call: 429, danach: Erfolg
|
|
call_count = [0]
|
|
|
|
def _side_effect(*args, **kwargs):
|
|
call_count[0] += 1
|
|
if call_count[0] == 1:
|
|
raise Exception("HTTP 429 Too Many Requests")
|
|
return {"success": True}
|
|
|
|
rest._request.side_effect = _side_effect
|
|
engine = _make_engine(rest=rest)
|
|
|
|
# Starte Puls manuell (ohne on_subagent_start)
|
|
engine._pulse_active = True
|
|
engine._pulse_phase = "away"
|
|
engine.counters["delegate_subagent"] = 1
|
|
|
|
# Simuliere 429
|
|
engine._rest_set_status("away", "test")
|
|
time.sleep(0.1)
|
|
assert engine.is_circuit_breaker_paused()
|
|
|
|
# Simuliere Circuit-Breaker-Expiry (manuell, ohne 30s zu warten)
|
|
engine._on_circuit_breaker_expired()
|
|
time.sleep(0.1)
|
|
|
|
# Circuit-Breaker sollte nicht mehr pausieren
|
|
assert not engine.is_circuit_breaker_paused()
|
|
# Puls sollte wieder laufen (Timer neu gestartet)
|
|
assert engine._pulse_active
|
|
|
|
def test_circuit_breaker_reset_on_success(self):
|
|
"""Erfolgreicher REST-Call → Circuit-Breaker Strikes zurückgesetzt."""
|
|
rest = _make_mock_rest()
|
|
# Erster Call: 429, zweiter: Erfolg
|
|
call_count = [0]
|
|
|
|
def _side_effect(*args, **kwargs):
|
|
call_count[0] += 1
|
|
if call_count[0] == 1:
|
|
raise Exception("HTTP 429 Too Many Requests")
|
|
return {"success": True}
|
|
|
|
rest._request.side_effect = _side_effect
|
|
engine = _make_engine(rest=rest)
|
|
|
|
# 429 triggern
|
|
engine._rest_set_status("away", "test")
|
|
assert engine.get_circuit_breaker_strikes() == 1
|
|
|
|
# Erfolgreicher Call
|
|
engine._rest_set_status("online", "")
|
|
assert engine.get_circuit_breaker_strikes() == 0
|
|
assert not engine.is_circuit_breaker_paused()
|
|
|
|
|
|
class TestPulse429ThreeStrikes:
|
|
"""V9.2.1: 3 consecutive 429 → Puls stoppt komplett."""
|
|
|
|
def test_three_strikes_stops_pulse(self):
|
|
"""3 Strikes → Puls gestoppt, _pulse_active = False."""
|
|
rest = _make_mock_rest()
|
|
rest._request.side_effect = Exception("HTTP 429 Too Many Requests")
|
|
engine = _make_engine(rest=rest)
|
|
|
|
# Starte Puls manuell (ohne on_subagent_start)
|
|
engine._pulse_active = True
|
|
engine._pulse_phase = "away"
|
|
engine.counters["delegate_subagent"] = 1
|
|
|
|
# Strike 1
|
|
engine._rest_set_status("away", "test")
|
|
time.sleep(0.1)
|
|
assert engine.get_circuit_breaker_strikes() == 1
|
|
assert engine.is_circuit_breaker_paused()
|
|
# Resume simulieren
|
|
engine._on_circuit_breaker_expired()
|
|
|
|
# Strike 2
|
|
engine._rest_set_status("away", "test")
|
|
time.sleep(0.1)
|
|
assert engine.get_circuit_breaker_strikes() == 2
|
|
engine._on_circuit_breaker_expired()
|
|
|
|
# Strike 3
|
|
engine._rest_set_status("away", "test")
|
|
time.sleep(0.1)
|
|
assert engine.get_circuit_breaker_strikes() == 3
|
|
engine._on_circuit_breaker_expired()
|
|
|
|
# Strike 4 → Puls stoppt
|
|
engine._rest_set_status("away", "test")
|
|
time.sleep(0.1)
|
|
assert engine.get_circuit_breaker_strikes() == 4
|
|
# Puls sollte gestoppt sein
|
|
assert not engine.is_pulse_active()
|
|
assert not engine.is_circuit_breaker_paused()
|
|
|
|
def test_strikes_reset_on_success_between(self):
|
|
"""Erfolg zwischen Strikes → Zähler zurückgesetzt."""
|
|
rest = _make_mock_rest()
|
|
call_count = [0]
|
|
|
|
def _side_effect(*args, **kwargs):
|
|
call_count[0] += 1
|
|
if call_count[0] in (1, 3): # 1st und 3rd = 429
|
|
raise Exception("HTTP 429 Too Many Requests")
|
|
return {"success": True}
|
|
|
|
rest._request.side_effect = _side_effect
|
|
engine = _make_engine(rest=rest)
|
|
|
|
# Strike 1
|
|
engine._rest_set_status("away", "test")
|
|
assert engine.get_circuit_breaker_strikes() == 1
|
|
|
|
# Erfolg → Reset
|
|
engine._rest_set_status("online", "")
|
|
assert engine.get_circuit_breaker_strikes() == 0
|
|
|
|
# Strike 1 (wieder)
|
|
engine._rest_set_status("away", "test")
|
|
assert engine.get_circuit_breaker_strikes() == 1
|
|
|
|
# Erfolg → Reset
|
|
engine._rest_set_status("online", "")
|
|
assert engine.get_circuit_breaker_strikes() == 0
|
|
|
|
|
|
class TestPulseInterval5s:
|
|
"""V9.2.1: Puls-Intervall ist 5s (nicht 3s)."""
|
|
|
|
def test_pulse_interval_is_5_seconds(self):
|
|
"""PULSE_INTERVAL_S ist 5.0."""
|
|
from plugin.archivar.presence_engine import PresenceEngine
|
|
assert PresenceEngine.PULSE_INTERVAL_S == 5.0
|
|
|
|
def test_pulse_timer_uses_5s_interval(self):
|
|
"""_schedule_pulse_tick erzeugt Timer mit 5s."""
|
|
engine = _make_engine()
|
|
engine._pulse_active = True
|
|
engine._schedule_pulse_tick()
|
|
|
|
# Timer sollte mit 5.0s Intervall erstellt sein
|
|
assert engine._pulse_timer is not None
|
|
assert engine._pulse_timer.interval == 5.0
|
|
|
|
# Cleanup
|
|
engine._pulse_timer.cancel()
|
|
|
|
|
|
class TestPulseRestCallEvery10s:
|
|
"""V9.2.1: Nicht jeder Tick sendet REST-Call — nur jeder 2. (alle 10s)."""
|
|
|
|
def test_rest_call_only_every_second_tick(self):
|
|
"""Tick 1 = kein REST, Tick 2 = REST, Tick 3 = kein REST, Tick 4 = REST."""
|
|
rest = _make_mock_rest()
|
|
engine = _make_engine(rest=rest)
|
|
|
|
# Starte Puls manuell
|
|
engine._pulse_active = True
|
|
engine._pulse_phase = "away"
|
|
engine._pulse_tick_count = 0
|
|
engine._status = "AWAY"
|
|
engine.counters["delegate_subagent"] = 1
|
|
|
|
# Tick 1 (tick_count wird 1, 1%2=1 → kein REST)
|
|
engine._on_pulse_tick()
|
|
assert engine._pulse_tick_count == 1
|
|
# Kein REST-Call weil send_rest=False
|
|
assert engine._telemetry_rest_calls == 0
|
|
|
|
# Tick 2 (tick_count wird 2, 2%2=0 → REST)
|
|
engine._on_pulse_tick()
|
|
assert engine._pulse_tick_count == 2
|
|
# REST-Call sollte gesendet worden sein
|
|
time.sleep(0.2)
|
|
assert engine._telemetry_rest_calls >= 1
|
|
|
|
calls_after_tick2 = engine._telemetry_rest_calls
|
|
|
|
# Tick 3 (tick_count wird 3, 3%2=1 → kein REST)
|
|
engine._on_pulse_tick()
|
|
assert engine._pulse_tick_count == 3
|
|
time.sleep(0.1)
|
|
assert engine._telemetry_rest_calls == calls_after_tick2 # Kein neuer Call
|
|
|
|
# Reset Cache damit Tick 4 einen neuen REST-Call sendet
|
|
engine._last_sent_status = None
|
|
engine._last_sent_message = ""
|
|
|
|
# Tick 4 (tick_count wird 4, 4%2=0 → REST)
|
|
engine._on_pulse_tick()
|
|
assert engine._pulse_tick_count == 4
|
|
time.sleep(0.2)
|
|
assert engine._telemetry_rest_calls > calls_after_tick2 # Neuer Call
|
|
|
|
# Cleanup
|
|
engine._pulse_active = False
|
|
|
|
def test_pulse_rest_every_n_ticks_configurable(self):
|
|
"""PULSE_REST_EVERY_N_TICKS ist 2."""
|
|
from plugin.archivar.presence_engine import PresenceEngine
|
|
assert PresenceEngine.PULSE_REST_EVERY_N_TICKS == 2
|
|
|
|
|
|
class TestVersionDisplay:
|
|
"""V9.2: Plugin-Version in ::status und ::hilfe."""
|
|
|
|
def test_version_format(self):
|
|
"""Version-String hat Format 'X.Y (hash)'."""
|
|
from archivar.version import __version__, __commit__
|
|
assert __version__ == "9.2"
|
|
# __commit__ ist "auto" im Dev-Repo, wird von install.sh gesetzt
|
|
assert isinstance(__commit__, str)
|
|
assert len(__commit__) > 0
|
|
|
|
def test_build_status_text_includes_version(self):
|
|
"""build_status_text() zeigt Plugin-Version an wenn übergeben."""
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
result = build_status_text(
|
|
room_count=5,
|
|
archivar_active=True,
|
|
butler_mode="cognitive",
|
|
plugin_version="9.2 (1d31d2c)",
|
|
)
|
|
assert "**Plugin-Version:** 9.2 (1d31d2c)" in result
|
|
|
|
def test_build_status_text_without_version(self):
|
|
"""build_status_text() ohne Version zeigt keine Versionszeile."""
|
|
from archivar.inline_commands import build_status_text
|
|
|
|
result = build_status_text(
|
|
room_count=5,
|
|
archivar_active=True,
|
|
butler_mode="cognitive",
|
|
)
|
|
assert "Plugin-Version:" not in result
|
|
|
|
def test_build_help_text_includes_version(self):
|
|
"""build_help_text() zeigt Plugin-Version an wenn übergeben."""
|
|
from archivar.inline_commands import build_help_text, InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
result = build_help_text(
|
|
registry,
|
|
plugin_version="9.2 (1d31d2c)",
|
|
)
|
|
assert "**Plugin-Version:** 9.2 (1d31d2c)" in result
|
|
|
|
def test_build_help_text_without_version(self):
|
|
"""build_help_text() ohne Version zeigt keine Versionszeile."""
|
|
from archivar.inline_commands import build_help_text, InlineCommandRegistry
|
|
|
|
registry = InlineCommandRegistry()
|
|
result = build_help_text(registry)
|
|
assert "Plugin-Version:" not in result
|
|
|
|
def test_get_plugin_version_returns_version(self):
|
|
"""_get_plugin_version() gibt Version-String zurück."""
|
|
# Wir testen die Funktion direkt — sie importiert aus archivar.version
|
|
# Da wir im Test-Kontext sind, sollte der Import funktionieren
|
|
from archivar.version import __version__
|
|
assert __version__ == "9.2"
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# V8.x Tests — SKIPPED (V8.x removed in V9)
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceIdleSetsOnline:
|
|
def test_idle_sets_online(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceBusySetsBusy:
|
|
def test_busy_sets_busy_with_room_name(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceDecrementBackToOnline:
|
|
def test_decrement_to_zero_sets_online(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceOnboardingSetsAway:
|
|
def test_onboarding_sets_away(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceMoveRequestSetsAway:
|
|
def test_move_request_sets_away(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceErrorSetsAway:
|
|
def test_error_sets_away(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceCachingSkipsRedundant:
|
|
def test_caching_skips_redundant(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceCoalesceDelaysSet:
|
|
def test_coalesce_delays_set(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceFormatMessage:
|
|
def test_format_message_busy(self):
|
|
pass
|
|
def test_format_message_idle(self):
|
|
pass
|
|
def test_format_message_onboarding(self):
|
|
pass
|
|
def test_format_message_move_request(self):
|
|
pass
|
|
def test_format_message_error(self):
|
|
pass
|
|
def test_format_message_heartbeat(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceThreadSafety:
|
|
def test_thread_safety_counter(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestHeartbeatPulsesWhenBackgroundActive:
|
|
def test_heartbeat_pulses(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestHeartbeatStopsWhenBackgroundDone:
|
|
def test_heartbeat_stops(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestHeartbeatIntervalConfigurable:
|
|
def test_interval_configurable(self):
|
|
pass
|
|
def test_interval_clamped(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestHeartbeatDisabledWhenPresenceOff:
|
|
def test_heartbeat_disabled(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestSetstatusTogglesPresence:
|
|
def test_setstatus_on(self):
|
|
pass
|
|
def test_setstatus_off(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestOnboardingAskActiveStatusIndikator:
|
|
def test_room_entry_has_active_status_field(self):
|
|
pass
|
|
def test_room_map_persists_active_status(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerStartStop:
|
|
def test_pulse_controller_start(self):
|
|
pass
|
|
def test_pulse_controller_stop_cleans_up(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerBindDdp:
|
|
def test_bind_ddp_sets_reference(self):
|
|
pass
|
|
def test_bind_ddp_after_start(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerDdpOnly:
|
|
def test_pulse_uses_ddp_not_rest(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerDdpOnlySend:
|
|
def test_ddp_only_send_no_message(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerRestFallback:
|
|
def test_rest_fallback_when_ddp_none(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerBothDefective:
|
|
def test_both_defective_no_crash(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerCoalesceSkip:
|
|
def test_coalesce_skip_duplicate_away(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerPhaseToggle:
|
|
def test_phase_toggles_correctly(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerLastSentPhase:
|
|
def test_last_sent_phase_updated(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestDetectionTimerPgrepPrimary:
|
|
def test_pgrep_finds_other_agents(self):
|
|
pass
|
|
def test_gateway_state_primary_active(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestDetectionTimerPgrepNoGatewayState:
|
|
def test_pgrep_works_without_gateway_state(self):
|
|
pass
|
|
def test_pgrep_returns_bool(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestDetectionTimerIntegration:
|
|
def test_detection_timer_start_stop(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestEdgeCaseOnConnectedRace:
|
|
def test_pulse_starts_before_ddp_available(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestEdgeCaseReconnectRace:
|
|
def test_reconnect_race_pause_resume(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestEdgeCaseOnAgentBusy:
|
|
def test_on_agent_busy_pauses_pulse(self):
|
|
pass
|
|
def test_on_agent_busy_resume_after_task(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestDetectionTimerOnChangeCallback:
|
|
def test_on_change_callback_fires_on_state_change(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPgrepArgvParsing:
|
|
def test_hermes_binary_in_argv(self):
|
|
pass
|
|
def test_hermes_binary_generic_path(self):
|
|
pass
|
|
def test_hermes_direct_binary(self):
|
|
pass
|
|
def test_hermes_py_script_still_works(self):
|
|
pass
|
|
def test_non_hermes_python_not_matched(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPulseControllerStartWithoutDdp:
|
|
def test_start_without_ddp_logs_warning(self):
|
|
pass
|
|
def test_start_without_ddp_no_crash(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPresenceClarificationPending:
|
|
def test_clarification_pending_sets_away(self):
|
|
pass
|
|
def test_clarification_pending_cleared(self):
|
|
pass
|
|
def test_clarification_pending_empty_after_clear_all(self):
|
|
pass
|
|
def test_clarification_priority_after_move_request(self):
|
|
pass
|
|
def test_clarification_priority_before_active_tasks(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestHoneymoonBusyMinVisible:
|
|
def test_busy_min_visible_duration(self):
|
|
pass
|
|
def test_busy_done_after_honeymoon(self):
|
|
pass
|
|
def test_double_busy_no_double_honeymoon(self):
|
|
pass
|
|
def test_active_tasks_balanced(self):
|
|
pass
|
|
def test_exception_during_dispatch_releases_busy(self):
|
|
pass
|
|
def test_status_send_order_busy_then_online(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPluginStateFile:
|
|
def test_get_plugin_state_path_default(self):
|
|
pass
|
|
def test_read_plugin_state_missing_file(self):
|
|
pass
|
|
def test_read_plugin_state_valid(self):
|
|
pass
|
|
def test_read_plugin_state_corrupt_json(self):
|
|
pass
|
|
def test_write_plugin_state_atomic(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestWritePluginStateConcurrency:
|
|
def test_concurrent_writes_produce_valid_json(self):
|
|
pass
|
|
def test_concurrent_writes_no_truncated_file(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestPluginStatePersistence:
|
|
def test_increment_writes_plugin_state(self):
|
|
pass
|
|
def test_decrement_writes_plugin_state(self):
|
|
pass
|
|
def test_decrement_to_zero_writes_zero(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestDetectionTimerPluginState:
|
|
def test_plugin_state_background_tasks_positive_detected(self):
|
|
pass
|
|
def test_plugin_state_background_tasks_zero_not_detected(self):
|
|
pass
|
|
def test_plugin_state_missing_file_no_error(self):
|
|
pass
|
|
def test_plugin_state_corrupt_json_no_crash(self):
|
|
pass
|
|
def test_plugin_state_priority_after_gateway(self):
|
|
pass
|
|
|
|
@pytest.mark.skip(reason="V8.x removed in V9")
|
|
class TestDetectionSourceTelemetry:
|
|
def test_detection_source_set_on_check_plugin_state(self):
|
|
pass
|
|
def test_detection_source_none_when_inactive(self):
|
|
pass
|
|
def test_detection_source_pgrep(self):
|
|
pass
|
|
def test_detection_source_gateway(self):
|
|
pass
|