osint-dashboard/tests/test_phase1_guardrails.py
Sirius DevOps 74722f7628 fix(ops): pin TiTiler digest, GIST bbox indexes, single uvicorn worker
Pin titiler to the Pi-running digest, make workers=1 explicit for
in-memory WS/layer caches, and add PostGIS GIST indexes for events/fires
bbox pans without dropping the existing btree indexes.
2026-09-01 00:47:06 -04:00

65 lines
2.3 KiB
Python

"""Phase 1 guardrails: compose limits, 500ms debounce, no extra brokers."""
from __future__ import annotations
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
def test_compose_memory_limits_and_shared_buffers():
text = (ROOT / "docker-compose.yml").read_text()
assert "shared_buffers=2GB" in text
assert "shared_preload_libraries=timescaledb" in text
assert "memory: 3G" in text or "memory: 3GB" in text
assert "memory: 2G" in text or "memory: 2GB" in text
def test_map_moveend_debounced_500ms():
html = (ROOT / "app" / "static" / "index.html").read_text()
assert "map.on('moveend'" in html
# Existing 300ms debounce must be 500ms so pans don't spam bbox POSTs/WS.
assert "}, 500);" in html
assert "}, 300);" not in html.split("map.on('moveend'")[1][:800]
def test_no_redis_kafka_celery():
req = (ROOT / "app" / "requirements.txt").read_text().lower()
compose = (ROOT / "docker-compose.yml").read_text().lower()
for blob in (req, compose):
assert "redis" not in blob
assert "kafka" not in blob
assert "celery" not in blob
assert "cachetools" in req
def test_titiler_image_pinned_by_digest():
text = (ROOT / "docker-compose.yml").read_text()
assert (
"ghcr.io/developmentseed/titiler:latest@sha256:"
"1809958d063543e3ec858259536002b2de78e9f8f09a22a8d9591bdc2b550b14"
in text
)
# Unpinned :latest would drift on every pull.
for line in text.splitlines():
if "titiler" in line.lower() and "image:" in line:
assert "@sha256:" in line
def test_uvicorn_single_worker_guard():
text = (ROOT / "app" / "main.py").read_text()
main_block = text.split('if __name__ == "__main__":', 1)[1]
assert "workers=1" in main_block
def test_bbox_gist_migration_keeps_btree_and_adds_gist():
text = (ROOT / "alembic" / "versions" / "010_bbox_gist.py").read_text()
assert "down_revision" in text and "009_vessels" in text
assert "ix_events_geom_gist" in text
assert "ix_fires_geom_gist" in text
assert "ST_MakePoint(location_lon, location_lat)" in text
assert "ST_MakePoint(longitude, latitude)" in text
assert "USING gist" in text
models = (ROOT / "app" / "models.py").read_text()
assert 'Index("ix_events_location"' in models
assert 'Index("ix_fires_bbox"' in models