mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
* refactor(types): prove runtime types at harness, search, rag and client boundaries Replace Any with adapter-validated types in the litellm.agent() harness, the search provider transformations, RAG ingestion and query, the vector store pre-call hook and registry, the galileo and opik logging integrations and the proxy client CLI. Each boundary gets unit tests for well-formed and malformed payloads. * chore(typing): prove types at more provider boundaries and restore search transformations Second pass over a2a, embedding, rerank, image, audio and small provider modules. Search transformations go back to their previous form because validating their response bodies would change the proxy status for malformed upstream bodies from 400 to 500. * refactor(types): prove types at logging, files, rerank, image, audio and management boundaries Replace Any with validated or annotation-only types in 37 more files: logging integrations, token counters, provider files/rerank/image generation/audio transcription transformations, pass-through logging handlers and management endpoints. No proxy HTTP status or error type changes. * refactor(types): prove types at repository, spend, files and router boundaries Replace Any with repository table accessors, validated mappings and annotation-only types in 33 more files: Prisma repositories, the enterprise batch and responses cost checkers, budget reservation, files endpoints, management endpoints, the policy registry, the adaptive and complexity routers and the secret managers. No proxy HTTP status or error type changes. * test(types): run the aiohttp transformation test in-process and cover repository row conversion The aiohttp chat transformation test no longer starts a server. It feeds the transformation a response whose json() returns the body under test. The proxy unit shards now exercise stored model rows whose params are JSON strings and the object permission create and update paths.
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""Unit tests for the native Opik integration's UUIDv7 id generation."""
|
|
|
|
import uuid
|
|
from datetime import datetime, timezone
|
|
from unittest.mock import patch
|
|
|
|
from litellm.integrations.opik.utils import create_uuid7, get_traces_and_spans_from_payload
|
|
|
|
|
|
def _timestamp_ms(uuid_str: str) -> int:
|
|
"""Return the unix-ms timestamp encoded in a UUIDv7's top 48 bits."""
|
|
return uuid.UUID(uuid_str).int >> 80
|
|
|
|
|
|
def test_create_uuid7_is_valid_version_7_uuid():
|
|
parsed = uuid.UUID(create_uuid7())
|
|
assert parsed.version == 7
|
|
assert parsed.variant == uuid.RFC_4122
|
|
|
|
|
|
def test_create_uuid7_encodes_timestamp_in_milliseconds():
|
|
fixed = datetime(2026, 6, 24, 10, 0, 0, tzinfo=timezone.utc)
|
|
|
|
with patch(
|
|
"litellm.integrations.opik.utils.time.time", return_value=fixed.timestamp()
|
|
):
|
|
value = create_uuid7()
|
|
|
|
assert _timestamp_ms(value) == int(fixed.timestamp() * 1000)
|
|
|
|
|
|
def test_queued_opik_payloads_are_split_into_traces_and_spans_without_their_null_fields():
|
|
traces, spans = get_traces_and_spans_from_payload(
|
|
[
|
|
{"id": "trace-1", "name": "chat.completion", "thread_id": None, "input": {"kept": None}},
|
|
{"id": "span-1", "type": "llm", "parent_span_id": None, "tags": [], "total_cost": 0},
|
|
{"id": "span-2", "type": None},
|
|
]
|
|
)
|
|
|
|
assert (traces, spans) == (
|
|
[{"id": "trace-1", "name": "chat.completion", "input": {"kept": None}}],
|
|
[{"id": "span-1", "type": "llm", "tags": [], "total_cost": 0}, {"id": "span-2"}],
|
|
)
|
|
|
|
|
|
def test_an_empty_opik_queue_has_no_traces_and_no_spans():
|
|
assert get_traces_and_spans_from_payload([]) == ([], [])
|