@kurokeita/add-skill 1.17.1 → 1.18.0

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.
@@ -21,7 +21,11 @@ Prereq: authenticate with the standard GitHub CLI once (for example, run `gh aut
21
21
 
22
22
  ## Quick start
23
23
 
24
- - `python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "<number-or-url>"`
24
+ - Detect the interpreter first:
25
+ `PYTHON_BIN=$(command -v python || command -v python3 || true)`
26
+ - If `PYTHON_BIN` is empty, skip the bundled script and use the manual `gh` fallback workflow.
27
+ - Otherwise run:
28
+ `"$PYTHON_BIN" "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "<number-or-url>"`
25
29
  - Add `--json` if you want machine-friendly output for summarization.
26
30
 
27
31
  ## Workflow
@@ -34,7 +38,11 @@ Prereq: authenticate with the standard GitHub CLI once (for example, run `gh aut
34
38
  - If the user provides a PR number or URL, use that directly.
35
39
  3. Inspect failing checks (GitHub Actions only).
36
40
  - Preferred: run the bundled script (handles gh field drift and job-log fallbacks):
37
- - `python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "<number-or-url>"`
41
+ - Resolve the interpreter first:
42
+ `PYTHON_BIN=$(command -v python || command -v python3 || true)`
43
+ - If `PYTHON_BIN` is set, run:
44
+ `"$PYTHON_BIN" "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "<number-or-url>"`
45
+ - If neither `python` nor `python3` is available, skip the bundled script and use the manual fallback below.
38
46
  - Add `--json` for machine-friendly output.
39
47
  - Manual fallback:
40
48
  - `gh pr checks <pr> --json name,state,bucket,link,startedAt,completedAt,workflow`
@@ -65,6 +73,6 @@ Fetch failing PR checks, pull GitHub Actions logs, and extract a failure snippet
65
73
 
66
74
  Usage examples:
67
75
 
68
- - `python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "123"`
69
- - `python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "https://github.com/org/repo/pull/123" --json`
70
- - `python "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --max-lines 200 --context 40`
76
+ - `PYTHON_BIN=$(command -v python || command -v python3 || true); test -n "$PYTHON_BIN" && "$PYTHON_BIN" "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "123"`
77
+ - `PYTHON_BIN=$(command -v python || command -v python3 || true); test -n "$PYTHON_BIN" && "$PYTHON_BIN" "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --pr "https://github.com/org/repo/pull/123" --json`
78
+ - `PYTHON_BIN=$(command -v python || command -v python3 || true); test -n "$PYTHON_BIN" && "$PYTHON_BIN" "<path-to-skill>/scripts/inspect_pr_checks.py" --repo "." --max-lines 200 --context 40`
@@ -46,9 +46,9 @@ The branch structure follows a categorized format:
46
46
 
47
47
  ### Workflow
48
48
 
49
- 1. Start from the main integration branch.
50
- 2. Ensure the local branch is up-to-date: `git pull origin main`.
51
- 3. Create the new branch: `git checkout -b <type>/<description>`.
49
+ 1. Start from the default branch.
50
+ 2. Ensure the local branch is up-to-date: `git pull origin $(git branch --show-current)`.
51
+ 3. Create the new branch without tracking: `git checkout --no-track -b <type>/<description>`.
52
52
 
53
53
  ## Additional Resources
54
54
 
@@ -0,0 +1,9 @@
1
+ ---
2
+ name: grill-me
3
+ description: Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".
4
+ ---
5
+
6
+ # Grill me
7
+
8
+ Interview me relentlessly about every aspect of this plan until we reach a shared understanding. Walk down each branch of the design tree, resolving dependencies between decisions one-by-one. For each question, provide your recommended answer.
9
+ If a question can be answered by exploring the codebase, explore the codebase instead.
@@ -0,0 +1,164 @@
1
+ ---
2
+ name: prd-to-tasks
3
+ description: >
4
+ Break a local PRD into independently grabbable implementation tasks using vertical slices, then save them under
5
+ .prd/{prd-name}/tasks/ in the current workspace. Use when the user wants to convert a PRD to tasks, break a spec
6
+ into actionable work, slice a PRD, or create implementation tasks from a local planning document. Do NOT trigger
7
+ for: writing PRDs, reviewing PRDs without task creation, or remote work item management systems.
8
+ argument-hint: "[prd-name]"
9
+ ---
10
+
11
+ # PRD to Tasks
12
+
13
+ Break a local PRD into independently grabbable implementation tasks using vertical slices.
14
+
15
+ Input location:
16
+
17
+ - PRD directory: `.prd/{prd-name}/`
18
+ - Source PRD: `.prd/{prd-name}/prd.md`
19
+
20
+ Output location:
21
+
22
+ - Tasks directory: `.prd/{prd-name}/tasks/`
23
+ - Optional index: `.prd/{prd-name}/tasks/README.md`
24
+
25
+ `{prd-name}` should be a filesystem-safe kebab-case slug. If the user provides a title instead, normalize it to a slug
26
+ and state the slug you used.
27
+
28
+ ## Step 1: Locate the PRD
29
+
30
+ If the user provided `$ARGUMENTS`, treat that as the PRD name and normalize it.
31
+
32
+ If not, ask which PRD directory to use.
33
+
34
+ Then:
35
+
36
+ 1. Confirm `.prd/{prd-name}/prd.md` exists
37
+ 2. Read it fully
38
+ 3. Check whether `.prd/{prd-name}/tasks/` already exists
39
+ 4. If task files already exist, summarize them and ask whether to overwrite, append, or regenerate selectively
40
+
41
+ If the PRD does not exist, stop and tell the user exactly which path is missing.
42
+
43
+ ## Step 2: Explore the codebase
44
+
45
+ If you have not already explored the relevant code in this conversation, do so now:
46
+
47
+ 1. Read top-level architecture guidance if present
48
+ 2. Search for code related to the PRD concepts
49
+ 3. Read nearby guidance files for affected subsystems
50
+ 4. Look for similar features and test patterns
51
+
52
+ The PRD tells you *what* to build. The codebase tells you enough about *where* and *how* to create useful tasks.
53
+
54
+ ## Step 3: Draft vertical slices
55
+
56
+ Break the PRD into **tracer bullet** tasks.
57
+
58
+ ### What is a tracer bullet?
59
+
60
+ A tracer bullet is a thin vertical slice through the whole feature path. It proves that the relevant layers connect
61
+ correctly end to end. It is not a horizontal "build all backend first, then all UI" slice.
62
+
63
+ Prefer slices that are:
64
+
65
+ - Independently verifiable
66
+ - Demoable on their own
67
+ - Thin and end to end
68
+ - Ordered by dependency
69
+
70
+ ### HITL vs AFK
71
+
72
+ Each slice should be marked:
73
+
74
+ - `HITL`: needs human input, review, testing on real devices, design signoff, or external coordination
75
+ - `AFK`: can be implemented and validated without waiting on a person
76
+
77
+ ### Vertical slice rules
78
+
79
+ - Each slice should deliver a complete behavior, not one technical layer
80
+ - Prefer many thin slices over a few broad ones
81
+ - Use the PRD's module design to inform slicing, but do not create one task per module
82
+ - Order slices so blockers come first
83
+
84
+ ## Step 4: Quiz the user
85
+
86
+ Present the proposed slices as a numbered list. For each slice, include:
87
+
88
+ - Title
89
+ - Type: `HITL` or `AFK`
90
+ - Blocked by
91
+ - User stories covered
92
+
93
+ Ask the user whether:
94
+
95
+ - The granularity is right
96
+ - The dependencies are correct
97
+ - Any slices should be merged or split
98
+ - The `HITL` versus `AFK` labels are accurate
99
+
100
+ Iterate until approved.
101
+
102
+ ## Step 5: Write task files
103
+
104
+ Only write files after the user approves the breakdown.
105
+
106
+ Create `.prd/{prd-name}/tasks/` if needed.
107
+
108
+ Create one Markdown file per task using zero-padded numeric prefixes:
109
+
110
+ - `.prd/{prd-name}/tasks/01-{task-slug}.md`
111
+ - `.prd/{prd-name}/tasks/02-{task-slug}.md`
112
+
113
+ `{task-slug}` should be kebab-case and derived from the task title.
114
+
115
+ Each task file should use this structure:
116
+
117
+ ```md
118
+ # {Task title}
119
+
120
+ - Type: AFK | HITL
121
+ - Status: Proposed
122
+ - Blocked by: None | 01-other-task
123
+ - Source PRD: ../prd.md
124
+
125
+ ## What to Build
126
+
127
+ Concise description of the vertical slice. Describe end-to-end behavior, not a layer-by-layer checklist.
128
+
129
+ ## Acceptance Criteria
130
+
131
+ - [ ] Criterion 1
132
+ - [ ] Criterion 2
133
+ - [ ] Criterion 3
134
+
135
+ ## User Stories Addressed
136
+
137
+ - User story 3
138
+ - User story 7
139
+
140
+ ## Notes
141
+
142
+ - Optional implementation hints grounded in the current codebase
143
+ - Reference relevant modules or concepts, but avoid binding the task to fragile file-level details unless necessary
144
+ ```
145
+
146
+ Also create or update `.prd/{prd-name}/tasks/README.md` with:
147
+
148
+ - The PRD title
149
+ - The approved slice list in dependency order
150
+ - A short summary of each task
151
+
152
+ ## Important constraints
153
+
154
+ - Do not modify `prd.md` unless the user asks
155
+ - Do not delete existing task files unless the user explicitly approves replacement
156
+ - If existing tasks overlap the proposed slices, call that out before writing duplicates
157
+
158
+ ## After writing
159
+
160
+ Summarize:
161
+
162
+ - The PRD slug used
163
+ - The task files created or updated
164
+ - Any existing task files that were preserved
@@ -1,389 +1,114 @@
1
1
  ---
2
- name: test-driven-development
3
- description: Use when implementing any feature or bugfix, before writing implementation code
2
+ name: tdd
3
+ description: Test-driven development with red-green-refactor loop. Use when user wants to build features or fix bugs using TDD, mentions "red-green-refactor", wants integration tests, or asks for test-first development.
4
4
  ---
5
5
 
6
- # Test-Driven Development (TDD)
6
+ # Test-Driven Development
7
7
 
8
- ## Overview
8
+ ## Philosophy
9
9
 
10
- Write the test first. Watch it fail. Write minimal code to pass.
10
+ **Core principle**: Tests should verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't.
11
11
 
12
- **Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
12
+ **Good tests** are integration-style: they exercise real code paths through public APIs. They describe _what_ the system does, not _how_ it does it. A good test reads like a specification - "user can checkout with valid cart" tells you exactly what capability exists. These tests survive refactors because they don't care about internal structure.
13
13
 
14
- **Violating the letter of the rules is violating the spirit of the rules.**
14
+ **Bad tests** are coupled to implementation. They mock internal collaborators, test private methods, or verify through external means (like querying a database directly instead of using the interface). The warning sign: your test breaks when you refactor, but behavior hasn't changed. If you rename an internal function and tests fail, those tests were testing implementation, not behavior.
15
15
 
16
- ## When to Use
16
+ See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.
17
17
 
18
- **Always:**
18
+ ## Anti-Pattern: Horizontal Slices
19
19
 
20
- - New features
21
- - Bug fixes
22
- - Refactoring
23
- - Behavior changes
20
+ **DO NOT write all tests first, then all implementation.** This is "horizontal slicing" - treating RED as "write all tests" and GREEN as "write all code."
24
21
 
25
- **Exceptions (ask your human partner):**
22
+ This produces **crap tests**:
26
23
 
27
- - Throwaway prototypes
28
- - Generated code
29
- - Configuration files
24
+ - Tests written in bulk test _imagined_ behavior, not _actual_ behavior
25
+ - You end up testing the _shape_ of things (data structures, function signatures) rather than user-facing behavior
26
+ - Tests become insensitive to real changes - they pass when behavior breaks, fail when behavior is fine
27
+ - You outrun your headlights, committing to test structure before understanding the implementation
30
28
 
31
- Thinking "skip TDD just this once"? Stop. That's rationalization.
29
+ **Correct approach**: Vertical slices via tracer bullets. One test → one implementation → repeat. Each test responds to what you learned from the previous cycle. Because you just wrote the code, you know exactly what behavior matters and how to verify it.
32
30
 
33
- ## The Iron Law
34
-
35
- ```
36
- NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
37
31
  ```
38
-
39
- Write code before the test? Delete it. Start over.
40
-
41
- **No exceptions:**
42
-
43
- - Don't keep it as "reference"
44
- - Don't "adapt" it while writing tests
45
- - Don't look at it
46
- - Delete means delete
47
-
48
- Implement fresh from tests. Period.
49
-
50
- ## Red-Green-Refactor
51
-
52
- ```dot
53
- digraph tdd_cycle {
54
- rankdir=LR;
55
- red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
56
- verify_red [label="Verify fails\ncorrectly", shape=diamond];
57
- green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
58
- verify_green [label="Verify passes\nAll green", shape=diamond];
59
- refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
60
- next [label="Next", shape=ellipse];
61
-
62
- red -> verify_red;
63
- verify_red -> green [label="yes"];
64
- verify_red -> red [label="wrong\nfailure"];
65
- green -> verify_green;
66
- verify_green -> refactor [label="yes"];
67
- verify_green -> green [label="no"];
68
- refactor -> verify_green [label="stay\ngreen"];
69
- verify_green -> next;
70
- next -> red;
71
- }
32
+ WRONG (horizontal):
33
+ RED: test1, test2, test3, test4, test5
34
+ GREEN: impl1, impl2, impl3, impl4, impl5
35
+
36
+ RIGHT (vertical):
37
+ RED→GREEN: test1→impl1
38
+ RED→GREEN: test2→impl2
39
+ RED→GREEN: test3→impl3
40
+ ...
72
41
  ```
73
42
 
74
- ### RED - Write Failing Test
75
-
76
- Write one minimal test showing what should happen.
77
-
78
- <Good>
79
- ```typescript
80
- test('retries failed operations 3 times', async () => {
81
- let attempts = 0;
82
- const operation = () => {
83
- attempts++;
84
- if (attempts < 3) throw new Error('fail');
85
- return 'success';
86
- };
43
+ ## Workflow
87
44
 
88
- const result = await retryOperation(operation);
45
+ ### 1. Planning
89
46
 
90
- expect(result).toBe('success');
91
- expect(attempts).toBe(3);
92
- });
47
+ Before writing any code:
93
48
 
94
- ```
95
- Clear name, tests real behavior, one thing
96
- </Good>
97
-
98
- <Bad>
99
- ```typescript
100
- test('retry works', async () => {
101
- const mock = jest.fn()
102
- .mockRejectedValueOnce(new Error())
103
- .mockRejectedValueOnce(new Error())
104
- .mockResolvedValueOnce('success');
105
- await retryOperation(mock);
106
- expect(mock).toHaveBeenCalledTimes(3);
107
- });
108
- ```
109
-
110
- Vague name, tests mock not code
111
- </Bad>
49
+ - [ ] Confirm with user what interface changes are needed
50
+ - [ ] Confirm with user which behaviors to test (prioritize)
51
+ - [ ] Identify opportunities for [deep modules](deep-modules.md) (small interface, deep implementation)
52
+ - [ ] Design interfaces for [testability](interface-design.md)
53
+ - [ ] List the behaviors to test (not implementation steps)
54
+ - [ ] Get user approval on the plan
112
55
 
113
- **Requirements:**
56
+ Ask: "What should the public interface look like? Which behaviors are most important to test?"
114
57
 
115
- - One behavior
116
- - Clear name
117
- - Real code (no mocks unless unavoidable)
58
+ **You can't test everything.** Confirm with the user exactly which behaviors matter most. Focus testing effort on critical paths and complex logic, not every possible edge case.
118
59
 
119
- ### Verify RED - Watch It Fail
60
+ ### 2. Tracer Bullet
120
61
 
121
- **MANDATORY. Never skip.**
62
+ Write ONE test that confirms ONE thing about the system:
122
63
 
123
- ```bash
124
- npm test path/to/test.test.ts
125
64
  ```
126
-
127
- Confirm:
128
-
129
- - Test fails (not errors)
130
- - Failure message is expected
131
- - Fails because feature missing (not typos)
132
-
133
- **Test passes?** You're testing existing behavior. Fix test.
134
-
135
- **Test errors?** Fix error, re-run until it fails correctly.
136
-
137
- ### GREEN - Minimal Code
138
-
139
- Write simplest code to pass the test.
140
-
141
- <Good>
142
- ```typescript
143
- async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
144
- for (let i = 0; i < 3; i++) {
145
- try {
146
- return await fn();
147
- } catch (e) {
148
- if (i === 2) throw e;
149
- }
150
- }
151
- throw new Error('unreachable');
152
- }
153
- ```
154
- Just enough to pass
155
- </Good>
156
-
157
- <Bad>
158
- ```typescript
159
- async function retryOperation<T>(
160
- fn: () => Promise<T>,
161
- options?: {
162
- maxRetries?: number;
163
- backoff?: 'linear' | 'exponential';
164
- onRetry?: (attempt: number) => void;
165
- }
166
- ): Promise<T> {
167
- // YAGNI
168
- }
169
- ```
170
- Over-engineered
171
- </Bad>
172
-
173
- Don't add features, refactor other code, or "improve" beyond the test.
174
-
175
- ### Verify GREEN - Watch It Pass
176
-
177
- **MANDATORY.**
178
-
179
- ```bash
180
- npm test path/to/test.test.ts
65
+ RED: Write test for first behavior
66
+ ↓ RUN TESTS — confirm it fails for the right reason
67
+ GREEN: Write minimal code to pass
68
+ ↓ RUN TESTS — confirm it passes
181
69
  ```
182
70
 
183
- Confirm:
184
-
185
- - Test passes
186
- - Other tests still pass
187
- - Output pristine (no errors, warnings)
188
-
189
- **Test fails?** Fix code, not test.
190
-
191
- **Other tests fail?** Fix now.
192
-
193
- ### REFACTOR - Clean Up
194
-
195
- After green only:
196
-
197
- - Remove duplication
198
- - Improve names
199
- - Extract helpers
200
-
201
- Keep tests green. Don't add behavior.
202
-
203
- ### Repeat
204
-
205
- Next failing test for next feature.
206
-
207
- ## Good Tests
208
-
209
- | Quality | Good | Bad |
210
- |---------|------|-----|
211
- | **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
212
- | **Clear** | Name describes behavior | `test('test1')` |
213
- | **Shows intent** | Demonstrates desired API | Obscures what code should do |
214
-
215
- ## Why Order Matters
216
-
217
- **"I'll write tests after to verify it works"**
218
-
219
- Tests written after code pass immediately. Passing immediately proves nothing:
220
-
221
- - Might test wrong thing
222
- - Might test implementation, not behavior
223
- - Might miss edge cases you forgot
224
- - You never saw it catch the bug
225
-
226
- Test-first forces you to see the test fail, proving it actually tests something.
227
-
228
- **"I already manually tested all the edge cases"**
71
+ This is your tracer bullet - proves the path works end-to-end.
229
72
 
230
- Manual testing is ad-hoc. You think you tested everything but:
73
+ **You MUST run the test before writing any implementation.** A test that was never observed to fail might always pass vacuously, be testing the wrong thing, or be broken. The failure message tells you what the test is actually checking.
231
74
 
232
- - No record of what you tested
233
- - Can't re-run when code changes
234
- - Easy to forget cases under pressure
235
- - "It worked when I tried it" ≠ comprehensive
75
+ ### 3. Incremental Loop
236
76
 
237
- Automated tests are systematic. They run the same way every time.
77
+ For each remaining behavior:
238
78
 
239
- **"Deleting X hours of work is wasteful"**
240
-
241
- Sunk cost fallacy. The time is already gone. Your choice now:
242
-
243
- - Delete and rewrite with TDD (X more hours, high confidence)
244
- - Keep it and add tests after (30 min, low confidence, likely bugs)
245
-
246
- The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
247
-
248
- **"TDD is dogmatic, being pragmatic means adapting"**
249
-
250
- TDD IS pragmatic:
251
-
252
- - Finds bugs before commit (faster than debugging after)
253
- - Prevents regressions (tests catch breaks immediately)
254
- - Documents behavior (tests show how to use code)
255
- - Enables refactoring (change freely, tests catch breaks)
256
-
257
- "Pragmatic" shortcuts = debugging in production = slower.
258
-
259
- **"Tests after achieve the same goals - it's spirit not ritual"**
260
-
261
- No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
262
-
263
- Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
264
-
265
- Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
266
-
267
- 30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work.
268
-
269
- ## Common Rationalizations
270
-
271
- | Excuse | Reality |
272
- |--------|---------|
273
- | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
274
- | "I'll test after" | Tests passing immediately prove nothing. |
275
- | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
276
- | "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
277
- | "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
278
- | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
279
- | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
280
- | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
281
- | "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
282
- | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
283
- | "Existing code has no tests" | You're improving it. Add tests for existing code. |
284
-
285
- ## Red Flags - STOP and Start Over
286
-
287
- - Code before test
288
- - Test after implementation
289
- - Test passes immediately
290
- - Can't explain why test failed
291
- - Tests added "later"
292
- - Rationalizing "just this once"
293
- - "I already manually tested it"
294
- - "Tests after achieve the same purpose"
295
- - "It's about spirit not ritual"
296
- - "Keep as reference" or "adapt existing code"
297
- - "Already spent X hours, deleting is wasteful"
298
- - "TDD is dogmatic, I'm being pragmatic"
299
- - "This is different because..."
300
-
301
- **All of these mean: Delete code. Start over with TDD.**
302
-
303
- ## Example: Bug Fix
304
-
305
- **Bug:** Empty email accepted
306
-
307
- **RED**
308
-
309
- ```typescript
310
- test('rejects empty email', async () => {
311
- const result = await submitForm({ email: '' });
312
- expect(result.error).toBe('Email required');
313
- });
314
- ```
315
-
316
- **Verify RED**
317
-
318
- ```bash
319
- $ npm test
320
- FAIL: expected 'Email required', got undefined
321
79
  ```
322
-
323
- **GREEN**
324
-
325
- ```typescript
326
- function submitForm(data: FormData) {
327
- if (!data.email?.trim()) {
328
- return { error: 'Email required' };
329
- }
330
- // ...
331
- }
332
- ```
333
-
334
- **Verify GREEN**
335
-
336
- ```bash
337
- $ npm test
338
- PASS
80
+ RED: Write next test
81
+ ↓ RUN TESTS — confirm new test fails, existing pass
82
+ GREEN: Minimal code to pass
83
+ ↓ RUN TESTS — confirm all pass
339
84
  ```
340
85
 
341
- **REFACTOR**
342
- Extract validation for multiple fields if needed.
343
-
344
- ## Verification Checklist
345
-
346
- Before marking work complete:
347
-
348
- - [ ] Every new function/method has a test
349
- - [ ] Watched each test fail before implementing
350
- - [ ] Each test failed for expected reason (feature missing, not typo)
351
- - [ ] Wrote minimal code to pass each test
352
- - [ ] All tests pass
353
- - [ ] Output pristine (no errors, warnings)
354
- - [ ] Tests use real code (mocks only if unavoidable)
355
- - [ ] Edge cases and errors covered
356
-
357
- Can't check all boxes? You skipped TDD. Start over.
86
+ Rules:
358
87
 
359
- ## When Stuck
88
+ - One test at a time
89
+ - Run tests after writing each test (confirm RED) and after each implementation step (confirm GREEN)
90
+ - Only enough code to pass current test
91
+ - Don't anticipate future tests
92
+ - Keep tests focused on observable behavior
360
93
 
361
- | Problem | Solution |
362
- |---------|----------|
363
- | Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
364
- | Test too complicated | Design too complicated. Simplify interface. |
365
- | Must mock everything | Code too coupled. Use dependency injection. |
366
- | Test setup huge | Extract helpers. Still complex? Simplify design. |
94
+ ### 4. Refactor
367
95
 
368
- ## Debugging Integration
96
+ After all tests pass, look for [refactor candidates](refactoring.md):
369
97
 
370
- Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
98
+ - [ ] Extract duplication
99
+ - [ ] Deepen modules (move complexity behind simple interfaces)
100
+ - [ ] Apply SOLID principles where natural
101
+ - [ ] Consider what new code reveals about existing code
102
+ - [ ] Run tests after each refactor step
371
103
 
372
- Never fix bugs without a test.
104
+ **Never refactor while RED.** Get to GREEN first.
373
105
 
374
- ## Testing Anti-Patterns
375
-
376
- When adding mocks or test utilities, read @testing-anti-patterns.md to avoid common pitfalls:
377
-
378
- - Testing mock behavior instead of real behavior
379
- - Adding test-only methods to production classes
380
- - Mocking without understanding dependencies
381
-
382
- ## Final Rule
106
+ ## Checklist Per Cycle
383
107
 
384
108
  ```
385
- Production code → test exists and failed first
386
- Otherwise → not TDD
109
+ [ ] Test describes behavior, not implementation
110
+ [ ] Test uses public interface only
111
+ [ ] Test would survive internal refactor
112
+ [ ] Code is minimal for this test
113
+ [ ] No speculative features added
387
114
  ```
388
-
389
- No exceptions without your human partner's permission.