Repository navigation
docs(agents): default to no new tests and tighten the anti-pattern list #37993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,32 @@ | ||
| # Test anti-patterns | ||
|
|
||
| Keep a test only if it fails when your change is reverted, its expected values are hardcoded (not computed by production code), it lives at the one cheapest layer that owns the behavior, and its size matches the change (a one-line fix gets about one case). | ||
|
|
||
| Tests that: | ||
|
|
||
| - Reimplement production logic instead of exercising it. | ||
| - Have no meaningful assertions, such as `expect(true).toBe(true)`. | ||
| - Assert only mock calls or values supplied by their own mocks. | ||
| - Promise inputs or behavior their setup never exercises. | ||
| - Claim pixel or interaction coverage from static markup. | ||
| - Duplicate coverage without faster feedback or clearer failures, including private predicates and provider replays. | ||
| - Copy inventories, manifests, exports, imports, or strings instead of proving behavior. | ||
| - Check persistence at a path the code never writes. | ||
| - Assert capability flags instead of delivery or acknowledgement. | ||
| - Pass negative cases without exercising the intended rejection path. | ||
| - Wait on real time or networks instead of fake clocks and deterministic boundaries. | ||
| - Reimplement production logic, or use it as the oracle (`expect(out).toBe(buildX(input))`). | ||
| - Assemble production pieces (pipelines, adapters, subclasses) instead of calling the real entry point. | ||
| - Assert nothing meaningful: `expect(true)`, lone `toBeDefined()`, `expect(a || b)`, `.not.toBe('')`, unpinned `toThrow()`, `not.toHaveBeenCalled()` on unreachable spies. | ||
| - Assert only mock calls, mock-supplied values, or fixtures the test built; or check `mock.calls[i][j]` when order doesn't matter. | ||
| - Promise inputs or behavior the setup never exercises, including unread fields and scale params (`it.each([1_000, 10_000])`) that change nothing. | ||
| - Claim pixel, layout, or interaction coverage from static markup, happy-dom/jsdom, or Tailwind/`data-slot` class strings. | ||
| - Re-test one contract per layer (shared/IPC/renderer/mobile/CLI), per desktop+mobile copy, or per locale/agent. | ||
| - Use Cartesian `it.each`, or branch inside a parameterized body, instead of one case per distinct behavior. | ||
| - Copy inventories, manifests, exports, strings, registry lists, or counts (`registry.size).toBe(50)`). | ||
| - Assert copy or translations (`changeLanguage('es')` + `getByText`, `key.replace('{{x}}', …)`). | ||
| - Pin constants, defaults, versions, or schema values. | ||
| - Test third-party behavior (Radix focus, zustand selectors, zod, i18next). | ||
| - Count internal work (`String.prototype` spies, getter/Proxy counts, read budgets) or assert wall-clock timing. Perf changes get correctness tests only. | ||
| - Reach into private state (`obj['x']`, `*ForTests()`, test-only subclasses). | ||
| - Check persistence at a path the code never writes, or capability flags instead of delivery. | ||
| - Wait on real time or networks instead of fake clocks. | ||
|
|
||
| Mocks and fixtures that: | ||
|
|
||
| - Fake React hooks while ignoring effect dependencies or cleanup. | ||
| - Hide incorrect tables, fields, joins, filters, or arguments behind mocked internal chains. | ||
| - Contradict real producers or source contracts. | ||
| - Implement the behavior under test or treat distinct APIs as equivalent. | ||
| - Supply receipts, admission decisions, callback ordering, or other outputs production code should generate. | ||
|
|
||
| Production code that: | ||
| - Fake React hooks while ignoring effect deps or cleanup. | ||
| - Hide wrong tables, fields, joins, filters, or arguments behind mocked internal chains. | ||
| - Contradict real producers (e.g. mocking a feature gate back to old logic). | ||
| - Implement the behavior under test (e.g. a mocked lock that sets the state it guards), or supply outputs production should generate. | ||
| - Are hand-copied across files instead of extending a shared typed fake. | ||
|
|
||
| - Adds exports, globals, wrappers, or code paths solely for tests. | ||
| Production code that adds exports, globals, wrappers, dependency overrides, or code paths only for tests. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply the test gate to updated tests too.
AGENTS.mdapplies this gate when contributors write or edit tests, and the anti-pattern guide says to check each test before committing. This checkbox covers only added tests, so an updated existing test can bypass the gate. ChangeEvery added testtoEvery added or updated test. (github.com)