test-first
Skill107 starsChanged 9 months agoMITView on GitHub
Use when implementing any feature or bugfix, before writing implementation code
11 other projects use a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- 9Ashwin/let-it-gotheir own version, first seen Sep 28, 2026
- llopresto87/Cypresstheir own version, first seen Sep 22, 2026
- atgreen/hackinatortheir own version, first seen Aug 24, 2026
- eeshsaxena/agent-skillstheir own version, first seen Aug 5, 2026
- duthaho/claudekittheir own version, first seen Jul 22, 2026
- TIANTIAN-ZHAN/claude-harnesstheir own version, first seen Jul 15, 2026
Other versions11 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- orkait/hyperstack★ 116% same
Wrote their own version · 10
- duthaho/claudekit★ 97same name
- llopresto87/Cypress★ 95same name
- claude-world/director-mode-lite★ 80same name
- s-hiraoku/synapse-a2a★ 16same name
- TIANTIAN-ZHAN/claude-harness★ 3same name
- eeshsaxena/agent-skills★ 2same name
- atgreen/hackinator★ 1same name
- goblindegook/skills★ 1same name
- 9Ashwin/let-it-go★ 0same name
- ccpowerpack/claude-code-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository35 other files it gives its agents.
- activationSkill
- agent-messagingSkill
- codebase-researchSkill
- completion-gateSkill
- comprehension-checkSkill
- delegated-executionSkill
- deployment-advisorSkill
- design-integrationSkill
- design-researchSkill
- environment-awarenessSkill
- error-recoverySkill
- fault-diagnosisSkill
- github-searchSkill
- intent-discoverySkill
- knowledge-captureSkill
- merge-protocolSkill
- parallel-executionSkill
- pattern-matchingSkill
- performance-tuningSkill
- project-bootstrapSkill
- protocol-authoringSkill
- quality-enforcementSkill
- quality-gateSkill
- rationaleSkill
- reference-engineSkill
- review-responseSkill
- security-protocolSkill
- specification-firstSkill
- system-designSkill
- task-planningSkill
- task-runnerSkill
- team-orchestrationSkill
- ui-engineeringSkill
- ux-patternsSkill
- workspace-isolationSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. 0 are common, 18 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
18
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Write the test first. Observe it fail.
- Distinctive: line 12
Core principle: If you did not watch the test fail, you have no evidence it validates the correct behavior.
- Distinctive: line 40
Do not keep it as "reference material"
- Distinctive: line 41
Do not "adjust" it while writing tests
- Distinctive: line 42
Do not glance at it
- Distinctive: line 73
Write one minimal test that describes the expected behavior.
- Distinctive: line 122
Test fails (not errors out)
- Distinctive: line 132
Write the simplest possible code that makes the test pass.
- Distinctive: line 166
Do not add features, refactor unrelated code, or "improve" beyond what the test requires.
- Distinctive: line 192
Keep tests green. Do not add new behavior.
- Distinctive: line 216
Test-first forces you to observe the failure, proving the test actually verifies something.
- Distinctive: line 221
No record of what you tested
- Distinctive: line 231
Delete and rebuild with test-first (X more hours, high confidence)
- Distinctive: line 232
Keep it and bolt on tests (30 min, low confidence, probable defects)
- Distinctive: line 329
Before declaring work finished:
- Distinctive: line 355
Never fix bugs without a test.
- Distinctive: line 359
When adding mocks or test utilities, read @testing-anti-patterns.md to avoid common pitfalls:
- Distinctive: line 371
No exceptions without your human partner's permission.
“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Test-First Development
Overview
Write the test first. Observe it fail. Write the minimum code to pass.
Core principle: If you did not watch the test fail, you have no evidence it validates the correct behavior.
No exceptions. No workarounds. No shortcuts.
When to Use
Required:
- New features
- Bug fixes
- Refactoring
- Behavior modifications
Exceptions (confirm with your human partner):
- Disposable prototypes
- Generated code
- Configuration files
Tempted to think "skip test-first just this once"? Stop. That is rationalization.
The Prime Directive
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRSTWrote code before the test? Delete it. Start over.
Zero tolerance:
- Do not keep it as "reference material"
- Do not "adjust" it while writing tests
- Do not glance at it
- Delete means delete
Build fresh from tests. Full stop.
Red-Green-Refactor
digraph tdd_loop {
rankdir=LR;
red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
check_red [label="Fails\ncorrectly?", shape=diamond];
green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
check_green [label="All tests\npass?", shape=diamond];
refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
next [label="Next", shape=ellipse];
red -> check_red;
check_red -> green [label="yes"];
check_red -> red [label="wrong\nfailure"];
green -> check_green;
check_green -> refactor [label="yes"];
check_green -> green [label="no"];
refactor -> check_green [label="stay\ngreen"];
check_green -> next;
next -> red;
}RED - Write the Failing Test
Write one minimal test that describes the expected behavior.
<Good>
```typescript
test('retries failed operations up to 3 times', async () => {
let callCount = 0;
const unstableOp = () => {
callCount++;
if (callCount < 3) throw new Error('transient failure');
return 'done';
};const outcome = await withRetry(unstableOp);
expect(outcome).toBe('done'); expect(callCount).toBe(3); });
Descriptive name, tests actual behavior, single concern
</Good>
<Bad>
```typescript
test('retry works', async () => {
const spy = jest.fn()
.mockRejectedValueOnce(new Error())
.mockRejectedValueOnce(new Error())
.mockResolvedValueOnce('done');
await withRetry(spy);
expect(spy).toHaveBeenCalledTimes(3);
});Vague name, validates mock interactions not real behavior
</Bad>
Criteria:
- One behavior per test
- Descriptive name
- Uses real code (mocks only when unavoidable)
Verify RED - Watch It Fail
MANDATORY. Never skip.
npm test path/to/test.test.tsConfirm:
- Test fails (not errors out)
- Failure message matches expectations
- Fails because the feature is missing (not due to typos)
Test passes? You are testing existing behavior. Rewrite the test.
Test errors? Fix the error, re-run until it fails correctly.
GREEN - Minimal Code
Write the simplest possible code that makes the test pass.
<Good>
```typescript
async function withRetry<T>(fn: () => Promise<T>): Promise<T> {
for (let attempt = 0; attempt < 3; attempt++) {
try {
return await fn();
} catch (e) {
if (attempt === 2) throw e;
}
}
throw new Error('unreachable');
}
```
Just enough to pass
</Good><Bad>
```typescript
async function withRetry<T>(
fn: () => Promise<T>,
opts?: {
maxAttempts?: number;
backoffStrategy?: 'linear' | 'exponential';
onAttempt?: (n: number) => void;
}
): Promise<T> {
// YAGNI
}
```
Over-engineered
</Bad>Do not add features, refactor unrelated code, or "improve" beyond what the test requires.
Verify GREEN - Watch It Pass
MANDATORY.
npm test path/to/test.test.tsConfirm:
- Test passes
- Other tests still pass
- Output is clean (no errors, no warnings)
Test fails? Fix the code, not the test.
Other tests fail? Fix them now.
REFACTOR - Clean Up
Only after green:
- Eliminate duplication
- Improve naming
- Extract helpers
Keep tests green. Do not add new behavior.
Repeat
Next failing test for the next behavior.
Quality Standards
| Quality | Good | Bad |
| Focused | One thing. "and" in the name? Split it. | test('validates email and domain and whitespace') |
| Descriptive | Name explains the behavior | test('test1') |
| Intentional | Demonstrates the desired API | Obscures what the code should do |
Why Sequence Matters
"I'll write tests afterward to confirm it works"
Tests written after code pass immediately. Passing immediately proves nothing:
- May validate the wrong thing
- May verify implementation details instead of behavior
- May miss edge cases you overlooked
- You never watched it catch the failure
Test-first forces you to observe the failure, proving the test actually verifies something.
"I already manually tested all the edge cases"
Manual testing is ad hoc. You believe you covered everything but:
- No record of what you tested
- Cannot rerun when code changes
- Easy to skip cases under pressure
- "It worked when I tried it" is not comprehensive
Automated tests are systematic. They execute identically every time.
"Deleting X hours of work is wasteful"
Sunk cost fallacy. The time is already spent. Your choice now:
- Delete and rebuild with test-first (X more hours, high confidence)
- Keep it and bolt on tests (30 min, low confidence, probable defects)
The real waste is keeping code you cannot trust. Working code without legitimate tests is technical debt.
"Test-first is dogmatic, being pragmatic means adapting"
Test-first IS pragmatic:
- Catches defects before commit (faster than debugging later)
- Prevents regressions (tests catch breakage immediately)
- Documents behavior (tests demonstrate how code works)
- Enables refactoring (change freely, tests catch problems)
"Pragmatic" shortcuts = debugging in production = slower.
"Tests after achieve the same goals - it's about the spirit not the ritual"
No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
Tests-after are biased by your implementation. You verify what you built, not what is required. You check the edge cases you remember, not ones you discover.
Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you did not).
30 minutes of tests after is not test-first. You get coverage, but lose proof that tests work.
Cognitive Traps
| Rationalization | What Is Actually True |
| "Too simple to test" | Simple code breaks. A test takes 30 seconds. |
| "I'll test afterward" | Tests passing immediately prove nothing. |
| "Tests after achieve the same thing" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
| "I already tested manually" | Ad hoc is not systematic. No record, cannot rerun. |
| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
| "Keep as reference, write tests first" | You will adapt it. That is testing after. Delete means delete. |
| "Need to explore first" | Fine. Discard the exploration, then start with test-first. |
| "Hard to test = I should skip it" | Listen to the test. Hard to test = hard to use. Simplify the design. |
| "Test-first will slow me down" | Test-first is faster than debugging. Pragmatic = test-first. |
| "Manual testing is faster" | Manual testing does not prove edge cases. You retest every change. |
| "Existing code has no tests" | You are improving it. Add tests for what exists. |
Guardrails - STOP and Start Over
- Code before test
- Test after implementation
- Test passes immediately
- Cannot explain why the test failed
- Tests added "later"
- Rationalizing "just this once"
- "I already tested it manually"
- "Tests after serve the same purpose"
- "It's about the spirit not the ritual"
- "Keep as reference" or "adapt existing code"
- "Already invested X hours, deleting is wasteful"
- "Test-first is dogmatic, I'm being pragmatic"
- "This is different because..."
All of these mean: Delete the code. Start over with test-first.
Example: Bug Fix
Bug: Empty email accepted by form
RED
test('rejects empty email', async () => {
const result = await processForm({ email: '' });
expect(result.error).toBe('Email required');
});Verify RED
$ npm test
FAIL: expected 'Email required', got undefinedGREEN
function processForm(data: FormData) {
if (!data.email?.trim()) {
return { error: 'Email required' };
}
// ...
}Verify GREEN
$ npm test
PASSREFACTOR Extract a validation pipeline for multiple fields if needed.
Completion Checklist
Before declaring work finished:
- Every new function/method has a test
- Watched each test fail before implementing
- Each test failed for the expected reason (feature missing, not typo)
- Wrote minimal code to pass each test
- All tests pass
- Output is clean (no errors, no warnings)
- Tests use real code (mocks only when unavoidable)
- Edge cases and error paths are covered
Cannot check every box? You skipped test-first. Start over.
When Stuck
| Problem | Solution |
| Do not know how to write the test | Write the API you wish existed. Write the assertion first. Ask your human partner. |
| Test too complicated | Design too complicated. Simplify the interface. |
| Must mock everything | Code too coupled. Use dependency injection. |
| Test setup is enormous | Extract helpers. Still heavy? Simplify the design. |
Debugging Integration
Bug found? Write a failing test that reproduces it. Follow the test-first cycle. The test both proves the fix and prevents regression.
Never fix bugs without a test.
Testing Anti-Patterns
When adding mocks or test utilities, read @testing-anti-patterns.md to avoid common pitfalls:
- Validating mock behavior instead of real behavior
- Adding test-only methods to production classes
- Mocking without understanding dependency chains
Final Rule
Production code -> test exists and failed first
Otherwise -> not test-firstNo exceptions without your human partner's permission.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

