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.

fix(devex): enforce narrowed turbo.json once a product is fully sealed (#65108)

Julian Bez58af8cc65685
diff --git a/products/engineering_analytics/turbo.json b/products/engineering_analytics/turbo.json
index 44865e1b7931..34a16b3d30ce 100644
--- a/products/engineering_analytics/turbo.json
+++ b/products/engineering_analytics/turbo.json
@@ -1,3 +1,10 @@
{
- "extends": ["//"]
+ "extends": ["//"],
+ "tasks": {
+ "backend:contract-check": {
+ "inputs": ["backend/facade/**", "backend/presentation/**"],
+ "outputs": [],
+ "cache": true
+ }
+ }
}
diff --git a/products/metrics/turbo.json b/products/metrics/turbo.json
new file mode 100644
index 000000000000..34a16b3d30ce
--- /dev/null
+++ b/products/metrics/turbo.json
@@ -0,0 +1,10 @@
+{
+ "extends": ["//"],
+ "tasks": {
+ "backend:contract-check": {
+ "inputs": ["backend/facade/**", "backend/presentation/**"],
+ "outputs": [],
+ "cache": true
+ }
+ }
+}
diff --git a/products/streamlit_apps/turbo.json b/products/streamlit_apps/turbo.json
new file mode 100644
index 000000000000..34a16b3d30ce
--- /dev/null
+++ b/products/streamlit_apps/turbo.json
@@ -0,0 +1,10 @@
+{
+ "extends": ["//"],
+ "tasks": {
+ "backend:contract-check": {
+ "inputs": ["backend/facade/**", "backend/presentation/**"],
+ "outputs": [],
+ "cache": true
+ }
+ }
+}
diff --git a/tools/hogli-commands/hogli_commands/product/checks.py b/tools/hogli-commands/hogli_commands/product/checks.py
index 1707dfc7f4b6..3f3a43eaea05 100644
--- a/tools/hogli-commands/hogli_commands/product/checks.py
+++ b/tools/hogli-commands/hogli_commands/product/checks.py
@@ -19,10 +19,7 @@ from pathlib import Path
from .isolation import (
IsolationStatus,
compute_isolation_status,
- has_contract_check_script,
has_legacy_interface_leaks,
- has_narrowed_turbo_inputs,
- has_real_facade,
has_tach_interface,
is_isolated_product,
iter_interface_blocks as _iter_interface_blocks,
@@ -250,6 +247,19 @@ class CheckContext:
is_isolated: bool
structure: dict
detailed: bool # True = single-product run, False = --all
+ _isolation: IsolationStatus | None = field(default=None, repr=False, compare=False)
+
+ def isolation_status(self) -> IsolationStatus:
+ """Memoized isolation seal status, shared across checks within one product run.
+
+ Several checks need it; computing once avoids re-reading tach.toml/pyproject.toml/
+ package.json per check (files don't change mid-run).
+ """
+ if self._isolation is None:
+ self._isolation = compute_isolation_status(
+ self.name, self.product_dir, self.backend_dir, is_isolated=self.is_isolated
+ )
+ return self._isolation
@dataclass
@@ -385,7 +395,7 @@ class PackageJsonScriptsCheck(ProductCheck):
# re-runs the full suite on facade/presentation changes, so an internals
# change flowing to HTTP through such a view would be hidden. The skip is the
# reward for finishing — it can't be enabled until the wave empties them.
- status = compute_isolation_status(ctx.name, ctx.product_dir, ctx.backend_dir, is_isolated=ctx.is_isolated)
+ status = ctx.isolation_status()
needs_contract_check = status.eligible_for_isolated_tests
required = ["backend:test"] + (["backend:contract-check"] if needs_contract_check else [])
for script in required:
@@ -607,21 +617,25 @@ class TachCheck(ProductCheck):
class IsolationChainCheck(ProductCheck):
- """Validates the isolation prerequisite chain is consistent.
+ """Validates the isolation prerequisite chain is consistent — and finished.
The chain: real facade → tach interfaces → contract-check script → narrowed turbo.json.
- Each step requires the previous one. A product that skips a step gets CI
- benefits it hasn't earned (Django suite skipped on changes).
+ Each step requires the previous one, so a product can't claim a CI benefit it hasn't
+ earned (the Django suite skipped on changes). The final step also can't be left
+ half-wired: once a product is fully sealed and eligible, it must actually turn the skip
+ on by narrowing turbo.json inputs — otherwise the contract-check script is inert
+ (inputs default to all of backend/, so every change still re-runs the Django suite).
"""
label = "isolation chain"
def run(self, ctx: CheckContext) -> CheckResult:
facade_api = ctx.backend_dir / "facade" / "api.py"
- real_facade = has_real_facade(ctx.backend_dir)
- has_tach = has_tach_interface(ctx.name)
- has_script = has_contract_check_script(ctx.product_dir)
- has_narrowed = has_narrowed_turbo_inputs(ctx.product_dir)
+ status = ctx.isolation_status()
+ real_facade = status.has_real_facade
+ has_tach = status.has_tach_interface
+ has_script = status.has_contract_check_script
+ has_narrowed = status.has_narrowed_turbo
result = CheckResult()
@@ -656,12 +670,37 @@ class IsolationChainCheck(ProductCheck):
"a real facade should convert models to contracts, not just re-export"
)
+ # Earned but not turned on: a fully sealed, eligible product that already carries
+ # 'backend:contract-check' (real facade, tach interface, no legacy leaks, presentation
+ # wave emptied). Without a turbo.json narrowing its inputs to facade/presentation, that
+ # script inherits the root task's all-of-backend inputs, so every internal change still
+ # re-runs the full Django suite — the skip is inert. Force the narrowing so READY
+ # products land on ON. Gating on has_script keeps this distinct from
+ # PackageJsonScriptsCheck, which is what nags a still-eligible product to add the script.
+ needs_turn_on = (
+ has_script and status.eligible_for_isolated_tests and status.externally_sealed and not has_narrowed
+ )
+ if needs_turn_on:
+ result.issues.append(
+ "product is fully sealed and eligible for isolated tests and carries "
+ "'backend:contract-check', but turbo.json does not narrow contract-check inputs to "
+ "facade/presentation — the skip is inert (every change still re-runs the full Django "
+ 'suite). Add a turbo.json narrowing inputs to ["backend/facade/**", '
+ '"backend/presentation/**"] to turn the skip on'
+ )
+
# Note: a product that has the contract-check script *and* deferred
# presentation-wave ignore_imports entries is hard-blocked by
# PackageJsonScriptsCheck — the skip can't be enabled until the wave empties them.
if result.issues or result.warnings:
- result.file = f"products/{ctx.name}/backend/facade/api.py"
+ # The turn-on issue can't co-occur with the facade/turbo mismatch issues above
+ # (it requires a real facade, a tach interface, a script, and no narrowing — each
+ # of which negates one of those), so when it fires it's the sole issue and the
+ # annotation belongs on turbo.json, not facade/api.py.
+ result.file = (
+ f"products/{ctx.name}/turbo.json" if needs_turn_on else f"products/{ctx.name}/backend/facade/api.py"
+ )
if result.issues:
result.lines = [f"✗ {len(result.issues)} issue(s)"] + [f" → {i}" for i in result.issues]
elif result.warnings:
diff --git a/tools/hogli-commands/hogli_commands/tests/test_checks.py b/tools/hogli-commands/hogli_commands/tests/test_checks.py
index 74967d346d5a..69e813453007 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_checks.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_checks.py
@@ -11,6 +11,7 @@ from hogli_commands.product import gh as gh_module
from hogli_commands.product.checks import (
CheckContext,
FileFolderConflictsCheck,
+ IsolationChainCheck,
OrphanedTestFilesCheck,
PackageJsonScriptsCheck,
ProductYamlCheck,
@@ -246,6 +247,86 @@ class TestAbsenceChecks:
assert not any("missing 'backend:contract-check'" in i for i in result.issues)
+# ---------------------------------------------------------------------------
+# Isolation chain: earned-but-not-turned-on enforcement
+# ---------------------------------------------------------------------------
+
+
+_NARROWED_TURBO = {
+ "extends": ["//"],
+ "tasks": {
+ "backend:contract-check": {
+ "inputs": ["backend/facade/**", "backend/presentation/**"],
+ "outputs": [],
+ "cache": True,
+ }
+ },
+}
+
+chain_check = IsolationChainCheck()
+
+
+_WITH_SCRIPT = {
+ "backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ -v --tb=short",
+ "backend:contract-check": "echo 'Contract files unchanged'",
+}
+
+
+def _seal_externally(monkeypatch: pytest.MonkeyPatch) -> None:
+ # The tmp fixture product isn't declared in the repo's real tach.toml/pyproject.toml,
+ # so force compute_isolation_status to see an externally sealed, internally clean product.
+ import hogli_commands.product.isolation as isolation_module
+
+ monkeypatch.setattr(isolation_module, "has_tach_interface", lambda *_a, **_k: True)
+ monkeypatch.setattr(isolation_module, "has_legacy_interface_leaks", lambda *_a, **_k: False)
+ monkeypatch.setattr(isolation_module, "presentation_bypass_entries", lambda *_a, **_k: [])
+
+
+class TestIsolationChainTurnOn:
+ def test_eligible_with_script_but_no_narrowed_turbo_fails(
+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ _seal_externally(monkeypatch)
+ ctx = _make_product(tmp_path, scripts=_WITH_SCRIPT, isolated=True)
+ result = chain_check.run(ctx)
+ assert any("inert" in i for i in result.issues)
+ assert result.file == "products/my_product/turbo.json"
+
+ def test_eligible_with_narrowed_turbo_passes(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ _seal_externally(monkeypatch)
+ ctx = _make_product(tmp_path, scripts=_WITH_SCRIPT, isolated=True)
+ (ctx.product_dir / "turbo.json").write_text(json.dumps(_NARROWED_TURBO))
+ result = chain_check.run(ctx)
+ assert not result.issues
+
+ def test_eligible_without_script_is_not_nagged_to_narrow_turbo(
+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+ ) -> None:
+ # Eligible + sealed but the contract-check script isn't added yet: PackageJsonScriptsCheck
+ # owns nagging for the script, so IsolationChainCheck must not raise the turn-on issue
+ # (which would falsely claim the product "carries 'backend:contract-check'").
+ _seal_externally(monkeypatch)
+ ctx = _make_product(
+ tmp_path,
+ scripts={"backend:test": "pytest -c ../../pytest.ini --rootdir ../.. backend/ -v --tb=short"},
+ isolated=True,
+ )
+ result = chain_check.run(ctx)
+ assert not any("inert" in i for i in result.issues)
+
+ def test_not_externally_sealed_does_not_demand_turbo(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
+ # Without the tach interface the product isn't externally sealed — TachCheck owns that
+ # failure, so the chain check must not pile on a turbo-narrowing demand.
+ import hogli_commands.product.isolation as isolation_module
+
+ monkeypatch.setattr(isolation_module, "has_tach_interface", lambda *_a, **_k: False)
+ monkeypatch.setattr(isolation_module, "has_legacy_interface_leaks", lambda *_a, **_k: False)
+ monkeypatch.setattr(isolation_module, "presentation_bypass_entries", lambda *_a, **_k: [])
+ ctx = _make_product(tmp_path, scripts=_WITH_SCRIPT, isolated=True)
+ result = chain_check.run(ctx)
+ assert not any("inert" in i for i in result.issues)
+
+
# ---------------------------------------------------------------------------
# Content checks: pytest path validation
# ---------------------------------------------------------------------------