160-tool MCP server for real-time global intelligence from free public APIs: markets, liquidity, prediction markets, SEC filings, conflict, military, aircraft-cohort early warning, migration and border flows, cyber, climate, news and more. Dated observation history, 29 research prompts, cited briefs, geofences, SSE dashboard. MIT, no paid API keys.
Python ai-toolsai-watchanthropicclaudecybersecuritydashboardgeofencinggeopoliticalgeospatialintelligencemarketsmcpmigrationmilitarymodel-context-protocolnuclearosintreal-timespace-weatherthreat-intelligence
Tests: bound the spacing test's wait; pin cache-served answers unthrottled
Phoenix Agent (mac-studio)743c9a99827e
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 9666281..1fde529 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -9,6 +9,10 @@ on:jobs:test:runs-on: ubuntu-latest+ # A full run takes a few minutes. A hung test (a deadlocked asyncio+ # lock prints nothing and uses no CPU) fails the job here instead of+ # holding the runner until the 6-hour platform default.+ timeout-minutes: 20strategy:matrix:python-version: ["3.11", "3.12"]diff --git a/src/world_intel_mcp/tests/test_fetcher_cache_paths_unthrottled.py b/src/world_intel_mcp/tests/test_fetcher_cache_paths_unthrottled.pynew file mode 100644index 0000000..3fea09e--- /dev/null+++ b/src/world_intel_mcp/tests/test_fetcher_cache_paths_unthrottled.py@@ -0,0 +1,83 @@+"""An answer that sends no request must not wait out the source's spacing.++Per-source spacing protects the upstream; a fresh cache hit, a stale copy+served while the source's breaker is open, or an open-breaker refusal+sends nothing, so it returns at once. One real request stamps the source+just before, so any throttle on these paths would have to sleep.+"""++import httpx+import pytest++from world_intel_mcp import fetcher as fetcher_mod+from world_intel_mcp.circuit_breaker import CircuitBreaker+from world_intel_mcp.fetcher import Fetcher++_SOURCE = "nominatim" # 1.1 s spacing in _SOURCE_RATE_LIMITS+++def recorded_sleeps(monkeypatch) -> list[float]:+ sleeps: list[float] = []++ async def sleep(delay):+ sleeps.append(delay)++ monkeypatch.setattr(fetcher_mod.asyncio, "sleep", sleep)+ return sleeps+++def _upstream(requests: list[str]) -> httpx.MockTransport:+ def respond(request):+ requests.append(request.url.path)+ if request.url.path == "/seed":+ return httpx.Response(200, json={"v": 1})+ return httpx.Response(503)++ return httpx.MockTransport(respond)++[email protected]("method", ["get_json", "get_text", "get_xml"])[email protected]("path", ["fresh cache hit", "stale copy, breaker open"])+async def test_cache_served_answer_skips_the_spacing(+ cache, recorded_sleeps, method: str, path: str,+) -> None:+ requests: list[str] = []+ breaker = CircuitBreaker(failure_threshold=1)+ async with httpx.AsyncClient(transport=_upstream(requests)) as client:+ fetch = getattr(Fetcher(cache, breaker, client=client, max_retries=0), method)+ ttl = 300 if path == "fresh cache hit" else -1+ seeded = await fetch("https://example.test/seed", _SOURCE, cache_key="k", cache_ttl=ttl)+ assert seeded is not None+ if path == "stale copy, breaker open":+ await fetch("https://example.test/down", _SOURCE, cache_key="down")+ assert not breaker.is_available(_SOURCE)+ sent, slept = len(requests), len(recorded_sleeps)++ result = await fetch("https://example.test/seed", _SOURCE, cache_key="k")++ assert len(requests) == sent, "the cache-served answer sent a request"+ assert recorded_sleeps[slept:] == [], "the cache-served answer waited for the source"+ if method == "get_json":+ assert result["v"] == 1+ assert result.get("_stale", False) is (path == "stale copy, breaker open")+ else:+ assert result == seeded+++async def test_open_breaker_binary_refusal_skips_the_spacing(+ cache, recorded_sleeps,+) -> None:+ requests: list[str] = []+ breaker = CircuitBreaker(failure_threshold=1)+ async with httpx.AsyncClient(transport=_upstream(requests)) as client:+ fetcher = Fetcher(cache, breaker, client=client, max_retries=0)+ await fetcher.get_bytes("https://example.test/down", _SOURCE)+ assert not breaker.is_available(_SOURCE)+ sent, slept = len(requests), len(recorded_sleeps)++ result = await fetcher.get_bytes("https://example.test/down", _SOURCE)++ assert result.error == f"circuit open for {_SOURCE}"+ assert len(requests) == sent+ assert recorded_sleeps[slept:] == []diff --git a/src/world_intel_mcp/tests/test_fetcher_retry_spacing.py b/src/world_intel_mcp/tests/test_fetcher_retry_spacing.pyindex 42bbbd2..8b1c3c6 100644--- a/src/world_intel_mcp/tests/test_fetcher_retry_spacing.py+++ b/src/world_intel_mcp/tests/test_fetcher_retry_spacing.py@@ -1,11 +1,19 @@"""Each retry must be spaced from the most recent attempt for its source."""+import asyncio+import httpximport pytestfrom world_intel_mcp import fetcher as fetcher_modfrom world_intel_mcp.fetcher import Fetcher+# Real seconds the interleaved caller gets. Unblocked it needs milliseconds;+# the bound turns a sleep taken while holding the source's throttle (a+# double throttle, or a throttle on a cache hit) into a failed assertion+# instead of a suite that hangs on the lock.+_INTERLEAVED_CALL_TIMEOUT = 5.0+@pytest.mark.parametrize("method", ["get_json", "get_text", "get_xml", "get_bytes"])@pytest.mark.parametrize("source", ["ripestat", "nominatim", "adsblol"])@@ -15,6 +23,7 @@ async def test_retries_respect_spacing_after_another_request(now = 100.0attempts = []interleaved = False+ blocked = []def respond(request):attempts.append(now)@@ -30,12 +39,23 @@ async def test_retries_respect_spacing_after_another_request(if not interleaved:# Another caller reaches this source while the first backs off.interleaved = True- await getattr(other, method)("https://example.test/other", source)+ try:+ await asyncio.wait_for(+ getattr(other, method)("https://example.test/other", source),+ _INTERLEAVED_CALL_TIMEOUT,+ )+ except TimeoutError:+ blocked.append(delay)monkeypatch.setattr(fetcher_mod.time, "time", lambda: now)monkeypatch.setattr(fetcher_mod.asyncio, "sleep", sleep)await getattr(primary, method)("https://example.test/primary", source)+ assert blocked == [], (+ f"the other caller was still waiting for {source} after "+ f"{_INTERLEAVED_CALL_TIMEOUT:.0f} s: the first caller slept "+ f"{blocked[0]} s while holding that source's throttle"+ )assert len(attempts) == 4 # three primary attempts and one other callerfloor = fetcher_mod._SOURCE_RATE_LIMITS[source]assert all(