fix(map): geofence delete, vessel snapshots, sentinel cache, news briefs
Geofences could be drawn but not removed. VesselAPI Hormuz dots vanished
on restart and DVR skipped between the 5 daily polls. Sentinel-1 re-hit
STAC on every pan and often painted a neighbouring swath. Executive
briefs truncated; ticker stayed empty unless something was critical.
- Layer-panel list + polygon popup DELETE /api/geofences/{id}
- Persist VesselAPI polls to vessels (UTC-day purge, DVR as-of, boot hydrate)
- Cache Sentinel-1 by 2° cell; pick covering scene; clip Leaflet tiles
- Retry truncated LLM JSON; ticker falls back to medium/low; 3-min HUD poll
This commit is contained in:
parent
fdf5969e27
commit
c48788d4b6
20 changed files with 669 additions and 57 deletions
|
|
@ -230,6 +230,21 @@ def test_api_news_ticker_returns_only_flagged(clean_news):
|
|||
assert item["url"] == "https://example.com/ticker"
|
||||
|
||||
|
||||
@requires_db
|
||||
def test_api_news_ticker_falls_back_to_lesser_when_nothing_flagged(clean_news):
|
||||
sid = _seed_summary("quiet brief", "2026-08-27T18:05:00+00:00", "Hermes-4.3-36B")
|
||||
_seed_news_item(
|
||||
sid, "ticker", "Shop theft downtown", "low",
|
||||
location_name="Raleigh", url="https://example.com/theft",
|
||||
)
|
||||
resp = _get("/api/news/ticker")
|
||||
assert resp.status_code == 200
|
||||
body = resp.json()
|
||||
assert len(body) == 1
|
||||
assert body[0]["headline"] == "Shop theft downtown"
|
||||
assert body[0]["importance"] == "low"
|
||||
|
||||
|
||||
@requires_db
|
||||
def test_api_news_map_returns_only_flagged_with_coords(clean_news):
|
||||
_seed_flagged_items()
|
||||
|
|
|
|||
|
|
@ -72,6 +72,14 @@ def test_chokepoint_skips_aisstream_subscribe_outside_conus():
|
|||
assert "minlat,minlon,maxlat,maxlon" in HTML.split("function chokepointLeafletBounds")[1][:400]
|
||||
|
||||
|
||||
def test_news_ticker_polls_more_often_than_summarizer_cycle():
|
||||
assert "NEWS_REFRESH_MS" in HTML
|
||||
# Summarizer is 15 min; ticker should refresh on a shorter cadence so
|
||||
# lesser-news fills show up without waiting for the next brief.
|
||||
line = [ln for ln in HTML.splitlines() if "NEWS_REFRESH_MS" in ln][0]
|
||||
assert "900000" not in line
|
||||
|
||||
|
||||
def test_phone_chokepoints_use_select_not_buttons():
|
||||
mobile = HTML.split("@media (max-width: 820px)")[1].split("@media (prefers-reduced-motion")[0]
|
||||
assert "#chokepoint-select { display: block; }" in mobile
|
||||
|
|
|
|||
26
tests/test_geofence_frontend.py
Normal file
26
tests/test_geofence_frontend.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
"""Geofence layer panel: draw + delete (DELETE /api/geofences/{id})."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
HTML = (ROOT / "app/static/index.html").read_text()
|
||||
|
||||
|
||||
def test_geofence_panel_has_list_and_delete_hook():
|
||||
assert 'id="gf-draw"' in HTML
|
||||
assert 'id="gf-list"' in HTML
|
||||
assert "function deleteGeofence" in HTML
|
||||
assert "method: 'DELETE'" in HTML or 'method: "DELETE"' in HTML
|
||||
assert "/api/geofences/" in HTML
|
||||
|
||||
|
||||
def test_load_geofences_renders_delete_controls():
|
||||
js = HTML.split("async function loadGeofences", 1)[1].split(
|
||||
"async function loadFireAircraftHits", 1
|
||||
)[0]
|
||||
assert "gf-list" in js
|
||||
assert "deleteGeofence" in js
|
||||
assert "onEachFeature" in js
|
||||
assert "bindPopup" in js
|
||||
|
|
@ -7,6 +7,7 @@ from live_layers import (
|
|||
filter_points_bbox,
|
||||
parse_bbox,
|
||||
quantize_bbox,
|
||||
pick_sentinel_feature,
|
||||
rainviewer_tile_url,
|
||||
sign_cog_url,
|
||||
sentinel1_tile_url,
|
||||
|
|
@ -734,8 +735,9 @@ def test_fetch_sentinel1_vv_signed_tile_url(monkeypatch):
|
|||
post_url, post_json = calls[0][1], calls[0][2]
|
||||
assert post_url.endswith("/api/stac/v1/search")
|
||||
assert post_json["collections"] == ["sentinel-1-grd"]
|
||||
assert post_json["limit"] == 1
|
||||
assert post_json["limit"] >= 1
|
||||
assert post_json["sortby"][0]["direction"] == "desc"
|
||||
assert "bbox" in out
|
||||
|
||||
|
||||
def test_fetch_sentinel1_uses_hh_when_vv_missing(monkeypatch):
|
||||
|
|
@ -783,3 +785,22 @@ def test_fetch_sentinel1_none_when_no_vv_or_hh(monkeypatch):
|
|||
_cache.clear()
|
||||
|
||||
assert asyncio.run(fetch_sentinel1("-80,35,-79,36")) is None
|
||||
|
||||
|
||||
def test_pick_sentinel_feature_prefers_scene_covering_center():
|
||||
features = [
|
||||
{"id": "far", "bbox": [10.0, 10.0, 12.0, 12.0]},
|
||||
{"id": "cover", "bbox": [-80.5, 34.5, -78.5, 36.5]},
|
||||
{"id": "also-far", "bbox": [-10.0, 0.0, -8.0, 2.0]},
|
||||
]
|
||||
picked = pick_sentinel_feature(features, -79.5, 35.5)
|
||||
assert picked["id"] == "cover"
|
||||
|
||||
|
||||
def test_pick_sentinel_feature_falls_back_to_first_when_none_cover():
|
||||
features = [
|
||||
{"id": "a", "bbox": [10.0, 10.0, 12.0, 12.0]},
|
||||
{"id": "b", "bbox": [20.0, 20.0, 22.0, 22.0]},
|
||||
]
|
||||
assert pick_sentinel_feature(features, -79.5, 35.5)["id"] == "a"
|
||||
assert pick_sentinel_feature([], -79.5, 35.5) is None
|
||||
|
|
|
|||
|
|
@ -39,3 +39,11 @@ def test_sentinel1_not_fetched_on_init_unless_on():
|
|||
assert "loadSentinel1()" not in init
|
||||
refresh = HTML.split("function refreshLiveOverlays", 1)[1].split("function addExtraAttrib", 1)[0]
|
||||
assert "if (sentinelOn) loadSentinel1();" in refresh
|
||||
|
||||
|
||||
def test_sentinel1_reuses_covering_scene_and_clips_tiles():
|
||||
js = HTML.split("async function loadSentinel1", 1)[1].split("function loadThermal", 1)[0]
|
||||
assert "sentinelStillCovers" in HTML
|
||||
assert "itemId" in js
|
||||
assert "L.latLngBounds" in js
|
||||
assert "sentinelBounds" in HTML
|
||||
|
|
|
|||
|
|
@ -234,6 +234,8 @@ def _patch_side_effects(monkeypatch):
|
|||
|
||||
monkeypatch.setattr("tracks.record_position", _noop)
|
||||
monkeypatch.setattr("geofence.record_and_notify", _noop)
|
||||
monkeypatch.setattr(vesselapi, "persist_vessel_snapshot", _noop)
|
||||
monkeypatch.setattr(vesselapi, "purge_old_vessels", _noop)
|
||||
|
||||
|
||||
def test_poll_once_lands_markers_in_vessel_last_known(monkeypatch):
|
||||
|
|
|
|||
36
tests/test_vessels_snapshot.py
Normal file
36
tests/test_vessels_snapshot.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
"""VesselAPI daily snapshot store — as-of DVR + UTC-day purge (no DB)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from vesselapi import pick_poll_at, snapshot_as_of, utc_day_start
|
||||
|
||||
|
||||
def test_utc_day_start_floors_to_midnight_utc():
|
||||
now = datetime(2026, 8, 29, 15, 30, 12, tzinfo=timezone.utc)
|
||||
assert utc_day_start(now) == datetime(2026, 8, 29, 0, 0, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
def test_pick_poll_at_returns_latest_snapshot_at_or_before_as_of():
|
||||
t1 = datetime(2026, 8, 29, 0, 0, tzinfo=timezone.utc)
|
||||
t2 = datetime(2026, 8, 29, 4, 48, tzinfo=timezone.utc)
|
||||
t3 = datetime(2026, 8, 29, 9, 36, tzinfo=timezone.utc)
|
||||
as_of = datetime(2026, 8, 29, 6, 0, tzinfo=timezone.utc)
|
||||
assert pick_poll_at([t1, t2, t3], as_of) == t2
|
||||
assert pick_poll_at([t1, t2, t3], t1) == t1
|
||||
assert pick_poll_at([t1, t2, t3], datetime(2026, 8, 28, 23, tzinfo=timezone.utc)) is None
|
||||
|
||||
|
||||
def test_snapshot_as_of_returns_the_matching_poll_only():
|
||||
t1 = datetime(2026, 8, 29, 0, 0, tzinfo=timezone.utc)
|
||||
t2 = datetime(2026, 8, 29, 4, 48, tzinfo=timezone.utc)
|
||||
rows = [
|
||||
{"id": "1", "poll_at": t1, "lat": 26.5, "lon": 56.0},
|
||||
{"id": "2", "poll_at": t1, "lat": 26.6, "lon": 56.1},
|
||||
{"id": "1", "poll_at": t2, "lat": 26.7, "lon": 56.2},
|
||||
]
|
||||
out = snapshot_as_of(rows, datetime(2026, 8, 29, 6, 0, tzinfo=timezone.utc))
|
||||
assert {r["id"] for r in out} == {"1"}
|
||||
assert out[0]["lat"] == 26.7
|
||||
assert all(r["poll_at"] == t2 for r in out)
|
||||
Loading…
Reference in a new issue