: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): upload remaining test suites to Trunk for flaky-test detection (#68973)
Paul D'Ambrac05437fb91ec
diff --git a/.github/workflows/ci-ai.yml b/.github/workflows/ci-ai.ymlindex e1b06bc511a1..8c7cf23700d0 100644--- a/.github/workflows/ci-ai.yml+++ b/.github/workflows/ci-ai.yml@@ -7,6 +7,9 @@ concurrency:group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}cancel-in-progress: true # We only want one AI CI run per PR concurrently+env:+ RUNS_ON_INTERNAL_PR: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }}+jobs:eval:timeout-minutes: 45@@ -197,3 +200,15 @@ jobs:with:name: junit-results-ai-evalspath: eval-artifacts/*/junit.xml++ # Upload results to Trunk for flaky-test detection. Non-gating (continue-on-error),+ # so a Trunk outage never fails the job. Runs the token only on internal PRs,+ # master, and the merge queue — never on fork PRs or Dependabot, which have no secret.+ - name: Upload test results to Trunk+ if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: eval-artifacts/*/junit.xml+ org-slug: posthog-inc+ token: ${{ secrets.TRUNK_API_TOKEN }}diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex 390865c0a26c..687ab8be3eba 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -800,14 +800,29 @@ jobs:# ClickHouse drop/create race conditions with ReplicatedMergeTree ZK metadata.# --durations-path: turbo runs products from products/<name>/, so pytest-split# needs an explicit path back to the repo-root durations file for balanced sharding.+ # --junitxml: written relative to each product's dir (turbo's cwd), so every+ # product in the group gets its own products/<name>/junit-product.xml.# On master, also collect timing data for pytest-split sharding.PYTEST_ADDOPTS: >---reuse-db--durations-path ../../.test_durations+ --junitxml=junit-product.xml${{ needs.detect-snapshot-mode.outputs.mode == 'update' && '--snapshot-update --snapshot-warn-unused' || '' }}${{ github.ref == 'refs/heads/master' && '--store-durations' || '' }}run: pnpm turbo run backend:test ${{ matrix.filters }} --concurrency=1 --output-logs=full --force --log-order=stream ${{ matrix.pytest_args }}+ # Upload results to Trunk for flaky-test detection. Non-gating (continue-on-error),+ # so a Trunk outage never fails the job. Runs the token only on internal PRs,+ # master, and the merge queue — never on fork PRs or Dependabot, which have no secret.+ - name: Upload test results to Trunk+ if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: products/*/junit-product.xml+ org-slug: posthog-inc+ token: ${{ secrets.TRUNK_API_TOKEN }}+- name: Upload timing datauses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0if: ${{ github.ref == 'refs/heads/master' }}diff --git a/.github/workflows/ci-dagster.yml b/.github/workflows/ci-dagster.ymlindex acb0f715198e..37d3fc6a5e82 100644--- a/.github/workflows/ci-dagster.yml+++ b/.github/workflows/ci-dagster.yml@@ -421,6 +421,18 @@ jobs:name: junit-results-dagster-${{ matrix.group }}path: junit-*.xml+ # Upload results to Trunk for flaky-test detection. Non-gating (continue-on-error),+ # so a Trunk outage never fails the job. Runs the token only on internal PRs,+ # master, and the merge queue — never on fork PRs or Dependabot, which have no secret.+ - name: Upload test results to Trunk+ if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-dagster-${{ matrix.group }}.xml+ org-slug: posthog-inc+ token: ${{ secrets.TRUNK_API_TOKEN }}+- name: Upload updated timing data as artifactsuses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0if: ${{ github.ref == 'refs/heads/master' && always() }}diff --git a/.github/workflows/ci-llm-gateway.yml b/.github/workflows/ci-llm-gateway.ymlindex 46b7943a95ee..b2363ecd2234 100644--- a/.github/workflows/ci-llm-gateway.yml+++ b/.github/workflows/ci-llm-gateway.yml@@ -23,6 +23,9 @@ permissions:contents: readpull-requests: read+env:+ RUNS_ON_INTERNAL_PR: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }}+jobs:changes:runs-on: ubuntu-latest@@ -94,6 +97,18 @@ jobs:name: junit-results-llm-gatewaypath: services/llm-gateway/junit.xml+ # Upload results to Trunk for flaky-test detection. Non-gating (continue-on-error),+ # so a Trunk outage never fails the job. Runs the token only on internal PRs,+ # master, and the merge queue — never on fork PRs or Dependabot, which have no secret.+ - name: Upload test results to Trunk+ if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: services/llm-gateway/junit.xml+ org-slug: posthog-inc+ token: ${{ secrets.TRUNK_API_TOKEN }}+# Single required status check for branch protection. Add future LLM# services test jobs to `needs` here rather than reconfiguring GitHub.llm_services_tests:diff --git a/.github/workflows/ci-mcp.yml b/.github/workflows/ci-mcp.ymlindex 4673ccc555cb..18f3852228eb 100644--- a/.github/workflows/ci-mcp.yml+++ b/.github/workflows/ci-mcp.yml@@ -22,6 +22,9 @@ permissions:contents: readpull-requests: read+env:+ RUNS_ON_INTERNAL_PR: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }}+jobs:changes:runs-on: ubuntu-24.04@@ -550,13 +553,26 @@ jobs:verbose: true- name: Run integration tests- run: cd services/mcp && pnpm run test:integration+ # The junit reporter (alongside the default console one) feeds the Trunk upload below.+ run: cd services/mcp && pnpm run test:integration -- --reporter=default --reporter=junit --outputFile.junit=junit-integration.xmlenv:TEST_POSTHOG_API_BASE_URL: http://localhost:8000TEST_POSTHOG_PERSONAL_API_KEY: phx_e2e_demo_api_keyTEST_ORG_ID: ${{ env.TEST_ORG_ID }}TEST_PROJECT_ID: ${{ env.TEST_PROJECT_ID }}+ # Upload results to Trunk for flaky-test detection. Non-gating (continue-on-error),+ # so a Trunk outage never fails the job. Runs the token only on internal PRs,+ # master, and the merge queue — never on fork PRs or Dependabot, which have no secret.+ - name: Upload test results to Trunk+ if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: services/mcp/junit-integration.xml+ org-slug: posthog-inc+ token: ${{ secrets.TRUNK_API_TOKEN }}+- name: Show server logs on failureif: failure()run: cat /tmp/server.log || truediff --git a/.github/workflows/ci-nodejs.yml b/.github/workflows/ci-nodejs.ymlindex a8a24f9ab3f4..f17b4eb47af2 100644--- a/.github/workflows/ci-nodejs.yml+++ b/.github/workflows/ci-nodejs.yml@@ -15,6 +15,7 @@ env:OBJECT_STORAGE_BUCKET: 'posthog'# set the max buffer size small enough that the functional tests behave the same in CI as when running locallySESSION_RECORDING_MAX_BUFFER_SIZE_KB: 1024+ RUNS_ON_INTERNAL_PR: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }}concurrency:group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}@@ -366,6 +367,13 @@ jobs:LOG_LEVEL: info# Enable localstack integration tests for DynamoDB/KMSLOCALSTACK_ENABLED: '1'+ # Emit JUnit XML for the Trunk upload below (turbo passes JEST_JUNIT_* through).+ JEST_JUNIT_OUTPUT_DIR: ${{ github.workspace }}/junit-results+ JEST_JUNIT_OUTPUT_NAME: junit-nodejs-${{ matrix.shard }}.xml+ # Trunk attributes flakes by test file; jest-junit's default suite name is the+ # describe block, so make it the file path instead.+ JEST_JUNIT_SUITE_NAME: '{filepath}'+ JEST_JUNIT_ADD_FILE_ATTRIBUTE: 'true'run: bin/turbo run test --filter=@posthog/nodejs- name: Test postgres-parity (isolated DB)@@ -378,8 +386,24 @@ jobs:REDIS_URL: 'redis://localhost'NODE_OPTIONS: '--max_old_space_size=4096'LOG_LEVEL: info+ JEST_JUNIT_OUTPUT_DIR: ${{ github.workspace }}/junit-results+ JEST_JUNIT_OUTPUT_NAME: junit-nodejs-postgres-parity.xml+ JEST_JUNIT_SUITE_NAME: '{filepath}'+ JEST_JUNIT_ADD_FILE_ATTRIBUTE: 'true'run: cd nodejs && pnpm run test:postgres-parity+ # Upload results to Trunk for flaky-test detection. Non-gating (continue-on-error),+ # so a Trunk outage never fails the job. Runs the token only on internal PRs,+ # master, and the merge queue — never on fork PRs or Dependabot, which have no secret.+ - name: Upload test results to Trunk+ if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-results/junit-*.xml+ org-slug: posthog-inc+ token: ${{ secrets.TRUNK_API_TOKEN }}+- name: Output logs on failureif: failure()run: |diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.ymlindex 849418a1f570..15353a838925 100644--- a/.github/workflows/ci-python.yml+++ b/.github/workflows/ci-python.yml@@ -15,6 +15,9 @@ concurrency:group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}cancel-in-progress: ${{ github.event_name == 'pull_request' }}+env:+ RUNS_ON_INTERNAL_PR: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }}+jobs:# Job to decide if we should run python ci# See https://github.com/dorny/paths-filter#conditional-execution for more details@@ -223,6 +226,18 @@ jobs:name: junit-results-dependency-detectionpath: junit-dependency-detection.xml+ # Upload results to Trunk for flaky-test detection. Non-gating (continue-on-error),+ # so a Trunk outage never fails the job. Runs the token only on internal PRs,+ # master, and the merge queue — never on fork PRs or Dependabot, which have no secret.+ - name: Upload test results to Trunk+ if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: junit-*.xml+ org-slug: posthog-inc+ token: ${{ secrets.TRUNK_API_TOKEN }}+# - name: Check if "taxonomy.json/taxonomy.tsx" is up to date# if: needs.changes.outputs.python == 'true'# shell: bashdiff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.ymlindex 0b6f837e262c..0a87ef6912fc 100644--- a/.github/workflows/ci-rust.yml+++ b/.github/workflows/ci-rust.yml@@ -13,6 +13,7 @@ concurrency:env:CARGO_TERM_COLOR: alwaysUV_HTTP_TIMEOUT: 120+ RUNS_ON_INTERNAL_PR: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork == false }}jobs:# Job to decide if we should run rust ci@@ -397,6 +398,15 @@ jobs:run: |cd ../ && ./bin/download-mmdb+ - name: Install cargo-binstall+ uses: cargo-bins/cargo-binstall@5cbf019d8cb9b9d5b086218c41458ea35d817691 # main++ - name: Install cargo-nextest+ # --force: Swatinem/rust-cache restores ~/.cargo/.crates2.json but not the+ # binary itself, so without --force binstall can short-circuit ("already+ # installed") and leave no `cargo nextest` binary.+ run: cargo binstall --no-confirm --force [email protected]+- name: Run cargo testenv:RUST_BACKTRACE: 1@@ -404,6 +414,21 @@ jobs:PERSONS_READ_DATABASE_URL: ${{ contains(format(' {0} ', matrix.packages), ' feature-flags ') && 'postgres://posthog:posthog@localhost:5432/posthog_persons' || '' }}PERSONS_WRITE_DATABASE_URL: ${{ contains(format(' {0} ', matrix.packages), ' feature-flags ') && 'postgres://posthog:posthog@localhost:5432/posthog_persons' || '' }}run: |+ # nextest (instead of plain `cargo test`) emits JUnit XML for the Trunk upload+ # below. It does not run doctests, so those keep running via `cargo test --doc`.+ # --no-tests=pass matches `cargo test` semantics for packages/filters with no tests.+ # Each run overwrites target/nextest/ci/junit.xml, so stash it per package —+ # even on failure, so the failing results still reach Trunk before we exit.+ run_nextest() {+ local junit_name=$1+ shift+ local rc=0+ cargo nextest run --profile ci --no-tests=pass "$@" || rc=$?+ if [ -f target/nextest/ci/junit.xml ]; then+ mv target/nextest/ci/junit.xml "junit-nextest-$junit_name.xml"+ fi+ return $rc+ }for pkg in ${{ matrix.packages }}; doecho "::group::Testing $pkg"# Free cgroups, overlayfs, and network namespaces from previous testcontainers@@ -411,20 +436,37 @@ jobs:extra_args=""# Limit test threads for packages with sqlx pool exhaustion issuesif [ "$pkg" = "property-defs-rs" ]; then- extra_args="-- --test-threads=4"+ extra_args="--test-threads=4"+ fi+ run_nextest "$pkg" -p "$pkg" $extra_args+ # nextest skips doctests; run them only for packages with a lib target+ # (`cargo test --doc` errors on bin-only packages).+ if cargo metadata --no-deps --format-version 1 | jq -e --arg p "$pkg" '[.packages[] | select(.name == $p) | .targets[] | select(.kind | index("lib"))] | length > 0' >/dev/null; then+ cargo test --doc -p "$pkg"fi- cargo test -p "$pkg" $extra_args# Error-tracking rate-limiter e2e tests are #[ignore]'d (they need a real Redis# via testcontainers/Docker, absent in some environments). This job has Docker,# so run them here, single-threaded to avoid concurrent-container flakes. The# `rate_limiting` filter matches nothing on branches without these tests, so it# stays safe for unrebased PRs.if [ "$pkg" = "cymbal" ]; then- cargo test -p cymbal rate_limiting -- --ignored --test-threads=1+ run_nextest cymbal-ignored -p cymbal -E 'test(rate_limiting)' --run-ignored only --test-threads=1fiecho "::endgroup::"done+ # Upload results to Trunk for flaky-test detection. Non-gating (continue-on-error),+ # so a Trunk outage never fails the job. Runs the token only on internal PRs,+ # master, and the merge queue — never on fork PRs or Dependabot, which have no secret.+ - name: Upload test results to Trunk+ if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' }}+ continue-on-error: true+ uses: trunk-io/analytics-uploader@385f1ccdf345b4532dc4b6c665dd432b702b8e28 # v2.1.2+ with:+ junit-paths: rust/junit-nextest-*.xml+ org-slug: posthog-inc+ token: ${{ secrets.TRUNK_API_TOKEN }}+linting:name: Lint Rust services (depot-ubuntu-22.04-4)needs: changesdiff --git a/nodejs/jest.config.js b/nodejs/jest.config.jsindex a02db978576d..8392b1d1e181 100644--- a/nodejs/jest.config.js+++ b/nodejs/jest.config.js@@ -8,6 +8,8 @@ module.exports = {],},testEnvironment: 'node',+ // Emit JUnit XML for Trunk flaky-test detection only when JEST_JUNIT_OUTPUT_DIR is set.+ reporters: process.env.JEST_JUNIT_OUTPUT_DIR ? ['default', 'jest-junit'] : ['default'],clearMocks: true,coverageProvider: 'v8',setupFiles: ['./jest.setup-env.ts'],diff --git a/nodejs/package.json b/nodejs/package.jsonindex 7a1f17a09a50..e38d4748144b 100644--- a/nodejs/package.json+++ b/nodejs/package.json@@ -186,6 +186,7 @@"eslint-plugin-no-only-tests": "^3.1.0","jest": "^30.0.0","jest-environment-node": "^30.0.0",+ "jest-junit": "^16.0.0","pino-pretty": "^9.1.0","prettier": "~3.6.2","supertest": "^7.2.2",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 2f22a38d9cf6..2b324be27327 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1770,6 +1770,9 @@ importers:jest-environment-node:specifier: ^30.0.0version: 30.0.5+ jest-junit:+ specifier: ^16.0.0+ version: 16.0.0pino-pretty:specifier: ^9.1.0version: 9.4.0diff --git a/rust/.config/nextest.toml b/rust/.config/nextest.tomlnew file mode 100644index 000000000000..99db22d79a27--- /dev/null+++ b/rust/.config/nextest.toml@@ -0,0 +1,9 @@+# CI profile: emits JUnit XML (target/nextest/ci/junit.xml) so test results can be+# uploaded to Trunk for flaky-test detection.+[profile.ci]+# Run the whole suite even after a failure, so the JUnit output captures every+# failing/flaky test for Trunk instead of stopping at the first one.+fail-fast = false++[profile.ci.junit]+path = "junit.xml"