Add State Hub RecentlyOnScope invocation

This commit is contained in:
2026-05-22 16:14:10 +02:00
parent f4c38e2d5f
commit 5055f3eaca
4 changed files with 73 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
from typing import Any
import httpx
import pytest
from activity_core.context_resolvers.state_hub import StateHubContextResolver
@@ -117,6 +118,47 @@ def test_unknown_query_returns_empty() -> None:
assert StateHubContextResolver().resolve("unknown", None, {}) == {}
def test_recently_on_scope_hourly_posts_batch(monkeypatch) -> None:
calls: list[dict[str, Any]] = []
def fake_post(url: str, **kwargs: Any) -> DummyResponse:
calls.append({"url": url, **kwargs})
return DummyResponse({"generated": [{"domain_slug": "custodian"}]})
monkeypatch.setenv("STATE_HUB_URL", "http://state-hub.test/")
monkeypatch.setattr(httpx, "post", fake_post)
result = StateHubContextResolver().resolve(
"recently_on_scope_hourly",
None,
{
"range": "1h",
"active_only": True,
"include_attention": False,
"required": True,
},
)
assert result == {"generated": [{"domain_slug": "custodian"}]}
assert calls == [
{
"url": "http://state-hub.test/recently-on-scope/hourly",
"json": {"range": "1h", "active_only": True, "include_attention": False},
"timeout": 10.0,
}
]
def test_recently_on_scope_hourly_failure_bubbles(monkeypatch) -> None:
def fake_post(url: str, **kwargs: Any) -> DummyResponse:
raise httpx.ConnectError("offline")
monkeypatch.setattr(httpx, "post", fake_post)
with pytest.raises(httpx.ConnectError):
StateHubContextResolver().resolve("recently_on_scope_hourly", None, {"range": "1h"})
def test_daily_triage_digest_is_curated_scalar_json(monkeypatch) -> None:
payloads = {
"/state/summary": {