: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(ci): run storybook when the replay player frame template changes (#120839)
Jimmy Zhua4507edeccc7
diff --git a/.agents/skills/authoring-ci-workflows/SKILL.md b/.agents/skills/authoring-ci-workflows/SKILL.mdindex cb028e937a5f..346ca800dd7f 100644--- a/.agents/skills/authoring-ci-workflows/SKILL.md+++ b/.agents/skills/authoring-ci-workflows/SKILL.md@@ -29,7 +29,7 @@ The linters own the mechanical rules (below); this skill is the **judgment calls## What the linters already enforceRun `bin/hogli lint:workflows` and `actionlint` before pushing — they gate CI, and they (not this list) are the source of truth for what's enforced.-Today that's: `timeout-minutes` on every job, the canonical PR concurrency block, a repo-wide budget for unscoped PR event dispatches, `dorny/paths-filter` negation safety, justification for full-depth checkouts, cache-write gating, semgrep service coverage, MCP path-filter coverage of the trees the MCP build compiles, required-check gate hygiene, secrets a reusable workflow reads being declared and passed by its callers, runner labels that name an OS version rather than a floating `-latest` alias, `#`-free values for the action inputs an inner shell re-parses, and generic GHA correctness (bad `secrets.*` / `needs:` refs, deprecated `::set-output`, unknown runner labels).+Today that's: `timeout-minutes` on every job, the canonical PR concurrency block, a repo-wide budget for unscoped PR event dispatches, `dorny/paths-filter` negation safety, justification for full-depth checkouts, cache-write gating, semgrep service coverage, MCP path-filter coverage of the trees the MCP build compiles, Storybook path-filter coverage of every `staticDirs` source, required-check gate hygiene, secrets a reusable workflow reads being declared and passed by its callers, runner labels that name an OS version rather than a floating `-latest` alias, `#`-free values for the action inputs an inner shell re-parses, and generic GHA correctness (bad `secrets.*` / `needs:` refs, deprecated `::set-output`, unknown runner labels).Third-party action digests are bumped by Renovate.## Check what a condition does before you push itdiff --git a/.github/workflows/ci-lint-workflows.yml b/.github/workflows/ci-lint-workflows.ymlindex 84f9e77eadd8..fba8d76a5df9 100644--- a/.github/workflows/ci-lint-workflows.yml+++ b/.github/workflows/ci-lint-workflows.yml@@ -7,6 +7,8 @@ on:- .github/workflows/**- .github/actions/**- services/**+ # WF013 reads its staticDirs, so a new entry has to run the lint.+ - common/storybook/.storybook/main.ts- tools/hogli-commands/hogli_commands/workflow_lint/**- tools/workflow-plan/**- hogli.yamldiff --git a/.github/workflows/ci-storybook.yml b/.github/workflows/ci-storybook.ymlindex 372d8c4b8b1c..96e46b5d7716 100644--- a/.github/workflows/ci-storybook.yml+++ b/.github/workflows/ci-storybook.yml@@ -143,6 +143,9 @@ jobs:- 'packages/quill/**'- 'ee/frontend/**'- 'services/mcp/src/ui-apps/**'+ # Served to the replay stories through staticDirs, so it never+ # enters the module graph. WF013 checks each staticDirs source.+ - 'posthog/templates/replay_player_frame/**'- '.storybook/**'- 'package.json'- '.github/workflows/ci-storybook.yml'diff --git a/bin/find-affected-stories b/bin/find-affected-storiesindex 9dd1ac56a67b..822722b0cb23 100755--- a/bin/find-affected-stories+++ b/bin/find-affected-stories@@ -43,6 +43,9 @@ const FULL_RUN_PATTERNS = ['frontend/src/lib/','frontend/src/styles/','frontend/src/mocks/',+ // A staticDirs source in common/storybook/.storybook/main.ts. The stories fetch it by URL,+ // so no story imports it and a selective run would render zero stories.+ 'posthog/templates/replay_player_frame/','common/tailwind/','tailwind.config.js','tailwind.config.ts',diff --git a/tools/hogli-commands/hogli_commands/tests/test_workflow_lint.py b/tools/hogli-commands/hogli_commands/tests/test_workflow_lint.pyindex ad16fc0d308b..cbfb940904de 100644--- a/tools/hogli-commands/hogli_commands/tests/test_workflow_lint.py+++ b/tools/hogli-commands/hogli_commands/tests/test_workflow_lint.py@@ -45,6 +45,7 @@ from hogli_commands.workflow_lint.checks.shell_split_action_args import (derive_shell_split_inputs,unparseable_actions,)+from hogli_commands.workflow_lint.checks.storybook_static_dirs_coverage import StorybookStaticDirsCoverageCheckfrom hogli_commands.workflow_lint.cli import cmd_lint_workflowsfrom hogli_commands.workflow_lint.model import PR_TRIGGERS, Workflow, WorkflowParseError, read_workflows@@ -2074,6 +2075,81 @@ class TestMcpFilterCoverageCheck:]+# ---------------------------------------------------------------------------+# StorybookStaticDirsCoverageCheck+# ---------------------------------------------------------------------------++_STORYBOOK_MAIN = """+const config = {+ staticDirs: [+ 'public',+ { from: '../../../frontend/public', to: '/static' },+ // { from: '../../../commented/out', to: '/x' },+ { from: '../../../frontend/node_modules/emojibase-data/en', to: '/static/emoji/en' },+ { from: '../../../posthog/templates/replay_player_frame', to: '/replay_player_frame' },+ ],+}+"""+++def _storybook_repo(repo_root: Path, filters: dict[str, list[str]], main: str = _STORYBOOK_MAIN) -> Path:+ _write_file(repo_root / "common" / "storybook" / ".storybook" / "main.ts", main)+ lines = ["name: x", "on: [pull_request]", "jobs:", " changes:", " runs-on: ubuntu-24.04"]+ lines += [" timeout-minutes: 5", " steps:", " - uses: ./.github/actions/paths-filter"]+ lines += [" with:", " filters: |"]+ for name, patterns in filters.items():+ lines += [f" {name}:", *(f" - '{pattern}'" for pattern in patterns)]+ workflows_dir = repo_root / ".github" / "workflows"+ workflows_dir.mkdir(parents=True)+ _write(workflows_dir, "ci-storybook.yml", "\n".join([*lines, ""]))+ return workflows_dir+++class TestStorybookStaticDirsCoverageCheck:+ @pytest.mark.parametrize(+ "filters, uncovered",+ [+ pytest.param(+ {+ "frontend": [+ "frontend/**",+ "common/{mosaic,storybook}/**",+ "posthog/templates/replay_player_frame/**",+ ]+ },+ [],+ id="covered-with-a-brace-group",+ ),+ pytest.param(+ {"frontend": ["frontend/**", "common/{mosaic,storybook}/**"]},+ ["posthog/templates/replay_player_frame"],+ id="template-dir-missing",+ ),+ pytest.param(+ {"frontend": ["frontend/**", "common/storybook/**"], "other": ["posthog/templates/**"]},+ ["posthog/templates/replay_player_frame"],+ id="covered-only-by-another-filter",+ ),+ pytest.param(+ {"frontend": ["frontend/**", "common/storybook/**", "{a,b,c,d,e,f,g,h,i,j}" * 9]},+ ["posthog/templates/replay_player_frame"],+ id="brace-groups-over-the-expansion-cap",+ ),+ ],+ )+ def test_flags_static_dirs_the_frontend_filter_misses(+ self, tmp_path: Path, filters: dict[str, list[str]], uncovered: list[str]+ ) -> None:+ workflows_dir = _storybook_repo(tmp_path, filters)+ issues = StorybookStaticDirsCoverageCheck(repo_root=tmp_path).run(_read_all(workflows_dir)).issues+ assert [issue.message.split("'")[1] for issue in issues] == uncovered++ def test_a_config_with_no_readable_static_dirs_is_reported(self, tmp_path: Path) -> None:+ workflows_dir = _storybook_repo(tmp_path, {"frontend": ["frontend/**"]}, main="const config = {}\n")+ issues = StorybookStaticDirsCoverageCheck(repo_root=tmp_path).run(_read_all(workflows_dir)).issues+ assert len(issues) == 1 and "staticDirs" in issues[0].message++class TestLiveTreeSmoke:"""Smoke test against the live ``.github/workflows/`` tree.diff --git a/tools/hogli-commands/hogli_commands/workflow_lint/checks/__init__.py b/tools/hogli-commands/hogli_commands/workflow_lint/checks/__init__.pyindex 4614b7063161..859ff3d27010 100644--- a/tools/hogli-commands/hogli_commands/workflow_lint/checks/__init__.py+++ b/tools/hogli-commands/hogli_commands/workflow_lint/checks/__init__.py@@ -24,6 +24,7 @@ from .required_gates import RequiredGateCheckfrom .reusable_secret_passthrough import ReusableSecretPassthroughCheckfrom .semgrep_services_coverage import SemgrepServicesCoverageCheckfrom .shell_split_action_args import ShellSplitActionArgsCheck+from .storybook_static_dirs_coverage import StorybookStaticDirsCoverageCheckCHECKS: list[WorkflowCheck] = [JobTimeoutsCheck(),@@ -38,6 +39,7 @@ CHECKS: list[WorkflowCheck] = [ReusableSecretPassthroughCheck(),PinnedRunnerImagesCheck(),ShellSplitActionArgsCheck(),+ StorybookStaticDirsCoverageCheck(),]diff --git a/tools/hogli-commands/hogli_commands/workflow_lint/checks/storybook_static_dirs_coverage.py b/tools/hogli-commands/hogli_commands/workflow_lint/checks/storybook_static_dirs_coverage.pynew file mode 100644index 000000000000..3823355f1491--- /dev/null+++ b/tools/hogli-commands/hogli_commands/workflow_lint/checks/storybook_static_dirs_coverage.py@@ -0,0 +1,140 @@+"""The Storybook ``frontend`` filter must cover every ``staticDirs`` source.++Storybook serves a ``staticDirs`` entry as plain files, so it never enters the+Vite module graph. When the ``frontend`` filter in ``ci-storybook.yml`` misses+one of those trees, a PR that changes only that tree skips Storybook, the merge+queue's ``trunk-merge/**`` run skips it for the same reason, and the visual+change reaches master without review. Every later queue run that does run+Storybook then fails on the unreviewed snapshots.++Entries under ``node_modules`` are skipped, because a dependency change reaches+the filter through ``package.json``.+"""++from __future__ import annotations++import re+from pathlib import Path++from hogli.manifest import REPO_ROOT++from ..check import CheckResult, Issue, WorkflowCheck+from ..model import Workflow, parse_filters+from .mcp_filter_coverage import _covers, _repo_relative++STORYBOOK_MAIN = Path("common/storybook/.storybook/main.ts")+WORKFLOW = "ci-storybook.yml"+FILTER = "frontend"++STATIC_DIRS = re.compile(r"staticDirs:\s*\[(?P<body>.*?)\n\s*\]", re.DOTALL)+STATIC_DIR_STRING = re.compile(r"""(?P<to>\bto:\s*)?['"](?P<path>[^'"]+)['"]""")+LINE_COMMENT = re.compile(r"^\s*//.*$", re.MULTILINE)+BRACES = re.compile(r"\{([^{}]*)\}")+MAX_BRACE_EXPANSIONS = 256+++class StorybookStaticDirsCoverageCheck(WorkflowCheck):+ id = "WF013-storybook-static-dirs-coverage"+ label = "Storybook filter covers staticDirs"+ description = "every staticDirs source in the Storybook config is covered by ci-storybook.yml's frontend filter"++ def __init__(self, repo_root: Path | None = None) -> None:+ self._repo_root = repo_root or REPO_ROOT++ @property+ def fix_hint(self) -> str | None:+ return (+ f"Add a '<dir>/**' pattern for each listed path to the '{FILTER}' filter in {WORKFLOW}, "+ "and add the path to FULL_RUN_PATTERNS in bin/find-affected-stories so the story "+ "selector does not narrow the run to zero stories."+ )++ def run(self, workflows: list[Workflow]) -> CheckResult:+ result = CheckResult()+ try:+ config = (self._repo_root / STORYBOOK_MAIN).read_text(encoding="utf-8")+ except OSError:+ return result+ sources = _static_dir_sources(config)+ if not sources:+ # Reading no sources would pass every filter without checking anything.+ result.issues.append(+ Issue(+ workflow=WORKFLOW,+ message=f"{STORYBOOK_MAIN} has no readable staticDirs entries, so this check verifies nothing",+ file=str(STORYBOOK_MAIN),+ )+ )+ return result++ wf = next((w for w in workflows if w.path.name == WORKFLOW), None)+ if wf is None:+ result.issues.append(+ Issue(workflow=WORKFLOW, message="workflow not found; cannot verify staticDirs coverage")+ )+ return result+ patterns = _filter_patterns(wf)+ for source in sources:+ if any(_covers(pattern, source, needs_directory=True) for pattern in patterns):+ continue+ result.issues.append(+ Issue(+ workflow=WORKFLOW,+ message=(+ f"Storybook serves '{source}' as a static dir, and no pattern in the "+ f"'{FILTER}' filter covers it, so a change there skips Storybook"+ ),+ file=str(wf.path),+ )+ )+ return result+++def _static_dir_sources(config: str) -> list[str]:+ """Repo-relative source directories of the ``staticDirs`` entries, ``node_modules`` excluded."""+ match = STATIC_DIRS.search(LINE_COMMENT.sub("", config))+ if match is None:+ return []+ sources: list[str] = []+ for entry in STATIC_DIR_STRING.finditer(match.group("body")):+ if entry.group("to"):+ continue+ # Storybook resolves staticDirs against the config directory.+ source = _repo_relative(STORYBOOK_MAIN.parent, entry.group("path"))+ if source is None or "node_modules" in source.split("/"):+ continue+ sources.append(source)+ return sources+++def _filter_patterns(wf: Workflow) -> list[str]:+ """Positive globs of the ``frontend`` filter, with ``{a,b}`` groups expanded."""+ patterns: list[str] = []+ for job in wf.jobs:+ for step in job.steps:+ filters = parse_filters(step.with_.get("filters")) if step.with_ is not None else None+ entries = filters.get(FILTER) if filters is not None else None+ if not isinstance(entries, list):+ continue+ for entry in entries:+ if isinstance(entry, str) and not entry.startswith("!"):+ patterns.extend(_expand_braces(entry))+ return patterns+++def _expand_braces(pattern: str) -> list[str]:+ # The filter comes from the PR under lint, so an entry with many brace groups must not+ # expand into millions of globs. An entry over the cap stays unexpanded and covers nothing.+ expansions = 1+ for group in BRACES.findall(pattern):+ expansions *= len(group.split(","))+ if expansions > MAX_BRACE_EXPANSIONS:+ return [pattern]+ match = BRACES.search(pattern)+ if match is None:+ return [pattern]+ head, tail = pattern[: match.start()], pattern[match.end() :]+ return [expanded for option in match.group(1).split(",") for expanded in _expand_braces(head + option + tail)]+++__all__ = ["StorybookStaticDirsCoverageCheck"]