: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(devex): watch the model surface in every narrowed product (#87080)
Julian Beze1702369ae5f
diff --git a/.agents/skills/isolating-product-facade-contracts/SKILL.md b/.agents/skills/isolating-product-facade-contracts/SKILL.mdindex 6353a57f622a..aa0698786fc7 100644--- a/.agents/skills/isolating-product-facade-contracts/SKILL.md+++ b/.agents/skills/isolating-product-facade-contracts/SKILL.md@@ -319,13 +319,15 @@ records the decrease. See `products/architecture.md` § Wiring couplings.4. **Narrowed `turbo.json` inputs** — restrict `backend:contract-check`inputs to `backend/facade/**` and `backend/presentation/**` so theDjango suite is only re-run on facade/presentation changes (see- `products/visual_review/turbo.json`). Widen the inputs when core- depends on the product **outside the import graph**: add- `backend/models.py` if hogql system tables expose the product's- tables or core config references its dotted paths (the scan's- string-reference section surfaces the latter). tach/import-linter- only police the import channel; a mechanical check for these- non-import channels is a known gap, noted and deferred.+ `products/visual_review/turbo.json`). The inputs must also watch the+ whole model surface — `backend/models.py` or `backend/models/**`,+ plus `backend/migrations/**` (required even before the first+ migration lands): a model is reachable without an import+ (`apps.get_model` strings, migrations, admin, hogql system tables,+ dotted-string config), so tach/import-linter cannot prove nothing+ outside observes it. `hogli product:lint` blocks a narrowing that+ omits any of it, and `product:bootstrap` scaffolds the inputs+ already covering it.- **Permanent-interface exception (irreducible import coupling).** Someimport coupling genuinely cannot be drained: ClickHouse DDL modules(`backend.sql`, `backend.embedding`, …) are imported by core'sdiff --git a/products/architecture.md b/products/architecture.mdindex 6de67ca35eec..21c7982a9f81 100644--- a/products/architecture.md+++ b/products/architecture.md@@ -78,6 +78,10 @@ Because this channel can't be enumerated, it is closed by construction rather th1. Keep the presentation layer thin and reaching internals only through the facade, so every observable behavior lives either in the facade (tested in-product, inside the boundary) or in the serializer shape (the OpenAPI schema, whose changes already force the full suite).2. Keep behavior tests in-product.+3. Keep the model surface — `backend/models/` (or `backend/models.py`) and `backend/migrations/` — in the `backend:contract-check` inputs.+ A model is reachable with no import: `apps.get_model("label", "Class")`, migrations, admin, fixtures.+ tach cannot see that, so a model or migration change always re-runs the full suite.+ `hogli product:lint` blocks a narrowing that leaves the surface out.A product whose views still hold business logic is not soundly skippable even if nothing imports it.This is also why "no in-process callers, so we don't need a facade" is the wrong test: a product whose only consumers are over HTTP (node services, the generated TS/MCP types) is _not_ facade-optional — there the facade's whole job is sealing its own presentation.@@ -92,7 +96,7 @@ These cross the boundary as classes — allowed only under all three rules:The class implements a core-owned base from the approved list — today `QueryRunner` (`posthog/hogql_queries/query_runner.py`), `MaxTool` (`ee/hogai/tool.py`), Temporal's `@workflow.defn`/`@activity.defn`, and Celery's `@shared_task`.Core code may rely only on the base's interface, never on product-specific members.Extending the list is a core PR: define the base and validate at the registration point.- DRF viewsets are not part of this channel: they live in `presentation/`, register through `routes.py`, and never pass through the facade (facades must not import DRF) — their soundness is governed by the presentation rules above.+ DRF viewsets are not part of this channel: they live in `presentation/`, register through `routes.py`, and never pass through the facade (a facade must not import DRF, and not its own `presentation/`; the `facade must not import presentation or DRF` import-linter contract enforces both, with the existing violations grandfathered in its TODO list) — their soundness is governed by the presentation rules above.2. **Designated location.**The implementation lives in the product's wiring location — `backend/hogql_queries/`, `backend/max_tools.py`, `backend/temporal/`, `backend/tasks/` (a flat `backend/tasks.py` also qualifies) — and isolated products keep those locations in their `backend:contract-check` inputs, so any change to a wiring implementation still re-runs the full suite.3. **Validated registration.**@@ -113,7 +117,8 @@ Core and seven products (alerts, dashboards, surveys, annotations, exports, cust`InsightViewed` crosses for the view-tracking upsert (`update_or_create`) that shared-insight rendering and the demo generator perform.The dashboards→product_analytics `DashboardTile.insight` FK and `Dashboard.insights` M2M-through cross into the product against §8's direction rule; that coupling is accepted under this entry until dashboards pursues its own isolation.-An allowance product's facade may hand out model classes defined under `backend/models/`, provided the whole model surface — `backend/models/` and `backend/migrations/` — stays in the `backend:contract-check` inputs, so any model or migration change still re-runs the full suite.+An allowance product's facade may hand out model classes defined under `backend/models/`.+The model surface is watched by every narrowed product anyway (see [What makes the skip sound](#what-makes-the-skip-sound)); the allowance adds only the permission to hand out the class.That is the same soundness contract wiring locations have; what it does not buy is isolation — the coupling to core remains, `hogli product:lint` keeps a standing warning on it, and the direction of travel is still facade functions returning contracts.The list lives in `MODEL_CROSSINGS` (`tools/hogli-commands/hogli_commands/product/isolation.py`) and is keyed `(product, class)`, like the carve-outs above: a class that is not listed is a leak and blocks narrowing, so a product already on the list cannot grow a new crossing without a doctrine change.It only shrinks.diff --git a/products/customer_analytics/turbo.json b/products/customer_analytics/turbo.jsonindex e4f5630a3c15..e1ee10eb4dba 100644--- a/products/customer_analytics/turbo.json+++ b/products/customer_analytics/turbo.json@@ -8,9 +8,10 @@"backend/routes.py","backend/hogql_queries/**","backend/max_tools.py",- "backend/models/team_customer_analytics_config.py","backend/tasks/**",- "backend/temporal/**"+ "backend/temporal/**",+ "backend/models/**",+ "backend/migrations/**"],"outputs": [],"cache": truediff --git a/products/engineering_analytics/turbo.json b/products/engineering_analytics/turbo.jsonindex 89467ab134d4..a765b03ee90e 100644--- a/products/engineering_analytics/turbo.json+++ b/products/engineering_analytics/turbo.json@@ -2,7 +2,14 @@"extends": ["//"],"tasks": {"backend:contract-check": {- "inputs": ["backend/facade/**", "backend/presentation/**", "backend/routes.py", "backend/tasks/**"],+ "inputs": [+ "backend/facade/**",+ "backend/presentation/**",+ "backend/routes.py",+ "backend/tasks/**",+ "backend/models.py",+ "backend/migrations/**"+ ],"outputs": [],"cache": true}diff --git a/products/error_tracking/turbo.json b/products/error_tracking/turbo.jsonindex 64a7226d2188..81d8b2d4fd6b 100644--- a/products/error_tracking/turbo.json+++ b/products/error_tracking/turbo.json@@ -12,7 +12,9 @@"backend/hogql_queries/**","backend/max_tools.py","backend/temporal/**",- "backend/tasks/**"+ "backend/tasks/**",+ "backend/models.py",+ "backend/migrations/**"],"outputs": [],"cache": truediff --git a/products/legal_documents/turbo.json b/products/legal_documents/turbo.jsonindex 89467ab134d4..a765b03ee90e 100644--- a/products/legal_documents/turbo.json+++ b/products/legal_documents/turbo.json@@ -2,7 +2,14 @@"extends": ["//"],"tasks": {"backend:contract-check": {- "inputs": ["backend/facade/**", "backend/presentation/**", "backend/routes.py", "backend/tasks/**"],+ "inputs": [+ "backend/facade/**",+ "backend/presentation/**",+ "backend/routes.py",+ "backend/tasks/**",+ "backend/models.py",+ "backend/migrations/**"+ ],"outputs": [],"cache": true}diff --git a/products/managed_warehouse/turbo.json b/products/managed_warehouse/turbo.jsonindex c144b4c4bd9a..f8784947d3dc 100644--- a/products/managed_warehouse/turbo.json+++ b/products/managed_warehouse/turbo.json@@ -12,7 +12,13 @@]},"backend:contract-check": {- "inputs": ["backend/facade/**", "backend/presentation/**", "backend/temporal/**"],+ "inputs": [+ "backend/facade/**",+ "backend/presentation/**",+ "backend/temporal/**",+ "backend/models.py",+ "backend/migrations/**"+ ],"outputs": [],"cache": true}diff --git a/products/metrics/turbo.json b/products/metrics/turbo.jsonindex 79170fa7526d..a79cf86db40e 100644--- a/products/metrics/turbo.json+++ b/products/metrics/turbo.json@@ -7,7 +7,9 @@"backend/presentation/**","backend/routes.py","backend/hogql_queries/**",- "backend/tasks/**"+ "backend/tasks/**",+ "backend/models.py",+ "backend/migrations/**"],"outputs": [],"cache": truediff --git a/products/stamphog/turbo.json b/products/stamphog/turbo.jsonindex bd3cdcbaff18..71041022421c 100644--- a/products/stamphog/turbo.json+++ b/products/stamphog/turbo.json@@ -7,7 +7,9 @@"backend/presentation/**","backend/routes.py","backend/tasks/**",- "backend/temporal/**"+ "backend/temporal/**",+ "backend/models.py",+ "backend/migrations/**"],"outputs": [],"cache": truediff --git a/products/streamlit_apps/turbo.json b/products/streamlit_apps/turbo.jsonindex 89467ab134d4..a765b03ee90e 100644--- a/products/streamlit_apps/turbo.json+++ b/products/streamlit_apps/turbo.json@@ -2,7 +2,14 @@"extends": ["//"],"tasks": {"backend:contract-check": {- "inputs": ["backend/facade/**", "backend/presentation/**", "backend/routes.py", "backend/tasks/**"],+ "inputs": [+ "backend/facade/**",+ "backend/presentation/**",+ "backend/routes.py",+ "backend/tasks/**",+ "backend/models.py",+ "backend/migrations/**"+ ],"outputs": [],"cache": true}diff --git a/products/visual_review/turbo.json b/products/visual_review/turbo.jsonindex 89467ab134d4..a765b03ee90e 100644--- a/products/visual_review/turbo.json+++ b/products/visual_review/turbo.json@@ -2,7 +2,14 @@"extends": ["//"],"tasks": {"backend:contract-check": {- "inputs": ["backend/facade/**", "backend/presentation/**", "backend/routes.py", "backend/tasks/**"],+ "inputs": [+ "backend/facade/**",+ "backend/presentation/**",+ "backend/routes.py",+ "backend/tasks/**",+ "backend/models.py",+ "backend/migrations/**"+ ],"outputs": [],"cache": true}diff --git a/products/wizard/turbo.json b/products/wizard/turbo.jsonindex 89467ab134d4..a765b03ee90e 100644--- a/products/wizard/turbo.json+++ b/products/wizard/turbo.json@@ -2,7 +2,14 @@"extends": ["//"],"tasks": {"backend:contract-check": {- "inputs": ["backend/facade/**", "backend/presentation/**", "backend/routes.py", "backend/tasks/**"],+ "inputs": [+ "backend/facade/**",+ "backend/presentation/**",+ "backend/routes.py",+ "backend/tasks/**",+ "backend/models.py",+ "backend/migrations/**"+ ],"outputs": [],"cache": true}diff --git a/pyproject.toml b/pyproject.tomlindex ee3444c45e15..f3e01d20b755 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -514,6 +514,7 @@ exclude = [[tool.importlinter]root_packages = ["products"]+include_external_packages = true# Presentation must only reach product internals through the facade.# Forbid all backend imports, then allowlist facade + self-imports.@@ -748,6 +749,37 @@ ignore_imports = ["products.workflows.backend.routes -> products.workflows.backend.api.workflow_tasks",]+# The facade is the layer below presentation. A facade that imports its product's presentation+# inverts the layering (and drags DRF onto every consumer's import path); a facade that imports+# DRF is presentation in disguise. Only direct imports are checked (allow_indirect_imports is+# forced — without it import-linter rejects the wildcard modules as having shared descendants),+# so DRF reached through an internal module stays green: this enforces the layering norm, not a+# transitive guarantee. See products/architecture.md § Wiring couplings.+[[tool.importlinter.contracts]]+name = "facade must not import presentation or DRF"+type = "forbidden"+source_modules = ["products.*.backend.facade"]+forbidden_modules = [+ "products.*.backend.presentation",+ "rest_framework",+]+allow_indirect_imports = true+ignore_imports = [+ # TODO: existing violations — move the presentation-shaped code out of the facade, or the+ # facade-shaped code out of presentation, and drop the line+ "products.alerts.backend.facade.api -> products.alerts.backend.presentation.views.alert",+ "products.alerts.backend.facade.api -> products.alerts.backend.presentation.views.alert_schedule_restriction",+ "products.managed_warehouse.backend.facade.api -> products.managed_warehouse.backend.presentation.views",+ "products.stamphog.backend.facade.webhooks -> products.stamphog.backend.presentation.webhooks",+ "products.tasks.backend.facade.api -> products.tasks.backend.presentation.serializers",+ "products.billing_alerts.backend.facade.api -> rest_framework",+ "products.dashboards.backend.facade.api -> rest_framework",+ "products.experiments.backend.facade.api -> rest_framework",+ "products.feature_flags.backend.facade.api -> rest_framework",+ "products.tasks.backend.facade.api -> rest_framework",+ "products.tasks.backend.facade.client_provenance -> rest_framework",+]+[tool.ty.rules]# Import resolution - ty can't always find all modules/stubsunresolved-import = "ignore"diff --git a/tools/hogli-commands/hogli_commands/product/checks.py b/tools/hogli-commands/hogli_commands/product/checks.pyindex b0f9cdda9c0f..b7cfa206e59d 100644--- a/tools/hogli-commands/hogli_commands/product/checks.py+++ b/tools/hogli-commands/hogli_commands/product/checks.py@@ -815,10 +815,10 @@ class IsolationChainCheck(ProductCheck):if has_narrowed and status.uncovered_model_surface:surface_globs = ", ".join(location_input_glob(p) for p in status.uncovered_model_surface)result.issues.append(- "turbo.json narrows contract-check inputs but omits the watched-models surface "- f"{', '.join(status.uncovered_model_surface)} — the facade hands out model classes under the "- f"watched-models allowance, so a change there would skip the Django suite. Add the matching "- f"input(s) ({surface_globs})"+ "turbo.json narrows contract-check inputs but omits the model surface "+ f"{', '.join(status.uncovered_model_surface)} — a model is reachable without an import "+ "(apps.get_model, migrations, admin), so a model or migration change must re-run the Django "+ f"suite. Add the matching input(s) ({surface_globs})")# Earned but not turned on: a fully sealed, eligible product that already carries@@ -843,8 +843,9 @@ class IsolationChainCheck(ProductCheck):"'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/**"] plus any wiring locations the product has '- "(backend/tasks/**, backend/temporal/**, …) to turn the skip on"+ '"backend/presentation/**"] plus the model surface (backend/models.py or '+ "backend/models/**, and backend/migrations/**) and any wiring locations the "+ "product has (backend/tasks/**, backend/temporal/**, …) to turn the skip on")# When needs_turn_on is suppressed purely because of a facade violation (the other four# conjuncts hold), the facade_violations warning above already explains what blocks narrowing,diff --git a/tools/hogli-commands/hogli_commands/product/isolation.py b/tools/hogli-commands/hogli_commands/product/isolation.pyindex 672e318b4013..f0f22e25ce4a 100644--- a/tools/hogli-commands/hogli_commands/product/isolation.py+++ b/tools/hogli-commands/hogli_commands/product/isolation.py@@ -343,11 +343,11 @@ def has_narrowed_turbo_inputs(skip inert, and a routes-only narrowing isn't a real contract surface — both are rejected.Negated globs ('!...') are excluded from the surface test.- Permanently-exposed modules, garage wiring locations, carve-out modules, and (for products- under the watched-models allowance) the model surface all count as extended surface: a product- may list them without forfeiting the narrowing, since core depends on each outside the plain- facade->contracts channel and they must re-run the suite on change (see- uncovered_permanent_modules, unwatched_garages, and the carve-out/model coverage checks)."""+ Permanently-exposed modules, garage wiring locations, carve-out modules, and the model surface+ all count as extended surface: a product may list them without forfeiting the narrowing, since+ core depends on each outside the plain facade->contracts channel and they must re-run the suite+ on change (see uncovered_permanent_modules, unwatched_garages, and the carve-out/model coverage+ checks)."""inputs = [i for i in contract_check_inputs(product_dir) if not i.startswith("!")]if not inputs:return False@@ -367,11 +367,15 @@ def has_narrowed_turbo_inputs(def _input_covers(input_glob: str, accepted: str) -> bool:"""A directory location (trailing slash) is covered by any input inside it; a single-file- location only by an exact input — backend/tasks.py.bak must not count as watching- backend/tasks.py."""+ location by an exact input, or by a wildcard-free `dir/**` input whose directory contains it —+ backend/models/** watches backend/models/tcac.py, but backend/tasks.py.bak must not count as+ watching backend/tasks.py (and backend/tasks/** does not watch backend/tasks.py)."""if accepted.endswith("/"):return input_glob.startswith(accepted)- return input_glob == accepted+ if input_glob == accepted:+ return True+ directory = input_glob.removesuffix("/**")+ return directory != input_glob and "*" not in directory and accepted.startswith(directory + "/")def _uncovered_locations(product_dir: Path, targets_to_prefixes: dict[str, tuple[str, ...]]) -> set[str]:@@ -765,8 +769,8 @@ def facade_carveout_modules(backend_dir: Path, name: str) -> set[str]:def facade_model_crossings(backend_dir: Path, name: str) -> list[FacadeClassImport]:"""Model classes this product's facade hands out under the watched-models allowance.- Sanctioned interim debt, never a leak; a narrowed product must keep the model surface- (MODEL_SURFACE_PREFIXES) in its contract-check inputs."""+ Sanctioned interim debt, never a leak. The model surface (MODEL_SURFACE_PREFIXES) is watched+ by every narrowed product regardless; see unwatched_model_surface."""return list(_split_facade_reexports(backend_dir, name).model_crossings)@@ -802,12 +806,14 @@ def _literal_prefix_overlaps(glob: str, prefix: str) -> bool:def unwatched_model_surface(product_dir: Path) -> set[str]:"""Model-surface locations present in the product but not wholly watched by its (narrowed)- contract-check inputs. Only meaningful for a product whose facade hands out model classes under- the watched-models allowance — callers gate on that.-- Stricter than the garage check on purpose: the allowance requires the WHOLE surface watched, so- a directory location needs its full glob (backend/models/**) — an input inside it, or a negation- that may carve files out of it, does not count. A garage may be watched piecemeal; the model+ contract-check inputs. Every narrowed product must watch its models and migrations: a model is+ reachable without an import (apps.get_model strings, migrations, admin, fixtures), so tach and+ the facade checks cannot prove nothing outside observes it, and a model or migration change has+ to re-run the full suite.++ Stricter than the garage check on purpose: the WHOLE surface must be watched, so a directory+ location needs its full glob (backend/models/**) — an input inside it, or a negation that may+ carve files out of it, does not count. A garage may be watched piecemeal; the modelsurface may not, because any unwatched model file is a class core can observe without re-runningthe suite. There is no glob engine here, so a negation only passes when its literal prefix (upto the first wildcard) is provably disjoint from the surface — `!backend/**/x.py` could match a@@ -862,8 +868,8 @@ class IsolationStatus:unwatched_garages: tuple[str, ...] = ()uncovered_carveout_modules: tuple[str, ...] = ()# Model classes the facade hands out under the watched-models allowance (see- # MODEL_CROSSINGS); uncovered_model_surface lists the surface locations a narrowed- # product fails to keep in its contract-check inputs.+ # MODEL_CROSSINGS). uncovered_model_surface lists the model/migration locations a narrowed+ # product fails to keep in its contract-check inputs; every narrowed product must watch them.model_crossings: tuple[FacadeClassImport, ...] = ()uncovered_model_surface: tuple[str, ...] = ()@@ -917,7 +923,6 @@ def compute_isolation_status(permanent_modules = frozenset(permanent_interface_modules(tach_content, module_path))reexports = _split_facade_reexports(backend_dir, name)carveout_modules = reexports.carveout_modules- model_surface = MODEL_SURFACE_PREFIXES if reexports.model_crossings else ()return IsolationStatus(name=name,is_isolated=is_isolated,@@ -926,7 +931,9 @@ def compute_isolation_status(has_legacy_leaks=has_legacy_interface_leaks(tach_content, module_path),bypass_entries=tuple(presentation_bypass_entries(name, pyproject_text)),has_contract_check_script=has_contract_check_script(product_dir),- has_narrowed_turbo=has_narrowed_turbo_inputs(product_dir, permanent_modules, carveout_modules, model_surface),+ has_narrowed_turbo=has_narrowed_turbo_inputs(+ product_dir, permanent_modules, carveout_modules, MODEL_SURFACE_PREFIXES+ ),permanent_exposures=tuple(sorted(permanent_modules)),uncovered_permanent_exposures=tuple(sorted(uncovered_permanent_modules(product_dir, permanent_modules))),unqualified_permanent_exposures=tuple(@@ -936,5 +943,5 @@ def compute_isolation_status(unwatched_garages=tuple(sorted(unwatched_garages(product_dir))),uncovered_carveout_modules=tuple(sorted(uncovered_carveout_modules(product_dir, carveout_modules))),model_crossings=reexports.model_crossings,- uncovered_model_surface=tuple(sorted(unwatched_model_surface(product_dir))) if model_surface else (),+ uncovered_model_surface=tuple(sorted(unwatched_model_surface(product_dir))),)diff --git a/tools/hogli-commands/hogli_commands/product_structure.yaml b/tools/hogli-commands/hogli_commands/product_structure.yamlindex bce083e576a1..a4c1f82ac2e2 100644--- a/tools/hogli-commands/hogli_commands/product_structure.yaml+++ b/tools/hogli-commands/hogli_commands/product_structure.yaml@@ -66,7 +66,13 @@ root_files:"extends": ["//"],"tasks": {{"backend:contract-check": {{- "inputs": ["backend/facade/**", "backend/presentation/**", "backend/tasks/**"],+ "inputs": [+ "backend/facade/**",+ "backend/presentation/**",+ "backend/tasks/**",+ "backend/models.py",+ "backend/migrations/**"+ ],"outputs": [],"cache": true}}diff --git a/tools/hogli-commands/hogli_commands/tests/test_checks.py b/tools/hogli-commands/hogli_commands/tests/test_checks.pyindex 1b131d1fc4c5..4c135e39202f 100644--- a/tools/hogli-commands/hogli_commands/tests/test_checks.py+++ b/tools/hogli-commands/hogli_commands/tests/test_checks.py@@ -306,7 +306,7 @@ _NARROWED_TURBO = {"extends": ["//"],"tasks": {"backend:contract-check": {- "inputs": ["backend/facade/**", "backend/presentation/**"],+ "inputs": ["backend/facade/**", "backend/presentation/**", "backend/migrations/**"],"outputs": [],"cache": True,}@@ -317,7 +317,7 @@ _NARROWED_TURBO_WITH_ROUTES = {"extends": ["//"],"tasks": {"backend:contract-check": {- "inputs": ["backend/facade/**", "backend/presentation/**", "backend/routes.py"],+ "inputs": ["backend/facade/**", "backend/presentation/**", "backend/routes.py", "backend/migrations/**"],"outputs": [],"cache": True,}@@ -1821,9 +1821,40 @@ class TestWatchedModelsAllowance:def test_chain_check_blocks_when_surface_omitted(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:ctx = self._allowance_ctx(tmp_path, monkeypatch, ["backend/facade/**", "backend/models/**"])result = chain_check.run(ctx)- assert any("watched-models surface" in i and "backend/migrations/" in i for i in result.issues)+ assert any("model surface" in i and "backend/migrations/" in i for i in result.issues)assert result.file == "products/my_product/turbo.json"+ def _narrowed_ctx(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch, turbo_inputs: list[str]) -> CheckContext:+ # a narrowed product with models but no allowance entry: the surface must still be watched+ _seal_externally(monkeypatch)+ ctx = _make_product(tmp_path, scripts=_WITH_SCRIPT, isolated=True)+ (ctx.backend_dir / "models.py").write_text("class Table:\n pass\n")+ (ctx.backend_dir / "migrations").mkdir()+ (ctx.product_dir / "turbo.json").write_text(+ json.dumps({"tasks": {"backend:contract-check": {"inputs": turbo_inputs}}})+ )+ return ctx++ @pytest.mark.parametrize(+ "turbo_inputs, expected_uncovered",+ [+ (["backend/facade/**"], ["backend/migrations/", "backend/models.py"]),+ (["backend/facade/**", "backend/models.py"], ["backend/migrations/"]),+ (["backend/facade/**", "backend/models.py", "backend/migrations/**"], []),+ ],+ )+ def test_chain_check_requires_the_model_surface_without_an_allowance(+ self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch, turbo_inputs: list[str], expected_uncovered: list[str]+ ) -> None:+ ctx = self._narrowed_ctx(tmp_path, monkeypatch, turbo_inputs)+ result = chain_check.run(ctx)+ surface_issues = [i for i in result.issues if "model surface" in i]+ if not expected_uncovered:+ assert surface_issues == []+ return+ assert len(surface_issues) == 1+ assert all(location in surface_issues[0] for location in expected_uncovered)+class TestUnwatchedGarages:@pytest.mark.parametrize(@@ -1876,6 +1907,8 @@ class TestNarrowedTurboWiringSurface:"inputs, expected",[(["backend/facade/**", "backend/models/tcac.py"], set()), # covered+ (["backend/facade/**", "backend/models/**"], set()), # a dir glob covers the file inside it+ (["backend/facade/**", "backend/models_extra/**"], {"backend/models/tcac.py"}), # sibling dir doesn't(["backend/facade/**"], {"backend/models/tcac.py"}), # missing -> uncovered],)diff --git a/tools/hogli-commands/hogli_commands/tests/test_scaffold.py b/tools/hogli-commands/hogli_commands/tests/test_scaffold.pynew file mode 100644index 000000000000..776c2c178c1e--- /dev/null+++ b/tools/hogli-commands/hogli_commands/tests/test_scaffold.py@@ -0,0 +1,36 @@+from __future__ import annotations++from pathlib import Path++from hogli_commands.product.isolation import MODEL_SURFACE_PREFIXES, has_narrowed_turbo_inputs, unwatched_model_surface+from hogli_commands.product.paths import load_structure+from hogli_commands.product.scaffold import _render_template, flatten_structure+++def _write_scaffold(product_dir: Path) -> None:+ # Renders every template like bootstrap_product does, minus the repo-file edits+ # (tach.toml, settings, db routing) that must not run inside a test.+ structure = load_structure()+ for path, config in flatten_structure(structure.get("root_files", {})).items():+ file_path = product_dir / path+ file_path.parent.mkdir(parents=True, exist_ok=True)+ file_path.write_text(_render_template(config.get("template", ""), "my_product", separate_db=True))+ for path, config in flatten_structure(structure.get("backend_files", {})).items():+ file_path = product_dir / "backend" / path+ file_path.parent.mkdir(parents=True, exist_ok=True)+ file_path.write_text(_render_template(config.get("template", ""), "my_product", separate_db=True))+++class TestScaffoldPassesIsolationGates:+ # The baseline header promises a bootstrapped product is sealed from its first+ # commit, so the scaffold must satisfy the same gates product:lint blocks on.++ def test_scaffold_watches_the_model_surface(self, tmp_path: Path) -> None:+ product_dir = tmp_path / "my_product"+ _write_scaffold(product_dir)+ assert unwatched_model_surface(product_dir) == set()++ def test_scaffold_inputs_count_as_narrowed(self, tmp_path: Path) -> None:+ product_dir = tmp_path / "my_product"+ _write_scaffold(product_dir)+ assert has_narrowed_turbo_inputs(product_dir, model_surface=MODEL_SURFACE_PREFIXES) is True