0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
185 lines
5.6 KiB
Python
185 lines
5.6 KiB
Python
"""Tests for the Hermes headroom_retrieve plugin (plugins/hermes/).
|
|
|
|
The plugin targets the Hermes Agent runtime, which provides a
|
|
``tools.registry`` module. That module does not exist inside the headroom
|
|
codebase, so these tests stub it before loading the plugin file directly
|
|
via importlib.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import json
|
|
import sys
|
|
import types
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
PLUGIN_PATH = (
|
|
Path(__file__).resolve().parent.parent
|
|
/ "plugins"
|
|
/ "hermes"
|
|
/ "headroom_retrieve"
|
|
/ "__init__.py"
|
|
)
|
|
|
|
|
|
def _load_plugin() -> types.ModuleType:
|
|
"""Load the plugin file with a stubbed Hermes ``tools.registry``."""
|
|
registry = types.ModuleType("tools.registry")
|
|
registry.tool_error = lambda msg: json.dumps({"error": msg}) # type: ignore[attr-defined]
|
|
registry.tool_result = lambda data: json.dumps({"result": data}) # type: ignore[attr-defined]
|
|
tools_pkg = types.ModuleType("tools")
|
|
tools_pkg.registry = registry # type: ignore[attr-defined]
|
|
sys.modules.setdefault("tools", tools_pkg)
|
|
sys.modules["tools.registry"] = registry
|
|
|
|
spec = importlib.util.spec_from_file_location("hermes_headroom_retrieve", PLUGIN_PATH)
|
|
assert spec is not None and spec.loader is not None
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
class _FakeResponse:
|
|
def __init__(self, status_code: int, payload: dict[str, Any] | None = None) -> None:
|
|
self.status_code = status_code
|
|
self._payload = payload or {}
|
|
self.text = json.dumps(self._payload)
|
|
|
|
def json(self) -> dict[str, Any]:
|
|
return self._payload
|
|
|
|
|
|
@pytest.fixture()
|
|
def plugin() -> types.ModuleType:
|
|
return _load_plugin()
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("raw", "expected"),
|
|
[
|
|
("abc123", "abc123"),
|
|
("ccr:abc123", "abc123"),
|
|
("<<ccr:abc123>>", "abc123"),
|
|
("<<ccr:abc123,base64,4.5KB>>", "abc123"),
|
|
("hash=abc123", "abc123"),
|
|
(" <<ccr:abc123>> ", "abc123"),
|
|
],
|
|
)
|
|
def test_handler_normalizes_marker_shapes_to_bare_hash(
|
|
plugin: types.ModuleType, monkeypatch: pytest.MonkeyPatch, raw: str, expected: str
|
|
) -> None:
|
|
# Arrange
|
|
seen: dict[str, Any] = {}
|
|
|
|
def fake_post(url: str, json: dict[str, Any], timeout: int) -> _FakeResponse: # noqa: A002
|
|
seen["payload"] = json
|
|
return _FakeResponse(200, {"original_content": "data", "original_tokens": 1})
|
|
|
|
monkeypatch.setattr(plugin.httpx, "post", fake_post)
|
|
|
|
# Act
|
|
plugin._handle_headroom_retrieve({"hash": raw})
|
|
|
|
# Assert
|
|
assert seen["payload"]["hash"] == expected
|
|
|
|
|
|
def test_handler_ignores_legacy_query(
|
|
plugin: types.ModuleType, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
# Retrieval is by hash only; a legacy ``query`` in the args is dropped,
|
|
# not forwarded to the proxy.
|
|
seen: dict[str, Any] = {}
|
|
|
|
def fake_post(url: str, json: dict[str, Any], timeout: int) -> _FakeResponse: # noqa: A002
|
|
seen["payload"] = json
|
|
return _FakeResponse(200, {"original_content": "data"})
|
|
|
|
monkeypatch.setattr(plugin.httpx, "post", fake_post)
|
|
|
|
# Act
|
|
plugin._handle_headroom_retrieve({"hash": "abc123", "query": "error lines"})
|
|
|
|
# Assert
|
|
assert seen["payload"] == {"hash": "abc123"}
|
|
|
|
|
|
def test_handler_returns_original_content_on_200(
|
|
plugin: types.ModuleType, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
# Arrange
|
|
payload = {"original_content": "full text", "original_tokens": 42, "tool_name": "read_file"}
|
|
monkeypatch.setattr(plugin.httpx, "post", lambda *a, **kw: _FakeResponse(200, payload))
|
|
|
|
# Act
|
|
out = json.loads(plugin._handle_headroom_retrieve({"hash": "abc123"}))
|
|
|
|
# Assert
|
|
assert out["result"]["original_content"] == "full text"
|
|
assert out["result"]["original_tokens"] == 42
|
|
assert out["result"]["tool_name"] == "read_file"
|
|
|
|
|
|
def test_handler_reports_expired_entry_on_404(
|
|
plugin: types.ModuleType, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
# Arrange
|
|
monkeypatch.setattr(plugin.httpx, "post", lambda *a, **kw: _FakeResponse(404))
|
|
|
|
# Act
|
|
out = json.loads(plugin._handle_headroom_retrieve({"hash": "deadbeef"}))
|
|
|
|
# Assert: actionable message, not a bare error
|
|
assert "expired" in out["error"]
|
|
assert "re-run" in out["error"].lower()
|
|
|
|
|
|
def test_handler_reports_unreachable_proxy_on_connection_error(
|
|
plugin: types.ModuleType, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
# Arrange
|
|
def raise_connect_error(*a: Any, **kw: Any) -> None:
|
|
raise httpx.ConnectError("connection refused")
|
|
|
|
monkeypatch.setattr(plugin.httpx, "post", raise_connect_error)
|
|
|
|
# Act
|
|
out = json.loads(plugin._handle_headroom_retrieve({"hash": "abc123"}))
|
|
|
|
# Assert
|
|
assert "unreachable" in out["error"]
|
|
|
|
|
|
def test_handler_rejects_empty_hash(plugin: types.ModuleType) -> None:
|
|
# Act
|
|
out = json.loads(plugin._handle_headroom_retrieve({"hash": " "}))
|
|
|
|
# Assert
|
|
assert "required" in out["error"]
|
|
|
|
|
|
def test_register_exposes_tool_with_marker_aware_schema(plugin: types.ModuleType) -> None:
|
|
# Arrange
|
|
registered: dict[str, Any] = {}
|
|
|
|
class FakeCtx:
|
|
def register_tool(self, **kwargs: Any) -> None:
|
|
registered.update(kwargs)
|
|
|
|
# Act
|
|
plugin.register(FakeCtx())
|
|
|
|
# Assert
|
|
assert registered["name"] == "headroom_retrieve"
|
|
assert registered["toolset"] == "headroom"
|
|
assert registered["schema"]["parameters"]["required"] == ["hash"]
|
|
# The description must teach both marker formats so the model recognizes them.
|
|
description = registered["schema"]["description"]
|
|
assert "<<ccr:" in description
|
|
assert "hash=" in description
|