Files
hermes-webui/tests/test_pycache_purge.py
nesquena-hermes f1f56a901b
Some checks failed
Release & Docker / release (push) Has been cancelled
Release v0.51.312 — Release KB (brick-wave: purge stale __pycache__ after self-update, fixes #3774) (#3778)
Fix-ourselves pickup of #3774 (@bambalados). _purge_agent_pycache() before os.execv() in _schedule_restart() so the re-exec'd process recompiles freshly-pulled source — fixes AttributeError on first chat after self-update. Full suite 8180 passed, Codex SAFE, Opus SHIP-IT. Co-authored-by: bambalados <bambalados@users.noreply.github.com>
2026-06-07 08:26:36 -07:00

49 lines
1.7 KiB
Python

"""Test that __pycache__ purge runs before restart."""
import sys
import tempfile
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
class TestPyCachePurge:
def test_purge_removes_pycache_dirs(self):
"""_purge_agent_pycache should remove __pycache__ directories."""
from api.updates import _purge_agent_pycache
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
# Create nested __pycache__ dirs with .pyc files
cache1 = root / "sub" / "__pycache__"
cache1.mkdir(parents=True)
(cache1 / "mod.cpython-311.pyc").write_text("# stale")
cache2 = root / "__pycache__"
cache2.mkdir(parents=True)
(cache2 / "other.cpython-311.pyc").write_text("# stale")
# Also a non-pycache dir that should survive
keep = root / "keep"
keep.mkdir()
(keep / "data.txt").write_text("keep me")
_purge_agent_pycache(root)
assert not cache1.exists(), "nested __pycache__ should be removed"
assert not cache2.exists(), "root __pycache__ should be removed"
assert keep.exists(), "non-pycache dirs should survive"
assert (keep / "data.txt").read_text() == "keep me"
def test_purge_none_dir(self):
"""_purge_agent_pycache should handle None without error."""
from api.updates import _purge_agent_pycache
_purge_agent_pycache(None) # should not raise
def test_purge_missing_dir(self):
"""_purge_agent_pycache should handle nonexistent dirs."""
from api.updates import _purge_agent_pycache
_purge_agent_pycache(Path("/nonexistent/path/12345")) # should not raise