Saas test flakiness

From Basinfy/Basinfy-SaaS-Studio · View interactive version

Saas test flakiness is an AI agent skill from the GitHub repository Basinfy/Basinfy-SaaS-Studio. Detect intermittent flaky tests across CI runs and recommend deterministic fixes.

How to use this skill

Skill file

<!-- Generated from .claude/skills by scripts/sync-agent-skills.py. -->

Running this workflow on this client

Run commands from the project root (use Git Bash on Windows if bash points to an unavailable WSL distro). Shared studio files live in .claude/; follow .agents/PORTABLE-RUNTIME.md and .claude/docs/config-resolution.md for client tools, delegation, and approval rules.

Run bash .claude/hooks/yaml-helper.sh resolve_config --keys locale,automation and use its output below.

Automation mode: Resolve modes.automation (project.local.yaml →

project.yaml → default collaborative). Every AskUserQuestion call and

every file write follows .claude/docs/automation-modes.md

(collaborative asks always · guided major-only · autonomous logs and proceeds;

automation_always_ask categories always prompt).

Test Flakiness Detection

Locale & User Profile: Match locale (pt-BR → natural Brazilian Portuguese questions/options, overriding English examples; en → English) and user_profile (founder → plain business language with (Recomendado) first, zero tech jargon; developer → technical). Keep code/tests in English.

A flaky test is one that sometimes passes and sometimes fails without any code

change. Flaky tests are worse than no tests in some ways — they train the team

to ignore red CI runs, masking genuine failures. This skill identifies them,

explains likely causes, and recommends whether to quarantine or fix each one.

Output: Updated tests/saas-regression-suite.md quarantine section + optional

production/qa/flakiness-report-[date].md

When to run:


1. Parse Arguments

Modes:

standard log output directories

section and provide remediation guidance for already-known flaky tests

registry


2. Locate CI Log Data

Option A — GitHub Actions (preferred)

Check for test result artifacts:

ls -t .github/ 2>/dev/null
ls -t test-results/ 2>/dev/null

For Next.js / TypeScript projects: Jest / Vitest outputs JUnit XML or JSON reports under reports/ or test-results/.

For FastAPI / Python projects: Pytest outputs JUnit XML to test-results/pytest.xml or terminal reports.

For Cloudflare / Worker projects: Vitest outputs reports to reports/ or terminal logs.

Option B — Local log files

If a path argument is provided, read that file directly.

Option C — No log data available

If no logs found:

"No CI log data found. To detect flaky tests, this skill needs test result

history from multiple runs. Options:

1. Run the test suite at least 3 times and collect the output logs

2. Check CI pipeline output and save a log to test-results/

3. Run /saas-test-flakiness registry to review tests already flagged as flaky

in tests/saas-regression-suite.md"

Stop and ask the user which option to pursue.


3. Parse Test Results

For each CI log or result file found, parse:

JUnit XML format (Jest / Vitest / Playwright / Pytest with JUnit reporter):

JSON / TAP format (Jest / Vitest / Playwright reporters):

Plain text runner logs:

Build a table: test_id → [run1_result, run2_result, run3_result, ...]


4. Identify Flaky Tests

A test is flaky if it appears in the result history with both PASS and

FAIL outcomes across runs with no code changes between them.

Flakiness thresholds:

genuinely rare failure

With fewer than 3 runs, every finding is suspected, whatever its fail rate.

One failure in two runs reads as 50%, but it is one data point: do not

quarantine it, label it suspected, and ask whether more run data is available.

The tiers above, and quarantine, apply from 3 runs up.

For each flaky test, classify the likely cause:

Cause classification

| Cause | Symptoms | Fix direction |

|-------|----------|---------------|

| Timing / async | Fails after awaiting signals or timers; pass rate correlates with system load | Add explicit await/synchronisation; avoid time-based delays |

| Order dependency | Fails when run after specific other tests; passes in isolation | Add proper setup/teardown; ensure test isolation |

| Random seed | Fails intermittently with no pattern; involves RNG | Pass explicit seed; don't use randf() in tests |

| Resource leak | Fails more often later in a test run | Fix cleanup in teardown; check orphan nodes (Next.js) or object disposal (FastAPI) |

| External state | Fails when a file, scene, or global exists from a prior test | Isolate test from file system; use in-memory mocks |

| Floating point | Fails on comparisons like == 0.5 | Use epsilon comparison (is_equal_approx, Assert.AreApproximately) |

| Scene/prefab load race | Fails when scenes are not yet ready | Await one frame after instantiation; use await get_tree().process_frame |

Use Grep to check the test file for timing calls, randf, global state access,

or equality comparisons on floats to narrow down the cause.


5. Recommend Action

For each flaky test:

Quarantine (High flakiness):

"Quarantine this test immediately. Skip it with the engine's own mechanism,

log it in the tests/saas-regression-suite.md quarantine section, and fix the root

cause before removing quarantine."

Skip mechanisms, by stack:

tests are skipped; do not invent an attribute.

to skip an automation test. Log it in the quarantine section and ask the user

how their CI excludes a test; do not invent a flag.

Investigate and fix soon (Moderate):

"This test is intermittently unreliable. Root cause appears to be [cause].

Suggested fix: [specific fix based on cause classification]. Do not quarantine

yet — fix the test directly."

Monitor (Low/suspected):

"This test shows suspected flakiness. Collect more run data before

quarantining. Note it as 'suspected' in the regression suite."


6. Generate Reports

In-conversation summary

## Flakiness Detection Results

**Runs analysed**: [N]
**Tests tracked**: [N]

### Flaky Tests Found

| Test | System | Fail Rate | Confidence | Likely Cause | Recommendation |
|------|--------|-----------|------------|--------------|----------------|
| [test_name] | [system] | [N]% | confirmed | Timing | Quarantine + fix async |
| [test_name] | [system] | [N]% | confirmed | Float comparison | Fix: use epsilon compare |
| [test_name] | [system] | [N]% | suspected (fewer than 3 runs) | Order dependency | Collect more runs before acting |

### Clean Tests (no flakiness detected)

[N] tests ran across [N] runs with consistent results — no flakiness detected.

### Data Limitations

[Note if fewer than 5 runs were available — fewer runs = less statistical confidence]

7. Update Regression Suite + Optional Report File

Ask: "May I update the quarantine section of tests/saas-regression-suite.md

with the flaky tests found?"

If yes: use Edit to append entries to the Quarantined Tests table.

Never remove existing quarantine entries — only add new ones.

Ask (separately): "May I write a full flakiness report to

production/qa/flakiness-report-[date].md?"

The full report includes per-test analysis with cause details and

stack-specific fix snippets.

After writing:

disable this test in CI. Re-enable after the root cause is fixed."

change the equality comparison on line [N] to use is_equal_approx."

Schedule fix work for the [N] quarantined tests before the release gate."


Collaborative Protocol

"suspected" not "confirmed"; ask if more run data is available

direction even when recommending quarantine

file require explicit approval. On write: Verdict: COMPLETE — flakiness report written. On decline: Verdict: BLOCKED — user declined write.

actions clearly; do not just silently quarantine without the team knowing

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.