Bring back sandbox VCR
This commit is contained in:
parent
81140e9d19
commit
0562809344
4 changed files with 210 additions and 21 deletions
|
|
@ -1,14 +1,21 @@
|
|||
import os
|
||||
from contextlib import AbstractContextManager
|
||||
from pathlib import Path
|
||||
|
||||
import docker
|
||||
import docker.errors
|
||||
import pytest
|
||||
import vcr
|
||||
import vcr.cassette
|
||||
from tests import json_body_serializer
|
||||
|
||||
from haiku.rag.agents.rlm.dependencies import RLMContext
|
||||
from haiku.rag.agents.rlm.docker_sandbox import DockerSandbox, SandboxResult
|
||||
from haiku.rag.client import HaikuRAG
|
||||
from haiku.rag.config.models import RLMConfig
|
||||
|
||||
CASSETTE_DIR = str(Path(__file__).parent.parent.parent / "cassettes" / "test_sandbox")
|
||||
|
||||
|
||||
def is_docker_available() -> bool:
|
||||
"""Check if Docker daemon is available."""
|
||||
|
|
@ -27,6 +34,19 @@ docker_required = pytest.mark.skipif(
|
|||
)
|
||||
|
||||
|
||||
def cassette(name: str) -> AbstractContextManager[vcr.cassette.Cassette]:
|
||||
"""VCR cassette scoped to embedding calls only (not docker-py)."""
|
||||
v = vcr.VCR()
|
||||
v.register_serializer("yaml", json_body_serializer)
|
||||
return v.use_cassette(
|
||||
f"{CASSETTE_DIR}/{name}.yaml",
|
||||
record_mode="none" if os.environ.get("CI") else "new_episodes",
|
||||
filter_headers=["authorization", "x-api-key"],
|
||||
ignore_hosts=["huggingface.co"],
|
||||
decode_compressed_response=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
class TestDockerSandboxBasics:
|
||||
"""Test basic Docker sandbox functionality."""
|
||||
|
|
@ -106,6 +126,7 @@ class TestDockerSandboxHaikuRAG:
|
|||
async def test_list_documents_with_data(self, temp_db_path, test_docker_image):
|
||||
"""Test list_documents returns documents when populated."""
|
||||
async with HaikuRAG(temp_db_path, create=True) as client:
|
||||
with cassette("test_list_documents_with_data"):
|
||||
await client.create_document(
|
||||
content="Test content",
|
||||
uri="test://doc1",
|
||||
|
|
@ -128,7 +149,7 @@ class TestDockerSandboxHaikuRAG:
|
|||
@pytest.mark.asyncio
|
||||
@pytest.mark.skipif(
|
||||
os.environ.get("CI") == "true",
|
||||
reason="Requires Ollama running inside Docker container",
|
||||
reason="Requires Ollama inside Docker container",
|
||||
)
|
||||
async def test_search_with_data(self, temp_db_path, test_docker_image):
|
||||
"""Test search function works."""
|
||||
|
|
@ -159,6 +180,7 @@ class TestDockerSandboxHaikuRAG:
|
|||
async def test_get_document(self, temp_db_path, test_docker_image):
|
||||
"""Test get_document function."""
|
||||
async with HaikuRAG(temp_db_path, create=True) as client:
|
||||
with cassette("test_get_document"):
|
||||
doc = await client.create_document(
|
||||
content="Content about foxes and dogs.",
|
||||
uri="test://doc",
|
||||
|
|
@ -199,6 +221,7 @@ class TestDockerSandboxContextFilter:
|
|||
):
|
||||
"""Test that context filter is passed to list_documents."""
|
||||
async with HaikuRAG(temp_db_path, create=True) as client:
|
||||
with cassette("test_filter_applied_to_list_documents"):
|
||||
await client.create_document(
|
||||
content="Public content",
|
||||
uri="public://doc1",
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
42
tests/cassettes/test_sandbox/test_get_document.yaml
Normal file
42
tests/cassettes/test_sandbox/test_get_document.yaml
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue