test: consolidate repetitive cases across the suite

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-25 14:28:21 +08:00
1 parent c406024b59
commit 6eccc2859a
31 files changed
+745 -1315

No files matched your search

+56 -77
View File
@@ -583,6 +583,22 @@ def test_provider_logout_openai_codex_removes_local_oauth_files(tmp_path, monkey
assert "Logged out from OpenAI Codex" in result.stdout
def test_provider_logout_github_copilot_removes_local_oauth_files(tmp_path, monkeypatch):
token_path = tmp_path / "auth" / "github-copilot.json"
lock_path = token_path.with_suffix(".lock")
token_path.parent.mkdir(parents=True, exist_ok=True)
token_path.write_text("{}", encoding="utf-8")
lock_path.write_text("", encoding="utf-8")
monkeypatch.setenv("OAUTH_CLI_KIT_TOKEN_PATH", str(token_path))
result = runner.invoke(app, ["provider", "logout", "github-copilot"])
assert result.exit_code == 0
assert not token_path.exists()
assert not lock_path.exists()
assert "Logged out from GitHub Copilot" in result.stdout
def test_provider_logout_openai_codex_succeeds_when_no_local_oauth_file(monkeypatch, tmp_path):
token_path = tmp_path / "auth" / "codex.json"
monkeypatch.setenv("OAUTH_CLI_KIT_TOKEN_PATH", str(token_path))
@@ -634,22 +650,6 @@ def test_provider_logout_xai_grok_uses_explicit_config_path(tmp_path, monkeypatc
assert "Using config:" in result.stdout
def test_provider_logout_github_copilot_removes_local_oauth_files(tmp_path, monkeypatch):
token_path = tmp_path / "auth" / "github-copilot.json"
lock_path = token_path.with_suffix(".lock")
token_path.parent.mkdir(parents=True, exist_ok=True)
token_path.write_text("{}", encoding="utf-8")
lock_path.write_text("", encoding="utf-8")
monkeypatch.setenv("OAUTH_CLI_KIT_TOKEN_PATH", str(token_path))
result = runner.invoke(app, ["provider", "logout", "github-copilot"])
assert result.exit_code == 0
assert not token_path.exists()
assert not lock_path.exists()
assert "Logged out from GitHub Copilot" in result.stdout
def test_provider_logout_github_copilot_succeeds_when_no_local_oauth_file(monkeypatch, tmp_path):
token_path = tmp_path / "auth" / "github-copilot.json"
monkeypatch.setenv("OAUTH_CLI_KIT_TOKEN_PATH", str(token_path))
@@ -1000,48 +1000,43 @@ def test_config_accepts_camel_case_explicit_provider_name_for_coding_plan():
assert config.get_api_base() == "https://ark.cn-beijing.volces.com/api/coding/v3"
def test_config_accepts_lm_studio_without_api_key_and_uses_default_localhost_api_base():
@pytest.mark.parametrize(
"provider_name, api_base, config_key",
[
pytest.param(
"lm_studio",
"http://localhost:1234/v1",
"lmStudio",
id="lm_studio_without_api_key_and_uses_default_localhost_api_base",
),
pytest.param(
"atomic_chat",
"http://localhost:1337/v1",
"atomicChat",
id="atomic_chat_without_api_key_and_uses_default_localhost_api_base",
),
],
)
def test_local_provider_defaults_without_api_key(provider_name, api_base, config_key):
config = Config.model_validate(
{
"agents": {
"defaults": {
"provider": "lm_studio",
"provider": provider_name,
"model": "local-model",
}
},
"providers": {
"lmStudio": {
config_key: {
"apiKey": None,
}
},
}
)
assert config.get_provider_name() == "lm_studio"
assert config.get_provider_name() == provider_name
assert config.get_api_key() is None
assert config.get_api_base() == "http://localhost:1234/v1"
def test_config_accepts_atomic_chat_without_api_key_and_uses_default_localhost_api_base():
config = Config.model_validate(
{
"agents": {
"defaults": {
"provider": "atomic_chat",
"model": "local-model",
}
},
"providers": {
"atomicChat": {
"apiKey": None,
}
},
}
)
assert config.get_provider_name() == "atomic_chat"
assert config.get_api_key() is None
assert config.get_api_base() == "http://localhost:1337/v1"
assert config.get_api_base() == api_base
def test_find_by_name_accepts_camel_case_and_hyphen_aliases():
@@ -1441,44 +1436,28 @@ def test_make_provider_strips_dynamic_custom_route_prefix_from_request_model():
assert body["model"] == "gpt-4o-mini"
def test_make_provider_preserves_namespaced_model_for_forced_dynamic_provider():
@pytest.mark.parametrize(
"provider_name, model",
[
pytest.param(
"my-company-api",
"openai/gpt-4o-mini",
id="preserves_namespaced_model_for_forced_dynamic_provider",
),
pytest.param(
"auto",
"my-company-api/openai/gpt-4o-mini",
id="strips_dynamic_custom_route_prefix_once",
),
],
)
def test_make_provider_preserves_dynamic_provider_model_namespace(provider_name, model):
config = Config.model_validate(
{
"agents": {
"defaults": {
"provider": "my-company-api",
"model": "openai/gpt-4o-mini",
}
},
"providers": {
"my-company-api": {
"apiBase": "https://example.com/v1",
}
},
}
)
provider = make_provider(config)
kwargs = provider._build_kwargs(
messages=[{"role": "user", "content": "hi"}],
tools=None,
model=None,
max_tokens=16,
temperature=0.1,
reasoning_effort=None,
tool_choice=None,
)
assert kwargs["model"] == "openai/gpt-4o-mini"
def test_make_provider_strips_dynamic_custom_route_prefix_once():
config = Config.model_validate(
{
"agents": {
"defaults": {
"provider": "auto",
"model": "my-company-api/openai/gpt-4o-mini",
"provider": provider_name,
"model": model,
}
},
"providers": {