File size: 1,724 Bytes
891fe52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Tests for checkpoint system."""
import pytest
from polyhedra.agent.checkpoint import CheckpointConfig, CheckpointManager, Checkpoint


@pytest.mark.asyncio
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


@pytest.mark.asyncio
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


@pytest.mark.asyncio
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"