: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): shard narrowed Django runs by their selected work (#86223)
Julian Bezc5f4db3c0a00
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 6f43f3e27d40..fde79144d845 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -670,6 +670,8 @@ jobs:full_run_reasons_count: ${{ steps.classify.outputs.full_run_reasons_count }}selected_test_seconds: ${{ steps.classify.outputs.selected_test_seconds }}skipped_test_seconds: ${{ steps.classify.outputs.skipped_test_seconds }}+ # Shards per segment for a narrowed run; build_django_matrix reads them as-is.+ segment_shards: ${{ steps.classify.outputs.segment_shards }}run_legacy: ${{ steps.fallback.outputs.run_legacy }}run_legacy_reason: ${{ steps.fallback.outputs.run_legacy_reason }}turbo_result: ${{ steps.fallback.outputs.turbo_result }}@@ -881,6 +883,9 @@ jobs: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"+ # Shards per narrowed segment: turbo-discover's per-shard budget applied+ # to the selected tests' recorded seconds. Degrades to 1 per segment.+ echo "segment_shards=$(node .github/scripts/selected-django-shards.js /tmp/selection.json)" >> "$GITHUB_OUTPUT"emit_metrics true ""echo "Selected: ${#core[@]} core, ${#poe[@]} POE-eligible, ${#temporal[@]} temporal, ${#compat[@]} compat"@@ -1536,6 +1541,7 @@ jobs:RUN_TEMPORAL: ${{ needs.select-tests.outputs.run_temporal }}CORE_FILES: ${{ needs.select-tests.outputs.core_files }}COMPAT_FILES: ${{ needs.select-tests.outputs.compat_files }}+ SEGMENT_SHARDS: ${{ needs.select-tests.outputs.segment_shards }}# 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@@ -1568,10 +1574,17 @@ jobs:exit 0fiif [[ "$MODE" == "selected" ]]; then- # Selected mode: collapse to one shard per active segment and skip- # segments with no selected files.+ # Selected mode: run only the segments that have selected files. Shard+ # counts come from select-tests, where selected-django-shards.js applied+ # turbo-discover's per-shard budget to the selected tests' recorded+ # seconds. A wide selection therefore spreads over several jobs instead+ # of running to the job timeout in one. No counts means one shard per+ # segment.+ segment_shards="${SEGMENT_SHARDS:-}"+ [[ -z "$segment_shards" ]] && segment_shards='{"core": 1, "poe": 1, "temporal": 1}'+core_count=0- [[ -n "$CORE_FILES" ]] && core_count=1+ [[ -n "$CORE_FILES" ]] && core_count=$(jq -r '.core' <<< "$segment_shards")core=$(jq -cn --arg image "$OLDEST_SUPPORTED_IMAGE" --argjson n "$core_count" '[range(1; $n + 1) | {segment: "Core",@@ -1579,9 +1592,9 @@ jobs:"new-events-schema": false,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "core-1",+ concurrency: $n,+ group: .,+ artifact_key: ("core-" + (.|tostring)),compat: false}]')@@ -1592,14 +1605,14 @@ jobs:"new-events-schema": true,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "core-events-json-1",+ concurrency: $n,+ group: .,+ artifact_key: ("core-events-json-" + (.|tostring)),compat: false}]')poe_count=0- [[ "$RUN_POE" == "true" ]] && poe_count=1+ [[ "$RUN_POE" == "true" ]] && poe_count=$(jq -r '.poe' <<< "$segment_shards")core_persons_on_events=$(jq -cn --arg image "$OLDEST_SUPPORTED_IMAGE" --argjson n "$poe_count" '[range(1; $n + 1) | {segment: "Core",@@ -1607,9 +1620,9 @@ jobs:"new-events-schema": false,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "core-poe-1",+ concurrency: $n,+ group: .,+ artifact_key: ("core-poe-" + (.|tostring)),compat: false}]')@@ -1620,14 +1633,14 @@ jobs:"new-events-schema": true,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "core-poe-events-json-1",+ concurrency: $n,+ group: .,+ artifact_key: ("core-poe-events-json-" + (.|tostring)),compat: false}]')temporal_count=0- [[ "$RUN_TEMPORAL" == "true" ]] && temporal_count=1+ [[ "$RUN_TEMPORAL" == "true" ]] && temporal_count=$(jq -r '.temporal' <<< "$segment_shards")temporal=$(jq -cn --arg image "$OLDEST_SUPPORTED_IMAGE" --argjson n "$temporal_count" '[range(1; $n + 1) | {segment: "Temporal",@@ -1635,9 +1648,9 @@ jobs:"new-events-schema": false,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "temporal-1",+ concurrency: $n,+ group: .,+ artifact_key: ("temporal-" + (.|tostring)),compat: false}]')@@ -1648,9 +1661,9 @@ jobs:"new-events-schema": true,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "temporal-events-json-1",+ concurrency: $n,+ group: .,+ artifact_key: ("temporal-events-json-" + (.|tostring)),compat: false}]')@@ -2167,7 +2180,8 @@ jobs:fiif [[ "$MODE" == "selected" ]]; then# Selected mode: run only the test files chosen by the snob shadow selector.- # No --splits/--group (no sharding), and no --reruns anywhere, mirroring+ # Sharded only when build_django_matrix sized the segment above one+ # shard, and no --reruns anywhere, mirroring# canonical: retries mask the raw flake signal Trunk needs (the shadow# strips the quarantine gate itself).if [[ "${{ matrix.compat }}" == "true" ]]; then@@ -2177,8 +2191,18 @@ jobs:elsetargets="$CORE_FILES"fi+ # A selection wide enough to need more than one shard is split like a+ # full run. Item granularity on purpose: the target list is already+ # narrow, so pre-import file skipping saves nothing, and the per-segment+ # plan file describes a different run-set than the selected subset.+ SELECTED_SPLIT=()+ if [[ "${{ matrix.concurrency }}" -gt 1 ]]; then+ SELECTED_SPLIT=(--splits "${{ matrix.concurrency }}" --group "${{ matrix.group }}"+ --splitting-algorithm="$SPLITTING_ALGORITHM")+ fi# shellcheck disable=SC2086pytest -v --tb=short --reuse-db -o junit_duration_report=call $targets -m "not async_migrations" \+ "${SELECTED_SPLIT[@]}" \-r fEsxX \--junitxml=junit-core.xml \$COV_ARGS \@@ -2270,10 +2294,20 @@ jobs:# two timeout tests fail downstream (hogql_table never reached). Canonical GHA still runs them.# The --deselect guards stay on both branches so a selected run can't re-enable them.if [[ "$MODE" == "selected" ]]; then- # Selected mode: no sharding, no --reruns — see the core selected branch;+ # Selected mode: no --reruns — see the core selected branch;# the full run also skips --reruns, mirroring canonical.+ # A selection wide enough to need more than one shard is split like a+ # full run. Item granularity on purpose: the target list is already+ # narrow, so pre-import file skipping saves nothing, and the per-segment+ # plan file describes a different run-set than the selected subset.+ SELECTED_SPLIT=()+ if [[ "${{ matrix.concurrency }}" -gt 1 ]]; then+ SELECTED_SPLIT=(--splits "${{ matrix.concurrency }}" --group "${{ matrix.group }}"+ --splitting-algorithm="$SPLITTING_ALGORITHM")+ fi# shellcheck disable=SC2086pytest -v --tb=short --reuse-db -o junit_duration_report=call $TEMPORAL_FILES -m "not async_migrations" \+ "${SELECTED_SPLIT[@]}" \--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_with_minio_bucket" \--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_timeout_does_not_pause_schedule_without_consecutive_failures" \--deselect "posthog/temporal/tests/data_modeling/test_run_workflow.py::test_run_workflow_timeout_pauses_schedule_after_5_consecutive_failures" \diff --git a/.github/scripts/selected-django-shards.js b/.github/scripts/selected-django-shards.jsnew file mode 100644index 000000000000..2db6f7b49d45--- /dev/null+++ b/.github/scripts/selected-django-shards.js@@ -0,0 +1,44 @@+// Sizes the Django shards of a narrowed (test-selection) run in ci-backend.yml.+//+// Reads the shadow selector's JSON and applies turbo-discover's calculateShards+// to the selected tests' recorded seconds, so a narrowed segment gets the same+// per-shard budget as the full matrix — target wall clock, per-segment overhead,+// safety factor and cap all stay defined in turbo-discover.js. Sizing from the+// selection's own recorded seconds also keeps a skewed selection honest: picking+// the heavy half of a segment costs more shards than picking the light half.+//+// The floor is 1 instead of DJANGO_MIN_SHARDS: a narrow selection should stay a+// single job. Anything missing or unreadable degrades to 1 shard per segment,+// which is what the matrix assumed for every narrowed run before this existed.+//+// Usage: node selected-django-shards.js /tmp/selection.json+// Prints e.g. {"core":1,"poe":1,"temporal":6}++const fs = require('fs')+const path = require('path')+const { calculateShards, DJANGO_OVERHEAD_SECONDS_BY_SEGMENT } = require(path.join(__dirname, 'turbo-discover.js'))++// Selector segment key -> Django matrix segment name.+const MATRIX_NAME_BY_SEGMENT = { core: 'Core', poe: 'CorePOE', temporal: 'Temporal' }++function selectedShards(selection) {+ const seconds = selection?.durations?.selected_seconds_by_segment ?? {}+ const shards = {}+ for (const [segment, matrixName] of Object.entries(MATRIX_NAME_BY_SEGMENT)) {+ const overhead = DJANGO_OVERHEAD_SECONDS_BY_SEGMENT[matrixName]+ shards[segment] = calculateShards(Number(seconds[segment]) || 0, overhead, 1)+ }+ return shards+}++module.exports = { selectedShards }++if (require.main === module) {+ let selection = {}+ try {+ selection = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'))+ } catch {+ // Fall through to the 1-shard-per-segment default.+ }+ process.stdout.write(JSON.stringify(selectedShards(selection)))+}diff --git a/.github/scripts/selected-django-shards.test.js b/.github/scripts/selected-django-shards.test.jsnew file mode 100644index 000000000000..3c7e8567dae4--- /dev/null+++ b/.github/scripts/selected-django-shards.test.js@@ -0,0 +1,35 @@+const { test } = require('node:test')+const assert = require('node:assert')+const { execFileSync } = require('node:child_process')+const path = require('path')++const { selectedShards } = require('./selected-django-shards.js')++test('applies the full-matrix budget to the selected seconds of each segment', () => {+ // Core: ceil(5000 * 1.3 / (1200 - 240)) = 7. Temporal has the larger overhead:+ // ceil(900 * 1.3 / (1200 - 360)) = 2. POE floors at 1 despite nothing selected.+ const selection = { durations: { selected_seconds_by_segment: { core: 5000, poe: 0, temporal: 900 } } }+ assert.deepStrictEqual(selectedShards(selection), { core: 7, poe: 1, temporal: 2 })+})++test('floors at one shard, below the full-run minimum of three', () => {+ const selection = { durations: { selected_seconds_by_segment: { core: 30, poe: 30, temporal: 30 } } }+ assert.deepStrictEqual(selectedShards(selection), { core: 1, poe: 1, temporal: 1 })+})++test('caps at the full-run maximum', () => {+ const selection = { durations: { selected_seconds_by_segment: { core: 10_000_000 } } }+ assert.strictEqual(selectedShards(selection).core, 50)+})++test('degrades to one shard per segment on missing or malformed selector output', () => {+ for (const selection of [{}, { durations: {} }, { durations: { selected_seconds_by_segment: { core: 'wat' } } }]) {+ assert.deepStrictEqual(selectedShards(selection), { core: 1, poe: 1, temporal: 1 })+ }+})++test('the CLI prints the one-shard default when the selection file is unreadable', () => {+ const script = path.join(__dirname, 'selected-django-shards.js')+ const stdout = execFileSync('node', [script, '/nonexistent/selection.json'], { encoding: 'utf8' })+ assert.deepStrictEqual(JSON.parse(stdout), { core: 1, poe: 1, temporal: 1 })+})diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.jsindex ca332df4d95f..5d72834314b7 100644--- a/.github/scripts/turbo-discover.js+++ b/.github/scripts/turbo-discover.js@@ -566,11 +566,13 @@ function getSegmentDuration(segment, durations) {// Fallback shard counts used when .test_durations is missing.const DJANGO_FALLBACK_SHARDS = { Core: 38, CorePOE: 7, Temporal: 7 }-function calculateShards(totalWorkSeconds, overheadSeconds) {+// minShards: full runs keep the DJANGO_MIN_SHARDS floor, but a narrowed+// (test-selection) run may legitimately fit one shard.+function calculateShards(totalWorkSeconds, overheadSeconds, minShards = DJANGO_MIN_SHARDS) {const testBudget = DJANGO_TARGET_WALL_SECONDS - overheadSecondsif (testBudget <= 0) {return DJANGO_MAX_SHARDS}const shards = Math.ceil((totalWorkSeconds * DJANGO_SAFETY_FACTOR) / testBudget)- return Math.max(DJANGO_MIN_SHARDS, Math.min(DJANGO_MAX_SHARDS, shards))+ return Math.max(minShards, Math.min(DJANGO_MAX_SHARDS, shards))}function buildDjangoShards(durations) {@@ -667,8 +669,11 @@ function buildMatrix(products, durations) {return matrix}-// Exported for unit tests only — not part of the public API.+// Exported for unit tests, plus the Django sizing pieces that+// selected-django-shards.js reuses so narrowed runs share one budget.module.exports = {+ calculateShards,+ DJANGO_OVERHEAD_SECONDS_BY_SEGMENT,collectTestFiles,checkProductStaleness,productPrefix,diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 62a956502ad4..14613318412e 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -606,6 +606,8 @@ jobs: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 }}+ # Shards per segment for a narrowed run; build_django_matrix reads them as-is.+ segment_shards: ${{ steps.classify.outputs.segment_shards }}steps:# 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@@ -814,6 +816,9 @@ jobs: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"+ # Shards per narrowed segment: turbo-discover's per-shard budget applied+ # to the selected tests' recorded seconds. Degrades to 1 per segment.+ echo "segment_shards=$(node .github/scripts/selected-django-shards.js /tmp/selection.json)" >> "$GITHUB_OUTPUT"emit_metrics true ""echo "Selected: ${#core[@]} core, ${#poe[@]} POE-eligible, ${#temporal[@]} temporal, ${#compat[@]} compat"@@ -2418,6 +2423,7 @@ jobs:RUN_TEMPORAL: ${{ needs.select-tests.outputs.run_temporal }}CORE_FILES: ${{ needs.select-tests.outputs.core_files }}COMPAT_FILES: ${{ needs.select-tests.outputs.compat_files }}+ SEGMENT_SHARDS: ${{ needs.select-tests.outputs.segment_shards }}# 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@@ -2457,10 +2463,17 @@ jobs:fiif [[ "$MODE" == "selected" ]]; then- # Selected mode: collapse to one shard per active segment and skip- # segments with no selected files.+ # Selected mode: run only the segments that have selected files. Shard+ # counts come from select-tests, where selected-django-shards.js applied+ # turbo-discover's per-shard budget to the selected tests' recorded+ # seconds. A wide selection therefore spreads over several jobs instead+ # of running to the job timeout in one. No counts means one shard per+ # segment.+ segment_shards="${SEGMENT_SHARDS:-}"+ [[ -z "$segment_shards" ]] && segment_shards='{"core": 1, "poe": 1, "temporal": 1}'+core_count=0- [[ -n "$CORE_FILES" ]] && core_count=1+ [[ -n "$CORE_FILES" ]] && core_count=$(jq -r '.core' <<< "$segment_shards")core=$(jq -cn --arg image "$OLDEST_SUPPORTED_IMAGE" --argjson n "$core_count" '[range(1; $n + 1) | {segment: "Core",@@ -2468,9 +2481,9 @@ jobs:"new-events-schema": false,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "core-1",+ concurrency: $n,+ group: .,+ artifact_key: ("core-" + (.|tostring)),compat: false}]')@@ -2481,14 +2494,14 @@ jobs:"new-events-schema": true,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "core-events-json-1",+ concurrency: $n,+ group: .,+ artifact_key: ("core-events-json-" + (.|tostring)),compat: false}]')poe_count=0- [[ "$RUN_POE" == "true" ]] && poe_count=1+ [[ "$RUN_POE" == "true" ]] && poe_count=$(jq -r '.poe' <<< "$segment_shards")core_persons_on_events=$(jq -cn --arg image "$OLDEST_SUPPORTED_IMAGE" --argjson n "$poe_count" '[range(1; $n + 1) | {segment: "Core",@@ -2496,9 +2509,9 @@ jobs:"new-events-schema": false,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "core-poe-1",+ concurrency: $n,+ group: .,+ artifact_key: ("core-poe-" + (.|tostring)),compat: false}]')@@ -2509,14 +2522,14 @@ jobs:"new-events-schema": true,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "core-poe-events-json-1",+ concurrency: $n,+ group: .,+ artifact_key: ("core-poe-events-json-" + (.|tostring)),compat: false}]')temporal_count=0- [[ "$RUN_TEMPORAL" == "true" ]] && temporal_count=1+ [[ "$RUN_TEMPORAL" == "true" ]] && temporal_count=$(jq -r '.temporal' <<< "$segment_shards")temporal=$(jq -cn --arg image "$OLDEST_SUPPORTED_IMAGE" --argjson n "$temporal_count" '[range(1; $n + 1) | {segment: "Temporal",@@ -2524,9 +2537,9 @@ jobs:"new-events-schema": false,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "temporal-1",+ concurrency: $n,+ group: .,+ artifact_key: ("temporal-" + (.|tostring)),compat: false}]')@@ -2537,9 +2550,9 @@ jobs:"new-events-schema": true,"python-version": "3.13.13","clickhouse-server-image": $image,- concurrency: 1,- group: 1,- artifact_key: "temporal-events-json-1",+ concurrency: $n,+ group: .,+ artifact_key: ("temporal-events-json-" + (.|tostring)),compat: false}]')@@ -3192,8 +3205,9 @@ jobs:fiif [[ "$MODE" == "selected" ]]; then# Selected mode: run only the test files chosen by the snob shadow selector.- # No --splits/--group (no sharding), no --store-durations (don't pollute timing- # data with a partial run), and no --reruns (fail loud on the narrow subset).+ # Sharded only when build_django_matrix sized the segment above one shard,+ # no --store-durations (don't pollute timing 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.compat }}" == "true" ]]; then@@ -3203,8 +3217,18 @@ jobs:elsetargets="$CORE_FILES"fi+ # A selection wide enough to need more than one shard is split like a+ # full run. Item granularity on purpose: the target list is already+ # narrow, so pre-import file skipping saves nothing, and the per-segment+ # plan file describes a different run-set than the selected subset.+ SELECTED_SPLIT=()+ if [[ "${{ matrix.concurrency }}" -gt 1 ]]; then+ SELECTED_SPLIT=(--splits "${{ matrix.concurrency }}" --group "${{ matrix.group }}"+ --splitting-algorithm="$SPLITTING_ALGORITHM")+ fi# shellcheck disable=SC2086pytest -v --tb=short --reuse-db -o junit_duration_report=call $targets -m "not async_migrations" \+ "${SELECTED_SPLIT[@]}" \-r fEsxX \--junitxml=junit-core.xml \$COV_ARGS \@@ -3320,11 +3344,21 @@ jobs:fifiif [[ "$MODE" == "selected" ]]; then- # Selected mode: no sharding, no --store-durations (don't pollute- # timing data with a partial run), no --reruns. See the core selected branch;- # the full run also skips --reruns so raw flake signal reaches Trunk.+ # Selected mode: no --store-durations (don't pollute timing data with a+ # partial run), no --reruns. See the core selected branch; the full run+ # also skips --reruns so raw flake signal reaches Trunk.+ # A selection wide enough to need more than one shard is split like a+ # full run. Item granularity on purpose: the target list is already+ # narrow, so pre-import file skipping saves nothing, and the per-segment+ # plan file describes a different run-set than the selected subset.+ SELECTED_SPLIT=()+ if [[ "${{ matrix.concurrency }}" -gt 1 ]]; then+ SELECTED_SPLIT=(--splits "${{ matrix.concurrency }}" --group "${{ matrix.group }}"+ --splitting-algorithm="$SPLITTING_ALGORITHM")+ fi# shellcheck disable=SC2086pytest -v --tb=short --reuse-db -o junit_duration_report=call $TEMPORAL_FILES -m "not async_migrations" \+ "${SELECTED_SPLIT[@]}" \-r fEsxX \--junitxml=junit-temporal.xml \$PYTEST_ARGSdiff --git a/.github/workflows/ci-scripts.yml b/.github/workflows/ci-scripts.ymlindex 19bda093d40f..1c140ad0cb95 100644--- a/.github/workflows/ci-scripts.yml+++ b/.github/workflows/ci-scripts.yml@@ -80,5 +80,8 @@ jobs:- name: Turbo-discover dependent-cascade tests (Node)run: node --test .github/scripts/turbo-discover-cascade.test.js+ - name: Selected Django shards tests (Node)+ run: node --test .github/scripts/selected-django-shards.test.js+- name: Trunk impacted-targets tests (Node)run: node --test .github/scripts/trunk-impacted-targets.test.jsdiff --git a/tools/snob_backend_test_selection_shadow.py b/tools/snob_backend_test_selection_shadow.pyindex 8237a400ca34..19d1c4f95e63 100755--- a/tools/snob_backend_test_selection_shadow.py+++ b/tools/snob_backend_test_selection_shadow.py@@ -638,6 +638,18 @@ def segments_for_test_file(path: str) -> frozenset[str]:return frozenset()+def selected_seconds_by_segment(test_files: list[str], durations: dict[str, float]) -> dict[str, int]:+ """Selected test-execution seconds per Django matrix segment.+ .github/scripts/selected-django-shards.js runs these through turbo-discover's shard+ sizing, so a narrowed run gets the same per-shard budget as a full one instead of a+ fixed single shard. POE files count in both core and poe, matching the two matrix+ legs that run them."""+ return {+ segment: round(estimate_duration([f for f in test_files if segment in segments_for_test_file(f)], durations))+ for segment in ("core", "poe", "temporal")+ }++def narrowable_baseline_seconds(durations: dict[str, float]) -> float:"""Total test-execution seconds across the Core/POE/Temporal universe thatselection can narrow. Excludes product/turbo tests, which run regardless of selection,@@ -685,6 +697,7 @@ def build_result(base_ref: str) -> dict[str, object]:"narrowable_baseline_seconds": round(baseline_seconds),"selected_seconds": round(selected_seconds),"skipped_seconds": round(max(baseline_seconds - selected_seconds, 0.0)),+ "selected_seconds_by_segment": selected_seconds_by_segment(combined_tests, durations),},}diff --git a/tools/test_snob_backend_test_selection_shadow.py b/tools/test_snob_backend_test_selection_shadow.pyindex b13297d2ceb8..91ba9c3b2bf7 100644--- a/tools/test_snob_backend_test_selection_shadow.py+++ b/tools/test_snob_backend_test_selection_shadow.py@@ -308,6 +308,33 @@ class TestSnobBackendTestSelectionShadow(unittest.TestCase):# path are excluded, so a draft can never be credited with skipping them.self.assertEqual(selection.narrowable_baseline_seconds(durations), 380.0)+ def test_selected_seconds_by_segment_splits_the_matrix_legs(self) -> None:+ selection = _load_selection_module()++ durations = {+ "posthog/models/test_a.py::t1": 100.0,+ "posthog/clickhouse/test_b.py::t2": 70.0,+ "posthog/temporal/tests/test_c.py::t3": 210.0,+ "posthog/models/test_unselected.py::t4": 5_000.0,+ "products/warehouse_sources/backend/test_d.py::t5": 100_000.0,+ "posthog/dags/test_e.py::t6": 42.0,+ }+ selected = [+ "posthog/models/test_a.py",+ "posthog/clickhouse/test_b.py",+ "posthog/temporal/tests/test_c.py",+ "products/warehouse_sources/backend/test_d.py",+ "posthog/dags/test_e.py",+ ]++ # The clickhouse file runs in both the Core and the person-on-events leg, so its+ # seconds count once per leg. Turbo product tests and ignored paths size no Django+ # shard, and an unselected file never contributes.+ self.assertEqual(+ selection.selected_seconds_by_segment(selected, durations),+ {"core": 170, "poe": 70, "temporal": 210},+ )+if __name__ == "__main__":unittest.main()