The previous test replaced _resolve_context_length itself with a fake that re-did the threading, so it could not fail if the production call dropped the kwarg; the sibling test only called get_model_context_length directly (green on main, and its list-shaped `models` fixture is silently ignored by the config loader). One test now patches agent.context_compressor.get_model_context_length where production reads it and asserts the kwarg arrives; file moved next to the other compressor tests. The defensive list copy is dropped (no caller mutates).
22 lines
846 B
Python
22 lines
846 B
Python
"""Per-model ``context_length`` overrides from custom_providers reach the compressor's deferred resolution (#83324)."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
from agent.context_compressor import ContextCompressor
|
|
|
|
|
|
def test_compressor_threads_custom_providers_into_context_length_resolution():
|
|
providers = [{"name": "p1", "models": {"m": {"context_length": 99999}}}]
|
|
captured = {}
|
|
|
|
def fake_resolve(model, **kwargs):
|
|
captured.update(kwargs)
|
|
return 99999
|
|
|
|
with patch("agent.context_compressor.get_model_context_length", side_effect=fake_resolve):
|
|
comp = ContextCompressor(model="m", base_url="https://x.example.com/v1", api_key="k", provider="custom",
|
|
custom_providers=providers)
|
|
assert comp.context_length == 99999
|
|
|
|
assert captured["custom_providers"] == providers
|