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
intel aoi CLI group: full terminal parity for the nine AOI operations
Phoenix Agent (Marcs-Mac-Studio)e7b4d0f2e70d
diff --git a/src/world_intel_mcp/cli.py b/src/world_intel_mcp/cli.pyindex 609503e..d67ea80 100644--- a/src/world_intel_mcp/cli.py+++ b/src/world_intel_mcp/cli.py@@ -20,6 +20,7 @@ Two rendering conventions keep the output honest:import asyncioimport json+from datetime import datetime, timezonefrom typing import Anyimport click@@ -30,6 +31,7 @@ from rich.text import Textfrom rich.panel import Panelfrom rich import box+from .analysis import aoi as aoi_analysisfrom .cache import Cachefrom .circuit_breaker import CircuitBreakerfrom .fetcher import Fetcher@@ -2029,5 +2031,352 @@ def report()+# ---------------------------------------------------------------------------+# AOI geofences+# ---------------------------------------------------------------------------++# AOI store — lazily initialized against the same physical SQLite file the+# CLI's Cache resolved to (fallback path included), mirroring how+# runtime.py builds the MCP server's store from its own cache.db_path.+_aoi_store: aoi_analysis.AOIStore | None = None+++def _get_aoi_store() -> aoi_analysis.AOIStore:+ global _aoi_store+ if _aoi_store is None:+ _aoi_store = aoi_analysis.AOIStore(_get_fetcher().cache.db_path)+ return _aoi_store+++def _parse_latlon_pairs(+ ctx: click.Context, param: click.Parameter, value: tuple[str, ...]+) -> list[list[float]]:+ """Parse repeated LAT,LON option values into [[lat, lon], ...].++ Only the syntax is checked here (a malformed pair is a usage error,+ exit 2); range and count rules belong to the analysis layer, which+ reports them as {"error": ...} dicts through _bail_on_error.+ """+ pairs: list[list[float]] = []+ for raw in value:+ parts = raw.split(",")+ if len(parts) != 2:+ raise click.BadParameter(f"expected LAT,LON (got {raw!r})")+ try:+ pairs.append([float(parts[0]), float(parts[1])])+ except ValueError:+ raise click.BadParameter(+ f"expected numeric LAT,LON (got {raw!r})"+ ) from None+ return pairs+++def _print_data_gaps(data: dict) -> None:+ for gap in data.get("data_gaps", []):+ console.print(f"[yellow]Gap:[/yellow] {escape(str(gap))}")++[email protected](name="aoi")+def aoi_group() -> None:+ """User-defined areas of interest (AOIs/geofences)."""+++@aoi_group.command(name="define")[email protected]("name")[email protected]("--lat", type=float, required=True, help="Center latitude, -90..90")[email protected]("--lon", type=float, required=True, help="Center longitude, -180..180")+ "--radius-km", type=float, required=True, help="Radius in kilometers, 1..2000"+)[email protected]_context+def aoi_define(+ ctx: click.Context, name: str, lat: float, lon: float, radius_km: float+) -> None:+ """Define a point-radius AOI."""+ data = aoi_analysis.define_aoi(+ _get_aoi_store(), name=name, lat=lat, lon=lon, radius_km=radius_km+ )+ if _bail_on_error(ctx, data):+ return+ a = data["aoi"]+ console.print(+ f"AOI [bold]{escape(str(a['name']))}[/bold] defined: "+ f"center {a['lat']}, {a['lon']} (radius {a['radius_km']:g} km)"+ )+++@aoi_group.command(name="define-polygon")[email protected]("name")+ "--vertex",+ "vertices",+ multiple=True,+ metavar="LAT,LON",+ callback=_parse_latlon_pairs,+ help="Polygon vertex as LAT,LON; repeat 3-64 times",+)[email protected]_context+def aoi_define_polygon(+ ctx: click.Context, name: str, vertices: list[list[float]]+) -> None:+ """Define a polygon AOI from repeated --vertex LAT,LON."""+ data = aoi_analysis.define_polygon_aoi(+ _get_aoi_store(), name=name, vertices=vertices+ )+ if _bail_on_error(ctx, data):+ return+ a = data["aoi"]+ n_vertices = len((a.get("geometry") or {}).get("vertices", []))+ console.print(+ f"Polygon AOI [bold]{escape(str(a['name']))}[/bold] defined: "+ f"{n_vertices} vertices, bounding radius {a['radius_km']:.0f} km "+ f"around {a['lat']:.4f}, {a['lon']:.4f}"+ )+++@aoi_group.command(name="define-corridor")[email protected]("name")+ "--waypoint",+ "waypoints",+ multiple=True,+ metavar="LAT,LON",+ callback=_parse_latlon_pairs,+ help="Route waypoint as LAT,LON; repeat 2-64 times",+)+ "--width-km", type=float, required=True, help="Total corridor width in km, 1..500"+)[email protected]_context+def aoi_define_corridor(+ ctx: click.Context, name: str, waypoints: list[list[float]], width_km: float+) -> None:+ """Define a corridor AOI from repeated --waypoint LAT,LON plus a width."""+ data = aoi_analysis.define_corridor_aoi(+ _get_aoi_store(), name=name, waypoints=waypoints, width_km=width_km+ )+ if _bail_on_error(ctx, data):+ return+ a = data["aoi"]+ geometry = a.get("geometry") or {}+ console.print(+ f"Corridor AOI [bold]{escape(str(a['name']))}[/bold] defined: "+ f"{len(geometry.get('waypoints', []))} waypoints, width "+ f"{geometry.get('width_km', width_km):g} km, bounding radius "+ f"{a['radius_km']:.0f} km"+ )+++@aoi_group.command(name="list")[email protected]_context+def aoi_list_cmd(ctx: click.Context) -> None:+ """List defined AOIs."""+ data = aoi_analysis.list_aois(_get_aoi_store())+ if _bail_on_error(ctx, data):+ return++ aois = data.get("aois", [])+ if not aois:+ console.print("[yellow]No AOIs defined[/yellow]")+ return++ table = Table(title=f"Areas of Interest ({len(aois)})", box=box.SIMPLE_HEAVY)+ table.add_column("Name", style="bold")+ table.add_column("Kind")+ table.add_column("Center", justify="right")+ table.add_column("Radius km", justify="right")+ table.add_column("Created")++ for a in aois:+ created = datetime.fromtimestamp(+ a.get("created_at", 0), tz=timezone.utc+ ).strftime("%Y-%m-%d")+ table.add_row(+ _cell(a.get("name", "")),+ _cell(a.get("kind", "circle")),+ f"{a.get('lat', 0):.4f}, {a.get('lon', 0):.4f}",+ f"{a.get('radius_km', 0):,.0f}",+ created,+ )+ console.print(table)+++@aoi_group.command(name="update")[email protected]("name")[email protected]("--new-name", default=None, help="New name (must not collide)")[email protected]("--lat", type=float, default=None, help="New center latitude")[email protected]("--lon", type=float, default=None, help="New center longitude")[email protected]("--radius-km", type=float, default=None, help="New radius in km")[email protected]_context+def aoi_update(+ ctx: click.Context,+ name: str,+ new_name: str | None,+ lat: float | None,+ lon: float | None,+ radius_km: float | None,+) -> None:+ """Rename an AOI and/or change a circle's center or radius."""+ data = aoi_analysis.update_aoi(+ _get_aoi_store(),+ name=name,+ new_name=new_name,+ lat=lat,+ lon=lon,+ radius_km=radius_km,+ )+ if _bail_on_error(ctx, data):+ return+ a = data["aoi"]+ console.print(+ f"AOI [bold]{escape(str(a['name']))}[/bold] updated: "+ f"center {a['lat']}, {a['lon']} (radius {a['radius_km']:g} km)"+ )+ if data.get("snapshot_dropped"):+ console.print(+ "[yellow]Change-detection baseline dropped (geometry changed); "+ "the next 'intel aoi changes' sweep re-baselines.[/yellow]"+ )+++@aoi_group.command(name="delete")[email protected]("name")[email protected]_context+def aoi_delete(ctx: click.Context, name: str) -> None:+ """Delete a defined AOI."""+ data = aoi_analysis.delete_aoi(_get_aoi_store(), name=name)+ if _bail_on_error(ctx, data):+ return+ console.print(f"Deleted AOI [bold]{escape(str(data.get('deleted', name)))}[/bold]")+++@aoi_group.command(name="brief")[email protected]("name")[email protected]_context+def aoi_brief(ctx: click.Context, name: str) -> None:+ """Cited brief for a defined AOI (data gaps included)."""+ data = _run(+ aoi_analysis.fetch_aoi_brief(_get_fetcher(), _get_aoi_store(), name=name)+ )+ if _bail_on_error(ctx, data):+ return+ # The brief's markdown embeds remote free text (news titles, place+ # names); Text renders it literally, never through the markup parser.+ # Its Data Gaps section is part of the markdown itself.+ console.print(Text(str(data.get("markdown", ""))))+++@aoi_group.command(name="escalation")[email protected]("name")[email protected]_context+def aoi_escalation(ctx: click.Context, name: str) -> None:+ """Escalation score (0-100) for a defined AOI."""+ data = _run(+ aoi_analysis.fetch_aoi_escalation(_get_fetcher(), _get_aoi_store(), name=name)+ )+ if _bail_on_error(ctx, data):+ return++ a = data.get("aoi", {})+ level = data.get("level", "")+ l_style = {+ "critical": "red bold",+ "elevated": "yellow",+ "watch": "dim",+ }.get(level, "")+ level_str = (+ f"[{l_style}]{escape(str(level))}[/{l_style}]"+ if l_style+ else escape(str(level))+ )+ console.print(+ f"[bold]{escape(str(a.get('name', name)))}[/bold] escalation: "+ f"{data.get('score', 0)}/100 ({level_str}, "+ f"trend {escape(str(data.get('trend_signal', '')))})"+ )++ table = Table(title="Components", box=box.SIMPLE_HEAVY)+ table.add_column("Component", style="bold")+ table.add_column("Points", justify="right")+ for comp, points in data.get("components", {}).items():+ if points is None:+ table.add_row(_cell(comp), "[dim]not measured[/dim]")+ else:+ table.add_row(_cell(comp), f"{points:.1f}")+ console.print(table)+ _print_data_gaps(data)+++@aoi_group.command(name="changes")[email protected]("name")[email protected]_context+def aoi_changes(ctx: click.Context, name: str) -> None:+ """What entered or left a defined AOI since the last sweep."""+ data = _run(+ aoi_analysis.fetch_aoi_changes(_get_fetcher(), _get_aoi_store(), name=name)+ )+ if _bail_on_error(ctx, data):+ return++ a = data.get("aoi", {})+ changes = data.get("changes", {})+ if data.get("baseline"):+ console.print(+ f"Baseline established for [bold]{escape(str(a.get('name', name)))}[/bold]"+ ": nothing is claimed to have entered or left; run again to diff."+ )+ table = Table(title="Baseline Observations", box=box.SIMPLE_HEAVY)+ table.add_column("Domain", style="bold")+ table.add_column("Observed", justify="right")+ for domain, info in changes.items():+ table.add_row(_cell(domain), str(info.get("unchanged", 0)))+ console.print(table)+ _print_data_gaps(data)+ return++ prev = data.get("previous_taken_at")+ if prev:+ console.print(f"[dim]Previous sweep: {escape(str(prev))}[/dim]")++ table = Table(+ title=f"AOI Changes — {escape(str(a.get('name', name)))}",+ box=box.SIMPLE_HEAVY,+ )+ table.add_column("Domain", style="bold")+ table.add_column("New", justify="right")+ table.add_column("Departed", justify="right")+ table.add_column("Unchanged", justify="right")+ for domain, info in changes.items():+ if info.get("baseline"):+ # A domain first seen this sweep: a baseline, not churn.+ table.add_row(+ _cell(domain),+ "[dim]baseline[/dim]",+ "[dim]baseline[/dim]",+ str(info.get("unchanged", 0)),+ )+ else:+ table.add_row(+ _cell(domain),+ str(len(info.get("new", []))),+ str(len(info.get("departed", []))),+ str(info.get("unchanged", 0)),+ )+ console.print(table)++ for domain, info in changes.items():+ for item in info.get("new", []):+ console.print(+ f" [green]+[/green] {escape(str(domain))}: "+ f"{escape(str(item.get('summary', '')))}"+ )+ for item in info.get("departed", []):+ console.print(+ f" [red]-[/red] {escape(str(domain))}: "+ f"{escape(str(item.get('summary', '')))}"+ )+ _print_data_gaps(data)++if __name__ == "__main__":main()diff --git a/src/world_intel_mcp/tests/test_cli.py b/src/world_intel_mcp/tests/test_cli.pyindex edf912e..e3a1085 100644--- a/src/world_intel_mcp/tests/test_cli.py+++ b/src/world_intel_mcp/tests/test_cli.py@@ -50,6 +50,7 @@ def _cli_isolation(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.setenv("WORLD_INTEL_CACHE_DB", str(tmp_path / "cli-cache.db"))monkeypatch.setenv("COLUMNS", "200")monkeypatch.setattr(cli, "_fetcher", None)+ monkeypatch.setattr(cli, "_aoi_store", None, raising=False)def _invoke(*args: str):@@ -127,12 +128,13 @@ def test_command_registry() -> None:"sync","dashboard","report",+ "aoi",} <= names# webcams_cmd has no explicit name=, but click >= 8.1 strips the# `_cmd` suffix when deriving default command names, so the# user-facing name still comes out right.assert "webcams" in names- assert len(names) == 53+ assert len(names) == 54# ---------------------------------------------------------------------------@@ -2078,3 +2080,483 @@ def test_error_dict_reaches_table_output(assert "Error:" in result.outputassert "upstream exploded" in result.outputassert '"error"' not in result.output+++# ---------------------------------------------------------------------------+# AOI geofences: intel aoi <define|define-polygon|define-corridor|list|+# update|delete|brief|escalation|changes>+#+# CRUD subcommands exercise the real AOIStore against the tmp SQLite file+# the _cli_isolation fixture points WORLD_INTEL_CACHE_DB at (the+# test_server_registry pattern); the network-bound brief/escalation/changes+# subcommands fake the analysis functions at the cli.aoi_analysis boundary,+# same as every other faked fetch in this file.+# ---------------------------------------------------------------------------+++def _define_zone(name: str = "TestZone") -> None:+ result = _invoke(+ "aoi", "define", name, "--lat", "12.5", "--lon", "45.25", "--radius-km", "150"+ )+ assert result.exit_code == 0, result.output+++def test_aoi_subcommand_registry() -> None:+ assert set(cli.aoi_group.commands) == {+ "define",+ "define-polygon",+ "define-corridor",+ "list",+ "update",+ "delete",+ "brief",+ "escalation",+ "changes",+ }+++def test_aoi_store_shares_the_fetchers_cache_db() -> None:+ # Mirrors runtime.py: the AOIStore must land in the literal SQLite+ # file the process's Cache resolved to, not a fresh default-path+ # computation.+ _define_zone()+ assert cli._aoi_store is not None+ assert cli._fetcher is not None+ assert cli._aoi_store.db_path == cli._fetcher.cache.db_path+ assert cli._aoi_store.db_path.name == "cli-cache.db"+++def test_aoi_define_and_list_roundtrip() -> None:+ _define_zone()+ result = _invoke("aoi", "list")+ assert result.exit_code == 0+ assert "TestZone" in result.output+ assert "circle" in result.output+ assert "150" in result.output+++def test_aoi_define_ack_names_center_and_radius() -> None:+ result = _invoke(+ "aoi",+ "define",+ "TestZone",+ "--lat",+ "12.5",+ "--lon",+ "45.25",+ "--radius-km",+ "150",+ )+ assert result.exit_code == 0+ assert "TestZone" in result.output+ assert "12.5" in result.output+ assert "45.25" in result.output+ assert "150" in result.output+++def test_aoi_define_duplicate_is_error_not_overwrite() -> None:+ _define_zone()+ result = _invoke(+ "aoi",+ "define",+ "testzone",+ "--lat",+ "1.5",+ "--lon",+ "2.5",+ "--radius-km",+ "10",+ )+ assert result.exit_code == 0+ assert "Error:" in result.output+ assert "already exists" in result.output+++def test_aoi_define_invalid_lat_surfaces_error_dict() -> None:+ result = _invoke(+ "aoi", "define", "Bad", "--lat", "95", "--lon", "0.5", "--radius-km", "50"+ )+ assert result.exit_code == 0+ assert "Error:" in result.output+ assert "lat must be between -90 and 90" in result.output+++def test_aoi_define_json_mode_passes_raw_dict() -> None:+ result = _invoke(+ "--json-output",+ "aoi",+ "define",+ "TestZone",+ "--lat",+ "12.5",+ "--lon",+ "45.25",+ "--radius-km",+ "150",+ )+ assert result.exit_code == 0+ assert '"aoi"' in result.output+ assert '"TestZone"' in result.output+++def test_aoi_list_empty_prints_no_aois_message() -> None:+ result = _invoke("aoi", "list")+ assert result.exit_code == 0+ assert "No AOIs defined" in result.output+++def test_aoi_list_json_mode_passes_raw_dict() -> None:+ _define_zone()+ result = _invoke("--json-output", "aoi", "list")+ assert result.exit_code == 0+ assert '"aois"' in result.output+ assert '"count"' in result.output+++def test_aoi_define_polygon_and_corridor_kinds_listed() -> None:+ poly = _invoke(+ "aoi",+ "define-polygon",+ "TriZone",+ "--vertex",+ "12.5,45.0",+ "--vertex",+ "13.0,45.5",+ "--vertex",+ "12.0,46.0",+ )+ assert poly.exit_code == 0, poly.output+ assert "TriZone" in poly.output+ assert "3" in poly.output # vertex count in the ack++ corr = _invoke(+ "aoi",+ "define-corridor",+ "LaneZone",+ "--waypoint",+ "10.5,40.0",+ "--waypoint",+ "11.5,41.0",+ "--width-km",+ "50",+ )+ assert corr.exit_code == 0, corr.output+ assert "LaneZone" in corr.output+ assert "2" in corr.output # waypoint count in the ack+ assert "50" in corr.output++ listing = _invoke("aoi", "list")+ assert "polygon" in listing.output+ assert "corridor" in listing.output+++def test_aoi_define_polygon_bad_vertex_format_is_usage_error() -> None:+ result = _invoke("aoi", "define-polygon", "Bad", "--vertex", "12.5")+ assert result.exit_code == 2+ assert "expected LAT,LON" in result.output+++def test_aoi_define_polygon_nonnumeric_vertex_is_usage_error() -> None:+ result = _invoke("aoi", "define-polygon", "Bad", "--vertex", "a,b")+ assert result.exit_code == 2+ assert "expected numeric LAT,LON" in result.output+++def test_aoi_define_polygon_too_few_vertices_surfaces_error_dict() -> None:+ # Count/range rules live in the analysis layer; the CLI surfaces its+ # error dict through the shared red Error line.+ result = _invoke(+ "aoi", "define-polygon", "Duo", "--vertex", "12.5,45.0", "--vertex", "13.0,45.5"+ )+ assert result.exit_code == 0+ assert "Error:" in result.output+ assert "at least 3" in result.output+++def test_aoi_define_corridor_missing_width_is_usage_error() -> None:+ result = _invoke(+ "aoi",+ "define-corridor",+ "Lane",+ "--waypoint",+ "10.5,40.0",+ "--waypoint",+ "11.5,41.0",+ )+ assert result.exit_code == 2+ assert "--width-km" in result.output+++def test_aoi_define_corridor_width_out_of_range_surfaces_error_dict() -> None:+ result = _invoke(+ "aoi",+ "define-corridor",+ "Lane",+ "--waypoint",+ "10.5,40.0",+ "--waypoint",+ "11.5,41.0",+ "--width-km",+ "900",+ )+ assert result.exit_code == 0+ assert "Error:" in result.output+ assert "width_km must be between" in result.output+++def test_aoi_update_rename_keeps_baseline() -> None:+ _define_zone("Alpha")+ result = _invoke("aoi", "update", "Alpha", "--new-name", "Bravo")+ assert result.exit_code == 0+ assert "Bravo" in result.output+ assert "updated" in result.output+ assert "baseline dropped" not in result.output++ listing = _invoke("aoi", "list")+ assert "Bravo" in listing.output+ assert "Alpha" not in listing.output+++def test_aoi_update_geometry_change_reports_dropped_baseline() -> None:+ _define_zone("Alpha")+ result = _invoke("aoi", "update", "Alpha", "--radius-km", "300")+ assert result.exit_code == 0+ assert "300" in result.output+ assert "baseline dropped" in result.output+++def test_aoi_update_missing_aoi_surfaces_error_dict() -> None:+ result = _invoke("aoi", "update", "Ghost", "--new-name", "Spectre")+ assert result.exit_code == 0+ assert "Error:" in result.output+ assert "not found" in result.output+++def test_aoi_update_polygon_geometry_is_refused() -> None:+ poly = _invoke(+ "aoi",+ "define-polygon",+ "TriZone",+ "--vertex",+ "12.5,45.0",+ "--vertex",+ "13.0,45.5",+ "--vertex",+ "12.0,46.0",+ )+ assert poly.exit_code == 0+ result = _invoke("aoi", "update", "TriZone", "--lat", "20.5")+ assert result.exit_code == 0+ assert "Error:" in result.output+ assert "cannot be set directly" in result.output+++def test_aoi_delete_then_missing() -> None:+ _define_zone()+ result = _invoke("aoi", "delete", "TestZone")+ assert result.exit_code == 0+ assert "Deleted AOI" in result.output+ assert "TestZone" in result.output++ again = _invoke("aoi", "delete", "TestZone")+ assert again.exit_code == 0+ assert "Error:" in again.output+ assert "not found" in again.output+++_AOI_BRIEF = {+ "aoi": {+ "name": "TestZone",+ "lat": 12.5,+ "lon": 45.25,+ "radius_km": 150.0,+ "kind": "circle",+ },+ "markdown": (+ "# AOI Brief: TestZone\n"+ "Center: 12.5, 45.25 (radius 150.0 km)\n\n"+ "## Earthquakes\n"+ "- M5.1 near [red]Quaketown[/red] (12 km) [1]\n\n"+ "## Data Gaps\n"+ "- Wildfires: FIRMS key missing"+ ),+ "counts": {"earthquakes": 1},+ "sources": [{"n": 1, "title": "USGS", "url": "https://example.test/eq"}],+ "cited": True,+ "data_gaps": ["Wildfires: FIRMS key missing"],+ "source": "aoi-brief",+ "timestamp": "2026-09-01T00:00:00Z",+}+++def test_aoi_brief_renders_markdown_and_gaps(monkeypatch: pytest.MonkeyPatch) -> None:+ calls: list = []+ monkeypatch.setattr(cli.aoi_analysis, "fetch_aoi_brief", _fake(_AOI_BRIEF, calls))+ result = _invoke("aoi", "brief", "TestZone")+ assert result.exit_code == 0+ assert calls == [{"name": "TestZone"}]+ assert "AOI Brief: TestZone" in result.output+ assert "Wildfires: FIRMS key missing" in result.output+ # Remote free text in the brief renders literally, never as markup.+ assert "[red]Quaketown[/red]" in result.output+++def test_aoi_brief_error_dict_is_surfaced(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(+ cli.aoi_analysis, "fetch_aoi_brief", _fake({"error": "AOI 'X' not found."})+ )+ result = _invoke("aoi", "brief", "X")+ assert result.exit_code == 0+ assert "Error:" in result.output+ assert "not found" in result.output+++def test_aoi_brief_json_mode_passes_raw_dict(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(cli.aoi_analysis, "fetch_aoi_brief", _fake(_AOI_BRIEF))+ result = _invoke("--json-output", "aoi", "brief", "TestZone")+ assert result.exit_code == 0+ assert '"markdown"' in result.output+ assert '"data_gaps"' in result.output+++_AOI_ESCALATION = {+ "aoi": {+ "name": "TestZone",+ "lat": 12.5,+ "lon": 45.25,+ "radius_km": 150.0,+ "kind": "circle",+ },+ "score": 42.5,+ "components": {+ "baseline": 0.0,+ "news": None,+ "military": 12.0,+ "conflict": 18.5,+ "social_unrest": 0.4,+ "convergence": None,+ },+ "unavailable_components": ["news", "convergence"],+ "level": "elevated",+ "trend_signal": "rising",+ "data_gaps": ["Military flights: partial coverage: adsb window failed"],+ "source": "aoi-escalation",+ "timestamp": "2026-09-01T00:00:00Z",+}+++def test_aoi_escalation_renders_score_components_and_gaps(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ calls: list = []+ monkeypatch.setattr(+ cli.aoi_analysis, "fetch_aoi_escalation", _fake(_AOI_ESCALATION, calls)+ )+ result = _invoke("aoi", "escalation", "TestZone")+ assert result.exit_code == 0+ assert calls == [{"name": "TestZone"}]+ assert "42.5" in result.output+ assert "elevated" in result.output+ assert "rising" in result.output+ assert "18.5" in result.output+ # None components render as unmeasured, never a fabricated 0.0.+ assert "not measured" in result.output+ assert "adsb window failed" in result.output+++def test_aoi_escalation_error_dict_is_surfaced(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.setattr(+ cli.aoi_analysis, "fetch_aoi_escalation", _fake({"error": "AOI 'X' not found."})+ )+ result = _invoke("aoi", "escalation", "X")+ assert result.exit_code == 0+ assert "Error:" in result.output+ assert "not found" in result.output+ assert '"error"' not in result.output+++_AOI_CHANGES_BASELINE = {+ "aoi": {+ "name": "TestZone",+ "lat": 12.5,+ "lon": 45.25,+ "radius_km": 150.0,+ "kind": "circle",+ },+ "baseline": True,+ "previous_taken_at": None,+ "changes": {+ "earthquakes": {"new": [], "departed": [], "unchanged": 3, "baseline": True},+ "news": {"new": [], "departed": [], "unchanged": 1, "baseline": True},+ },+ "counts": {"earthquakes": 3, "news": 1},+ "data_gaps": [],+ "source": "aoi-changes",+ "timestamp": "2026-09-01T00:00:00Z",+}++_AOI_CHANGES_DIFF = {+ "aoi": {+ "name": "TestZone",+ "lat": 12.5,+ "lon": 45.25,+ "radius_km": 150.0,+ "kind": "circle",+ },+ "baseline": False,+ "previous_taken_at": "2026-09-01T10:00:00Z",+ "changes": {+ "earthquakes": {+ "new": [{"key": "eq-new", "summary": "M5.1 Quaketown (12 km)"}],+ "departed": [{"key": "eq-old", "summary": "M4.2 Oldplace (99 km)"}],+ "unchanged": 2,+ },+ "military_flights": {+ "new": [],+ "departed": [],+ "unchanged": 0,+ "baseline": True,+ },+ },+ "counts": {"earthquakes": 3, "military_flights": 0},+ "data_gaps": ["News: RSS down"],+ "source": "aoi-changes",+ "timestamp": "2026-09-01T12:00:00Z",+}+++def test_aoi_changes_baseline_then_diff(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setattr(+ cli.aoi_analysis, "fetch_aoi_changes", _fake(_AOI_CHANGES_BASELINE)+ )+ result = _invoke("aoi", "changes", "TestZone")+ assert result.exit_code == 0+ # First sweep is a baseline: nothing may be claimed new or departed.+ assert "Baseline established" in result.output+ assert "M5.1" not in result.output+ assert "departed" not in result.output.lower()++ monkeypatch.setattr(cli.aoi_analysis, "fetch_aoi_changes", _fake(_AOI_CHANGES_DIFF))+ result = _invoke("aoi", "changes", "TestZone")+ assert result.exit_code == 0+ assert "Baseline established" not in result.output+ assert "2026-09-01T10:00:00Z" in result.output+ assert "M5.1 Quaketown (12 km)" in result.output+ assert "M4.2 Oldplace (99 km)" in result.output+ assert "News: RSS down" in result.output+ # A domain first seen this sweep reads as baseline, not as churn.+ assert "military_flights" in result.output+++def test_aoi_changes_error_dict_json_mode_passes_raw_dict(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.setattr(+ cli.aoi_analysis, "fetch_aoi_changes", _fake({"error": "store exploded"})+ )+ result = _invoke("--json-output", "aoi", "changes", "TestZone")+ assert result.exit_code == 0+ assert '"error"' in result.output+ assert "store exploded" in result.output