fix-flaky-tests
它能做什么
这项技能调查不稳定的自动化测试,即在代码没有改动的情况下时过时不过的测试,并加以修复。适合希望测试套件可靠的开发者。
适用场景
- ✓当 Tuist 将某个测试标记为不稳定,并且你希望修复它时。
- ✓当许多测试随机失败,你想找出共同原因的时候。
- ✓当你想在项目中发现并修复所有不稳定测试的时候。
技能链接
https://github.com/tuist/tuist/blob/main/skills/skills/fix-flaky-tests/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请找出我项目中的不稳定测试,并修复失败次数最多的那一个。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会读取每个不稳定测试的可靠性和失败细节,查看报告行所在的源代码,找出导致不稳定的模式并修复,然后多次运行该测试以确认。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Fix Flaky Tests
Quick Start
You'll typically receive a Tuist test case URL or identifier. Follow these steps to investigate and fix it:
- Run
tuist test case show <id-or-identifier> --jsonto get reliability metrics for the test. - Run
tuist test case run list Module/Suite/TestCase --flaky --jsonto see flaky run patterns. - Run
tuist test case run show <test-case-run-id> --jsonon failing flaky runs to get failure messages and file paths. - Read the test source at the reported path and line, identify the flaky pattern, and fix it.
- 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 identifieravg_duration— helps prioritize (fix fast unit tests first)is_quarantined— whether the test is already quarantined
Triage strategy:
- Group tests by suite — multiple flaky tests in the same suite often share a root cause.
- 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. - 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 daystotal_runs/failed_runs— volume contextlast_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 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); containsexception_type,signal,exception_subtype, andtriggered_thread_frames
Code Analysis
- Open the file at
failures[0].pathand go tofailures[0].line_number. - Read the full test function and its setup/teardown.
- Identify which of the common flaky patterns below applies.
- 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 tim
常见问题
它如何找到不稳定的测试?
它会列出 Tuist 测试洞察中被标记为不稳定的测试。
如果没有指定测试会怎样?
它会在项目中发现不稳定的测试,并按套件进行分组。
它如何确认修复有效?
它会多次运行该测试,检查其是否始终通过。
详情
作者的原始描述
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.
repo: tuist/tuist
热度
- GitHub 星标
- 5.9k
- 排名
- #14544
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
analyze-selective-testing
5.9k帮你的智能体检查 Xcode 选择性测试跳过未改动测试目标的效果,并找出两次运行之间跳过情况变化的原因。
compare-builds
5.9k帮你的智能体比较两次 Xcode 构建,找出变慢的构建、缓存使用的变化和新出现的问题。
compare-bundles
5.9k帮你的智能体比较两个应用包,找出体积变化、新增或删除的文件以及平台差异。
compare-cache-runs
5.9k帮你的智能体比较两次缓存运行,找出缓存命中率的变化,并解释缓存失效的原因。