fix(e2e): resolve basedpyright errors in logging_client

Two zero-error gate regressions from PR #32857:

- completion_response_id relied on json.loads (returns Any) and dict.get on
  an unnarrowed dict, which triggered reportAny and reportUnknownVariableType.
  Route the parse through a TypeAdapter[dict[str, object]] so parsed and
  raw are typed and validation errors funnel through ValidationError.
- LangfuseListParams(...) was constructed with the field-name kwargs
  trace_id and from_start_time, but pydantic's Field alias narrows the
  generated __init__ to traceId and fromStartTime; basedpyright flagged
  those calls as reportCallIssue. Pass the aliased names; populate_by_name
  plus by_alias serialization keep runtime identical.

Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-07-11 20:07:48 +00:00
parent 345d353912
commit 3d829e4ebd
No known key found for this signature in database

View file

@ -21,7 +21,7 @@ from dataclasses import dataclass
from typing import Literal
import pytest
from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError
from e2e_config import POLL_INTERVAL, POLL_TIMEOUT
from e2e_gateway import Gateway, build_gateway
@ -200,15 +200,16 @@ def costs_agree(expected: float, actual: float, *, rel_tol: float = 0.05) -> boo
return abs(expected - actual) <= max(1e-9, abs(expected) * rel_tol)
_JSON_OBJECT: TypeAdapter[dict[str, object]] = TypeAdapter(dict[str, object])
def completion_response_id(body: str) -> str | None:
"""SpendLogs.request_id is the chat completion body id, not x-litellm-call-id."""
if not body or body == "<streamed>":
return None
try:
parsed = json.loads(body)
except json.JSONDecodeError:
return None
if not isinstance(parsed, dict):
parsed = _JSON_OBJECT.validate_json(body)
except ValidationError:
return None
raw = parsed.get("id")
return raw if isinstance(raw, str) and raw else None
@ -499,9 +500,9 @@ class LoggingClient:
headers=creds.auth_headers,
params=LangfuseListParams(
limit=100,
trace_id=trace_id,
traceId=trace_id,
name=name,
from_start_time=from_start_time,
fromStartTime=from_start_time,
),
response_type=LangfuseObservationList,
timeout=30.0,