fix(gateway): ensure deterministic thread eviction in helpers

This commit is contained in:
hharry11 2026-04-21 21:26:52 +03:00 committed by Teknium
parent 935cf2fcca
commit 247c9d468c
2 changed files with 25 additions and 6 deletions

View file

@ -67,6 +67,21 @@ class TestDiscordThreadPersistence:
saved = json.loads((tmp_path / "discord_threads.json").read_text())
assert len(saved) == 5
assert saved == ["5", "6", "7", "8", "9"]
def test_capacity_keeps_newest_thread_when_existing_state_is_full(self, tmp_path):
"""A newly joined thread must not be evicted by unordered set iteration."""
state_file = tmp_path / "discord_threads.json"
state_file.write_text(json.dumps(["0", "1", "2", "3", "4"]), encoding="utf-8")
adapter = self._make_adapter(tmp_path)
adapter._threads._max_tracked = 5
with patch.dict(os.environ, {"HERMES_HOME": str(tmp_path)}):
adapter._threads.mark("newest")
saved = json.loads(state_file.read_text(encoding="utf-8"))
assert saved == ["1", "2", "3", "4", "newest"]
assert "newest" in adapter._threads
def test_corrupted_state_file_falls_back_to_empty(self, tmp_path):
state_file = tmp_path / "discord_threads.json"