5a558eb09e
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
Lint Opik Helm Chart / render-equality (push) Has been cancelled
Opik Optimizer - Unit Tests / Opik Optimizer Unit Tests Python ${{matrix.python_version}} (push) Has been cancelled
Python BE E2E Tests / Python BE E2E (push) Has been cancelled
Python Backend Tests / run-python-backend-tests (push) Has been cancelled
Python SDK Unit Tests / Python SDK Unit Tests ${{matrix.python_version}} (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
SDK E2E Libraries Integration Tests / Check Secrets (push) Has been cancelled
SDK E2E Libraries Integration Tests / Missed OpenAI API Key Warning (push) Has been cancelled
SDK E2E Libraries Integration Tests / build-opik (push) Has been cancelled
SDK E2E Libraries Integration Tests / E2E Lib Integration Python ${{matrix.python_version}} (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-gemini) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-langchain) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-openai) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-otel) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-vercel) (push) Has been cancelled
TypeScript SDK Build & Publish / build-and-publish (push) Has been cancelled
TypeScript SDK Unit Tests / Test on Node ${{ matrix.node-version }} (push) Has been cancelled
Backend Tests / discover-tests (push) Has been cancelled
Backend Tests / ${{ matrix.name }} (push) Has been cancelled
Build and Publish SDK / build-and-publish (push) Has been cancelled
Build Opik Docker Images / set-version (push) Has been cancelled
Build Opik Docker Images / build-backend (push) Has been cancelled
Build Opik Docker Images / build-sandbox-executor-python (push) Has been cancelled
Build Opik Docker Images / build-python-backend (push) Has been cancelled
Build Opik Docker Images / build-frontend (push) Has been cancelled
Build Opik Docker Images / create-git-tag (push) Has been cancelled
ClickHouse Migration Cluster Check / validate-clickhouse-migrations (push) Has been cancelled
Docs - Publish / run (push) Has been cancelled
E2E Tests - Post Merge (v2) / 🧪 E2E v2 Tests (${{ github.event.inputs.tier || 't1' }}) (push) Has been cancelled
E2E Tests - Post Merge (v2) / 📢 Slack Notification (push) Has been cancelled
Frontend Unit Tests / Test on Node 20 (push) Has been cancelled
Guardrails E2E Tests / Select Python version matrix (push) Has been cancelled
Guardrails E2E Tests / Guardrails E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Guardrails E2E Tests / 📢 Slack Notification (push) Has been cancelled
Guardrails Backend Unit Tests / Guardrails Backend Unit Tests (push) Has been cancelled
Guardrails Backend Unit Tests / 📢 Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v3.21.0) (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v4.2.0) (push) Has been cancelled
Lint Opik Helm Chart / unittest-helm-chart (push) Has been cancelled
170 lines
6.0 KiB
Python
170 lines
6.0 KiB
Python
from unittest import mock
|
|
|
|
import pytest
|
|
|
|
from opik import exceptions
|
|
from opik.api_objects.dashboard import types, validation
|
|
|
|
|
|
def _section(section_id, widgets, layout_ids):
|
|
return {
|
|
"id": section_id,
|
|
"title": "t",
|
|
"widgets": [{"id": w, "type": "text_markdown", "config": {}} for w in widgets],
|
|
"layout": [{"i": i, "x": 0, "y": 0, "w": 1, "h": 1} for i in layout_ids],
|
|
}
|
|
|
|
|
|
def test_validate_structure__valid_passes():
|
|
state = {"version": 4, "sections": [_section("s1", ["w1"], ["w1"])]}
|
|
validation.validate_structure(state)
|
|
|
|
|
|
def test_validate_structure__widget_without_layout_raises():
|
|
state = {"version": 4, "sections": [_section("s1", ["w1"], [])]}
|
|
with pytest.raises(exceptions.DashboardValidationError, match="without a layout"):
|
|
validation.validate_structure(state)
|
|
|
|
|
|
def test_validate_structure__orphan_layout_item_raises():
|
|
state = {"version": 4, "sections": [_section("s1", [], ["ghost"])]}
|
|
with pytest.raises(exceptions.DashboardValidationError, match="missing widgets"):
|
|
validation.validate_structure(state)
|
|
|
|
|
|
def test_validate_structure__duplicate_widget_ids_across_sections_raises():
|
|
state = {
|
|
"version": 4,
|
|
"sections": [
|
|
_section("s1", ["dup"], ["dup"]),
|
|
_section("s2", ["dup"], ["dup"]),
|
|
],
|
|
}
|
|
with pytest.raises(exceptions.DashboardValidationError, match="Duplicate widget"):
|
|
validation.validate_structure(state)
|
|
|
|
|
|
def test_validate_structure__duplicate_section_ids_raises():
|
|
state = {
|
|
"version": 4,
|
|
"sections": [_section("s1", ["w1"], ["w1"]), _section("s1", ["w2"], ["w2"])],
|
|
}
|
|
with pytest.raises(exceptions.DashboardValidationError, match="Duplicate section"):
|
|
validation.validate_structure(state)
|
|
|
|
|
|
def test_validate_widget_for_dashboard__incompatible_type_raises():
|
|
widget = {"type": "experiment_leaderboard", "config": {}}
|
|
with pytest.raises(exceptions.DashboardValidationError, match="not supported"):
|
|
validation.validate_widget_for_dashboard(widget, "multi_project")
|
|
|
|
|
|
def test_validate_widget_for_dashboard__compatible_type_ok():
|
|
widget = {"type": "project_metrics", "config": {"metricType": "TRACE_COUNT"}}
|
|
validation.validate_widget_for_dashboard(widget, "multi_project")
|
|
|
|
|
|
def test_validate_widget_for_dashboard__no_dashboard_type_skips_compatibility():
|
|
widget = {"type": "experiment_leaderboard", "config": {}}
|
|
validation.validate_widget_for_dashboard(widget, None)
|
|
|
|
|
|
def test_validate_widget_for_dashboard__unknown_metric_warns_not_raises():
|
|
widget = {"type": "project_metrics", "config": {"metricType": "not_a_metric"}}
|
|
with mock.patch.object(validation.LOGGER, "warning") as mock_warning:
|
|
validation.validate_widget_for_dashboard(widget, "multi_project")
|
|
mock_warning.assert_called_once()
|
|
assert "Unknown project_metrics metricType" in mock_warning.call_args[0][0]
|
|
|
|
|
|
def test_validate_widget_for_dashboard__dynamic_feedback_metric_no_warning():
|
|
widget = {
|
|
"type": "project_stats_card",
|
|
"config": {"metric": "feedback_scores.helpfulness"},
|
|
}
|
|
with mock.patch.object(validation.LOGGER, "warning") as mock_warning:
|
|
validation.validate_widget_for_dashboard(widget, "multi_project")
|
|
mock_warning.assert_not_called()
|
|
|
|
|
|
def test_validate_writable_version__known_version_ok():
|
|
validation.validate_writable_version(4)
|
|
validation.validate_writable_version(None)
|
|
|
|
|
|
def test_validate_writable_version__unknown_version_raises():
|
|
with pytest.raises(exceptions.DashboardValidationError, match="schema version 5"):
|
|
validation.validate_writable_version(5)
|
|
|
|
|
|
def test_as_widget_dict__from_model__returns_jsonable():
|
|
widget = types.DashboardWidget(
|
|
id="w1", type=types.WidgetType.TEXT_MARKDOWN, config=types.TextMarkdownConfig()
|
|
)
|
|
result = validation.as_widget_dict(widget)
|
|
assert result["id"] == "w1"
|
|
assert result["type"] == "text_markdown"
|
|
|
|
|
|
def test_as_widget_dict__from_dict__returns_same_dict():
|
|
d = {"id": "w1", "type": "text_markdown", "config": {}}
|
|
result = validation.as_widget_dict(d)
|
|
assert result is d
|
|
|
|
|
|
def test_as_widget_dict__invalid_type__raises():
|
|
with pytest.raises(
|
|
exceptions.DashboardValidationError, match="Expected a DashboardWidget"
|
|
):
|
|
validation.as_widget_dict(42)
|
|
|
|
|
|
def test_as_section_dicts__from_models__returns_jsonable():
|
|
section = types.DashboardSection(title="S1")
|
|
result = validation.as_section_dicts([section])
|
|
assert len(result) == 1
|
|
assert result[0]["title"] == "S1"
|
|
assert "id" in result[0]
|
|
|
|
|
|
def test_as_section_dicts__from_dicts__returns_same_dicts():
|
|
d = {"id": "s1", "title": "S1", "widgets": [], "layout": []}
|
|
result = validation.as_section_dicts([d])
|
|
assert result[0] is d
|
|
|
|
|
|
def test_as_section_dicts__invalid_type__raises():
|
|
with pytest.raises(
|
|
exceptions.DashboardValidationError, match="Expected a DashboardSection"
|
|
):
|
|
validation.as_section_dicts(["not-a-section"])
|
|
|
|
|
|
def test_inject_project_id__project_scoped_widget_injects():
|
|
widget = {"type": "project_stats_card", "config": {"metric": "trace_count"}}
|
|
validation.inject_project_id(widget, "proj-123")
|
|
assert widget["config"]["projectId"] == "proj-123"
|
|
|
|
|
|
def test_inject_project_id__project_metrics_injects():
|
|
widget = {"type": "project_metrics", "config": {"metricType": "DURATION"}}
|
|
validation.inject_project_id(widget, "proj-abc")
|
|
assert widget["config"]["projectId"] == "proj-abc"
|
|
|
|
|
|
def test_inject_project_id__non_project_widget_untouched():
|
|
widget = {"type": "text_markdown", "config": {"content": "hi"}}
|
|
validation.inject_project_id(widget, "proj-123")
|
|
assert "projectId" not in widget["config"]
|
|
|
|
|
|
def test_inject_project_id__no_project_id_raises():
|
|
widget = {"type": "project_stats_card", "config": {}}
|
|
with pytest.raises(exceptions.DashboardValidationError, match="project-scoped"):
|
|
validation.inject_project_id(widget, None)
|
|
|
|
|
|
def test_inject_project_id__no_project_id_for_non_project_widget_ok():
|
|
widget = {"type": "text_markdown", "config": {}}
|
|
validation.inject_project_id(widget, None)
|