@tianhai/pi-workflow-kit 0.5.3 → 0.6.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.
- package/README.md +44 -494
- package/docs/developer-usage-guide.md +41 -401
- package/docs/oversight-model.md +13 -34
- package/docs/workflow-phases.md +32 -46
- package/extensions/workflow-guard.ts +67 -0
- package/package.json +3 -7
- package/skills/brainstorming/SKILL.md +16 -67
- package/skills/executing-tasks/SKILL.md +26 -227
- package/skills/finalizing/SKILL.md +33 -0
- package/skills/writing-plans/SKILL.md +23 -132
- package/ROADMAP.md +0 -16
- package/agents/code-reviewer.md +0 -18
- package/agents/config.ts +0 -5
- package/agents/implementer.md +0 -26
- package/agents/spec-reviewer.md +0 -13
- package/agents/worker.md +0 -17
- package/docs/plans/2026-04-10-brainstorming-boundary-enforcement-design.md +0 -60
- package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-design.md +0 -56
- package/docs/plans/completed/2026-04-09-cleanup-legacy-state-and-enforce-think-phases-implementation.md +0 -196
- package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-design.md +0 -185
- package/docs/plans/completed/2026-04-09-workflow-next-autocomplete-implementation.md +0 -334
- package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-design.md +0 -251
- package/docs/plans/completed/2026-04-09-workflow-next-handoff-state-implementation.md +0 -253
- package/extensions/constants.ts +0 -15
- package/extensions/lib/logging.ts +0 -138
- package/extensions/plan-tracker.ts +0 -508
- package/extensions/subagent/agents.ts +0 -144
- package/extensions/subagent/concurrency.ts +0 -52
- package/extensions/subagent/env.ts +0 -47
- package/extensions/subagent/index.ts +0 -1181
- package/extensions/subagent/lifecycle.ts +0 -25
- package/extensions/subagent/timeout.ts +0 -13
- package/extensions/workflow-monitor/debug-monitor.ts +0 -98
- package/extensions/workflow-monitor/git.ts +0 -31
- package/extensions/workflow-monitor/heuristics.ts +0 -58
- package/extensions/workflow-monitor/investigation.ts +0 -52
- package/extensions/workflow-monitor/reference-tool.ts +0 -42
- package/extensions/workflow-monitor/skip-confirmation.ts +0 -19
- package/extensions/workflow-monitor/tdd-monitor.ts +0 -137
- package/extensions/workflow-monitor/test-runner.ts +0 -37
- package/extensions/workflow-monitor/verification-monitor.ts +0 -61
- package/extensions/workflow-monitor/warnings.ts +0 -81
- package/extensions/workflow-monitor/workflow-handler.ts +0 -363
- package/extensions/workflow-monitor/workflow-next-completions.ts +0 -68
- package/extensions/workflow-monitor/workflow-next-state.ts +0 -112
- package/extensions/workflow-monitor/workflow-tracker.ts +0 -286
- package/extensions/workflow-monitor/workflow-transitions.ts +0 -88
- package/extensions/workflow-monitor.ts +0 -909
- package/skills/dispatching-parallel-agents/SKILL.md +0 -194
- package/skills/receiving-code-review/SKILL.md +0 -196
- package/skills/systematic-debugging/SKILL.md +0 -170
- package/skills/systematic-debugging/condition-based-waiting-example.ts +0 -158
- package/skills/systematic-debugging/condition-based-waiting.md +0 -115
- package/skills/systematic-debugging/defense-in-depth.md +0 -122
- package/skills/systematic-debugging/find-polluter.sh +0 -63
- package/skills/systematic-debugging/reference/rationalizations.md +0 -61
- package/skills/systematic-debugging/root-cause-tracing.md +0 -169
- package/skills/test-driven-development/SKILL.md +0 -266
- package/skills/test-driven-development/reference/examples.md +0 -101
- package/skills/test-driven-development/reference/rationalizations.md +0 -67
- package/skills/test-driven-development/reference/when-stuck.md +0 -33
- package/skills/test-driven-development/testing-anti-patterns.md +0 -299
- package/skills/using-git-worktrees/SKILL.md +0 -231
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: test-driven-development
|
|
3
|
-
description: Use when implementing any feature or bugfix, before writing implementation code
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
> **Related skills:** Before claiming done, use `/skill:executing-tasks` to verify tests actually pass.
|
|
7
|
-
|
|
8
|
-
# Test-Driven Development (TDD)
|
|
9
|
-
|
|
10
|
-
## Overview
|
|
11
|
-
|
|
12
|
-
Write the test first. Watch it fail. Write minimal code to pass.
|
|
13
|
-
|
|
14
|
-
**Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
|
|
15
|
-
|
|
16
|
-
**Violating the letter of the rules is violating the spirit of the rules.**
|
|
17
|
-
|
|
18
|
-
## Prerequisites
|
|
19
|
-
- Active branch (not main) or user-confirmed intent to work on main
|
|
20
|
-
- Approved plan or clear task scope
|
|
21
|
-
|
|
22
|
-
## When to Use — Three Scenarios
|
|
23
|
-
|
|
24
|
-
Not every change requires the same TDD approach. Determine which scenario applies:
|
|
25
|
-
|
|
26
|
-
### Scenario 1: New Feature / New File
|
|
27
|
-
|
|
28
|
-
Full TDD cycle. No shortcuts.
|
|
29
|
-
|
|
30
|
-
1. Write a failing test
|
|
31
|
-
2. Watch it fail
|
|
32
|
-
3. Write minimal code to pass
|
|
33
|
-
4. Watch it pass
|
|
34
|
-
5. Refactor
|
|
35
|
-
6. Repeat
|
|
36
|
-
|
|
37
|
-
**This is the default.** If in doubt, use this scenario.
|
|
38
|
-
|
|
39
|
-
### Scenario 2: Modifying Code with Existing Tests
|
|
40
|
-
|
|
41
|
-
When changing code that already has test coverage:
|
|
42
|
-
|
|
43
|
-
1. Run existing tests — confirm green
|
|
44
|
-
2. Make your change
|
|
45
|
-
3. Run tests again — confirm still green
|
|
46
|
-
4. If your change isn't covered by existing tests, add a test for it
|
|
47
|
-
5. If existing tests already cover the changed behavior, you're done
|
|
48
|
-
|
|
49
|
-
**Key:** You must verify existing tests pass *before* and *after* your change. If you can't confirm test coverage, fall back to Scenario 1.
|
|
50
|
-
|
|
51
|
-
### Scenario 3: Trivial Change
|
|
52
|
-
|
|
53
|
-
For typo fixes, config tweaks, string changes, renames:
|
|
54
|
-
|
|
55
|
-
- Use judgment
|
|
56
|
-
- If relevant tests exist, run them after your change
|
|
57
|
-
- Don't write a new test for a string literal change
|
|
58
|
-
|
|
59
|
-
**Be honest:** If the change touches logic, it's not trivial. Use Scenario 1 or 2.
|
|
60
|
-
|
|
61
|
-
### Scenario 4: If You See a ⚠️ TDD Warning
|
|
62
|
-
|
|
63
|
-
The workflow monitor detected a potential TDD violation. Pause and assess:
|
|
64
|
-
|
|
65
|
-
1. **Identify your scenario** — which of 1, 2, or 3 applies to this change?
|
|
66
|
-
2. **Scenario 1 (new file):** If no test exists yet, stop, delete any written source code, write a failing test first, then re-implement.
|
|
67
|
-
3. **Scenario 2 (existing tests):** Run the existing tests now. Confirm they're green. Then proceed with your change. Run them again after.
|
|
68
|
-
4. **Scenario 3 (trivial):** If the change truly is trivial, run relevant tests after and continue.
|
|
69
|
-
|
|
70
|
-
The warning is a signal to think, not a hard stop. But if you can't clearly identify which scenario applies, default to Scenario 1.
|
|
71
|
-
|
|
72
|
-
## Interpreting Runtime Warnings
|
|
73
|
-
|
|
74
|
-
The workflow monitor tracks your TDD phase and may inject warnings like:
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
⚠️ TDD: Writing source code (src/foo.ts) without a failing test.
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
**When you see this, pause and assess:**
|
|
81
|
-
- Which scenario applies to this change?
|
|
82
|
-
- If Scenario 2: run existing tests to confirm coverage, then proceed
|
|
83
|
-
- If Scenario 1: write a failing test first
|
|
84
|
-
- If Scenario 3: proceed, run tests after
|
|
85
|
-
|
|
86
|
-
The warning is a signal to think, not a hard stop.
|
|
87
|
-
|
|
88
|
-
## The Iron Law (Scenario 1)
|
|
89
|
-
|
|
90
|
-
```
|
|
91
|
-
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Write code before the test? Delete it. Start over.
|
|
95
|
-
- Don't keep it as "reference"
|
|
96
|
-
- Don't "adapt" it while writing tests
|
|
97
|
-
- Delete means delete. Implement fresh from tests.
|
|
98
|
-
|
|
99
|
-
## Red-Green-Refactor
|
|
100
|
-
|
|
101
|
-
### RED — Write Failing Test
|
|
102
|
-
|
|
103
|
-
Write one minimal test showing what should happen.
|
|
104
|
-
|
|
105
|
-
**Requirements:**
|
|
106
|
-
- One behavior per test
|
|
107
|
-
- Clear name describing behavior (if the name contains "and", split it)
|
|
108
|
-
- Real code (no mocks unless unavoidable)
|
|
109
|
-
- Shows desired API — demonstrates how code should be called
|
|
110
|
-
|
|
111
|
-
**Good:**
|
|
112
|
-
```typescript
|
|
113
|
-
test('retries failed operations 3 times', async () => {
|
|
114
|
-
let attempts = 0;
|
|
115
|
-
const operation = () => {
|
|
116
|
-
attempts++;
|
|
117
|
-
if (attempts < 3) throw new Error('fail');
|
|
118
|
-
return 'success';
|
|
119
|
-
};
|
|
120
|
-
const result = await retryOperation(operation);
|
|
121
|
-
expect(result).toBe('success');
|
|
122
|
-
expect(attempts).toBe(3);
|
|
123
|
-
});
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
**Bad:**
|
|
127
|
-
```typescript
|
|
128
|
-
test('retry works', async () => {
|
|
129
|
-
const mock = jest.fn().mockRejectedValueOnce(new Error()).mockResolvedValueOnce('ok');
|
|
130
|
-
await retryOperation(mock);
|
|
131
|
-
expect(mock).toHaveBeenCalledTimes(2);
|
|
132
|
-
});
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Verify RED — Watch It Fail
|
|
136
|
-
|
|
137
|
-
**MANDATORY. Never skip.**
|
|
138
|
-
|
|
139
|
-
Run the test. Confirm:
|
|
140
|
-
- Test **fails** (not errors from syntax/import issues)
|
|
141
|
-
- Failure message matches expectation
|
|
142
|
-
- Fails because the feature is missing (not because of typos)
|
|
143
|
-
|
|
144
|
-
**Test passes immediately?** You're testing existing behavior. Fix the test.
|
|
145
|
-
**Test errors instead of failing?** Fix the error, re-run until it fails correctly.
|
|
146
|
-
|
|
147
|
-
### GREEN — Minimal Code
|
|
148
|
-
|
|
149
|
-
Write the simplest code to pass the test. Nothing more.
|
|
150
|
-
|
|
151
|
-
Don't add features, refactor other code, or "improve" beyond what the test requires. If you're writing code that no test exercises, stop.
|
|
152
|
-
|
|
153
|
-
**Good:** Just enough to pass the test.
|
|
154
|
-
**Bad:** Adding options, config, generalization that no test asks for (YAGNI).
|
|
155
|
-
|
|
156
|
-
### Verify GREEN — Watch It Pass
|
|
157
|
-
|
|
158
|
-
**MANDATORY.**
|
|
159
|
-
|
|
160
|
-
Run the test. Confirm:
|
|
161
|
-
- New test passes
|
|
162
|
-
- All other tests still pass
|
|
163
|
-
- Output is pristine (no errors, no warnings)
|
|
164
|
-
|
|
165
|
-
**Test fails?** Fix code, not test.
|
|
166
|
-
**Other tests fail?** Fix now — don't move on with broken tests.
|
|
167
|
-
|
|
168
|
-
### REFACTOR — Clean Up
|
|
169
|
-
|
|
170
|
-
Only after green:
|
|
171
|
-
- Remove duplication
|
|
172
|
-
- Improve names
|
|
173
|
-
- Extract helpers
|
|
174
|
-
|
|
175
|
-
Keep tests green throughout. Don't add new behavior during refactor.
|
|
176
|
-
|
|
177
|
-
### Repeat
|
|
178
|
-
|
|
179
|
-
Next failing test for next behavior.
|
|
180
|
-
|
|
181
|
-
## Common Rationalizations
|
|
182
|
-
|
|
183
|
-
| Excuse | Reality |
|
|
184
|
-
|--------|---------|
|
|
185
|
-
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
186
|
-
| "I'll test after" | Tests passing immediately prove nothing. |
|
|
187
|
-
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
|
|
188
|
-
| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
|
|
189
|
-
| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
|
|
190
|
-
| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
|
|
191
|
-
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
|
|
192
|
-
| "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
|
|
193
|
-
| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
|
|
194
|
-
| "Existing code has no tests" | You're improving it. Add tests for the code you're changing. |
|
|
195
|
-
| "This is different because..." | It's not. Follow the process. |
|
|
196
|
-
|
|
197
|
-
## Red Flags — STOP and Start Over
|
|
198
|
-
|
|
199
|
-
If you catch yourself doing any of these, stop immediately:
|
|
200
|
-
|
|
201
|
-
- Writing production code before the test
|
|
202
|
-
- Writing tests after implementation
|
|
203
|
-
- Test passes immediately (didn't catch the bug)
|
|
204
|
-
- Can't explain why test failed
|
|
205
|
-
- Rationalizing "just this once"
|
|
206
|
-
- "I already manually tested it"
|
|
207
|
-
- "Keep as reference" or "adapt existing code"
|
|
208
|
-
- "Already spent X hours, deleting is wasteful"
|
|
209
|
-
- "TDD is dogmatic, I'm being pragmatic"
|
|
210
|
-
|
|
211
|
-
**All of these mean: Delete code. Start over with TDD.**
|
|
212
|
-
|
|
213
|
-
## Verification Checklist
|
|
214
|
-
|
|
215
|
-
Before marking work complete:
|
|
216
|
-
|
|
217
|
-
- [ ] Every new function/method has a test
|
|
218
|
-
- [ ] Watched each test fail before implementing
|
|
219
|
-
- [ ] Each test failed for expected reason (feature missing, not typo)
|
|
220
|
-
- [ ] Wrote minimal code to pass each test
|
|
221
|
-
- [ ] All tests pass
|
|
222
|
-
- [ ] Output pristine (no errors, warnings)
|
|
223
|
-
- [ ] Tests use real code (mocks only if unavoidable)
|
|
224
|
-
- [ ] Edge cases and errors covered
|
|
225
|
-
|
|
226
|
-
Can't check all boxes? You skipped TDD. Start over.
|
|
227
|
-
|
|
228
|
-
## When Stuck
|
|
229
|
-
|
|
230
|
-
| Problem | Solution |
|
|
231
|
-
|---------|----------|
|
|
232
|
-
| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
|
|
233
|
-
| Test too complicated | Design too complicated. Simplify interface. |
|
|
234
|
-
| Must mock everything | Code too coupled. Use dependency injection. |
|
|
235
|
-
| Test setup huge | Extract helpers. Still complex? Simplify design. |
|
|
236
|
-
|
|
237
|
-
## Debugging Integration
|
|
238
|
-
|
|
239
|
-
Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression. Never fix bugs without a test.
|
|
240
|
-
|
|
241
|
-
## Testing Anti-Patterns
|
|
242
|
-
|
|
243
|
-
When adding mocks or test utilities, read `testing-anti-patterns.md` in this skill directory to avoid common pitfalls:
|
|
244
|
-
- Testing mock behavior instead of real behavior
|
|
245
|
-
- Adding test-only methods to production classes
|
|
246
|
-
- Mocking without understanding dependencies
|
|
247
|
-
|
|
248
|
-
## Reference
|
|
249
|
-
|
|
250
|
-
Use `workflow_reference` for additional detail:
|
|
251
|
-
- `tdd-rationalizations` — Extended rationalization discussion
|
|
252
|
-
- `tdd-examples` — More good/bad code examples, bug fix walkthrough
|
|
253
|
-
- `tdd-when-stuck` — Extended solutions for common blockers
|
|
254
|
-
- `tdd-anti-patterns` — Mock pitfalls, test-only methods, incomplete mocks
|
|
255
|
-
|
|
256
|
-
## Final Rule
|
|
257
|
-
|
|
258
|
-
```
|
|
259
|
-
Production code → test exists and failed first (Scenario 1)
|
|
260
|
-
Modifying tested code → existing tests verified before and after (Scenario 2)
|
|
261
|
-
Trivial change → relevant tests run after (Scenario 3)
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
No exceptions without your human partner's permission.
|
|
265
|
-
|
|
266
|
-
When the TDD implementation cycle is complete (all tests green, code committed), the orchestrating agent updates `plan_tracker` for the current task as part of the executing-tasks lifecycle.
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# TDD Examples Reference
|
|
2
|
-
|
|
3
|
-
**Load via:** `workflow_reference({ topic: "tdd-examples" })`
|
|
4
|
-
|
|
5
|
-
## Good vs Bad Tests
|
|
6
|
-
|
|
7
|
-
### RED — Write Failing Test
|
|
8
|
-
|
|
9
|
-
<Good>
|
|
10
|
-
```typescript
|
|
11
|
-
test('retries failed operations 3 times', async () => {
|
|
12
|
-
let attempts = 0;
|
|
13
|
-
const operation = () => {
|
|
14
|
-
attempts++;
|
|
15
|
-
if (attempts < 3) throw new Error('fail');
|
|
16
|
-
return 'success';
|
|
17
|
-
};
|
|
18
|
-
const result = await retryOperation(operation);
|
|
19
|
-
expect(result).toBe('success');
|
|
20
|
-
expect(attempts).toBe(3);
|
|
21
|
-
});
|
|
22
|
-
```
|
|
23
|
-
Clear name, tests real behavior, one thing
|
|
24
|
-
</Good>
|
|
25
|
-
|
|
26
|
-
<Bad>
|
|
27
|
-
```typescript
|
|
28
|
-
test('retry works', async () => {
|
|
29
|
-
const mock = jest.fn()
|
|
30
|
-
.mockRejectedValueOnce(new Error())
|
|
31
|
-
.mockRejectedValueOnce(new Error())
|
|
32
|
-
.mockResolvedValueOnce('success');
|
|
33
|
-
await retryOperation(mock);
|
|
34
|
-
expect(mock).toHaveBeenCalledTimes(3);
|
|
35
|
-
});
|
|
36
|
-
```
|
|
37
|
-
Vague name, tests mock not code
|
|
38
|
-
</Bad>
|
|
39
|
-
|
|
40
|
-
### GREEN — Minimal Code
|
|
41
|
-
|
|
42
|
-
<Good>
|
|
43
|
-
```typescript
|
|
44
|
-
async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
|
|
45
|
-
for (let i = 0; i < 3; i++) {
|
|
46
|
-
try { return await fn(); }
|
|
47
|
-
catch (e) { if (i === 2) throw e; }
|
|
48
|
-
}
|
|
49
|
-
throw new Error('unreachable');
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
Just enough to pass
|
|
53
|
-
</Good>
|
|
54
|
-
|
|
55
|
-
<Bad>
|
|
56
|
-
```typescript
|
|
57
|
-
async function retryOperation<T>(
|
|
58
|
-
fn: () => Promise<T>,
|
|
59
|
-
options?: { maxRetries?: number; backoff?: 'linear' | 'exponential'; onRetry?: (attempt: number) => void }
|
|
60
|
-
): Promise<T> { /* YAGNI */ }
|
|
61
|
-
```
|
|
62
|
-
Over-engineered
|
|
63
|
-
</Bad>
|
|
64
|
-
|
|
65
|
-
## Good Tests Table
|
|
66
|
-
|
|
67
|
-
| Quality | Good | Bad |
|
|
68
|
-
|---------|------|-----|
|
|
69
|
-
| **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
|
|
70
|
-
| **Clear** | Name describes behavior | `test('test1')` |
|
|
71
|
-
| **Shows intent** | Demonstrates desired API | Obscures what code should do |
|
|
72
|
-
|
|
73
|
-
## Bug Fix Example
|
|
74
|
-
|
|
75
|
-
**Bug:** Empty email accepted
|
|
76
|
-
|
|
77
|
-
**RED**
|
|
78
|
-
```typescript
|
|
79
|
-
test('rejects empty email', async () => {
|
|
80
|
-
const result = await submitForm({ email: '' });
|
|
81
|
-
expect(result.error).toBe('Email required');
|
|
82
|
-
});
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
**Verify RED**
|
|
86
|
-
```bash
|
|
87
|
-
$ npm test
|
|
88
|
-
FAIL: expected 'Email required', got undefined
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
**GREEN**
|
|
92
|
-
```typescript
|
|
93
|
-
function submitForm(data: FormData) {
|
|
94
|
-
if (!data.email?.trim()) return { error: 'Email required' };
|
|
95
|
-
// ...
|
|
96
|
-
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
**Verify GREEN** → PASS
|
|
100
|
-
|
|
101
|
-
**REFACTOR** — Extract validation for multiple fields if needed.
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# TDD Rationalizations Reference
|
|
2
|
-
|
|
3
|
-
**Load via:** `workflow_reference({ topic: "tdd-rationalizations" })`
|
|
4
|
-
|
|
5
|
-
## Why Order Matters
|
|
6
|
-
|
|
7
|
-
**"I'll write tests after to verify it works"**
|
|
8
|
-
Tests written after code pass immediately. Passing immediately proves nothing:
|
|
9
|
-
- Might test wrong thing
|
|
10
|
-
- Might test implementation, not behavior
|
|
11
|
-
- Might miss edge cases you forgot
|
|
12
|
-
- You never saw it catch the bug
|
|
13
|
-
|
|
14
|
-
Test-first forces you to see the test fail, proving it actually tests something.
|
|
15
|
-
|
|
16
|
-
**"I already manually tested all the edge cases"**
|
|
17
|
-
Manual testing is ad-hoc. You think you tested everything but:
|
|
18
|
-
- No record of what you tested
|
|
19
|
-
- Can't re-run when code changes
|
|
20
|
-
- Easy to forget cases under pressure
|
|
21
|
-
- "It worked when I tried it" ≠ comprehensive
|
|
22
|
-
|
|
23
|
-
**"Deleting X hours of work is wasteful"**
|
|
24
|
-
Sunk cost fallacy. The time is already gone. Your choice:
|
|
25
|
-
- Delete and rewrite with TDD (X more hours, high confidence)
|
|
26
|
-
- Keep it and add tests after (30 min, low confidence, likely bugs)
|
|
27
|
-
|
|
28
|
-
**"TDD is dogmatic, being pragmatic means adapting"**
|
|
29
|
-
TDD IS pragmatic. "Pragmatic" shortcuts = debugging in production = slower.
|
|
30
|
-
|
|
31
|
-
**"Tests after achieve the same goals - it's spirit not ritual"**
|
|
32
|
-
Tests-after answer "What does this do?" Tests-first answer "What should this do?"
|
|
33
|
-
Tests-after are biased by your implementation. 30 minutes of tests after ≠ TDD.
|
|
34
|
-
|
|
35
|
-
## Common Rationalizations Table
|
|
36
|
-
|
|
37
|
-
| Excuse | Reality |
|
|
38
|
-
|--------|---------|
|
|
39
|
-
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
40
|
-
| "I'll test after" | Tests passing immediately prove nothing. |
|
|
41
|
-
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
|
|
42
|
-
| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
|
|
43
|
-
| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
|
|
44
|
-
| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
|
|
45
|
-
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
|
|
46
|
-
| "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
|
|
47
|
-
| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
|
|
48
|
-
| "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
|
|
49
|
-
| "Existing code has no tests" | You're improving it. Add tests for existing code. |
|
|
50
|
-
|
|
51
|
-
## Red Flags — STOP and Start Over
|
|
52
|
-
|
|
53
|
-
- Code before test
|
|
54
|
-
- Test after implementation
|
|
55
|
-
- Test passes immediately
|
|
56
|
-
- Can't explain why test failed
|
|
57
|
-
- Tests added "later"
|
|
58
|
-
- Rationalizing "just this once"
|
|
59
|
-
- "I already manually tested it"
|
|
60
|
-
- "Tests after achieve the same purpose"
|
|
61
|
-
- "It's about spirit not ritual"
|
|
62
|
-
- "Keep as reference" or "adapt existing code"
|
|
63
|
-
- "Already spent X hours, deleting is wasteful"
|
|
64
|
-
- "TDD is dogmatic, I'm being pragmatic"
|
|
65
|
-
- "This is different because..."
|
|
66
|
-
|
|
67
|
-
**All of these mean: Delete code. Start over with TDD.**
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# TDD When Stuck Reference
|
|
2
|
-
|
|
3
|
-
**Load via:** `workflow_reference({ topic: "tdd-when-stuck" })`
|
|
4
|
-
|
|
5
|
-
## When Stuck
|
|
6
|
-
|
|
7
|
-
| Problem | Solution |
|
|
8
|
-
|---------|----------|
|
|
9
|
-
| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
|
|
10
|
-
| Test too complicated | Design too complicated. Simplify interface. |
|
|
11
|
-
| Must mock everything | Code too coupled. Use dependency injection. |
|
|
12
|
-
| Test setup huge | Extract helpers. Still complex? Simplify design. |
|
|
13
|
-
|
|
14
|
-
## Verification Checklist
|
|
15
|
-
|
|
16
|
-
Before marking work complete:
|
|
17
|
-
|
|
18
|
-
- [ ] Every new function/method has a test
|
|
19
|
-
- [ ] Watched each test fail before implementing
|
|
20
|
-
- [ ] Each test failed for expected reason (feature missing, not typo)
|
|
21
|
-
- [ ] Wrote minimal code to pass each test
|
|
22
|
-
- [ ] All tests pass
|
|
23
|
-
- [ ] Output pristine (no errors, warnings)
|
|
24
|
-
- [ ] Tests use real code (mocks only if unavoidable)
|
|
25
|
-
- [ ] Edge cases and errors covered
|
|
26
|
-
|
|
27
|
-
Can't check all boxes? You skipped TDD. Start over.
|
|
28
|
-
|
|
29
|
-
## Debugging Integration
|
|
30
|
-
|
|
31
|
-
Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
|
|
32
|
-
|
|
33
|
-
Never fix bugs without a test.
|