fix: complete intelligence layer refreshes and UAP fallback

This commit is contained in:
BigBodyCobain
2026-08-23 20:14:07 -06:00
parent 2461756da4
commit cd6395f5ee
11 changed files with 389 additions and 26 deletions
@@ -2,6 +2,7 @@
from __future__ import annotations
import inspect
from unittest.mock import MagicMock
import pytest
@@ -199,3 +200,13 @@ def test_fetch_path_never_calls_legacy_grid_start(monkeypatch: pytest.MonkeyPatc
sigint_fetcher.fetch_sigint()
legacy_start.assert_not_called()
def test_layer_toggle_does_not_start_legacy_global_aprs_client() -> None:
"""The layer endpoint must route APRS through the bounded bridge only."""
from routers import data as data_router
source = inspect.getsource(data_router.update_layers)
assert "sigint_grid.aprs.start" not in source
assert "sigint_grid.aprs.stop" not in source
assert "aprs_is_bridge.reconcile" in source
+18 -1
View File
@@ -88,6 +88,23 @@ def test_heatmap_returns_geojson_features(engine: GT_EarlyWarning) -> None:
assert feature["geometry"]["type"] == "Point"
def test_heatmap_keeps_geolocated_items_without_costly_signal(engine: GT_EarlyWarning) -> None:
"""Coordinates must survive even when the item only contributes baseline risk."""
engine.process_feed_item(
{
"id": "geo-baseline-1",
"text": "Routine regional update.",
"source": "news",
"region": "lisbon",
"coords": [38.72, -9.14],
}
)
features = engine.get_risk_heatmap()["features"]
assert features
assert features[0]["geometry"]["coordinates"] == [-9.14, 38.72]
def test_dossier_includes_recent_signals(engine: GT_EarlyWarning) -> None:
engine.process_feed_item(
{
@@ -147,4 +164,4 @@ def test_refresh_from_latest_data_processes_telegram(monkeypatch: pytest.MonkeyP
}
summary = refresh_from_latest_data(latest, persist=False)
assert summary["enabled"] is True
assert summary["processed"] >= 1
assert summary["processed"] >= 1
@@ -88,3 +88,58 @@ def test_cctv_enable_reuses_nonempty_catalog():
count.assert_called_once()
seed.assert_not_called()
fetch_cctv.assert_called_once()
def test_refreshes_intelligence_layers_on_enable():
"""Cold optional feeds must not wait for the next slow-tier scheduler tick."""
keys = {
"uap_sightings",
"malware_c2",
"cyber_threats",
"scm_suppliers",
"telegram_osint",
"gt_risk",
}
before = snapshot_active_layers()
for key in keys:
active_layers[key] = True
try:
with patch("services.data_fetcher._SLOW_EXECUTOR") as slow_exec:
refresh_newly_enabled_layers({**before, **{key: False for key in keys}})
slow_exec.submit.assert_called_once()
assert set(slow_exec.submit.call_args.args[1]) == keys
finally:
for key in keys:
active_layers[key] = before.get(key, False)
def test_slow_fetch_supports_intelligence_layers_without_network():
"""Each newly supported layer dispatches to its existing fetcher."""
from services.layer_enable_refresh import _slow_fetch
with (
patch("services.fetchers.earth_observation.fetch_uap_sightings") as uap,
patch("services.fetchers.malware.fetch_malware_threats") as malware,
patch("services.fetchers.cyber_status.fetch_cyber_threats") as cyber,
patch("services.scm.suppliers.fetch_scm_suppliers") as scm,
patch("services.fetchers.telegram_osint.fetch_telegram_osint") as telegram,
patch("analytics.integration.maybe_refresh_gt_analytics") as gt,
):
for key in (
"uap_sightings",
"malware_c2",
"cyber_threats",
"scm_suppliers",
"telegram_osint",
"gt_risk",
):
_slow_fetch(key)
uap.assert_called_once_with()
malware.assert_called_once_with()
cyber.assert_called_once_with()
scm.assert_called_once_with()
telegram.assert_called_once_with()
gt.assert_called_once_with()
@@ -226,6 +226,32 @@ def test_fetch_uap_sightings_succeeds_when_fallback_returns_data(monkeypatch):
assert canary_calls == [], "canary should not trip when fallback supplies data"
def test_fetch_uap_sightings_retains_last_known_snapshot_when_refresh_empty(monkeypatch):
"""An empty weekly refresh must not erase the last visible UAP snapshot."""
from services.fetchers import earth_observation as eo
from services.fetchers import _store
monkeypatch.setattr(_store, "is_any_active", lambda layer: True)
monkeypatch.setattr(eo, "_load_nuforc_sightings_cache", lambda force_refresh=False: None)
monkeypatch.setattr(
eo,
"_build_recent_uap_sightings",
lambda: (_ for _ in ()).throw(RuntimeError("NUFORC unavailable")),
)
monkeypatch.setattr(eo, "_build_uap_sightings_from_hf_mirror", lambda: [])
last_known = [{"id": "older-uap", "date_time": "2025-01-01", "lat": 39.7, "lng": -104.9}]
monkeypatch.setattr(eo, "_load_nuforc_last_known_sightings", lambda: last_known)
monkeypatch.setattr(eo, "_mark_fresh", lambda *keys: None)
with _store._data_lock:
_store.latest_data["uap_sightings"] = []
eo.fetch_uap_sightings()
with _store._data_lock:
assert _store.latest_data["uap_sightings"] == last_known
def test_uap_scheduler_runs_weekly():
"""UAP layer refreshes weekly so each install pulls live NUFORC on a steady cadence."""
from services import data_fetcher