Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

fixing-flaky-tests

БесплатноБез исполняемых скриптовНе проверен

Diagnose and fix flaky (intermittently failing) tests in Bitwarden iOS. Finds the root cause of non-deterministic test failures (race conditions, timing…

bitwardenот bitwarden★ 748 звёзд на GitHub

Об этом скилле

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:

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 target Scheme Unit test plan
BitwardenSharedTests, BitwardenTests, BitwardenAutoFillExtensionTests, BitwardenActionExtensionTests, BitwardenShareExtensionTests Bitwarden Bitwarden-Unit
AuthenticatorSharedTests, AuthenticatorTests, AuthenticatorBridgeKitTests Authenticator Authenticator-Unit
BitwardenKitTests BitwardenKit BitwardenKit-Unit
BitwardenKitViewInspectorTests BitwardenKit BitwardenKit-ViewInspector
NetworkingTests BitwardenKit BitwardenKit-Default

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

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

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

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

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

Полный SKILL.md на GitHub

Установить fixing-flaky-tests в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл fixing-flaky-tests?

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?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл fixing-flaky-tests запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить fixing-flaky-tests с