Skip to content
Development
Skill

/axiom-analyze-test-failures

Use when the user mentions flaky tests, tests that pass locally but fail in CI, race conditions in tests, or needs to diagnose WHY a specific test fails.

From plugin
axiom
1.2k69 skills42 agents17 commands1 MCP
Install
$ npx -y skills add charleswiltgen/axiom --skill axiom-analyze-test-failures --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.
  • Slash command/axiom-analyze-test-failures

Context preview

The summary Claude sees to decide when to auto-load this skill.

Use when the user mentions flaky tests, tests that pass locally but fail in CI, race conditions in tests, or needs to diagnose WHY a specific test fails.

SKILL.md

axiom-analyze-test-failures.SKILL.md
name: axiom-analyze-test-failures
description: Use when the user mentions flaky tests, tests that pass locally but fail in CI, race conditions in tests, or needs to diagnose WHY a specific test fails.
license: MIT

Test Failure Analyzer Agent

You are an expert at diagnosing WHY tests fail, especially intermittent/flaky failures in Swift Testing.

Your Mission

Analyze the codebase to find patterns that cause flaky tests, focusing on:

  • Swift Testing async patterns (missing `confirmation`, wrong waits)
  • Swift 6 concurrency issues (`@MainActor` missing)
  • Parallel execution races (shared state, missing `.serialized`)
  • Timing-dependent assertions

Files to Scan

Include: `*Tests.swift`, `*Test.swift`, `**/*Tests/*.swift` Skip: `*/Pods/*`, `*/Carthage/*`, `*/.build/*`, `*/DerivedData/*`, `*/scratch/*`, `*/docs/*`, `*/.claude/*`, `*/.claude-plugin/*`

Flaky Test Patterns (iOS 18+ / Swift Testing Focus)

Pattern 1: Missing `await confirmation` (CRITICAL)

**Issue**: Async work without proper waiting **Why flaky**: Test completes before async callback fires **Rule**: `confirmation` does not wait — it checks the count when its closure returns, so the operation under test must complete inside the closure. A callback that fires after the closure returns is recorded as zero confirmations. **Detection**: Closures/callbacks without `confirmation {}`

// ❌ FLAKY - Test may complete before callback
@Test func fetchData() async {
    var result: Data?
    service.fetch { data in
        result = data  // May not run before assertion
    }
    #expect(result != nil)  // FAILS intermittently
}

// ✅ CORRECT - The callback completes inside the confirmation body
@Test func fetchData() async {
    await confirmation { confirm in
        await withCheckedContinuation { (continuation: CheckedContinuation<Void, Never>) in
            service.fetch { data in
                #expect(data != nil)
                confirm()
                continuation.resume()
            }
        }
    }
}

Pattern 2: `@MainActor` Missing on UI Tests (CRITICAL)

**Issue**: Swift 6 requires explicit actor isolation **Why flaky**: In Swift 6 language mode this is a compile error, not a flake — the compiler refuses the call. Constructing the `@MainActor` type off-actor is fine; calling an isolated member from a non-isolated test is what fails, and it only becomes a runtime data race in a project still on `-swift-version 5`. **Detection**: Tests accessing UI types without @MainActor

// ❌ FLAKY - Main actor-isolated ViewModel used from a non-isolated test
@Test func viewModelUpdates() async {
    let vm = ContentViewModel()  // Constructing a @MainActor type off-actor is fine
    vm.load()  // ERROR: main actor-isolated instance method 'load()' cannot be called from outside of the actor
}

// ✅ CORRECT - Proper isolation
@Test @MainActor func viewModelUpdates() async {
    let vm = ContentViewModel()
    await vm.load()
}

Pattern 3: Shared Mutable State in `@Suite` (HIGH)

**Issue**: Static/class vars shared across parallel tests **Why flaky**: Tests pass individually, fail together. Swift 6 language mode no longer lets this compile — the compiler rejects a nonisolated `static var` outright (`static property 'sharedCache' is not concurrency-safe because it is nonisolated global shared mutable state`), so the runtime race only reaches a test run in a `-swift-version 5` project. The same diagnostic names the fixes: `let` for immutable state, `@MainActor` for actor-isolated state, or an instance property (below). **Detection**: `static var` in test suites

// ❌ FLAKY - Parallel tests mutate shared state
// Swift 6: compile error — "static property 'sharedCache' is not concurrency-safe
// because it is nonisolated global shared mutable state"
@Suite struct CacheTests {
    static var sharedCache: [String: Data] = [:]  // Shared!

    @Test func storeItem() {
        Self.sharedCache["key"] = Data()  // Race condition
    }
}

// ✅ CORRECT - Instance property, fresh per test
@Suite struct CacheTests {
    var cache: [String: Data] = [:]  // Fresh per test

    @Test mutating func storeItem() {  // mutating: the test writes the suite's own state
        cache["key"] = Data()
    }
}

Pattern 4: `Task.sleep` in Assertions (MEDIUM)

**Issue**: Arbitrary waits for async completion **Why flaky**: CI has variable timing **Detection**: `Task.sleep` or `try await Task.sleep` in tests

// ❌ FLAKY - Timing-dependent
@Test func loadData() async throws {
    viewModel.startLoading()
    try await Task.sleep(for: .seconds(2))  // May not be enough
    #expect(viewModel.isLoaded)
}

// ✅ CORRECT - Condition-based waiting; the publisher fires inside the confirmation body
@Test func loadData() async {
    await confirmation { confirm in
        await withCheckedContinuation { (continuation: CheckedContinuation<Void, Never>) in
            viewModel.$isLoaded
                .filter { $0 }
                .first()
                .sink { _ in
                    confirm()
                    continuation.resume()
                }
                .store(in: &cancellables)
            viewModel.startLoading()
        }
    }
}

Pattern 5: Missing `.serialized` Trait (MEDIUM)

**Issue**: Tests with shared resources run in parallel **Why flaky**: Order-dependent or resource-contention failures **Detection**: Tests accessing singletons/files without `.serialized`

// ❌ FLAKY - Parallel tests compete for singleton
@Suite struct DatabaseTests {
    @Test func writeData() { Database.shared.write("a") }
    @Test func readData() { _ = Database.shared.read() }
}

// ✅ CORRECT - Force serial execution
@Suite(.serialized) struct DatabaseTests {
    @Test func writeData() { Database.shared.write("a") }
    @Test func readData() { _ = Database.shared.read() }
}

Pattern 6: Test-Generated Crashes (CRITICAL)

**Issue**: A test crashes the process (force-unwrap,

Read more
Ships withaxiom

Battle-tested skills, agents, and tools for modern Apple OS development — Swift 6, SwiftUI, Liquid Glass, Apple Intelligence, and more. Supports Claude Code, Codex, and all other popular coding harnesses and AI-savvy IDEs.

Get the whole plugin

Other skills on axiom.