Files
nousresearch--hermes-agent/tests/tools/test_image_generation_artifacts.py
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

125 lines
4.3 KiB
Python

import json
from types import SimpleNamespace
def test_postprocess_adds_agent_visible_image_for_active_ssh_env(monkeypatch, tmp_path):
from tools import image_generation_tool
hermes_home = tmp_path / ".hermes"
image_dir = hermes_home / "cache" / "images"
image_dir.mkdir(parents=True)
image_path = image_dir / "xai_grok-imagine-image_test.jpg"
image_path.write_bytes(b"jpg")
sync_calls = []
class FakeSyncManager:
def sync(self, *, force=False):
sync_calls.append(force)
env = SimpleNamespace(
_remote_home="/home/remotesshuser",
_sync_manager=FakeSyncManager(),
)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setattr(image_generation_tool, "_active_terminal_env", lambda task_id: env)
raw = json.dumps({"success": True, "image": str(image_path)})
result = json.loads(
image_generation_tool._postprocess_image_generate_result(raw, task_id="task-1")
)
assert result["image"] == str(image_path)
assert result["host_image"] == str(image_path)
assert result["agent_visible_image"] == (
"/home/remotesshuser/.hermes/cache/images/xai_grok-imagine-image_test.jpg"
)
assert sync_calls == [True]
def test_postprocess_maps_docker_cache_path_without_active_env(monkeypatch, tmp_path):
from tools import image_generation_tool
hermes_home = tmp_path / ".hermes"
image_dir = hermes_home / "cache" / "images"
image_dir.mkdir(parents=True)
image_path = image_dir / "generated.png"
image_path.write_bytes(b"png")
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setenv("TERMINAL_ENV", "docker")
monkeypatch.setattr(image_generation_tool, "_active_terminal_env", lambda task_id: None)
raw = json.dumps({"success": True, "image": str(image_path)})
result = json.loads(image_generation_tool._postprocess_image_generate_result(raw))
assert result["image"] == str(image_path)
assert result["agent_visible_image"] == "/root/.hermes/cache/images/generated.png"
def test_postprocess_maps_ssh_cache_path_without_active_env(monkeypatch, tmp_path):
from tools import image_generation_tool
hermes_home = tmp_path / ".hermes"
image_dir = hermes_home / "cache" / "images"
image_dir.mkdir(parents=True)
image_path = image_dir / "first-call.png"
image_path.write_bytes(b"png")
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setenv("TERMINAL_ENV", "ssh")
monkeypatch.setattr(image_generation_tool, "_active_terminal_env", lambda task_id: None)
raw = json.dumps({"success": True, "image": str(image_path)})
result = json.loads(image_generation_tool._postprocess_image_generate_result(raw))
assert result["image"] == str(image_path)
assert result["agent_visible_image"] == "~/.hermes/cache/images/first-call.png"
def test_postprocess_leaves_remote_image_urls_unchanged(monkeypatch):
from tools import image_generation_tool
monkeypatch.setattr(image_generation_tool, "_active_terminal_env", lambda task_id: None)
raw = json.dumps({"success": True, "image": "https://example.com/image.png"})
assert image_generation_tool._postprocess_image_generate_result(raw) == raw
def test_handle_image_generate_postprocesses_plugin_result(monkeypatch, tmp_path):
from tools import image_generation_tool
hermes_home = tmp_path / ".hermes"
image_dir = hermes_home / "cache" / "images"
image_dir.mkdir(parents=True)
image_path = image_dir / "plugin.png"
image_path.write_bytes(b"png")
env = SimpleNamespace(_remote_home="/home/remote", _sync_manager=None)
seen_task_ids = []
def fake_active_env(task_id):
seen_task_ids.append(task_id)
return env
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setattr(image_generation_tool, "_active_terminal_env", fake_active_env)
monkeypatch.setattr(
image_generation_tool,
"_dispatch_to_plugin_provider",
lambda prompt, aspect_ratio, **kw: json.dumps({"success": True, "image": str(image_path)}),
)
result = json.loads(
image_generation_tool._handle_image_generate(
{"prompt": "draw", "aspect_ratio": "square"},
task_id="plugin-task",
)
)
assert seen_task_ids == ["plugin-task"]
assert result["agent_visible_image"] == "/home/remote/.hermes/cache/images/plugin.png"