fix(terminal): cache cleanup keeps the max_age_hours kwarg the housekeeping loop calls
7fe77f29a7 renamed cleanup_terminal_temp_cache's kwarg to max_idle_hours;
gateway/run.py::_run_media_cache_cleanup calls every registered cleanup
as fn(max_age_hours=24), so the terminal sweep raised TypeError inside
housekeeping on every tick. The kwarg is the shared cleanup_*_cache
signature (bot_relay notes the same parity); the idle semantics stay.
A test binds the loop's call shape against every registered cleanup.
This commit is contained in:
24
tests/gateway/test_media_cache_cleanup_signature.py
Normal file
24
tests/gateway/test_media_cache_cleanup_signature.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Every cache cleanup the gateway housekeeping loop iterates accepts the loop's call shape.
|
||||
|
||||
The loop calls each entry as ``fn(max_age_hours=24)``; a cleanup renamed to another kwarg
|
||||
raised ``TypeError`` inside housekeeping on every tick (the terminal temp sweep did, once).
|
||||
"""
|
||||
import inspect
|
||||
|
||||
|
||||
def test_every_housekeeping_cache_cleanup_accepts_max_age_hours(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||
from tools.environments.local import cleanup_terminal_temp_cache
|
||||
from tools.bot_mode_dm import cleanup_bot_dm_cache
|
||||
from tools.bot_relay import cleanup_bot_relay_artifacts
|
||||
from tools.tool_result_storage import cleanup_spillover_cache
|
||||
from gateway.platforms.base import (
|
||||
cleanup_audio_cache, cleanup_document_cache, cleanup_image_cache,
|
||||
cleanup_screenshot_cache, cleanup_video_cache,
|
||||
)
|
||||
cleanups = (cleanup_image_cache, cleanup_document_cache, cleanup_audio_cache, cleanup_video_cache,
|
||||
cleanup_screenshot_cache, cleanup_spillover_cache, cleanup_terminal_temp_cache,
|
||||
cleanup_bot_dm_cache, cleanup_bot_relay_artifacts)
|
||||
for fn in cleanups:
|
||||
inspect.signature(fn).bind(max_age_hours=24)
|
||||
assert isinstance(fn(max_age_hours=24), int), fn.__name__
|
||||
@@ -114,7 +114,7 @@ def test_cleanup_terminal_temp_cache(tmp_path, monkeypatch):
|
||||
f.write_text("x")
|
||||
os.utime(f, (old, old))
|
||||
|
||||
removed = local_mod.cleanup_terminal_temp_cache(max_idle_hours=24)
|
||||
removed = local_mod.cleanup_terminal_temp_cache(max_age_hours=24)
|
||||
assert removed == 4 # stale snap + 3 dead-group files
|
||||
assert keep.exists()
|
||||
assert live_pid.exists() and live_log.exists()
|
||||
|
||||
@@ -58,16 +58,17 @@ def _default_terminal_temp_dir() -> "Path | None":
|
||||
return None
|
||||
|
||||
|
||||
def cleanup_terminal_temp_cache(max_idle_hours: float = TERMINAL_TEMP_MAX_IDLE_HOURS) -> int:
|
||||
"""Delete session temp artifacts idle for *max_idle_hours* (no write anywhere in a
|
||||
directory's subtree); return count.
|
||||
def cleanup_terminal_temp_cache(max_age_hours: float = TERMINAL_TEMP_MAX_IDLE_HOURS) -> int:
|
||||
"""Delete session temp artifacts idle for *max_age_hours* (no write anywhere in a
|
||||
directory's subtree; the kwarg name is the ``cleanup_*_cache`` signature the gateway
|
||||
housekeeping loop calls every entry with); return count.
|
||||
Only the managed default dir is pruned — never a user-pointed ``terminal.temp_dir``."""
|
||||
from hermes_constants_scratch import subtree_touched_since
|
||||
|
||||
root = _default_terminal_temp_dir()
|
||||
if root is None:
|
||||
return 0
|
||||
cutoff = time.time() - (max_idle_hours * 3600)
|
||||
cutoff = time.time() - (max_age_hours * 3600)
|
||||
try:
|
||||
entries = list(root.iterdir())
|
||||
except OSError:
|
||||
|
||||
Reference in New Issue
Block a user