: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(data-warehouse): exempt warehouse source changes from stamphog auth gate (#63931)
Tom Owers50e705db4c4a
diff --git a/tools/pr-approval-agent/gates.py b/tools/pr-approval-agent/gates.pyindex ee4be575ebd7..d6137b3e3ee3 100644--- a/tools/pr-approval-agent/gates.py+++ b/tools/pr-approval-agent/gates.py@@ -374,6 +374,20 @@ def test_only(categories: dict[str, int]) -> bool:# ── Deny / allow detection ───────────────────────────────────────+# Path prefixes exempt from the `auth` deny category. Code under these trees+# performs auth/OAuth/credential handshakes as part of its normal job — e.g.+# every data warehouse import connector — so the code and PR titles legitimately+# mention auth, oauth, token, login, etc. without touching the auth *system*.+# Without this, the `auth` deny would force T2-never on essentially every such+# PR. Other deny categories (crypto/secrets, migrations, …) still apply. Add new+# exempt trees here rather than special-casing in detect_deny_categories.+AUTH_EXEMPT_PATH_PREFIXES = ("posthog/temporal/data_imports/sources/",)+++def _is_auth_exempt_path(path: str) -> bool:+ low = path.lower()+ return any(low.startswith(prefix) for prefix in AUTH_EXEMPT_PATH_PREFIXES)+def detect_deny_categories(files: list[str], subject: str, ignored_files: set[str] | None = None) -> list[str]:hits: set[str] = set()@@ -381,13 +395,23 @@ def detect_deny_categories(files: list[str], subject: str, ignored_files: set[stpaths_lower = [f.lower() for f in files if f.lower() not in ignored_files_lower]subject_lower = subject.lower()+ # Auth exemption for AUTH_EXEMPT_PATH_PREFIXES: drop exempt paths from auth+ # path-matching, and — when any exempt path is in the change set — only let+ # the PR title trip `auth` if a non-exempt file is also touched. PRs that+ # touch no exempt paths are evaluated exactly as before.+ auth_paths = [p for p in paths_lower if not _is_auth_exempt_path(p)]+ has_exempt_path = len(auth_paths) != len(paths_lower)+ auth_title_eligible = (not has_exempt_path) or bool(auth_paths)+for category, scopes in DENY_PATTERNS.items():+ category_paths = auth_paths if category == "auth" else paths_lower+ title_eligible = auth_title_eligible if category == "auth" else Truefound = False# "paths" patterns — only match against file pathsfor rx in scopes.get("paths", []):if found:break- for p in paths_lower:+ for p in category_paths:if rx.search(p):hits.add(category)found = True@@ -398,12 +422,12 @@ def detect_deny_categories(files: list[str], subject: str, ignored_files: set[stfor path_rx, title_rx in scopes.get("any", []):if found:break- for p in paths_lower:+ for p in category_paths:if path_rx.search(p):hits.add(category)found = Truebreak- if not found and title_rx.search(subject_lower):+ if not found and title_eligible and title_rx.search(subject_lower):hits.add(category)found = Truereturn sorted(hits)diff --git a/tools/pr-approval-agent/test_gates.py b/tools/pr-approval-agent/test_gates.pyindex eace17803d5b..00423168af7b 100644--- a/tools/pr-approval-agent/test_gates.py+++ b/tools/pr-approval-agent/test_gates.py@@ -188,3 +188,67 @@ def test_ignored_files_does_not_bypass_other_deny_list_files() -> None:ignored = {"posthog/migrations/1117_alter_integration_kind.py"}assert detect_deny_categories(files, "feat: integration field", ignored_files=ignored) == ["migrations"]+++# ── Data warehouse source auth exemption ─────────────────────────+++ "files, subject",+ [+ pytest.param(+ ["posthog/temporal/data_imports/sources/stripe/auth.py"],+ "fix(stripe): refresh oauth token before sync",+ id="dwh-source-auth-file-and-title",+ ),+ pytest.param(+ ["posthog/temporal/data_imports/sources/postgres/source.py"],+ "fix(postgres): treat invalid SSH tunnel auth as non-retryable",+ id="dwh-source-auth-in-title-only",+ ),+ pytest.param(+ [+ "posthog/temporal/data_imports/sources/salesforce/source.py",+ "posthog/temporal/data_imports/sources/salesforce/settings.py",+ ],+ "fix(salesforce): treat deleted oauth credential as non-retryable",+ id="dwh-source-multi-file-oauth-credential",+ ),+ ],+)+def test_dwh_source_auth_exempt(files: list[str], subject: str) -> None:+ assert "auth" not in detect_deny_categories(files, subject)+++def test_dwh_source_still_denies_non_auth_categories() -> None:+ # Only `auth` is exempted — crypto/secrets still applies to source files.+ files = ["posthog/temporal/data_imports/sources/stripe/api_key_store.py"]+ result = detect_deny_categories(files, "feat(stripe): rotate api key")+ assert "auth" not in result+ assert "crypto_secrets" in result+++ "files, subject",+ [+ pytest.param(+ [+ "posthog/temporal/data_imports/sources/stripe/source.py",+ "posthog/api/authentication.py",+ ],+ "fix: stripe auth and login flow",+ id="dwh-source-mixed-real-auth-file",+ ),+ pytest.param(+ [+ "posthog/temporal/data_imports/sources/stripe/source.py",+ "posthog/api/foo.py",+ ],+ "fix: oauth login redirect",+ id="dwh-source-mixed-unrelated-file-auth-title",+ ),+ ],+)+def test_dwh_source_mixed_still_denies(files: list[str], subject: str) -> None:+ # Auth gate must still fire when any non-source file is in the change set.+ assert "auth" in detect_deny_categories(files, subject)