From 889d8aec15b11250eb3ea18c825be34eac94b6b1 Mon Sep 17 00:00:00 2001 From: tavren27 <348969968+tavren27@users.noreply.github.com> Date: Wed, 28 Oct 2026 04:38:21 -0700 Subject: [PATCH] test(decisions): audit #47508 (#48777) * test(decisions): audit #47508 * test(decisions): price the Databricks decision cell from its cost-map row --------- Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com> --- .../cost_calculation/cases/decisions.py | 32 +++++++++++++++++++ .../integration/cost_calculation/cost_map.py | 6 ++++ .../providers/test_decisions_wire.py | 23 ++++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/tests/integration/cost_calculation/cases/decisions.py b/tests/integration/cost_calculation/cases/decisions.py index 1cc57afe8ed..6594510b232 100644 --- a/tests/integration/cost_calculation/cases/decisions.py +++ b/tests/integration/cost_calculation/cases/decisions.py @@ -162,6 +162,37 @@ TYPESAFE_JEV_LATEST_SYSTEMONE: Final = CostTrackingTestCase( completion_tokens=22, ), ) +TYPESAFE_JEV_PREVIEW_ANSWERED_AS_PRICED_VERSION_SYSTEMONE: Final = CostTrackingTestCase( + name="typesafe/jev-preview-answered-as-priced-version-systemone", + covers="quota_management.spend_tracking.systemone.logs_cost", + model="typesafe/jev-preview", + endpoint="/v1/systemone", + request={ + "model": "$MODEL", + "state": "The replacement part arrived but the wrong size.", + "questions": {"is_refund": {"type": "noul", "instructions": "Is the customer asking for a refund?"}}, + }, + upstream_body={ + "model": "jev-preview", + "state": "The replacement part arrived but the wrong size.", + "questions": {"is_refund": {"type": "noul", "instructions": "Is the customer asking for a refund?"}}, + }, + response=JsonResponse( + content_type="application/json", + body={ + "model": "jev-latest", + "answers": {"is_refund": {"type": "noul", "noul": 0.31}}, + "usage": {"input_tokens": 311, "output_tokens": 9}, + }, + ), + expected=ExactExpected( + spend=311 * 4.2e-08, + input_cost=311 * 4.2e-08, + output_cost=0.0, + prompt_tokens=311, + completion_tokens=9, + ), +) # perplexity/pplx-decider-v1-27b PERPLEXITY_PPLX_DECIDER_V1_27B_DECISIONS: Final = CostTrackingTestCase( @@ -514,6 +545,7 @@ CASES: Final[tuple[CostTrackingTestCase, ...]] = ( OPENAI_GPT_6_LUNA_SYSTEMONE, TYPESAFE_JEV_LATEST_DECISIONS, TYPESAFE_JEV_LATEST_SYSTEMONE, + TYPESAFE_JEV_PREVIEW_ANSWERED_AS_PRICED_VERSION_SYSTEMONE, PERPLEXITY_PPLX_DECIDER_V1_27B_DECISIONS, PERPLEXITY_PPLX_DECIDER_V1_27B_SYSTEMONE, CLOUDFLARE_CLEF_FLASH_DECISIONS, diff --git a/tests/integration/cost_calculation/cost_map.py b/tests/integration/cost_calculation/cost_map.py index 16107def2ad..32722b37c9b 100644 --- a/tests/integration/cost_calculation/cost_map.py +++ b/tests/integration/cost_calculation/cost_map.py @@ -121,6 +121,12 @@ COST_MAP_ENTRIES: Final[dict[str, dict[str, JsonValue]]] = { "input_cost_per_token": 4.2e-08, "output_cost_per_token": 0.0, }, + "typesafe/jev-preview": { + "litellm_provider": "typesafe", + "mode": "evaluation", + "input_cost_per_token": 8.4e-08, + "output_cost_per_token": 0.0, + }, "fireworks_ai/accounts/fireworks/routers/rune": { "litellm_provider": "fireworks_ai", "mode": "evaluation", diff --git a/tests/integration/providers/test_decisions_wire.py b/tests/integration/providers/test_decisions_wire.py index 89ca674ef31..04b78985b20 100644 --- a/tests/integration/providers/test_decisions_wire.py +++ b/tests/integration/providers/test_decisions_wire.py @@ -137,7 +137,7 @@ _PROVIDERS: Final = ( "databricks-openjev-qwen35-4b", _API_KEY, False, - None, + "databricks/databricks-openjev-qwen35-4b", ), ) _PERPLEXITY: Final = _PROVIDERS[0] @@ -576,13 +576,26 @@ def test_upstream_errors_keep_their_status_and_log_an_unbilled_failure(gateway: ) -def test_upstream_success_without_answers_is_a_gateway_side_server_error(gateway: Gateway) -> None: +@pytest.mark.parametrize( + ("reply", "field"), + ( + pytest.param({"model": _PERPLEXITY.body_model, "usage": _USAGE}, "answers", id="missing_answers"), + pytest.param( + {"model": _PERPLEXITY.body_model, "answers": {"defect": {"type": "Request timed out"}}, "usage": _USAGE}, + "answers.defect", + id="answer_type_timeout_text", + ), + ), +) +def test_a_malformed_upstream_success_is_a_server_error_naming_the_field( + gateway: Gateway, reply: dict[str, JsonValue], field: str +) -> None: with gateway.scenario() as scenario: - handle: Final = _register(scenario, {"model": _PERPLEXITY.body_model, "usage": _USAGE}) + handle: Final = _register(scenario, reply) model: Final = _deployment(scenario, handle, _PERPLEXITY) response: Final = _decide(gateway, model, num_retries=0) - assert 500 <= response.status_code < 600, response.text - assert "answers" in response.text + assert response.status_code == 500, response.text + assert field in response.text assert _spend_row(response.headers["x-litellm-call-id"])["status"] == "failure"