: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(ci): emit reason detail for playwright spec-selection fallbacks (#72254)
Georges-Antoine Assi0c131f6aac41
diff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.ymlindex 33c8ed5a432f..4e34ab8ed617 100644--- a/.github/workflows/ci-e2e-playwright.yml+++ b/.github/workflows/ci-e2e-playwright.yml@@ -335,6 +335,7 @@ jobs:skipped_count: ${{ steps.classify.outputs.skipped_count }}changed_file_count: ${{ steps.classify.outputs.changed_file_count }}full_run_reason_category: ${{ steps.classify.outputs.full_run_reason_category }}+ full_run_reason_detail: ${{ steps.classify.outputs.full_run_reason_detail }}steps:# Full checkout at PR head so the selector can glob specs on disk and read# the map/script from the branch under test. Bounded depth + blob:none keeps@@ -385,6 +386,7 @@ jobs:SKIPPED_COUNT=""CHANGED_COUNT=""REASON_CATEGORY=""+ REASON_DETAIL=""if [[ "$SELECT_OUTCOME" != "success" ]] || [[ ! -s /tmp/spec-selection.json ]]; thenecho "::warning::spec selector produced no output — running the FULL suite"@@ -396,6 +398,7 @@ jobs:TOTAL_COUNT=$(jq -r '.total_spec_count' /tmp/spec-selection.json)CHANGED_COUNT=$(jq -r '.changed_file_count' /tmp/spec-selection.json)REASON_CATEGORY=$(jq -r '.full_run_reason_category' /tmp/spec-selection.json)+ REASON_DETAIL=$(jq -r '.full_run_reason_detail // ""' /tmp/spec-selection.json)SKIPPED_COUNT=$((TOTAL_COUNT - SELECTED_COUNT))if [[ "$MODE" == "selected" ]]; thenSPECS=$(jq -r '.spec_files | join(" ")' /tmp/spec-selection.json)@@ -423,6 +426,7 @@ jobs:echo "skipped_count=$SKIPPED_COUNT"echo "changed_file_count=$CHANGED_COUNT"echo "full_run_reason_category=$REASON_CATEGORY"+ echo "full_run_reason_detail=$REASON_DETAIL"} >> "$GITHUB_OUTPUT"echo "mode=$MODE category=${REASON_CATEGORY:-none} selected=${SELECTED_COUNT:-?}/${TOTAL_COUNT:-?}"@@ -1092,6 +1096,7 @@ jobs:"skipped_count": ${{ needs.select-specs.outputs.skipped_count || 'null' }},"changed_file_count": ${{ needs.select-specs.outputs.changed_file_count || 'null' }},"full_run_reason_category": ${{ toJSON(needs.select-specs.outputs.full_run_reason_category || '') }},+ "full_run_reason_detail": ${{ toJSON(needs.select-specs.outputs.full_run_reason_detail || '') }},"playwright_test_seconds": ${{ needs.playwright.outputs.test_seconds || 'null' }},"playwright_result": ${{ toJSON(needs.playwright.result) }},"runner_billing_multiplier": 4,diff --git a/tools/playwright_spec_selection.py b/tools/playwright_spec_selection.pyindex 360e9d95c530..f9ab72264388 100644--- a/tools/playwright_spec_selection.py+++ b/tools/playwright_spec_selection.py@@ -21,13 +21,20 @@ Emits a single JSON object to stdout:{"mode": "selected" | "full",- "spec_files": [...], # [] when mode == "full"- "full_run_reasons": [...], # why a full run was chosen (empty when selected)+ "spec_files": [...], # [] when mode == "full"+ "full_run_reasons": [...], # why a full run was chosen (empty when selected)+ "full_run_reason_category": "", # low-cardinality category (empty when selected)+ "full_run_reason_detail": "", # low-cardinality trigger (the pattern/scene/product/dir)"changed_files": [...],"changed_file_count": N,"selected_count": M,"total_spec_count": T}++`full_run_reason_detail` names the specific thing that forced the full run, normalized+to stay low-cardinality so it groups cleanly in analytics: the matched `force_full`+pattern, the unmapped scene/product name, or the offending file's directory prefix+(for `unmapped_path`). It's what tells you which map gap to close next."""from __future__ import annotations@@ -51,6 +58,18 @@ SPEC_GLOBS = ("playwright/e2e/**/*.spec.ts", "products/*/frontend/e2e/**/*.spec._PRODUCT_FRONTEND_RE = re.compile(r"^products/([^/]+)/frontend/")_SCENE_RE = re.compile(r"^frontend/src/scenes/([^/]+)/")+# How many leading path segments to keep when normalizing an unmapped file to a+# directory prefix — enough to point at the area to map, bounded so cardinality stays low.+_DETAIL_PREFIX_SEGMENTS = 3+++def _dir_prefix(path: str) -> str:+ """The file's directory, capped to the first few segments, as a low-cardinality label."""+ parts = path.split("/")[:-1]+ if not parts:+ return "./"+ return "/".join(parts[:_DETAIL_PREFIX_SEGMENTS]) + "/"+class MapError(Exception):"""A map entry doesn't resolve to a real spec on disk — treat as untrustworthy."""@@ -112,13 +131,15 @@ def _result(changed_files: list[str],total_spec_count: int,reason_category: str = "",+ reason_detail: str = "",) -> dict:return {"mode": mode,"spec_files": spec_files,"full_run_reasons": reasons,- # Low-cardinality label for analytics grouping (the reasons carry file paths).+ # Low-cardinality labels for analytics grouping (the reasons carry file paths)."full_run_reason_category": reason_category,+ "full_run_reason_detail": reason_detail,"changed_files": changed_files,"changed_file_count": len(changed_files),"selected_count": len(spec_files),@@ -130,8 +151,8 @@ def select(changed_files: list[str], area_map: dict, all_specs: set[str]) -> dic"""Pure selection: changed files + map + on-disk specs -> a full/selected decision."""total = len(all_specs)- def full(reason: str, category: str) -> dict:- return _result("full", [], [reason], changed_files, total, category)+ def full(reason: str, category: str, detail: str = "") -> dict:+ return _result("full", [], [reason], changed_files, total, category, detail)if not changed_files:return full("empty diff (defensive full run)", "empty_diff")@@ -156,7 +177,7 @@ def select(changed_files: list[str], area_map: dict, all_specs: set[str]) -> dic# 1. Shared infra / backend / unattributable code -> full (highest priority).for pat, rx in force_full:if rx.match(f):- return full(f"{f} matches force-full pattern '{pat}'", "force_full")+ return full(f"{f} matches force-full pattern '{pat}'", "force_full", pat)# 2. Product-owned frontend -> that product's specs (or an explicit rule for# products whose behavior is exercised by top-level specs).@@ -169,7 +190,7 @@ def select(changed_files: list[str], area_map: dict, all_specs: set[str]) -> diccontinueif explicit_match(f, selected):continue- return full(f"{f}: product '{name}' has no spec mapping", "unmapped_product")+ return full(f"{f}: product '{name}' has no spec mapping", "unmapped_product", name)# 3. Frontend scene -> mapped specs.sm = _SCENE_RE.match(f)@@ -179,7 +200,7 @@ def select(changed_files: list[str], area_map: dict, all_specs: set[str]) -> dicfor t in scenes[area]:selected |= expand_target(t, all_specs)continue- return full(f"{f}: scene '{area}' has no spec mapping", "unmapped_scene")+ return full(f"{f}: scene '{area}' has no spec mapping", "unmapped_scene", area)# 4. Explicit path rules.if explicit_match(f, selected):@@ -191,7 +212,7 @@ def select(changed_files: list[str], area_map: dict, all_specs: set[str]) -> diccontinue# 6. Anything unrecognized -> full (fail closed).- return full(f"{f}: unmapped path", "unmapped_path")+ return full(f"{f}: unmapped path", "unmapped_path", _dir_prefix(f))# Belt-and-suspenders: a directly-edited spec always runs even if its area also mapped.selected |= {f for f in changed_files if f in all_specs}diff --git a/tools/test_playwright_spec_selection.py b/tools/test_playwright_spec_selection.pyindex 6cf3a1f5663e..ee4de4eae030 100644--- a/tools/test_playwright_spec_selection.py+++ b/tools/test_playwright_spec_selection.py@@ -45,8 +45,9 @@ class TestPlaywrightSpecSelection(unittest.TestCase):return selection.select(changed, FAKE_MAP, FAKE_SPECS)def test_select_behavior_matrix(self) -> None:- # (name, changed files, expected mode, expected specs (selected) or reason category (full))- cases: list[tuple[str, list[str], str, set[str] | str]] = [+ # (name, changed files, expected mode,+ # selected -> expected specs; full -> (reason category, reason detail))+ cases: list[tuple[str, list[str], str, set[str] | tuple[str, str]]] = [("mapped product frontend narrows to that product's specs",["products/surveys/frontend/logic.ts"],@@ -75,16 +76,29 @@ class TestPlaywrightSpecSelection(unittest.TestCase):{"playwright/e2e/auth.spec.ts"},),# Fail-closed: the core safety property. Any of these dropping to "selected" is a- # coverage hole. The category is the analytics grouping key, so lock it too.- ("unmapped scene forces full", ["frontend/src/scenes/settings/x.ts"], "full", "unmapped_scene"),- ("unmapped product forces full", ["products/messaging/frontend/x.ts"], "full", "unmapped_product"),- ("unrecognized path forces full", ["some/random/file.ts"], "full", "unmapped_path"),- # force_full wins even when another changed file would have narrowed.+ # coverage hole. Category + detail are the analytics grouping keys (detail names the+ # map gap to close and must stay low-cardinality), so lock both.+ (+ "unmapped scene forces full",+ ["frontend/src/scenes/settings/x.ts"],+ "full",+ ("unmapped_scene", "settings"),+ ),+ (+ "unmapped product forces full",+ ["products/messaging/frontend/x.ts"],+ "full",+ ("unmapped_product", "messaging"),+ ),+ ("unrecognized path forces full", ["some/random/file.ts"], "full", ("unmapped_path", "some/random/")),+ # unmapped_path detail is normalized to a bounded dir prefix, not the raw (high-cardinality) file path.+ ("deep unmapped path caps to leading segments", ["a/b/c/d/e.ts"], "full", ("unmapped_path", "a/b/c/")),+ # force_full wins even when another changed file would have narrowed; detail is the matched pattern.("force-full pattern forces full alongside a mappable file",["products/surveys/frontend/logic.ts", "posthog/models/team.py"],"full",- "force_full",+ ("force_full", "posthog/**"),),# `*` must not cross `/`: a nested spec dir change must not be swallowed by `playwright/*.ts`.(@@ -93,7 +107,7 @@ class TestPlaywrightSpecSelection(unittest.TestCase):"selected",{"playwright/e2e/billing/billing.spec.ts"},),- ("empty diff defaults to full", [], "full", "empty_diff"),+ ("empty diff defaults to full", [], "full", ("empty_diff", "")),]for name, changed, mode, expected in cases:with self.subTest(name):@@ -102,8 +116,10 @@ class TestPlaywrightSpecSelection(unittest.TestCase):if mode == "selected":self.assertEqual(set(result["spec_files"]), expected, msg=name)else:+ category, detail = expectedself.assertTrue(result["full_run_reasons"], msg=f"{name}: expected a reason")- self.assertEqual(result["full_run_reason_category"], expected, msg=name)+ self.assertEqual(result["full_run_reason_category"], category, msg=name)+ self.assertEqual(result["full_run_reason_detail"], detail, msg=name)def test_over_ceiling_forces_full(self) -> None:changed = [f"products/surveys/frontend/f{i}.ts" for i in range(selection.MAX_CHANGED_FILES + 1)]