litellm/tests/unit/rust_bridge/host/test_model_cost.py
yujonglee 11af2eb22d
refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822)
* refactor(rust_bridge): route every Rust-to-Python call through host modules

Rust now reaches Python only through litellm/rust_bridge/host/ (plus the
execution driver), and no Python module outside host/ imports it. Library
calls that reproduce Python behavior (httpx and OSError error text,
huggingface_hub downloads, the random generator, os.environ) go through
host functions too. The rule is written into host/AGENTS.md

The live litellm.model_cost table, its version and every Python writer move
to litellm_core_utils/model_cost_table.py, and host/model_cost.py keeps only
the functions Rust calls. The cost map fetch passes use_http_settings instead
of handing Rust an http_settings() snapshot

* refactor(rust_bridge): read REDIS_USERNAME from the process environment in Rust

The Redis bridge asked Python for all of os.environ to read one key. CPython's
os.environ writes through to the process environment, so Rust reads it with
ProcessEnvironment like the rest of the module. Also drops doc comments that
restated their code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci(rust): raise the native extension size cap to 55 MB

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 01:57:54 +00:00

25 lines
1 KiB
Python

from typing import Final
import pytest
import litellm
from litellm.litellm_core_utils.model_cost_table import AliasedCostEntry
from litellm.rust_bridge.host.model_cost import merged, resolve
pytestmark = pytest.mark.usefixtures("local_model_cost_map")
def test_resolve_lands_on_the_row_a_lookup_in_the_published_table_resolves() -> None:
landing: Final = resolve(litellm.model_cost, "openai/gpt-4o", {"input_cost_per_token": 1.0}, None)
assert landing is not None
assert (landing.key, landing.matched_builtin) == ("gpt-4o", True)
def test_merged_keeps_the_alias_names_and_adds_only_the_fields_a_registration_set() -> None:
current: Final = AliasedCostEntry({"mode": "chat", "x": 1}, ("owner", "alias"), frozenset({"mode"}))
row: Final = merged(current, {"x": 2}, {"litellm_provider": "openai", "output_cost_per_token": None})
assert row == {"mode": "chat", "x": 2, "litellm_provider": "openai"}
assert (row.names, row.registered_fields) == (("owner", "alias"), frozenset({"mode", "litellm_provider"}))