fix-flaky-tests
ما الذي تفعله
تحقق هذه المهارة في الاختبارات الآلية المتقلبة، وهي التي تنجح وتفشل دون تغيير في الكود، وتصلحها. وهي مناسبة للمطورين الذين يريدون مجموعة اختبارات موثوقة.
متى تستخدمها
- ✓عندما يُعلَّم اختبار كمتقلب في Tuist وتريد إصلاحه.
- ✓عندما تفشل اختبارات كثيرة عشوائياً وتريد إيجاد السبب المشترك.
- ✓عندما تريد اكتشاف كل الاختبارات المتقلبة في المشروع وإصلاحها.
رابط المهارة
https://github.com/tuist/tuist/blob/main/skills/skills/fix-flaky-tests/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“ابحث عن الاختبارات المتقلبة في مشروعي وأصلح الاختبار الذي يفشل أكثر من غيره.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
يقرأ وكيلك موثوقية كل اختبار متقلب وتفاصيل فشله، ثم يقرأ مصدره عند السطر المبلَّغ عنه، ويحدد النمط الذي يسبب التقلب، ويصلحه، ثم يشغّل الاختبار عدة مرات للتأكد.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
Fix Flaky Tests
Quick Start
You'll typically receive a Tuist test case URL or identifier. Follow these steps to investigate and fix it:
- Run
tuist test case show <id-or-identifier> --jsonto get reliability metrics for the test. - Run
tuist test case run list Module/Suite/TestCase --flaky --jsonto see flaky run patterns. - Run
tuist test case run show <test-case-run-id> --jsonon failing flaky runs to get failure messages and file paths. - Read the test source at the reported path and line, identify the flaky pattern, and fix it.
- Verify by running the test multiple times to confirm it passes consistently.
If no specific test is provided, start with the Discovery section below.
Discovery
When no specific test case is provided, find all flaky tests in the project:
tuist test case list --flaky --json --page-size 50
This returns all test cases currently flagged as flaky. Key fields:
module.name/suite.name/name— the test identifieravg_duration— helps prioritize (fix fast unit tests first)is_quarantined— whether the test is already quarantined
Triage strategy:
- Group tests by suite — multiple flaky tests in the same suite often share a root cause.
- Check if failures share a
test_run_id— tests that all failed in the same run may have been killed by a process crash, not individual test bugs. - Look at failure messages to categorize: test logic bugs vs infrastructure issues (network errors, server 502s, conflicts on retry).
Investigation
1. Get test case metrics
You can pass either the UUID or the Module/Suite/TestCase identifier:
tuist test case show <id> --json
tuist test case show Module/Suite/TestCase --json
Key fields:
reliability_rate— percentage of successful runs (higher is better)flakiness_rate— percentage of runs marked flaky in the last 30 daystotal_runs/failed_runs— volume contextlast_status— current state
2. View flaky run history
tuist test case run list Module/Suite/TestCase --flaky --json
The identifier uses the format ModuleName/SuiteName/TestCaseName or ModuleName/TestCaseName when there is no suite. This returns only runs that were detected as flaky.
3. View full run history
tuist test case run list Module/Suite/TestCase --json --page-size 20
Look for patterns:
- Does it fail on specific branches?
- Does it fail only on CI (
is_ci: true) or also locally? - Are failures clustered around specific commits?
4. Get failure details
tuist test case run show <test-case-run-id> --json
Key fields:
failures[].message— the assertion or error messagefailures[].path— source file pathfailures[].line_number— exact line of failurefailures[].issue_type— type of issue (assertion_failure, etc.)repetitions— if present, shows retry behavior (pass/fail sequence)test_run_id— the broader test run this execution belongs tocrash_report— crash report data (present when the test runner crashed); containsexception_type,signal,exception_subtype, andtriggered_thread_frames
Code Analysis
- Open the file at
failures[0].pathand go tofailures[0].line_number. - Read the full test function and its setup/teardown.
- Identify which of the common flaky patterns below applies.
- Check if the test shares state with other tests in the same suite.
Common Flaky Patterns
Timing and async issues
- Missing waits: Test checks a result before an async operation completes. Fix: use
await, expectations with timeouts, or polling. - Race conditions: Multiple concurrent operations access shared state. Fix: synchronize access or use serial queues.
- Hardcoded timeouts:
sleep(1)or fixed delays that are too short on CI. Fix: use condition-based waits instead of fixed delays.
Shared state
- Test pollution: One test modifies global/static state that another test depends on. Fix: reset state in setUp/tearDown or use unique instances per test.
- Singleton contamination: Shared singletons carry state between tests. Fix: inject dependencies or reset singletons.
- File system leftovers: Tests leave files that affect subsequent runs. Fix: use temporary directories and clean up.
Environment dependencies
- Network calls: Tests hit real services that may be slow or unavailable. Fix: mock network calls.
- Date/time sensitivity: Tests depend on current time or tim
الأسئلة الشائعة
كيف تجد الاختبارات المتقلبة؟
تسرد الاختبارات التي وُسمت كمتقلبة في تحليلات الاختبار في Tuist.
ماذا إذا لم يُعطَ اختبار محدد؟
تكتشف الاختبارات المتقلبة في المشروع وتجمعها حسب المجموعة.
كيف تتأكد من الإصلاح؟
تشغّل الاختبار عدة مرات للتحقق من أنه ينجح باستمرار.
التفاصيل
الوصف الأصلي من المؤلف
Fixes flaky tests by analyzing failure patterns from Tuist test insights, identifying root causes, and applying targeted corrections. Can be invoked with a specific test case URL (e.g. `https://tuist.dev/{account}/{project}/tests/test-cases/{id}`) or without arguments to discover and fix all flaky tests in the project.
repo: tuist/tuist
الشعبية
- نجوم GitHub
- 5.9k
- الترتيب
- #14544
- الترخيص
- —
- آخر تحديث
- 2/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
analyze-selective-testing
5.9kيساعد وكيلك على فحص مدى نجاح الاختبار الانتقائي في Xcode في تخطي أهداف الاختبار غير المتغيرة، ومعرفة سبب اختلاف التخطي بين التشغيلات.
compare-builds
5.9kيساعد وكيلك على مقارنة تشغيلي بناء في Xcode لمعرفة البناء الأبطأ والتغيرات في استخدام الذاكرة المؤقتة والمشكلات الجديدة.
compare-bundles
5.9kيساعد وكيلك على مقارنة حزمتين للتطبيق لمعرفة تغيرات الحجم والملفات المضافة أو المحذوفة والفروق بين المنصات.
compare-cache-runs
5.9kيساعد وكيلك على مقارنة تشغيلين للذاكرة المؤقتة لمعرفة التغيرات في نسب الإصابة، وشرح سبب إبطال الذاكرة المؤقتة.
مهارات مشابهة
test-driven-development
311kيعلّم وكيلك كتابة اختبار فاشل أولًا، ثم رؤيته يفشل، ثم كتابة أصغر شيفرة تنجحه، قبل بناء أي ميزة أو إصلاح.
verification-before-completion
311kيعلّم وكيلك تشغيل فحوصات حقيقية وقراءة نتائجها قبل أن يقول إن المهمة أو الإصلاح أو البناء مكتمل أو ناجح.
migrate-to-shoehorn
310kيستبدل تأكيدات النوع الخطرة في ملفات الاختبار بمكتبة shoehorn، حتى تتمكن الاختبارات من استخدام بيانات جزئية وتجتاز فحوص الأنواع.