From ec4f8e4d7fb682a5557399cc9e201b2d751a3189 Mon Sep 17 00:00:00 2001 From: kerry Date: Wed, 23 Sep 2026 01:33:09 +0000 Subject: [PATCH] test(integration): cover config-defined pass-through failure spend rows Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/integration/contracts.json | 3 ++ .../spend/test_passthrough_failure.py | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/integration/spend/test_passthrough_failure.py diff --git a/tests/integration/contracts.json b/tests/integration/contracts.json index ee9b81f63dc..257c4722aae 100644 --- a/tests/integration/contracts.json +++ b/tests/integration/contracts.json @@ -1794,6 +1794,9 @@ ], "tests/integration/observability/test_callback_delivery.py::test_response_survives_raising_success_deployment_hook[videos]": [ "other.observability.callbacks.raising_success_deployment_hook_keeps_response" + ], + "tests/integration/spend/test_passthrough_failure.py::test_config_pass_through_endpoint_failure_writes_a_spend_row": [ + "quota_management.spend_tracking.pass_through_failure.failure_row_written" ] }, "browser": { diff --git a/tests/integration/spend/test_passthrough_failure.py b/tests/integration/spend/test_passthrough_failure.py new file mode 100644 index 00000000000..34b6250889d --- /dev/null +++ b/tests/integration/spend/test_passthrough_failure.py @@ -0,0 +1,52 @@ +import json +from typing import Final + +import pytest +from integration._support.client import Gateway, eventually +from integration._support.database import read_rows +from integration._support.process import owned_proxy +from integration._support.wire import Reply, Request, wire_server + + +@pytest.mark.covers("quota_management.spend_tracking.pass_through_failure.failure_row_written") +@pytest.mark.timeout(180) +def test_config_pass_through_endpoint_failure_writes_a_spend_row(gateway: Gateway, tmp_path) -> None: + def respond(request: Request) -> Reply: + assert request.target == "/" + assert json.loads(request.body) == {"search": "hello"} + return Reply(status=500, body=json.dumps({"error": "upstream search failure"}).encode()) + + with wire_server(respond) as wire: + config: Final = tmp_path / "proxy_config.yaml" + config.write_text( + "model_list: []\n" + "general_settings:\n" + " master_key: os.environ/LITELLM_MASTER_KEY\n" + " database_url: os.environ/DATABASE_URL\n" + " store_model_in_db: true\n" + " disable_spend_logs: false\n" + " proxy_batch_write_at: 1\n" + " pass_through_endpoints:\n" + " - path: /azure-search\n" + f" target: {wire.url}\n" + " headers:\n" + " Authorization: Bearer synthetic-search-key\n" + "router_settings:\n" + " disable_cooldowns: true\n" + ) + with owned_proxy(gateway, tmp_path, {}, config=config) as candidate: + response: Final = candidate.request("POST", "/azure-search", {"search": "hello"}) + assert response.status_code == 500, response.text + call_id: Final = response.headers["x-litellm-call-id"] + rows: Final = eventually( + lambda: read_rows( + 'SELECT status, call_type, api_base, spend FROM "LiteLLM_SpendLogs" WHERE request_id=%s', + (call_id,), + ), + lambda values: len(values) == 1, + seconds=70, + ) + assert rows[0]["status"] == "failure", rows + assert rows[0]["call_type"] == "pass_through_endpoint", rows + assert "127.0.0.1" in rows[0]["api_base"], rows + assert [(request.method, request.target) for request in wire.drain()] == [("POST", "/")]