Debugging & Incident Diagnosis
Compatible with Cursor, Claude Code, Cline, Roo Code, Antigravity

Flaky CI Test & Async Timing Resolution

Fix nondeterministic test failures, unhandled async promises, and race conditions in Playwright, Jest, or Vitest.

TestingPlaywrightVitestJestCI/CDAsync
Skill Objective

Eliminate arbitrary sleep timers, race conditions, shared mutable state, and unhandled promises in flaky automated test suites.

Execution Workflow Procedure

Ordered steps the coding agent executes when performing this skill.

1

Locate Nondeterminism Triggers

Scan test files for hardcoded setTimeout / sleep calls, shared database fixtures, and missing await statements.

2

Implement Event-Driven Polling

Replace arbitrary time delays with auto-retrying assertions (e.g. waitFor, expect.poll, findBy).

3

Ensure Test Isolation

Verify that mocks, timers, and database state are cleanly wiped in beforeEach and afterEach hooks.

Agent Safety Guardrails & Anti-Hallucination Rules

  • DO NOT increase sleep durations to fix flaky tests; replace them with event-driven synchronization.
  • DO NOT allow tests to mutate shared global state across parallel workers.

Expected Output Format

Flakiness root cause and 100% deterministic test implementation.

🔍 Flakiness Root Cause: Race condition or timer flaw explanation.
🛠️ Deterministic Test Code: Refactored test with auto-retrying assertions.

Domain Verification Checks

Zero Hardcoded Sleep: Replaces setTimeout with condition-polling assertions.
Database Isolation: Wraps tests in rollback transactions or generates isolated schemas.
Parallel Safety: Ensures test suite can run concurrently without collisions.

Example Agent Invocations

"Fix this flaky Playwright end-to-end test that fails intermittently on GitHub Actions."
"Refactor this Vitest async component test to eliminate setTimeout sleep waits."

Install / Configure This Skill

# Place in .cursorrules or create .cursor/rules/flaky-ci-test-async-resolution.mdc
# Trigger: Whenever you perform flaky ci test & async timing resolution

---
name: flaky-ci-test-async-resolution
description: Eliminate nondeterministic test failures, race conditions, and arbitrary sleep waits in automated test suites.
version: 1.0.0
compatibility: [Cursor, Claude Code, Cline, Roo Code, Antigravity]
---

# Flaky CI Test & Async Timing Resolution

## Objective
Convert flaky, timing-sensitive test suites into 100% deterministic, fast-running automated tests.

## Workflow
1. **Flakiness Detection**: Find arbitrary sleep timers, unawaited promises, and shared state collisions.
2. **Event-Driven Synchronization**: Replace timers with polling assertions (`waitFor`, `expect.poll`).
3. **Fixture Isolation**: Clean mocks and test data before and after each run.
Complementary Agent Prompt

Need a quick one-time prompt for chat?

Try the Flaky Test & Async Timing Race Condition Debugger — a lightweight version designed for 1-click copying directly into Claude, ChatGPT, or Cursor chat.

View Prompt

SprintKit Workflow Integrations

Complementary tools and checklists to pair with this agent workflow.

Related Agent Skills

Explore related procedural workflows in this discipline.

All Skills

Comprehensive Unit Test Suite Generation (AAA Pattern)

Generate mutation-tested unit tests with Arrange-Act-Assert structure, boundary cases, and proper mock boundaries.

TestingJUnitVitest+3
3 workflow stepsView skill

GitHub Actions CI/CD Pipeline & Caching Optimization

Speed up slow GitHub Actions workflows with dependency caching, matrix parallelization, and security secrets.

GitHub ActionsCI/CDDevOps+2
3 workflow stepsView skill

Next.js App Router & React Server Components Review

Inspect Next.js App Router code for RSC boundaries, data fetching waterfalls, caching, and hydration safety.

ReactNext.jsTypeScript+2
4 workflow stepsView skill