: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
feat(experiments): collapse long prompt experiment snippets (#102656)
ruby childs71900a3dbdb8
diff --git a/frontend/src/scenes/experiments/ExperimentCodeSnippets.tsx b/frontend/src/scenes/experiments/ExperimentCodeSnippets.tsxindex 5191272d3fbc..6f7c6d0f3220 100644--- a/frontend/src/scenes/experiments/ExperimentCodeSnippets.tsx+++ b/frontend/src/scenes/experiments/ExperimentCodeSnippets.tsx@@ -252,9 +252,12 @@ export interface PromptSnippetProps {flagKey: string}+// Prompt experiment snippets run 40+ lines, so they collapse to a preview until the user expands.+const PROMPT_SNIPPET_PREVIEW_LINES = 12+export function PromptExperimentPythonSnippet({ flagKey }: PromptSnippetProps): JSX.Element {return (- <CodeSnippet language={Language.Python} wrap compact>+ <CodeSnippet language={Language.Python} wrap compact maxLinesWithoutExpansion={PROMPT_SNIPPET_PREVIEW_LINES}>{`import jsonimport os@@ -309,7 +312,12 @@ print(response.choices[0].message.content)export function PromptExperimentJSSnippet({ flagKey }: PromptSnippetProps): JSX.Element {return (- <CodeSnippet language={Language.TypeScript} wrap compact>+ <CodeSnippet+ language={Language.TypeScript}+ wrap+ compact+ maxLinesWithoutExpansion={PROMPT_SNIPPET_PREVIEW_LINES}+ >{`import { PostHog } from 'posthog-node'import { OpenAI } from '@posthog/ai/openai'import { Prompts } from '@posthog/ai/prompts'@@ -363,7 +371,7 @@ console.log(response.choices[0].message.content)export function PromptExperimentAgentPromptSnippet({ flagKey }: PromptSnippetProps): JSX.Element {return (- <CodeSnippet language={Language.Text} wrap compact>+ <CodeSnippet language={Language.Text} wrap compact maxLinesWithoutExpansion={PROMPT_SNIPPET_PREVIEW_LINES}>{`Wire up a PostHog prompt experiment in this project.Contextdiff --git a/frontend/src/scenes/experiments/ExperimentImplementationDetails.test.tsx b/frontend/src/scenes/experiments/ExperimentImplementationDetails.test.tsxnew file mode 100644index 000000000000..d20163f143cd--- /dev/null+++ b/frontend/src/scenes/experiments/ExperimentImplementationDetails.test.tsx@@ -0,0 +1,28 @@+import '@testing-library/jest-dom'++import { fireEvent, render, screen } from '@testing-library/react'++import type { Experiment } from '~/types'++import { ExperimentImplementationDetails } from './ExperimentImplementationDetails'++const PROMPT_EXPERIMENT = {+ feature_flag: { key: 'my-prompt-experiment' },+ parameters: {+ prompt_metadata: { name: 'support-reply', templates: ['support-reply'], versions: [1, 2] },+ },+} as unknown as Experiment++describe('ExperimentImplementationDetails', () => {+ // The agent prompt runs past 50 lines. Without the collapse it pushes the rest of the page+ // out of view, so the snippet must open collapsed and only unfold when the user asks.+ it('collapses the agent prompt until expanded', () => {+ render(<ExperimentImplementationDetails experiment={PROMPT_EXPERIMENT} />)++ expect(screen.queryByText(/Reference docs/)).not.toBeInTheDocument()++ fireEvent.click(screen.getByText(/more lines/))++ expect(screen.getByText(/Reference docs/)).toBeInTheDocument()+ })+})