: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
feat(hogli): flag depot shadow drift in ci:preflight (#83733)
Raúl Negrón-Otero3ee7bb270174
diff --git a/tools/hogli-commands/hogli_commands/ci_preflight.py b/tools/hogli-commands/hogli_commands/ci_preflight.pyindex c3481e81a848..bae452a4ebe4 100644--- a/tools/hogli-commands/hogli_commands/ci_preflight.py+++ b/tools/hogli-commands/hogli_commands/ci_preflight.py@@ -5,7 +5,8 @@ you what's broken on master, preflight stops you from being the one who breaksit. It scopes a curated set of checks to the files your branch actually touched,each mapped to a CI failure class we've seen take master down, plus an always-onbranch-freshness check that flags concrete merge risks (textual conflicts,-migration collisions, generated-file drift, CI changes on master).+migration collisions, generated-file drift, CI changes on master), plus+companion-file checks that fail when a mirrored file moves without its pair.hogli ci:preflight # report what your diff could break in CIhogli ci:preflight --fix # auto-remediate what's safe, report the rest@@ -203,6 +204,31 @@ DIFF_CHECKS: list[DiffCheck] = []+@dataclass(frozen=True, kw_only=True, slots=True)+class CompanionCheck:+ """Two files a CI gate requires to move together. The diff is the evidence, so+ unlike a ``DiffCheck`` there is nothing to run."""++ key: str+ label: str+ source: str+ companion: str+ escape_hatch: str # what to do when the change is deliberately one-sided+++# Duplicated from .github/workflows/ci-backend-shadow-drift.yml so the failure lands+# pre-push instead of a CI round-trip. A test binds the two so they cannot drift.+COMPANION_CHECKS: list[CompanionCheck] = [+ CompanionCheck(+ key="shadow-drift",+ label="depot shadow drift (.depot mirror of ci-backend.yml)",+ source=".github/workflows/ci-backend.yml",+ companion=".depot/workflows/ci-backend.yml",+ escape_hatch="document it as an intentional delta in that file's header",+ ),+]++def _has_node_modules() -> bool:return (REPO_ROOT / "node_modules" / ".pnpm").exists()@@ -330,6 +356,12 @@ def _run_diff_check(chk: DiffCheck, do_fix: bool) -> tuple[Status, str]:return "fail", " · ".join(lines[:3]) if lines else f"exit {result.returncode}"+def _run_companion_check(chk: CompanionCheck, files: list[str]) -> tuple[Status, str]:+ if chk.companion in files:+ return "pass", "both files updated"+ return "fail", f"mirror the change into {chk.companion}, or {chk.escape_hatch}"++# Branch-freshness backstop thresholds. The risk signals in ``_staleness_risks``# are the primary advisory trigger; these are a secondary net for branches old# enough that generic (undetected) drift is likely. Deliberately aggressive to@@ -555,6 +587,7 @@ def ci_preflight(do_fix: bool, strict: bool, against: str | None, as_json: bool)chk.matched = [f for f in files if matches_globs(f, chk.triggers)]if chk.matched:triggered.append(chk)+ triggered_companions = [c for c in COMPANION_CHECKS if c.source in files]results: list[dict[str, Any]] = []failures = 0@@ -571,6 +604,14 @@ def ci_preflight(do_fix: bool, strict: bool, against: str | None, as_json: bool)click.secho(f" {_ICON[stale_status]} [staleness] branch freshness vs master", fg=_COLOR[stale_status])click.echo(f" {stale_detail}")+ for companion in triggered_companions:+ status, detail = _run_companion_check(companion, files)+ failures += status == "fail"+ results.append({"check": companion.key, "status": status, "files": 1, "detail": detail})+ if not as_json:+ click.secho(f" {_ICON[status]} [{companion.key}] {companion.label}", fg=_COLOR[status])+ click.echo(f" {detail}")+for chk in triggered:status, detail = _run_diff_check(chk, do_fix)failures += status == "fail"@@ -584,7 +625,7 @@ def ci_preflight(do_fix: bool, strict: bool, against: str | None, as_json: bool)summary = {"changed_files": len(files),- "triggered": [c.key for c in triggered],+ "triggered": [c.key for c in triggered_companions] + [c.key for c in triggered],"failures": failures,"advisories": advisories,"mode": "fix" if do_fix else ("strict" if strict else "advisory"),@@ -594,7 +635,7 @@ def ci_preflight(do_fix: bool, strict: bool, against: str | None, as_json: bool)if as_json:click.echo(json.dumps(summary))else:- if not triggered:+ if not triggered and not triggered_companions:click.secho(" ✓ Nothing in this diff maps to a known CI failure class.", fg="green")click.echo()click.echo(diff --git a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.pyindex 92a38bdb1aa0..10c477d48257 100644--- a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py+++ b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py@@ -7,7 +7,13 @@ from unittest.mock import MagicMock, patchfrom click.testing import CliRunnerfrom hogli.cli import cli-from hogli_commands.ci_preflight import DIFF_CHECKS, _pnpm_workspace_root, _run_workspace_scoped, _staleness_risks+from hogli_commands.ci_preflight import (+ COMPANION_CHECKS,+ DIFF_CHECKS,+ _pnpm_workspace_root,+ _run_workspace_scoped,+ _staleness_risks,+)runner = CliRunner()@@ -207,3 +213,48 @@ class TestWorkspaceScopedLockfile:assert status == "skipped"assert "products/desktop: needs node" in detail+++class TestShadowDriftCompanion:+ @pytest.mark.parametrize(+ "changed,expected_exit,expected_fragment",+ [+ ([".github/workflows/ci-backend.yml"], 1, "mirror the change into .depot/workflows/ci-backend.yml"),+ ([".github/workflows/ci-backend.yml", ".depot/workflows/ci-backend.yml"], 0, "both files updated"),+ # Depot-only is a notice in CI, never a failure. Blocking it would false-block depot tuning.+ ([".depot/workflows/ci-backend.yml"], 0, ""),+ ],+ )+ @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")+ @patch("hogli_commands.ci_preflight.shutil.which", return_value=None)+ def test_verdict_matches_ci(+ self,+ mock_which: MagicMock,+ mock_fetch: MagicMock,+ mock_stale: MagicMock,+ mock_emit: MagicMock,+ changed: list[str],+ expected_exit: int,+ expected_fragment: str,+ ) -> None:+ with patch("hogli_commands.ci_preflight.changed_files", return_value=changed):+ result = runner.invoke(cli, ["ci:preflight", "--strict"])++ assert result.exit_code == expected_exit+ if expected_fragment:+ assert expected_fragment in result.output+ else:+ assert "shadow-drift" not in result.output++ def test_pair_matches_workflow(self) -> None:+ import yaml+ from hogli.manifest import REPO_ROOT++ workflow = yaml.safe_load((REPO_ROOT / ".github" / "workflows" / "ci-backend-shadow-drift.yml").read_text())+ # `on` parses as the boolean True in YAML 1.1.+ watched = set(workflow[True]["pull_request"]["paths"])+ shadow = next(chk for chk in COMPANION_CHECKS if chk.key == "shadow-drift")++ assert watched == {shadow.source, shadow.companion}