feat(p1-2): Plugin-State-Datei — atomare Hilfsfunktionen (_get_plugin_state_path, _read_plugin_state, _write_plugin_state)
This commit is contained in:
@@ -1777,3 +1777,59 @@ class TestHoneymoonBusyMinVisible:
|
||||
assert busy_idx < online_idx, (
|
||||
f"busy (idx={busy_idx}) muss vor online (idx={online_idx}) kommen: {statuses}"
|
||||
)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# P1-2: Plugin-State-Datei — Pfad, atomares Lesen/Schreiben
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
|
||||
class TestPluginStateFile:
|
||||
"""P1-2: Plugin-State-Datei — Pfad, atomares Lesen/Schreiben."""
|
||||
|
||||
def test_get_plugin_state_path_default(self):
|
||||
"""_get_plugin_state_path() liefert ~/.hermes/plugin_state/hermes_rocket_plugin.json."""
|
||||
from plugin.archivar.presence_engine import _get_plugin_state_path
|
||||
path = _get_plugin_state_path()
|
||||
assert path.endswith("hermes_rocket_plugin.json")
|
||||
assert ".hermes" in path
|
||||
assert "plugin_state" in path
|
||||
|
||||
def test_read_plugin_state_missing_file(self):
|
||||
"""_read_plugin_state() bei fehlender Datei → {}."""
|
||||
from plugin.archivar.presence_engine import _read_plugin_state
|
||||
result = _read_plugin_state("/tmp/nonexistent_plugin_state.json")
|
||||
assert result == {}
|
||||
|
||||
def test_read_plugin_state_valid(self, tmp_path):
|
||||
"""_read_plugin_state() liest gültige JSON-Datei."""
|
||||
from plugin.archivar.presence_engine import _read_plugin_state
|
||||
import json
|
||||
p = tmp_path / "state.json"
|
||||
p.write_text(json.dumps({"background_tasks": 3, "last_update_iso": "2026-01-01T00:00:00", "source": "plugin_internal", "schema_version": 1}))
|
||||
result = _read_plugin_state(str(p))
|
||||
assert result["background_tasks"] == 3
|
||||
assert result["source"] == "plugin_internal"
|
||||
|
||||
def test_read_plugin_state_corrupt_json(self, tmp_path):
|
||||
"""_read_plugin_state() bei korrupter JSON → {} (kein Crash)."""
|
||||
from plugin.archivar.presence_engine import _read_plugin_state
|
||||
p = tmp_path / "state.json"
|
||||
p.write_text("{invalid json")
|
||||
result = _read_plugin_state(str(p))
|
||||
assert result == {}
|
||||
|
||||
def test_write_plugin_state_atomic(self, tmp_path):
|
||||
"""_write_plugin_state() schreibt atomar (temp + rename)."""
|
||||
from plugin.archivar.presence_engine import _write_plugin_state, _read_plugin_state
|
||||
import json
|
||||
p = tmp_path / "state.json"
|
||||
data = {"background_tasks": 5, "last_update_iso": "2026-01-01T00:00:00", "source": "plugin_internal", "schema_version": 1}
|
||||
_write_plugin_state(str(p), data)
|
||||
# Datei existiert
|
||||
assert p.exists()
|
||||
# Inhalt korrekt
|
||||
result = _read_plugin_state(str(p))
|
||||
assert result["background_tasks"] == 5
|
||||
# Keine .tmp-Datei liegt rum
|
||||
assert not list(tmp_path.glob("*.tmp"))
|
||||
|
||||
Reference in New Issue
Block a user