feat(STATE-WP-0064): wire consistency_sweep_remote_all state-hub query

Add POST /consistency/sweep/remote-all resolver support with a 330s
timeout and k8s projection for the consistency sweep definition.
This commit is contained in:
2026-06-21 20:19:22 +02:00
parent dbd2fbb11c
commit 3a981cc98f
3 changed files with 122 additions and 2 deletions

View File

@@ -407,6 +407,70 @@ def test_recently_on_scope_hourly_failure_bubbles(monkeypatch) -> None:
StateHubContextResolver().resolve("recently_on_scope_hourly", None, {"range": "1h"})
def test_consistency_sweep_remote_all_posts_batch(monkeypatch) -> None:
calls: list[dict[str, Any]] = []
def fake_post(url: str, **kwargs: Any) -> DummyResponse:
calls.append({"url": url, **kwargs})
return DummyResponse(
{
"exit_code": 0,
"lock_skipped": False,
"repos_processed": [{"repo_slug": "state-hub", "result": "pass"}],
"skipped_clean": ["quiet-repo"],
"skipped_missing": [],
"skipped_budget": [],
}
)
monkeypatch.setenv("STATE_HUB_URL", "http://state-hub.test/")
monkeypatch.setattr(httpx, "post", fake_post)
result = StateHubContextResolver().resolve(
"consistency_sweep_remote_all",
None,
{"max_seconds": 300, "required": True},
)
assert result["exit_code"] == 0
assert result["repos_processed"][0]["repo_slug"] == "state-hub"
assert calls == [
{
"url": "http://state-hub.test/consistency/sweep/remote-all",
"json": {"max_seconds": 300},
"timeout": 330.0,
}
]
def test_consistency_sweep_remote_all_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(
"consistency_sweep_remote_all",
None,
{"max_seconds": 300},
)
def test_consistency_sweep_remote_all_rejects_empty_response(monkeypatch) -> None:
def fake_post(url: str, **kwargs: Any) -> DummyResponse:
return DummyResponse({})
monkeypatch.setattr(httpx, "post", fake_post)
with pytest.raises(RuntimeError, match="missing required key"):
StateHubContextResolver().resolve(
"consistency_sweep_remote_all",
None,
{"max_seconds": 300},
)
def test_recently_on_scope_hourly_rejects_empty_response(monkeypatch) -> None:
def fake_post(url: str, **kwargs: Any) -> DummyResponse:
return DummyResponse({})