generated from coulomb/repo-seed
Extend State Hub context resolver for daily triage
This commit is contained in:
117
tests/test_state_hub_context_resolver.py
Normal file
117
tests/test_state_hub_context_resolver.py
Normal file
@@ -0,0 +1,117 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
from activity_core.context_resolvers.state_hub import StateHubContextResolver
|
||||
|
||||
|
||||
class DummyResponse:
|
||||
def __init__(self, payload: Any, status_error: Exception | None = None) -> None:
|
||||
self.payload = payload
|
||||
self.status_error = status_error
|
||||
|
||||
def raise_for_status(self) -> None:
|
||||
if self.status_error is not None:
|
||||
raise self.status_error
|
||||
|
||||
def json(self) -> Any:
|
||||
return self.payload
|
||||
|
||||
|
||||
def test_state_summary_query(monkeypatch) -> None:
|
||||
calls: list[dict[str, Any]] = []
|
||||
|
||||
def fake_get(url: str, **kwargs: Any) -> DummyResponse:
|
||||
calls.append({"url": url, **kwargs})
|
||||
return DummyResponse({"tasks": {"todo": 3}})
|
||||
|
||||
monkeypatch.setenv("STATE_HUB_URL", "http://state-hub.test")
|
||||
monkeypatch.setattr(httpx, "get", fake_get)
|
||||
|
||||
result = StateHubContextResolver().resolve("state_summary", None, {})
|
||||
|
||||
assert result == {"tasks": {"todo": 3}}
|
||||
assert calls == [
|
||||
{
|
||||
"url": "http://state-hub.test/state/summary",
|
||||
"params": None,
|
||||
"timeout": 10.0,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_daily_triage_queries(monkeypatch) -> None:
|
||||
calls: list[dict[str, Any]] = []
|
||||
|
||||
def fake_get(url: str, **kwargs: Any) -> DummyResponse:
|
||||
calls.append({"url": url, **kwargs})
|
||||
return DummyResponse({"url": url, "params": kwargs.get("params")})
|
||||
|
||||
monkeypatch.setenv("STATE_HUB_URL", "http://state-hub.test/")
|
||||
monkeypatch.setattr(httpx, "get", fake_get)
|
||||
resolver = StateHubContextResolver()
|
||||
|
||||
resolver.resolve("next_steps", None, {})
|
||||
resolver.resolve("workplan_index", None, {"refresh": False})
|
||||
resolver.resolve("hub_inbox", None, {"to_agent": "hub", "unread_only": True})
|
||||
|
||||
assert calls == [
|
||||
{
|
||||
"url": "http://state-hub.test/state/next_steps",
|
||||
"params": None,
|
||||
"timeout": 10.0,
|
||||
},
|
||||
{
|
||||
"url": "http://state-hub.test/workstreams/workplan-index",
|
||||
"params": {"refresh": False},
|
||||
"timeout": 10.0,
|
||||
},
|
||||
{
|
||||
"url": "http://state-hub.test/messages/",
|
||||
"params": {"to_agent": "hub", "unread_only": True},
|
||||
"timeout": 10.0,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_existing_queries_still_resolve(monkeypatch) -> None:
|
||||
calls: list[dict[str, Any]] = []
|
||||
|
||||
def fake_get(url: str, **kwargs: Any) -> DummyResponse:
|
||||
calls.append({"url": url, **kwargs})
|
||||
return DummyResponse({"ok": True})
|
||||
|
||||
monkeypatch.setenv("STATE_HUB_URL", "http://state-hub.test")
|
||||
monkeypatch.setattr(httpx, "get", fake_get)
|
||||
resolver = StateHubContextResolver()
|
||||
|
||||
assert resolver.resolve("domain_summary", None, {"domain": "custodian"}) == {"ok": True}
|
||||
assert resolver.resolve("repo_sbom_status", None, {"repo_slug": "activity-core"}) == {"ok": True}
|
||||
|
||||
assert calls == [
|
||||
{
|
||||
"url": "http://state-hub.test/state/domain/custodian",
|
||||
"params": None,
|
||||
"timeout": 10.0,
|
||||
},
|
||||
{
|
||||
"url": "http://state-hub.test/sbom/status",
|
||||
"params": {"repo": "activity-core"},
|
||||
"timeout": 10.0,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_resolver_failure_returns_empty(monkeypatch) -> None:
|
||||
def fake_get(url: str, **kwargs: Any) -> DummyResponse:
|
||||
raise httpx.ConnectError("offline")
|
||||
|
||||
monkeypatch.setattr(httpx, "get", fake_get)
|
||||
|
||||
assert StateHubContextResolver().resolve("state_summary", None, {}) == {}
|
||||
|
||||
|
||||
def test_unknown_query_returns_empty() -> None:
|
||||
assert StateHubContextResolver().resolve("unknown", None, {}) == {}
|
||||
Reference in New Issue
Block a user