Commit Graph

3 Commits

Author SHA1 Message Date
yuneng-jiang b175990b4a test(proxy/utils): pin ProxyLogging behavior (#29485)
* test(proxy/utils): pin ProxyLogging behavior

Add behavior-pinning tests for the ProxyLogging cluster in
litellm/proxy/utils.py under tests/test_litellm/proxy/utils/proxy_logging/.
Covers InternalUsageCache, _CallbackCapabilities, top-of-file helpers
(print_verbose, _get_email_logger_class, _accepts_litellm_call_info,
_enrich_http_exception_with_guardrail_context), the full ProxyLogging
class (lifecycle, MCP-LLM bridging, capability probes, guardrail
pipeline, pre/during/post/streaming hooks, alerting), plus the
bottom-of-region helpers (on_backoff, jsonify_object, _lookup_deprecated_key).

Each pinned symbol has happy-path and error-path coverage; happy paths
use direct dict-equality with three or more keys (or HiddenParams /
Pydantic model_validate where the surface is a Pydantic shape). The
subdirectory carries a local _pin_check.py and _coverage_check.py that
enforce the gate without surfacing numeric thresholds in CI logs.

Wires tests/test_litellm/proxy/utils into the existing test-path block
in .github/workflows/test-unit-proxy-endpoints.yml.

* test(proxy/utils): drop unused mock_httpx_client fixture

Declared in conftest.py but never referenced by any test. Removing
the dead fixture per Greptile P2 feedback.

* test(proxy/utils): drop local-only gate scripts from PR

_pin_check.py and _coverage_check.py are local stopping signals (not
wired into CI, consume a gitignored .pin_list.txt). They served their
purpose telling the engineer when to stop writing tests; the pytest
suite is the artifact that belongs in the repo.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-02 17:45:39 -07:00
yuneng-jiang 457f65eff9 test(proxy/utils): pin PrismaClient and spend-update behavior (#29488)
* test(proxy/utils): pin PrismaClient and spend-update behavior

PR2 of the litellm/proxy/utils.py behavior-pinning plan
(https://www.notion.so/37343b8acdab81f68f39f66915f62bcf). Adds
tests/test_litellm/proxy/utils/prisma_and_spend/, with happy + error
pins for every symbol in the PR2 list: the config-param cache,
PrismaClient lifecycle/data ops/engine watcher/reconnect/health
clusters, the user-row cache and SMTP helper, password/token helpers,
ProxyUpdateSpend, and the module-level spend functions.

Tests run against fully-mocked Prisma stacks (patched ``Prisma`` /
``PrismaWrapper`` at fixture setup), with a fake SMTP transport and a
clock-driven asyncio.sleep for the monitor loop, so unit runs need no
DB or network. ``_pin_check.py`` enforces happy + error coverage for
every symbol; ``_coverage_check.py`` filters branch + line coverage to
the PR2 source range (lines 2,668-5,541) and prints PASS / FAIL with
no numbers. Workflow shard ``tests/test_litellm/proxy/utils`` is added
to the existing proxy-endpoints job.

* test(proxy/utils): commit pin list and drop dead exclusion line

Addresses Greptile review feedback on PR #29488:
  - Check in ``.pin_list.txt`` (force-added, overriding the repo-wide
    ``.gitignore`` rule) so reviewers can reproduce the ``_pin_check.py``
    PASS shown in the PR description without first regenerating the
    file from Notion.
  - Remove the unreachable ``_harness_smoke_test.py`` continue in
    ``_pin_check.py``: the surrounding ``test_*.py`` glob already
    excludes underscore-prefixed files; rephrase the docstring instead.

* test(proxy/utils): shift PR2 coverage line range by +1 after merge

``litellm_internal_staging`` added one line in ``ProxyLogging`` at
``utils.py:645`` (PR1 territory, before the PR2 region). Bump the
``_PR2_LINE_START`` / ``_PR2_LINE_END`` constants accordingly so the
coverage gate keeps scoring the same source region after the merge.

* test(proxy/utils): drop committed pin-list and gate scripts

``_pin_check.py``, ``_coverage_check.py``, and ``.pin_list.txt`` are
local-only stopping signals: no workflow or pytest collection invokes
them, so committing them adds rot risk (line-range drift in the
coverage check, pin-list staleness) without any enforcement upside.

The pin-list contract lives in the Notion plan; the tests themselves
are the durable artifact.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-02 17:45:28 -07:00
yuneng-jiang 1aed5e1bbd test(proxy/utils): pin bottom-of-file helper behavior (#29509)
* test(proxy/utils): pin bottom-of-file helper behavior

Pin current behavior of the bottom-of-file pure-function helpers in
litellm/proxy/utils.py (projection, team config, time helpers,
guardrail merge, error helpers, URL/path helpers, premium gate, model
access, and misc DB/API-key helpers).

Adds tests/test_litellm/proxy/utils/helpers/ with one happy + one error
test per pinned symbol; folds the prior single-test
tests/test_litellm/proxy/test_utils.py into test_url_helpers.py and
deletes the old file. _pin_check.py and _coverage_check.py serve as
local stopping gates.

Adds tests/test_litellm/proxy/utils to the existing test-path block in
.github/workflows/test-unit-proxy-endpoints.yml.

Plan:     https://www.notion.so/37343b8acdab81f68f39f66915f62bcf
Pin list: https://www.notion.so/37343b8acdab8150acdbf40e5756869f

* test(proxy/utils): apply greptile fixes to behavior-pinning gates

Address findings from the sibling PR1/PR2 greptile reviews that also
apply to this PR:

- Commit pin_list.txt alongside the gate script (was previously a
  gitignored .pin_list.txt fetched from Notion). The gate is now
  reproducible without out-of-band setup.
- Resolve the coverage region by locating the first pinned symbol's
  def line in litellm/proxy/utils.py at runtime, instead of hardcoded
  line numbers that drift when lines above shift.
- Word-boundary the pin reference check so pins like update_spend do
  not falsely match update_spend_logs_job.
- Drop the dead _harness_smoke_test.py exclusion; the test_*.py glob
  already filters underscore-prefixed files.

* test(proxy/utils): drop local-only stopping-signal scripts

Remove _pin_check.py, _coverage_check.py, and pin_list.txt. These were
dev-time tooling for knowing when test authoring was done; they are
not wired into CI and the test files themselves are the merge artifact.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-02 17:45:19 -07:00