litellm/tests/unit/tracing/test_receiver.py
ishaan-berri bf9bd35469
feat(lens): scope traces to one agent with a header picker (#45202)
* feat(lens): add trace_agents rollup query

* feat(lens): register the trace_agents read query

* feat(lens): add trace_agents params and row types

* feat(lens): dispatch the trace_agents query

* feat(lens): export trace_agents wire schemas

* test(lens): pin the trace_agents query name

* test(lens): cover trace_agents scope, window and failure counts

* feat(lens): cap the agent list size

* feat(lens): declare the trace_agents bridge query

* feat(lens): read trace agents from clickhouse storage

* feat(lens): add trace agent response models

* feat(lens): list agents within the reader's trace scope

* feat(lens): add GET /v1/traces/agents

* chore(lens): regenerate trace models with trace_agents

* chore(lens): regenerate trace types with trace_agents

* chore(lens): regenerate read query name schema

* chore(lens): add trace agent row schema

* chore(lens): add trace agents params schema

* test(lens): cover the trace agents route

* test(lens): cover agent listing scope and timestamps

* chore(ui): regenerate api types with trace agents route

* feat(lens): derive trace agent types from the schema

* feat(lens): fetch the agent list from the traces api

* feat(lens): roll up demo runs into agents

* feat(lens): serve the agent list in demo data

* feat(lens): load agents seen in the last two weeks

* feat(lens): remember the selected agent per browser

* feat(lens): add the agent picker

* feat(lens): wire agent selection into the lens header

* feat(lens): show the agent picker next to the lens title

* refactor(lens): drop the toolbar agent filter in favor of the header picker

* test(lens): remove tests for the toolbar agent filter

* test(lens): cover agent resolution and rollup

* test(lens): cover scoping, switching and remembering the agent

* test(lens): read only the create request in guided setup

* test(lens): assert the toolbar agent filter is gone

* test(lens): read stubbed requests without their abort signal
2026-10-07 23:48:04 +00: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.rust_bridge.trace.generated.models import TraceAgentRow, TraceAgentsParams
from litellm.rust_bridge.trace.generated.types import TraceScope
from litellm.rust_bridge.trace.storage import ClickHouseStorage
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(ClickHouseStorage, 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),
),
)