skills/skills/fix-flaky-tests/SKILL.md
You'll typically receive a Tuist test case URL or identifier. Follow these steps to investigate and fix it:
tuist test case show <id-or-identifier> --json to get reliability metrics for the test.tuist test case run list Module/Suite/TestCase --flaky --json to see flaky run patterns.tuist test case run show <test-case-run-id> --json on failing flaky runs to get failure messages and file paths.If no specific test is provided, start with the Discovery section below.
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 identifieravg_duration — helps prioritize (fix fast unit tests first)is_quarantined — whether the test is already quarantinedTriage strategy:
test_run_id — tests that all failed in the same run may have been killed by a process crash, not individual test bugs.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 daystotal_runs / failed_runs — volume contextlast_status — current statetuist 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.
tuist test case run list Module/Suite/TestCase --json --page-size 20
Look for patterns:
is_ci: true) or also locally?tuist test case run show <test-case-run-id> --json
Key fields:
failures[].message — the assertion or error messagefailures[].path — source file pathfailures[].line_number — exact line of failurefailures[].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 tocrash_report — crash report data (present when the test runner crashed); contains exception_type, signal, exception_subtype, and triggered_thread_framesfailures[0].path and go to failures[0].line_number.await, expectations with timeouts, or polling.sleep(1) or fixed delays that are too short on CI. Fix: use condition-based waits instead of fixed delays.crash_report)EXC_BREAKPOINT / SIGTRAP — force-unwrap of nil, Swift precondition failureEXC_BAD_ACCESS / SIGSEGV — use-after-free or dangling pointerEXC_CRASH / SIGABRT — uncaught Objective-C exceptionAfter identifying the pattern:
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.
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.
Race conditions and concurrency bugs often only manifest under CI-level parallelism and are hard to reproduce locally. Try these strategies in order:
-parallel-testing-enabled YES to run test suites concurrently.-only-testing ModuleTests) to increase contention on shared resources.xcodebuild test -workspace <workspace> -scheme <scheme> -only-testing <module> -enableThreadSanitizer YES
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.