: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
chore(ci): derive non-isolated product lanes from the tach graph (#76951)
Georges-Antoine Assi509e7c77af2b
diff --git a/.github/scripts/trunk-impacted-targets.js b/.github/scripts/trunk-impacted-targets.jsindex 6b9274d33991..5941005421ab 100644--- a/.github/scripts/trunk-impacted-targets.js+++ b/.github/scripts/trunk-impacted-targets.js@@ -25,17 +25,32 @@// renames a facade function and updates every current caller, PR B adds a new// call to the old name, and master breaks on a combination neither run held.//-// 1. Only a change to a product's declared contract surface seeds the-// dependent cascade. A file that no module outside the product can import-// cannot be the shared symbol two PRs disagree about, so a change confined-// to internals keeps its own product's lane. The surface is the product's-// own `backend:contract-check` inputs in products/<name>/turbo.json, the-// same declaration turbo-discover reads to decide whether dependent test-// suites run, so the two mechanisms cannot drift apart. A product that-// declares no narrowed inputs cascades on every backend file as before.-// This makes the declaration load-bearing for correctness: an input list-// that omits a file other products import puts those products in a-// parallel lane.+// 1. A product change claims its own lane plus its direct importers, rather+// than every backend lane. tach.toml is the enforced Python module graph+// (`tach check` runs in CI), so for a product it declares, the modules+// that may import it are exactly the ones listing it in `depends_on`. A+// product absent from that graph is unconstrained and still widens.+//+// This does NOT require the product to be isolated. Isolation is the+// stronger claim that a change inside the product can only break the+// product's own tests, which is what lets CI skip the full Django suite,+// and products/architecture.md is explicit that tach cannot prove it:+// cross-cutting tests reach a product's endpoints by URL, in process,+// with no import for any graph to see. A lane only has to answer whether+// another PR can reference the symbols this one changed, which is the+// import half that tach does enforce. So a product too unsealed to skip+// the suite still has a bounded importer set, and gets a lane from it.+//+// Which of the product's own files seed that cascade is the narrower+// question isolation does govern. An isolated product declares a contract+// surface as its `backend:contract-check` inputs in products/<name>/turbo.json.+// This is the same declaration turbo-discover reads to decide whether dependent+// test suites run, so the two mechanisms cannot drift apart. A change confined+// to its internals keeps its own lane without cascading. This makes the+// declaration load-bearing for+// correctness: an input list that omits a file other products import puts+// those products in a parallel lane. A product that declares no narrowed+// inputs, isolated or not, cascades on every backend file.//// 2. The cascade names direct importers rather than the transitive closure.// Only a direct importer can reference the changed product's symbols.@@ -636,16 +651,28 @@ function loadBackendDetachedProducts(repoRoot, products, tachGraph) {}const detached = new Set()for (const product of products) {- // tach spells its modules both ways across the file, so a product- // counts as declared under either spelling.- const declared = tachGraph.graph.has(product) || tachGraph.graph.has(product.replace(/_/g, '-'))- if (ignored.has(`products/${product}`) && !declared) {+ if (ignored.has(`products/${product}`) && !isTachDeclared(product, tachGraph)) {detached.add(product)}}return detached}+// tach spells its modules both ways across the file, so a product counts as+// declared under either spelling. A product absent from the graph, or a graph+// that could not be read at all, is not constrained by `tach check` and so has+// no bounded importer set.+function isTachDeclared(product, tachGraph) {+ if (!tachGraph) {+ return false+ }+ return tachGraph.graph.has(product) || tachGraph.graph.has(product.replace(/_/g, '-'))+}++function listTachDeclaredProducts(products, tachGraph) {+ return new Set(products.filter((product) => isTachDeclared(product, tachGraph)))+}+// --- Contract surfaces ---const CONTRACT_TASK = 'backend:contract-check'@@ -1079,6 +1106,7 @@ function computeTargets(changedFiles, context) {contractSurfaces = new Map(),productWorkspaces = new Map(),backendDetachedProducts = new Set(),+ tachDeclaredProducts = listTachDeclaredProducts(products, tachGraph),} = contextconst targets = new Set()@@ -1247,13 +1275,27 @@ function computeTargets(changedFiles, context) {// case below: a product absent from the module graph has no// importers for the cascade to name.targets.add(pyProduct(product))- } else if (isContractDeclaration(product, file)) {- // A non-isolated product's backend code has no declared- // boundary, so it keeps widening below. Its declarations- // are a different kind of file: they configure this- // product's own tasks, including the backend:test command- // most of them carry, and every importer that a change to- // them can reach is named by the cascade instead.+ } else if (isContractDeclaration(product, file) || tachDeclaredProducts.has(product)) {+ // A non-isolated product has declared no contract surface,+ // so every backend file in it counts as contract and seeds+ // the cascade. That names its direct importers, which is+ // what a lane needs.+ //+ // Isolation is a stronger claim than this one and is not+ // required here. It says a change inside the product can+ // only break the product's own tests, which lets CI skip+ // the full Django suite, and products/architecture.md is+ // explicit that tach cannot prove it: cross-cutting tests+ // reach a product's endpoints by URL, in process, with no+ // import to see. A lane only has to answer whether another+ // PR can reference the symbols this one changed, and that+ // is the import half, which `tach check` does enforce. So a+ // product can be too unsealed to skip the suite and still+ // have a bounded importer set.+ //+ // The bound only holds for a product tach declares. One+ // absent from the graph is unconstrained by `tach check`,+ // so anything may import it and it still widens below.targets.add(pyProduct(product))cascadeSeeds.add(product)} else {@@ -1385,6 +1427,7 @@ function buildContext(repoRoot) {contractSurfaces: loadContractSurfaces(repoRoot, products),productWorkspaces: loadProductWorkspaces(repoRoot, products),backendDetachedProducts: loadBackendDetachedProducts(repoRoot, products, tachGraph),+ tachDeclaredProducts: listTachDeclaredProducts(products, tachGraph),semgrepDomains: loadSemgrepDomains(repoRoot),rustGraph: loadRustGraph(repoRoot),tachGraph,diff --git a/.github/scripts/trunk-impacted-targets.test.js b/.github/scripts/trunk-impacted-targets.test.jsindex b469afe6d034..9d8ffe558c47 100644--- a/.github/scripts/trunk-impacted-targets.test.js+++ b/.github/scripts/trunk-impacted-targets.test.js@@ -64,6 +64,32 @@ const CONTEXT = {// What a widening decision now uploads in place of the "ALL" sentinel.const EVERYTHING = allKnownTargets(CONTEXT)+// A graph that declares all three products, so their importer sets are bounded.+// The base CONTEXT deliberately declares none, which covers the case where a+// product sits outside `tach check` and has to keep widening.+const TACH_DECLARED_CONTEXT = {+ ...CONTEXT,+ tachGraph: {+ graph: parseTachModules(`+[[modules]]+path = "products.alpha"+depends_on = []+layer = "modules"++[[modules]]+path = "products.beta"+depends_on = ["products.gamma"]+layer = "modules"++[[modules]]+path = "products.gamma"+depends_on = []+layer = "modules"+`),+ tachDependents,+ },+}+// gamma vendors its own pnpm workspace; alpha and beta keep the conventional// backend/ + frontend/ layout, so the cases above stay on the old behavior.const WORKSPACE_CONTEXT = {@@ -541,7 +567,10 @@ layer = "modules"])})-test('a non-isolated product change widens to every backend target', () => {+// The base CONTEXT keeps an empty tach graph, so no product is declared in it.+// A product `tach check` does not constrain has no bounded importer set: any+// module may import it, so its change still has to reach every backend lane.+test('a product absent from the tach graph widens to every backend target', () => {const targets = computeTargets(['products/gamma/backend/api.py'], CONTEXT)assert.equal(targets.includes('py:core'), true)for (const product of CONTEXT.products) {@@ -549,6 +578,41 @@ test('a non-isolated product change widens to every backend target', () => {}})+// The lane only has to answer whether another PR can reference the symbols this+// one changed, and tach.toml answers exactly that. Isolation is the stronger,+// separate claim that the product's own suite is sufficient, which lets CI+// skip the full Django suite, and which products/architecture.md says tach+// cannot prove. A product can be too unsealed for that and still be bounded+// here, which is why gamma (non-isolated) narrows the same way alpha does.+test('a non-isolated product tach declares claims its own lane and its importers', () => {+ assert.deepEqual(computeTargets(['products/gamma/backend/api.py'], TACH_DECLARED_CONTEXT), [+ 'py:product:beta',+ 'py:product:gamma',+ ])+ // Every backend file seeds, because a product with no declared contract+ // surface has no way to say a file is internal.+ assert.deepEqual(+ computeTargets(['products/gamma/backend/internal/helper.py'], TACH_DECLARED_CONTEXT),+ computeTargets(['products/gamma/backend/api.py'], TACH_DECLARED_CONTEXT)+ )+})++// Isolation still governs the narrower question of which of a product's own+// files seed the cascade at all, which is what a contract surface declares.+test('isolation still buys a narrowed contract surface on top of the lane', () => {+ const context = {+ ...TACH_DECLARED_CONTEXT,+ isolatedProducts: new Set([...CONTEXT.isolatedProducts, 'gamma']),+ contractSurfaces: new Map([['gamma', compileContractMatcher(['backend/facade/**'])]]),+ }+ // Internals keep the product's own lane, with no cascade to beta.+ assert.deepEqual(computeTargets(['products/gamma/backend/internal/helper.py'], context), ['py:product:gamma'])+ assert.deepEqual(computeTargets(['products/gamma/backend/facade/api.py'], context), [+ 'py:product:beta',+ 'py:product:gamma',+ ])+})+// 63 of the products are non-isolated, and their package.json carries the// backend:test command rather than being a bare JS manifest. It still claims a// backend lane, just this product's own plus its importers, instead of dragging@@ -571,9 +635,10 @@ test("a non-isolated product's declarations still seed the dependent cascade", (])})-// The narrowing is scoped to the declarations. Backend code in a non-isolated-// product has no declared boundary, which is the whole reason it widens.-test('a non-isolated product keeps widening on everything that is not a declaration', () => {+// Declarations narrow even for a product tach does not declare, because they+// configure only this product's own tasks. Its other files have neither a+// declared boundary nor a bounded importer set, so they still widen.+test('an undeclared product keeps widening on everything that is not a declaration', () => {for (const file of ['products/gamma/backend/api.py', 'products/gamma/mcp/tools.yaml']) {assert.equal(computeTargets([file], CONTEXT).includes('py:product:alpha'), true, file)}