Download tests/test_agent/test_checkpoint.py from polyHedra/PolyHedra: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/polyHedra/PolyHedra/resolve/main/tests/test_agent/test_checkpoint.py
- Command line
-
hf download hf://spaces/polyHedra/PolyHedra/tests/test_agent/test_checkpoint.py
-
curl -L -o test_checkpoint.py https://huggingface.co/spaces/polyHedra/PolyHedra/resolve/main/tests/test_agent/test_checkpoint.py
1.72 kB
| """Tests for checkpoint system.""" | |
| import pytest | |
| from polyhedra.agent.checkpoint import CheckpointConfig, CheckpointManager, Checkpoint | |
| async def test_checkpoint_auto_approve_small_cost(): | |
| """Test auto-approval for small costs.""" | |
| config = CheckpointConfig(auto_approve_below=0.10) | |
| manager = CheckpointManager(config) | |
| checkpoint = Checkpoint( | |
| step_name="test", | |
| operation="test_op", | |
| estimated_cost=0.05, | |
| rationale="Small cost" | |
| ) | |
| approved = await manager.request_approval(checkpoint) | |
| assert approved | |
| assert checkpoint.auto_approved | |
| async def test_checkpoint_requires_approval_large_cost(): | |
| """Test approval required for large costs.""" | |
| config = CheckpointConfig(cost_threshold=0.50) | |
| manager = CheckpointManager(config) | |
| # In development mode, auto-approves | |
| checkpoint = Checkpoint( | |
| step_name="test", | |
| operation="test_op", | |
| estimated_cost=1.00, | |
| rationale="Large cost" | |
| ) | |
| approved = await manager.request_approval(checkpoint) | |
| assert approved # Auto-approved in dev mode | |
| async def test_checkpoint_history(): | |
| """Test checkpoint history tracking.""" | |
| config = CheckpointConfig() | |
| manager = CheckpointManager(config) | |
| checkpoint1 = Checkpoint("step1", "op1", 0.05, "test") | |
| checkpoint2 = Checkpoint("step2", "op2", 0.15, "test") | |
| await manager.request_approval(checkpoint1) | |
| await manager.request_approval(checkpoint2) | |
| history = manager.get_checkpoint_history() | |
| assert len(history) == 2 | |
| assert history[0].step_name == "step1" | |
| assert history[1].step_name == "step2" | |