:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
from unittest import TestCase
from parameterized import parameterized
from products.canvas.backend.capabilities import ConnectorGrant, capability_widening
BASE = {
"posthog": {
"insights": ["abc"],
"captureEvents": ["clicked"],
"inlineQueries": False,
"agentRequests": False,
},
"network": {"origins": []},
}
WIDER = {
"posthog": {
"insights": ["abc", "def"],
"captureEvents": ["clicked"],
"inlineQueries": True,
"state": ["user"],
"actions": ["tasks.create"],
"tools": ["feature-flag-enable"],
"agentRequests": True,
},
"network": {"origins": ["https://api.example.com"]},
"connectors": [
{"provider": "github", "tools": ["list_pull_requests", "search_issues"]},
{"provider": "mcp:mcp.example.com", "tools": ["list_events"]},
],
}
NARROWER = {
"posthog": {"insights": [], "captureEvents": [], "inlineQueries": False, "agentRequests": False},
"network": {"origins": []},
}
class TestCapabilityWidening(TestCase):
@parameterized.expand(
[
("identical", BASE, BASE, False),
("narrowing_only", BASE, NARROWER, False),
("unknown_baseline_flags_everything", None, BASE, True),
("empty_manifests", {}, {}, False),
]
)
def test_widens_flag(self, _name, before, after, expected):
assert capability_widening(before, after).widens is expected
def test_reports_each_added_capability(self):
widening = capability_widening(BASE, WIDER)
assert widening.widens is True
assert widening.insights_added == ["def"]
assert widening.capture_events_added == []
assert widening.inline_queries_enabled is True
assert widening.agent_requests_enabled is True
assert widening.network_origins_added == ["https://api.example.com"]
assert widening.state_scopes_added == ["user"]
assert widening.actions_added == ["tasks.create"]
assert widening.tools_added == ["feature-flag-enable"]
assert widening.connectors_added == [
ConnectorGrant(provider="github", tools=["list_pull_requests", "search_issues"]),
ConnectorGrant(provider="mcp:mcp.example.com", tools=["list_events"]),
]
def test_only_new_connector_tools_count_as_widening(self):
before = {"connectors": [{"provider": "github", "tools": ["list_pull_requests"]}]}
after = {"connectors": [{"provider": "github", "tools": ["search_issues", "list_pull_requests"]}]}
widening = capability_widening(before, after)
assert widening.connectors_added == [ConnectorGrant(provider="github", tools=["search_issues"])]
assert capability_widening(after, before).widens is False
def test_inline_queries_already_enabled_is_not_a_widening(self):
enabled = {"posthog": {"inlineQueries": True}}
assert capability_widening(enabled, enabled).widens is False