1d31d2c372
- _determine_status() @staticmethod: subagent_active → AWAY (GELB) - _apply_counter_delta() auf 3-State umgebaut (ONLINE/BUSY/AWAY) - delegate_subagent, chat_profile, background_term → AWAY (GELB) - main_agent only → BUSY (ROT), sum=0 → ONLINE (GRÜN) - 10 neue GELB-Tests (TestGelbLogic) + bestehende Tests aktualisiert - 49 passed, 82 skipped (V8.x legacy)
940 lines
34 KiB
Python
940 lines
34 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"
|
|
|
|
|
|
# ═══════════════════════════════════════════════════════════════════════════
|
|
# 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
|