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.

feat(demo): pin starter views and seed recent exceptions (#124934)

Chris Volzerf8f97ee038bf
diff --git a/products/demo/backend/logic/products/hedgebox/matrix.py b/products/demo/backend/logic/products/hedgebox/matrix.py
index feb101af7204..1150ae6b963c 100644
--- a/products/demo/backend/logic/products/hedgebox/matrix.py
+++ b/products/demo/backend/logic/products/hedgebox/matrix.py
@@ -49,6 +49,8 @@ from posthog.cloud_utils import is_cloud
from posthog.constants import PAGEVIEW_EVENT
from posthog.exceptions_capture import capture_exception
from posthog.models.event.util import create_event
+from posthog.models.file_system.constants import DEFAULT_SURFACE
+from posthog.models.file_system.file_system_shortcut import FileSystemShortcut
from posthog.models.oauth import OAuthApplication
from posthog.models.oauth_provisioning import ProvisioningConfig
from posthog.scopes import UNPRIVILEGED_SCOPES
@@ -915,6 +917,27 @@ class HedgeboxMatrix(Matrix):
last_modified_by=user,
)
+ FileSystemShortcut.objects.bulk_create(
+ [
+ FileSystemShortcut(
+ team=team,
+ user=user,
+ surface=DEFAULT_SURFACE,
+ type=item_type,
+ ref=str(item_ref),
+ path=item_name or "Untitled",
+ order=order,
+ )
+ for order, (item_type, item_ref, item_name) in enumerate(
+ [
+ ("dashboard", key_metrics_dashboard.pk, key_metrics_dashboard.name),
+ ("insight", weekly_signups_insight.short_id, weekly_signups_insight.name),
+ ("insight", signups_by_country_insight.short_id, signups_by_country_insight.name),
+ ]
+ )
+ ]
+ )
+
# Insight views
record_insight_views(
team_id=team.pk,
@@ -1887,7 +1910,7 @@ class HedgeboxMatrix(Matrix):
],
},
],
- "days_ago": [2, 5, 11, 18],
+ "days_ago": [2, 5, 11, 18, 0],
},
{
"name": "File preview render failure",
@@ -1941,7 +1964,7 @@ class HedgeboxMatrix(Matrix):
],
},
],
- "days_ago": [1, 4, 9],
+ "days_ago": [1, 4, 9, 0],
},
{
"name": "Team invite rejected",
@@ -1993,7 +2016,7 @@ class HedgeboxMatrix(Matrix):
],
},
],
- "days_ago": [3, 7],
+ "days_ago": [3, 7, 0],
},
]
@@ -2033,7 +2056,7 @@ class HedgeboxMatrix(Matrix):
distinct_id = (
sorted(person.distinct_ids_at_now)[0] if person.distinct_ids_at_now else person.in_product_id
)
- timestamp = self.now - dt.timedelta(days=days_ago, hours=index % 5)
+ timestamp = self.now - dt.timedelta(days=days_ago, hours=2 if days_ago == 0 else index % 5)
frames = issue_spec["frames"]
event_frames = [self._stack_frame_contents(frame) for frame in frames]
exception_type = issue_spec["type"]
diff --git a/products/demo/backend/test/test_hedgebox_matrix.py b/products/demo/backend/test/test_hedgebox_matrix.py
index 1e8f48f5c669..39bacc87a50c 100644
--- a/products/demo/backend/test/test_hedgebox_matrix.py
+++ b/products/demo/backend/test/test_hedgebox_matrix.py
@@ -3,12 +3,18 @@ import datetime as dt
from types import SimpleNamespace
from typing import Any, cast
+from posthog.test.base import BaseTest
from unittest.mock import MagicMock, patch
from django.test import SimpleTestCase, override_settings
from parameterized import parameterized
+from posthog.models.file_system.constants import DEFAULT_SURFACE
+from posthog.models.file_system.file_system_shortcut import FileSystemShortcut
+
+from products.dashboards.backend.models.dashboard import Dashboard
+from products.demo.backend.logic.matrix.matrix import Cluster
from products.demo.backend.logic.matrix.models import SimEvent
from products.demo.backend.logic.products.hedgebox.matrix import HedgeboxMatrix
from products.demo.backend.logic.products.hedgebox.taxonomy import (
@@ -20,6 +26,74 @@ from products.demo.backend.logic.products.hedgebox.taxonomy import (
EVENT_UPGRADED_PLAN,
EVENT_UPLOADED_FILE,
)
+from products.product_analytics.backend.facade.models import Insight
+
+
+def _matrix_with_one_person(seed: str) -> HedgeboxMatrix:
+ matrix = HedgeboxMatrix(seed=seed, n_clusters=0)
+ matrix.clusters = [
+ cast(
+ Cluster,
+ SimpleNamespace(
+ people=[
+ SimpleNamespace(
+ past_events=[object()],
+ in_posthog_id=uuid.uuid4(),
+ in_product_id="demo-person",
+ distinct_ids_at_now={"demo-person"},
+ properties_at_now={"email": "[email protected]"},
+ first_seen_at=matrix.start,
+ )
+ ]
+ ),
+ )
+ ]
+ return matrix
+
+
+class TestHedgeboxMatrixInitialViews(BaseTest):
+ @patch("products.demo.backend.logic.products.hedgebox.matrix.sync_issues_to_clickhouse")
+ @patch("products.demo.backend.logic.products.hedgebox.matrix.create_event")
+ def test_project_setup_populates_user_pins_and_last_24_hour_errors(
+ self, mock_create_event: MagicMock, _mock_sync: MagicMock
+ ) -> None:
+ matrix = _matrix_with_one_person("initial-views")
+
+ existing_shortcut_ids = set(FileSystemShortcut.objects.values_list("pk", flat=True))
+
+ matrix.set_project_up(self.team, self.user)
+
+ dashboard_id = self.team.primary_dashboard_id
+ assert dashboard_id is not None
+ dashboard = Dashboard.objects.get(team=self.team, pk=dashboard_id, pinned=True)
+ expected_refs = {
+ ("dashboard", str(dashboard.pk)),
+ ("insight", Insight.objects.get(team=self.team, name="Weekly signups", saved=True).short_id),
+ (
+ "insight",
+ Insight.objects.get(team=self.team, name="Last month's signups by country", saved=True).short_id,
+ ),
+ }
+ new_shortcuts = FileSystemShortcut.objects.filter(type__in=["dashboard", "insight"]).exclude(
+ pk__in=existing_shortcut_ids
+ )
+ assert new_shortcuts.count() == len(expected_refs)
+ assert set(new_shortcuts.values_list("type", "ref", "surface", "team_id", "user_id")) == {
+ (item_type, ref, DEFAULT_SURFACE, self.team.pk, self.user.pk) for item_type, ref in expected_refs
+ }
+ assert FileSystemShortcut.objects.filter(pk__in=existing_shortcut_ids).count() == len(existing_shortcut_ids)
+
+ recent_errors = [
+ call.kwargs
+ for call in mock_create_event.call_args_list
+ if matrix.now - dt.timedelta(hours=24) < call.kwargs["timestamp"] < matrix.now
+ ]
+ assert len(recent_errors) == 3
+ assert len({event["properties"]["$exception_issue_id"] for event in recent_errors}) == 3
+ for event in recent_errors:
+ assert event["event"] == "$exception"
+ assert event["team"] == self.team
+ assert event["properties"]["$exception_list"][0]["stacktrace"]["frames"]
class TestHedgeboxMatrixSimulation(SimpleTestCase):