Skip to content
Development
Skill

/fix-flaky-tests

Fixes flaky tests by analyzing failure patterns from Tuist test insights, identifying root causes, and applying targeted corrections. Can be invoked with a specific test case URL (e.g. `https://tuist.dev/{account}/{project}/tests/test-cases/{id}`) or without arguments to

From plugin
tuist
5.9k13 skills46 agents

Claude Code

$ npx -y skills add tuist/tuist --skill fix-flaky-tests --agent claude-code

SKILL.md

fix-flaky-tests.SKILL.md
name: fix-flaky-tests
description: Fixes flaky tests by analyzing failure patterns from Tuist test insights, identifying root causes, and applying targeted corrections. Can be invoked with a specific test case URL (e.g. `https://tuist.dev/{account}/{project}/tests/test-cases/{id}`) or without arguments to discover and fix all flaky tests in the project.

Fix Flaky Tests

Quick Start

You'll typically receive a Tuist test case URL or identifier. Follow these steps to investigate and fix it:

1. Run `tuist test case show <id-or-identifier> --json` to get reliability metrics for the test. 2. Run `tuist test case run list Module/Suite/TestCase --flaky --json` to see flaky run patterns. 3. Run `tuist test case run show <test-case-run-id> --json` on failing flaky runs to get failure messages and file paths. 4. Read the test source at the reported path and line, identify the flaky pattern, and fix it. 5. Verify by running the test multiple times to confirm it passes consistently.

If no specific test is provided, start with the Discovery section below.

Discovery

When no specific test case is provided, find all flaky tests in the project:

tuist test case list --flaky --json --page-size 50

This returns all test cases currently flagged as flaky. Key fields:

  • `module.name` / `suite.name` / `name` — the test identifier
  • `avg_duration` — helps prioritize (fix fast unit tests first)
  • `is_quarantined` — whether the test is already quarantined

**Triage strategy:** 1. Group tests by suite — multiple flaky tests in the same suite often share a root cause. 2. Check if failures share a `test_run_id` — tests that all failed in the same run may have been killed by a process crash, not individual test bugs. 3. Look at failure messages to categorize: test logic bugs vs infrastructure issues (network errors, server 502s, conflicts on retry).

Investigation

1. Get test case metrics

You can pass either the UUID or the `Module/Suite/TestCase` identifier:

tuist test case show <id> --json
tuist test case show Module/Suite/TestCase --json

Key fields:

  • `reliability_rate` — percentage of successful runs (higher is better)
  • `flakiness_rate` — percentage of runs marked flaky in the last 30 days
  • `total_runs` / `failed_runs` — volume context
  • `last_status` — current state

2. View flaky run history

tuist test case run list Module/Suite/TestCase --flaky --json

The identifier uses the format `ModuleName/SuiteName/TestCaseName` or `ModuleName/TestCaseName` when there is no suite. This returns only runs that were detected as flaky.

3. View full run history

tuist test case run list Module/Suite/TestCase --json --page-size 20

Look for patterns:

  • Does it fail on specific branches?
  • Does it fail only on CI (`is_ci: true`) or also locally?
  • Are failures clustered around specific commits?

4. Get failure details

tuist test case run show <test-case-run-id> --json

Key fields:

  • `failures[].message` — the assertion or error message
  • `failures[].path` — source file path
  • `failures[].line_number` — exact line of failure
  • `failures[].issue_type` — type of issue (assertion_failure, etc.)
  • `repetitions` — if present, shows retry behavior (pass/fail sequence)
  • `test_run_id` — the broader test run this execution belongs to
  • `crash_report` — crash report data (present when the test runner crashed); contains `exception_type`, `signal`, `exception_subtype`, and `triggered_thread_frames`

Code Analysis

1. Open the file at `failures[0].path` and go to `failures[0].line_number`. 2. Read the full test function and its setup/teardown. 3. Identify which of the common flaky patterns below applies. 4. Check if the test shares state with other tests in the same suite.

