: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(devex): run backend test selection on ready PRs, not just drafts (#85530)
Julian Bez4628e6d1ede4
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 64f118e550d4..05dbb64ed33f 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -107,10 +107,11 @@ on:description: ClickHouse server version. Leave blank for defaulttype: stringpull_request:- # Draft PRs run the snob-selected Django subset (≤3 shards); turbo-tests- # still skip drafts. Ready PRs run the full matrices — the merge gate —- # and ready_for_review re-triggers them when a PR leaves draft. Add the- # `run-ci-backend` label to force the full matrices on a draft; the+ # PRs run the snob-selected Django subset (one shard per active segment),+ # draft or ready; turbo-tests still skip drafts. When selection can't be+ # trusted, a ready PR runs the full matrices and a draft skips them. The+ # queue's trunk-merge/** run and master pushes always run full. Add the+ # `run-ci-backend` label to force the full matrices on a PR; the# `no-ci` label silences the workflow on a draft entirely. No# labeled/unlabeled triggers, so a label takes effect from the next push# or from ready_for_review. Mirrors canonical.@@ -496,6 +497,7 @@ jobs:name: Discover product testsoutputs:run_legacy: ${{ steps.discover.outputs.run_legacy }}+ run_legacy_reason: ${{ steps.discover.outputs.run_legacy_reason }}matrix: ${{ steps.discover.outputs.matrix }}schema_cache_key: ${{ steps.schema-key.outputs.key }}schema_migrations_key: ${{ steps.schema-key.outputs.migrations_key }}@@ -591,15 +593,17 @@ jobs:echo "Result: $RESULT"echo "matrix=$(echo "$RESULT" | jq -c '.matrix')" >> $GITHUB_OUTPUTecho "run_legacy=$(echo "$RESULT" | jq -r '.run_legacy')" >> $GITHUB_OUTPUT+ echo "run_legacy_reason=$(echo "$RESULT" | jq -r '.run_legacy_reason // empty')" >> "$GITHUB_OUTPUT"echo "django_shards=$(echo "$RESULT" | jq -c '.django_shards // empty')" >> $GITHUB_OUTPUT- # Pick which Django tests to run on draft PRs. Drafts get the snob-selected- # subset for fast feedback; the full matrix runs once the PR is marked ready- # for review, and that ready run is the merge gate. When selection can't be- # trusted on a draft (legacy graph impact, turbo-discover or selector failure,- # a selector full-run signal), the draft skips the heavy matrices entirely —- # the pre-selection draft behavior — and defers to the ready full run.- # hogli-lint: not-a-required-gate - selects draft coverage and emits no required check.+ # Pick which Django tests to run on a PR. Both drafts and ready PRs get the+ # snob-selected subset; the difference is what happens when selection can't be+ # trusted (product->legacy cascade, turbo-discover or selector failure, a+ # selector full-run signal). A ready PR then runs the full matrices, a draft+ # skips them and defers to its ready run — the pre-selection draft behavior.+ # Master pushes and the queue's trunk-merge/** run never reach this job, so+ # what gates master is still a full run.+ # hogli-lint: not-a-required-gate - selects PR coverage and emits no required check.## Depot shadow note: canonical uploads /tmp/selection.json for its# test-selection-verdict job. The depot shadow strips that job (and all@@ -607,25 +611,26 @@ jobs:select-tests:name: Select testsneeds: [changes, turbo-discover]- # Only draft PRs do selective runs; ready PRs and pushes always run full,- # which build_django_matrix falls back to- # when select-tests is skipped (empty MODE). The run-ci-backend label- # forces the full matrices on a draft.+ # Pushes always run full, which build_django_matrix falls back to when+ # select-tests is skipped (empty MODE). The run-ci-backend label forces+ # the full matrices on a PR.# Trunk's merge-queue branches open as draft PRs, but their run IS the# merge gate, so they must never get the narrowed selection.if: |github.event_name == 'pull_request' &&- github.event.pull_request.draft == true &&!startsWith(github.head_ref, 'trunk-merge/') &&!contains(github.event.pull_request.labels.*.name, 'run-ci-backend') &&needs.changes.outputs.backend == 'true'runs-on: depot-ubuntu-24.04- timeout-minutes: 5+ # Headroom over checkout + uv + the selector's whole-tree parse. A timeout here+ # leaves MODE empty, which on a ready PR means the full matrix — the worst case.+ timeout-minutes: 10outputs:mode: ${{ steps.classify.outputs.mode }}core_files: ${{ steps.classify.outputs.core_files }}poe_files: ${{ steps.classify.outputs.poe_files }}temporal_files: ${{ steps.classify.outputs.temporal_files }}+ compat_files: ${{ steps.classify.outputs.compat_files }}run_poe: ${{ steps.classify.outputs.run_poe }}run_temporal: ${{ steps.classify.outputs.run_temporal }}# Kept apples-to-apples with canonical, though the shadow strips the@@ -638,48 +643,69 @@ jobs:selected_test_seconds: ${{ steps.classify.outputs.selected_test_seconds }}skipped_test_seconds: ${{ steps.classify.outputs.skipped_test_seconds }}run_legacy: ${{ steps.fallback.outputs.run_legacy }}+ run_legacy_reason: ${{ steps.fallback.outputs.run_legacy_reason }}turbo_result: ${{ steps.fallback.outputs.turbo_result }}steps:- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2- with:- fetch-depth: 1000- filter: blob:none-- - name: Install uv- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0- with:- version: '0.11.28'-+ # Ahead of the checkout on purpose: this reads job outputs only, and when it+ # decides selection can't be trusted, cloning the repo would just delay the+ # full matrix that is about to run instead.- name: Decide whether selection can be trustedid: fallbackenv:RUN_LEGACY: ${{ needs.turbo-discover.outputs.run_legacy }}+ RUN_LEGACY_REASON: ${{ needs.turbo-discover.outputs.run_legacy_reason }}TURBO_RESULT: ${{ needs.turbo-discover.result }}+ DISABLED: ${{ vars.DISABLE_BACKEND_TEST_SELECTION || 'false' }}shell: bashrun: |set -euo pipefailskip=false- if [[ "$RUN_LEGACY" == "true" ]]; then- # turbo-discover detected product->legacy graph impact; the- # diff-based selector can't see this, so its subset would be- # incomplete. Skip the draft matrices; the ready run is full.+ reason=untrusted+ if [[ "$DISABLED" == "true" ]]; then+ # Kill switch — set the DISABLE_BACKEND_TEST_SELECTION repo variable to+ # put every PR back on the full matrices without a code change. Its own+ # reason string, so flipping it during an incident stays distinguishable+ # from a genuine cascade in the selection telemetry.+ skip=true+ reason=disabled+ elif [[ "$RUN_LEGACY" == "true" && "$RUN_LEGACY_REASON" != "legacy_changed" ]]; then+ # turbo-discover inferred legacy impact from a product, contract, or+ # schema change rather than seeing a direct edit. The diff-based selector+ # cannot see that cascade, so its subset would be incomplete.+ # A direct legacy edit is the selector's home turf and is deliberately not+ # untrusted here — the selector's own FULL_RUN_PATTERNS decide when a+ # legacy change is too broad to narrow.skip=trueelif [[ "$TURBO_RESULT" != "success" && "$TURBO_RESULT" != "skipped" ]]; then# Conservative — turbo-discover failed.skip=truefiecho "skip=$skip" >> "$GITHUB_OUTPUT"- # Surface the inputs behind an untrusted skip so the telemetry can- # tell legacy-graph impact apart from a turbo-discover failure.+ echo "reason=$reason" >> "$GITHUB_OUTPUT"+ # Surface the raw inputs too, so the telemetry can audit the decision.echo "run_legacy=${RUN_LEGACY:-}" >> "$GITHUB_OUTPUT"+ echo "run_legacy_reason=${RUN_LEGACY_REASON:-}" >> "$GITHUB_OUTPUT"echo "turbo_result=${TURBO_RESULT:-}" >> "$GITHUB_OUTPUT"+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ if: steps.fallback.outputs.skip == 'false'+ with:+ fetch-depth: 1000+ filter: blob:none++ - name: Install uv+ if: steps.fallback.outputs.skip == 'false'+ uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0+ with:+ version: '0.11.28'+- name: Run shadow selectorid: select# continue-on-error so a selector or git fetch failure doesn't fail this# job — a failed select-tests would leave MODE empty and build_django_matrix# would fall back to an expensive full matrix on a draft. Classify reads- # steps.select.outcome (pre-continue-on-error) and emits mode=skip instead.+ # steps.select.outcome (pre-continue-on-error) and emits the fallback mode+ # for this PR instead.continue-on-error: trueif: steps.fallback.outputs.skip == 'false'env:@@ -696,7 +722,15 @@ jobs:id: classifyenv:FALLBACK_SKIP: ${{ steps.fallback.outputs.skip }}+ FALLBACK_REASON: ${{ steps.fallback.outputs.reason }}SELECT_OUTCOME: ${{ steps.select.outcome }}+ # Guards the empty-selection backstop below. select-tests only runs on+ # pull_request, so the bare filter output is the whole story here.+ LEGACY_CHANGED: ${{ needs.changes.outputs.legacy }}+ # What an untrusted selection falls back to. A ready PR has no later+ # run to defer to, so it must run everything; a draft still skips and+ # leans on the ready run, which is the cheaper of the two mistakes.+ FALLBACK_MODE: ${{ github.event.pull_request.draft && 'skip' || 'full' }}shell: bashrun: |set -euo pipefail@@ -722,34 +756,35 @@ jobs:} >> "$GITHUB_OUTPUT"}- # Untrusted selection on a draft skips the heavy matrices (the- # pre-selection draft behavior); the ready-for-review run is full.- fall_back_to_skip() {- echo "mode=skip" >> "$GITHUB_OUTPUT"+ # Untrusted selection runs the full matrices on a ready PR and skips+ # them on a draft (the pre-selection draft behavior).+ fall_back() {+ echo "mode=$FALLBACK_MODE" >> "$GITHUB_OUTPUT"echo "core_files=" >> "$GITHUB_OUTPUT"echo "poe_files=" >> "$GITHUB_OUTPUT"echo "temporal_files=" >> "$GITHUB_OUTPUT"+ echo "compat_files=" >> "$GITHUB_OUTPUT"echo "run_poe=false" >> "$GITHUB_OUTPUT"echo "run_temporal=false" >> "$GITHUB_OUTPUT"emit_metrics false "$1"}if [[ "$FALLBACK_SKIP" == "true" ]]; then- fall_back_to_skip untrusted+ fall_back "${FALLBACK_REASON:-untrusted}"exit 0fiif [[ "$SELECT_OUTCOME" != "success" ]] || [[ ! -s /tmp/selection.json ]]; then- echo "::warning::shadow selector did not produce output; draft skips heavy matrices (full run happens on ready for review)"- fall_back_to_skip selector_error+ echo "::warning::shadow selector did not produce output; falling back to mode=$FALLBACK_MODE"+ fall_back selector_errorexit 0fifull_run_reasons=$(jq -r '.ast.full_run_reasons | length' /tmp/selection.json)if [[ "$full_run_reasons" -gt 0 ]]; then- echo "Selector requested a full run; draft defers it to ready for review:"+ echo "Selector requested a full run (mode=$FALLBACK_MODE):"jq -r '.ast.full_run_reasons[]' /tmp/selection.json- fall_back_to_skip full_run_requested+ fall_back full_run_requestedexit 0fi@@ -761,14 +796,26 @@ jobs:# posthog/api/test/dashboards/test_dashboard.py, ee/clickhouse/# Temporal: posthog/temporal, products/{batch_exports,tasks}/backend/temporal,# products/signals/backend/emission+ # Compat: CLICKHOUSE_COMPAT_PYTEST_TARGETS (posthog/clickhouse, ee/clickhouse)# Files outside posthog/ and ee/ (e.g. products/foo/backend/test_*) are not in this# matrix. turbo-tests handles them; warehouse_sources and managed_warehouse run# their own temporal suites there.core=()poe=()temporal=()+ compat=()while IFS= read -r f; do[[ -z "$f" ]] && continue+ # Compat overlaps the POE scope rather than partitioning with it, so+ # it is collected separately from the segment case below. Driven by the+ # same env var the compat pytest invocation uses, so widening one can't+ # silently under-select the other.+ for compat_target in $CLICKHOUSE_COMPAT_PYTEST_TARGETS; do+ if [[ "$f" == "${compat_target%/}/"* ]]; then+ compat+=("$f")+ break+ fi+ donecase "$f" inposthog/temporal/*|products/batch_exports/backend/tests/temporal/*|products/tasks/backend/temporal/*|products/signals/backend/emission/*)temporal+=("$f")@@ -786,15 +833,29 @@ jobs:esacdone < <(jq -r '.combined.tests[]?' /tmp/selection.json)+ # Backstop: a diff that touched legacy code but selected no Django test at+ # all means the selector had no rule for it, not that there is nothing to+ # run — a non-Python legacy file (C++ parser sources, a JSON config) reaches+ # no import edge. Narrowing to zero would silently gate on nothing, so treat+ # it as untrusted. FULL_RUN_PATTERNS covers the known cases; this catches the+ # ones that get added to the `legacy` paths filter and forgotten there.+ # Products-only diffs legitimately select nothing here and are not legacy.+ if [[ "$LEGACY_CHANGED" == "true" && ${#core[@]} -eq 0 && ${#temporal[@]} -eq 0 ]]; then+ echo "::warning::legacy files changed but no Django test was selected; falling back to mode=$FALLBACK_MODE"+ fall_back empty_selection+ exit 0+ fi+echo "mode=selected" >> "$GITHUB_OUTPUT"echo "core_files=${core[*]:-}" >> "$GITHUB_OUTPUT"echo "poe_files=${poe[*]:-}" >> "$GITHUB_OUTPUT"echo "temporal_files=${temporal[*]:-}" >> "$GITHUB_OUTPUT"+ echo "compat_files=${compat[*]:-}" >> "$GITHUB_OUTPUT"echo "run_poe=$([[ ${#poe[@]} -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"echo "run_temporal=$([[ ${#temporal[@]} -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"emit_metrics true ""- echo "Selected: ${#core[@]} core, ${#poe[@]} POE-eligible, ${#temporal[@]} temporal"+ echo "Selected: ${#core[@]} core, ${#poe[@]} POE-eligible, ${#temporal[@]} temporal, ${#compat[@]} compat"build-product-test-matrix:name: Build product test matrix@@ -1385,6 +1446,7 @@ jobs:RUN_POE: ${{ needs.select-tests.outputs.run_poe }}RUN_TEMPORAL: ${{ needs.select-tests.outputs.run_temporal }}CORE_FILES: ${{ needs.select-tests.outputs.core_files }}+ COMPAT_FILES: ${{ needs.select-tests.outputs.compat_files }}# A trunk-merge/** PR opens as a draft but is the merge gate, and# select-tests deliberately does not run for it. Reporting it as a# draft here would turn that empty MODE into "skip" and build an@@ -1397,8 +1459,8 @@ jobs:# :NOTE: Keep shard counts/group ranges in sync with historical Django matrix tuning.# Consult #team-devex before changing.- # A draft PR must never fall back to the full matrix. select-tests only- # runs on drafts and sets MODE to "skip"/"selected"; an empty MODE on a+ # A draft PR must never fall back to the full matrix. select-tests sets+ # MODE to "skip"/"full"/"selected"; an empty MODE on a# draft means select-tests was cancelled or failed (typically# ready_for_review superseding it mid-flight). Skip here and defer to the# ready run. The run-ci-backend label intentionally forces full on a draft.@@ -1415,8 +1477,8 @@ jobs:exit 0fiif [[ "$MODE" == "selected" ]]; then- # Selected mode: collapse to one shard per active segment, skip- # segments with no selected files, drop compat entirely.+ # Selected mode: collapse to one shard per active segment and skip+ # segments with no selected files.core_count=0[[ -n "$CORE_FILES" ]] && core_count=1core=$(jq -cn --arg image "$OLDEST_SUPPORTED_IMAGE" --argjson n "$core_count" '@@ -1501,7 +1563,31 @@ jobs:compat: false}]')- compat="[]"+ # Compat covers the older supported ClickHouse versions over+ # CLICKHOUSE_COMPAT_PYTEST_TARGETS. Selection can drop it only when the+ # diff touches none of those paths — otherwise a narrowed run would+ # silently lose the one signal the full matrix has about old servers.+ # One unsharded entry per version, over the selected compat files.+ if [[ -n "$COMPAT_FILES" ]]; then+ compat=$(jq -cn --argjson compat "${COMPAT_MATRIX_JSON:-[]}" '+ [ $compat+ | map(."clickhouse-server-image") | unique | to_entries[]+ | {+ "clickhouse-server-image": .value,+ segment: "Core",+ "person-on-events": false,+ "new-events-schema": false,+ "python-version": "3.13.13",+ concurrency: 1,+ group: 1,+ compat: true,+ artifact_key: ("compat-" + ((.key + 1)|tostring))+ }+ ]+ ')+ else+ compat="[]"+ fielse# Full run: auto-shard counts from turbo-discover (Amdahl's law on .test_durations).# Falls back to hardcoded defaults if turbo-discover failed or data is missing.@@ -1937,9 +2023,12 @@ jobs:MODE: ${{ needs.select-tests.outputs.mode }}CORE_FILES: ${{ needs.select-tests.outputs.core_files }}POE_FILES: ${{ needs.select-tests.outputs.poe_files }}+ COMPAT_FILES: ${{ needs.select-tests.outputs.compat_files }}# devex: measure core (posthog/ee) coverage on PRs to size the gap vs products. sysmon = low overhead.COVERAGE_CORE: sysmon- COV_ARGS: ${{ github.event_name == 'pull_request' && '--cov=posthog --cov=ee --cov-config=.github/coverage-core.cfg --cov-report=xml:coverage-core.xml' || '' }}+ # Mirrors canonical: the coverage report skips narrowed runs, so+ # instrumenting one is pure overhead.+ COV_ARGS: ${{ github.event_name == 'pull_request' && needs.select-tests.outputs.mode != 'selected' && '--cov=posthog --cov=ee --cov-config=.github/coverage-core.cfg --cov-report=xml:coverage-core.xml' || '' }}shell: 'signal-fanout bash --noprofile --norc -eo pipefail {0}'run: |unset GITHUB_TOKEN # reserved var injected by Depot CI; can't override via env: (see workflow env note)@@ -1970,7 +2059,9 @@ jobs:# No --splits/--group (no sharding), and no --reruns anywhere, mirroring# canonical: retries mask the raw flake signal Trunk needs (the shadow# strips the quarantine gate itself).- if [[ "${{ matrix.person-on-events }}" == "true" ]]; then+ if [[ "${{ matrix.compat }}" == "true" ]]; then+ targets="$COMPAT_FILES"+ elif [[ "${{ matrix.person-on-events }}" == "true" ]]; thentargets="$POE_FILES"elsetargets="$CORE_FILES"diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.jsindex 4212d924cc93..7d7dac53c15e 100644--- a/.github/scripts/turbo-discover.js+++ b/.github/scripts/turbo-discover.js@@ -707,11 +707,16 @@ const allProductSet = new Set(allProducts)let productslet runLegacy+// Why runLegacy was set, so ci-backend's test selection can tell a direct legacy edit+// (which the diff-based selector handles) from an inferred product->legacy cascade+// (which it cannot see). Empty when runLegacy is false.+let runLegacyReason = ''if (legacyChanged) {console.error('Legacy code changed — testing all products')products = allProductsrunLegacy = true+ runLegacyReason = 'legacy_changed'} else {const isolatedProducts = getIsolatedProducts(contractTasks)const affectedProducts = getAffectedTaskProducts(affectedTestTasks)@@ -728,6 +733,7 @@ if (legacyChanged) {)products = allProductsrunLegacy = true+ runLegacyReason = 'non_isolated_product'} else if (affectedProducts.length > 0) {// Only isolated products changed — check whether their contract surface was affectedconst affectedProductSet = new Set(affectedProducts)@@ -737,6 +743,7 @@ if (legacyChanged) {if (affectedContracts.length > 0) {console.error(`Isolated product contracts changed: ${JSON.stringify(affectedContracts)} — Django will run`)runLegacy = true+ runLegacyReason = 'contract_cascade'const tachGraph = loadTachModuleGraph()if (tachGraph === null) {// Fail toward over-testing, like the quarantine loaders above: without the@@ -771,6 +778,7 @@ if (legacyChanged) {console.error(`Schema diff unavailable (${impact.reason}) — falling back to all products + Django`)products = allProductsrunLegacy = true+ runLegacyReason = 'schema'} else {if (impact.kind === 'impacting') {console.error(`Schema-affected products: ${JSON.stringify(impact.affectedProducts)}`)@@ -785,6 +793,7 @@ if (legacyChanged) {}// Core (posthog/, ee/, etc.) imports schema heavily; always run Django on schema changes.runLegacy = true+ runLegacyReason = 'schema'}}}@@ -803,11 +812,13 @@ if (quarantinedProducts.size > 0) {products = dropProducts(products, allProducts, quarantinedProducts, 'Quarantined products (mode: skip)')}-// Un-quarantining must re-run the suite. Today the ci-backend `legacy` paths--// filter already forces a full run on any PR touching the quarantine file, so-// this diff against the merge base rarely changes the outcome — it is the-// backstop that keeps product re-runs correct if that coarse trigger is ever-// narrowed (Turbo itself never sees .test_quarantine.json as a product input).+// Un-quarantining must re-run the suite. The ci-backend `legacy` paths-filter still+// pulls every product into the matrix on any PR touching the quarantine file, so this+// diff against the merge base rarely changes the outcome — it is the backstop that+// keeps product re-runs correct if that coarse trigger is ever narrowed (Turbo itself+// never sees .test_quarantine.json as a product input). Django's side of the same+// invariant is carried by FULL_RUN_PATTERNS in the backend test selector, since a+// legacy diff no longer implies a full Django run on its own.if (process.env.TURBO_SCM_BASE) {const baseQuarantined = loadBaseQuarantinedSkipProducts(process.env.TURBO_SCM_BASE, todayISO)const allProductSet = new Set(allProducts)@@ -822,7 +833,7 @@ if (process.env.TURBO_SCM_BASE) {}console.error(`Products to test: ${JSON.stringify(products)}`)-console.error(`Run legacy (Django): ${runLegacy}`)+console.error(`Run legacy (Django): ${runLegacy}${runLegacyReason ? ` (${runLegacyReason})` : ''}`)const durations = loadTestDurations()@@ -832,6 +843,7 @@ const djangoShards = buildDjangoShards(durations)const result = {matrix: buildMatrix(products, durations),run_legacy: runLegacy,+ run_legacy_reason: runLegacyReason,django_shards: djangoShards,}// eslint-disable-next-line no-consolediff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 0fdca0c8fe3f..0fc12a44455f 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -13,11 +13,14 @@ on:description: ClickHouse server version. Leave blank for defaulttype: stringpull_request:- # Draft PRs run the snob-selected Django subset (≤3 shards) for fast feedback;- # turbo-tests (product tests) still skip drafts. Ready PRs run the full- # matrices — that full run is the merge gate, and ready_for_review re-triggers- # it when a PR leaves draft. To force the full matrices on a draft, add the- # `run-ci-backend` label. Cheap checks still run on drafts.+ # PRs run the snob-selected Django subset (one shard per active segment)+ # for fast feedback, draft or ready. When selection can't be trusted, a+ # ready PR falls back to the full matrices and a draft skips them instead,+ # deferring to its ready run. turbo-tests (product tests) still skip drafts.+ # The merge queue's trunk-merge/** run and master pushes always run the full+ # matrices, and the queue run is what actually gates master. To force the+ # full matrices on a PR, add the `run-ci-backend` label. Cheap checks still+ # run on drafts.# The `no-ci` label does the opposite: it silences this workflow on a draft# entirely (prototypes/spikes).# No labeled/unlabeled triggers: GitHub cannot filter a label trigger by name,@@ -390,6 +393,7 @@ jobs:name: Discover product testsoutputs:run_legacy: ${{ steps.discover.outputs.run_legacy }}+ run_legacy_reason: ${{ steps.discover.outputs.run_legacy_reason }}matrix: ${{ steps.discover.outputs.matrix }}schema_cache_key: ${{ steps.schema-key.outputs.key }}schema_migrations_key: ${{ steps.schema-key.outputs.migrations_key }}@@ -542,37 +546,42 @@ jobs:echo "Result: $RESULT"echo "matrix=$(echo "$RESULT" | jq -c '.matrix')" >> $GITHUB_OUTPUTecho "run_legacy=$(echo "$RESULT" | jq -r '.run_legacy')" >> $GITHUB_OUTPUT+ echo "run_legacy_reason=$(echo "$RESULT" | jq -r '.run_legacy_reason // empty')" >> "$GITHUB_OUTPUT"echo "django_shards=$(echo "$RESULT" | jq -c '.django_shards // empty')" >> $GITHUB_OUTPUT- # Pick which Django tests to run on draft PRs. Drafts get the snob-selected- # subset for fast feedback; the full matrix runs once the PR is marked ready- # for review, and that ready run is the merge gate. When selection can't be- # trusted on a draft (legacy graph impact, turbo-discover or selector failure,- # a selector full-run signal), the draft skips the heavy matrices entirely —- # the pre-selection draft behavior — and defers to the ready full run.- # hogli-lint: not-a-required-gate - selects draft coverage and emits no required check.+ # Pick which Django tests to run on a PR. Both drafts and ready PRs get the+ # snob-selected subset; the difference is what happens when selection can't be+ # trusted (product->legacy cascade, turbo-discover or selector failure, a+ # selector full-run signal). A ready PR then runs the full matrices, a draft+ # skips them and defers to its ready run — the pre-selection draft behavior.+ # Master pushes and the queue's trunk-merge/** run never reach this job, so+ # what gates master is still a full run.+ # hogli-lint: not-a-required-gate - selects PR coverage and emits no required check.select-tests:name: Select testsneeds: [changes, turbo-discover]- # Only draft PRs do selective runs; ready PRs and pushes always run full,- # which build_django_matrix falls back to- # when select-tests is skipped (empty MODE). The run-ci-backend label- # forces the full matrices on a draft.+ # Pushes always run full, which build_django_matrix falls back to when+ # select-tests is skipped (empty MODE). The run-ci-backend label forces+ # the full matrices on a PR.# Trunk's merge-queue branches open as draft PRs, but their run IS the# merge gate, so they must never get the narrowed selection.if: |github.event_name == 'pull_request' &&- github.event.pull_request.draft == true &&!startsWith(github.head_ref, 'trunk-merge/') &&!contains(github.event.pull_request.labels.*.name, 'run-ci-backend') &&needs.changes.outputs.backend == 'true'- runs-on: ubuntu-latest- timeout-minutes: 5+ # Depot, like every other pre-job this one shares the Django critical path with.+ # It gates every PR now, not just drafts, so its checkout speed is on the wall.+ runs-on: depot-ubuntu-24.04+ # Headroom over checkout + uv + the selector's whole-tree parse. A timeout here+ # leaves MODE empty, which on a ready PR means the full matrix — the worst case.+ timeout-minutes: 10outputs:mode: ${{ steps.classify.outputs.mode }}core_files: ${{ steps.classify.outputs.core_files }}poe_files: ${{ steps.classify.outputs.poe_files }}temporal_files: ${{ steps.classify.outputs.temporal_files }}+ compat_files: ${{ steps.classify.outputs.compat_files }}run_poe: ${{ steps.classify.outputs.run_poe }}run_temporal: ${{ steps.classify.outputs.run_temporal }}# Telemetry for the capture-test-selection job below.@@ -582,50 +591,71 @@ jobs:selected_test_count: ${{ steps.classify.outputs.selected_test_count }}full_run_reasons_count: ${{ steps.classify.outputs.full_run_reasons_count }}run_legacy: ${{ steps.fallback.outputs.run_legacy }}+ run_legacy_reason: ${{ steps.fallback.outputs.run_legacy_reason }}turbo_result: ${{ steps.fallback.outputs.turbo_result }}selected_test_seconds: ${{ steps.classify.outputs.selected_test_seconds }}skipped_test_seconds: ${{ steps.classify.outputs.skipped_test_seconds }}steps:- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2- with:- fetch-depth: 1000- filter: blob:none-- - name: Install uv- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0- with:- version: '0.11.28'-+ # Ahead of the checkout on purpose: this reads job outputs only, and when it+ # decides selection can't be trusted, cloning the repo would just delay the+ # full matrix that is about to run instead.- name: Decide whether selection can be trustedid: fallbackenv:RUN_LEGACY: ${{ needs.turbo-discover.outputs.run_legacy }}+ RUN_LEGACY_REASON: ${{ needs.turbo-discover.outputs.run_legacy_reason }}TURBO_RESULT: ${{ needs.turbo-discover.result }}+ DISABLED: ${{ vars.DISABLE_BACKEND_TEST_SELECTION || 'false' }}shell: bashrun: |set -euo pipefailskip=false- if [[ "$RUN_LEGACY" == "true" ]]; then- # turbo-discover detected product->legacy graph impact; the- # diff-based selector can't see this, so its subset would be- # incomplete. Skip the draft matrices; the ready run is full.+ reason=untrusted+ if [[ "$DISABLED" == "true" ]]; then+ # Kill switch — set the DISABLE_BACKEND_TEST_SELECTION repo variable to+ # put every PR back on the full matrices without a code change. Its own+ # reason string, so flipping it during an incident stays distinguishable+ # from a genuine cascade in the selection telemetry.+ skip=true+ reason=disabled+ elif [[ "$RUN_LEGACY" == "true" && "$RUN_LEGACY_REASON" != "legacy_changed" ]]; then+ # turbo-discover inferred legacy impact from a product, contract, or+ # schema change rather than seeing a direct edit. The diff-based selector+ # cannot see that cascade, so its subset would be incomplete.+ # A direct legacy edit is the selector's home turf and is deliberately not+ # untrusted here — the selector's own FULL_RUN_PATTERNS decide when a+ # legacy change is too broad to narrow.skip=trueelif [[ "$TURBO_RESULT" != "success" && "$TURBO_RESULT" != "skipped" ]]; then# Conservative — turbo-discover failed.skip=truefiecho "skip=$skip" >> "$GITHUB_OUTPUT"- # Surface the inputs behind an untrusted skip so the telemetry can- # tell legacy-graph impact apart from a turbo-discover failure.+ echo "reason=$reason" >> "$GITHUB_OUTPUT"+ # Surface the raw inputs too, so the telemetry can audit the decision.echo "run_legacy=${RUN_LEGACY:-}" >> "$GITHUB_OUTPUT"+ echo "run_legacy_reason=${RUN_LEGACY_REASON:-}" >> "$GITHUB_OUTPUT"echo "turbo_result=${TURBO_RESULT:-}" >> "$GITHUB_OUTPUT"+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ if: steps.fallback.outputs.skip == 'false'+ with:+ fetch-depth: 1000+ filter: blob:none++ - name: Install uv+ if: steps.fallback.outputs.skip == 'false'+ uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0+ with:+ version: '0.11.28'+- name: Run shadow selectorid: select# continue-on-error so a selector or git fetch failure doesn't fail this# job — a failed select-tests would leave MODE empty and build_django_matrix# would fall back to an expensive full matrix on a draft. Classify reads- # steps.select.outcome (pre-continue-on-error) and emits mode=skip instead.+ # steps.select.outcome (pre-continue-on-error) and emits the fallback mode+ # for this PR instead.continue-on-error: trueif: steps.fallback.outputs.skip == 'false'env:@@ -642,7 +672,15 @@ jobs:id: classifyenv:FALLBACK_SKIP: ${{ steps.fallback.outputs.skip }}+ FALLBACK_REASON: ${{ steps.fallback.outputs.reason }}SELECT_OUTCOME: ${{ steps.select.outcome }}+ # Guards the empty-selection backstop below. select-tests only runs on+ # pull_request, so the bare filter output is the whole story here.+ LEGACY_CHANGED: ${{ needs.changes.outputs.legacy }}+ # What an untrusted selection falls back to. A ready PR has no later+ # run to defer to, so it must run everything; a draft still skips and+ # leans on the ready run, which is the cheaper of the two mistakes.+ FALLBACK_MODE: ${{ github.event.pull_request.draft && 'skip' || 'full' }}shell: bashrun: |set -euo pipefail@@ -668,34 +706,35 @@ jobs:} >> "$GITHUB_OUTPUT"}- # Untrusted selection on a draft skips the heavy matrices (the- # pre-selection draft behavior); the ready-for-review run is full.- fall_back_to_skip() {- echo "mode=skip" >> "$GITHUB_OUTPUT"+ # Untrusted selection runs the full matrices on a ready PR and skips+ # them on a draft (the pre-selection draft behavior).+ fall_back() {+ echo "mode=$FALLBACK_MODE" >> "$GITHUB_OUTPUT"echo "core_files=" >> "$GITHUB_OUTPUT"echo "poe_files=" >> "$GITHUB_OUTPUT"echo "temporal_files=" >> "$GITHUB_OUTPUT"+ echo "compat_files=" >> "$GITHUB_OUTPUT"echo "run_poe=false" >> "$GITHUB_OUTPUT"echo "run_temporal=false" >> "$GITHUB_OUTPUT"emit_metrics false "$1"}if [[ "$FALLBACK_SKIP" == "true" ]]; then- fall_back_to_skip untrusted+ fall_back "${FALLBACK_REASON:-untrusted}"exit 0fiif [[ "$SELECT_OUTCOME" != "success" ]] || [[ ! -s /tmp/selection.json ]]; then- echo "::warning::shadow selector did not produce output; draft skips heavy matrices (full run happens on ready for review)"- fall_back_to_skip selector_error+ echo "::warning::shadow selector did not produce output; falling back to mode=$FALLBACK_MODE"+ fall_back selector_errorexit 0fifull_run_reasons=$(jq -r '.ast.full_run_reasons | length' /tmp/selection.json)if [[ "$full_run_reasons" -gt 0 ]]; then- echo "Selector requested a full run; draft defers it to ready for review:"+ echo "Selector requested a full run (mode=$FALLBACK_MODE):"jq -r '.ast.full_run_reasons[]' /tmp/selection.json- fall_back_to_skip full_run_requested+ fall_back full_run_requestedexit 0fi@@ -707,14 +746,26 @@ jobs:# posthog/api/test/dashboards/test_dashboard.py, ee/clickhouse/# Temporal: posthog/temporal, products/{batch_exports,tasks}/backend/temporal,# products/signals/backend/emission+ # Compat: CLICKHOUSE_COMPAT_PYTEST_TARGETS (posthog/clickhouse, ee/clickhouse)# Files outside posthog/ and ee/ (e.g. products/foo/backend/test_*) are not in this# matrix. turbo-tests handles them; warehouse_sources and managed_warehouse run# their own temporal suites there.core=()poe=()temporal=()+ compat=()while IFS= read -r f; do[[ -z "$f" ]] && continue+ # Compat overlaps the POE scope rather than partitioning with it, so+ # it is collected separately from the segment case below. Driven by the+ # same env var the compat pytest invocation uses, so widening one can't+ # silently under-select the other.+ for compat_target in $CLICKHOUSE_COMPAT_PYTEST_TARGETS; do+ if [[ "$f" == "${compat_target%/}/"* ]]; then+ compat+=("$f")+ break+ fi+ donecase "$f" inposthog/temporal/*|products/batch_exports/backend/tests/temporal/*|products/tasks/backend/temporal/*|products/signals/backend/emission/*)temporal+=("$f")@@ -732,15 +783,29 @@ jobs:esacdone < <(jq -r '.combined.tests[]?' /tmp/selection.json)+ # Backstop: a diff that touched legacy code but selected no Django test at+ # all means the selector had no rule for it, not that there is nothing to+ # run — a non-Python legacy file (C++ parser sources, a JSON config) reaches+ # no import edge. Narrowing to zero would silently gate on nothing, so treat+ # it as untrusted. FULL_RUN_PATTERNS covers the known cases; this catches the+ # ones that get added to the `legacy` paths filter and forgotten there.+ # Products-only diffs legitimately select nothing here and are not legacy.+ if [[ "$LEGACY_CHANGED" == "true" && ${#core[@]} -eq 0 && ${#temporal[@]} -eq 0 ]]; then+ echo "::warning::legacy files changed but no Django test was selected; falling back to mode=$FALLBACK_MODE"+ fall_back empty_selection+ exit 0+ fi+echo "mode=selected" >> "$GITHUB_OUTPUT"echo "core_files=${core[*]:-}" >> "$GITHUB_OUTPUT"echo "poe_files=${poe[*]:-}" >> "$GITHUB_OUTPUT"echo "temporal_files=${temporal[*]:-}" >> "$GITHUB_OUTPUT"+ echo "compat_files=${compat[*]:-}" >> "$GITHUB_OUTPUT"echo "run_poe=$([[ ${#poe[@]} -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"echo "run_temporal=$([[ ${#temporal[@]} -gt 0 ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"emit_metrics true ""- echo "Selected: ${#core[@]} core, ${#poe[@]} POE-eligible, ${#temporal[@]} temporal"+ echo "Selected: ${#core[@]} core, ${#poe[@]} POE-eligible, ${#temporal[@]} temporal, ${#compat[@]} compat"- name: Upload selection artifactif: always() && steps.select.outcome == 'success'@@ -2336,6 +2401,7 @@ jobs:RUN_POE: ${{ needs.select-tests.outputs.run_poe }}RUN_TEMPORAL: ${{ needs.select-tests.outputs.run_temporal }}CORE_FILES: ${{ needs.select-tests.outputs.core_files }}+ COMPAT_FILES: ${{ needs.select-tests.outputs.compat_files }}# A trunk-merge/** PR opens as a draft but is the merge gate, and# select-tests deliberately does not run for it. Reporting it as a# draft here would turn that empty MODE into "skip" and build an@@ -2353,8 +2419,8 @@ jobs:# :NOTE: Keep shard counts/group ranges in sync with historical Django matrix tuning.# Consult #team-devex before changing.- # A draft PR must never fall back to the full matrix. select-tests only- # runs on drafts and sets MODE to "skip"/"selected"; an empty MODE on a+ # A draft PR must never fall back to the full matrix. select-tests sets+ # MODE to "skip"/"full"/"selected"; an empty MODE on a# draft means it was cancelled or failed (typically ready_for_review# superseding it mid-flight). Without this, the draft builds the full# matrix and holds the per-branch concurrency slot for the whole run, so the@@ -2375,8 +2441,8 @@ jobs:fiif [[ "$MODE" == "selected" ]]; then- # Selected mode: collapse to one shard per active segment, skip- # segments with no selected files, drop compat entirely.+ # Selected mode: collapse to one shard per active segment and skip+ # segments with no selected files.core_count=0[[ -n "$CORE_FILES" ]] && core_count=1core=$(jq -cn --arg image "$OLDEST_SUPPORTED_IMAGE" --argjson n "$core_count" '@@ -2461,7 +2527,31 @@ jobs:compat: false}]')- compat="[]"+ # Compat covers the older supported ClickHouse versions over+ # CLICKHOUSE_COMPAT_PYTEST_TARGETS. Selection can drop it only when the+ # diff touches none of those paths — otherwise a narrowed run would+ # silently lose the one signal the full matrix has about old servers.+ # One unsharded entry per version, over the selected compat files.+ if [[ -n "$COMPAT_FILES" ]]; then+ compat=$(jq -cn --argjson compat "${COMPAT_MATRIX_JSON:-[]}" '+ [ $compat+ | map(."clickhouse-server-image") | unique | to_entries[]+ | {+ "clickhouse-server-image": .value,+ segment: "Core",+ "person-on-events": false,+ "new-events-schema": false,+ "python-version": "3.13.13",+ concurrency: 1,+ group: 1,+ compat: true,+ artifact_key: ("compat-" + ((.key + 1)|tostring))+ }+ ]+ ')+ else+ compat="[]"+ fielse# Full run: auto-shard counts from turbo-discover (Amdahl's law on .test_durations).# Falls back to hardcoded defaults if turbo-discover failed or data is missing.@@ -3038,9 +3128,13 @@ jobs:MODE: ${{ needs.select-tests.outputs.mode }}CORE_FILES: ${{ needs.select-tests.outputs.core_files }}POE_FILES: ${{ needs.select-tests.outputs.poe_files }}+ COMPAT_FILES: ${{ needs.select-tests.outputs.compat_files }}# devex: measure core (posthog/ee) coverage on PRs to size the gap vs products. sysmon = low overhead.COVERAGE_CORE: sysmon- COV_ARGS: ${{ github.event_name == 'pull_request' && '--cov=posthog --cov=ee --cov-config=.github/coverage-core.cfg --cov-report=xml:coverage-core.xml' || '' }}+ # backend-coverage-report skips narrowed runs (patch coverage would read+ # as false gaps), so instrumenting one just costs time and uploads an+ # artifact nothing reads.+ COV_ARGS: ${{ github.event_name == 'pull_request' && needs.select-tests.outputs.mode != 'selected' && '--cov=posthog --cov=ee --cov-config=.github/coverage-core.cfg --cov-report=xml:coverage-core.xml' || '' }}# Wrap bash with signal-fanout so the runner's cancel signal is# propagated to the entire process tree (incl. pytest). Without# this, GHA only signals the top-level bash and pytest survives@@ -3081,7 +3175,9 @@ jobs:# data with a partial run), and no --reruns (fail loud on the narrow subset).# The full run below also runs without --reruns: retries mask the raw flake# signal Trunk needs, and the quarantine gate is the flake net instead.- if [[ "${{ matrix.person-on-events }}" == "true" ]]; then+ if [[ "${{ matrix.compat }}" == "true" ]]; then+ targets="$COMPAT_FILES"+ elif [[ "${{ matrix.person-on-events }}" == "true" ]]; thentargets="$POE_FILES"elsetargets="$CORE_FILES"@@ -3129,7 +3225,7 @@ jobs:- name: Upload core coverageuses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0- if: ${{ always() && github.event_name == 'pull_request' && matrix.segment == 'Core' }}+ if: ${{ always() && github.event_name == 'pull_request' && needs.select-tests.outputs.mode != 'selected' && matrix.segment == 'Core' }}with:name: coverage-core-${{ strategy.job-index }}path: coverage-core.xml@@ -3820,7 +3916,7 @@ jobs:needs: [select-tests]runs-on: ubuntu-latesttimeout-minutes: 5- # select-tests only runs on internal draft PRs; fire only when it actually+ # select-tests only runs on internal PRs; fire only when it actually# produced a decision. DevEx project only, mirroring monitor-github-rate-limit;# continue-on-error so telemetry never reds CI. Skipped on forks/Dependabot,# which never have the secret (and where select-tests didn't run anyway).@@ -3846,6 +3942,7 @@ jobs:"selected_test_count": ${{ needs.select-tests.outputs.selected_test_count || 'null' }},"full_run_reasons_count": ${{ needs.select-tests.outputs.full_run_reasons_count || 'null' }},"run_legacy": ${{ toJSON(needs.select-tests.outputs.run_legacy || '') }},+ "run_legacy_reason": ${{ toJSON(needs.select-tests.outputs.run_legacy_reason || '') }},"turbo_result": ${{ toJSON(needs.select-tests.outputs.turbo_result || '') }},"selected_test_seconds": ${{ needs.select-tests.outputs.selected_test_seconds || 'null' }},"skipped_test_seconds": ${{ needs.select-tests.outputs.skipped_test_seconds || 'null' }},@@ -3925,7 +4022,7 @@ jobs:backend-coverage-report:name: Backend coverage report- needs: [turbo-tests, django_tests]+ needs: [turbo-tests, django_tests, select-tests]runs-on: ubuntu-latestcontinue-on-error: true # report-only, never block a PRtimeout-minutes: 10@@ -3937,7 +4034,8 @@ jobs:# In-repo PRs only — fork PRs get a read-only token that can't comment. Runs when either# the product (turbo-tests) or core (django_tests) suite ran, so a core-only PR still# gets a comment; both skip on drafts, leaving nothing to report.- # drafts run a partial test selection — patch coverage would report false gaps+ # A narrowed run measures only the selected tests, so patch coverage would report+ # gaps that the full suite covers. Report only when the Django matrix ran full.# Security invariant: this job runs PR-head-controlled scripts (coverage_report.py,# post-coverage-section.mjs) — never add secrets beyond github.token to this job# (report-test-timings checks out the base ref for exactly this reason).@@ -3945,6 +4043,7 @@ jobs:!cancelled() &&github.event_name == 'pull_request' &&github.event.pull_request.draft == false &&+ needs.select-tests.outputs.mode != 'selected' &&github.event.pull_request.head.repo.full_name == 'PostHog/posthog' &&(needs.turbo-tests.result != 'skipped' || needs.django_tests.result != 'skipped')steps:diff --git a/tools/snob_backend_test_selection_shadow.py b/tools/snob_backend_test_selection_shadow.pyindex 2c537f8b554d..d361489553a0 100755--- a/tools/snob_backend_test_selection_shadow.py+++ b/tools/snob_backend_test_selection_shadow.py@@ -20,10 +20,18 @@ precision reasonable (don't run everything on every PR):Validated against pytest-testmon runtime coverage data (PR #56370).The import graph alone covers ~33% of real test dependencies. The ASTheuristics close the URL-dispatch gap (~4%). Django-aware expansion closes-signals, middleware, and same-app fallback gaps (~12%). The remainder is-migration noise and framework-level indirection covered by FULL_RUN_PATTERNS.--Shadow mode: outputs JSON to stdout, does not affect CI pass/fail.+signals, middleware, and same-app fallback gaps (~12%). FULL_RUN_PATTERNS covers+the rest of the framework-level indirection.++Known gap: a migration reaches no test through the import graph and matches no+full-run pattern, so a migration-only diff narrows to whatever else changed. That+is deliberate for now, not an oversight — forcing a full run on every migration+would cover a failure mode we have not actually observed, at the cost of the+narrowing on a very common kind of PR.++Outputs JSON to stdout. The "shadow" in the filename is historical — ci-backend's+select-tests job now acts on this output, so a test this misses is a test that does not+run on the PR. Recall beats precision: when in doubt, add a FULL_RUN_PATTERNS entry."""from __future__ import annotations@@ -66,6 +74,9 @@ FULL_RUN_PATTERNS = ("pytest.ini","mypy.ini",".test_durations",+ # Un-quarantining must re-run the tests it un-skips, and the import graph can't+ # see that edge. turbo-discover.js documents this as a live invariant.+ ".test_quarantine.json",# CI / Docker infrastructure".github/workflows/ci-backend.yml",".github/clickhouse-versions.json",@@ -79,6 +90,12 @@ FULL_RUN_PATTERNS = ("frontend/public/email/","rust/feature-flags/src/properties/property_models.rs","common/plugin_transpiler/src",+ # C++ parser and HogQL VM: no Python import edge reaches them, but they change+ # what every HogQL query evaluates to.+ "common/hogql_parser/",+ "common/hogvm/",+ # Generates frontend/src/products.json, which is a full-run pattern in its own right.+ "manifest.tsx",)# Patterns that indicate "broad API tests needed" but not full suite.@@ -602,8 +619,9 @@ def segments_for_test_file(path: str) -> frozenset[str]:"""Which Django matrix segments run a given test file. Mirrors the Core/POE/Temporalpartition in ci-backend.yml's select-tests `classify` step — POE files run in both theCore matrix and the person-on-events matrix, so they belong to both segments. An empty- result means no draft-narrowable matrix runs the file (a product/turbo test, or an- explicitly ignored path)."""+ result means no narrowable matrix runs the file (a product/turbo test, or an explicitly+ ignored path). Compat is not a segment here: it re-runs POE-scope files against older+ ClickHouse servers, so it adds no files to the universe this partitions."""if path.startswith(_TEMPORAL_PREFIXES):return frozenset({"temporal"})if path.startswith(_CORE_IGNORED_PREFIXES):@@ -621,9 +639,9 @@ def segments_for_test_file(path: str) -> frozenset[str]:def narrowable_baseline_seconds(durations: dict[str, float]) -> float:- """Total test-execution seconds across the Core/POE/Temporal universe that draft+ """Total test-execution seconds across the Core/POE/Temporal universe thatselection can narrow. Excludes product/turbo tests, which run regardless of selection,- so this is the honest denominator for how much a draft skipped. This is raw pytest+ so this is the honest denominator for how much a run skipped. This is raw pytestexecution time from the sharding-balance file — it is not real CI minutes (no per-joboverhead, setup, or concurrency); the minutes model lives downstream in the dashboard."""total = 0.0diff --git a/tools/test_snob_backend_test_selection_shadow.py b/tools/test_snob_backend_test_selection_shadow.pyindex 7ba57e0c019a..b13297d2ceb8 100644--- a/tools/test_snob_backend_test_selection_shadow.py+++ b/tools/test_snob_backend_test_selection_shadow.py@@ -8,6 +8,8 @@ from types import ModuleTypeimport unittest+from parameterized import parameterized+SCRIPT_PATH = Path(__file__).with_name("snob_backend_test_selection_shadow.py")@@ -261,6 +263,24 @@ class TestSnobBackendTestSelectionShadow(unittest.TestCase):self.assertEqual([], result.full_run_reasons)self.assertEqual({"changed_tests": ["posthog/test/test_version_requirement.py"]}, result.groups)+ # ci-backend's `legacy` paths filter routes these into test selection, but none of+ # them is Python, so the import graph reaches no test through them. Without a full-run+ # pattern the selector returns an empty set and the narrowed run gates on nothing.+ @parameterized.expand(+ [+ ("quarantine_lift", ".test_quarantine.json"),+ ("hogql_parser_sources", "common/hogql_parser/HogQLParser.cpp"),+ ("hogvm", "common/hogvm/python/execute.py"),+ ("product_manifest", "products/surveys/manifest.tsx"),+ ]+ )+ def test_non_python_legacy_inputs_signal_full_run(self, _name: str, path: str) -> None:+ selection = _load_selection_module()++ result = selection.ast_select_tests([path], {})++ self.assertTrue(result.full_run_reasons, f"{path} selected nothing and forced no full run")+def test_segments_for_test_file_mirrors_matrix_partition(self) -> None:selection = _load_selection_module()