Add flake_cluster: cluster tests that flake together (co-failure Jaccard)#412
Merged
Conversation
…ard) Flaky tests are rarely independent - a wobbly fixture or noisy dependency makes a group fail in the same runs (~75% of flaky tests cluster). Ranking tests one-by-one by flip rate misses that shared root cause. Measure how often each pair fails in the same runs (Jaccard over their failing-run sets) and group tests above a threshold into connected clusters with a cohesion score. Pure stdlib over a list of failed-test sets.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 43 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
Flaky tests are rarely independent: a wobbly shared fixture, a slow dependency or a noisy environment makes a group of tests fail in the same runs (research finds ~75% of flaky tests fall into co-failure clusters). Ranking tests one-by-one by flip rate misses that shared root cause.
flake_clustermeasures how often each pair of tests fails in the same runs — Jaccard similarity over the set of runs each failed in — and groups tests above a threshold, so you chase one root cause instead of N symptoms.cofailure_pairs— test pairs that fail together above a Jaccard thresholdfailure_clusters— connected clusters of co-failing tests with a cohesion score (mean pairwise Jaccard)Third item of the test-robustness lane. Input is a list of runs, each the test names that failed in it.
Design
text_similarity.jaccardis n-gram string similarity (different), so set-Jaccard stays internal. Every function under CC 10 (radon-clean).__all__→AC_failure_clusters/AC_cofailure_pairs→ read-onlyac_*MCP tools → Script Builder (Testing). Qt-free verified;pytest.approxfor cohesion (no float==).Tests
test/unit_test/headless/test_flake_cluster_batch.py— clusters group co-failing tests (cohesion 1.0), singleton excluded bymin_size,min_size=1keeps singletons, high threshold keeps only perfect co-failure,cofailure_pairsscores + sort + count, empty / no-co-failure cases, the executor paths + 5-layer wiring. 9 passed.