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
158 lines
5.7 KiB
Python
158 lines
5.7 KiB
Python
from unittest import mock
|
|
|
|
from opik.api_objects.dataset import dataset_item
|
|
from opik.evaluation.resume import context, iteration
|
|
|
|
|
|
def _make_context(completed: dict = None, default: int = 1) -> context.ResumeContext:
|
|
return context.ResumeContext(
|
|
experiment=mock.Mock(),
|
|
dataset=mock.Mock(),
|
|
completed_runs_by_item_id=completed or {},
|
|
default_runs_per_item=default,
|
|
dataset_filter_string=None,
|
|
nb_samples=None,
|
|
candidate_dataset_item_ids=None,
|
|
)
|
|
|
|
|
|
class TestExpectedRunsForItem:
|
|
def test_item_without_execution_policy__uses_context_default(self):
|
|
ctx = _make_context(default=5)
|
|
item = dataset_item.DatasetItem(id="item-1")
|
|
|
|
assert iteration.expected_runs_for_item(ctx, item) == 5
|
|
|
|
def test_item_with_runs_per_item__overrides_default(self):
|
|
ctx = _make_context(default=2)
|
|
item = dataset_item.DatasetItem(
|
|
id="item-1",
|
|
execution_policy=dataset_item.ExecutionPolicyItem(runs_per_item=7),
|
|
)
|
|
|
|
assert iteration.expected_runs_for_item(ctx, item) == 7
|
|
|
|
def test_item_with_only_pass_threshold__falls_back_to_default(self):
|
|
ctx = _make_context(default=4)
|
|
item = dataset_item.DatasetItem(
|
|
id="item-1",
|
|
execution_policy=dataset_item.ExecutionPolicyItem(pass_threshold=1),
|
|
)
|
|
|
|
assert iteration.expected_runs_for_item(ctx, item) == 4
|
|
|
|
|
|
class TestRemainingRunsForItem:
|
|
def test_no_completed_runs__returns_full_count(self):
|
|
ctx = _make_context(completed={}, default=3)
|
|
item = dataset_item.DatasetItem(id="item-1")
|
|
|
|
assert iteration.remaining_runs_for_item(ctx, item) == 3
|
|
|
|
def test_partial_completion__replays_only_missing_runs(self):
|
|
"""Trials are independent: only the missing runs are replayed."""
|
|
ctx = _make_context(completed={"item-1": 1}, default=3)
|
|
item = dataset_item.DatasetItem(id="item-1")
|
|
|
|
assert iteration.remaining_runs_for_item(ctx, item) == 2
|
|
|
|
def test_fully_completed__returns_zero(self):
|
|
ctx = _make_context(completed={"item-1": 3}, default=3)
|
|
item = dataset_item.DatasetItem(id="item-1")
|
|
|
|
assert iteration.remaining_runs_for_item(ctx, item) == 0
|
|
|
|
def test_over_completed__returns_zero(self):
|
|
ctx = _make_context(completed={"item-1": 5}, default=3)
|
|
item = dataset_item.DatasetItem(id="item-1")
|
|
|
|
assert iteration.remaining_runs_for_item(ctx, item) == 0
|
|
|
|
def test_per_item_override__beats_default__only_missing_runs_replayed(self):
|
|
ctx = _make_context(completed={"item-1": 2}, default=10)
|
|
item = dataset_item.DatasetItem(
|
|
id="item-1",
|
|
execution_policy=dataset_item.ExecutionPolicyItem(runs_per_item=5),
|
|
)
|
|
|
|
# 2 of 5 done → only the 3 missing runs replay.
|
|
assert iteration.remaining_runs_for_item(ctx, item) == 3
|
|
|
|
def test_per_item_override__fully_completed_returns_zero(self):
|
|
ctx = _make_context(completed={"item-1": 5}, default=10)
|
|
item = dataset_item.DatasetItem(
|
|
id="item-1",
|
|
execution_policy=dataset_item.ExecutionPolicyItem(runs_per_item=5),
|
|
)
|
|
|
|
assert iteration.remaining_runs_for_item(ctx, item) == 0
|
|
|
|
|
|
class TestIsFullyCompleted:
|
|
def test_returns_true_when_completed_meets_expected(self):
|
|
ctx = _make_context(completed={"item-1": 3}, default=3)
|
|
item = dataset_item.DatasetItem(id="item-1")
|
|
|
|
assert iteration.is_fully_completed(ctx, item) is True
|
|
|
|
def test_returns_false_when_partial(self):
|
|
ctx = _make_context(completed={"item-1": 1}, default=3)
|
|
item = dataset_item.DatasetItem(id="item-1")
|
|
|
|
assert iteration.is_fully_completed(ctx, item) is False
|
|
|
|
def test_returns_false_when_pending(self):
|
|
ctx = _make_context(completed={}, default=3)
|
|
item = dataset_item.DatasetItem(id="item-1")
|
|
|
|
assert iteration.is_fully_completed(ctx, item) is False
|
|
|
|
|
|
class TestBuildPendingItemsIterator:
|
|
def test_skips_fully_completed_items_only(self):
|
|
ctx = _make_context(
|
|
completed={"done-1": 3, "partial-1": 1, "done-2": 3}, default=3
|
|
)
|
|
items = [
|
|
dataset_item.DatasetItem(id="done-1"),
|
|
dataset_item.DatasetItem(id="partial-1"),
|
|
dataset_item.DatasetItem(id="done-2"),
|
|
dataset_item.DatasetItem(id="fresh-1"),
|
|
]
|
|
|
|
pending = list(iteration.build_pending_items_iterator(iter(items), ctx))
|
|
|
|
assert [item.id for item in pending] == ["partial-1", "fresh-1"]
|
|
|
|
def test_sets_runs_per_item_to_missing_count(self):
|
|
"""Each item's ``runs_per_item`` is set to the count of missing runs."""
|
|
ctx = _make_context(completed={"partial-1": 1}, default=3)
|
|
items = [
|
|
dataset_item.DatasetItem(id="partial-1"),
|
|
dataset_item.DatasetItem(id="fresh-1"),
|
|
]
|
|
|
|
pending = list(iteration.build_pending_items_iterator(iter(items), ctx))
|
|
|
|
# partial-1 had 1 of 3 done → only 2 missing runs replay
|
|
assert pending[0].execution_policy.runs_per_item == 2
|
|
# fresh-1 had 0 of 3 done → all 3 run
|
|
assert pending[1].execution_policy.runs_per_item == 3
|
|
|
|
def test_preserves_existing_pass_threshold(self):
|
|
ctx = _make_context(completed={}, default=2)
|
|
items = [
|
|
dataset_item.DatasetItem(
|
|
id="item-1",
|
|
execution_policy=dataset_item.ExecutionPolicyItem(
|
|
runs_per_item=4,
|
|
pass_threshold=3,
|
|
),
|
|
),
|
|
]
|
|
|
|
pending = list(iteration.build_pending_items_iterator(iter(items), ctx))
|
|
|
|
assert pending[0].execution_policy.runs_per_item == 4
|
|
assert pending[0].execution_policy.pass_threshold == 3
|