fix-flaky-tests

tuist/agent-skills · updated Apr 8, 2026

MDX-style export adds YAML metadata + attribution linking explainx.ai and this canonical listing URL.

$npx skills add https://github.com/tuist/agent-skills --skill fix-flaky-tests
0 commentsdiscussion
summary

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

skill.md

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:

xcodebuild test -workspace <workspace> -scheme <scheme> -only-testing <module>/<suite>/<test> -test-iterations <count> -run-tests-until-failure

This runs the test up to <count> times and stops at the first failure. Choose the iteration count based on how long the test takes — for fast unit tests use 50–100, for slower integration or acceptance tests use 2–5.

Reproducing before fixing

Before applying a fix, try to reproduce the flaky failure locally. A successful reproduction confirms your root cause analysis and lets you verify the fix directly. Use the "Running tests repeatedly" approach above, or the race condition strategies below if concurrency is suspected.

Some flaky scenarios — especially race conditions, CI-specific timing issues, or environment-dependent failures — may be difficult or impossible to reproduce locally. If you cannot reproduce after reasonable effort, proceed with fixing based on code analysis and failure logs. A fix backed by clear evidence of a bug (e.g. unsynchronized shared state, TOCTOU pattern) is valid even without local reproduction.

Reproducing race conditions

Race conditions and concurrency bugs often only manifest under CI-level parallelism and are hard to reproduce locally. Try these strategies in order:

  1. Increase parallelism: Add -parallel-testing-enabled YES to run test suites concurrently.
  2. Run broader test suites: Instead of running a single test, run the entire module (e.g. -only-testing ModuleTests) to increase contention on shared resources.
  3. Thread Sanitizer: Run with TSan enabled to detect data races deterministically. Note: TSan adds overhead which can change timing, so some races may not trigger under TSan.
xcodebuild test -workspace <workspace> -scheme <scheme> -only-testing <module> -enableThreadSanitizer YES
  1. High iteration count with broad scope: Combine all the above — run the full module with parallelism and many iterations.

If a race condition cannot be reproduced locally but the code is provably thread-unsafe (e.g. unsynchronized mutation of shared state), the fix is still valid. Verify the fix by confirming the tests pass with the same reproduction strategies above. Document in the commit message that the fix addresses a CI-only race condition identified through code analysis and failure logs.

Done Checklist

  • Identified the root cause of flakiness
  • Applied a targeted fix
  • Verified the test passes consistently (multiple runs)
  • Did not introduce new test dependencies or shared state
  • Committed the fix with a descriptive message
how to use fix-flaky-tests

How to use fix-flaky-tests on Cursor

AI-first code editor with Composer

1

Prerequisites

Before installing skills in Cursor, ensure your development environment meets these requirements:

  • Cursor installed and configured on your development machine
  • Node.js version 16.0+ with npm package manager (verify with node --version)
  • Active project directory or workspace where you want to add fix-flaky-tests
2

Execute installation command

Execute the skills CLI command in your project's root directory to begin installation:

$npx skills add https://github.com/tuist/agent-skills --skill fix-flaky-tests

The skills CLI fetches fix-flaky-tests from GitHub repository tuist/agent-skills and configures it for Cursor.

3

Select Cursor when prompted

The CLI will show a list of available agents. Use arrow keys to navigate and space to select Cursor:

◆ Which agents do you want to install to?
│ ── Universal (.agents/skills) ── always included ────
│ • Amp
│ • Antigravity
│ • Cline
│ • Codex
│ ●Cursor(selected)
│ • Cursor
│ • Windsurf
4

Verify installation

Confirm successful installation by checking the skill directory location:

.cursor/skills/fix-flaky-tests

Reload or restart Cursor to activate fix-flaky-tests. Access the skill through slash commands (e.g., /fix-flaky-tests) or your agent's skill management interface.

Security & Verification Notice

We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.

Skills execute code in your development environment. Always verify the publisher's identity, review recent commits, and test in isolated environments before production deployment.

List & Monetize Your Skill

Submit your Claude Code skill and start earning

GET_STARTED →

Use Cases

Task Automation & Efficiency

Automate repetitive workflows and reduce manual effort

Example

Generate reports, summarize documents, draft communications

Save 3-5 hours per week on routine tasks

Knowledge Enhancement

Learn new skills, understand complex topics, get expert guidance

Example

Explain concepts, provide examples, suggest learning resources

Accelerate learning and skill development by 2x

Quality Improvement

Enhance output quality through reviews, suggestions, and refinements

Example

Review drafts, suggest improvements, catch errors

Improve work quality by 30-40% with less effort

Implementation Guide

Prerequisites

  • Claude Desktop or compatible AI client with skill support
  • Clear understanding of task or problem to solve
  • Willingness to iterate and refine outputs

Time Estimate

15-45 minutes depending on use case complexity

Installation Steps

  1. 1.Install skill using provided installation command
  2. 2.Test with simple use case relevant to your work
  3. 3.Evaluate output quality and relevance
  4. 4.Iterate on prompts to improve results
  5. 5.Integrate into regular workflow if valuable

Common Pitfalls

  • Expecting perfect results without iteration
  • Not providing enough context in prompts
  • Using skill for tasks outside its intended scope
  • Accepting outputs without review and validation

Best Practices

✓ Do

  • +Start with clear, specific prompts
  • +Provide relevant context and constraints
  • +Review and refine all outputs before using
  • +Iterate to improve output quality
  • +Document successful prompt patterns

✗ Don't

  • Don't use without understanding skill limitations
  • Don't skip validation of outputs
  • Don't share sensitive information in prompts
  • Don't expect skill to replace human judgment

💡 Pro Tips

  • Be specific about desired format and style
  • Ask for multiple options to choose from
  • Request explanations to understand reasoning
  • Combine AI efficiency with human expertise

When to Use This

✓ Use When

Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.

✗ Avoid When

Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.

Learning Path

  1. 1Familiarize yourself with skill capabilities and limitations
  2. 2Start with low-risk, non-critical tasks
  3. 3Progress to more complex and valuable use cases
  4. 4Build expertise through regular use and experimentation

Discussion

Product Hunt–style comments (not star reviews)
  • No comments yet — start the thread.
general reviews

Ratings

4.564 reviews
  • Yuki Mehta· Dec 28, 2024

    Registry listing for fix-flaky-tests matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Shikha Mishra· Dec 20, 2024

    Useful defaults in fix-flaky-tests — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Camila Reddy· Dec 16, 2024

    I recommend fix-flaky-tests for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.

  • Layla Farah· Dec 12, 2024

    Useful defaults in fix-flaky-tests — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.

  • Chinedu Sharma· Nov 19, 2024

    fix-flaky-tests fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Rahul Santra· Nov 11, 2024

    fix-flaky-tests is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Maya Shah· Nov 7, 2024

    Keeps context tight: fix-flaky-tests is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Layla Liu· Nov 3, 2024

    fix-flaky-tests is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Diego Singh· Oct 26, 2024

    fix-flaky-tests is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Fatima Li· Oct 22, 2024

    Keeps context tight: fix-flaky-tests is the kind of skill you can hand to a new teammate without a long onboarding doc.

showing 1-10 of 64

1 / 7