@simplysm/sd-claude 13.0.78 → 13.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude/rules/sd-claude-rules.md +4 -63
- package/claude/rules/sd-simplysm-usage.md +7 -0
- package/claude/sd-session-start.sh +10 -0
- package/claude/sd-statusline.py +249 -0
- package/claude/skills/sd-api-review/SKILL.md +89 -0
- package/claude/skills/sd-check/SKILL.md +55 -57
- package/claude/skills/sd-commit/SKILL.md +37 -42
- package/claude/skills/sd-debug/SKILL.md +75 -265
- package/claude/skills/sd-document/SKILL.md +63 -53
- package/claude/skills/sd-document/_common.py +94 -0
- package/claude/skills/sd-document/extract_docx.py +19 -48
- package/claude/skills/sd-document/extract_pdf.py +22 -50
- package/claude/skills/sd-document/extract_pptx.py +17 -40
- package/claude/skills/sd-document/extract_xlsx.py +19 -40
- package/claude/skills/sd-email-analyze/SKILL.md +23 -31
- package/claude/skills/sd-email-analyze/email-analyzer.py +79 -65
- package/claude/skills/sd-init/SKILL.md +133 -0
- package/claude/skills/sd-plan/SKILL.md +69 -120
- package/claude/skills/sd-readme/SKILL.md +106 -131
- package/claude/skills/sd-review/SKILL.md +38 -155
- package/claude/skills/sd-simplify/SKILL.md +59 -0
- package/dist/commands/install.js +20 -6
- package/dist/commands/install.js.map +1 -1
- package/package.json +3 -2
- package/src/commands/install.ts +29 -7
- package/README.md +0 -297
- package/claude/refs/sd-angular.md +0 -127
- package/claude/refs/sd-code-conventions.md +0 -155
- package/claude/refs/sd-directories.md +0 -7
- package/claude/refs/sd-library-issue.md +0 -7
- package/claude/refs/sd-migration.md +0 -7
- package/claude/refs/sd-orm-v12.md +0 -81
- package/claude/refs/sd-orm.md +0 -23
- package/claude/refs/sd-service.md +0 -5
- package/claude/refs/sd-simplysm-docs.md +0 -52
- package/claude/refs/sd-solid.md +0 -68
- package/claude/refs/sd-workflow.md +0 -25
- package/claude/rules/sd-refs-linker.md +0 -52
- package/claude/sd-statusline.js +0 -296
- package/claude/skills/sd-api-name-review/SKILL.md +0 -154
- package/claude/skills/sd-brainstorm/SKILL.md +0 -215
- package/claude/skills/sd-debug/condition-based-waiting-example.ts +0 -158
- package/claude/skills/sd-debug/condition-based-waiting.md +0 -114
- package/claude/skills/sd-debug/defense-in-depth.md +0 -128
- package/claude/skills/sd-debug/find-polluter.sh +0 -64
- package/claude/skills/sd-debug/root-cause-tracing.md +0 -168
- package/claude/skills/sd-discuss/SKILL.md +0 -91
- package/claude/skills/sd-explore/SKILL.md +0 -118
- package/claude/skills/sd-plan-dev/SKILL.md +0 -294
- package/claude/skills/sd-plan-dev/code-quality-reviewer-prompt.md +0 -49
- package/claude/skills/sd-plan-dev/final-review-prompt.md +0 -50
- package/claude/skills/sd-plan-dev/implementer-prompt.md +0 -60
- package/claude/skills/sd-plan-dev/spec-reviewer-prompt.md +0 -45
- package/claude/skills/sd-review/api-reviewer-prompt.md +0 -75
- package/claude/skills/sd-review/code-reviewer-prompt.md +0 -82
- package/claude/skills/sd-review/convention-checker-prompt.md +0 -61
- package/claude/skills/sd-review/refactoring-analyzer-prompt.md +0 -92
- package/claude/skills/sd-skill/SKILL.md +0 -417
- package/claude/skills/sd-skill/anthropic-best-practices.md +0 -156
- package/claude/skills/sd-skill/cso-guide.md +0 -161
- package/claude/skills/sd-skill/examples/CLAUDE_MD_TESTING.md +0 -200
- package/claude/skills/sd-skill/persuasion-principles.md +0 -220
- package/claude/skills/sd-skill/testing-skills-with-subagents.md +0 -408
- package/claude/skills/sd-skill/writing-guide.md +0 -159
- package/claude/skills/sd-tdd/SKILL.md +0 -385
- package/claude/skills/sd-tdd/testing-anti-patterns.md +0 -317
- package/claude/skills/sd-use/SKILL.md +0 -67
- package/claude/skills/sd-worktree/SKILL.md +0 -78
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
# Skill Writing Guide
|
|
2
|
-
|
|
3
|
-
**Load this reference when:** writing or editing skill content, organizing skill files, or bulletproofing discipline-enforcing skills against rationalization.
|
|
4
|
-
|
|
5
|
-
## Flowchart Usage
|
|
6
|
-
|
|
7
|
-
Use Mermaid (`flowchart`) when there are decision branches or non-obvious process flows.
|
|
8
|
-
|
|
9
|
-
```mermaid
|
|
10
|
-
flowchart TD
|
|
11
|
-
A{"Need to show information?"} -->|yes| B{"Decision where I might go wrong?"}
|
|
12
|
-
B -->|yes| C[Small inline flowchart]
|
|
13
|
-
B -->|no| D[Use markdown]
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
**Use flowcharts ONLY for:**
|
|
17
|
-
|
|
18
|
-
- Non-obvious decision points
|
|
19
|
-
- Process loops where you might stop too early
|
|
20
|
-
- "When to use A vs B" decisions
|
|
21
|
-
|
|
22
|
-
**Never use flowcharts for:**
|
|
23
|
-
|
|
24
|
-
- Reference material -> Tables, lists
|
|
25
|
-
- Code examples -> Markdown blocks
|
|
26
|
-
- Linear instructions -> Numbered lists
|
|
27
|
-
- Labels without semantic meaning (step1, helper2)
|
|
28
|
-
|
|
29
|
-
## Code Examples
|
|
30
|
-
|
|
31
|
-
**One excellent example beats many mediocre ones**
|
|
32
|
-
|
|
33
|
-
Choose most relevant language:
|
|
34
|
-
|
|
35
|
-
- Testing techniques -> TypeScript/JavaScript
|
|
36
|
-
- System debugging -> Shell/Python
|
|
37
|
-
- Data processing -> Python
|
|
38
|
-
|
|
39
|
-
**Good example:**
|
|
40
|
-
|
|
41
|
-
- Complete and runnable
|
|
42
|
-
- Well-commented explaining WHY
|
|
43
|
-
- From real scenario
|
|
44
|
-
- Shows pattern clearly
|
|
45
|
-
- Ready to adapt (not generic template)
|
|
46
|
-
|
|
47
|
-
**Don't:**
|
|
48
|
-
|
|
49
|
-
- Implement in 5+ languages
|
|
50
|
-
- Create fill-in-the-blank templates
|
|
51
|
-
- Write contrived examples
|
|
52
|
-
|
|
53
|
-
You're good at porting - one great example is enough.
|
|
54
|
-
|
|
55
|
-
## File Organization
|
|
56
|
-
|
|
57
|
-
### Self-Contained Skill
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
defense-in-depth/
|
|
61
|
-
SKILL.md # Everything inline
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
When: All content fits, no heavy reference needed
|
|
65
|
-
|
|
66
|
-
### Skill with Reusable Tool
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
condition-based-waiting/
|
|
70
|
-
SKILL.md # Overview + patterns
|
|
71
|
-
example.ts # Working helpers to adapt
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
When: Tool is reusable code, not just narrative
|
|
75
|
-
|
|
76
|
-
### Skill with Heavy Reference
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
pptx/
|
|
80
|
-
SKILL.md # Overview + workflows
|
|
81
|
-
pptxgenjs.md # 600 lines API reference
|
|
82
|
-
ooxml.md # 500 lines XML structure
|
|
83
|
-
scripts/ # Executable tools
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
When: Reference material too large for inline
|
|
87
|
-
|
|
88
|
-
## Bulletproofing Skills Against Rationalization
|
|
89
|
-
|
|
90
|
-
Skills that enforce discipline (like TDD) need to resist rationalization. Agents are smart and will find loopholes when under pressure.
|
|
91
|
-
|
|
92
|
-
**Psychology note:** Understanding WHY persuasion techniques work helps you apply them systematically. See persuasion-principles.md for research foundation (Cialdini, 2021; Meincke et al., 2025) on authority, commitment, scarcity, social proof, and unity principles.
|
|
93
|
-
|
|
94
|
-
### Close Every Loophole Explicitly
|
|
95
|
-
|
|
96
|
-
Don't just state the rule - forbid specific workarounds:
|
|
97
|
-
|
|
98
|
-
Bad:
|
|
99
|
-
```markdown
|
|
100
|
-
Write code before test? Delete it.
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Good:
|
|
104
|
-
```markdown
|
|
105
|
-
Write code before test? Delete it. Start over.
|
|
106
|
-
|
|
107
|
-
**No exceptions:**
|
|
108
|
-
|
|
109
|
-
- Don't keep it as "reference"
|
|
110
|
-
- Don't "adapt" it while writing tests
|
|
111
|
-
- Don't look at it
|
|
112
|
-
- Delete means delete
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### Address "Spirit vs Letter" Arguments
|
|
116
|
-
|
|
117
|
-
Add foundational principle early:
|
|
118
|
-
|
|
119
|
-
```markdown
|
|
120
|
-
**Violating the letter of the rules is violating the spirit of the rules.**
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
This cuts off entire class of "I'm following the spirit" rationalizations.
|
|
124
|
-
|
|
125
|
-
### Build Rationalization Table
|
|
126
|
-
|
|
127
|
-
Capture rationalizations from baseline testing. Every excuse agents make goes in the table:
|
|
128
|
-
|
|
129
|
-
```markdown
|
|
130
|
-
| Excuse | Reality |
|
|
131
|
-
| -------------------------------- | ----------------------------------------------------------------------- |
|
|
132
|
-
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
133
|
-
| "I'll test after" | Tests passing immediately prove nothing. |
|
|
134
|
-
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
### Create Red Flags List
|
|
138
|
-
|
|
139
|
-
Make it easy for agents to self-check when rationalizing:
|
|
140
|
-
|
|
141
|
-
```markdown
|
|
142
|
-
## Red Flags - STOP and Start Over
|
|
143
|
-
|
|
144
|
-
- Code before test
|
|
145
|
-
- "I already manually tested it"
|
|
146
|
-
- "Tests after achieve the same purpose"
|
|
147
|
-
- "It's about spirit not ritual"
|
|
148
|
-
- "This is different because..."
|
|
149
|
-
|
|
150
|
-
**All of these mean: Delete code. Start over with TDD.**
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Update CSO for Violation Symptoms
|
|
154
|
-
|
|
155
|
-
Add to description: symptoms of when you're ABOUT to violate the rule:
|
|
156
|
-
|
|
157
|
-
```yaml
|
|
158
|
-
description: use when implementing any feature or bugfix, before writing implementation code
|
|
159
|
-
```
|
|
@@ -1,385 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: sd-tdd
|
|
3
|
-
description: "TDD - failing test first, then implement (explicit invocation only)"
|
|
4
|
-
user-invocable: false
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Test-Driven Development (TDD)
|
|
8
|
-
|
|
9
|
-
## Overview
|
|
10
|
-
|
|
11
|
-
Write the test first. Watch it fail. Write minimal code to pass.
|
|
12
|
-
|
|
13
|
-
**Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
|
|
14
|
-
|
|
15
|
-
**Violating the letter of the rules is violating the spirit of the rules.**
|
|
16
|
-
|
|
17
|
-
## When to Use
|
|
18
|
-
|
|
19
|
-
**Always:**
|
|
20
|
-
|
|
21
|
-
- New features
|
|
22
|
-
- Bug fixes
|
|
23
|
-
- Refactoring
|
|
24
|
-
- Behavior changes
|
|
25
|
-
|
|
26
|
-
**Exceptions (ask your human partner):**
|
|
27
|
-
|
|
28
|
-
- Throwaway prototypes
|
|
29
|
-
- Generated code
|
|
30
|
-
- Configuration files
|
|
31
|
-
|
|
32
|
-
Thinking "skip TDD just this once"? Stop. That's rationalization.
|
|
33
|
-
|
|
34
|
-
## The Iron Law
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Write code before the test? Delete it. Start over.
|
|
41
|
-
|
|
42
|
-
**No exceptions:**
|
|
43
|
-
|
|
44
|
-
- Don't keep it as "reference"
|
|
45
|
-
- Don't "adapt" it while writing tests
|
|
46
|
-
- Don't look at it
|
|
47
|
-
- Delete means delete
|
|
48
|
-
|
|
49
|
-
Implement fresh from tests. Period.
|
|
50
|
-
|
|
51
|
-
## Red-Green-Refactor
|
|
52
|
-
|
|
53
|
-
```mermaid
|
|
54
|
-
flowchart LR
|
|
55
|
-
A["RED<br>Write failing test"]:::red --> B{"Verify fails<br>correctly"}
|
|
56
|
-
B -->|yes| C["GREEN<br>Minimal code"]:::green
|
|
57
|
-
B -->|"wrong failure"| A
|
|
58
|
-
C --> D{"Verify passes<br>All green"}
|
|
59
|
-
D -->|yes| E["REFACTOR<br>Clean up"]:::blue
|
|
60
|
-
D -->|no| C
|
|
61
|
-
E -->|"stay green"| D
|
|
62
|
-
D --> F(["Next"])
|
|
63
|
-
F --> A
|
|
64
|
-
|
|
65
|
-
classDef red fill:#ffcccc
|
|
66
|
-
classDef green fill:#ccffcc
|
|
67
|
-
classDef blue fill:#ccccff
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### RED - Write Failing Test
|
|
71
|
-
|
|
72
|
-
Write one minimal test showing what should happen.
|
|
73
|
-
|
|
74
|
-
<Good>
|
|
75
|
-
```typescript
|
|
76
|
-
test('retries failed operations 3 times', async () => {
|
|
77
|
-
let attempts = 0;
|
|
78
|
-
const operation = () => {
|
|
79
|
-
attempts++;
|
|
80
|
-
if (attempts < 3) throw new Error('fail');
|
|
81
|
-
return 'success';
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const result = await retryOperation(operation);
|
|
85
|
-
|
|
86
|
-
expect(result).toBe('success');
|
|
87
|
-
expect(attempts).toBe(3);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
````
|
|
91
|
-
Clear name, tests real behavior, one thing
|
|
92
|
-
</Good>
|
|
93
|
-
|
|
94
|
-
<Bad>
|
|
95
|
-
```typescript
|
|
96
|
-
test('retry works', async () => {
|
|
97
|
-
const mock = jest.fn()
|
|
98
|
-
.mockRejectedValueOnce(new Error())
|
|
99
|
-
.mockRejectedValueOnce(new Error())
|
|
100
|
-
.mockResolvedValueOnce('success');
|
|
101
|
-
await retryOperation(mock);
|
|
102
|
-
expect(mock).toHaveBeenCalledTimes(3);
|
|
103
|
-
});
|
|
104
|
-
````
|
|
105
|
-
|
|
106
|
-
Vague name, tests mock not code
|
|
107
|
-
</Bad>
|
|
108
|
-
|
|
109
|
-
**Requirements:**
|
|
110
|
-
|
|
111
|
-
- One behavior
|
|
112
|
-
- Clear name
|
|
113
|
-
- Real code (no mocks unless unavoidable)
|
|
114
|
-
|
|
115
|
-
### Verify RED - Watch It Fail
|
|
116
|
-
|
|
117
|
-
**MANDATORY. Never skip.**
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
npx vitest path/to/test.spec.ts --run
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Confirm:
|
|
124
|
-
|
|
125
|
-
- Test fails (not errors)
|
|
126
|
-
- Failure message is expected
|
|
127
|
-
- Fails because feature missing (not typos)
|
|
128
|
-
|
|
129
|
-
**Test passes?** You're testing existing behavior. Fix test.
|
|
130
|
-
|
|
131
|
-
**Test errors?** Fix error, re-run until it fails correctly.
|
|
132
|
-
|
|
133
|
-
### GREEN - Minimal Code
|
|
134
|
-
|
|
135
|
-
Write simplest code to pass the test.
|
|
136
|
-
|
|
137
|
-
<Good>
|
|
138
|
-
```typescript
|
|
139
|
-
async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
|
|
140
|
-
for (let i = 0; i < 3; i++) {
|
|
141
|
-
try {
|
|
142
|
-
return await fn();
|
|
143
|
-
} catch (e) {
|
|
144
|
-
if (i === 2) throw e;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
throw new Error('unreachable');
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
Just enough to pass
|
|
151
|
-
</Good>
|
|
152
|
-
|
|
153
|
-
<Bad>
|
|
154
|
-
```typescript
|
|
155
|
-
async function retryOperation<T>(
|
|
156
|
-
fn: () => Promise<T>,
|
|
157
|
-
options?: {
|
|
158
|
-
maxRetries?: number;
|
|
159
|
-
backoff?: 'linear' | 'exponential';
|
|
160
|
-
onRetry?: (attempt: number) => void;
|
|
161
|
-
}
|
|
162
|
-
): Promise<T> {
|
|
163
|
-
// YAGNI
|
|
164
|
-
}
|
|
165
|
-
```
|
|
166
|
-
Over-engineered
|
|
167
|
-
</Bad>
|
|
168
|
-
|
|
169
|
-
Don't add features, refactor other code, or "improve" beyond the test.
|
|
170
|
-
|
|
171
|
-
### Verify GREEN - Watch It Pass
|
|
172
|
-
|
|
173
|
-
**MANDATORY.**
|
|
174
|
-
|
|
175
|
-
```bash
|
|
176
|
-
npx vitest path/to/test.spec.ts --run
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
Confirm:
|
|
180
|
-
|
|
181
|
-
- Test passes
|
|
182
|
-
- Other tests still pass
|
|
183
|
-
- Output pristine (no errors, warnings)
|
|
184
|
-
|
|
185
|
-
**Test fails?** Fix code, not test.
|
|
186
|
-
|
|
187
|
-
**Other tests fail?** Fix now.
|
|
188
|
-
|
|
189
|
-
### REFACTOR - Clean Up
|
|
190
|
-
|
|
191
|
-
After green only:
|
|
192
|
-
|
|
193
|
-
- Remove duplication
|
|
194
|
-
- Improve names
|
|
195
|
-
- Extract helpers
|
|
196
|
-
|
|
197
|
-
Keep tests green. Don't add behavior.
|
|
198
|
-
|
|
199
|
-
### Repeat
|
|
200
|
-
|
|
201
|
-
Next failing test for next feature.
|
|
202
|
-
|
|
203
|
-
## Good Tests
|
|
204
|
-
|
|
205
|
-
| Quality | Good | Bad |
|
|
206
|
-
| ---------------- | ----------------------------------- | --------------------------------------------------- |
|
|
207
|
-
| **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
|
|
208
|
-
| **Clear** | Name describes behavior | `test('test1')` |
|
|
209
|
-
| **Shows intent** | Demonstrates desired API | Obscures what code should do |
|
|
210
|
-
|
|
211
|
-
## Why Order Matters
|
|
212
|
-
|
|
213
|
-
**"I'll write tests after to verify it works"**
|
|
214
|
-
|
|
215
|
-
Tests written after code pass immediately. Passing immediately proves nothing:
|
|
216
|
-
|
|
217
|
-
- Might test wrong thing
|
|
218
|
-
- Might test implementation, not behavior
|
|
219
|
-
- Might miss edge cases you forgot
|
|
220
|
-
- You never saw it catch the bug
|
|
221
|
-
|
|
222
|
-
Test-first forces you to see the test fail, proving it actually tests something.
|
|
223
|
-
|
|
224
|
-
**"I already manually tested all the edge cases"**
|
|
225
|
-
|
|
226
|
-
Manual testing is ad-hoc. You think you tested everything but:
|
|
227
|
-
|
|
228
|
-
- No record of what you tested
|
|
229
|
-
- Can't re-run when code changes
|
|
230
|
-
- Easy to forget cases under pressure
|
|
231
|
-
- "It worked when I tried it" ≠ comprehensive
|
|
232
|
-
|
|
233
|
-
Automated tests are systematic. They run the same way every time.
|
|
234
|
-
|
|
235
|
-
**"Deleting X hours of work is wasteful"**
|
|
236
|
-
|
|
237
|
-
Sunk cost fallacy. The time is already gone. Your choice now:
|
|
238
|
-
|
|
239
|
-
- Delete and rewrite with TDD (X more hours, high confidence)
|
|
240
|
-
- Keep it and add tests after (30 min, low confidence, likely bugs)
|
|
241
|
-
|
|
242
|
-
The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
|
|
243
|
-
|
|
244
|
-
**"TDD is dogmatic, being pragmatic means adapting"**
|
|
245
|
-
|
|
246
|
-
TDD IS pragmatic:
|
|
247
|
-
|
|
248
|
-
- Finds bugs before commit (faster than debugging after)
|
|
249
|
-
- Prevents regressions (tests catch breaks immediately)
|
|
250
|
-
- Documents behavior (tests show how to use code)
|
|
251
|
-
- Enables refactoring (change freely, tests catch breaks)
|
|
252
|
-
|
|
253
|
-
"Pragmatic" shortcuts = debugging in production = slower.
|
|
254
|
-
|
|
255
|
-
**"Tests after achieve the same goals - it's spirit not ritual"**
|
|
256
|
-
|
|
257
|
-
No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
|
|
258
|
-
|
|
259
|
-
Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
|
|
260
|
-
|
|
261
|
-
Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
|
|
262
|
-
|
|
263
|
-
30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work.
|
|
264
|
-
|
|
265
|
-
## Common Rationalizations
|
|
266
|
-
|
|
267
|
-
| Excuse | Reality |
|
|
268
|
-
| -------------------------------------- | ----------------------------------------------------------------------- |
|
|
269
|
-
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
270
|
-
| "I'll test after" | Tests passing immediately prove nothing. |
|
|
271
|
-
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
|
|
272
|
-
| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
|
|
273
|
-
| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
|
|
274
|
-
| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
|
|
275
|
-
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
|
|
276
|
-
| "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
|
|
277
|
-
| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
|
|
278
|
-
| "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
|
|
279
|
-
| "Existing code has no tests" | You're improving it. Add tests for existing code. |
|
|
280
|
-
|
|
281
|
-
## Red Flags - STOP and Start Over
|
|
282
|
-
|
|
283
|
-
- Code before test
|
|
284
|
-
- Test after implementation
|
|
285
|
-
- Test passes immediately
|
|
286
|
-
- Can't explain why test failed
|
|
287
|
-
- Tests added "later"
|
|
288
|
-
- Rationalizing "just this once"
|
|
289
|
-
- "I already manually tested it"
|
|
290
|
-
- "Tests after achieve the same purpose"
|
|
291
|
-
- "It's about spirit not ritual"
|
|
292
|
-
- "Keep as reference" or "adapt existing code"
|
|
293
|
-
- "Already spent X hours, deleting is wasteful"
|
|
294
|
-
- "TDD is dogmatic, I'm being pragmatic"
|
|
295
|
-
- "This is different because..."
|
|
296
|
-
|
|
297
|
-
**All of these mean: Delete code. Start over with TDD.**
|
|
298
|
-
|
|
299
|
-
## Example: Bug Fix
|
|
300
|
-
|
|
301
|
-
**Bug:** Empty email accepted
|
|
302
|
-
|
|
303
|
-
**RED**
|
|
304
|
-
|
|
305
|
-
```typescript
|
|
306
|
-
test("rejects empty email", async () => {
|
|
307
|
-
const result = await submitForm({ email: "" });
|
|
308
|
-
expect(result.error).toBe("Email required");
|
|
309
|
-
});
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
**Verify RED**
|
|
313
|
-
|
|
314
|
-
```bash
|
|
315
|
-
$ npx vitest path/to/test.spec.ts --run
|
|
316
|
-
FAIL: expected 'Email required', got undefined
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
**GREEN**
|
|
320
|
-
|
|
321
|
-
```typescript
|
|
322
|
-
function submitForm(data: FormData) {
|
|
323
|
-
if (!data.email?.trim()) {
|
|
324
|
-
return { error: "Email required" };
|
|
325
|
-
}
|
|
326
|
-
// ...
|
|
327
|
-
}
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
**Verify GREEN**
|
|
331
|
-
|
|
332
|
-
```bash
|
|
333
|
-
$ npx vitest path/to/test.spec.ts --run
|
|
334
|
-
PASS
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
**REFACTOR**
|
|
338
|
-
Extract validation for multiple fields if needed.
|
|
339
|
-
|
|
340
|
-
## Verification Checklist
|
|
341
|
-
|
|
342
|
-
Before marking work complete:
|
|
343
|
-
|
|
344
|
-
- [ ] Every new function/method has a test
|
|
345
|
-
- [ ] Watched each test fail before implementing
|
|
346
|
-
- [ ] Each test failed for expected reason (feature missing, not typo)
|
|
347
|
-
- [ ] Wrote minimal code to pass each test
|
|
348
|
-
- [ ] All tests pass
|
|
349
|
-
- [ ] Output pristine (no errors, warnings)
|
|
350
|
-
- [ ] Tests use real code (mocks only if unavoidable)
|
|
351
|
-
- [ ] Edge cases and errors covered
|
|
352
|
-
|
|
353
|
-
Can't check all boxes? You skipped TDD. Start over.
|
|
354
|
-
|
|
355
|
-
## When Stuck
|
|
356
|
-
|
|
357
|
-
| Problem | Solution |
|
|
358
|
-
| ---------------------- | -------------------------------------------------------------------- |
|
|
359
|
-
| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
|
|
360
|
-
| Test too complicated | Design too complicated. Simplify interface. |
|
|
361
|
-
| Must mock everything | Code too coupled. Use dependency injection. |
|
|
362
|
-
| Test setup huge | Extract helpers. Still complex? Simplify design. |
|
|
363
|
-
|
|
364
|
-
## Debugging Integration
|
|
365
|
-
|
|
366
|
-
Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
|
|
367
|
-
|
|
368
|
-
Never fix bugs without a test.
|
|
369
|
-
|
|
370
|
-
## Testing Anti-Patterns
|
|
371
|
-
|
|
372
|
-
When adding mocks or test utilities, read testing-anti-patterns.md to avoid common pitfalls:
|
|
373
|
-
|
|
374
|
-
- Testing mock behavior instead of real behavior
|
|
375
|
-
- Adding test-only methods to production classes
|
|
376
|
-
- Mocking without understanding dependencies
|
|
377
|
-
|
|
378
|
-
## Final Rule
|
|
379
|
-
|
|
380
|
-
```
|
|
381
|
-
Production code → test exists and failed first
|
|
382
|
-
Otherwise → not TDD
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
No exceptions without your human partner's permission.
|