File size: 1,498 Bytes
7cc81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def test_analytics_migration_is_additive_and_forces_rls() -> None:
    text = (ROOT / "app/social/migrations/0010_analytics_insights.sql").read_text()
    normalized = text.lower()
    assert "drop table" not in normalized
    for table in (
        "analytics_sync_runs",
        "analytics_metric_snapshots",
        "analytics_post_metrics",
        "analytics_platform_metrics",
    ):
        assert f"create table if not exists {table}" in normalized
    assert normalized.count("force row level security") >= 1
    assert "current_setting(''app.workspace_id''" in normalized


def test_analytics_routes_and_transports_are_narrow() -> None:
    api = (ROOT / "app/analytics/api.py").read_text()
    mcp = (ROOT / "app/mcp/tools/analytics.py").read_text()
    sdk = (ROOT / "sdk/typescript/src/resources/analytics.ts").read_text()
    for route in (
        '"/overview"',
        '"/timeseries"',
        '"/platforms"',
        '"/posts"',
        '"/sync"',
    ):
        assert route in api
    assert "execute analytics query" not in mcp.lower()
    assert "class AnalyticsResource" in sdk


def test_analytics_never_fabricates_provider_metrics() -> None:
    service = (ROOT / "app/analytics/service.py").read_text()
    provider = (ROOT / "app/social/providers/base.py").read_text()
    assert "self.social_analytics.post" in service
    assert "get_metrics" in provider
    assert "random.randint" not in service