Files
hermes-agent/tests/hermes_cli/test_custom_provider_context_feedback.py
teknium1 e8016a18c1 fix(cli): report the auto-detected context length when a custom provider is saved without one
Leaving the context-length prompt blank in the custom-endpoint wizard said
"will auto-detect" and then went silent, so users could not tell whether their
endpoint runs on a detected window or the runtime's default fallback (which
shapes compression and prompt-cache behaviour). After the save prompt, run the
same resolver the runtime uses (with the endpoint's URL and key) and print
either "auto-detected N tokens" or "not detected — using the default N tokens".
Feedback only: the probe result is not persisted, and a failing probe never
blocks the save.

Fixes #2513. Approach from PR #2522 (@ygd58) and PR #85499 (@Luna161), both
written against the pre-decomposition wizard module.

Co-authored-by: Luna161 <268031236+Luna161@users.noreply.github.com>
2026-09-12 05:10:51 -07:00

27 lines
1.2 KiB
Python

"""#2513: a blank context-length prompt in the custom-endpoint wizard tells the user whether the
runtime resolver detected a value or will run on the silent default."""
from unittest.mock import patch
import pytest
from hermes_cli import model_setup_flows_custom as flows
@pytest.mark.parametrize("resolved, expect", [
(200_000, "auto-detected"),
(None, "using the default"),
])
def test_blank_context_length_reports_detection_outcome(capsys, resolved, expect):
from agent.model_metadata import DEFAULT_FALLBACK_CONTEXT
with patch("agent.model_metadata.get_model_context_length",
return_value=resolved if resolved is not None else DEFAULT_FALLBACK_CONTEXT) as probe:
flows._report_context_length_detection("some-model", "http://localhost:8000/v1", "k")
probe.assert_called_once_with("some-model", base_url="http://localhost:8000/v1", api_key="k")
assert expect in capsys.readouterr().out
def test_probe_failure_never_blocks_the_save(capsys):
with patch("agent.model_metadata.get_model_context_length", side_effect=RuntimeError("boom")):
flows._report_context_length_detection("some-model", "http://x/v1", "")
assert capsys.readouterr().out == ""