Skip to content

: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.

chore(ci): stop path-filtered python suites depending on unfiltered files (#117523)

posthog[bot]91bd6be8ba51
diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml
index cbb29236d2ca..0d1b6699e7b6 100644
--- a/.github/workflows/ci-python.yml
+++ b/.github/workflows/ci-python.yml
@@ -157,17 +157,35 @@ jobs:
# Stamphog policy files validated by the pr-approval-agent suite
- '.stamphog/**'
- '**/AGENT_APPROVALS.md'
- # Per-tool groups below gate the pytest steps in code-quality. Each of
- # these trees imports only stdlib and its own package — none of them
- # imports posthog — so a change under posthog/ cannot affect them and
- # they do not need to run on every Python PR. Verify that before adding
- # a tree here: a path filter that skips tests is a claim about the
- # import graph (see ci-things-already-tried.md, #50137).
+ # Real repo files the hogli suite reads, listed under hogli below
+ - 'devenv/**'
+ - 'products/model_crossing_uses_baseline.txt'
+ - .github/workflows/ci-security.yaml
+ # Per-tool groups below gate the pytest steps in code-quality, so these
+ # suites skip Python PRs that cannot affect them. A path filter that skips
+ # tests is a claim about everything the suite reads (see
+ # ci-things-already-tried.md, #50137): the modules it imports and the real
+ # repo files its tests open. Each group lists both. A test that only needs
+ # a file to exist builds it under tmp_path instead, so the group stays small.
+ # The hourly run skips this filter, so a missed input turns master red there.
# Dependency and workflow changes run all of them.
hogli:
- 'tools/hogli/**'
- 'tools/hogli-commands/**'
- 'hogli.yaml'
+ # Imported by hogli_commands
+ - 'posthog/dataclasses.py'
+ - 'common/migration_utils/**'
+ - 'packages/owners-yaml/**'
+ - 'tools/owners/**'
+ # Real repo files that hogli tests check on purpose
+ - 'bin/lint-complexity.limits.json'
+ - 'bin/mprocs.yaml'
+ - 'bin/mprocs-e2e.yaml'
+ - 'devenv/**'
+ - 'products/model_crossing_uses_baseline.txt'
+ - '.stamphog/policy.yml'
+ - .github/workflows/ci-security.yaml
- 'pyproject.toml'
- 'uv.lock'
- .github/workflows/ci-python.yml
@@ -189,11 +207,19 @@ jobs:
- 'products/stamphog/packages/pr-approval-agent/**'
- '.stamphog/**'
- '**/AGENT_APPROVALS.md'
+ # The ownership gate runs the real resolver
+ - 'packages/owners-yaml/**'
+ - 'tools/owners/**'
- 'pyproject.toml'
- 'uv.lock'
- .github/workflows/ci-python.yml
bin_scripts:
- 'bin/**'
+ # test_package_exists checks that each LOCAL_PACKAGES root is a package
+ - 'posthog/__init__.py'
+ - 'ee/__init__.py'
+ - 'products/__init__.py'
+ - 'common/__init__.py'
- 'pyproject.toml'
- 'uv.lock'
- .github/workflows/ci-python.yml
diff --git a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py
index a8362b5119d3..a6e7e58e1c8c 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import json
from collections.abc import Iterator
+from pathlib import Path
import pytest
from unittest.mock import MagicMock, patch
@@ -9,6 +10,7 @@ from unittest.mock import MagicMock, patch
from click.testing import CliRunner
from hogli.cli import cli
from hogli.manifest import REPO_ROOT
+from hogli_commands import ci_preflight
from hogli_commands.change_detection import matches_globs
from hogli_commands.ci_preflight import (
DIFF_CHECKS,
@@ -293,9 +295,17 @@ class TestStalenessRisks:
assert fragment in risk
+def workspaces(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ for ws in ("", "products/desktop", "packages/agent", "tools/hedgebox-dummy"):
+ (tmp_path / ws).mkdir(parents=True, exist_ok=True)
+ (tmp_path / ws / "pnpm-workspace.yaml").touch()
+ monkeypatch.setattr(ci_preflight, "REPO_ROOT", tmp_path)
+
+
[email protected]("workspaces")
class TestWorkspaceScopedLockfile:
- """The lockfile check must validate each pnpm workspace against its own lockfile.
- These hit the real repo layout, like TestDetectTestType in test_test_runner.py."""
+ """The lockfile check must validate each pnpm workspace against its own lockfile."""
@pytest.mark.parametrize(
"file_path,expected_workspace",
@@ -342,9 +352,8 @@ class TestWorkspaceScopedLockfile:
assert status == "pass"
ran_dirs = [call.kwargs["cwd"] for call in mock_run.call_args_list]
- from hogli.manifest import REPO_ROOT
-
- assert ran_dirs == [REPO_ROOT if d == "." else REPO_ROOT / d for d in expected_dirs]
+ root = ci_preflight.REPO_ROOT
+ assert ran_dirs == [root if d == "." else root / d for d in expected_dirs]
@patch("hogli_commands.ci_preflight._workspace_install_present", return_value=True)
@patch("hogli_commands.ci_preflight.shutil.which", return_value="/usr/bin/pnpm")
diff --git a/tools/hogli-commands/hogli_commands/tests/test_complexity_lint.py b/tools/hogli-commands/hogli_commands/tests/test_complexity_lint.py
index 9cb108027c5d..6f03cce08de2 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_complexity_lint.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_complexity_lint.py
@@ -1,10 +1,13 @@
from __future__ import annotations
+from pathlib import Path
+
import pytest
from unittest.mock import MagicMock, call, patch
from click.testing import CliRunner
from hogli.cli import cli
+from hogli_commands import ci_preflight, complexity_lint
from hogli_commands.complexity_lint import TEST_WARN_AT, WARN_AT, Finding, _python_findings, is_test_file
runner = CliRunner()
@@ -15,6 +18,23 @@ def _branchy_function(name: str, branches: int) -> str:
return f"def {name}(n: int) -> int:\n{checks} return -1\n"
+def repo(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
+ # lint:complexity and ci:preflight skip a path that is missing under REPO_ROOT.
+ # A refactor can move a real path, so the tests write their own files.
+ for path in (
+ "posthog/tasks/usage_report.py",
+ "posthog/api/test/test_activity_log.py",
+ "manage.py",
+ "frontend/src/scenes/sceneTypes.ts",
+ ):
+ (tmp_path / path).parent.mkdir(parents=True, exist_ok=True)
+ (tmp_path / path).write_text("")
+ monkeypatch.setattr(complexity_lint, "REPO_ROOT", tmp_path)
+ monkeypatch.setattr(ci_preflight, "REPO_ROOT", tmp_path)
+ return tmp_path
+
+
class TestComplexityLint:
@pytest.mark.parametrize(
("branches", "name", "expected"),
@@ -72,6 +92,7 @@ class TestComplexityLint:
def test_is_test_file(self, path: str, expected: bool) -> None:
assert is_test_file(path) is expected
+ @pytest.mark.usefixtures("repo")
def test_cli_reports_warnings_without_failing(self, tmp_path) -> None:
# The check is advisory: even a high-complexity finding must exit 0 and be
# written to the --report file the CI report poster reads.
@@ -90,6 +111,7 @@ class TestComplexityLint:
assert "warn >10" in result.output
assert finding.name in report_path.read_text()
+ @pytest.mark.usefixtures("repo")
@patch("hogli_commands.complexity_lint._python_findings", return_value=[])
def test_only_scoped_files_are_checked(self, mock_findings: MagicMock) -> None:
# Explicit paths outside posthog/ee/products (or deleted ones) must not reach ruff.
@@ -107,6 +129,7 @@ class TestComplexityLint:
assert result.exit_code == 0
mock_findings.assert_called_once_with(["posthog/tasks/usage_report.py"], max_complexity=WARN_AT)
+ @pytest.mark.usefixtures("repo")
@patch("hogli_commands.complexity_lint._python_findings", return_value=[])
def test_test_files_are_linted_at_the_relaxed_threshold(self, mock_findings: MagicMock) -> None:
# Test and production files go to ruff in separate runs, one per limit.
@@ -122,6 +145,7 @@ class TestComplexityLint:
class TestPreflightSoftCheck:
+ @pytest.mark.usefixtures("repo")
@patch("hogli_commands.ci_preflight._emit_telemetry")
@patch("hogli_commands.ci_preflight._staleness", return_value=("pass", "even with master", {}))
@patch("hogli_commands.ci_preflight._fetch_master")
diff --git a/tools/hogli-commands/hogli_commands/tests/test_crossings.py b/tools/hogli-commands/hogli_commands/tests/test_crossings.py
index 074b64b57839..69a75a7739bd 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_crossings.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_crossings.py
@@ -191,20 +191,34 @@ class TestGetModelStrings:
assert crossings._get_model_uses(tree, {"alerts": "alerts"}, LOOKUP) == {}
+def products_dir(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
+ # One product per model-surface shape the scan has to walk: a models package, and a flat models.py.
+ for product, models_path, model in (
+ ("alerts", "models/alert.py", "AlertConfiguration"),
+ ("error_tracking", "models.py", "ErrorTrackingIssue"),
+ ):
+ backend = tmp_path / product / "backend"
+ (backend / models_path).parent.mkdir(parents=True, exist_ok=True)
+ (backend / "apps.py").write_text(f'class Config(AppConfig):\n label = "{product}"\n')
+ (backend / models_path).write_text(f"class {model}(Model):\n pass\n")
+ monkeypatch.setattr(crossings, "PRODUCTS_DIR", tmp_path)
+ return tmp_path
+
+
class TestProductModelLabels:
+ @pytest.mark.usefixtures("products_dir")
@pytest.mark.parametrize(
"label,product",
[
- # The first two are off MODEL_CROSSINGS, and cover the two model-surface shapes the
- # scan has to walk: a models package, and a flat models.py.
("alerts.AlertConfiguration", "alerts"),
("error_tracking.ErrorTrackingIssue", "error_tracking"),
- ("product_analytics.Insight", "product_analytics"),
],
)
def test_model_surface_classes_resolve_to_their_product(self, label: str, product: str) -> None:
assert crossings.product_model_labels().get(label) == product
+ @pytest.mark.usefixtures("products_dir")
def test_products_filter_keeps_only_the_named_product(self) -> None:
labels = crossings.product_model_labels(["alerts"])
assert labels and set(labels.values()) == {"alerts"}
diff --git a/tools/hogli-commands/hogli_commands/tests/test_preflight_checks.py b/tools/hogli-commands/hogli_commands/tests/test_preflight_checks.py
index 597bc9849271..c2c9ca9796ff 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_preflight_checks.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_preflight_checks.py
@@ -129,6 +129,7 @@ class TestSemgrepDevex:
)
@patch("hogli_commands.preflight_checks._semgrep_findings", side_effect=_every_line_is_a_finding)
@patch("hogli_commands.preflight_checks.shutil.which", return_value="/usr/bin/uv")
+ @patch("hogli_commands.preflight_checks._semgrep_spec", lambda: "semgrep==1.0.0")
def test_only_findings_the_branch_introduced_are_reported(
self,
mock_which: MagicMock,
@@ -152,6 +153,7 @@ class TestSemgrepDevex:
"hogli_commands.preflight_checks._semgrep_findings", side_effect=SemgrepUnavailable("tool cache unavailable")
)
@patch("hogli_commands.preflight_checks.shutil.which", return_value="/usr/bin/uv")
+ @patch("hogli_commands.preflight_checks._semgrep_spec", lambda: "semgrep==1.0.0")
def test_an_incomplete_scan_skips_instead_of_reporting(
self, mock_which: MagicMock, mock_findings: MagicMock
) -> None:
@@ -173,6 +175,7 @@ class TestSemgrepDevex:
assert "--offline" in command
@patch("hogli_commands.preflight_checks.shutil.which", return_value="/usr/bin/uv")
+ @patch("hogli_commands.preflight_checks._semgrep_spec", lambda: "semgrep==1.0.0")
def test_baseline_scan_uses_only_the_remaining_check_budget(self, mock_which: MagicMock) -> None:
clock = [100.0]
scans = 0
diff --git a/tools/hogli-commands/hogli_commands/tests/test_quarantine.py b/tools/hogli-commands/hogli_commands/tests/test_quarantine.py
index 34d99fec3ffc..d9cf2776679a 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_quarantine.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_quarantine.py
@@ -21,6 +21,12 @@ def pin_today_utc(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(core, "today_utc", lambda: TODAY)
+def batch_exports_product(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ (tmp_path / "products" / "batch_exports").mkdir(parents=True)
+ monkeypatch.setattr(core, "REPO_ROOT", tmp_path)
+
+
def make_entry(**overrides: Any) -> core.Entry:
defaults: dict[str, Any] = {
"id": "posthog/api/test/test_foo.py::TestFoo::test_bar",
@@ -111,6 +117,7 @@ def test_selector_matches(selector: str, test_id: str, expected: bool) -> None:
("anything at all", "some-future-runner", True), # unadapted runner: not validated
],
)
[email protected]("batch_exports_product")
def test_validate_selector_by_runner(selector: str, runner: str, valid: bool) -> None:
assert (core.validate_selector(selector, runner) is None) is valid
@@ -437,6 +444,7 @@ def test_list_shows_status(runner: CliRunner, tmp_path: Path) -> None:
([raw_entry(id="product:batch_exports")], 1, "dashed product name"),
],
)
[email protected]("batch_exports_product")
def test_check(
runner: CliRunner, tmp_path: Path, entries: list[dict[str, Any]], expected_exit: int, expected_fragment: str
) -> None:
diff --git a/tools/hogli-commands/hogli_commands/tests/test_size_lint.py b/tools/hogli-commands/hogli_commands/tests/test_size_lint.py
index 47dc4d3a537d..89d5a35158c2 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_size_lint.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_size_lint.py
@@ -238,7 +238,16 @@ class TestPreflightForwardsDiffScope:
pytest.param("abc123", True, ["--against", "abc123", "--committed"], id="explicit_base_forwarded"),
],
)
- def test_only_an_explicit_base_is_forwarded(self, against: str | None, strict: bool, expected: list[str]) -> None:
+ def test_only_an_explicit_base_is_forwarded(
+ self,
+ against: str | None,
+ strict: bool,
+ expected: list[str],
+ tmp_path: Path,
+ monkeypatch: pytest.MonkeyPatch,
+ ) -> None:
+ _write(tmp_path, "posthog/api/team.py", 1)
+ monkeypatch.setattr(ci_preflight, "REPO_ROOT", tmp_path)
check = ci_preflight.DiffCheck(
key="size",
label="file size",
diff --git a/tools/hogli-commands/hogli_commands/tests/test_test_runner.py b/tools/hogli-commands/hogli_commands/tests/test_test_runner.py
index 98b90f812e7d..8f4880b37879 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_test_runner.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_test_runner.py
@@ -355,6 +355,26 @@ class TestResolveToRepoRelative:
assert result == "posthog/test_foo.py::TestBar"
+def source_tree(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ for rel in (
+ "posthog/api/comments.py",
+ "posthog/api/test/test_comments.py",
+ "frontend/src/scenes/dashboard/DashboardHeader.tsx",
+ "frontend/src/scenes/dashboard/DashboardHeader.test.tsx",
+ "livestream/events/filter.go",
+ "livestream/events/filter_test.go",
+ "tools/hogli-commands/hogli_commands/test_runner.py",
+ "tools/hogli-commands/hogli_commands/tests/test_test_runner.py",
+ ):
+ (tmp_path / rel).parent.mkdir(parents=True, exist_ok=True)
+ (tmp_path / rel).touch()
+ for rel in ("rust/capture/src/api.rs", "rust/capture/src/v1/util.rs"):
+ (tmp_path / rel).parent.mkdir(parents=True, exist_ok=True)
+ (tmp_path / rel).write_text("#[cfg(test)]\nmod tests {}\n")
+ monkeypatch.setattr("hogli_commands.test_runner.REPO_ROOT", tmp_path)
+
+
class TestIsTestFile:
@parameterized.expand(
[
@@ -383,6 +403,7 @@ class TestIsTestFile:
("rust/capture/src/v1/util.rs",),
]
)
+ @pytest.mark.usefixtures("source_tree")
def test_rs_inline_cfg_test_detected_with_batch(self, path: str) -> None:
rs_cfg_test = _batch_find_rs_cfg_test("rust/capture/src")
assert _is_test_file(path, rs_cfg_test=rs_cfg_test)
@@ -406,6 +427,7 @@ class TestGetChangedFiles:
assert _get_changed_files() == ["tools/hogli-commands/hogli_commands/test_runner.py"]
[email protected]("source_tree")
class TestFindTestFilesForSource:
@parameterized.expand(
[
@@ -471,6 +493,7 @@ class TestRunChanged:
@patch("hogli_commands.test_runner._run")
@patch("hogli_commands.test_runner._get_changed_files")
+ @pytest.mark.usefixtures("source_tree")
def test_discovers_tests_for_changed_source_files(self, mock_changed, mock_run) -> None:
mock_changed.return_value = ["posthog/api/comments.py"]
_run_changed([])