ref(ci): Run more of sentry's tests when we change the API in snuba - #8237
ref(ci): Run more of sentry's tests when we change the API in snuba#8237pbhandari wants to merge 4 commits into
Conversation
e9b30da to
bb56d76
Compare
| if: needs.files-changed.outputs.api_changes == 'false' | ||
| working-directory: sentry | ||
| run: | | ||
| # Only these dirs carry the `snuba_ci` marker; collecting all of tests/ just to find them is wasteful. |
There was a problem hiding this comment.
This comment is valid; but given that pytest collection is pretty fast, and reverting a change can take up to 2+ hours if we miss something on the CI ... better to just collect everything
| -m snuba \ | ||
| tests \ |
There was a problem hiding this comment.
Theoretically we are missing some tests that used to be covered before. But I don't think that's an actual concern since we care more about how our API changes interact with the monolith, only running the SnubaTestCase test cases should be sufficient.
|
|
||
| - name: Run CI module tests | ||
| if: needs.files-changed.outputs.api_changes == 'true' | ||
| working-directory: sentry | ||
| run: | | ||
| pytest -k 'not __In' \ | ||
| tests/sentry/snuba \ | ||
| tests/sentry/workflow_engine/endpoints \ | ||
| tests/snuba/rules/conditions \ | ||
| -m snuba_ci \ | ||
| -n "$XDIST_WORKERS" --dist=loadfile --reuse-db \ | ||
| -vv | ||
|
|
There was a problem hiding this comment.
This was identical to the Run snuba tests step; with the only exception being the if gate.
| tests/sentry/workflow_engine/endpoints \ | ||
| tests/snuba/rules/conditions \ | ||
| -m snuba_ci \ | ||
| tests \ |
There was a problem hiding this comment.
Acceptance collection can fail CI
High Severity
Widening collection to all of tests now pulls in tests/acceptance, which this PR already notes fails to collect without a webpack/pnpm frontend build. This job uses mode: minimal and does not build frontend assets, and pytest treats collection errors as failures even when no snuba/snuba_ci tests live there. The previous path lists never included acceptance, so this can fail the sentry job on every PR.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit bb56d76. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5150e13. Configure here.
| -vv | ||
|
|
||
| - name: Run full tests | ||
| if: needs.files-changed.outputs.api_changes == 'true' |
There was a problem hiding this comment.
Full tests missing API-change gate
Medium Severity
The Run full tests step dropped its if: needs.files-changed.outputs.api_changes == 'true' guard, so the large -m snuba suite now runs on every PR. The PR description still treats that suite as API-change-only, and api_changes is computed but unused. Non-API PRs therefore pay for ~5,555 tests instead of the intended ~173 snuba_ci set.
Reviewed by Cursor Bugbot for commit 5150e13. Configure here.
| working-directory: sentry | ||
| run: | | ||
| pytest -k 'not __In' \ | ||
| tests/snuba \ | ||
| tests/sentry/snuba \ | ||
| tests/sentry/eventstream/kafka \ | ||
| tests/sentry/post_process_forwarder \ | ||
| tests/sentry/services/eventstore/snuba \ | ||
| tests/sentry/search/events \ | ||
| tests/sentry/event_manager \ | ||
| tests/sentry/api/endpoints/test_organization_profiling_functions.py \ | ||
| tests/sentry/integrations/slack/test_unfurl.py \ | ||
| tests/sentry/uptime/endpoints/test_project_uptime_alert_check_index.py \ | ||
| tests/sentry/uptime/endpoints/test_organization_uptime_stats.py \ | ||
| tests/sentry/api/endpoints/test_organization_traces.py \ | ||
| tests/sentry/api/endpoints/test_organization_spans_fields.py \ | ||
| tests/sentry/api/endpoints/test_organization_ai_conversations.py \ | ||
| tests/sentry/api/endpoints/test_organization_ai_conversation_details.py \ | ||
| tests/sentry/sentry_metrics/querying \ | ||
| -m snuba \ | ||
| tests \ | ||
| -n "$XDIST_WORKERS" --dist=loadfile --reuse-db \ | ||
| -vv |
There was a problem hiding this comment.
Bug: The if conditions gating the "Run snuba CI tests" and "Run full tests" steps have been removed, causing both to run unconditionally on every PR.
Severity: MEDIUM
Suggested Fix
Restore the if conditions to the respective test steps. The "Run snuba CI tests" step should have if: needs.files-changed.outputs.api_changes == 'false', and the "Run full tests" step should have if: needs.files-changed.outputs.api_changes == 'true'. This will ensure the expensive full test suite only runs when necessary.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: .github/workflows/ci.yml#L478-L484
Potential issue: The `if` conditions that were supposed to conditionally execute test
steps based on `needs.files-changed.outputs.api_changes` have been removed from the CI
workflow. As a result, both the "Run snuba CI tests" step and the expensive "Run full
tests" step now run on every pull request, regardless of whether API changes were
detected. This contradicts the PR's stated intent to only run the full test suite when
API changes are present, leading to significant CI resource waste by unnecessarily
executing a large test suite.


What
The
sentry-testsjob maintained a hand-curated list oftests/sentry/...paths to decide which of Sentry's tests to run against a Snuba change. That list is brittle: as Snuba-dependent tests are added, moved, or renamed in theSentry repo, the list silently goes stale and we stop covering them.
The lack of coverage can lead to a snuba deploy that is incompatible with Sentry which can take up to 2+
This replaces the path lists with marker-based selection; that marker is associated with the base class
SnubaTestCase, and is now run over the wholeteststree:api_changes == false):-m snuba_cinow scans all oftests/instead of three hardcoded directories.api_changes == true): collapses the old "Run full tests" (explicit path list) steps into a single-m snuba testsrun.api_changes == true): is identical to theapi_changes == falsepath and has been collapsed.So which tests run is now driven by how tests are marked in Sentry, not by a path list in this repo that has to be kept in sync by hand.
Tests collected: before → after
Collected with
pytest --collect-only -k 'not __In'in the Sentry repo.-m snuba_ci)tests/)snuba_ci)-m snubawholetests/)Takeaways:
snuba_ciset is unchanged (173) — widening collection to the whole tree discovers the same marked tests, just without the stale hardcoded dirs.snuba-marked tests vs the previous 4,716 path-listed tests — ~840 more, and no longer dependent on the path list staying current.(Local collection reports 1 error for
tests/acceptance, which needs a webpack/pnpm frontend build that isn't set up locally; it carries nosnuba-marked tests and is present in CI, so it doesn't affect these counts.)🤖 Generated with Claude Code