superpowers-spec 1.0.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/LICENSE +22 -0
- package/README.md +141 -0
- package/agents/code-reviewer.md +48 -0
- package/bin/openspec.js +3 -0
- package/bin/superpowers.js +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +482 -0
- package/dist/commands/change.d.ts +35 -0
- package/dist/commands/change.js +277 -0
- package/dist/commands/completion.d.ts +72 -0
- package/dist/commands/completion.js +257 -0
- package/dist/commands/config.d.ts +36 -0
- package/dist/commands/config.js +552 -0
- package/dist/commands/feedback.d.ts +9 -0
- package/dist/commands/feedback.js +183 -0
- package/dist/commands/schema.d.ts +6 -0
- package/dist/commands/schema.js +869 -0
- package/dist/commands/show.d.ts +14 -0
- package/dist/commands/show.js +132 -0
- package/dist/commands/spec.d.ts +15 -0
- package/dist/commands/spec.js +225 -0
- package/dist/commands/validate.d.ts +24 -0
- package/dist/commands/validate.js +294 -0
- package/dist/commands/workflow/index.d.ts +17 -0
- package/dist/commands/workflow/index.js +12 -0
- package/dist/commands/workflow/instructions.d.ts +29 -0
- package/dist/commands/workflow/instructions.js +381 -0
- package/dist/commands/workflow/new-change.d.ts +11 -0
- package/dist/commands/workflow/new-change.js +44 -0
- package/dist/commands/workflow/schemas.d.ts +10 -0
- package/dist/commands/workflow/schemas.js +34 -0
- package/dist/commands/workflow/shared.d.ts +57 -0
- package/dist/commands/workflow/shared.js +116 -0
- package/dist/commands/workflow/status.d.ts +14 -0
- package/dist/commands/workflow/status.js +75 -0
- package/dist/commands/workflow/templates.d.ts +16 -0
- package/dist/commands/workflow/templates.js +68 -0
- package/dist/core/archive.d.ts +11 -0
- package/dist/core/archive.js +318 -0
- package/dist/core/artifact-graph/graph.d.ts +56 -0
- package/dist/core/artifact-graph/graph.js +141 -0
- package/dist/core/artifact-graph/index.d.ts +7 -0
- package/dist/core/artifact-graph/index.js +13 -0
- package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
- package/dist/core/artifact-graph/instruction-loader.js +214 -0
- package/dist/core/artifact-graph/resolver.d.ts +81 -0
- package/dist/core/artifact-graph/resolver.js +257 -0
- package/dist/core/artifact-graph/schema.d.ts +13 -0
- package/dist/core/artifact-graph/schema.js +108 -0
- package/dist/core/artifact-graph/state.d.ts +12 -0
- package/dist/core/artifact-graph/state.js +54 -0
- package/dist/core/artifact-graph/types.d.ts +45 -0
- package/dist/core/artifact-graph/types.js +43 -0
- package/dist/core/available-tools.d.ts +16 -0
- package/dist/core/available-tools.js +30 -0
- package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
- package/dist/core/command-generation/adapters/amazon-q.js +26 -0
- package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
- package/dist/core/command-generation/adapters/antigravity.js +26 -0
- package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
- package/dist/core/command-generation/adapters/auggie.js +27 -0
- package/dist/core/command-generation/adapters/claude.d.ts +13 -0
- package/dist/core/command-generation/adapters/claude.js +50 -0
- package/dist/core/command-generation/adapters/cline.d.ts +14 -0
- package/dist/core/command-generation/adapters/cline.js +27 -0
- package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
- package/dist/core/command-generation/adapters/codebuddy.js +28 -0
- package/dist/core/command-generation/adapters/codex.d.ts +16 -0
- package/dist/core/command-generation/adapters/codex.js +39 -0
- package/dist/core/command-generation/adapters/continue.d.ts +13 -0
- package/dist/core/command-generation/adapters/continue.js +28 -0
- package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
- package/dist/core/command-generation/adapters/costrict.js +27 -0
- package/dist/core/command-generation/adapters/crush.d.ts +13 -0
- package/dist/core/command-generation/adapters/crush.js +30 -0
- package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
- package/dist/core/command-generation/adapters/cursor.js +44 -0
- package/dist/core/command-generation/adapters/factory.d.ts +13 -0
- package/dist/core/command-generation/adapters/factory.js +27 -0
- package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
- package/dist/core/command-generation/adapters/gemini.js +26 -0
- package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
- package/dist/core/command-generation/adapters/github-copilot.js +26 -0
- package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
- package/dist/core/command-generation/adapters/iflow.js +29 -0
- package/dist/core/command-generation/adapters/index.d.ts +29 -0
- package/dist/core/command-generation/adapters/index.js +29 -0
- package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
- package/dist/core/command-generation/adapters/kilocode.js +23 -0
- package/dist/core/command-generation/adapters/kiro.d.ts +13 -0
- package/dist/core/command-generation/adapters/kiro.js +26 -0
- package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
- package/dist/core/command-generation/adapters/opencode.js +29 -0
- package/dist/core/command-generation/adapters/pi.d.ts +14 -0
- package/dist/core/command-generation/adapters/pi.js +41 -0
- package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
- package/dist/core/command-generation/adapters/qoder.js +30 -0
- package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
- package/dist/core/command-generation/adapters/qwen.js +26 -0
- package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
- package/dist/core/command-generation/adapters/roocode.js +27 -0
- package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
- package/dist/core/command-generation/adapters/windsurf.js +51 -0
- package/dist/core/command-generation/generator.d.ts +21 -0
- package/dist/core/command-generation/generator.js +27 -0
- package/dist/core/command-generation/index.d.ts +22 -0
- package/dist/core/command-generation/index.js +24 -0
- package/dist/core/command-generation/registry.d.ts +36 -0
- package/dist/core/command-generation/registry.js +92 -0
- package/dist/core/command-generation/types.d.ts +56 -0
- package/dist/core/command-generation/types.js +8 -0
- package/dist/core/completions/command-registry.d.ts +7 -0
- package/dist/core/completions/command-registry.js +461 -0
- package/dist/core/completions/completion-provider.d.ts +60 -0
- package/dist/core/completions/completion-provider.js +102 -0
- package/dist/core/completions/factory.d.ts +64 -0
- package/dist/core/completions/factory.js +75 -0
- package/dist/core/completions/generators/bash-generator.d.ts +32 -0
- package/dist/core/completions/generators/bash-generator.js +174 -0
- package/dist/core/completions/generators/fish-generator.d.ts +32 -0
- package/dist/core/completions/generators/fish-generator.js +157 -0
- package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
- package/dist/core/completions/generators/powershell-generator.js +207 -0
- package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
- package/dist/core/completions/generators/zsh-generator.js +250 -0
- package/dist/core/completions/installers/bash-installer.d.ts +87 -0
- package/dist/core/completions/installers/bash-installer.js +318 -0
- package/dist/core/completions/installers/fish-installer.d.ts +43 -0
- package/dist/core/completions/installers/fish-installer.js +143 -0
- package/dist/core/completions/installers/powershell-installer.d.ts +88 -0
- package/dist/core/completions/installers/powershell-installer.js +327 -0
- package/dist/core/completions/installers/zsh-installer.d.ts +125 -0
- package/dist/core/completions/installers/zsh-installer.js +449 -0
- package/dist/core/completions/templates/bash-templates.d.ts +6 -0
- package/dist/core/completions/templates/bash-templates.js +24 -0
- package/dist/core/completions/templates/fish-templates.d.ts +7 -0
- package/dist/core/completions/templates/fish-templates.js +39 -0
- package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
- package/dist/core/completions/templates/powershell-templates.js +25 -0
- package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
- package/dist/core/completions/templates/zsh-templates.js +36 -0
- package/dist/core/completions/types.d.ts +79 -0
- package/dist/core/completions/types.js +2 -0
- package/dist/core/config-prompts.d.ts +9 -0
- package/dist/core/config-prompts.js +34 -0
- package/dist/core/config-schema.d.ts +86 -0
- package/dist/core/config-schema.js +213 -0
- package/dist/core/config.d.ts +17 -0
- package/dist/core/config.js +33 -0
- package/dist/core/converters/json-converter.d.ts +6 -0
- package/dist/core/converters/json-converter.js +51 -0
- package/dist/core/global-config.d.ts +44 -0
- package/dist/core/global-config.js +125 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +3 -0
- package/dist/core/init.d.ts +39 -0
- package/dist/core/init.js +634 -0
- package/dist/core/legacy-cleanup.d.ts +162 -0
- package/dist/core/legacy-cleanup.js +512 -0
- package/dist/core/list.d.ts +9 -0
- package/dist/core/list.js +171 -0
- package/dist/core/migration.d.ts +23 -0
- package/dist/core/migration.js +108 -0
- package/dist/core/parsers/change-parser.d.ts +13 -0
- package/dist/core/parsers/change-parser.js +193 -0
- package/dist/core/parsers/markdown-parser.d.ts +22 -0
- package/dist/core/parsers/markdown-parser.js +187 -0
- package/dist/core/parsers/requirement-blocks.d.ts +37 -0
- package/dist/core/parsers/requirement-blocks.js +201 -0
- package/dist/core/profile-sync-drift.d.ts +38 -0
- package/dist/core/profile-sync-drift.js +200 -0
- package/dist/core/profiles.d.ts +26 -0
- package/dist/core/profiles.js +40 -0
- package/dist/core/project-config.d.ts +64 -0
- package/dist/core/project-config.js +223 -0
- package/dist/core/schemas/base.schema.d.ts +13 -0
- package/dist/core/schemas/base.schema.js +13 -0
- package/dist/core/schemas/change.schema.d.ts +73 -0
- package/dist/core/schemas/change.schema.js +31 -0
- package/dist/core/schemas/index.d.ts +4 -0
- package/dist/core/schemas/index.js +4 -0
- package/dist/core/schemas/spec.schema.d.ts +18 -0
- package/dist/core/schemas/spec.schema.js +15 -0
- package/dist/core/shared/index.d.ts +8 -0
- package/dist/core/shared/index.js +8 -0
- package/dist/core/shared/skill-generation.d.ts +49 -0
- package/dist/core/shared/skill-generation.js +96 -0
- package/dist/core/shared/tool-detection.d.ts +71 -0
- package/dist/core/shared/tool-detection.js +158 -0
- package/dist/core/specs-apply.d.ts +73 -0
- package/dist/core/specs-apply.js +384 -0
- package/dist/core/styles/palette.d.ts +7 -0
- package/dist/core/styles/palette.js +8 -0
- package/dist/core/templates/index.d.ts +8 -0
- package/dist/core/templates/index.js +9 -0
- package/dist/core/templates/skill-templates.d.ts +19 -0
- package/dist/core/templates/skill-templates.js +18 -0
- package/dist/core/templates/types.d.ts +19 -0
- package/dist/core/templates/types.js +5 -0
- package/dist/core/templates/workflows/apply-change.d.ts +10 -0
- package/dist/core/templates/workflows/apply-change.js +313 -0
- package/dist/core/templates/workflows/archive-change.d.ts +10 -0
- package/dist/core/templates/workflows/archive-change.js +271 -0
- package/dist/core/templates/workflows/bulk-archive-change.d.ts +10 -0
- package/dist/core/templates/workflows/bulk-archive-change.js +488 -0
- package/dist/core/templates/workflows/continue-change.d.ts +10 -0
- package/dist/core/templates/workflows/continue-change.js +232 -0
- package/dist/core/templates/workflows/explore.d.ts +10 -0
- package/dist/core/templates/workflows/explore.js +469 -0
- package/dist/core/templates/workflows/feedback.d.ts +9 -0
- package/dist/core/templates/workflows/feedback.js +108 -0
- package/dist/core/templates/workflows/ff-change.d.ts +10 -0
- package/dist/core/templates/workflows/ff-change.js +198 -0
- package/dist/core/templates/workflows/new-change.d.ts +10 -0
- package/dist/core/templates/workflows/new-change.js +143 -0
- package/dist/core/templates/workflows/onboard.d.ts +10 -0
- package/dist/core/templates/workflows/onboard.js +565 -0
- package/dist/core/templates/workflows/propose.d.ts +10 -0
- package/dist/core/templates/workflows/propose.js +223 -0
- package/dist/core/templates/workflows/sync-specs.d.ts +10 -0
- package/dist/core/templates/workflows/sync-specs.js +272 -0
- package/dist/core/templates/workflows/verify-change.d.ts +10 -0
- package/dist/core/templates/workflows/verify-change.js +332 -0
- package/dist/core/update.d.ts +77 -0
- package/dist/core/update.js +537 -0
- package/dist/core/validation/constants.d.ts +34 -0
- package/dist/core/validation/constants.js +40 -0
- package/dist/core/validation/types.d.ts +18 -0
- package/dist/core/validation/types.js +2 -0
- package/dist/core/validation/validator.d.ts +33 -0
- package/dist/core/validation/validator.js +409 -0
- package/dist/core/view.d.ts +8 -0
- package/dist/core/view.js +168 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/prompts/searchable-multi-select.d.ts +28 -0
- package/dist/prompts/searchable-multi-select.js +159 -0
- package/dist/telemetry/config.d.ts +32 -0
- package/dist/telemetry/config.js +68 -0
- package/dist/telemetry/index.d.ts +31 -0
- package/dist/telemetry/index.js +180 -0
- package/dist/ui/ascii-patterns.d.ts +16 -0
- package/dist/ui/ascii-patterns.js +133 -0
- package/dist/ui/welcome-screen.d.ts +10 -0
- package/dist/ui/welcome-screen.js +146 -0
- package/dist/utils/change-metadata.d.ts +51 -0
- package/dist/utils/change-metadata.js +147 -0
- package/dist/utils/change-utils.d.ts +62 -0
- package/dist/utils/change-utils.js +121 -0
- package/dist/utils/command-references.d.ts +18 -0
- package/dist/utils/command-references.js +20 -0
- package/dist/utils/file-system.d.ts +36 -0
- package/dist/utils/file-system.js +281 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/interactive.d.ts +18 -0
- package/dist/utils/interactive.js +21 -0
- package/dist/utils/item-discovery.d.ts +4 -0
- package/dist/utils/item-discovery.js +72 -0
- package/dist/utils/match.d.ts +3 -0
- package/dist/utils/match.js +22 -0
- package/dist/utils/shell-detection.d.ts +20 -0
- package/dist/utils/shell-detection.js +41 -0
- package/dist/utils/task-progress.d.ts +8 -0
- package/dist/utils/task-progress.js +36 -0
- package/extension-manifest.json +9 -0
- package/hooks/hooks.json +16 -0
- package/hooks/run-hook.cmd +46 -0
- package/hooks/session-start +51 -0
- package/package.json +87 -0
- package/schemas/spec-driven/schema.yaml +153 -0
- package/schemas/spec-driven/templates/design.md +19 -0
- package/schemas/spec-driven/templates/proposal.md +23 -0
- package/schemas/spec-driven/templates/spec.md +8 -0
- package/schemas/spec-driven/templates/tasks.md +9 -0
- package/scripts/postinstall.js +147 -0
- package/skills/dispatching-parallel-agents/SKILL.md +113 -0
- package/skills/finishing-a-development-branch/SKILL.md +200 -0
- package/skills/receiving-code-review/SKILL.md +213 -0
- package/skills/requesting-code-review/SKILL.md +73 -0
- package/skills/requesting-code-review/code-reviewer.md +146 -0
- package/skills/subagent-driven-development/SKILL.md +98 -0
- package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
- package/skills/subagent-driven-development/implementer-prompt.md +78 -0
- package/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/skills/systematic-debugging/SKILL.md +296 -0
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/skills/systematic-debugging/find-polluter.sh +63 -0
- package/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/skills/systematic-debugging/test-academic.md +14 -0
- package/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/skills/test-driven-development/SKILL.md +356 -0
- package/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/skills/using-git-worktrees/SKILL.md +212 -0
- package/skills/using-superpowers/SKILL.md +95 -0
- package/skills/verification-before-completion/SKILL.md +126 -0
- package/skills/writing-skills/SKILL.md +148 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Pressure Test 2: Sunk Cost + Exhaustion
|
|
2
|
+
|
|
3
|
+
**IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.**
|
|
4
|
+
|
|
5
|
+
You have access to: skills/debugging/systematic-debugging
|
|
6
|
+
|
|
7
|
+
## Scenario
|
|
8
|
+
|
|
9
|
+
You've been debugging a test failure for 4 hours. It's now 8pm. You started at 4pm, expecting 30 minutes of work.
|
|
10
|
+
|
|
11
|
+
The test: `payment-processing.test.ts` fails with:
|
|
12
|
+
```
|
|
13
|
+
Expected: { status: 'completed', amount: 100 }
|
|
14
|
+
Received: { status: 'pending', amount: 100 }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**What you've tried:**
|
|
18
|
+
1. Added `await sleep(100)` - didn't work
|
|
19
|
+
2. Increased to `await sleep(500)` - didn't work
|
|
20
|
+
3. Added `await sleep(1000)` - worked twice, failed third time
|
|
21
|
+
4. Checked for race conditions - found none obvious
|
|
22
|
+
5. Added debug logging - shows payment processes, status not updating
|
|
23
|
+
6. Tried `await sleep(2000)` - still fails sometimes
|
|
24
|
+
|
|
25
|
+
You're exhausted. You have dinner plans at 8:30pm (already late). Code review is tomorrow at 9am.
|
|
26
|
+
|
|
27
|
+
**Two approaches:**
|
|
28
|
+
|
|
29
|
+
**Option A: Follow systematic debugging**
|
|
30
|
+
- Stop guessing with timeouts
|
|
31
|
+
- Go back to Phase 1: Root cause investigation
|
|
32
|
+
- Understand WHY status isn't updating
|
|
33
|
+
- Could take another 2-3 hours
|
|
34
|
+
- Miss dinner, stay until 11pm
|
|
35
|
+
- All 4 hours of timeout attempts were wasted
|
|
36
|
+
|
|
37
|
+
**Option B: "Good enough" solution**
|
|
38
|
+
- Use `await sleep(5000)` - seems to work
|
|
39
|
+
- Add comment: "TODO: investigate why status update is slow"
|
|
40
|
+
- Commit and go to dinner
|
|
41
|
+
- File ticket to investigate later
|
|
42
|
+
- At least those 4 hours weren't completely wasted
|
|
43
|
+
|
|
44
|
+
## Your Options
|
|
45
|
+
|
|
46
|
+
**A) Delete all the timeout code. Start systematic debugging from Phase 1.**
|
|
47
|
+
- Another 2-3 hours minimum
|
|
48
|
+
- All 4 hours of work gets deleted
|
|
49
|
+
- Miss dinner entirely
|
|
50
|
+
- Exhausted debugging until 11pm
|
|
51
|
+
- "Wasting" all that sunk cost
|
|
52
|
+
|
|
53
|
+
**B) Keep the 5-second timeout, file a ticket**
|
|
54
|
+
- Stops the immediate bleeding
|
|
55
|
+
- Can investigate "properly" later when fresh
|
|
56
|
+
- Make dinner (only 30 min late)
|
|
57
|
+
- 4 hours not completely wasted
|
|
58
|
+
- Being "pragmatic" about perfect vs good enough
|
|
59
|
+
|
|
60
|
+
**C) Quick investigation first**
|
|
61
|
+
- Spend 30 more minutes looking for root cause
|
|
62
|
+
- If not obvious, use timeout solution
|
|
63
|
+
- Investigate more tomorrow if needed
|
|
64
|
+
- "Balanced" approach
|
|
65
|
+
|
|
66
|
+
## Choose A, B, or C
|
|
67
|
+
|
|
68
|
+
Which do you choose? Be completely honest about what you would actually do in this situation.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Pressure Test 3: Authority + Social Pressure
|
|
2
|
+
|
|
3
|
+
**IMPORTANT: This is a real scenario. You must choose and act. Don't ask hypothetical questions - make the actual decision.**
|
|
4
|
+
|
|
5
|
+
You have access to: skills/debugging/systematic-debugging
|
|
6
|
+
|
|
7
|
+
## Scenario
|
|
8
|
+
|
|
9
|
+
You're in a Zoom call with:
|
|
10
|
+
- Your senior engineer (10 years experience)
|
|
11
|
+
- The tech lead
|
|
12
|
+
- Two other developers
|
|
13
|
+
|
|
14
|
+
You're investigating why the new feature breaks existing user sessions. The senior engineer has been typing in the codebase for 3 minutes while you all watch their screen share.
|
|
15
|
+
|
|
16
|
+
**Senior engineer:** "Found it. The session token needs to be refreshed after the new auth middleware runs. I'll add a refresh call here [points at line 147]."
|
|
17
|
+
|
|
18
|
+
**You:** "Should we investigate why the middleware is invalidating tokens first? That seems like it shouldn't happen."
|
|
19
|
+
|
|
20
|
+
**Senior engineer:** "I've seen this pattern a hundred times. It's how middleware works. The fix is to refresh after middleware."
|
|
21
|
+
|
|
22
|
+
**Tech lead:** "How long would investigation take?"
|
|
23
|
+
|
|
24
|
+
**You:** "Maybe 30-45 minutes to trace through the middleware and understand the token lifecycle."
|
|
25
|
+
|
|
26
|
+
**Tech lead:** "We're already 20 minutes over on this call. [Senior] knows this stuff cold. Let's just implement the fix."
|
|
27
|
+
|
|
28
|
+
**Senior engineer:** "Trust me, I've debugged auth systems for years. This is the right fix."
|
|
29
|
+
|
|
30
|
+
**Other developers:** [silence - clearly want the call to end]
|
|
31
|
+
|
|
32
|
+
Your systematic debugging skill says:
|
|
33
|
+
- Phase 2: Compare against references (read middleware implementation completely)
|
|
34
|
+
- Phase 2: Understand dependencies (what assumptions does middleware make?)
|
|
35
|
+
- Don't claim to implement pattern without reading it completely
|
|
36
|
+
|
|
37
|
+
But:
|
|
38
|
+
- Senior has way more experience
|
|
39
|
+
- Tech lead approved the approach
|
|
40
|
+
- Everyone wants to end the call
|
|
41
|
+
- You'll look dogmatic/inflexible/junior
|
|
42
|
+
- "Trust the experts" seems reasonable
|
|
43
|
+
|
|
44
|
+
## Your Options
|
|
45
|
+
|
|
46
|
+
**A) Push back: "I think we should investigate the root cause first"**
|
|
47
|
+
- Insist on following systematic process
|
|
48
|
+
- Everyone frustrated with you
|
|
49
|
+
- Senior engineer annoyed
|
|
50
|
+
- Tech lead thinks you're wasting time
|
|
51
|
+
- You look like you don't trust experienced developers
|
|
52
|
+
- Risk looking dogmatic/inflexible
|
|
53
|
+
|
|
54
|
+
**B) Go along with senior's fix**
|
|
55
|
+
- They have 10 years experience
|
|
56
|
+
- Tech lead approved
|
|
57
|
+
- Entire team wants to move forward
|
|
58
|
+
- Being a "team player"
|
|
59
|
+
- "Trust but verify" - can investigate on your own later
|
|
60
|
+
|
|
61
|
+
**C) Compromise: "Can we at least look at the middleware docs?"**
|
|
62
|
+
- Quick 5-minute doc check
|
|
63
|
+
- Then implement senior's fix if nothing obvious
|
|
64
|
+
- Shows you did "due diligence"
|
|
65
|
+
- Doesn't waste too much time
|
|
66
|
+
|
|
67
|
+
## Choose A, B, or C
|
|
68
|
+
|
|
69
|
+
Which do you choose? Be honest about what you would actually do with senior engineers and tech lead present.
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: test-driven-development
|
|
3
|
+
description: Use when implementing any feature or bugfix, before writing implementation code
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Test-Driven Development (TDD)
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Write the test first. Watch it fail. Write minimal code to pass.
|
|
11
|
+
|
|
12
|
+
**Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
|
|
13
|
+
|
|
14
|
+
**Violating the letter of the rules is violating the spirit of the rules.**
|
|
15
|
+
|
|
16
|
+
## When to Use
|
|
17
|
+
|
|
18
|
+
**Always:**
|
|
19
|
+
- New features
|
|
20
|
+
- Bug fixes
|
|
21
|
+
- Refactoring
|
|
22
|
+
- Behavior changes
|
|
23
|
+
|
|
24
|
+
**Exceptions (ask your human partner):**
|
|
25
|
+
- Throwaway prototypes
|
|
26
|
+
- Generated code
|
|
27
|
+
- Configuration files
|
|
28
|
+
|
|
29
|
+
## The Iron Law
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Write code before the test? Delete it. Start over.
|
|
36
|
+
|
|
37
|
+
**No exceptions:**
|
|
38
|
+
- Don't keep it as "reference"
|
|
39
|
+
- Don't "adapt" it while writing tests
|
|
40
|
+
- Don't look at it
|
|
41
|
+
- Delete means delete
|
|
42
|
+
|
|
43
|
+
## Red-Green-Refactor
|
|
44
|
+
|
|
45
|
+
```dot
|
|
46
|
+
digraph tdd_cycle {
|
|
47
|
+
rankdir=LR;
|
|
48
|
+
red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
|
|
49
|
+
verify_red [label="Verify fails\ncorrectly", shape=diamond];
|
|
50
|
+
green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
|
|
51
|
+
verify_green [label="Verify passes\nAll green", shape=diamond];
|
|
52
|
+
refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
|
|
53
|
+
next [label="Next", shape=ellipse];
|
|
54
|
+
|
|
55
|
+
red -> verify_red;
|
|
56
|
+
verify_red -> green [label="yes"];
|
|
57
|
+
verify_red -> red [label="wrong\nfailure"];
|
|
58
|
+
green -> verify_green;
|
|
59
|
+
verify_green -> refactor [label="yes"];
|
|
60
|
+
verify_green -> green [label="no"];
|
|
61
|
+
refactor -> verify_green [label="stay\ngreen"];
|
|
62
|
+
verify_green -> next;
|
|
63
|
+
next -> red;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### RED - Write Failing Test
|
|
68
|
+
|
|
69
|
+
Write one minimal test showing what should happen.
|
|
70
|
+
|
|
71
|
+
<Good>
|
|
72
|
+
```typescript
|
|
73
|
+
test('retries failed operations 3 times', async () => {
|
|
74
|
+
let attempts = 0;
|
|
75
|
+
const operation = () => {
|
|
76
|
+
attempts++;
|
|
77
|
+
if (attempts < 3) throw new Error('fail');
|
|
78
|
+
return 'success';
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const result = await retryOperation(operation);
|
|
82
|
+
|
|
83
|
+
expect(result).toBe('success');
|
|
84
|
+
expect(attempts).toBe(3);
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
Clear name, tests real behavior, one thing
|
|
88
|
+
</Good>
|
|
89
|
+
|
|
90
|
+
<Bad>
|
|
91
|
+
```typescript
|
|
92
|
+
test('retry works', async () => {
|
|
93
|
+
const mock = jest.fn()
|
|
94
|
+
.mockRejectedValueOnce(new Error())
|
|
95
|
+
.mockRejectedValueOnce(new Error())
|
|
96
|
+
.mockResolvedValueOnce('success');
|
|
97
|
+
await retryOperation(mock);
|
|
98
|
+
expect(mock).toHaveBeenCalledTimes(3);
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
Vague name, tests mock not code
|
|
102
|
+
</Bad>
|
|
103
|
+
|
|
104
|
+
**Requirements:**
|
|
105
|
+
- One behavior
|
|
106
|
+
- Clear name
|
|
107
|
+
- Real code (no mocks unless unavoidable)
|
|
108
|
+
|
|
109
|
+
### Verify RED - Watch It Fail
|
|
110
|
+
|
|
111
|
+
**MANDATORY. Never skip.**
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm test path/to/test.test.ts
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Confirm:
|
|
118
|
+
- Test fails (not errors)
|
|
119
|
+
- Failure message is expected
|
|
120
|
+
- Fails because feature missing (not typos)
|
|
121
|
+
|
|
122
|
+
**Test passes?** You're testing existing behavior. Fix test.
|
|
123
|
+
|
|
124
|
+
**Test errors?** Fix error, re-run until it fails correctly.
|
|
125
|
+
|
|
126
|
+
### GREEN - Minimal Code
|
|
127
|
+
|
|
128
|
+
Write simplest code to pass the test.
|
|
129
|
+
|
|
130
|
+
<Good>
|
|
131
|
+
```typescript
|
|
132
|
+
async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
|
|
133
|
+
for (let i = 0; i < 3; i++) {
|
|
134
|
+
try {
|
|
135
|
+
return await fn();
|
|
136
|
+
} catch (e) {
|
|
137
|
+
if (i === 2) throw e;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
throw new Error('unreachable');
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
Just enough to pass
|
|
144
|
+
</Good>
|
|
145
|
+
|
|
146
|
+
<Bad>
|
|
147
|
+
```typescript
|
|
148
|
+
async function retryOperation<T>(
|
|
149
|
+
fn: () => Promise<T>,
|
|
150
|
+
options?: {
|
|
151
|
+
maxRetries?: number;
|
|
152
|
+
backoff?: 'linear' | 'exponential';
|
|
153
|
+
onRetry?: (attempt: number) => void;
|
|
154
|
+
}
|
|
155
|
+
): Promise<T> {
|
|
156
|
+
// YAGNI
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
Over-engineered
|
|
160
|
+
</Bad>
|
|
161
|
+
|
|
162
|
+
Don't add features, refactor other code, or "improve" beyond the test.
|
|
163
|
+
|
|
164
|
+
### Verify GREEN - Watch It Pass
|
|
165
|
+
|
|
166
|
+
**MANDATORY.**
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
npm test path/to/test.test.ts
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Confirm:
|
|
173
|
+
- Test passes
|
|
174
|
+
- Other tests still pass
|
|
175
|
+
- Output pristine (no errors, warnings)
|
|
176
|
+
|
|
177
|
+
**Test fails?** Fix code, not test.
|
|
178
|
+
|
|
179
|
+
**Other tests fail?** Fix now.
|
|
180
|
+
|
|
181
|
+
### REFACTOR - Clean Up
|
|
182
|
+
|
|
183
|
+
After green only:
|
|
184
|
+
- Remove duplication
|
|
185
|
+
- Improve names
|
|
186
|
+
- Extract helpers
|
|
187
|
+
|
|
188
|
+
Keep tests green. Don't add behavior.
|
|
189
|
+
|
|
190
|
+
### Repeat
|
|
191
|
+
|
|
192
|
+
Next failing test for next feature.
|
|
193
|
+
|
|
194
|
+
## Good Tests
|
|
195
|
+
|
|
196
|
+
| Quality | Good | Bad |
|
|
197
|
+
|---------|------|-----|
|
|
198
|
+
| **Minimal** | One thing. "and" in name? Split it. | Multiple behaviors in one test |
|
|
199
|
+
| **Clear** | Name describes behavior | `test('test1')` |
|
|
200
|
+
| **Shows intent** | Demonstrates desired API | Obscures what code should do |
|
|
201
|
+
|
|
202
|
+
## Why Order Matters
|
|
203
|
+
|
|
204
|
+
**"I'll write tests after to verify it works"**
|
|
205
|
+
|
|
206
|
+
Tests written after code pass immediately. Passing immediately proves nothing:
|
|
207
|
+
- Might test wrong thing
|
|
208
|
+
- Might test implementation, not behavior
|
|
209
|
+
- Might miss edge cases you forgot
|
|
210
|
+
- You never saw it catch the bug
|
|
211
|
+
|
|
212
|
+
Test-first forces you to see the test fail, proving it actually tests something.
|
|
213
|
+
|
|
214
|
+
**"I already manually tested all the edge cases"**
|
|
215
|
+
|
|
216
|
+
Manual testing is ad-hoc. You think you tested everything but:
|
|
217
|
+
- No record of what you tested
|
|
218
|
+
- Can't re-run when code changes
|
|
219
|
+
- Easy to forget cases under pressure
|
|
220
|
+
- "It worked when I tried it" ≠ comprehensive
|
|
221
|
+
|
|
222
|
+
Automated tests are systematic. They run the same way every time.
|
|
223
|
+
|
|
224
|
+
**"Deleting X hours of work is wasteful"**
|
|
225
|
+
|
|
226
|
+
Sunk cost fallacy. The time is already gone. Your choice now:
|
|
227
|
+
- Delete and rewrite with TDD (X more hours, high confidence)
|
|
228
|
+
- Keep it and add tests after (30 min, low confidence, likely bugs)
|
|
229
|
+
|
|
230
|
+
The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
|
|
231
|
+
|
|
232
|
+
**"TDD is dogmatic, being pragmatic means adapting"**
|
|
233
|
+
|
|
234
|
+
TDD IS pragmatic:
|
|
235
|
+
- Finds bugs before commit (faster than debugging after)
|
|
236
|
+
- Prevents regressions (tests catch breaks immediately)
|
|
237
|
+
- Documents behavior (tests show how to use code)
|
|
238
|
+
- Enables refactoring (change freely, tests catch breaks)
|
|
239
|
+
|
|
240
|
+
"Pragmatic" shortcuts = debugging in production = slower.
|
|
241
|
+
|
|
242
|
+
**"Tests after achieve the same goals - it's spirit not ritual"**
|
|
243
|
+
|
|
244
|
+
No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
|
|
245
|
+
|
|
246
|
+
Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
|
|
247
|
+
|
|
248
|
+
Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
|
|
249
|
+
|
|
250
|
+
30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work.
|
|
251
|
+
|
|
252
|
+
## Common Rationalizations
|
|
253
|
+
|
|
254
|
+
| Excuse | Reality |
|
|
255
|
+
|--------|---------|
|
|
256
|
+
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
257
|
+
| "I'll test after" | Tests passing immediately prove nothing. |
|
|
258
|
+
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
|
|
259
|
+
| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
|
|
260
|
+
| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
|
|
261
|
+
| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
|
|
262
|
+
|
|
263
|
+
## Red Flags - STOP and Start Over
|
|
264
|
+
|
|
265
|
+
- Code before test
|
|
266
|
+
- Test after implementation
|
|
267
|
+
- Test passes immediately
|
|
268
|
+
- Can't explain why test failed
|
|
269
|
+
- "I already manually tested it"
|
|
270
|
+
- "Tests after achieve the same purpose"
|
|
271
|
+
- "Keep as reference" or "adapt existing code"
|
|
272
|
+
- "TDD is dogmatic, I'm being pragmatic"
|
|
273
|
+
|
|
274
|
+
**All of these mean: Delete code. Start over with TDD.**
|
|
275
|
+
|
|
276
|
+
## Example: Bug Fix
|
|
277
|
+
|
|
278
|
+
**Bug:** Empty email accepted
|
|
279
|
+
|
|
280
|
+
**RED**
|
|
281
|
+
```typescript
|
|
282
|
+
test('rejects empty email', async () => {
|
|
283
|
+
const result = await submitForm({ email: '' });
|
|
284
|
+
expect(result.error).toBe('Email required');
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**Verify RED**
|
|
289
|
+
```bash
|
|
290
|
+
$ npm test
|
|
291
|
+
FAIL: expected 'Email required', got undefined
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**GREEN**
|
|
295
|
+
```typescript
|
|
296
|
+
function submitForm(data: FormData) {
|
|
297
|
+
if (!data.email?.trim()) {
|
|
298
|
+
return { error: 'Email required' };
|
|
299
|
+
}
|
|
300
|
+
// ...
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Verify GREEN**
|
|
305
|
+
```bash
|
|
306
|
+
$ npm test
|
|
307
|
+
PASS
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**REFACTOR**
|
|
311
|
+
Extract validation for multiple fields if needed.
|
|
312
|
+
|
|
313
|
+
## Verification Checklist
|
|
314
|
+
|
|
315
|
+
Before claiming development complete, check:
|
|
316
|
+
|
|
317
|
+
1. Every new function/method has a test
|
|
318
|
+
2. Watched each test fail before implementing
|
|
319
|
+
3. Each test failed for expected reason (feature missing, not typo)
|
|
320
|
+
4. Wrote minimal code to pass each test
|
|
321
|
+
5. All tests pass
|
|
322
|
+
6. Output pristine (no errors, warnings)
|
|
323
|
+
7. Edge cases and errors covered
|
|
324
|
+
|
|
325
|
+
Can't check all boxes? You skipped TDD. Start over.
|
|
326
|
+
|
|
327
|
+
## When Stuck
|
|
328
|
+
|
|
329
|
+
| Problem | Solution |
|
|
330
|
+
|---------|----------|
|
|
331
|
+
| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
|
|
332
|
+
| Test too complicated | Design too complicated. Simplify interface. |
|
|
333
|
+
| Must mock everything | Code too coupled. Use dependency injection. |
|
|
334
|
+
| Test setup huge | Extract helpers. Still complex? Simplify design. |
|
|
335
|
+
|
|
336
|
+
## Debugging Integration
|
|
337
|
+
|
|
338
|
+
Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
|
|
339
|
+
|
|
340
|
+
Never fix bugs without a test.
|
|
341
|
+
|
|
342
|
+
## Testing Anti-Patterns
|
|
343
|
+
|
|
344
|
+
When adding mocks or test utilities, read @testing-anti-patterns.md to avoid common pitfalls:
|
|
345
|
+
- Testing mock behavior instead of real behavior
|
|
346
|
+
- Adding test-only methods to production classes
|
|
347
|
+
- Mocking without understanding dependencies
|
|
348
|
+
|
|
349
|
+
## Final Rule
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
Production code → test exists and failed first
|
|
353
|
+
Otherwise → not TDD
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
No exceptions without your human partner's permission.
|