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 new files in ee/ without human approval (#124071)

Reece Jones0633aa2d09fe
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index ca3ce13f4b18..08596ed2f4eb 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -1611,6 +1611,11 @@ jobs:
else
pytest -p no:cacheprovider posthog/test/test_startup_import_budget.py posthog/test/test_dataclass_defaults.py
fi
+ # New files in `ee/` need a human decision, and a path comparison sees an empty
+ # file that a content scan cannot. Exemptions live in the script.
+ - name: Check for new files under ee/
+ if: github.event_name == 'pull_request'
+ run: python .github/scripts/check-no-new-ee-files.py --against HEAD^1 --committed
# Deterministic = a static check above failed after setup completed.
# A retry can't fix it, so this signals the cancellation gate to stop the run.
- name: Flag deterministic failure
diff --git a/.github/scripts/check-no-new-ee-files.py b/.github/scripts/check-no-new-ee-files.py
new file mode 100644
index 000000000000..15af0b7ab756
--- /dev/null
+++ b/.github/scripts/check-no-new-ee-files.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+# ruff: noqa: T201 allow print statements
+"""Fail when a branch adds a file under `ee/` without human approval.
+
+`ee/` is deprecated: new code belongs in `posthog/` or `products/<product>/`. A person
+approves a new file by adding its exact path to `EXEMPT` below, which shows up in review.
+See `ee/AGENTS.md`.
+
+ check-no-new-ee-files.py --against origin/master [--committed]
+"""
+
+from __future__ import annotations
+
+import sys
+import argparse
+import subprocess
+
+# Approved new files, one exact path each, added by hand after a human agreed in the pull
+# request. Never add a glob, because it approves files nobody reviewed.
+EXEMPT: frozenset[str] = frozenset()
+
+
+def _git(*args: str) -> str:
+ return subprocess.run(["git", *args], capture_output=True, text=True, check=True).stdout
+
+
+def _paths(*args: str) -> list[str]:
+ return [path for path in _git(*args).split("\0") if path]
+
+
+def _added(args: argparse.Namespace, merge_base: str) -> list[str]:
+ """Paths this branch adds under `ee/`. Renames count: they create a new path here."""
+ head = ["HEAD"] if args.committed else []
+ added = _paths("diff", "-z", "--name-only", "--diff-filter=AR", merge_base, *head, "--", "ee/")
+ if args.committed:
+ return added
+ # `git diff` ignores untracked files, and a new file is often still untracked.
+ return added + _paths("ls-files", "-z", "--others", "--exclude-standard", "--", "ee/")
+
+
+def main() -> int:
+ parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
+ parser.add_argument("--against", default="origin/master", help="diff base ref")
+ parser.add_argument("--committed", action="store_true", help="check commits only, not the working tree")
+ args = parser.parse_args()
+
+ try:
+ merge_base = _git("merge-base", args.against, "HEAD").strip()
+ except subprocess.CalledProcessError:
+ print(f"No merge base with {args.against}, so the `ee/` check did not run.", file=sys.stderr)
+ return 2
+
+ offenders = sorted({path for path in _added(args, merge_base) if path not in EXEMPT})
+ if not offenders:
+ return 0
+
+ print("This branch adds file(s) under `ee/`, which is deprecated:")
+ for path in offenders:
+ print(f" {path}")
+ print(
+ "\nNew code belongs in `posthog/` or `products/<product>/`. A file that must live in `ee/`\n"
+ "needs human approval: ask in the pull request, then add its exact path to `EXEMPT` in\n"
+ ".github/scripts/check-no-new-ee-files.py. See `ee/AGENTS.md`."
+ )
+ return 1
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/.github/scripts/test_check_no_new_ee_files.py b/.github/scripts/test_check_no_new_ee_files.py
new file mode 100644
index 000000000000..30ee15654e9b
--- /dev/null
+++ b/.github/scripts/test_check_no_new_ee_files.py
@@ -0,0 +1,71 @@
+import sys
+import subprocess
+import importlib.util
+from pathlib import Path
+
+import pytest
+
+SCRIPT_PATH = Path(__file__).with_name("check-no-new-ee-files.py")
+SPEC = importlib.util.spec_from_file_location("check_no_new_ee_files", SCRIPT_PATH)
+assert SPEC is not None
+assert SPEC.loader is not None
+check_no_new_ee_files = importlib.util.module_from_spec(SPEC)
+SPEC.loader.exec_module(check_no_new_ee_files)
+
+
+def _git(repo: Path, *args: str) -> None:
+ subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True)
+
+
+def repo(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
+ repo = tmp_path / "repo"
+ (repo / "ee").mkdir(parents=True)
+ (repo / "ee" / "kept.py").write_text("x = 1\n")
+ _git(repo, "init", "-q", "-b", "master")
+ _git(repo, "config", "user.email", "[email protected]")
+ _git(repo, "config", "user.name", "test")
+ _git(repo, "config", "commit.gpgsign", "false")
+ _git(repo, "add", "-A")
+ _git(repo, "commit", "-qm", "base")
+ _git(repo, "checkout", "-q", "-b", "feature")
+ monkeypatch.chdir(repo)
+ return repo
+
+
+def _main(monkeypatch: pytest.MonkeyPatch, *args: str) -> int:
+ monkeypatch.setattr(sys, "argv", ["check-no-new-ee-files.py", "--against", "master", *args])
+ return check_no_new_ee_files.main()
+
+
+def test_committed_file_is_flagged(
+ repo: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
+) -> None:
+ (repo / "ee" / "new.py").write_text("y = 2\n")
+ _git(repo, "add", "-A")
+ _git(repo, "commit", "-qm", "add a file")
+
+ assert _main(monkeypatch, "--committed") == 1
+ assert "ee/new.py" in capsys.readouterr().out
+
+
+def test_untracked_empty_file_is_flagged(
+ repo: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
+) -> None:
+ (repo / "ee" / "empty.py").touch()
+
+ assert _main(monkeypatch) == 1
+ assert "ee/empty.py" in capsys.readouterr().out
+
+
+def test_edit_to_an_existing_file_passes(repo: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ (repo / "ee" / "kept.py").write_text("x = 2\n")
+
+ assert _main(monkeypatch) == 0
+
+
+def test_exempt_path_passes(repo: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ (repo / "ee" / "new.py").write_text("y = 2\n")
+ monkeypatch.setattr(check_no_new_ee_files, "EXEMPT", frozenset({"ee/new.py"}))
+
+ assert _main(monkeypatch) == 0
diff --git a/ee/AGENTS.md b/ee/AGENTS.md
index 96c9c0b89036..64573fdb4a20 100644
--- a/ee/AGENTS.md
+++ b/ee/AGENTS.md
@@ -1,3 +1,19 @@
# Enterprise edition code
-Do not add new features to the `ee/` folder under any circumstance. Only extend existing code under the `ee/` folder when absolutely necessary, and the code cannot be placed under the `posthog/` directory or one of the `product/*` directories. The `ee/` folder is deprecated, and our goal is to move as much code out of it as possible. If you absolutely must add new code to the `ee/` folder, explicitly state why in your pull request description.
+Do not add a file to `ee/`. The folder is deprecated and new code belongs in `posthog/` or `products/<product>/`.
+
+The `.github/scripts/check-no-new-ee-files.py` check fails a pull request that adds any new file here. It compares paths, so an empty file counts too.
+
+## A new file here needs human approval
+
+1. Ask a human person for approval before making any change that adds new files to the `ee/` folder. Explain to them that the `ee/` folder is deprecated and should not accept new files.
+2. If the human confirms to add the file, then add the file's exact path to the `EXEMPT` set in `.github/scripts/check-no-new-ee-files.py`.
+3. State the reason for why the file was added here in the pull request description.
+
+An agent must not do step 2 on its own. Report the blocked file to the person and let them decide.
+
+## Extending existing code
+
+Extend code in `ee/` only when the change cannot live in `posthog/` or a `products/` folder. Say why in the pull request description.
+
+Tests and migrations for existing `ee/` code are new files too, so they follow the same approval.
diff --git a/owners.yaml b/owners.yaml
index e64b67ed0183..e271feccf594 100644
--- a/owners.yaml
+++ b/owners.yaml
@@ -128,6 +128,7 @@ rules:
# setup receivers and frozen dataclass baselines) stay out, so that the review requests
# stay rare.
- match:
+ - '/.github/scripts/check-no-new-ee-files.py'
- '/.github/scripts/migration-deletion-allowlist.txt'
- '/.semgrep/rules/devex/'
- '/.semgrep/rules/security/prefer-codegen-api.*'
diff --git a/tools/hogli-commands/hogli_commands/ci_preflight.py b/tools/hogli-commands/hogli_commands/ci_preflight.py
index 6bef9ba5f080..c6c15cbaee33 100644
--- a/tools/hogli-commands/hogli_commands/ci_preflight.py
+++ b/tools/hogli-commands/hogli_commands/ci_preflight.py
@@ -359,6 +359,13 @@ DIFF_CHECKS: list[DiffCheck] = [
verify=None,
run=check_semgrep_devex,
),
+ DiffCheck(
+ key="new-ee-files",
+ label="new file under ee/ (needs human approval)",
+ triggers=["ee/*"],
+ verify=["python", ".github/scripts/check-no-new-ee-files.py"],
+ takes_diff_scope=True,
+ ),
DiffCheck(
key="cross-lane",
label="Python or frontend changes mixed with Node or Rust changes (fails CI without a label)",