mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-29 06:31:32 +00:00
Six days after #23937 (608 fixes) the codebase had accumulated 241 new PLR6201 violations. Same mechanical `x in (...)` → `x in {...}` fix, same zero-risk profile: set lookup is O(1) vs O(n) for tuple and the two are semantically equivalent for hashable scalar membership tests. All 241 instances fixed via `ruff check --select PLR6201 --fix --unsafe-fixes`, zero remaining. Every changed value is a hashable scalar (str/int/None/enum/signal); no risk of unhashable runtime errors. No behavior change. Test plan: - 119 files changed, +244/-244 (net zero) — exactly one-line edits - `ruff check` clean afterward - Compile checks pass on the largest touched files (cli.py, run_agent.py, gateway/run.py, gateway/platforms/discord.py, model_tools.py) - Subset broad test run on tests/gateway/ tests/hermes_cli/ tests/agent/ tests/tools/: 18187 passed, 59 pre-existing failures (verified against origin/main with the same shape — identical failure count, identical category — all xdist test-order flakes unrelated to this change) Follows the same template as PR #23937 ([tracker: #23972](https://github.com/NousResearch/hermes-agent/issues/23972)).
113 lines
3.9 KiB
Python
113 lines
3.9 KiB
Python
"""Smoke tests for the xAI video gen plugin — load & register surface."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from agent import video_gen_registry
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _reset_registry():
|
|
video_gen_registry._reset_for_tests()
|
|
yield
|
|
video_gen_registry._reset_for_tests()
|
|
|
|
|
|
def test_xai_provider_registers():
|
|
from plugins.video_gen.xai import XAIVideoGenProvider
|
|
|
|
provider = XAIVideoGenProvider()
|
|
video_gen_registry.register_provider(provider)
|
|
|
|
assert video_gen_registry.get_provider("xai") is provider
|
|
assert provider.display_name == "xAI"
|
|
assert provider.default_model() == "grok-imagine-video"
|
|
|
|
|
|
def test_xai_capabilities_text_and_image_only():
|
|
"""xAI was previously advertised with edit/extend operations. The
|
|
simplified surface only exposes text-to-video and image-to-video —
|
|
confirm those are the only modalities advertised."""
|
|
from plugins.video_gen.xai import XAIVideoGenProvider
|
|
|
|
caps = XAIVideoGenProvider().capabilities()
|
|
assert caps["modalities"] == ["text", "image"]
|
|
# No 'operations' key in the simplified surface
|
|
assert "operations" not in caps
|
|
assert caps["max_reference_images"] == 7
|
|
|
|
|
|
def test_xai_unavailable_without_key(monkeypatch):
|
|
from plugins.video_gen.xai import XAIVideoGenProvider
|
|
|
|
monkeypatch.delenv("XAI_API_KEY", raising=False)
|
|
assert XAIVideoGenProvider().is_available() is False
|
|
|
|
|
|
def test_xai_generate_requires_xai_key(monkeypatch):
|
|
from plugins.video_gen.xai import XAIVideoGenProvider
|
|
|
|
monkeypatch.delenv("XAI_API_KEY", raising=False)
|
|
result = XAIVideoGenProvider().generate("a happy dog")
|
|
assert result["success"] is False
|
|
assert result["error_type"] == "auth_required"
|
|
|
|
|
|
def test_xai_available_with_oauth_only(monkeypatch):
|
|
"""The plugin must honour xAI Grok OAuth credentials, not just
|
|
XAI_API_KEY. Otherwise the agent's tool-availability check filters
|
|
``video_generate`` out of the toolbelt and the agent silently falls
|
|
back to whatever skill advertises video generation (e.g. comfyui).
|
|
"""
|
|
import plugins.video_gen.xai as xai_plugin
|
|
|
|
monkeypatch.delenv("XAI_API_KEY", raising=False)
|
|
monkeypatch.setattr(
|
|
"tools.xai_http.resolve_xai_http_credentials",
|
|
lambda: {
|
|
"provider": "xai-oauth",
|
|
"api_key": "oauth-bearer-token",
|
|
"base_url": "https://api.x.ai/v1",
|
|
},
|
|
)
|
|
|
|
assert xai_plugin.XAIVideoGenProvider().is_available() is True
|
|
|
|
|
|
def test_xai_resolved_credentials_threaded_through_request(monkeypatch):
|
|
"""OAuth-resolved creds must reach the HTTP layer — bug class where
|
|
``is_available()`` says yes but the request still hits with no key.
|
|
"""
|
|
import plugins.video_gen.xai as xai_plugin
|
|
|
|
monkeypatch.delenv("XAI_API_KEY", raising=False)
|
|
monkeypatch.setattr(
|
|
"tools.xai_http.resolve_xai_http_credentials",
|
|
lambda: {
|
|
"provider": "xai-oauth",
|
|
"api_key": "oauth-bearer-token",
|
|
"base_url": "https://api.x.ai/v1",
|
|
},
|
|
)
|
|
|
|
api_key, base_url = xai_plugin._resolve_xai_credentials()
|
|
assert api_key == "oauth-bearer-token"
|
|
assert base_url == "https://api.x.ai/v1"
|
|
headers = xai_plugin._xai_headers(api_key)
|
|
assert headers["Authorization"] == "Bearer oauth-bearer-token"
|
|
|
|
|
|
def test_xai_no_operation_kwarg():
|
|
"""The ABC's generate() signature no longer accepts 'operation'.
|
|
Passing it through **kwargs should be ignored (forward-compat)."""
|
|
from plugins.video_gen.xai import XAIVideoGenProvider
|
|
|
|
# We're not actually hitting the network — just verify the call
|
|
# doesn't TypeError on the unexpected kwarg.
|
|
# Will fail with auth_required (no XAI_API_KEY), but should NOT
|
|
# fail with TypeError.
|
|
result = XAIVideoGenProvider().generate("x", operation="generate")
|
|
assert result["success"] is False
|
|
# auth_required, NOT some signature error
|
|
assert result["error_type"] in {"auth_required", "api_error"}
|