Skip to content

Add flaky-test ranking metric and dashboard panel - #374

Merged
bg-playground merged 5 commits into
mainfrom
copilot/add-failure-flip-rate-widget
Jul 15, 2026
Merged

Add flaky-test ranking metric and dashboard panel#374
bg-playground merged 5 commits into
mainfrom
copilot/add-failure-flip-rate-widget

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This change adds a Quality KPI widget that ranks the top tests by failure-flip rate across the selected dashboard window, using existing external_case_results data. It introduces a new aggregated backend endpoint and connects it to a sortable frontend table to surface flapping tests at a glance.

  • Backend: flaky ranking aggregation + API

    • Added FlakyTestEntry and FlakyRankingResponse schemas.
    • Added get_flaky_ranking(db, window_days, top_n) in quality metrics CRUD.
      • Reuses existing window helpers and case-row loader.
      • Groups by stable identity (test_case_idexternal_idid).
      • Computes runs, flaky_outcomes, transitions, flip_rate, last_outcome, last_seen_at.
      • Excludes non-signal outcomes (started, skipped, aborted) from transition sequence.
      • Applies ranking sort: flip_rate desc, flaky_outcomes desc, runs desc, display_name asc.
      • Returns synthetic/empty-state reasons aligned with existing quality-metrics behavior.
    • Added GET /quality-metrics/flaky-ranking with window and top_n query params.
  • Backend tests

    • Added dedicated flaky-ranking test module covering:
      • empty DB synthetic response,
      • high-flip sequence behavior (pass↔fail),
      • exclusion of all-pass and single-run tests,
      • top_n capping,
      • independent counting of flaky_outcomes,
      • window-boundary exclusion,
      • external-id-only identities with test_case_id = null.
  • Frontend: API + dashboard widget

    • Added getFlakyRanking({ window, topN }) and corresponding TS types.
    • Added FlakyRankingPanel to QualityDashboardPage, driven by existing window state.
    • Renders sortable table with columns:
      • Test, Runs, Flips, Flip rate, Last outcome, Last seen.
    • Reuses existing outcome chip color mapping style.
    • Handles loading/empty/synthetic states with reason messaging.
    • Links test cells to filtered test-case view (/test-cases?search=...).
  • Frontend tests

    • Added panel tests for:
      • rendering rows from mocked response,
      • synthetic empty state,
      • refetch on window change,
      • client-side sort via column headers.
# backend/app/crud/quality_metrics.py (core calculation)
considered_outcomes = [
    case_result.outcome
    for case_result, _test_case in ordered_rows
    if case_result.outcome in {CaseStatus.passed, CaseStatus.failed, CaseStatus.flaky}
]
transitions = sum(
    1 for previous, current in zip(considered_outcomes, considered_outcomes[1:], strict=False)
    if previous != current
)
flip_rate = transitions / max(len(considered_outcomes) - 1, 1)

Copilot AI changed the title [WIP] Add widget to rank top-N tests by failure-flip rate Add flaky-test ranking metric and dashboard panel Jun 17, 2026
Copilot AI requested a review from bg-playground June 17, 2026 18:51
- Change db_session fixture return type from AsyncSession to
  AsyncGenerator[AsyncSession, None] (async generator, not coroutine)
- Pre-allocate UUIDs before ExternalRunSession construction so
  _seed_session returns uuid.UUID values instead of Column[Any]

@bg-playground bg-playground left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
CI checks are still failing - See screen shot for E2E test CI

Image

…ngPanel

Main refactored selectedWindow → filters.window with URL/storage persistence.
Update FlakyRankingPanel usage to use filters.window so the merged result
no longer references an undefined identifier at build time.

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
CI checks are still failing - See screen shot for E2E test CI
...

Fixed in commit fix: update QualityDashboardPage to use filters.window for FlakyRankingPanel.

Root cause: the base branch (main) had refactored selectedWindowfilters.window (with URL/localStorage persistence via useSearchParams). Our branch still used selectedWindow, so the CI merge result had <FlakyRankingPanel window={selectedWindow} /> at line 542 where selectedWindow no longer existed.

The fix rebases our page file onto main's refactored version and updates the FlakyRankingPanel prop to window={filters.window}.

@bg-playground
bg-playground marked this pull request as ready for review July 15, 2026 17:41
@bg-playground
bg-playground merged commit 33378ae into main Jul 15, 2026
11 checks passed
@bg-playground
bg-playground deleted the copilot/add-failure-flip-rate-widget branch July 15, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants