mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix(cli): validate user-defined providers consistently
This commit is contained in:
parent
3aa1a41e88
commit
ccc8fccf77
4 changed files with 135 additions and 13 deletions
|
|
@ -3,6 +3,8 @@
|
|||
import os
|
||||
import sys
|
||||
import types
|
||||
import io
|
||||
import contextlib
|
||||
from argparse import Namespace
|
||||
from types import SimpleNamespace
|
||||
|
||||
|
|
@ -255,6 +257,57 @@ def test_run_doctor_termux_treats_docker_and_browser_warnings_as_expected(monkey
|
|||
assert "docker not found (optional)" not in out
|
||||
|
||||
|
||||
def test_run_doctor_accepts_named_provider_from_providers_section(monkeypatch, tmp_path):
|
||||
home = tmp_path / ".hermes"
|
||||
home.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
import yaml
|
||||
|
||||
(home / "config.yaml").write_text(
|
||||
yaml.dump(
|
||||
{
|
||||
"model": {
|
||||
"provider": "volcengine-plan",
|
||||
"default": "doubao-seed-2.0-code",
|
||||
},
|
||||
"providers": {
|
||||
"volcengine-plan": {
|
||||
"name": "volcengine-plan",
|
||||
"base_url": "https://ark.cn-beijing.volces.com/api/coding/v3",
|
||||
"default_model": "doubao-seed-2.0-code",
|
||||
"models": {"doubao-seed-2.0-code": {}},
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
monkeypatch.setattr(doctor_mod, "HERMES_HOME", home)
|
||||
monkeypatch.setattr(doctor_mod, "PROJECT_ROOT", tmp_path / "project")
|
||||
monkeypatch.setattr(doctor_mod, "_DHH", str(home))
|
||||
(tmp_path / "project").mkdir(exist_ok=True)
|
||||
|
||||
fake_model_tools = types.SimpleNamespace(
|
||||
check_tool_availability=lambda *a, **kw: ([], []),
|
||||
TOOLSET_REQUIREMENTS={},
|
||||
)
|
||||
monkeypatch.setitem(sys.modules, "model_tools", fake_model_tools)
|
||||
|
||||
try:
|
||||
from hermes_cli import auth as _auth_mod
|
||||
monkeypatch.setattr(_auth_mod, "get_nous_auth_status", lambda: {})
|
||||
monkeypatch.setattr(_auth_mod, "get_codex_auth_status", lambda: {})
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
buf = io.StringIO()
|
||||
with contextlib.redirect_stdout(buf):
|
||||
doctor_mod.run_doctor(Namespace(fix=False))
|
||||
|
||||
out = buf.getvalue()
|
||||
assert "model.provider 'volcengine-plan' is not a recognised provider" not in out
|
||||
|
||||
|
||||
def test_run_doctor_termux_does_not_mark_browser_available_without_agent_browser(monkeypatch, tmp_path):
|
||||
home = tmp_path / ".hermes"
|
||||
home.mkdir(parents=True, exist_ok=True)
|
||||
|
|
|
|||
|
|
@ -339,6 +339,41 @@ def test_select_provider_and_model_warns_if_named_custom_provider_disappears(
|
|||
assert "selected saved custom provider is no longer available" in out
|
||||
|
||||
|
||||
def test_select_provider_and_model_accepts_named_provider_from_providers_section(
|
||||
tmp_path, monkeypatch, capsys
|
||||
):
|
||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||
_clear_provider_env(monkeypatch)
|
||||
|
||||
cfg = load_config()
|
||||
cfg["model"] = {
|
||||
"provider": "volcengine-plan",
|
||||
"default": "doubao-seed-2.0-code",
|
||||
}
|
||||
cfg["providers"] = {
|
||||
"volcengine-plan": {
|
||||
"name": "volcengine-plan",
|
||||
"base_url": "https://ark.cn-beijing.volces.com/api/coding/v3",
|
||||
"default_model": "doubao-seed-2.0-code",
|
||||
"models": {"doubao-seed-2.0-code": {}},
|
||||
}
|
||||
}
|
||||
save_config(cfg)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"hermes_cli.main._prompt_provider_choice",
|
||||
lambda choices, default=0: len(choices) - 1,
|
||||
)
|
||||
|
||||
from hermes_cli.main import select_provider_and_model
|
||||
|
||||
select_provider_and_model()
|
||||
|
||||
out = capsys.readouterr().out
|
||||
assert "Warning: Unknown provider 'volcengine-plan'" not in out
|
||||
assert "Active provider: volcengine-plan" in out
|
||||
|
||||
|
||||
def test_codex_setup_uses_runtime_access_token_for_live_model_list(tmp_path, monkeypatch):
|
||||
"""Codex model list fetching uses the runtime access token."""
|
||||
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue