Files
Shadowbroker/backend/tests/test_gt_alerts.py
T
Shadowbroker cfbeabda1e Feat/gt analytics openclaw (#392)
* feat(telegram): auto-translate OSINT channel posts to English

Cherry-picked from @Bobpick PR #391 (telegram-only slice): server-side translation during fetch, SHOW ORIGINAL toggle in TelegramOsintPopup, and on-demand /api/telegram-feed?lang=.

Co-authored-by: Robert Pickett <bobpickettsr@yahoo.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(gt): experimental Derived OSINT analytics with lean-node safeguards

Cherry-picked from @Bobpick PR #391 (GT + OpenClaw slice): Bayesian strategic-risk engine, map overlay, OpenClaw commands, and telegram_rhetoric watchdog. Off by default (GT_ANALYTICS_ENABLED=false, gt_risk layer false). 1 vCPU nodes get cgroup detection, UI warning on layer toggle, and lean profile that skips scheduled ingest/Louvain unless GT_ANALYTICS_ACK_LOW_CPU=true. Backtest HUD removed from dashboard (OpenClaw/API regression only).

Co-authored-by: Robert Pickett <bobpickettsr@yahoo.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Robert Pickett <bobpickettsr@yahoo.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 17:05:46 -06:00

56 lines
1.8 KiB
Python

"""Top GT alerts ranking and coordinate filtering."""
from __future__ import annotations
from analytics.gt_alerts import parse_heatmap_alerts, top_gt_alerts
def test_parse_heatmap_filters_invalid_coords() -> None:
heatmap = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"region": "ukraine",
"risk": 0.55,
"conflict": 0.62,
"financial": 0.15,
"unrest": 0.2,
},
"geometry": {"type": "Point", "coordinates": [31.0, 48.0]},
},
{
"type": "Feature",
"properties": {"region": "no_coords", "risk": 0.9},
"geometry": {"type": "Point", "coordinates": [0.0, 0.0]},
},
{
"type": "Feature",
"properties": {"region": "global", "risk": 0.99},
"geometry": {"type": "Point", "coordinates": [0.0, 0.0]},
},
],
}
alerts, plotted = parse_heatmap_alerts(heatmap, limit=5)
assert plotted == 1
assert len(alerts) == 1
assert alerts[0]["region"] == "ukraine"
assert alerts[0]["lat"] == 48.0
assert alerts[0]["lng"] == 31.0
def test_region_label_formats_coordinates() -> None:
from analytics.gt_alerts import _region_label
assert "48.00" in _region_label("48.00,31.17")
assert _region_label("ukraine") == "ukraine"
def test_top_gt_alerts_disabled(monkeypatch) -> None:
monkeypatch.delenv("GT_ANALYTICS_ENABLED", raising=False)
from analytics.integration import reset_gt_engine
reset_gt_engine()
report = top_gt_alerts(limit=3)
assert report["alerts"] == []