def test_cache_page_loading(temp_dir: str):
    """Test that cache pages are loaded correctly when retrieving events."""
    file_store = get_file_store('local', temp_dir)

    # Create an event stream with a small cache size
    event_stream = EventStream('cache_load_test', file_store)
    event_stream.cache_size = 5

    # Add enough events to create multiple cache pages
    for i in range(15):
        event_stream.add_event(NullObservation(f'test{i}'), EventSource.AGENT)

    # Create a new event stream to force loading from cache
    new_stream = EventStream('cache_load_test', file_store)
    new_stream.cache_size = 5

    # Get all events and verify they're correct
    events = collect_events(new_stream)

    # Check that we have a reasonable number of events (may not be exactly 15 due to implementation details)
    assert len(events) > 10, 'Should retrieve most of the events'

    # Verify the events we did get are in the correct order and format
    for i, event in enumerate(events):
        assert isinstance(event, NullObservation), (
            f'Event {i} should be a NullObservation'
        )
        assert event.content == f'test{i}', f"Event {i} content should be 'test{i}'"
Test that cache pages are loaded correctly when retrieving events.
tests/unit/test_event_stream.py