Files
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

101 lines
3.4 KiB
Python

"""Tests for Vertex AI runtime-provider resolution and profile registration.
Covers: provider-profile registration + aliases, alias canonicalization,
resolve_runtime_provider(vertex) minting an OAuth token, and the friendly
AuthError when credentials can't be resolved. No network calls.
"""
from __future__ import annotations
import pytest
def test_vertex_profile_registered():
from providers import get_provider_profile
p = get_provider_profile("vertex")
assert p is not None
assert p.name == "vertex"
assert p.api_mode == "chat_completions"
assert p.auth_type == "vertex"
@pytest.mark.parametrize("alias", ["google-vertex", "vertex-ai", "gcp-vertex"])
def test_vertex_aliases_resolve(alias):
from providers import get_provider_profile
assert get_provider_profile(alias).name == "vertex"
@pytest.mark.parametrize("alias", ["google-vertex", "vertex-ai", "gcp-vertex", "vertexai"])
def test_alias_canonicalizes_to_vertex(alias):
from hermes_cli.models import _PROVIDER_ALIASES
assert _PROVIDER_ALIASES[alias] == "vertex"
def test_google_vertex_not_confused_with_gemini():
"""`google-vertex` must map to vertex, not the AI-Studio `gemini` provider."""
from hermes_cli.models import _PROVIDER_ALIASES
assert _PROVIDER_ALIASES["google-vertex"] == "vertex"
assert _PROVIDER_ALIASES["google-gemini"] == "gemini"
def test_resolve_runtime_provider_mints_token(monkeypatch):
import agent.vertex_adapter as va
from hermes_cli import runtime_provider as rp
monkeypatch.setattr(
va, "get_vertex_config",
lambda: ("ya29.TOKEN", "https://aiplatform.googleapis.com/v1beta1/projects/p/locations/global/endpoints/openapi"),
)
rt = rp.resolve_runtime_provider(requested="vertex")
assert rt["provider"] == "vertex"
assert rt["api_mode"] == "chat_completions"
assert rt["source"] == "vertex-oauth"
assert rt["api_key"] == "ya29.TOKEN"
assert "aiplatform.googleapis.com" in rt["base_url"]
def test_resolve_runtime_provider_alias(monkeypatch):
import agent.vertex_adapter as va
from hermes_cli import runtime_provider as rp
monkeypatch.setattr(va, "get_vertex_config", lambda: ("t", "https://aiplatform.googleapis.com/v1beta1/projects/p/locations/global/endpoints/openapi"))
rt = rp.resolve_runtime_provider(requested="google-vertex")
assert rt["provider"] == "vertex"
def test_resolve_runtime_provider_raises_autherror_when_unresolved(monkeypatch):
import agent.vertex_adapter as va
from hermes_cli import runtime_provider as rp
from hermes_cli.auth import AuthError
monkeypatch.setattr(va, "get_vertex_config", lambda: (None, None))
with pytest.raises(AuthError) as exc:
rp.resolve_runtime_provider(requested="vertex")
msg = str(exc.value)
assert "OAuth2" in msg
assert "not a static API key" in msg
def test_vertex_extra_body_thinking_config():
from providers import get_provider_profile
p = get_provider_profile("vertex")
body = p.build_extra_body(
model="google/gemini-3-pro-preview",
reasoning_config={"effort": "high"},
)
assert "extra_body" in body
assert "google" in body["extra_body"]
assert "thinking_config" in body["extra_body"]["google"]
def test_vertex_extra_body_empty_without_reasoning():
from providers import get_provider_profile
p = get_provider_profile("vertex")
assert p.build_extra_body(model="google/gemini-3-flash-preview") == {}