feat(skill): Add flaky-test-detection skill#61
Merged
NicolasMassart merged 4 commits intoJul 2, 2026
Merged
Conversation
…and-detection-agent-skill
There was a problem hiding this comment.
Pull request overview
Adds a new flaky-test-detection skill intended to help MetaMask Mobile contributors identify, prevent, and remediate flaky Jest unit tests, with both PR/diff review guidance and a GitHub Actions run-history audit procedure.
Changes:
- Introduces the
flaky-test-detectionskill entrypoint with review vs audit mode guidance. - Adds a MetaMask Mobile–specific flakiness pattern catalog (J1–J10) with example fixes and a local reproduction loop.
- Documents an audit procedure for mining GitHub Actions logs to rank historically flaky test files by failure rate.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| domains/coding/skills/flaky-test-detection/skill.md | Adds the top-level skill description, constraints, and mode selection guidance. |
| domains/coding/skills/flaky-test-detection/repos/metamask-mobile.md | Adds the MetaMask Mobile pattern table (J1–J10) with fix guidance and reproduction commands. |
| domains/coding/skills/flaky-test-detection/references/gh-analysis.md | Adds the GitHub Actions audit procedure and ranking output format for flaky tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…s in failure logs
asalsys
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new
flaky-test-detectionskill for MetaMask Mobile that detects, prevents, and fixes flaky Jest unit tests. It provides a review mode for scanning changed test files against known flakiness risk patterns (async, timing, isolation, mock, state), and an audit mode that queries GitHub Actions run history to rank historically flaky tests by failure rate.Type of Change
Skill Details (if adding a new skill)
Provider Name: MetaMask
Skill Name: flaky-test-detection
Brief Description: Detect, prevent, and fix flaky Jest unit tests in MetaMask Mobile before they reach CI, via PR/diff review against a risk-pattern table and a GitHub Actions history audit mode.
Checklist
Testing
Ran the skill against MetaMask Mobile PR diffs and CI run history to validate both review mode (pattern classification) and audit mode (ranked flaky test output).
Example result from running on Metamask Mobile repo:
Flaky test audit — Jest unit tests (
ci.yml, last 150 CI runs)Of 150 recent
ci.ymlruns, 31 failed overall; only 3 failed due to actual Jest failures (the rest were infra: yarn install retries, build issues, etc.). All 3 are confirmed flaky — same commit passed on a separate re-run.app/components/UI/Tokens/TokenList/TokenListItem/TokenListItem.test.tsxapp/components/Views/confirmations/components/gas/selected-gas-fee-token/selected-gas-fee-token.test.tsxapp/components/Views/confirmations/components/info/contract-deployment/contract-deployment.test.tsxapp/selectors/assets/balances.test.tsapp/components/Views/confirmations/components/confirm/confirm-component.test.tsxapp/components/Views/confirmations/hooks/gas/useGasFeeToken.test.tsapp/components/Views/confirmations/components/gas/gas-fee-token-toast/gas-fee-token-toast.test.tsxapp/components/Views/confirmations/components/gas/gas-fee-token-list-item/gas-fee-token-list-item.test.tsxapp/core/Engine/Engine.test.tsIndividually every file's rate is below the 5% "monitor" threshold, but the two ranked incidents matter more than the per-file rate:
Incident 1 —
feat/stellar/ramp-onramp-supportPR, commit9953242: run 28582173232 failed, run 28582184123 on the exact same commit passed. All 3 unrelated files threwTypeError: selectAccountByScope is not a functionin the same shard.Incident 2 — same PR, earlier commit
ff7051b: run 28577001112 — 5 unrelated files (selectors, a confirm hook, gas-fee-token components) all threw the identicalTypeError: Cannot read properties of undefined (reading 'some'). In the same job log there's alsoReferenceError: You are trying to import a file after the Jest environment has been torn downfromDeeplinkProtocolService.test.tsright before the cascade starts.Both incidents share a signature: several unrelated test files in the same worker/shard fail simultaneously with the identical generic error, and the same commit is green elsewhere. That's not per-file flakiness — it's cross-test contamination inside a shared Jest worker, consistent with skill categories J1 (dangling async work bleeding past test teardown — the "torn down" error is the smoking gun) and J9/J10 (module-level mock state not reset between files in the same worker, causing
selectAccountByScope/array-selector mocks to be undefined for the next test).Given the low per-file rate, I'd flag this as a worker-isolation issue to dig into (likely a shared mock or setup file) rather than something to fix per test file.
Root cause found in
app/core/SDKConnect/SDKDeeplinkProtocol/DeeplinkProtocolService.ts:The constructor fires an un-awaited
init()promise chain as a side effect.DeeplinkProtocolService.test.ts'sbeforeEachcallsservice = new DeeplinkProtocolService();14+ times, and a constructor return value can't be awaited — so every dangling.then()/.catch()callback (referencingDevLogger.log/Logger.log, bothjest.mock()'d) resolves on a later microtask/macrotask. When the last of these fires after this test file's suite is done and Jest has already torn down its module environment (and possibly moved the worker to the next test file), it throws exactly the observedReferenceError: You are trying to import a file after the Jest environment has been torn down, and can corrupt shared worker state for whatever unrelated test runs next in that worker — matching the cascadingTypeError: Cannot read properties of undefined (reading 'some')/selectAccountByScope is not a functionfailures across totally unrelated files.This is category J1 (missing await on async side effects) from the skill.
Proposed fix: add an
afterEachinDeeplinkProtocolService.test.tsthat flushes pending promises (using the existingflushPromiseshelper fromapp/util/test/utils.js) so the constructor's danglinginit()chain always settles before the test/file ends, instead of leaking into the next test file's environment.Note
created https://consensyssoftware.atlassian.net/browse/MCWP-699 for the above issue that the skill found.
Additional Context
Includes
references/gh-analysis.md(GitHub Actions audit procedure) andrepos/metamask-mobile.md(repo-specific flakiness pattern catalog, J1–J10).fixes https://consensyssoftware.atlassian.net/browse/MCWP-473