Skip to content

: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.

chore(ci): exclude warehouse sources tests from Trunk quarantine (#89769)

Paul D'Ambrafefd8ab1ec2e
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.yml
index cc182e96a2f9..03b1b47157b8 100644
--- a/.depot/workflows/ci-backend.yml
+++ b/.depot/workflows/ci-backend.yml
@@ -22,8 +22,9 @@
# --store-durations write, test-selection verdict, Trunk flaky-test quarantine
# gate (canonical runs per-shard analytics-uploader steps that post to the
# external Trunk service; the upload is best-effort and a local "Fail on test
-# failure" step owns the pass/fail verdict. The shadow strips all of it — no
-# Trunk posting from a non-blocking timing trial — and so also omits the test
+# failure" step owns the pass/fail verdict. Canonical can stage or filter JUnit
+# before this upload. The shadow strips all of it because a non-blocking timing
+# trial must not post to Trunk, and so it also omits the test
# steps' continue-on-error and that verdict step, letting each shard's test
# exit code be the verdict directly. Canonical gates each quarantine gate on the
# TRUNK_UPLOAD_ENABLED repo variable as an upload kill-switch, and its verdict step
diff --git a/.github/scripts/prepare-product-junit-for-trunk.sh b/.github/scripts/prepare-product-junit-for-trunk.sh
new file mode 100644
index 000000000000..55fcf14a5554
--- /dev/null
+++ b/.github/scripts/prepare-product-junit-for-trunk.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+if [ "$#" -lt 3 ]; then
+ echo "usage: $0 OUTPUT_DIR MATRIX_FILTERS EXCLUDED_JUNIT_PATH..." >&2
+ exit 2
+fi
+
+output_dir="$1"
+matrix_filters="$2"
+shift 2
+excluded_reports=("$@")
+read -r -a selected_filters <<<"$matrix_filters"
+
+is_excluded() {
+ local report="$1" excluded_report
+ for excluded_report in "${excluded_reports[@]}"; do
+ if [ "$report" = "$excluded_report" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+is_selected() {
+ local package_name="$1" filter
+ for filter in "${selected_filters[@]}"; do
+ if [ "$filter" = "--filter=$package_name" ]; then
+ return 0
+ fi
+ done
+ return 1
+}
+
+mkdir -p "$output_dir"
+find "$output_dir" -maxdepth 1 -type f -name 'junit-product-*.xml' -delete
+
+for report in products/*/junit-product.xml; do
+ [ -f "$report" ] || continue
+ if ! is_excluded "$report"; then
+ product="$(basename "$(dirname "$report")")"
+ cp "$report" "$output_dir/junit-product-$product.xml"
+ fi
+done
+
+excluded_failure=0
+for report in "${excluded_reports[@]}"; do
+ package_json="$(dirname "$report")/package.json"
+ if [ ! -f "$package_json" ]; then
+ echo "::error file=$package_json::Cannot resolve the package for excluded JUnit report $report"
+ excluded_failure=1
+ continue
+ fi
+
+ package_name="$(node -e 'process.stdout.write(JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).name)' "$package_json")"
+ if ! is_selected "$package_name"; then
+ continue
+ fi
+ if [ ! -f "$report" ]; then
+ echo "::error file=$report::The selected package $package_name did not produce its excluded JUnit report"
+ excluded_failure=1
+ elif grep -qE '<(failure|error)([[:space:]>])' "$report"; then
+ echo "::error file=$report::Tests in $package_name failed and cannot use Trunk quarantine"
+ excluded_failure=1
+ fi
+done
+
+exit "$excluded_failure"
diff --git a/.github/scripts/prepare-product-junit-for-trunk.test.sh b/.github/scripts/prepare-product-junit-for-trunk.test.sh
new file mode 100644
index 000000000000..cbf69067350d
--- /dev/null
+++ b/.github/scripts/prepare-product-junit-for-trunk.test.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+script="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/prepare-product-junit-for-trunk.sh"
+workdir="$(mktemp -d)"
+trap 'rm -rf "$workdir"' EXIT
+
+create_product() {
+ local root="$1" directory="$2" package_name="$3" report="$4"
+ mkdir -p "$root/products/$directory"
+ printf '{"name":"%s"}\n' "$package_name" >"$root/products/$directory/package.json"
+ if [ -n "$report" ]; then
+ printf '%s\n' "$report" >"$root/products/$directory/junit-product.xml"
+ fi
+}
+
+run_case() {
+ local name="$1" filters="$2" expected_status="$3" warehouse_report="$4" other_report="$5"
+ local excluded_paths="${6:-products/warehouse_sources/junit-product.xml}"
+ local root="$workdir/$name" output status excluded_path product
+ read -r -a exclusions <<<"$excluded_paths"
+ mkdir -p "$root"
+ create_product "$root" warehouse_sources @posthog/products-warehouse-sources "$warehouse_report"
+ create_product "$root" warehouse_sources_queue @posthog/products-warehouse-sources-queue '<testsuite tests="1" failures="0" />'
+ create_product "$root" other @posthog/products-other "$other_report"
+
+ set +e
+ output=$(cd "$root" && bash "$script" trunk-junit "$filters" "${exclusions[@]}" 2>&1)
+ status=$?
+ set -e
+
+ if [ "$status" -ne "$expected_status" ]; then
+ echo "FAIL: $name returned $status, expected $expected_status"
+ printf '%s\n' "$output"
+ exit 1
+ fi
+ for excluded_path in "${exclusions[@]}"; do
+ product="$(basename "$(dirname "$excluded_path")")"
+ if [ -e "$root/trunk-junit/junit-product-$product.xml" ]; then
+ echo "FAIL: $name staged excluded report $excluded_path"
+ exit 1
+ fi
+ done
+ if [ ! -e "$root/trunk-junit/junit-product-warehouse_sources_queue.xml" ]; then
+ echo "FAIL: $name did not stage an included report"
+ exit 1
+ fi
+ echo "ok: $name"
+}
+
+run_case exact-package-match '--filter=@posthog/products-warehouse-sources-queue' 0 '' '<testsuite tests="1" failures="0" />'
+run_case selected-report-missing '--filter=@posthog/products-warehouse-sources' 1 '' '<testsuite tests="1" failures="0" />'
+run_case selected-report-passes '--filter=@posthog/products-warehouse-sources' 0 '<testsuite tests="1" failures="0" />' '<testsuite tests="1" failures="0" />'
+run_case selected-report-fails '--filter=@posthog/products-warehouse-sources' 1 '<testsuite tests="1" failures="1"><testcase><failure /></testcase></testsuite>' '<testsuite tests="1" failures="0" />'
+run_case multiple-exclusions '--filter=@posthog/products-other' 0 '<testsuite tests="1" failures="0" />' '<testsuite tests="1" failures="0" />' 'products/warehouse_sources/junit-product.xml products/other/junit-product.xml'
+
+echo "Product JUnit preparation regression cases passed."
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index debe189fa398..559638db70f4 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -1005,6 +1005,19 @@ jobs:
exit $exit_code
fi
+ # Excluded reports bypass Trunk quarantine, so this step owns their verdict.
+ - name: Prepare product JUnit for Trunk
+ id: prepare_product_junit
+ if: always()
+ shell: bash
+ env:
+ PRODUCT_FILTERS: ${{ matrix.filters }}
+ run: |
+ bash .github/scripts/prepare-product-junit-for-trunk.sh \
+ trunk-junit \
+ "$PRODUCT_FILTERS" \
+ products/warehouse_sources/junit-product.xml
+
# Best-effort Trunk upload (continue-on-error); the "Fail on test failure" step below is
# the verdict, so a Trunk outage can't red a passing shard. Internal PRs only (needs the
# secret).
@@ -1018,7 +1031,7 @@ jobs:
if: ${{ !cancelled() && env.RUNS_ON_INTERNAL_PR == 'true' && github.repository == 'PostHog/posthog' && github.actor != 'dependabot[bot]' && vars.TRUNK_UPLOAD_ENABLED == 'true' }}
uses: ./.github/actions/trunk-quarantine-gate
with:
- junit-paths: products/*/junit-product.xml
+ junit-paths: trunk-junit/junit-product-*.xml
previous-step-outcome: ${{ steps.run-product-tests.outcome }}
token: ${{ secrets.TRUNK_API_TOKEN }}
@@ -1026,7 +1039,7 @@ jobs:
# also covers the skipped gate on fork/Dependabot. Sits before the timing-data upload so
# a real failure still skips it, as it did before the test step got continue-on-error.
- name: Fail on test failure
- if: ${{ !cancelled() && steps.run-product-tests.outcome == 'failure' && (vars.TRUNK_QUARANTINE_ENABLED != 'true' || steps.quarantine_gate.outcome != 'success') }}
+ if: ${{ !cancelled() && (steps.prepare_product_junit.outcome == 'failure' || (steps.run-product-tests.outcome == 'failure' && (vars.TRUNK_QUARANTINE_ENABLED != 'true' || steps.quarantine_gate.outcome != 'success'))) }}
shell: bash
run: exit 1
diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml
index 84391071f2be..35670dfd7370 100644
--- a/.github/workflows/shellcheck.yml
+++ b/.github/workflows/shellcheck.yml
@@ -39,6 +39,11 @@ jobs:
shellcheck .github/scripts/desktop/*.sh
.github/scripts/desktop/check-pr-backend-coupling.test.sh
+ - name: Check product JUnit preparation script
+ run: |
+ shellcheck .github/scripts/prepare-product-junit-for-trunk.sh .github/scripts/prepare-product-junit-for-trunk.test.sh
+ bash .github/scripts/prepare-product-junit-for-trunk.test.sh
+
# Runs here, not in a path-gated ci-* job, so AGENTS/CLAUDE changes
# anywhere in the repo are validated on every PR.
- name: Check AGENTS.md / CLAUDE.md symlinks