Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计提醒

fix-flaky-tests修复不稳定的测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

6,952

周安装

284

GitHub Stars

33

下载量

2,249
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:fix-flaky-tests(修复不稳定的测试)
来源仓库:https://github.com/tuist/agent-skills
仓库路径:skills/fix-flaky-tests
安装命令:
npx skills add https://github.com/tuist/agent-skills --skill fix-flaky-tests
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

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

简介

用于辅助测试设计、自动化测试和回归验证。

  • 适合编写单元测试、端到端测试或分析失败日志。
  • 通过 npx skills add 命令从 tuist/agent-skills 仓库安装。
  • 需确认项目测试框架和运行命令配置。fix-flaky-tests 属于研究检索类 Skill,可作为该场景下的辅助能力补充。
  • 避免为通过测试而破坏真实业务逻辑。

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

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.24%
按下载量换算793

Claude

33.69%
按下载量换算758

Cursor

18.38%
按下载量换算413

Gemini CLI

10.5%
按下载量换算236

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills