Features: - Add /api/ask endpoint for plain-language audit log queries - Regex-based time/entity extraction (no LLM required for parsing) - LLM-powered narrative summarisation with OpenAI-compatible APIs - Graceful fallback to structured bullet lists when LLM is unavailable - Frontend ask panel with markdown rendering and cited events Production: - Harden Dockerfile: non-root user, gunicorn+uvicorn workers - Add docker-compose.prod.yml with internal networks and health checks - Add nginx reverse proxy with security headers - MongoDB no longer exposed externally in production Tests: - 29 new tests for ask parsing, query building, and endpoint behaviour - Fix conftest monkeypatch for routes.ask events collection Bump version to 1.1.0
46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
import mongomock
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_events_collection():
|
|
client = mongomock.MongoClient()
|
|
db = client["micro_soc"]
|
|
coll = db["events"]
|
|
return coll
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def mock_watermarks_collection():
|
|
client = mongomock.MongoClient()
|
|
db = client["micro_soc"]
|
|
coll = db["watermarks"]
|
|
return coll
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def client(mock_events_collection, mock_watermarks_collection, monkeypatch):
|
|
monkeypatch.setattr("database.events_collection", mock_events_collection)
|
|
monkeypatch.setattr("routes.fetch.events_collection", mock_events_collection)
|
|
monkeypatch.setattr("routes.events.events_collection", mock_events_collection)
|
|
monkeypatch.setattr("routes.ask.events_collection", mock_events_collection)
|
|
monkeypatch.setattr("watermark.watermarks_collection", mock_watermarks_collection)
|
|
monkeypatch.setattr("routes.health.watermarks_collection", mock_watermarks_collection)
|
|
monkeypatch.setattr("routes.fetch.get_watermark", lambda source: None)
|
|
monkeypatch.setattr("routes.fetch.set_watermark", lambda source, ts: None)
|
|
monkeypatch.setattr("auth.AUTH_ENABLED", False)
|
|
monkeypatch.setattr("database.db.command", lambda cmd: {"ok": 1} if cmd == "ping" else {})
|
|
|
|
# Mock audit trail and rules collections so tests don't wait on real MongoDB
|
|
audit_client = mongomock.MongoClient()
|
|
audit_db = audit_client["micro_soc"]
|
|
monkeypatch.setattr("audit_trail.audit_collection", audit_db["aoc_audit"])
|
|
monkeypatch.setattr("rules.alerts_collection", audit_db["alerts"])
|
|
monkeypatch.setattr("rules.rules_collection", audit_db["alert_rules"])
|
|
monkeypatch.setattr("routes.rules.rules_collection", audit_db["alert_rules"])
|
|
|
|
from main import app
|
|
|
|
return TestClient(app)
|