: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
chore(devex): dynamically build visual regression test matrix based on event type (#54360)
Georges-Antoine Assi3bd8e7c9a6c7
diff --git a/.github/scripts/verify-storybook-new-stories.sh b/.github/scripts/verify-storybook-new-stories.shindex 417fc6b95a10..6802c6e7d363 100755--- a/.github/scripts/verify-storybook-new-stories.sh+++ b/.github/scripts/verify-storybook-new-stories.sh@@ -67,9 +67,6 @@ echo ""echo "testPathPattern: $pattern"echo ""-# Build products once before the loop — test:visual:ci:verify rebuilds each time.-pnpm --filter=@posthog/storybook run build:products-# Run the stories REPEAT_COUNT times. Each run does a full snapshot comparison.# If any run fails, the story is flaky.failed_runs=0@@ -85,7 +82,7 @@ for run in $(seq 1 "$REPEAT_COUNT"); dofiset +e- # Run test-storybook directly (skipping build:products which we already did).+ # Run test-storybook directly (tests a pre-built storybook dist served over http-server).# pipefail is set at script level so tee preserves the exit code.pnpm --filter=@posthog/storybook exec test-storybook \$snapshot_flag --no-index-json --maxWorkers=1 \diff --git a/.github/workflows/ci-storybook.yml b/.github/workflows/ci-storybook.ymlindex 3452ffecbb3e..c7904a5c8225 100644--- a/.github/workflows/ci-storybook.yml+++ b/.github/workflows/ci-storybook.yml@@ -34,6 +34,7 @@ jobs:&& fromJSON(steps.filter.outputs.frontend_count || '0')> fromJSON(steps.filter.outputs.frontend_generated_count || '0'))}}+ matrix: ${{ steps.matrix.outputs.matrix }}steps:- uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1id: app-token@@ -61,6 +62,32 @@ jobs:- 'frontend/src/generated/**'- 'products/**/frontend/generated/**'+ # Build the visual-regression matrix.+ # On PRs, only run chromium shards — no story currently opts into webkit snapshots+ # (see common/storybook/.storybook/test-runner.ts), so webkit shards consume CI+ # minutes without producing snapshot diffs. WebKit render-error coverage is+ # preserved on master pushes.+ - name: Build matrix+ id: matrix+ run: |+ # Shard counts — change here to resize the matrix.+ CHROMIUM_SHARDS=16+ WEBKIT_SHARDS=4++ shards() {+ jq -cn --arg browser "$1" --argjson count "$2" \+ '[range(1; $count + 1) | {browser: $browser, shard_count: $count, shard: .}]'+ }++ CHROMIUM=$(shards chromium "$CHROMIUM_SHARDS")+ if [ "${{ github.event_name }}" = "pull_request" ]; then+ MATRIX=$(jq -cn --argjson c "$CHROMIUM" '{include: $c}')+ else+ WEBKIT=$(shards webkit "$WEBKIT_SHARDS")+ MATRIX=$(jq -cn --argjson c "$CHROMIUM" --argjson w "$WEBKIT" '{include: $c + $w}')+ fi+ echo "matrix=$MATRIX" >> $GITHUB_OUTPUT+build-storybook:name: Build Storybook (${{ matrix.runner }})strategy:@@ -197,70 +224,12 @@ jobs:image: ghcr.io/posthog/playwright:v1.45.0strategy:fail-fast: false- matrix:- # Shard counts and worker config (maxWorkers in common/storybook/package.json)- # are tuned for runner CPU — consult #team-devex before changing- include:- - browser: chromium- shard_count: 16- shard: 1- - browser: chromium- shard_count: 16- shard: 2- - browser: chromium- shard_count: 16- shard: 3- - browser: chromium- shard_count: 16- shard: 4- - browser: chromium- shard_count: 16- shard: 5- - browser: chromium- shard_count: 16- shard: 6- - browser: chromium- shard_count: 16- shard: 7- - browser: chromium- shard_count: 16- shard: 8- - browser: chromium- shard_count: 16- shard: 9- - browser: chromium- shard_count: 16- shard: 10- - browser: chromium- shard_count: 16- shard: 11- - browser: chromium- shard_count: 16- shard: 12- - browser: chromium- shard_count: 16- shard: 13- - browser: chromium- shard_count: 16- shard: 14- - browser: chromium- shard_count: 16- shard: 15- - browser: chromium- shard_count: 16- shard: 16- - browser: webkit- shard_count: 4- shard: 1- - browser: webkit- shard_count: 4- shard: 2- - browser: webkit- shard_count: 4- shard: 3- - browser: webkit- shard_count: 4- shard: 4+ # Shard counts and worker config (maxWorkers in common/storybook/package.json)+ # are tuned for runner CPU — consult #team-devex before changing.+ # Matrix is built dynamically in the `changes` job: chromium-only on PRs,+ # chromium + webkit on master pushes. Storybook CI is skipped entirely on+ # merge_group (the `changes` job gates on event_name != 'merge_group').+ matrix: ${{ fromJson(needs.changes.outputs.matrix) }}env:NODE_OPTIONS: --max-old-space-size=16384OPT_OUT_CAPTURE: 1@@ -289,9 +258,6 @@ jobs:- name: Install package.json dependencies with pnpmrun: pnpm --filter=@posthog/storybook... install --frozen-lockfile- - name: Install CI utilities with pnpm- run: pnpm install http-server wait-on -g-- name: Download Storybook build artifactuses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0with:@@ -299,10 +265,13 @@ jobs:path: common/storybook/dist- name: Serve Storybook in the background+ # http-server and wait-on are devDependencies of @posthog/storybook.+ # Run via `pnpm --filter` so pnpm resolves them from common/storybook/node_modules/.bin+ # (no global install) and cd's into the package — `dist` is relative to common/storybook.run: |retries=5max_timeout=30- pnpm exec http-server common/storybook/dist --port 6006 --silent &+ pnpm --filter=@posthog/storybook exec http-server dist --port 6006 --silent &server_pid=$!echo "Started http-server with PID: $server_pid"@@ -311,7 +280,7 @@ jobs:while [ $retries -gt 0 ]; doecho "Checking if Storybook is available (retries left: $retries, timeout: ${max_timeout}s)..."- if pnpm wait-on http://127.0.0.1:6006 --timeout $max_timeout; then+ if pnpm --filter=@posthog/storybook exec wait-on http://127.0.0.1:6006 --timeout $max_timeout; thenecho "✅ Storybook is available at http://127.0.0.1:6006"breakfi@@ -321,7 +290,7 @@ jobs:# Check if server is still runningif ! kill -0 $server_pid 2>/dev/null; thenecho "❌ http-server process is no longer running, restarting it..."- pnpm exec http-server common/storybook/dist --port 6006 --silent &+ pnpm --filter=@posthog/storybook exec http-server dist --port 6006 --silent &server_pid=$!echo "Restarted http-server with PID: $server_pid"sleep 2@@ -417,9 +386,6 @@ jobs:- name: Install dependenciesrun: pnpm --filter=@posthog/storybook... install --frozen-lockfile- - name: Install CI utilities- run: pnpm install http-server wait-on -g-- name: Download Storybook build artifactuses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0with:@@ -427,10 +393,11 @@ jobs:path: common/storybook/dist- name: Serve Storybook+ # Resolve http-server/wait-on from common/storybook's devDependencies (no global install).run: |- pnpm exec http-server common/storybook/dist --port 6006 --silent &+ pnpm --filter=@posthog/storybook exec http-server dist --port 6006 --silent &sleep 2- pnpm wait-on http://127.0.0.1:6006 --timeout 30+ pnpm --filter=@posthog/storybook exec wait-on http://127.0.0.1:6006 --timeout 30- name: Verify changed stories are stableid: flake-verifydiff --git a/common/storybook/package.json b/common/storybook/package.jsonindex bc81eccd9c32..fad1963ea012 100644--- a/common/storybook/package.json+++ b/common/storybook/package.json@@ -4,8 +4,8 @@"build:products": "pnpm --filter=@posthog/frontend build:products","build": "pnpm build:products && DEBUG=0 storybook build -o dist","start": "pnpm build:products && DEBUG=0 storybook dev -p 6006",- "test:visual:ci:update": "pnpm build:products && test-storybook -u --junit --no-index-json --maxWorkers=1",- "test:visual:ci:verify": "pnpm build:products && test-storybook --ci --junit --no-index-json --maxWorkers=1",+ "test:visual:ci:update": "test-storybook -u --junit --no-index-json --maxWorkers=1",+ "test:visual:ci:verify": "test-storybook --ci --junit --no-index-json --maxWorkers=1","test:visual:debug": "pnpm build:products && PWDEBUG=1 NODE_OPTIONS=--max-old-space-size=16384 test-storybook --browsers chromium webkit --no-index-json","test:visual:update": "pnpm build:products && cd ../.. && rm -rf frontend/__snapshots__/__failures__/ && docker compose -f docker-compose.playwright.yml run --rm -it --build playwright pnpm test:visual:update:docker --url http://host.docker.internal:6006","test:visual:update:docker": "pnpm build:products && NODE_OPTIONS=--max-old-space-size=16384 test-storybook -u --browsers chromium webkit --no-index-json"@@ -57,5 +57,8 @@"webpack": "^5.88.2","webpack-cli": "^5.1.4"},- "devDependencies": {}+ "devDependencies": {+ "http-server": "^14.1.1",+ "wait-on": "^7.2.0"+ }}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 88ab676f44b7..5d55a3e4916e 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -519,6 +519,13 @@ importers:webpack-cli:specifier: ^5.1.4version: 5.1.4([email protected])+ devDependencies:+ http-server:+ specifier: ^14.1.1+ version: 14.1.1+ wait-on:+ specifier: ^7.2.0+ version: 7.2.0common/tailwind:dependencies:@@ -13182,6 +13189,9 @@ packages:resolution: {integrity: sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==}+ resolution: {integrity: sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==}+resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}@@ -13401,6 +13411,10 @@ packages:engines: {node: '>=6.0.0'}hasBin: true+ resolution: {integrity: sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==}+ engines: {node: '>= 0.8'}+resolution: {integrity: sha512-VoMINM2rqJwJgfdHq6RiUudKt2BV+FY5ZFezP/ypmwayk68+NzzAQy4XXLlqsGD4MCzq3DrmNFD/uUmBJuGoXw==}engines: {node: '>=10.0.0'}@@ -14134,6 +14148,10 @@ packages:resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}engines: {node: '>= 0.10'}+ resolution: {integrity: sha512-utCYNzRSQIZNPIcGZdQc92UVJYAhtGAteCFg0yRaFm8f0P+CPtyGyHXJcGXnffjCybUCEx3FQ2G7U3/o9eIkVQ==}+ engines: {node: '>= 0.4.0'}+resolution: {integrity: sha512-AdmX6xUzdNASswsFtmwSt7Vj8po9IuqXm0UXz7QKPuEUmPB4XyjGfaAr2PSuELMwkRMVH1EpIkX5bTZGRB3eCA==}engines: {node: '>=10'}@@ -15232,6 +15250,9 @@ packages:resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==}engines: {node: '>=6'}+ resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==}+resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==}@@ -16254,9 +16275,18 @@ packages:resolution: {integrity: sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==}engines: {node: '>= 14'}+ resolution: {integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==}+ engines: {node: '>=8.0.0'}+resolution: {integrity: sha512-bqX0XTF6fnXSQcEJ2Iuyr75yVakyjIDCqroJQ/aHfSdlM743Cwqoi2nDYMzLGWUcuTWGWy8AAvOKXTfiv6q9RA==}+ resolution: {integrity: sha512-+cbxadF40UXd9T01zUHgA+rlo2Bg1Srer4+B4NwIHdaGxAGGv59nYRnGGDJ9LBk7alpS0US+J+bLLdQOOkJq4A==}+ engines: {node: '>=12'}+ hasBin: true+resolution: {integrity: sha512-zoDhWrkR3of1l9QAL8/scJZyLu8j/gBkcwcaQOZh7Gyh/+uJQzGVETdgT30akuwkpL8HTRfssqI3BZuV18teDg==}engines: {node: '>= 6.0.0'}@@ -18980,6 +19010,10 @@ packages:resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==}engines: {node: '>=12'}+ resolution: {integrity: sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A==}+ hasBin: true+resolution: {integrity: sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==}engines: {node: '>= 0.8.0'}@@ -19441,6 +19475,10 @@ packages:resolution: {integrity: sha512-Sz2Lkdxz6F2Pgnpi9U5Ng/WdWAUZxmHrNPoVlm3aAemxoy2Qy7LGjQg4uf8qKelDAUW94F4np3iH2YPf2qefcQ==}engines: {node: '>=10'}+ resolution: {integrity: sha512-rEwq/ZHlJIKw++XtLAO8PPuOQA/zaPJOZJ37BVuN97nLpMJeuDVLVGRwbFoBgLudgdTMP2hdRJP++H+8QOA3vg==}+ engines: {node: '>= 10.12'}+resolution: {integrity: sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==}engines: {node: '>= 0.4'}@@ -21208,6 +21246,9 @@ packages:resolution: {integrity: sha512-49oNpRjWRvnU8NyGVmUaYG4jtTkNonFZI86MmGRDqBphEK2EXT9gdEUoQPZhuBM8yWHxCWbobltqYO5M4XrUvQ==}+ resolution: {integrity: sha512-AckIIV90rPDcBcglUwXPF3kg0P0qmPsPXAj6BBEENQE1p5yA1xfmDJzfi1Tappj37Pv2mVbKpL3Z1T+Nn7k1Qw==}+resolution: {integrity: sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==}@@ -22561,6 +22602,10 @@ packages:resolution: {integrity: sha512-tJfXmxMeWYnczCVs7XAEvIV7ieppALdyepWMkHkwciRpZraG/xwT+s2JN8+pr1+8jCRf80FFzvr+MpQeeoF4Xg==}engines: {node: '>=0.10.0'}+ resolution: {integrity: sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA==}+ engines: {node: '>= 0.8.0'}+resolution: {integrity: sha512-fJAy3gTHjFi5S3TP5EGdjs/OUMFFvI/ady3T8qVuZfkv8Qi8prV/Q8BuFEgODJslhZTT2z2qdD2lGdee9qjEnA==}@@ -22651,6 +22696,9 @@ packages:resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==}+ resolution: {integrity: sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==}+resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==}@@ -37135,6 +37183,8 @@ snapshots:+ [email protected]: {}+@@ -37503,6 +37553,10 @@ snapshots:+ dependencies:+ safe-buffer: 5.1.2+@@ -38276,6 +38330,8 @@ snapshots:object-assign: 4.1.1vary: 1.1.2+ [email protected]: {}+dependencies:'@types/parse-json': 4.0.0@@ -39812,6 +39868,8 @@ snapshots:+ [email protected]: {}+@@ -41075,11 +41133,38 @@ snapshots:transitivePeerDependencies:- supports-color+ dependencies:+ eventemitter3: 4.0.7+ follow-redirects: 1.15.11+ requires-port: 1.0.0+ transitivePeerDependencies:+ - debug+dependencies:'@types/node': 10.17.60optional: true+ dependencies:+ basic-auth: 2.0.1+ chalk: 4.1.2+ corser: 2.0.1+ he: 1.2.0+ html-encoding-sniffer: 3.0.0+ http-proxy: 1.18.1+ mime: 1.6.0+ minimist: 1.2.8+ opener: 1.5.2+ portfinder: 1.0.38+ secure-compare: 3.0.1+ union: 0.5.0+ url-join: 4.0.1+ transitivePeerDependencies:+ - debug+ - supports-color+dependencies:agent-base: 5.1.1@@ -44826,6 +44911,8 @@ snapshots:is-docker: 2.2.1is-wsl: 2.2.0+ [email protected]: {}+dependencies:'@aashutoshrathi/word-wrap': 1.2.6@@ -45423,6 +45510,13 @@ snapshots:dependencies:'@babel/runtime': 7.29.2+ dependencies:+ async: 3.2.6+ debug: 4.4.3+ transitivePeerDependencies:+ - supports-color+@@ -47760,6 +47854,8 @@ snapshots:dependencies:compute-scroll-into-view: 3.1.1+ [email protected]: {}+@@ -49356,6 +49452,10 @@ snapshots:is-extendable: 0.1.1set-value: 2.0.1+ dependencies:+ qs: 6.15.1+dependencies:fs-monkey: 1.0.4@@ -49481,6 +49581,8 @@ snapshots:dependencies:punycode: 2.3.0+ [email protected]: {}+dependencies:querystringify: 2.2.0