Files
agents/sdk/python/tests/test_agent_helpers.py
zeekayandGitHub 5b5cf9e9db feat: merge AgentField control plane + SDKs as Hanzo Agents (#1)
Transforms hanzoai/agents from a marketplace config repo into a full
agent orchestration platform by merging the AgentField infrastructure:

- Go control plane (K8s-like agent orchestration, service mesh, DAG workflows)
- Python SDK (FastAPI-based agent framework, LiteLLM, memory, DID/VC)
- TypeScript SDK (@hanzo/agents - Vercel AI SDK, MCP, workflows)
- Go SDK (idiomatic agent builder + client)
- React 19 embedded dashboard (XyFlow DAGs, Recharts, Radix UI)
- Docker/K8s/Helm deployment configs
- Examples: hello world, deep research, RAG, simulation, benchmarks
- Functional test suite across Python/Go/TypeScript

All references rebranded: AgentField → Hanzo Agents
- Module: github.com/hanzoai/agents/control-plane
- Python: hanzo_agents
- TypeScript: @hanzo/agents
- Go: github.com/hanzoai/agents/sdk/go
- Env vars: HANZO_AGENTS_*
- Config: hanzo-agents.yaml

Previous marketplace configs moved to config/ directory.
2026-02-09 18:53:09 -08:00

72 lines
3.0 KiB
Python

from hanzo_agents.agent import _resolve_callback_url, _build_callback_candidates
def test_resolve_callback_url_prefers_explicit_url():
url = _resolve_callback_url("https://example.com:9000", port=8000)
assert url == "https://example.com:9000"
url = _resolve_callback_url("example.org", port=7000)
assert url == "http://example.org:7000"
def test_resolve_callback_url_uses_env(monkeypatch):
monkeypatch.setenv("AGENT_CALLBACK_URL", "https://env.example.com")
try:
url = _resolve_callback_url(None, port=5000)
assert url == "https://env.example.com:5000"
finally:
monkeypatch.delenv("AGENT_CALLBACK_URL", raising=False)
def test_resolve_callback_url_handles_container_overrides(monkeypatch):
monkeypatch.delenv("AGENT_CALLBACK_URL", raising=False)
monkeypatch.setenv("RAILWAY_SERVICE_NAME", "my-service")
monkeypatch.setenv("RAILWAY_ENVIRONMENT", "prod")
monkeypatch.setattr("hanzo_agents.agent._is_running_in_container", lambda: True)
monkeypatch.setattr("hanzo_agents.agent._detect_container_ip", lambda: None)
monkeypatch.setattr("hanzo_agents.agent._detect_local_ip", lambda: "10.0.0.5")
url = _resolve_callback_url(None, port=4500)
assert url == "http://my-service.railway.internal:4500"
def test_resolve_callback_url_fallback_to_detected_ips(monkeypatch):
monkeypatch.delenv("AGENT_CALLBACK_URL", raising=False)
monkeypatch.delenv("RAILWAY_SERVICE_NAME", raising=False)
monkeypatch.delenv("RAILWAY_ENVIRONMENT", raising=False)
monkeypatch.setattr("hanzo_agents.agent._is_running_in_container", lambda: True)
monkeypatch.setattr("hanzo_agents.agent._detect_container_ip", lambda: "203.0.113.10")
url = _resolve_callback_url(None, port=3200)
assert url == "http://203.0.113.10:3200"
monkeypatch.setattr("hanzo_agents.agent._detect_container_ip", lambda: None)
monkeypatch.setattr("hanzo_agents.agent._detect_local_ip", lambda: "192.168.1.2")
url = _resolve_callback_url(None, port=3201)
assert url == "http://192.168.1.2:3201"
def test_resolve_callback_url_final_fallback(monkeypatch):
monkeypatch.delenv("AGENT_CALLBACK_URL", raising=False)
monkeypatch.setattr("hanzo_agents.agent._is_running_in_container", lambda: False)
monkeypatch.setattr("hanzo_agents.agent._detect_local_ip", lambda: None)
monkeypatch.setattr("hanzo_agents.agent.socket.gethostname", lambda: "")
url = _resolve_callback_url(None, port=8080)
assert url in {"http://localhost:8080", "http://host.docker.internal:8080"}
def test_build_callback_candidates_includes_defaults(monkeypatch):
monkeypatch.setattr("hanzo_agents.agent._is_running_in_container", lambda: False)
monkeypatch.setattr("hanzo_agents.agent._detect_local_ip", lambda: "192.168.1.50")
monkeypatch.setattr("hanzo_agents.agent.socket.gethostname", lambda: "my-host")
candidates = _build_callback_candidates(None, 9000)
assert "http://192.168.1.50:9000" in candidates
assert "http://localhost:9000" in candidates
assert "http://127.0.0.1:9000" in candidates