Skip to content

: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.

chore(capture): make mixed ai lane test independent of request order (#126922)

Paul D'Ambra663be2ed0d5e
diff --git a/posthog/api/test/test_capture_internal.py b/posthog/api/test/test_capture_internal.py
index 31863c3079c3..680945c55b00 100644
--- a/posthog/api/test/test_capture_internal.py
+++ b/posthog/api/test/test_capture_internal.py
@@ -70,7 +70,13 @@ class InstallV1Spy:
Thread-safe: concurrent calls from chunked batch submissions are serialized via lock.
"""
- def __init__(self, mock_session_fn: MagicMock, responses: list[MockResponse] | None = None):
+ def __init__(
+ self,
+ mock_session_fn: MagicMock,
+ responses: list[MockResponse] | None = None,
+ *,
+ responses_by_url: dict[str, MockResponse] | None = None,
+ ):
self.calls: list[dict[str, Any]] = []
self._responses = list(responses or [MockResponse(body={})])
self._call_idx = 0
@@ -79,6 +85,8 @@ class InstallV1Spy:
def spy_post(url: str, **kwargs: Any) -> MockResponse:
with self._lock:
self.calls.append({"url": url, **kwargs})
+ if responses_by_url is not None:
+ return responses_by_url[url]
resp = self._responses[min(self._call_idx, len(self._responses) - 1)]
self._call_idx += 1
return resp
@@ -1552,10 +1560,12 @@ class TestAiLaneRouting(SimpleTestCase):
]
spy = InstallV1Spy(
mock_session_fn,
- [
- MockResponse(body=_ok_results(an_uid)),
- MockResponse(body={"results": {ai_uid: {"result": "ok"}, ai_uid2: {"result": "drop"}}}),
- ],
+ responses_by_url={
+ EXPECTED_URL: MockResponse(body=_ok_results(an_uid)),
+ EXPECTED_AI_URL: MockResponse(
+ body={"results": {ai_uid: {"result": "ok"}, ai_uid2: {"result": "drop"}}}
+ ),
+ },
)
entry_point = capture_batch_ai_internal if ai_lane else capture_batch_internal