litellm/tests/unit/tracing/test_receiver.py
moe-berri 22ad3c5fff
refactor(lens): connect LiteLLM to the independent Lens service (#45529)
* feat(lens): consume the independent Lens service and shared UI

* fix(lens): keep embedded setup stable and vendor UI before builds

* chore(lens): pin embedded UI provenance to published Lens source

* fix(lens): complete embedded UI extraction across CI builds

* docs(lens): record latest main and removal-boundary validation

* fix(lens): wire external chart credentials and ingestion modes

* test(lens): cover adapter failures and fix extraction CI

* docs(lens): refresh bundled chart setup instructions

* test(lens): restore gateway adapter test package marker

* build(lens): pin clean-cut UI and supported storage chart

* test(ui): await guardrail scope menu before checking options

* perf(lens): omit unused trace-team lookup from product requests

* docs(lens): record final-image adapter permission checks

* test(lens): assert delegated investigation authorization

* refactor(lens): remove copied trace runtime and preserve spend logging

* test(lens): verify independent gateway image upgrades and outages

* test(lens): pin the chart qualification database image

* fix(lens): update embedded UI metadata filters

* test: wait for Lens chart pod identity convergence

* fix(e2e): select Lens chart pods by deployment ownership

* fix(e2e): select Helm migration ownership for Lens upgrades

* test(lens): retain migration Jobs through rollout assertions

* docs(helm): require existing database for migration hooks

* test(lens): qualify release boundaries with embedded navigation update

* docs(lens): record browser qualification for embedded tabs

* fix(lens): remove unrelated CI and guardrail test changes

* test(lens): give qualification tenants unique key aliases

* feat(lens): embed the latest canonical Lens interface

* fix(lens): qualify split inference through the gateway

* fix(lens): preserve scoped auth and isolate delegated credentials

* chore(lens): remove unrelated documentation and lint changes

* fix(lens): bound concurrent forwarding buffers through response delivery

* fix(lens): preserve OAuth2 dispatch without inference policies

* chore(lens): adopt current shared onboarding UI

* fix(lens): refresh shared setup UI and review context

* fix(lens): bound uploads before gateway authentication

* docs(lens): remove extraction evidence from the gateway repo

* docs(lens): refresh shared setup prompt for paired releases
2026-10-09 16:17:05 -07:00

71 lines
2.4 KiB
Python

from datetime import datetime, timezone
from typing import Final, cast
import pytest
from litellm.constants import AGENT_TRACING_AGENT_LIST_LIMIT
from litellm.tracing.generated.models import TraceAgentRow, TraceAgentsParams
from litellm.tracing.generated.types import TraceScope
from litellm.tracing.storage import LensTraceStorage
from litellm.tracing import TraceReceiver
from litellm.tracing.types import TraceAgent
class AgentRowsStorage:
def __init__(self, rows: tuple[TraceAgentRow, ...]) -> None:
self.rows: Final = rows
self.requests: tuple[TraceAgentsParams, ...] = ()
async def trace_agents(self, parameters: TraceAgentsParams) -> tuple[TraceAgentRow, ...]:
self.requests = (*self.requests, parameters)
return self.rows
@pytest.mark.asyncio
@pytest.mark.parametrize(
("scope", "all_teams", "user_id", "team_ids"),
(
pytest.param(TraceScope(all_teams=1, user_id="", team_ids=()), 1, "", (), id="all-teams"),
pytest.param(TraceScope(all_teams=0, user_id="u1", team_ids=("t1", "t2")), 0, "u1", ("t1", "t2"), id="owned"),
),
)
async def test_list_agents_queries_the_reader_scope_and_shapes_rows(
scope: TraceScope, all_teams: int, user_id: str, team_ids: tuple[str, ...]
) -> None:
storage: Final = AgentRowsStorage(
(
TraceAgentRow(
agent_name="moyai", runs=5, failed_runs=2, last_seen_ms=1_791_405_060_123, frameworks=("pi",)
),
TraceAgentRow(agent_name="research", runs=1, failed_runs=0, last_seen_ms=0),
)
)
receiver: Final = TraceReceiver(storage=cast(LensTraceStorage, storage))
result: Final = await receiver.list_agents(scope, start_ms=10, end_ms=20)
assert storage.requests == (
TraceAgentsParams(
all_teams=all_teams,
user_id=user_id,
team_ids=team_ids,
start_ms=10,
end_ms=20,
limit=AGENT_TRACING_AGENT_LIST_LIMIT,
),
)
assert result.agents == (
TraceAgent(
name="moyai",
runs=5,
failed_runs=2,
last_seen=datetime(2026, 10, 7, 20, 31, 0, 123000, tzinfo=timezone.utc),
frameworks=("pi",),
),
TraceAgent(
name="research",
runs=1,
failed_runs=0,
last_seen=datetime(1970, 1, 1, tzinfo=timezone.utc),
),
)