Files
wehub-resource-sync 5a558eb09e
Backend Tests / discover-tests (push) Waiting to run
Backend Tests / ${{ matrix.name }} (push) Blocked by required conditions
Build and Publish SDK / build-and-publish (push) Waiting to run
Build Opik Docker Images / set-version (push) Waiting to run
Build Opik Docker Images / build-backend (push) Blocked by required conditions
Build Opik Docker Images / build-sandbox-executor-python (push) Blocked by required conditions
Build Opik Docker Images / build-python-backend (push) Blocked by required conditions
Build Opik Docker Images / build-frontend (push) Blocked by required conditions
Build Opik Docker Images / create-git-tag (push) Blocked by required conditions
ClickHouse Migration Cluster Check / validate-clickhouse-migrations (push) Waiting to run
Docs - Publish / run (push) Waiting to run
E2E Tests - Post Merge (v2) / 🧪 E2E v2 Tests (${{ github.event.inputs.tier || 't1' }}) (push) Waiting to run
E2E Tests - Post Merge (v2) / 📢 Slack Notification (push) Blocked by required conditions
Frontend Unit Tests / Test on Node 20 (push) Waiting to run
Guardrails E2E Tests / Select Python version matrix (push) Waiting to run
Guardrails E2E Tests / Guardrails E2E Tests ${{matrix.python_version}} (push) Blocked by required conditions
Guardrails E2E Tests / 📢 Slack Notification (push) Blocked by required conditions
Guardrails Backend Unit Tests / Guardrails Backend Unit Tests (push) Waiting to run
Guardrails Backend Unit Tests / 📢 Slack Notification (push) Blocked by required conditions
Lint Opik Helm Chart / lint-helm-chart (Helm v3.21.0) (push) Waiting to run
Lint Opik Helm Chart / lint-helm-chart (Helm v4.2.0) (push) Waiting to run
Lint Opik Helm Chart / unittest-helm-chart (push) Waiting to run
Lint Opik Helm Chart / render-equality (push) Waiting to run
Opik Optimizer - Unit Tests / Opik Optimizer Unit Tests Python ${{matrix.python_version}} (push) Waiting to run
Python BE E2E Tests / Python BE E2E (push) Waiting to run
Python Backend Tests / run-python-backend-tests (push) Waiting to run
Python SDK Unit Tests / Python SDK Unit Tests ${{matrix.python_version}} (push) Waiting to run
Release Drafter / update_release_draft (push) Waiting to run
SDK E2E Libraries Integration Tests / Check Secrets (push) Waiting to run
SDK E2E Libraries Integration Tests / Missed OpenAI API Key Warning (push) Blocked by required conditions
SDK E2E Libraries Integration Tests / build-opik (push) Blocked by required conditions
SDK E2E Libraries Integration Tests / E2E Lib Integration Python ${{matrix.python_version}} (push) Blocked by required conditions
TypeScript SDK Integration Build & Publish / build-and-publish (opik-gemini) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-langchain) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-openai) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-otel) (push) Waiting to run
TypeScript SDK Integration Build & Publish / build-and-publish (opik-vercel) (push) Waiting to run
TypeScript SDK Build & Publish / build-and-publish (push) Waiting to run
TypeScript SDK Unit Tests / Test on Node ${{ matrix.node-version }} (push) Waiting to run
TypeScript SDK Compatibility V1.x E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / TypeScript SDK Compatibility V1.x E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
TypeScript SDK E2E Tests / TypeScript SDK E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
Python SDK E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK E2E Tests / Python SDK E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK E2E Tests / build-opik (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Python SDK Compatibility V1.x E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK E2E Tests / build-opik (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer E2E Tests Python ${{matrix.python_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer Integration Smoke Tests (push) Has been cancelled
🐙 Code Quality / detect (push) Has been cancelled
🐙 Code Quality / lint (${{ matrix.leg.name }}) (push) Has been cancelled
🐙 Code Quality / summary (push) Has been cancelled
TypeScript SDK Library Integration Tests / Check Secrets (push) Has been cancelled
TypeScript SDK Library Integration Tests / opik-vercel (Vercel AI SDK / eve) (push) Has been cancelled
SDK Library Integration Tests Runner / Check Secrets (push) Has been cancelled
SDK Library Integration Tests Runner / Missed OpenAI API Key Warning (push) Has been cancelled
SDK Library Integration Tests Runner / Build (push) Has been cancelled
SDK Library Integration Tests Runner / openai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_legacy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / llama_index_tests (push) Has been cancelled
SDK Library Integration Tests Runner / anthropic_tests (push) Has been cancelled
SDK Library Integration Tests Runner / mistral_tests (push) Has been cancelled
SDK Library Integration Tests Runner / groq_tests (push) Has been cancelled
SDK Library Integration Tests Runner / aisuite_tests (push) Has been cancelled
SDK Library Integration Tests Runner / haystack_tests (push) Has been cancelled
SDK Library Integration Tests Runner / dspy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v1_tests (push) Has been cancelled
SDK Library Integration Tests Runner / genai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_legacy_1_3_0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / evaluation_metrics_tests (push) Has been cancelled
SDK Library Integration Tests Runner / bedrock_tests (push) Has been cancelled
SDK Library Integration Tests Runner / litellm_tests (push) Has been cancelled
SDK Library Integration Tests Runner / harbor_tests (push) Has been cancelled
SDK Library Integration Tests Runner / Slack Notification (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:25:44 +08:00

203 lines
7.4 KiB
Python

"""Integration tests for simulation functionality."""
from unittest.mock import Mock, patch
from opik.simulation import SimulatedUser, run_simulation
class TestSimulationIntegration:
"""Integration tests for simulation functionality."""
def test_simulation_with_class_based_app(self):
"""Test simulation with a class-based app that manages state."""
class WeatherAgent:
def __init__(self):
self.histories = {}
def __call__(self, message, *, thread_id, **kwargs):
# Initialize history for this thread
if thread_id not in self.histories:
self.histories[thread_id] = []
# Add user message to history
self.histories[thread_id].append(message)
# Generate response based on full history
response_content = f"Response to turn {len(self.histories[thread_id])}"
assistant_message = {"role": "assistant", "content": response_content}
# Add to history
self.histories[thread_id].append(assistant_message)
return assistant_message
agent = WeatherAgent()
user_simulator = SimulatedUser(
persona="You are curious about weather",
fixed_responses=["What's the weather?", "Tell me more", "Thanks!"],
)
result = run_simulation(app=agent, user_simulator=user_simulator, max_turns=3)
# Verify conversation structure
history = result["conversation_history"]
assert len(history) == 6 # 3 turns * 2 messages
# Verify agent maintained state
assert len(agent.histories[result["thread_id"]]) == 6
# Verify responses reference turn numbers
assert "Response to turn 1" in history[1]["content"]
assert "Response to turn 3" in history[3]["content"]
assert "Response to turn 5" in history[5]["content"]
def test_simulation_with_multiple_threads(self):
"""Test that different thread_ids maintain separate state."""
class StatefulAgent:
def __init__(self):
self.histories = {}
def __call__(self, message, *, thread_id, **kwargs):
if thread_id not in self.histories:
self.histories[thread_id] = []
self.histories[thread_id].append(message)
response = {
"role": "assistant",
"content": f"Thread {thread_id} turn {len(self.histories[thread_id])}",
}
self.histories[thread_id].append(response)
return response
agent = StatefulAgent()
user_simulator = SimulatedUser(persona="Test user", fixed_responses=["Message"])
# Run first simulation
result1 = run_simulation(
app=agent, user_simulator=user_simulator, thread_id="thread-1", max_turns=2
)
# Run second simulation with different thread
result2 = run_simulation(
app=agent, user_simulator=user_simulator, thread_id="thread-2", max_turns=2
)
# Verify separate state
assert result1["thread_id"] == "thread-1"
assert result2["thread_id"] == "thread-2"
assert len(agent.histories["thread-1"]) == 4
assert len(agent.histories["thread-2"]) == 4
# Verify responses reference correct threads
assert "Thread thread-1 turn 1" in result1["conversation_history"][1]["content"]
assert "Thread thread-2 turn 1" in result2["conversation_history"][1]["content"]
@patch("opik.simulation.simulated_user.OpikBaseModel")
def test_simulation_with_llm_user(self, mock_base_model):
"""Test simulation with LLM-based user simulator."""
# Mock LLM responses
mock_llm_instance = Mock()
mock_llm_instance.generate.side_effect = [
"What's the weather like?",
"That's interesting, tell me more",
"Thank you for the information",
]
mock_base_model.return_value = mock_llm_instance
def mock_app(message, *, thread_id, **kwargs):
return {"role": "assistant", "content": f"Assistant: {message['content']}"}
user_simulator = SimulatedUser(
persona="You are curious about weather", model="gpt-4o-mini"
)
user_simulator._llm = mock_llm_instance
result = run_simulation(
app=mock_app, user_simulator=user_simulator, max_turns=3
)
# Verify LLM was called for each user message
assert mock_llm_instance.generate.call_count == 3
# Verify conversation structure
history = result["conversation_history"]
assert "What's the weather like?" in history[0]["content"]
assert "Assistant: What's the weather like?" in history[1]["content"]
assert "That's interesting, tell me more" in history[2]["content"]
def test_simulation_error_recovery(self):
"""Test simulation continues after app errors."""
call_count = 0
def error_prone_app(message, *, thread_id, **kwargs):
nonlocal call_count
call_count += 1
if call_count == 2: # Fail on second call
raise Exception("Temporary error")
return {"role": "assistant", "content": f"Success {call_count}"}
user_simulator = SimulatedUser(
persona="Test user", fixed_responses=["Message 1", "Message 2", "Message 3"]
)
result = run_simulation(
app=error_prone_app, user_simulator=user_simulator, max_turns=3
)
history = result["conversation_history"]
# First turn should succeed
assert "Success 1" in history[1]["content"]
# Second turn should have error message
assert "Error processing message: Temporary error" in history[3]["content"]
# Third turn should succeed again
assert "Success 3" in history[5]["content"]
def test_simulation_with_complex_app_kwargs(self):
"""Test simulation with complex app configuration."""
class ConfigurableAgent:
def __init__(self):
self.config = {}
self.histories = {}
def __call__(
self, message, *, thread_id, model=None, temperature=None, **kwargs
):
# Store configuration
self.config[thread_id] = {
"model": model,
"temperature": temperature,
"other_kwargs": kwargs,
}
# Manage history
if thread_id not in self.histories:
self.histories[thread_id] = []
self.histories[thread_id].append(message)
response = {"role": "assistant", "content": "Configured response"}
self.histories[thread_id].append(response)
return response
agent = ConfigurableAgent()
user_simulator = SimulatedUser(persona="Test user", fixed_responses=["Message"])
result = run_simulation(
app=agent,
user_simulator=user_simulator,
model="gpt-4",
temperature=0.7,
custom_param="test",
max_turns=1,
)
# Verify configuration was stored
config = agent.config[result["thread_id"]]
assert config["model"] == "gpt-4"
assert config["temperature"] == 0.7
assert config["other_kwargs"]["custom_param"] == "test"