Official agent skill

Fixing Flaky Tests

by bitwarden in bitwarden/ios

Diagnose and fix flaky (intermittently failing) tests in Bitwarden iOS.

OfficialGPL-3.0Auto-check passedTesting & QA

Install Fixing Flaky Tests

skills CLI
$ npx skills add bitwarden/ios --skill fixing-flaky-tests -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install bitwarden/ios fixing-flaky-tests --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/bitwarden/ios.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.claude/skills/fixing-flaky-tests .claude/skills/fixing-flaky-tests && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
fixing-flaky-tests
GitHub stars
695
Token cost
~2.3k tokens
SKILL.md length
934 words
Files
1
Skills in repo
11
Repo updated
First seen
Licence
GPL-3.0

At a glance

Diagnose and fix flaky (intermittently failing) tests in Bitwarden iOS.

  • Works in 7 steps: Locate the test(s) → Map the test to a scheme and test plan → Diagnose the root cause → …
  • A test is failing intermittently
  • SKILL.md covers Step 1: Locate the test(s), Step 2: Map the test to a…, Step 3: Diagnose the root cause and Step 4: Fix the test (or plan…, plus 4 more sections
  • Calls xcodebuild

What it does

Fixing Flaky Tests is an agent skill from bitwarden/ios, published by the product's own GitHub organization. Diagnose and fix flaky (intermittently failing) tests in Bitwarden iOS. Finds the root cause of non-deterministic test failures (race conditions, timing issues, shared state, order dependence), applies a targeted fix, then stress-tests the fix by running the test 100 times to confirm stability. Use this skill whenever a test is failing intermittently, sometimes passes / sometimes fails, or someone describes a test as flaky, unstable, or non-deterministic — even if the exact cause is unknown. Trigger phrases: "fix…

Its SKILL.md is about 2.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Testing & QA, covering Failing and flaky tests. It works with iOS. The repository describes itself as: Bitwarden mobile apps (Password Manager and Authenticator) for iOS. The licence is GPL-3.0.

When your agent uses it

  • A test is failing intermittently
  • Sometimes passes / sometimes fails
  • Someone describes a test as flaky
  • Non-deterministic — even if the exact cause is unknown

Example prompts

  • “fix flaky test”
  • “test is flaky”
  • “test keeps failing”
  • “/fixing-flaky-tests”

Workflow steps

7 steps, taken from the step headings in SKILL.md.

  1. Locate the test(s)
  2. Map the test to a scheme and test plan
  3. Diagnose the root cause
  4. Fix the test (or plan the SUT change)
  5. Verify the fix — run the test 100 times
  6. Run the full unit test suite (once)
  7. Final verification — run the build-test-verify skill

What it can do on your machine

Read from SKILL.md and the folder at commit 6399b1d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • xcodebuild

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Fixing Flaky Tests loads about 2.3k tokens when it runs. Until then it costs about 172 tokens; SKILL.md has 934 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~172
When it runs · the whole SKILL.md, loaded when a task matches
~2.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from bitwarden/ios at commit 6399b1d, republished under its GPL-3.0 licence (© bitwarden). 934 words, ~2,274 tokens.

Download SKILL.mdSave it as .claude/skills/fixing-flaky-tests/SKILL.md (or your agent's skills folder).
name
fixing-flaky-tests
description
Diagnose and fix flaky (intermittently failing) tests in Bitwarden iOS. Finds the root cause of non-deterministic test failures (race conditions, timing issues, shared state, order dependence), applies a targeted fix, then stress-tests the fix by running the test 100 times to confirm stability. Use this skill whenever a test is failing intermittently, sometimes passes / sometimes fails, or someone describes a test as flaky, unstable, or non-deterministic — even if the exact cause is unknown. Trigger phrases: "fix flaky test", "test is flaky", "test keeps failing", "intermittent failure", "test is non-deterministic", "test fails sometimes", "test randomly fails".

Fixing Flaky Tests — Bitwarden iOS

A flaky test passes sometimes and fails other times without any code change. Flakiness usually comes from a small set of root causes. Your job is to find which one applies, fix it surgically, and then prove the fix holds by running the test many times.

Step 1: Locate the test(s)

Search for the function name(s) the user provided:

bash
grep -r "func <testFunctionName>" . --include="*.swift" -l

Note that:

  • XCTest functions are named test_<methodName>_<description> (prefix required by XCTest)
  • Swift Testing functions use the @Test macro and can have any name — the test_ prefix is conventional but not required

For each test:

  • Read the full test function and the class it belongs to
  • Read the @testable import at the top of the file — that's the module under test (e.g., @testable import BitwardenShared → module BitwardenShared)
  • Read the SUT code being exercised by the test

Step 2: Map the test to a scheme and test plan

Test targetSchemeUnit test plan
BitwardenSharedTests, BitwardenTests, BitwardenAutoFillExtensionTests, BitwardenActionExtensionTests, BitwardenShareExtensionTestsBitwardenBitwarden-Unit
AuthenticatorSharedTests, AuthenticatorTests, AuthenticatorBridgeKitTestsAuthenticatorAuthenticator-Unit
BitwardenKitTestsBitwardenKitBitwardenKit-Unit
BitwardenKitViewInspectorTestsBitwardenKitBitwardenKit-ViewInspector
NetworkingTestsBitwardenKitBitwardenKit-Default

When in doubt, search TestPlans/ for the test class name to confirm the plan (and therefore scheme):

bash
grep -r "<TestClassName>" TestPlans/ -l

Always read the simulator config from the project files rather than hardcoding:

bash
DEVICE=$(tr -d '\n' < .test-simulator-device-name)
OS=$(tr -d '\n' < .test-simulator-ios-version)

Step 3: Diagnose the root cause

Read the test carefully and the SUT it exercises. Flaky tests in Swift/iOS typically fall into one of these categories:

Race condition / async ordering The test observes a side effect before the async SUT has finished producing it. Signs: bare Task.sleep or DispatchQueue.asyncAfter in the test, expectations that time out occasionally, @MainActor-isolated code whose scheduling the test doesn't account for.

Shared mutable state State from one test bleeds into the next. Signs: static properties or singletons not reset in tearDown, NotificationCenter observers not removed, Task or DispatchQueue.async work from a previous test still running when the next one starts.

Time / date dependence The SUT reads Date() or Calendar.current inline, so the test result depends on the real clock. Signs: test passes during the day but fails near midnight, or fails only under heavy load when wall-clock timing drifts.

Order dependence Test execution order is randomized in the -Default test plans ("testExecutionOrdering" : "random"), but the -Unit plans used for verification here run sequentially. To reproduce order-dependent flakiness, run against the -Default plan rather than -Unit.

Resource contention CoreData, Keychain, or file system state left behind by a previous run.

Step 4: Fix the test (or plan the SUT change)

Fixes in the test file only — apply and move on

Replacing bare delays with condition polling: Use the project's test helpers instead of a fixed sleep. These are available to all test targets:

  • XCTest (subclasses of BaseBitwardenTestCase):

    • waitFor { condition } — spins the run loop; use when the SUT uses Timer.scheduledTimer
    • waitForAsync { condition } — polls asynchronously; use for Swift Concurrency-based SUT code
  • Swift Testing (SwiftTestingHelpers.swift):

    • try await waitForAsync { condition } — polls asynchronously in @Test functions
    • waitFor(condition) — spins the run loop in @Test functions using @MainActor
    • await withContinuationTimeout { resume in … } — wraps callback-based async code so the test fails cleanly rather than hanging if the callback is never called

Shared state:

  • Move subject and dependency properties from static var to instance var
  • Reset all mutable properties in tearDown / addTeardownBlock
  • Remove NotificationCenter observers: addTeardownBlock { NotificationCenter.default.removeObserver(token) }

CoreData / Keychain leaks:

  • Use .memory store type when constructing AuthenticatorBridgeDataStore or any CoreData stack in tests so nothing persists to disk between runs
Show full SKILL.md (373 more words)Show less
If the fix requires changing the SUT (production code)

Stop before touching production code. Present the plan:

  1. The root cause
  2. The specific SUT file, line, and change (what pattern to replace with what)
  3. Why a test-only fix is insufficient

Then ask: "Would you like me to proceed, or would you prefer to handle the SUT change separately?"

The most common SUT fix is replacing an inline Date() or Calendar.current call with an injected TimeProvider (protocol in BitwardenKit/Core/Platform/Services/TimeProvider.swift), then using MockTimeProvider in the test.

Only proceed with SUT edits after the user agrees.

Step 5: Verify the fix — run the test 100 times

Build first so the changes are compiled:

bash
xcodebuild build-for-testing \
  -workspace Bitwarden.xcworkspace \
  -scheme <SCHEME> \
  -destination "platform=iOS Simulator,name=$DEVICE,OS=$OS" \
  2>&1 | grep -E "error:|BUILD (SUCCEEDED|FAILED)"

Then stress-test the fixed test using -test-iterations, which runs N repetitions in a single simulator session (far faster than re-launching xcodebuild 100 times):

bash
xcodebuild test-without-building \
  -workspace Bitwarden.xcworkspace \
  -scheme <SCHEME> \
  -only-testing:"<TARGET_NAME>/<TestClassName>/<testFunctionName>" \
  -test-iterations 100 \
  -test-repetition-mode count-up \
  -destination "platform=iOS Simulator,name=$DEVICE,OS=$OS" \
  2>&1 | grep -E "(Test Case|Executed|error:|FAILED)" | tail -20

<TARGET_NAME> is the test bundle (e.g., BitwardenSharedTests), <TestClassName> is the class (e.g., MyProcessorTests), and <testFunctionName> is the Swift function name exactly as written.

Interpreting results:

  • Executed 100 tests, with 0 failures → fix holds, proceed to Step 6
  • Any failure → return to Step 3; the root cause wasn't fully addressed

Step 6: Run the full unit test suite (once)

Confirm the fix didn't accidentally break anything else in the same target:

bash
xcodebuild test \
  -workspace Bitwarden.xcworkspace \
  -scheme <SCHEME> \
  -testPlan <SCHEME>-Unit \
  -destination "platform=iOS Simulator,name=$DEVICE,OS=$OS" \
  2>&1 | grep -E "(Test Suite|error:|FAILED|Executed)" | tail -30

The <SCHEME>-Unit plan (e.g., Bitwarden-Unit) excludes snapshot and ViewInspector tests, keeping the run fast and focused on correctness. If any other test fails, investigate whether the fix introduced a regression before proceeding.

Step 7: Final verification — run the build-test-verify skill

As the last step, invoke the build-test-verify skill to confirm the full pipeline is clean (lint, formatter, spell check):

Skill: build-test-verify

Quick reference

SymptomLikely causeFix
Bare try await Task.sleep(…) after triggering async SUTSide effect races the sleepReplace with waitForAsync { … }
Timer.scheduledTimer result observed immediatelyRun loop not spinningUse waitFor { … } (spins run loop)
Callback never called → hangMissing continuation timeoutUse withContinuationTimeout { resume in … }
static var on subject or dependencyShared state across testsMove to instance var, reset in tearDown
NotificationCenter.addObserver without removeObserverObserver leaksaddTeardownBlock { NotificationCenter.default.removeObserver(token) }
Date() / Calendar.current inline in SUTWall-clock dependenceInject TimeProvider; use MockTimeProvider in tests
waitForExpectations(timeout: 0.1)Timeout too tight under loadIncrease timeout or replace with waitForAsync
CoreData state persists across testsDisk-backed store in testsUse .memory store type

© bitwarden, GPL-3.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .claude/skills/fixing-flaky-tests of bitwarden/ios.

Open the folder on GitHubat commit 6399b1d

Compare with similar skills

Fixing Flaky Tests next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Fixing Flaky Tests compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Fixing Flaky Tests this skillbitwarden/ios695—~2.3kAutomated safety check: PassGPL-3.0
Macios CI Failure Inspectordotnet/macios2.9k—~2.3kAutomated safety check: PassCustom licence
Codex Local CLI E2Erebornix/Agmente545—~625Automated safety check: PassMIT
Fix Random CI Test Failuredotnet/macios2.9k—~1.3kAutomated safety check: PassCustom licence
Diagnosing Bugsgetsentry/sentry-react-native1.8k—~1.4kAutomated safety check: PassMIT
MAUI UI Test Writerdotnet/maui23k—~3kAutomated safety check: PassMIT

Similar skills

  • Official

    Investigate and triage CI failures for dotnet/macios from Azure DevOps build URLs.

    2.9k GitHub stars~2.3k tokensUpdated today
    Testing & QAAuto-check passed
  • Codex Local CLI E2E

    rebornix/Agmente

    Run and debug Agmente iOS end-to-end tests against a real local Codex CLI app-server instance.

    545 GitHub stars~625 tokensUpdated 4 mo ago
    Testing & QAAuto-check passed
  • Official

    Investigate and fix flaky/random CI test failures in dotnet/macios.

    2.9k GitHub stars~1.3k tokensUpdated today
    Testing & QAAuto-check passed
  • Diagnosing Bugs

    getsentry/sentry-react-native

    Official

    A discipline for hard bugs, flaky tests, CI hangs, native crashes, and performance regressions in this SDK.

    1.8k GitHub stars~1.4k tokensUpdated today
    Testing & QAAuto-check passed
  • Official

    Writes UI tests that reproduce a GitHub issue in .NET MAUI and keeps iterating until the tests actually fail, proving they catch the bug.

    23k GitHub stars~3k tokensUpdated today
    Testing & QAAuto-check passed
  • Debug

    woocommerce/woocommerce-ios

    Debug a failing test or build error in WooCommerce iOS. An agent skill from woocommerce/woocommerce-ios.

    358 GitHub stars~539 tokensUpdated today
    Testing & QAAuto-check: notes

More from bitwarden/ios

All 11 skills in this repo
  • Testing iOS Code

    bitwarden/ios

    Official

    Write tests, add test coverage, unit test, or add missing tests for Bitwarden iOS.

    695 GitHub stars~1.8k tokensUpdated today
    Auto-check passed
  • Official

    Build the Bitwarden iOS app, capture all compiler and lint warnings, categorize them into Swift 6 concurrency vs actionable, and interactively fix the actionable ones.

    695 GitHub stars~1.9k tokensUpdated today
    Auto-check passed
  • Build Test Verify

    bitwarden/ios

    Official

    Build the project, run tests, lint, format, spell check, generate mocks, or verify the build passes for Bitwarden iOS.

    695 GitHub stars~1.3k tokensUpdated today
    Auto-check passed
  • Official

    Convert a hand-written bespoke mock to a Sourcery AutoMockable-generated mock.

    695 GitHub stars~3.5k tokensUpdated today
    Auto-check passed
  • Official

    Evaluates a bitwarden/ios "Update SDK to" PR against the sdk-swift commit range for compile-time, runtime and serialization breaking changes, maps affected symbols to iOS call sites, and applies…

    695 GitHub stars~2.6k tokensUpdated today
    Auto-check passed
  • Official

    Implement, write code, add a new screen, create a feature, new view, new processor, or wire up a new service in Bitwarden iOS.

    695 GitHub stars~1.9k tokensUpdated today
    Auto-check passed

Works with

Categories

Questions about Fixing Flaky Tests

What does Fixing Flaky Tests do?

Diagnose and fix flaky (intermittently failing) tests in Bitwarden iOS. Fixing Flaky Tests is an agent skill from bitwarden/ios, published by the product's own GitHub organization. Diagnose and fix flaky (intermittently failing) tests in Bitwarden iOS.

When should I use Fixing Flaky Tests?

Fixing Flaky Tests fits situations like: A test is failing intermittently; sometimes passes / sometimes fails; someone describes a test as flaky; non-deterministic — even if the exact cause is unknown.

How do I install Fixing Flaky Tests in Claude Code?

Run `npx skills add bitwarden/ios --skill fixing-flaky-tests -a claude-code`. Or copy the skill folder (.claude/skills/fixing-flaky-tests in bitwarden/ios) into .claude/skills/fixing-flaky-tests in your project. Claude Code loads it when a task matches its description.

How do I install Fixing Flaky Tests in Codex?

Run `npx skills add bitwarden/ios --skill fixing-flaky-tests -a codex`. Or copy the skill folder (.claude/skills/fixing-flaky-tests in bitwarden/ios) into .agents/skills/fixing-flaky-tests in your project. Codex loads it when a task matches its description.

Can I use Fixing Flaky Tests in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add bitwarden/ios --skill fixing-flaky-tests -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/fixing-flaky-tests, .gemini/skills/fixing-flaky-tests, .github/skills/fixing-flaky-tests and .opencode/skills/fixing-flaky-tests in your project.

What does Fixing Flaky Tests need to run?

Going by SKILL.md and its folder, Fixing Flaky Tests needs the command-line tools its instructions call (xcodebuild).

Does Fixing Flaky Tests access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Fixing Flaky Tests safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Fixing Flaky Tests use?

Fixing Flaky Tests is published under the GPL-3.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Fixing Flaky Tests use?

About 2.3k tokens (SKILL.md is roughly 9.1k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Fixing Flaky Tests?

Skills that share tags, products or a category with Fixing Flaky Tests: Macios CI Failure Inspector (dotnet/macios, 2.9k stars), Codex Local CLI E2E (rebornix/Agmente, 545 stars), Fix Random CI Test Failure (dotnet/macios, 2.9k stars) and Diagnosing Bugs (getsentry/sentry-react-native, 1.8k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Fixing Flaky Tests?

bitwarden (a GitHub organization, an official publisher) maintains it in bitwarden/ios, which has 695 GitHub stars. The repository holds 11 skills in this directory. The repository was last updated on October 7, 2026.

Source: bitwarden/ios on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.