Common Flaky Patterns

Timing and async issues

  • **Missing waits**: Test checks a result before an async operation completes. Fix: use `await`, expectations with timeouts, or polling.
  • **Race conditions**: Multiple concurrent operations access shared state. Fix: synchronize access or use serial queues.
  • **Hardcoded timeouts**: `sleep(1)` or fixed delays that are too short on CI. Fix: use condition-based waits instead of fixed delays.

Shared state

  • **Test pollution**: One test modifies global/static state that another test depends on. Fix: reset state in setUp/tearDown or use unique instances per test.
  • **Singleton contamination**: Shared singletons carry state between tests. Fix: inject dependencies or reset singletons.
  • **File system leftovers**: Tests leave files that affect subsequent runs. Fix: use temporary directories and clean up.

Environment dependencies

  • **Network calls**: Tests hit real services that may be slow or unavailable. Fix: mock network calls.
  • **Date/time sensitivity**: Tests depend on current time or timezone. Fix: inject a clock or freeze time.
  • **File system paths**: Hardcoded paths that differ between environments. Fix: use relative paths or temp directories.

Order dependence

  • **Implicit ordering**: Test passes only when run after another test that sets up required state. Fix: make each test self-contained.
  • **Parallel execution conflicts**: Tests that work in isolation but fail when run concurrently. Fix: use unique resources per test.

Crashes (identified via `crash_report`)

  • `EXC_BREAKPOINT` / `SIGTRAP` — force-unwrap of nil, Swift precondition failure
  • `EXC_BAD_ACCESS` / `SIGSEGV` — use-after-free or dangling pointer
  • `EXC_CRASH` / `SIGABRT` — uncaught Objective-C exception

Fix Implementation

After identifying the pattern:

1. Apply the smallest fix that addresses the root cause. 2. Do not refactor unrelated code. 3. If the fix requires a test utility (like a mock or helper), check if one already exists before creating a new one.

Verification

Running tests repeatedly

Run the specific test repeatedly until failure using `xcodebuild`'s built-in repetition support:

xcodebuil
Read more
@tuist
Ships withtuist

Tuist is a build platform for engineering teams and their coding agents. It works with Xcode, Gradle, Bazel, Elixir, and Rust builds. Features vary by toolchain: Rust compilation caching is experimental, and Once support is in canary.

5.9k13 skills46 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
5.9k
Star history of tuist/tuist on GitHub, a chart by star-history.com

Other skills on tuist.

verifying-work-with-tuist

verifying-work-with-tu…

Checks a change against the project's history in Tuist before calling it done, so that flaky tests, failures that already happen…

@tuist@tuistInstall Skill
analyze-selective-testing

analyze-selective-test…

Analyzes Xcode selective testing effectiveness for a test run, showing which test targets were skipped or ran, and diagnosing…

@tuist@tuistInstall Skill
compare-builds

compare-builds

Compares two Xcode build runs to identify duration regressions, cache changes, and new issues. Can be invoked with build IDs,…

@tuist@tuistInstall Skill
compare-bundles

compare-bundles

Compares two app bundles to identify size changes, new or removed artifacts, and platform differences. Can be invoked with bundle…

@tuist@tuistInstall Skill
compare-cache-runs

compare-cache-runs

Compares two `tuist cache` runs to identify cache hit rate changes and root-cause analysis of cache invalidation. Can be invoked…

@tuist@tuistInstall Skill
compare-generations

compare-generations

Compares two `tuist generate` runs to identify cache hit rate changes and root-cause analysis of cache invalidation. Can be…

@tuist@tuistInstall Skill

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills2w309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android — semantic ARIA roles and labels,…

ecc2w293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commits…

react9d252k
@facebook@facebookInstall Skill

Questions about fix-flaky-tests.

Which coding agents can use fix-flaky-tests?
fix-flaky-tests installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.