Skip to content

Add flaky-test detector (flaky) + FLAKY_TESTS.md#102

Merged
kyleve merged 2 commits into
mainfrom
flaky-test-detector
Jul 17, 2026
Merged

Add flaky-test detector (flaky) + FLAKY_TESTS.md#102
kyleve merged 2 commits into
mainfrom
flaky-test-detector

Conversation

@kyleve

@kyleve kyleve commented Jul 17, 2026

Copy link
Copy Markdown
Owner

What

Adds a report-only `flaky` root script that hunts for flaky tests along two dimensions, and a root `FLAKY_TESTS.md` that records the findings. Intended to be driven by a weekly Cursor automation (set up separately) that runs the script to detect/update — and optionally fix — flaky tests.

How it works

  • `tuist generate --no-open`, then one `xcodebuild build-for-testing` (`Stuff-iOS-Tests`) into a shared DerivedData reused by both phases (no recompiles between runs).
  • Phase 1 (suite): run the whole scheme N times (default 10) via `test-without-building`; parse each `.xcresult` for per-test pass/fail. Any test that fails in ≥1 run is a "suspect".
  • Phase 2 (tight loop): re-run only the suspects, each in isolation via `-only-testing: -test-iterations M` (default 50) with `-test-repetition-relaunch-enabled YES` (fresh process per iteration).
  • Classification: a test is reported flaky only if it produced both passes and failures across everything observed, so a consistently-failing (broken) test and a consistently-passing test are both excluded. Flake rate averages the suite and tight-loop failure rates.
  • Like `./profile`, it's report-only: flaky/failing tests never make it exit non-zero (only a genuine build failure does), and it never opens Xcode. macOS-only (Tuist + Simulator), matching CI on macos-26.

Flags: `--suite-runs`, `--iterations`, `--device`/`--os`, `--scheme`, `--relaunch`, `--no-update`, `--top`, `-h`.

FLAKY_TESTS.md

Written/updated by the script (unless `--no-update`): a do-not-hand-edit header with run params + UTC timestamp, a table sorted by flake rate (test id, bundle, suite fails `k/N`, tight-loop fails `j/M`, flake rate), and an explicit no-flakes state.

Seed run

Ran the script end to end: 1248 distinct tests across 10 suite runs, 0 suspects → no flaky tests detected. `FLAKY_TESTS.md` is seeded with that clean result.

Docs

Documented `flaky` in `AGENTS.md` (Root dev scripts) and `README.md` (scripts list + prose); `CLAUDE.md` regenerated via `./sync-agents`. No `Project.swift`/`Package.swift` changes — it targets the existing `Stuff-iOS-Tests` scheme and per-test `-only-testing`.

Notes

  • The seed run surfaced (and this PR fixes) a cosmetic `integer expression expected` warning from counting suspects with `grep -c` on an empty file; now counted with `awk 'NF' | wc -l`.

kyleve added 2 commits July 17, 2026 13:34
Add a report-only `flaky` root script that detects flaky tests in two
dimensions: it runs the full Stuff-iOS-Tests suite N times (default 10),
then tight-loops (in isolation, fresh process per iteration) any test that
failed at least once M times (default 50). A test is reported only when it
both passed and failed across those runs (non-deterministic), so consistently
passing/failing tests are excluded. Findings and flake counts are written to
FLAKY_TESTS.md at the repo root.

Like ./profile it never fails on flaky/failing tests (only a build failure
errors) and runs tuist generate --no-open so it never opens Xcode. Documented
in AGENTS.md and README.md; CLAUDE.md regenerated via ./sync-agents.
- Count suspects with awk|wc instead of `grep -c`, which printed 0 and
  exited non-zero on no match and tripped the fallback into a bogus two-line
  count (the harmless "integer expression expected" warning at 0 suspects).
- Seed FLAKY_TESTS.md from a real run: 1248 tests across 10 suite runs, no
  flaky tests detected.
@kyleve
kyleve merged commit a58d14a into main Jul 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant