feat(p1-2): increment/decrement_background_tasks persistieren in Plugin-State-Datei
This commit is contained in:
@@ -1833,3 +1833,79 @@ class TestPluginStateFile:
|
||||
assert result["background_tasks"] == 5
|
||||
# Keine .tmp-Datei liegt rum
|
||||
assert not list(tmp_path.glob("*.tmp"))
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# P1-2: Plugin-State Persistenz in increment/decrement_background_tasks
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
|
||||
class TestPluginStatePersistence:
|
||||
"""P1-2: increment/decrement_background_tasks persistieren in Plugin-State-Datei."""
|
||||
|
||||
def test_increment_writes_plugin_state(self, tmp_path):
|
||||
"""increment_background_tasks() schreibt background_tasks in Plugin-State-Datei."""
|
||||
from plugin.archivar.presence_engine import PresenceEngine, _read_plugin_state
|
||||
|
||||
state_path = str(tmp_path / "hermes_rocket_plugin.json")
|
||||
os.makedirs(os.path.dirname(state_path), exist_ok=True)
|
||||
|
||||
mock_rest = MagicMock()
|
||||
mock_rest.auth_token = "token"
|
||||
mock_rest.user_id = "user123"
|
||||
|
||||
engine = PresenceEngine(rest=mock_rest, enabled=True)
|
||||
# Override path for test
|
||||
engine._plugin_state_path = state_path
|
||||
|
||||
count = engine.increment_background_tasks()
|
||||
assert count == 1
|
||||
|
||||
# Read back from file
|
||||
state = _read_plugin_state(state_path)
|
||||
assert state["background_tasks"] == 1
|
||||
assert state["source"] == "plugin_internal"
|
||||
assert "last_update_iso" in state
|
||||
|
||||
def test_decrement_writes_plugin_state(self, tmp_path):
|
||||
"""decrement_background_tasks() schreibt reduzierten Wert in Plugin-State-Datei."""
|
||||
from plugin.archivar.presence_engine import PresenceEngine, _read_plugin_state
|
||||
|
||||
state_path = str(tmp_path / "hermes_rocket_plugin.json")
|
||||
os.makedirs(os.path.dirname(state_path), exist_ok=True)
|
||||
|
||||
mock_rest = MagicMock()
|
||||
mock_rest.auth_token = "token"
|
||||
mock_rest.user_id = "user123"
|
||||
|
||||
engine = PresenceEngine(rest=mock_rest, enabled=True)
|
||||
engine._plugin_state_path = state_path
|
||||
|
||||
engine.increment_background_tasks()
|
||||
engine.increment_background_tasks()
|
||||
count = engine.decrement_background_tasks()
|
||||
assert count == 1
|
||||
|
||||
state = _read_plugin_state(state_path)
|
||||
assert state["background_tasks"] == 1
|
||||
|
||||
def test_decrement_to_zero_writes_zero(self, tmp_path):
|
||||
"""decrement auf 0 schreibt background_tasks=0 in Datei."""
|
||||
from plugin.archivar.presence_engine import PresenceEngine, _read_plugin_state
|
||||
|
||||
state_path = str(tmp_path / "hermes_rocket_plugin.json")
|
||||
os.makedirs(os.path.dirname(state_path), exist_ok=True)
|
||||
|
||||
mock_rest = MagicMock()
|
||||
mock_rest.auth_token = "token"
|
||||
mock_rest.user_id = "user123"
|
||||
|
||||
engine = PresenceEngine(rest=mock_rest, enabled=True)
|
||||
engine._plugin_state_path = state_path
|
||||
|
||||
engine.increment_background_tasks()
|
||||
count = engine.decrement_background_tasks()
|
||||
assert count == 0
|
||||
|
||||
state = _read_plugin_state(state_path)
|
||||
assert state["background_tasks"] == 0
|
||||
|
||||
Reference in New Issue
Block a user