: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
perf(ci): bound script-tests checkout and fix the proto-tree guard (#86880)
posthog[bot]e9f989346bdc
diff --git a/.github/scripts/trunk-impacted-targets.test.js b/.github/scripts/trunk-impacted-targets.test.jsindex 1e1f9a3c793d..1174a3f3b162 100644--- a/.github/scripts/trunk-impacted-targets.test.js+++ b/.github/scripts/trunk-impacted-targets.test.js@@ -9,6 +9,7 @@const test = require('node:test')const assert = require('node:assert/strict')+const { execFileSync } = require('node:child_process')const fs = require('node:fs')const os = require('node:os')const path = require('node:path')@@ -871,6 +872,29 @@ test('nodejs is still the only workspace package importing a rust binding', () =}const packageDirs = workspaceGlobs.flatMap(expand)+ // An incomplete checkout (e.g. a sparse CI checkout missing workspace+ // manifests) would silently shrink the inspection set: expand() and the+ // existsSync checks below skip whatever is absent. The git index stays+ // complete even when the working tree is sparse, so any tracked manifest+ // inside the workspace that is not on disk means the checkout dropped it.+ const matcher = compileWorkspaceMatcher(workspaceGlobs)+ const trackedManifests = execFileSync('git', ['ls-files', '-z', '--', ':(glob)**/package.json', 'package.json'], {+ cwd: REPO_ROOT,+ encoding: 'utf8',+ })+ .split('\0')+ .filter(Boolean)+ assert.ok(trackedManifests.length > 0, 'git ls-files found no manifests, so the checkout check below is vacuous')+ for (const manifest of new Set(trackedManifests)) {+ if (manifest !== 'package.json' && !matcher(manifest)) {+ continue+ }+ assert.ok(+ fs.existsSync(path.join(REPO_ROOT, manifest)),+ `${manifest} is tracked by git but absent on disk — an incomplete checkout guts this guard`+ )+ }+const bindingPackages = new Set()for (const dir of packageDirs) {if (!dir.startsWith('rust/')) {diff --git a/.github/workflows/ci-scripts.yml b/.github/workflows/ci-scripts.ymlindex a8774eb4952c..f9ccba4366ff 100644--- a/.github/workflows/ci-scripts.yml+++ b/.github/workflows/ci-scripts.yml@@ -34,100 +34,65 @@ jobs:runs-on: ubuntu-latesttimeout-minutes: 5steps:+ # The tests take seconds, so a full checkout of the monorepo dominated+ # the job. Check out only the trees the suite reads: most tests are+ # pure logic over path strings, but a few read the real repo to guard+ # against drift — trunk-impacted-targets.test.js walks proto/, rust/,+ # nodejs/ and every workspace package.json (the unanchored pattern+ # pulls each manifest without its source tree), and+ # report_test_timings imports tools/owners and finds the root by+ # owners.yaml. A new test that reads another path must add it here.- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ fetch-depth: 1+ sparse-checkout: |+ /.github/+ /.depot/+ /tools/+ /proto/+ /rust/+ /nodejs/+ /posthog/personhog_client/+ /.semgrep/+ /frontend/bin/ci-report/+ /products/README.md+ /services/README.md+ /.nvmrc+ /owners.yaml+ /pnpm-workspace.yaml+ /uv.lock+ /tach.toml+ /pyproject.toml+ package.json+ sparse-checkout-cone-mode: false- name: Setup Node.jsuses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0with:node-version-file: .nvmrc- - name: Setup Python- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0- with:- python-version-file: pyproject.toml-- # defusedxml + opentelemetry + tools/owners are report_test_timings.py's script deps.+ # The preinstalled python3 runs these standalone tests, so no+ # setup-python step. defusedxml + opentelemetry + tools/owners are+ # report_test_timings.py's script deps.- name: Install pytest- run: python -m pip install --quiet pytest parameterized defusedxml==0.7.1 opentelemetry-sdk==1.33.1 opentelemetry-exporter-otlp-proto-http==1.33.1 ./tools/owners+ run: python3 -m pip install --quiet pytest parameterized defusedxml==0.7.1 opentelemetry-sdk==1.33.1 opentelemetry-exporter-otlp-proto-http==1.33.1 ./tools/owners# `-c /dev/null` skips the repo pytest.ini (its --reuse-db addopt needs# pytest-django, which we don't install here). `--noconftest` skips the# root conftest.py, whose autouse fixtures import the posthog package- # (and thus Django) — not installed in this lightweight job. These tests- # are standalone and need no conftest fixtures beyond pytest's tmp_path.- - name: Schema-usage scanner tests (Python)- run: python -m pytest .github/scripts/test_schema_usage_scan.py -v -c /dev/null -p no:cacheprovider --noconftest-- - name: Test-timings reporter tests (Python)- run: python -m pytest .github/scripts/test_report_test_timings.py -v -c /dev/null -p no:cacheprovider --noconftest-- - name: Durations optimizer tests (Python)- if: ${{ hashFiles('.github/scripts/test_optimize_test_durations.py') != '' }}- run: python -m pytest .github/scripts/test_optimize_test_durations.py -v -c /dev/null -p no:cacheprovider --noconftest-- # A wrong fingerprint is silent: the Jest bytecode cache either serves stale entries or- # never hits, and nothing goes red either way. hashFiles guard for unrebased PRs.- - name: Hog compiler fingerprint tests (Python)- if: ${{ hashFiles('.github/scripts/test_hog_compiler_fingerprint.py') != '' }}- run: python -m pytest .github/scripts/test_hog_compiler_fingerprint.py -v -c /dev/null -p no:cacheprovider --noconftest-- # hashFiles guard so an unrebased PR predating this script doesn't fail here.- - name: Workflow-run trace reporter tests (Python)- if: ${{ hashFiles('.github/scripts/test_report_workflow_run_traces.py') != '' }}- run: python -m pytest .github/scripts/test_report_workflow_run_traces.py -v -c /dev/null -p no:cacheprovider --noconftest-- # The Django test selector decides what ci-backend runs, and a wrong- # subset is silent: it reports green having skipped the test that would- # have failed. hashFiles guard for PRs that predate the selector tests.- - name: Backend test-selection tests (Python)- if: ${{ hashFiles('tools/test_snob_backend_test_selection_shadow.py') != '' }}- run: python -m pytest tools/test_snob_backend_test_selection_shadow.py tools/test_test_selection_verdict.py -v -c /dev/null -p no:cacheprovider --noconftest-- # Shells out to schema_usage_scan.py via python3 (preinstalled on ubuntu).- - name: Schema-impact tests (Node)- run: node --test .github/scripts/schema-impact.test.js-- - name: Master CI alerts tests (Node)- run: node --test .github/scripts/ci-alerts-devex.test.js-- - name: Rate-limit monitor tests (Node)- run: node --test .github/scripts/monitor-github-rate-limit.test.js-- - name: PR title labeler tests (Node)- run: node --test .github/scripts/label-pr-from-title.test.js-- - name: Auto-assign reviewers tests (Node)- run: node --test .github/scripts/assign-reviewers.test.js-- - name: CI report section tests (Node)- run: node --test .github/scripts/post-ci-sections.test.mjs-- - name: Weekly flaky report tests (Node)- if: ${{ hashFiles('.github/scripts/weekly-flaky-report.test.mjs') != '' }}- run: node --test .github/scripts/weekly-flaky-report.test.mjs-- - name: Weekly slow tests report tests (Node)- if: ${{ hashFiles('.github/scripts/weekly-slow-tests-report.test.mjs') != '' }}- run: node --test .github/scripts/weekly-slow-tests-report.test.mjs-- - name: CLI npm installer patch tests (Node)- if: ${{ hashFiles('.github/scripts/patch-cli-npm-installer.test.mjs') != '' }}- run: node --test .github/scripts/patch-cli-npm-installer.test.mjs-- - name: Turbo-discover dependent-cascade tests (Node)- run: node --test .github/scripts/turbo-discover-cascade.test.js-- # hashFiles guard so an unrebased PR predating these files doesn't fail here.- - name: Turbo-discover segment and staleness tests (Node)- if: ${{ hashFiles('.github/scripts/turbo-discover.test.js') != '' }}- run: node --test .github/scripts/turbo-discover.test.js .github/scripts/turbo-discover-staleness.test.js-- - name: Turbo-discover sizing tests (Node)- if: ${{ hashFiles('.github/scripts/turbo-discover-sizing.test.js') != '' }}- run: node --test .github/scripts/turbo-discover-sizing.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.js+ # (and thus Django) — not installed in this lightweight job. The tools/+ # files stay explicit: a tools glob would double-run the dagster and+ # playwright selection tests (they run in ci-dagster and+ # ci-e2e-playwright) and collect test_selection_verdict.py, which is+ # the script under test, not a test.+ - name: Python script tests+ run: |+ python3 -m pytest -v -c /dev/null -p no:cacheprovider --noconftest \+ .github/scripts/test_*.py \+ tools/test_snob_backend_test_selection_shadow.py \+ tools/test_test_selection_verdict.py++ # schema-impact.test.js shells out to schema_usage_scan.py via the same+ # preinstalled python3.+ - name: Node script tests+ run: node --test .github/scripts/*.test.js .github/scripts/*.test.mjsdiff --git a/tools/test_snob_backend_test_selection_shadow.py b/tools/test_snob_backend_test_selection_shadow.pyindex d92148397029..db13b0a7dad6 100644--- a/tools/test_snob_backend_test_selection_shadow.py+++ b/tools/test_snob_backend_test_selection_shadow.py@@ -81,30 +81,37 @@ class TestSnobBackendTestSelectionShadow(unittest.TestCase):self.assertEqual(["products/feature_flags/backend/test/test_api.py"], result.tests)def test_ast_selection_matches_posthog_api_test_by_filename(self) -> None:- selection = _load_selection_module()+ with tempfile.TemporaryDirectory() as root:+ tmp_path = Path(root)+ selection = _load_selection_module()+ selection.REPO_ROOT = tmp_path- result = selection.ast_select_tests(- ["posthog/api/project.py"],- {- "posthog/api/test/test_project.py": selection.TestFeatures(- path="posthog/api/test/test_project.py",- imports_api_client=True,- api_tokens=("project",),- ),- "posthog/api/test/test_user.py": selection.TestFeatures(- path="posthog/api/test/test_user.py",- imports_api_client=True,- api_tokens=("user",),- ),- },- )+ neighbor = tmp_path / "posthog" / "api" / "test" / "test_project.py"+ neighbor.parent.mkdir(parents=True)+ neighbor.touch()- self.assertIn("conventional_neighbors", result.groups)- self.assertIn("posthog_api_route_tokens", result.groups)- # same-app fallback includes all tests under posthog/api/- self.assertIn("same_app:posthog/api", result.groups)- self.assertIn("posthog/api/test/test_project.py", result.tests)- self.assertIn("posthog/api/test/test_user.py", result.tests)+ result = selection.ast_select_tests(+ ["posthog/api/project.py"],+ {+ "posthog/api/test/test_project.py": selection.TestFeatures(+ path="posthog/api/test/test_project.py",+ imports_api_client=True,+ api_tokens=("project",),+ ),+ "posthog/api/test/test_user.py": selection.TestFeatures(+ path="posthog/api/test/test_user.py",+ imports_api_client=True,+ api_tokens=("user",),+ ),+ },+ )++ self.assertIn("conventional_neighbors", result.groups)+ self.assertIn("posthog_api_route_tokens", result.groups)+ # same-app fallback includes all tests under posthog/api/+ self.assertIn("same_app:posthog/api", result.groups)+ self.assertIn("posthog/api/test/test_project.py", result.tests)+ self.assertIn("posthog/api/test/test_user.py", result.tests)def test_snob_selection_filters_to_python_files(self) -> None:selection = _load_selection_module()