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.

fix(ci): stop fork PRs failing on cross-shard unused snapshots (#66240)

Phil Haackfbd6fb09b0cb
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
index c0abc3bdf660..8b39271c989a 100644
--- a/.github/workflows/ci-backend.yml
+++ b/.github/workflows/ci-backend.yml
@@ -2337,6 +2337,26 @@ jobs:
shell: bash
run: echo "PYTEST_ARGS=--snapshot-update --snapshot-warn-unused" >> $GITHUB_ENV
+ - name: Warn (don't fail) on unused snapshots for sharded CHECK runs
+ # CHECK mode (fork PRs, the 'no-snapshot-update' label) runs without
+ # --snapshot-update, so the steps above don't fire and no snapshot flags
+ # are set. But pytest-split shards individual tests across runners, so each
+ # shard only exercises a subset of the snapshots in a given file — every
+ # snapshot owned by a test that landed on another shard is reported as
+ # "unused". Under sharding that signal is structurally unreliable, so without
+ # --snapshot-warn-unused a shard fails on those false positives even when
+ # every test that ran passed (the snapshot report's "N snapshots unused"
+ # line). Every non-fork run (UPDATE, poe, compat) already passes the flag;
+ # this just makes forks symmetric. Trade-off: it downgrades unused snapshots
+ # to a warning, so genuinely orphaned snapshots go uncaught here — but they
+ # already do everywhere else, and sharding makes per-shard orphan detection
+ # impossible regardless. Snapshot *mismatches* and missing snapshots still
+ # fail, so real value drift is still caught. Mutually exclusive with the
+ # steps above (mode != update, not poe, not compat).
+ if: ${{ needs.changes.outputs.backend == 'true' && needs.detect-snapshot-mode.outputs.mode != 'update' && !matrix.person-on-events && !matrix.compat }}
+ shell: bash
+ run: echo "PYTEST_ARGS=--snapshot-warn-unused" >> $GITHUB_ENV
+
# Tests
- name: Log test environment diagnostics
if: ${{ needs.changes.outputs.backend == 'true' && matrix.segment == 'Core' }}