: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): stop managed warehouse and dags edits fanning out tests (#125990)
Eric Duong060a1b214fae
diff --git a/.github/scripts/turbo-discover-selection.test.js b/.github/scripts/turbo-discover-selection.test.jsindex ea09ea3d0d1c..a500ba5d7b21 100644--- a/.github/scripts/turbo-discover-selection.test.js+++ b/.github/scripts/turbo-discover-selection.test.js@@ -6,7 +6,13 @@const { test } = require('node:test')const assert = require('node:assert/strict')-const { decideJsonTargets, decideSelection, narrowedProducts, selectedShards } = require('./turbo-discover')+const {+ decideJsonTargets,+ decideSelection,+ isDagsterOnlyLegacyEdit,+ narrowedProducts,+ selectedShards,+} = require('./turbo-discover')const segments = (extra) => ({ core: [], poe: [], temporal: [], compat: [], ...extra })@@ -63,6 +69,16 @@ test('each distrusted input has its own reason, so telemetry can tell them apart[{ selection: null }, 'selector_error'],[{ selection: selectionFixture({ ast: { full_run_reasons: ['posthog/settings/base.py'] } }) }, 'full_run_requested'],[{ selection: selectionFixture({ combined: { count: 0, products: [], segments: segments() } }) }, 'empty_selection'],+ [+ {+ dagsterOnlyLegacyEdit: true,+ selection: selectionFixture({+ snob: { status: 'error' },+ combined: { count: 0, products: [], segments: segments() },+ }),+ },+ 'empty_selection',+ ],[{ selection: selectionFixture({ durations: { total_seconds: 0, selected_seconds: 0, skipped_seconds: 0 } }) }, 'no_durations'],[{ selection: selectionFixture({ durations: undefined }) }, 'no_durations'],]@@ -128,6 +144,37 @@ test('a selection with no temporal file does not start the temporal leg', () =>assert.equal(decision.temporal_files, '')})+test('a Dagster-only legacy edit that selects no Django test runs no Django leg', () => {+ const decision = decide({+ dagsterOnlyLegacyEdit: true,+ selection: selectionFixture({+ snob: { status: 'ok' },+ combined: { count: 0, products: [], segments: segments() },+ }),+ })+ assert.equal(decision.mode, 'selected')+ assert.equal(decision.narrowed, true)+ assert.equal(decision.skip_reason, '')+ assert.equal(decision.core_files, '')+ assert.equal(decision.run_poe, false)+ assert.equal(decision.run_temporal, false)+})++test('only Dagster Python that still exists counts as a Dagster-only legacy edit', () => {+ const exists = (file) => !file.includes('deleted')+ const cases = [+ [['posthog/dags/backfill.py'], true],+ [['posthog/dags/backfill.py', 'posthog/dags/README.md', 'products/foo/backend/bar.py'], true],+ [['posthog/dags/backfill.py', 'posthog/models/team.py'], false],+ [['posthog/dags/schedule.yaml'], false],+ [['posthog/dags/deleted_job.py'], false],+ [undefined, false],+ ]+ for (const [changedFiles, expected] of cases) {+ assert.equal(isDagsterOnlyLegacyEdit(changedFiles, exists), expected, JSON.stringify(changedFiles))+ }+})+test('applies the full-matrix budget to the selected seconds of each segment', () => {// Work budget per shard is (target wall - segment overhead), same as the full// matrix: Core ceil(5000 / (720 - 295)) = 12, Temporal ceil(900 / (720 - 182)) = 2.diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.jsindex 8120eaeaa3ae..a3fdee673379 100644--- a/.github/scripts/turbo-discover.js+++ b/.github/scripts/turbo-discover.js@@ -1206,6 +1206,25 @@ function fallbackSelection(fallbackMode, reason, selection) {return { mode: fallbackMode, narrowed: false, skip_reason: reason, ...emptySegments(), ...selectionMetrics(selection) }}+// Whether every legacy edit in the diff is Dagster Python under posthog/dags/. ci-dagster.yml runs+// the tests there, and the selector assigns them to no Django segment. No module that Django loads+// imports posthog.dags, because its __init__.py calls django.setup() again, so a Django test reaches+// Dagster code only through its own import, which the selector follows. That makes an empty Django+// selection correct for such a diff. A deleted file has no imports left to follow, so it does not+// qualify. Products and Markdown are not legacy edits, so they may sit beside the Dagster files.+function isDagsterOnlyLegacyEdit(changedFiles, fileExists) {+ if (!Array.isArray(changedFiles)) {+ return false+ }+ const isDagsterPython = (file) => file.startsWith('posthog/dags/') && file.endsWith('.py')+ const dagsterFiles = changedFiles.filter(isDagsterPython)+ return (+ dagsterFiles.length > 0 &&+ dagsterFiles.every((file) => fileExists(file)) &&+ changedFiles.every((file) => isDagsterPython(file) || file.startsWith('products/') || /\.mdx?$/.test(file))+ )+}+// Which Django tests this run should execute, and whether the product matrix may narrow.// Pure: every input is an argument, so each branch is unit-tested rather than inferred// from a workflow run.@@ -1213,9 +1232,19 @@ function fallbackSelection(fallbackMode, reason, selection) {// disabled the DISABLE_BACKEND_TEST_SELECTION kill switch// draft fall back by skipping rather than by running everything// legacyChanged the paths filter saw an edit under posthog/ or ee/+// dagsterOnlyLegacyEdit every legacy edit is Dagster Python, see isDagsterOnlyLegacyEdit// runLegacy whether the Django suite runs, and why// selection the selector's parsed output, null when it did not produce one-function decideSelection({ applies, disabled, draft, legacyChanged, runLegacy, runLegacyReason, selection }) {+function decideSelection({+ applies,+ disabled,+ draft,+ legacyChanged,+ dagsterOnlyLegacyEdit,+ runLegacy,+ runLegacyReason,+ selection,+}) {if (!applies || runLegacy === false) {// Nothing to narrow: either the event never selects, or the Django suite is// skipped outright. An empty mode leaves every consumer on its own default.@@ -1251,13 +1280,17 @@ function decideSelection({ applies, disabled, draft, legacyChanged, runLegacy, rconst poe = segments.poe ?? []const temporal = segments.temporal ?? []const compat = segments.compat ?? []- if (legacyChanged && core.length === 0 && temporal.length === 0) {+ // The Dagster exemption trusts the import graph. A failed Snob run still exits cleanly, with+ // segments that the graph never filled, so it cannot claim the exemption.+ const dagsterExempt = dagsterOnlyLegacyEdit && selection.snob?.status === 'ok'+ if (legacyChanged && !dagsterExempt && core.length === 0 && temporal.length === 0) {// A diff that touched legacy code but selected no Django test at all means the// selector had no rule for it, not that there is nothing to run — a non-Python// legacy file (C++ parser sources, a JSON config) reaches no import edge.// Narrowing to zero would silently gate on nothing. FULL_RUN_PATTERNS covers the// known cases; this catches the ones added to the `legacy` paths filter and// forgotten there. Products-only diffs legitimately select nothing and are not legacy.+ // A diff whose legacy edits are all Dagster Python also legitimately selects nothing.return fallbackSelection(fallbackMode, 'empty_selection', selection)}console.error(`Selected: ${core.length} core, ${poe.length} POE-eligible, ${temporal.length} temporal, ${compat.length} compat`)@@ -1513,6 +1546,7 @@ function buildMatrix(products, durations, productsScaled = false) {module.exports = {narrowedProducts,decideSelection,+ isDagsterOnlyLegacyEdit,decideJsonTargets,loadJsonTargets,selectedShards,@@ -1772,6 +1806,7 @@ const selectionDecision = decideSelection({disabled: process.env.SELECTION_DISABLED === 'true',draft: process.env.PR_DRAFT === 'true',legacyChanged,+ dagsterOnlyLegacyEdit: isDagsterOnlyLegacyEdit(selection?.changed_files, fs.existsSync),runLegacy,runLegacyReason,selection,diff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.ymlindex 6747889fb511..cbc7ff7000a3 100644--- a/.github/workflows/ci-e2e-playwright.yml+++ b/.github/workflows/ci-e2e-playwright.yml@@ -214,6 +214,10 @@ jobs:- '!posthog/**/conftest.py'- '!ee/**/test_*.py'- '!ee/**/conftest.py'+ # Dagster code never loads in the E2E stack. No Dagster process runs there,+ # and no web app or worker module imports posthog.dags, because its+ # __init__.py calls django.setup() again. ci-dagster.yml runs its tests.+ - '!posthog/dags/**'hogqlParser:- 'common/hogql_parser/**'diff --git a/posthog/hogql/direct_sql/duckgres_adapter.py b/posthog/hogql/direct_sql/duckgres_adapter.pyindex 3277ce8be3da..b0a1953f70cd 100644--- a/posthog/hogql/direct_sql/duckgres_adapter.py+++ b/posthog/hogql/direct_sql/duckgres_adapter.py@@ -35,8 +35,6 @@ from posthog.dataclasses import frozenfrom posthog.direct_query_cancellation import is_direct_query_cancellation_requestedfrom posthog.psycopg_helpers import resolve_psycopg_hostaddr_with_timeout-from products.managed_warehouse.backend.facade.contracts import ManagedWarehouseSourceAuth, ServiceCredentialUnavailable-from products.managed_warehouse.backend.facade.sql_editor import resolve_managed_warehouse_postgres_connectionfrom products.warehouse_sources.backend.facade.models import MANAGED_WAREHOUSE_SERVICE_CREDENTIAL_KINDfrom products.warehouse_sources.backend.facade.source_inputs import SourceInputsStore, UnreadableSourceInputsError@@ -396,6 +394,17 @@ class DuckgresRawAdapter:if not request.source.is_dynamic_managed_warehouse or request.principal is None:raise ExposedHogQLError(MANAGED_WAREHOUSE_UNAVAILABLE_ERROR)+ # posthog.test.base reaches this module through posthog.hogql.query. Module-level imports of+ # the managed warehouse facade here make every test that uses posthog.test.base depend on the+ # facade, so the CI test selector selects all of those tests for any edit to the facade.+ from products.managed_warehouse.backend.facade.contracts import ( # noqa: PLC0415 -- keeps the facade out of the test import graph+ ManagedWarehouseSourceAuth,+ ServiceCredentialUnavailable,+ )+ from products.managed_warehouse.backend.facade.sql_editor import ( # noqa: PLC0415 -- keeps the facade out of the test import graph+ resolve_managed_warehouse_postgres_connection,+ )+try:connection = resolve_managed_warehouse_postgres_connection(source_auth=ManagedWarehouseSourceAuth(diff --git a/posthog/hogql/test/test_direct_duckgres_query.py b/posthog/hogql/test/test_direct_duckgres_query.pyindex 7228a8698519..2e30469ebe51 100644--- a/posthog/hogql/test/test_direct_duckgres_query.py+++ b/posthog/hogql/test/test_direct_duckgres_query.py@@ -25,6 +25,11 @@ from posthog.constants import AvailableFeaturefrom posthog.models import OrganizationMembership, Teamfrom products.access_control.backend.models.access_control import AccessControl++# The adapter imports these inside a method, and the CI test selector does not follow such imports.+# Module-level imports here keep an edit to the facade selecting this file.+from products.managed_warehouse.backend.facade import sql_editor as managed_warehouse_sql_editor+from products.managed_warehouse.backend.facade.contracts import ManagedWarehouseTrinoConnectionUnavailablefrom products.warehouse_sources.backend.facade.models import (MANAGED_WAREHOUSE_SOURCE_PREFIX,DataWarehouseTable,@@ -279,8 +284,6 @@ class TestDirectDuckgresQuery(APIBaseTest):@parameterized.expand([("open",), ("enter",)])@patch("posthoganalytics.feature_enabled", return_value=True)def test_managed_trino_unavailable_does_not_fall_back_to_duckgres(self, stage: str, _flag: MagicMock) -> None:- from products.managed_warehouse.backend.facade.contracts import ManagedWarehouseTrinoConnectionUnavailable-source = self._dynamic_managed_source()source.job_inputs = {}source.save(update_fields=["job_inputs"])@@ -445,7 +448,7 @@ class TestDirectDuckgresQuery(APIBaseTest):cursor.stream.assert_called_once_with("SELECT 1 AS value", None)@patch("posthog.hogql.direct_sql.duckgres_adapter._connect_duckgres_address")- @patch("posthog.hogql.direct_sql.duckgres_adapter.resolve_managed_warehouse_postgres_connection")+ @patch.object(managed_warehouse_sql_editor, "resolve_managed_warehouse_postgres_connection")def test_dynamic_source_mints_for_the_stable_user_identity_and_uses_tls(self, resolve_connection, connect) -> None:source = self._dynamic_managed_source()source.job_inputs = {}