mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-27 01:11:40 +00:00
feat(checkpoint): add pre-compression checkpoint flush hook
This commit is contained in:
parent
bd7fba2c52
commit
888d241ca2
2 changed files with 88 additions and 0 deletions
39
tests/test_checkpoint_flush.py
Normal file
39
tests/test_checkpoint_flush.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""Test that flush_checkpoint is called during context compression."""
|
||||
import json
|
||||
import pytest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
def test_flush_checkpoint_method_exists():
|
||||
"""AIAgent must have a flush_checkpoint method."""
|
||||
from run_agent import AIAgent
|
||||
assert hasattr(AIAgent, "flush_checkpoint")
|
||||
|
||||
|
||||
def test_flush_checkpoint_writes_to_store(tmp_path):
|
||||
"""flush_checkpoint should write a checkpoint with current session state."""
|
||||
from agent.checkpoint_store import CheckpointStore
|
||||
from tools.checkpoint_tool import checkpoint_tool
|
||||
store = CheckpointStore(checkpoints_dir=tmp_path / "checkpoints")
|
||||
|
||||
mock_agent = MagicMock()
|
||||
mock_agent.session_id = "flush_test_session"
|
||||
mock_agent._checkpoint_store = store
|
||||
mock_agent._todo_store = MagicMock()
|
||||
mock_agent._todo_store.format_for_injection.return_value = "- [x] Step 1"
|
||||
|
||||
# Verify the checkpoint tool writes successfully (same path flush_checkpoint uses)
|
||||
result = checkpoint_tool(
|
||||
action="write",
|
||||
task="Auto-checkpoint before compression",
|
||||
progress=[],
|
||||
state={},
|
||||
decisions=[],
|
||||
store=store,
|
||||
agent=mock_agent,
|
||||
)
|
||||
data = json.loads(result)
|
||||
assert data["success"] is True
|
||||
saved = store.read("flush_test_session")
|
||||
assert saved is not None
|
||||
assert saved["task"] == "Auto-checkpoint before compression"
|
||||
Loading…
Add table
Add a link
Reference in a new issue