hermes-agent/tests/tools/test_checkpoint_footprint_notice.py
ethernet 6716b72ef2 refactor: separate checkpoint store maintenance from snapshots
Move retention, orphan pruning, status and clear operations into a topical sibling and route callers and tests directly to their defining module. Keep the shared store paths and git execution in checkpoint_manager; shorten the local child-env WHAT docstring.
2026-09-24 01:55:51 -04:00

39 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""``checkpoint_footprint_notice``: tells a user their /rollback store is on and large.
Checkpoints were on by default Mar–May 2026 and that ``enabled: true`` persisted into user
configs after the default flipped back, so a GB-scale store can sit under a feature the user
never invokes. The notice fires only when checkpoints are enabled AND the store is at/over
``max_total_size_mb``; it names the opt-out.
"""
import os
import hermes_yaml as yaml
from hermes_constants import get_hermes_home
from tools.checkpoint_manager import CheckpointManager
from tools.checkpoint_maintenance import checkpoint_footprint_notice
def _write_config(enabled: bool, cap_mb: int) -> None:
home = get_hermes_home()
home.mkdir(parents=True, exist_ok=True)
(home / "config.yaml").write_text(
yaml.safe_dump({"checkpoints": {"enabled": enabled, "max_total_size_mb": cap_mb}}), encoding="utf-8")
def test_notice_only_when_enabled_and_over_cap(tmp_path, monkeypatch):
base = get_hermes_home() / "checkpoints"
monkeypatch.setattr("tools.checkpoint_manager.CHECKPOINT_BASE", base)
work = tmp_path / "proj"
work.mkdir()
(work / "blob.bin").write_bytes(os.urandom(2 * 1024 * 1024)) # incompressible → store > 1 MB
_write_config(enabled=True, cap_mb=1)
assert CheckpointManager(enabled=True, max_total_size_mb=1).ensure_checkpoint(str(work), "seed")
notice = checkpoint_footprint_notice()
assert notice
_write_config(enabled=True, cap_mb=500) # under the cap: no nag for a healthy store
assert checkpoint_footprint_notice() is None
_write_config(enabled=False, cap_mb=1) # off: the store's size is irrelevant
assert checkpoint_footprint_notice() is None