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(tests): make the stable_chunks log test pass in any order (#121791)

Phil Haack03bbb1ee0128
diff --git a/posthog/test/test_stable_chunks.py b/posthog/test/test_stable_chunks.py
index cad69befa0d5..6b2094ace5c8 100644
--- a/posthog/test/test_stable_chunks.py
+++ b/posthog/test/test_stable_chunks.py
@@ -142,9 +142,10 @@ class TestStableChunks(SimpleTestCase):
assert REGISTRY.get_sample_value("posthog_stable_chunks_fallback_total", labels) == before + 1
def test_an_unmapped_specifier_is_logged_without_the_page_path(self) -> None:
+ page_path = "/reset/0190a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b/fake-reset-token"
request = RequestFactory().get(
- "/reset/0190a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b/fake-reset-token"
- "?stable_chunks=fallback&stable_chunks_unmapped=@c/Abc123"
+ f"{page_path}?stable_chunks=fallback&stable_chunks_unmapped=@c/Abc123",
+ HTTP_REFERER=f"https://app.example.com{page_path}",
)
request.user = AnonymousUser()
# The structlog context is thread-local, so an earlier test's `bind()` on this worker would leak into the event.
@@ -153,9 +154,13 @@ class TestStableChunks(SimpleTestCase):
with capture_logs() as logs:
stable_chunks_choice(request, None)
- assert [log for log in logs if log["event"] == "stable_chunks_unmapped_specifier"] == [
- {"event": "stable_chunks_unmapped_specifier", "specifier": "@c/Abc123", "log_level": "warning"}
- ]
+ # posthog/settings/logs.py configures structlog with one context dict per thread. Nothing clears it between log calls.
+ # Keys that earlier code bound on this thread appear on this event. A whole-dict comparison then depends on test order.
+ [unmapped] = [log for log in logs if log["event"] == "stable_chunks_unmapped_specifier"]
+ assert unmapped["specifier"] == "@c/Abc123"
+ assert unmapped["log_level"] == "warning"
+ assert "/reset/" not in str(unmapped)
+ assert "fake-reset-token" not in str(unmapped)
def test_a_failing_logged_out_flag_check_serves_the_hashed_build(self) -> None:
request = RequestFactory().get("/")