mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
Second, deeper pass over tools/gateway/hermes_cli plus first pass over the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker, dashboard, conformance, monitoring, secret_sources, hermes_state, providers). Same rubric as wave 1 (AGENTS.md test policy); security, alternation/caching invariants, issue-number regressions, and E2E kept. Real test-quality fixes found and rooted out along the way: - tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls (DEFAULT_CONFIG smart-approval leaked in) — pinned approval mode=manual via autouse fixture: 17.4s → 0.4s. - test_model_switch_custom_providers.py / test_user_providers_model_switch.py silently probed live provider catalogs (~2s/test) — stubbed cached_provider_model_ids/provider_model_ids/fetch_api_models. - test_telegram_noise_filter.py: 15-platform copy-paste matrix over shared gateway.run logic → 3 representative platforms (55s → 3.9s). - test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on MagicMock agents — interrupt.side_effect now clears _running_agents (22s → 1.0s). - test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait 5s → 0.5s. - test_telegram_init_deadline.py: loop-block margin restored to 1.0s with rationale comment — the watchdog-dump assertion needs the loop blocked well past deadline+grace under parallel load (flaked once in the 40-worker verification run at a 0.2s margin). Verification: full hermetic suite via scripts/run_tests.sh — 2,438 files, 21,718 tests passed, 0 failed, 293.9s wall. Suite totals vs original baseline: 46,820 → 19,757 test functions (−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
105 lines
3 KiB
Python
105 lines
3 KiB
Python
"""Tests for the dynamic schema builder."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from agent import video_gen_registry
|
|
from agent.video_gen_provider import VideoGenProvider
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _reset_registry():
|
|
video_gen_registry._reset_for_tests()
|
|
yield
|
|
video_gen_registry._reset_for_tests()
|
|
|
|
|
|
@pytest.fixture
|
|
def cfg_home(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
return tmp_path
|
|
|
|
|
|
def _write_cfg(home, cfg: dict):
|
|
(home / "config.yaml").write_text(yaml.safe_dump(cfg))
|
|
|
|
|
|
class _BothModalitiesProvider(VideoGenProvider):
|
|
"""Supports both text-to-video AND image-to-video (the common case)."""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "both"
|
|
|
|
def is_available(self) -> bool:
|
|
return True
|
|
|
|
def list_models(self) -> List[Dict[str, Any]]:
|
|
return [{"id": "family-a", "modalities": ["text", "image"]}]
|
|
|
|
def default_model(self) -> Optional[str]:
|
|
return "family-a"
|
|
|
|
def capabilities(self) -> Dict[str, Any]:
|
|
return {
|
|
"modalities": ["text", "image"],
|
|
"aspect_ratios": ["16:9", "9:16"],
|
|
"resolutions": ["720p", "1080p"],
|
|
"min_duration": 1,
|
|
"max_duration": 15,
|
|
"supports_audio": True,
|
|
"supports_negative_prompt": True,
|
|
"max_reference_images": 0,
|
|
}
|
|
|
|
def generate(self, prompt, **kwargs):
|
|
return {"success": True}
|
|
|
|
|
|
class _ImageOnlyProvider(VideoGenProvider):
|
|
"""Backend with only image-to-video support (rare but possible)."""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "img-only"
|
|
|
|
def is_available(self) -> bool:
|
|
return True
|
|
|
|
def list_models(self) -> List[Dict[str, Any]]:
|
|
return [{"id": "img-only-v1", "modalities": ["image"]}]
|
|
|
|
def default_model(self) -> Optional[str]:
|
|
return "img-only-v1"
|
|
|
|
def capabilities(self) -> Dict[str, Any]:
|
|
return {"modalities": ["image"], "min_duration": 1, "max_duration": 10}
|
|
|
|
def generate(self, prompt, **kwargs):
|
|
return {"success": True}
|
|
|
|
|
|
class TestDynamicSchemaBuilder:
|
|
def test_no_config_says_so(self, cfg_home):
|
|
from tools.video_generation_tool import _build_dynamic_video_schema
|
|
|
|
desc = _build_dynamic_video_schema()["description"]
|
|
# No provider configured AND none available → description says so. The
|
|
# wording reflects the *resolved* active provider (mirrors execution),
|
|
# so it reads "available" rather than "configured".
|
|
assert "No video backend is available" in desc
|
|
assert "hermes tools" in desc
|
|
|
|
|
|
def test_builder_wired_into_registry(self):
|
|
from tools.registry import discover_builtin_tools, registry
|
|
|
|
discover_builtin_tools()
|
|
entry = registry._tools["video_generate"]
|
|
assert entry.dynamic_schema_overrides is not None
|
|
out = entry.dynamic_schema_overrides()
|
|
assert "description" in out
|