Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tests/cross/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
"""Shared fixtures for cross package tests."""

import json
from collections.abc import AsyncIterator, Callable, Iterator
from pathlib import Path

import pytest

from openhands.agent_server.conversation_service import ConversationService
from openhands.agent_server.persistence import reset_stores
from openhands.sdk import Agent
from openhands.sdk.conversation.request import StartConversationRequest
from openhands.sdk.testing import TestLLM
from openhands.sdk.utils.cipher import Cipher
from openhands.sdk.workspace import LocalWorkspace


@pytest.fixture
def ownership_cipher() -> Cipher:
return Cipher("conversation-state-ownership-test-key")


@pytest.fixture
def ownership_request(tmp_path: Path) -> StartConversationRequest:
return StartConversationRequest(
agent=Agent(
llm=TestLLM(model="openai/gpt-4o", usage_id="ownership-actor"),
tools=[],
),
workspace=LocalWorkspace(working_dir=str(tmp_path / "workspace")),
autotitle=False,
)


@pytest.fixture
def ownership_service_factory(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, ownership_cipher: Cipher
) -> Iterator[Callable[[], ConversationService]]:
monkeypatch.setenv("OH_PERSISTENCE_DIR", str(tmp_path / "settings"))
reset_stores()

def create_service() -> ConversationService:
return ConversationService(
conversations_dir=tmp_path / "conversations",
cipher=ownership_cipher,
lease_ttl_seconds=0,
)

try:
yield create_service
finally:
reset_stores()


@pytest.fixture
async def ownership_service(
ownership_service_factory: Callable[[], ConversationService],
) -> AsyncIterator[ConversationService]:
async with ownership_service_factory() as service:
yield service


@pytest.fixture
def llm_fixtures_dir():
Expand Down
Loading
Loading