: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
fix(ci): delete 2 tests and ignore deleted tests during backend selection (#90083)
Paul D'Ambradb794afd9408
diff --git a/posthog/test/test_migration_1310.py b/posthog/test/test_migration_1310.pydeleted file mode 100644index 5f8db3ff9e62..000000000000--- a/posthog/test/test_migration_1310.py+++ /dev/null@@ -1,70 +0,0 @@-from typing import Any--from posthog.test.base import NonAtomicTestMigrations---# Non-atomic so a later posthog migration with a CONCURRENTLY index doesn't break the rewind.-class ProvisioningRateLimitOverridesMigrationTest(NonAtomicTestMigrations):- migrate_from = "1309_integration_kind_ext_idx"- migrate_to = "1310_provisioning_rate_limit_overrides"-- CLASS_DATA_LEVEL_SETUP = False-- def setUpBeforeMigration(self, apps: Any) -> None:- OAuthApplication = apps.get_model("posthog", "OAuthApplication")- self.OAuthApplication = OAuthApplication-- def create(client_id: str, config: dict) -> Any:- return OAuthApplication.objects.create(- name=client_id,- client_id=client_id,- client_secret="",- client_type="confidential",- authorization_grant_type="authorization-code",- redirect_uris="https://example.com/callback",- algorithm="RS256",- _provisioning_config=config,- )-- # Tier-sourced: the persisted tier value goes, other keys are normalized while- # this row is being written anyway.- self.tiered = create(- "tiered",- {- "active": True,- "rate_limits": {- "account_requests": 100,- "resource_creates": 5,- "wizard_runs": 0,- "token_exchanges": None,- },- "rate_limit_source": "default_verified",- },- )- # Not tier-sourced, so the migration leaves it alone. 1274 wrote a config onto- # every OAuthApplication, so rewriting these rows would mean rewriting the table;- # the read-path validator normalizes them instead.- self.admin_set = create(- "admin_set",- {- "active": True,- "rate_limits": {"account_requests": 250, "wizard_runs": 0},- "rate_limit_source": "admin",- },- )- self.legacy = create("legacy", {"active": True, "rate_limits": {"account_requests": 42}})- self.untouched = create("untouched", {})-- def test_only_tier_sourced_rows_are_rewritten(self) -> None:- tiered = self.OAuthApplication.objects.get(pk=self.tiered.pk)._provisioning_config- assert tiered["rate_limits"] == {"resource_creates": 5, "wizard_runs": -1}- assert "rate_limit_source" not in tiered-- admin_set = self.OAuthApplication.objects.get(pk=self.admin_set.pk)._provisioning_config- assert admin_set["rate_limits"] == {"account_requests": 250, "wizard_runs": 0}- assert admin_set["rate_limit_source"] == "admin"-- legacy = self.OAuthApplication.objects.get(pk=self.legacy.pk)._provisioning_config- assert legacy["rate_limits"] == {"account_requests": 42}-- assert self.OAuthApplication.objects.get(pk=self.untouched.pk)._provisioning_config == {}diff --git a/products/signals/backend/test/test_migration_0099.py b/products/signals/backend/test/test_migration_0099.pydeleted file mode 100644index ac76ba3b867d..000000000000--- a/products/signals/backend/test/test_migration_0099.py+++ /dev/null@@ -1,56 +0,0 @@-from datetime import UTC, datetime-from typing import Any--from posthog.test.base import NonAtomicTestMigrations---# Non-atomic so a future signals migration with a CONCURRENTLY index doesn't break the rewind.-class BackfillFirstVisibleAtMigrationTest(NonAtomicTestMigrations):- migrate_from = "0098_signalreport_first_visible_index"- migrate_to = "0099_backfill_first_visible_at"-- CLASS_DATA_LEVEL_SETUP = False-- @property- def app(self) -> str:- return "signals"-- def setUpBeforeMigration(self, apps: Any) -> None:- Organization = apps.get_model("posthog", "Organization")- Project = apps.get_model("posthog", "Project")- Team = apps.get_model("posthog", "Team")- SignalReport = apps.get_model("signals", "SignalReport")-- org = Organization.objects.create(name="Test Organization")- project = Project.objects.create(id=999997, organization=org, name="Test Project")- team = Team.objects.create(organization=org, project=project, name="Test Team")-- def make_report(status: str, **kwargs: Any) -> Any:- return SignalReport.objects.create(team_id=team.id, status=status, **kwargs)-- self.stamped_ids = [- make_report("ready").id,- make_report("pending_input").id,- make_report("resolved").id,- make_report("suppressed", status_before_suppression="ready").id,- ]- self.untouched_ids = [- make_report("potential").id,- make_report("failed").id,- make_report("suppressed", status_before_suppression="potential").id,- ]- self.preset_stamp = datetime(2026, 1, 5, 12, 0, tzinfo=UTC)- self.preset_id = make_report("ready", first_visible_at=self.preset_stamp).id-- def test_backfills_only_previously_visible_unstamped_reports(self) -> None:- assert self.apps is not None- SignalReport = self.apps.get_model("signals", "SignalReport")-- for report_id in self.stamped_ids:- report = SignalReport.objects.get(id=report_id)- assert report.first_visible_at == report.created_at-- for report_id in self.untouched_ids:- assert SignalReport.objects.get(id=report_id).first_visible_at is None-- assert SignalReport.objects.get(id=self.preset_id).first_visible_at == self.preset_stampdiff --git a/tools/snob_backend_test_selection_shadow.py b/tools/snob_backend_test_selection_shadow.pyindex 42b966342fb4..3d0e5c96c3e1 100755--- a/tools/snob_backend_test_selection_shadow.py+++ b/tools/snob_backend_test_selection_shadow.py@@ -411,6 +411,10 @@ def _candidate_conventional_tests(path: str) -> list[str]:return [str(candidate) for candidate in candidates if (REPO_ROOT / candidate).is_file()]+def _existing_test_files(paths: list[str] | set[str]) -> list[str]:+ return sorted(path for path in paths if (REPO_ROOT / path).is_file())++def _add_group(groups: dict[str, set[str]], name: str, tests: list[str] | set[str]) -> None:if not tests:return@@ -423,7 +427,7 @@ def ast_select_tests(changed_files: list[str], features_by_path: dict[str, TestFall_test_files = set(features_by_path.keys())# ── 1. Changed test files themselves ─────────────────────────────- changed_tests = [path for path in changed_files if _is_test_file(path)]+ changed_tests = _existing_test_files([path for path in changed_files if _is_test_file(path)])_add_group(groups, "changed_tests", changed_tests)# ── 2. Conventional test neighbors (test_<name>.py next to <name>.py) ─@@ -573,7 +577,7 @@ def snob_select_tests(changed_files: list[str]) -> dict[str, object]:return {"status": "error", "error": f"could not import snob_lib: {exc}", "tests": [], "count": 0}try:- tests = sorted(normalize_repo_path(str(test)) for test in snob_lib.get_tests(changed_py_files))+ tests = _existing_test_files({normalize_repo_path(str(test)) for test in snob_lib.get_tests(changed_py_files)})except Exception as exc:return {"status": "error", "error": f"snob_lib.get_tests failed: {exc}", "tests": [], "count": 0}@@ -682,7 +686,7 @@ def build_result(base_ref: str) -> dict[str, object]:snob_selection = snob_select_tests(changed_files)snob_tests = [str(test) for test in snob_selection.get("tests", [])]- combined_tests = sorted(set(snob_tests) | set(ast_selection.tests))+ combined_tests = _existing_test_files(set(snob_tests) | set(ast_selection.tests))durations = load_durations()selected_seconds = estimate_duration(combined_tests, durations)diff --git a/tools/test_snob_backend_test_selection_shadow.py b/tools/test_snob_backend_test_selection_shadow.pyindex 200ee9a06161..d38fd5e8e021 100644--- a/tools/test_snob_backend_test_selection_shadow.py+++ b/tools/test_snob_backend_test_selection_shadow.py@@ -82,6 +82,16 @@ class TestSnobBackendTestSelectionShadow(unittest.TestCase):self.assertIn("same_app:products/feature_flags/backend", result.groups)self.assertEqual(["products/feature_flags/backend/test/test_api.py"], result.tests)+ def test_ast_selection_ignores_deleted_test_files(self) -> None:+ with tempfile.TemporaryDirectory() as root:+ selection = _load_selection_module()+ selection.REPO_ROOT = Path(root)++ result = selection.ast_select_tests(["posthog/test/test_deleted.py"], {})++ self.assertEqual({}, result.groups)+ self.assertEqual([], result.tests)+def test_ast_selection_matches_posthog_api_test_by_filename(self) -> None:with tempfile.TemporaryDirectory() as root:tmp_path = Path(root)@@ -122,6 +132,7 @@ class TestSnobBackendTestSelectionShadow(unittest.TestCase):selected_test = selection.REPO_ROOT / "posthog" / "api" / "test" / "test_feature_flags.py"selected_test.parent.mkdir(parents=True)selected_test.write_text("def test_feature_flags():\n pass\n")+ deleted_test = selection.REPO_ROOT / "posthog" / "api" / "test" / "test_deleted.py"seen_changed_files: list[list[str]] = []@@ -129,7 +140,7 @@ class TestSnobBackendTestSelectionShadow(unittest.TestCase):def get_tests(changed_files: list[str]) -> set[str]:seen_changed_files.append(changed_files)- return {str(selected_test)}+ return {str(selected_test), str(deleted_test)}fake_snob.get_tests = get_tests # type: ignore[attr-defined]previous_snob = sys.modules.get("snob_lib")@@ -258,19 +269,24 @@ class TestSnobBackendTestSelectionShadow(unittest.TestCase):selection.HIGH_FANOUT_PATH = original_pathdef test_changed_tests_do_not_trigger_full_run_patterns(self) -> None:- selection = _load_selection_module()+ with tempfile.TemporaryDirectory() as root:+ selection = _load_selection_module()+ selection.REPO_ROOT = Path(root)+ test_path = selection.REPO_ROOT / "posthog" / "test" / "test_version_requirement.py"+ test_path.parent.mkdir(parents=True)+ test_path.touch()- result = selection.ast_select_tests(- ["posthog/test/test_version_requirement.py"],- {- "posthog/test/test_version_requirement.py": selection.TestFeatures(- path="posthog/test/test_version_requirement.py"- )- },- )+ result = selection.ast_select_tests(+ ["posthog/test/test_version_requirement.py"],+ {+ "posthog/test/test_version_requirement.py": selection.TestFeatures(+ path="posthog/test/test_version_requirement.py"+ )+ },+ )- self.assertEqual([], result.full_run_reasons)- self.assertEqual({"changed_tests": ["posthog/test/test_version_requirement.py"]}, result.groups)+ self.assertEqual([], result.full_run_reasons)+ self.assertEqual({"changed_tests": ["posthog/test/test_version_requirement.py"]}, result.groups)# ci-backend's `legacy` paths filter routes these into test selection, but none of# them is Python, so the import graph reaches no test through them. Without a full-run