engine7 7.1.38 → 7.1.40
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/dist/cli.mjs +81 -45
- package/dist/engine-startup.mjs +4856 -3650
- package/dist/main.mjs +4852 -3646
- package/package.json +2 -1
- package/templates/skills/superpowers/brainstorming/SKILL.md +151 -0
- package/templates/skills/superpowers/brainstorming/scripts/frame-template.html +213 -0
- package/templates/skills/superpowers/brainstorming/scripts/helper.js +167 -0
- package/templates/skills/superpowers/brainstorming/scripts/server.cjs +723 -0
- package/templates/skills/superpowers/brainstorming/scripts/start-server.sh +209 -0
- package/templates/skills/superpowers/brainstorming/scripts/stop-server.sh +120 -0
- package/templates/skills/superpowers/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/templates/skills/superpowers/brainstorming/visual-companion.md +298 -0
- package/templates/skills/superpowers/dispatching-parallel-agents/SKILL.md +167 -0
- package/templates/skills/superpowers/executing-plans/SKILL.md +64 -0
- package/templates/skills/superpowers/finishing-a-development-branch/SKILL.md +201 -0
- package/templates/skills/superpowers/receiving-code-review/SKILL.md +205 -0
- package/templates/skills/superpowers/requesting-code-review/SKILL.md +95 -0
- package/templates/skills/superpowers/requesting-code-review/code-reviewer.md +172 -0
- package/templates/skills/superpowers/subagent-driven-development/SKILL.md +503 -0
- package/templates/skills/superpowers/subagent-driven-development/implementer-prompt.md +142 -0
- package/templates/skills/superpowers/subagent-driven-development/re-review-prompt.md +106 -0
- package/templates/skills/superpowers/subagent-driven-development/scripts/review-package +46 -0
- package/templates/skills/superpowers/subagent-driven-development/scripts/sdd-workspace +40 -0
- package/templates/skills/superpowers/subagent-driven-development/scripts/task-brief +41 -0
- package/templates/skills/superpowers/subagent-driven-development/task-reviewer-prompt.md +185 -0
- package/templates/skills/superpowers/systematic-debugging/CREATION-LOG.md +119 -0
- package/templates/skills/superpowers/systematic-debugging/SKILL.md +283 -0
- package/templates/skills/superpowers/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/templates/skills/superpowers/systematic-debugging/condition-based-waiting.md +115 -0
- package/templates/skills/superpowers/systematic-debugging/defense-in-depth.md +122 -0
- package/templates/skills/superpowers/systematic-debugging/find-polluter.sh +72 -0
- package/templates/skills/superpowers/systematic-debugging/root-cause-tracing.md +169 -0
- package/templates/skills/superpowers/systematic-debugging/test-academic.md +14 -0
- package/templates/skills/superpowers/systematic-debugging/test-pressure-1.md +58 -0
- package/templates/skills/superpowers/systematic-debugging/test-pressure-2.md +68 -0
- package/templates/skills/superpowers/systematic-debugging/test-pressure-3.md +69 -0
- package/templates/skills/superpowers/test-driven-development/SKILL.md +320 -0
- package/templates/skills/superpowers/test-driven-development/writing-good-tests.md +198 -0
- package/templates/skills/superpowers/using-git-worktrees/SKILL.md +167 -0
- package/templates/skills/superpowers/using-superpowers/SKILL.md +62 -0
- package/templates/skills/superpowers/using-superpowers/references/antigravity-tools.md +23 -0
- package/templates/skills/superpowers/using-superpowers/references/codex-tools.md +39 -0
- package/templates/skills/superpowers/using-superpowers/references/gemini-tools.md +63 -0
- package/templates/skills/superpowers/using-superpowers/references/pi-tools.md +16 -0
- package/templates/skills/superpowers/verification-before-completion/SKILL.md +120 -0
- package/templates/skills/superpowers/writing-plans/SKILL.md +168 -0
- package/templates/skills/superpowers/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/templates/skills/superpowers/writing-skills/SKILL.md +679 -0
- package/templates/skills/superpowers/writing-skills/anthropic-best-practices.md +1150 -0
- package/templates/skills/superpowers/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/templates/skills/superpowers/writing-skills/graphviz-conventions.dot +172 -0
- package/templates/skills/superpowers/writing-skills/persuasion-principles.md +187 -0
- package/templates/skills/superpowers/writing-skills/render-graphs.js +168 -0
- package/templates/skills/superpowers/writing-skills/testing-skills-with-subagents.md +384 -0
|
@@ -0,0 +1,320 @@
|
|
|
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
|
+
Thinking "skip TDD just this once"? Stop. That's rationalization.
|
|
30
|
+
|
|
31
|
+
## The Iron Law
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Write code before the test? Delete it. Start over.
|
|
38
|
+
|
|
39
|
+
**No exceptions:**
|
|
40
|
+
- Don't keep it as "reference"
|
|
41
|
+
- Don't "adapt" it while writing tests
|
|
42
|
+
- Don't look at it
|
|
43
|
+
- Delete means delete
|
|
44
|
+
|
|
45
|
+
Implement fresh from tests. Period.
|
|
46
|
+
|
|
47
|
+
## Red-Green-Refactor
|
|
48
|
+
|
|
49
|
+
```dot
|
|
50
|
+
digraph tdd_cycle {
|
|
51
|
+
rankdir=LR;
|
|
52
|
+
red [label="RED\nWrite failing test", shape=box, style=filled, fillcolor="#ffcccc"];
|
|
53
|
+
verify_red [label="Verify fails\ncorrectly", shape=diamond];
|
|
54
|
+
green [label="GREEN\nMinimal code", shape=box, style=filled, fillcolor="#ccffcc"];
|
|
55
|
+
verify_green [label="Verify passes\nAll green", shape=diamond];
|
|
56
|
+
refactor [label="REFACTOR\nClean up", shape=box, style=filled, fillcolor="#ccccff"];
|
|
57
|
+
next [label="Next", shape=ellipse];
|
|
58
|
+
|
|
59
|
+
red -> verify_red;
|
|
60
|
+
verify_red -> green [label="yes"];
|
|
61
|
+
verify_red -> red [label="wrong\nfailure"];
|
|
62
|
+
green -> verify_green;
|
|
63
|
+
verify_green -> refactor [label="yes"];
|
|
64
|
+
verify_green -> green [label="no"];
|
|
65
|
+
refactor -> verify_green [label="stay\ngreen"];
|
|
66
|
+
verify_green -> next;
|
|
67
|
+
next -> red;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### RED - Write Failing Test
|
|
72
|
+
|
|
73
|
+
Write one minimal test showing what should happen.
|
|
74
|
+
|
|
75
|
+
<Good>
|
|
76
|
+
```typescript
|
|
77
|
+
test('retries failed operations 3 times', async () => {
|
|
78
|
+
let attempts = 0;
|
|
79
|
+
const operation = () => {
|
|
80
|
+
attempts++;
|
|
81
|
+
if (attempts < 3) throw new Error('fail');
|
|
82
|
+
return 'success';
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const result = await retryOperation(operation);
|
|
86
|
+
|
|
87
|
+
expect(result).toBe('success');
|
|
88
|
+
expect(attempts).toBe(3);
|
|
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
|
+
Vague name, tests mock not code
|
|
106
|
+
</Bad>
|
|
107
|
+
|
|
108
|
+
**Requirements:**
|
|
109
|
+
- One behavior
|
|
110
|
+
- Clear name
|
|
111
|
+
- Real code (no mocks unless unavoidable)
|
|
112
|
+
|
|
113
|
+
### Verify RED - Watch It Fail
|
|
114
|
+
|
|
115
|
+
**MANDATORY. Never skip.**
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm test path/to/test.test.ts
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Confirm:
|
|
122
|
+
- Test fails (not errors)
|
|
123
|
+
- Failure message is expected
|
|
124
|
+
- Fails because feature missing (not typos)
|
|
125
|
+
|
|
126
|
+
**Test passes?** You're testing existing behavior. Fix test.
|
|
127
|
+
|
|
128
|
+
**Test errors?** Fix error, re-run until it fails correctly.
|
|
129
|
+
|
|
130
|
+
### GREEN - Minimal Code
|
|
131
|
+
|
|
132
|
+
Write simplest code to pass the test.
|
|
133
|
+
|
|
134
|
+
<Good>
|
|
135
|
+
```typescript
|
|
136
|
+
async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
|
|
137
|
+
for (let i = 0; i < 3; i++) {
|
|
138
|
+
try {
|
|
139
|
+
return await fn();
|
|
140
|
+
} catch (e) {
|
|
141
|
+
if (i === 2) throw e;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
throw new Error('unreachable');
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
Just enough to pass
|
|
148
|
+
</Good>
|
|
149
|
+
|
|
150
|
+
<Bad>
|
|
151
|
+
```typescript
|
|
152
|
+
async function retryOperation<T>(
|
|
153
|
+
fn: () => Promise<T>,
|
|
154
|
+
options?: {
|
|
155
|
+
maxRetries?: number;
|
|
156
|
+
backoff?: 'linear' | 'exponential';
|
|
157
|
+
onRetry?: (attempt: number) => void;
|
|
158
|
+
}
|
|
159
|
+
): Promise<T> {
|
|
160
|
+
// YAGNI
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
Over-engineered
|
|
164
|
+
</Bad>
|
|
165
|
+
|
|
166
|
+
Don't add features, refactor other code, or "improve" beyond the test.
|
|
167
|
+
|
|
168
|
+
### Verify GREEN - Watch It Pass
|
|
169
|
+
|
|
170
|
+
**MANDATORY.**
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
npm test path/to/test.test.ts
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Confirm:
|
|
177
|
+
- Test passes
|
|
178
|
+
- Other tests still pass
|
|
179
|
+
- Output pristine (no errors, warnings)
|
|
180
|
+
|
|
181
|
+
**Test fails?** Fix code, not test.
|
|
182
|
+
|
|
183
|
+
**Other tests fail?** Fix now.
|
|
184
|
+
|
|
185
|
+
### REFACTOR - Clean Up
|
|
186
|
+
|
|
187
|
+
After green only:
|
|
188
|
+
- Remove duplication
|
|
189
|
+
- Improve names
|
|
190
|
+
- Extract helpers
|
|
191
|
+
|
|
192
|
+
Keep tests green. Don't add behavior.
|
|
193
|
+
|
|
194
|
+
### Repeat
|
|
195
|
+
|
|
196
|
+
Next failing test for next feature.
|
|
197
|
+
|
|
198
|
+
## Good Tests
|
|
199
|
+
|
|
200
|
+
| Quality | Good | Bad |
|
|
201
|
+
|---------|------|-----|
|
|
202
|
+
| **Minimal** | One thing. "and" in name? Split it. | `test('validates email and domain and whitespace')` |
|
|
203
|
+
| **Clear** | Name describes behavior | `test('test1')` |
|
|
204
|
+
| **Shows intent** | Demonstrates desired API | Obscures what code should do |
|
|
205
|
+
|
|
206
|
+
When writing or changing any test, read [writing-good-tests.md](writing-good-tests.md) for the rules that keep tests honest:
|
|
207
|
+
- Name the production change that would make the test fail — before writing it
|
|
208
|
+
- Assert on real behavior, never on mock behavior
|
|
209
|
+
- Keep test-only code in test utilities, out of production classes
|
|
210
|
+
- Understand a dependency's side effects before mocking it
|
|
211
|
+
|
|
212
|
+
## Common Rationalizations
|
|
213
|
+
|
|
214
|
+
| Excuse | Reality |
|
|
215
|
+
|--------|---------|
|
|
216
|
+
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
217
|
+
| "I'll test after" | Tests written after pass immediately — which proves nothing. They may test the wrong thing, test the implementation instead of the behavior, or miss the edge case you forgot. You never watched it fail, so you never proved it can catch the bug. Test-first forces that failure. |
|
|
218
|
+
| "Tests after achieve same goals (spirit not ritual)" | Tests-after answer "what does this do?"; tests-first answer "what should this do?" Tests written after are biased by the code you already wrote — you verify the cases you remembered, not the ones you'd have discovered. Coverage without proof the tests work. |
|
|
219
|
+
| "Already manually tested" | Manual testing is ad-hoc: no record of what you covered, no way to re-run it when the code changes, easy to forget cases under pressure. "Worked when I tried it" ≠ comprehensive. Automated tests run the same way every time. |
|
|
220
|
+
| "Deleting X hours is wasteful" | Sunk cost fallacy — that time is already spent either way. The real choice: rewrite with TDD (high confidence) vs. keep it and bolt tests on after (low confidence, likely bugs). Keeping code you can't trust is the waste. |
|
|
221
|
+
| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
|
|
222
|
+
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
|
|
223
|
+
| "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
|
|
224
|
+
| "TDD will slow me down" | TDD IS the pragmatic path: catches bugs before commit, prevents regressions, lets you refactor without fear. "Pragmatic" shortcuts mean debugging in production — slower, not faster. |
|
|
225
|
+
| "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
|
|
226
|
+
| "Existing code has no tests" | You're improving it. Add tests for existing code. |
|
|
227
|
+
|
|
228
|
+
## Red Flags - STOP and Start Over
|
|
229
|
+
|
|
230
|
+
- Code before test
|
|
231
|
+
- Test after implementation
|
|
232
|
+
- Test passes immediately
|
|
233
|
+
- Can't explain why test failed
|
|
234
|
+
- Tests added "later"
|
|
235
|
+
- Rationalizing "just this once"
|
|
236
|
+
- "I already manually tested it"
|
|
237
|
+
- "Tests after achieve the same purpose"
|
|
238
|
+
- "It's about spirit not ritual"
|
|
239
|
+
- "Keep as reference" or "adapt existing code"
|
|
240
|
+
- "Already spent X hours, deleting is wasteful"
|
|
241
|
+
- "TDD is dogmatic, I'm being pragmatic"
|
|
242
|
+
- "This is different because..."
|
|
243
|
+
|
|
244
|
+
**All of these mean: Delete code. Start over with TDD.**
|
|
245
|
+
|
|
246
|
+
## Example: Bug Fix
|
|
247
|
+
|
|
248
|
+
**Bug:** Empty email accepted
|
|
249
|
+
|
|
250
|
+
**RED**
|
|
251
|
+
```typescript
|
|
252
|
+
test('rejects empty email', async () => {
|
|
253
|
+
const result = await submitForm({ email: '' });
|
|
254
|
+
expect(result.error).toBe('Email required');
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Verify RED**
|
|
259
|
+
```bash
|
|
260
|
+
$ npm test
|
|
261
|
+
FAIL: expected 'Email required', got undefined
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**GREEN**
|
|
265
|
+
```typescript
|
|
266
|
+
function submitForm(data: FormData) {
|
|
267
|
+
if (!data.email?.trim()) {
|
|
268
|
+
return { error: 'Email required' };
|
|
269
|
+
}
|
|
270
|
+
// ...
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**Verify GREEN**
|
|
275
|
+
```bash
|
|
276
|
+
$ npm test
|
|
277
|
+
PASS
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**REFACTOR**
|
|
281
|
+
Extract validation for multiple fields if needed.
|
|
282
|
+
|
|
283
|
+
## Verification Checklist
|
|
284
|
+
|
|
285
|
+
Before marking work complete:
|
|
286
|
+
|
|
287
|
+
- [ ] Every new function/method has a test
|
|
288
|
+
- [ ] Watched each test fail before implementing
|
|
289
|
+
- [ ] Each test failed for expected reason (feature missing, not typo)
|
|
290
|
+
- [ ] Wrote minimal code to pass each test
|
|
291
|
+
- [ ] All tests pass
|
|
292
|
+
- [ ] Output pristine (no errors, warnings)
|
|
293
|
+
- [ ] Tests use real code (mocks only if unavoidable)
|
|
294
|
+
- [ ] Edge cases and errors covered
|
|
295
|
+
|
|
296
|
+
Can't check all boxes? You skipped TDD. Start over.
|
|
297
|
+
|
|
298
|
+
## When Stuck
|
|
299
|
+
|
|
300
|
+
| Problem | Solution |
|
|
301
|
+
|---------|----------|
|
|
302
|
+
| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
|
|
303
|
+
| Test too complicated | Design too complicated. Simplify interface. |
|
|
304
|
+
| Must mock everything | Code too coupled. Use dependency injection. |
|
|
305
|
+
| Test setup huge | Extract helpers. Still complex? Simplify design. |
|
|
306
|
+
|
|
307
|
+
## Debugging Integration
|
|
308
|
+
|
|
309
|
+
Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
|
|
310
|
+
|
|
311
|
+
Never fix bugs without a test.
|
|
312
|
+
|
|
313
|
+
## Final Rule
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
Production code → test exists and failed first
|
|
317
|
+
Otherwise → not TDD
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
No exceptions without your human partner's permission.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Writing Good Tests
|
|
2
|
+
|
|
3
|
+
**Load this reference when:** writing or changing tests, adding mocks, or
|
|
4
|
+
adding cleanup/helper methods for tests.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
A test exists to catch a specific break. Two principles govern everything
|
|
9
|
+
here:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
1. Every test names the break it catches
|
|
13
|
+
2. Every test exercises the real thing
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Strict TDD produces both naturally: a test written first and watched
|
|
17
|
+
failing against real code has already proven it can fail, and only earns
|
|
18
|
+
a mock when the real dependency proves slow or external.
|
|
19
|
+
|
|
20
|
+
## Principle 1: Name the Break
|
|
21
|
+
|
|
22
|
+
Before writing the test body, answer: **what production change should
|
|
23
|
+
make this test fail — and is that change a bug or a decision?** A test
|
|
24
|
+
earns its place by catching a wrong branch, missing side effect, wrong
|
|
25
|
+
argument, boundary case, or broken contract.
|
|
26
|
+
|
|
27
|
+
**Derive expectations independently.** Use literals and hand-checked
|
|
28
|
+
fixtures; table-driven tests with literal `want` values are the preferred
|
|
29
|
+
shape. An expectation computed by the code under test — or its helpers —
|
|
30
|
+
passes no matter what that code does:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
// ❌ Mirror assertion: the same builder computes both sides — always true
|
|
34
|
+
const expected = buildSearchQuery({ tag: 'urgent' });
|
|
35
|
+
expect(buildSearchQuery({ tag: 'urgent' })).toBe(expected);
|
|
36
|
+
|
|
37
|
+
// ✅ Hand-derived literal
|
|
38
|
+
expect(buildSearchQuery({ tag: 'urgent' })).toBe('tag:"urgent"');
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**No change detectors.** If only intentional decisions can fail a test —
|
|
42
|
+
a constant's value, exact message wording, private structure — it fires
|
|
43
|
+
on redesign and sleeps through bugs. Test the behavior that depends on
|
|
44
|
+
the decision: not `expect(MAX_RETRIES).toBe(5)` but "a failing call is
|
|
45
|
+
retried 5 times and the 6th attempt never happens."
|
|
46
|
+
|
|
47
|
+
**Behavior, not text.** Asserting that a script, skill, or config
|
|
48
|
+
contains an exact line proves only that the source is the source. Run
|
|
49
|
+
scripts against controlled inputs and assert outputs, side effects, or
|
|
50
|
+
exit codes. Documents that instruct agents are tested by the consuming
|
|
51
|
+
agent's behavior (superpowers:writing-skills); prose for humans earns no
|
|
52
|
+
test at all.
|
|
53
|
+
|
|
54
|
+
**Your code, not the framework.** Test the contract your code makes at
|
|
55
|
+
its boundaries — the route you register, the query you emit, the payload
|
|
56
|
+
you produce. Upstream mechanics are their maintainers' tests to write
|
|
57
|
+
(the classic: asserting your router invokes a registered handler — that
|
|
58
|
+
is the framework's test, not yours). When upstream behavior genuinely
|
|
59
|
+
surprised you, write one narrow characterization test naming the
|
|
60
|
+
assumption. The same boundary applies inside your code: constructors,
|
|
61
|
+
getters, constants, and trivial forwarding earn tests only when they
|
|
62
|
+
validate, normalize, default, derive, enforce, or cause side effects —
|
|
63
|
+
otherwise assert the first consumer-visible result that depends on them.
|
|
64
|
+
|
|
65
|
+
### Gate Function
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
BEFORE writing the test body:
|
|
69
|
+
Name the production change that would make this test fail.
|
|
70
|
+
|
|
71
|
+
Cannot name one → redesign around an observable behavior
|
|
72
|
+
"The source text changed" → run the artifact and assert its effects
|
|
73
|
+
Only intentional decisions → change detector; test the behavior
|
|
74
|
+
that depends on the decision
|
|
75
|
+
|
|
76
|
+
Confirm the expected value is derived without the code under test.
|
|
77
|
+
IF it reuses the code's logic or helpers:
|
|
78
|
+
Replace it with a literal or hand-checked fixture
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Principle 2: Exercise the Real Thing
|
|
82
|
+
|
|
83
|
+
**The mock earns no assertions.** A mock assertion passes when the mock
|
|
84
|
+
is present and fails when it is absent — it says nothing about the
|
|
85
|
+
component. Assert the real component's behavior; if the mock is what you
|
|
86
|
+
are checking, unmock it or delete the assertion.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
// ✅ Real behavior
|
|
90
|
+
expect(screen.getByRole('navigation')).toBeInTheDocument();
|
|
91
|
+
|
|
92
|
+
// ❌ Mock existence
|
|
93
|
+
expect(screen.getByTestId('sidebar-mock')).toBeInTheDocument();
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**your human partner's correction:** "Are we testing the behavior of a
|
|
97
|
+
mock?"
|
|
98
|
+
|
|
99
|
+
**Mock at the right level.** Learn every side effect of the real method
|
|
100
|
+
before replacing it; mock the slow or external operation and keep what
|
|
101
|
+
the test depends on real. When unsure, run the test against the real
|
|
102
|
+
implementation first and observe what actually needs to happen.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// ❌ The mock swallows the config write that duplicate detection reads
|
|
106
|
+
vi.mock('ToolCatalog', () => ({
|
|
107
|
+
discoverAndCacheTools: vi.fn().mockResolvedValue(undefined)
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
// ✅ Mock only the slow server startup; the config write stays real
|
|
111
|
+
vi.mock('MCPServerManager');
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Make doubles specific.** When arguments, call counts, or ordering are
|
|
115
|
+
part of the contract, assert them — a fake that accepts anything verifies
|
|
116
|
+
nothing. Give each branch (success, error, malformed) its own fixture or
|
|
117
|
+
spy, so the wrong branch cannot satisfy the expectation.
|
|
118
|
+
|
|
119
|
+
**Mirror real data completely.** Mock the complete structure as it exists
|
|
120
|
+
in reality — all documented fields — not just the ones your test reads.
|
|
121
|
+
Partial mocks fail silently when downstream code reads an omitted field:
|
|
122
|
+
the test passes while integration breaks.
|
|
123
|
+
|
|
124
|
+
**Production classes carry production methods only.** Cleanup that only
|
|
125
|
+
tests need lives in test utilities, never as a `destroy()` on the
|
|
126
|
+
production class. Ask: is this method called only from tests? Does this
|
|
127
|
+
class own this resource's lifecycle? Wrong answers → test utility.
|
|
128
|
+
|
|
129
|
+
**Prefer real components over complex mocks.** When mock setup outgrows
|
|
130
|
+
the test logic, mocks miss methods the real components have, or tests
|
|
131
|
+
break when the mock changes, switch to an integration test with real
|
|
132
|
+
components. **your human partner's question:** "Do we need to be using a
|
|
133
|
+
mock here?"
|
|
134
|
+
|
|
135
|
+
### Gate Function
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
BEFORE adding a mock or test helper:
|
|
139
|
+
List the real method's side effects; keep the ones the test
|
|
140
|
+
depends on real — mock the slow/external level below them.
|
|
141
|
+
|
|
142
|
+
Mock responses mirror the complete real structure.
|
|
143
|
+
|
|
144
|
+
A method only tests call lives in test utilities, not production.
|
|
145
|
+
|
|
146
|
+
About to assert on the mock itself?
|
|
147
|
+
Unmock it or delete the assertion.
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Tests Ship With the Implementation
|
|
151
|
+
|
|
152
|
+
The TDD cycle — failing test, minimal implementation, refactor — is what
|
|
153
|
+
"complete" means. Ship the tests the behavior needs and only those:
|
|
154
|
+
trivial code and human prose earn none, and a test written to satisfy
|
|
155
|
+
process costs maintenance forever.
|
|
156
|
+
|
|
157
|
+
## The Mutation Check
|
|
158
|
+
|
|
159
|
+
Before finishing, mentally mutate the production code; at least one test
|
|
160
|
+
should fail for each realistic mutation:
|
|
161
|
+
|
|
162
|
+
- Wrong constant or argument
|
|
163
|
+
- Wrong branch handler
|
|
164
|
+
- Missing state change or side effect
|
|
165
|
+
- Empty or default return
|
|
166
|
+
- Missing validation for zero, empty, nil, unauthorized, or malformed input
|
|
167
|
+
|
|
168
|
+
A mutation nothing catches marks the behavior as unprotected — or the
|
|
169
|
+
test as tautological.
|
|
170
|
+
|
|
171
|
+
## Quick Reference
|
|
172
|
+
|
|
173
|
+
| When you... | Do |
|
|
174
|
+
|-------------|-----|
|
|
175
|
+
| Write any test | Name the break it catches — a bug, not a decision |
|
|
176
|
+
| Build an expected value | Derive it by hand; never with the code under test |
|
|
177
|
+
| Test a script or document | Run it / pressure-test its consumer; never grep its text |
|
|
178
|
+
| Reach for a dependency test | Test your boundary contract, not their documented mechanics |
|
|
179
|
+
| Want to assert on a mocked element | Test the real component, or unmock it |
|
|
180
|
+
| Are about to mock a method | Learn its side effects; mock the slow/external level |
|
|
181
|
+
| Build a mock response | Mirror the real structure completely |
|
|
182
|
+
| Need cleanup only tests use | Put it in test utilities |
|
|
183
|
+
| Watch mock setup balloon | Switch to an integration test with real components |
|
|
184
|
+
| Finish a test file | Run the mutation check |
|
|
185
|
+
|
|
186
|
+
## Warning Signs
|
|
187
|
+
|
|
188
|
+
- Setup and assertion share the same object, guaranteeing equality
|
|
189
|
+
- The test can fail only through a panic, crash, or missing selector
|
|
190
|
+
- The test fails on every intentional change, never on accidental breakage
|
|
191
|
+
- Expected values are hidden behind loops, builders, or helpers
|
|
192
|
+
- The test greps source text, or asserts a removed symbol stays removed
|
|
193
|
+
- The test would still matter if only the framework remained
|
|
194
|
+
- The test exists for coverage, checking no side effect or outcome
|
|
195
|
+
- An assertion checks a `*-mock` test ID, or fails if you remove the mock
|
|
196
|
+
- A method is called only from test files
|
|
197
|
+
- Mock setup is more than half the test, or you can't explain why the mock is needed
|
|
198
|
+
- Mocking "just to be safe"
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: using-git-worktrees
|
|
3
|
+
description: Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Using Git Worktrees
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Ensure work happens in an isolated workspace. Prefer your platform's native worktree tools. Fall back to manual git worktrees only when no native tool is available.
|
|
11
|
+
|
|
12
|
+
**Core principle:** Detect existing isolation first. Then use native tools. Then fall back to git. Never fight the harness.
|
|
13
|
+
|
|
14
|
+
**Announce at start:** "I'm using the using-git-worktrees skill to set up an isolated workspace."
|
|
15
|
+
|
|
16
|
+
## Step 0: Detect Existing Isolation
|
|
17
|
+
|
|
18
|
+
**Before creating anything, check if you are already in an isolated workspace.**
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
GIT_DIR=$(cd "$(git rev-parse --git-dir)" 2>/dev/null && pwd -P)
|
|
22
|
+
GIT_COMMON=$(cd "$(git rev-parse --git-common-dir)" 2>/dev/null && pwd -P)
|
|
23
|
+
BRANCH=$(git branch --show-current)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Submodule guard:** `GIT_DIR != GIT_COMMON` is also true inside git submodules. Before concluding "already in a worktree," verify you are not in a submodule:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# If this returns a path, you're in a submodule, not a worktree — treat as normal repo
|
|
30
|
+
git rev-parse --show-superproject-working-tree 2>/dev/null
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**If `GIT_DIR != GIT_COMMON` (and not a submodule):** You are already in a linked worktree. Skip to Step 2 (Project Setup). Do NOT create another worktree.
|
|
34
|
+
|
|
35
|
+
Report with branch state:
|
|
36
|
+
- On a branch: "Already in isolated workspace at `<path>` on branch `<name>`."
|
|
37
|
+
- Detached HEAD: "Already in isolated workspace at `<path>` (detached HEAD, externally managed). Branch creation needed at finish time."
|
|
38
|
+
|
|
39
|
+
**If `GIT_DIR == GIT_COMMON` (or in a submodule):** You are in a normal repo checkout.
|
|
40
|
+
|
|
41
|
+
Has the user already indicated their worktree preference in your instructions? If not, ask for consent before creating a worktree:
|
|
42
|
+
|
|
43
|
+
> "Would you like me to set up an isolated worktree? It protects your current branch from changes."
|
|
44
|
+
|
|
45
|
+
Honor any existing declared preference without asking. If the user declines consent, work in place and skip to Step 2.
|
|
46
|
+
|
|
47
|
+
## Step 1: Create Isolated Workspace
|
|
48
|
+
|
|
49
|
+
**You have two mechanisms. Try them in this order.**
|
|
50
|
+
|
|
51
|
+
### 1a. Native Worktree Tools (preferred)
|
|
52
|
+
|
|
53
|
+
The user has asked for an isolated workspace (Step 0 consent). Do you already have a way to create a worktree? It might be a tool with a name like `EnterWorktree`, `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag. If you do, use it and skip to Step 2.
|
|
54
|
+
|
|
55
|
+
Native tools handle directory placement, branch creation, and cleanup automatically. Using `git worktree add` when you have a native tool creates phantom state your harness can't see or manage.
|
|
56
|
+
|
|
57
|
+
Only proceed to Step 1b if you have no native worktree tool available.
|
|
58
|
+
|
|
59
|
+
### 1b. Git Worktree Fallback
|
|
60
|
+
|
|
61
|
+
**Only use this if Step 1a does not apply** — you have no native worktree tool available. Create a worktree manually using git.
|
|
62
|
+
|
|
63
|
+
#### Directory Selection
|
|
64
|
+
|
|
65
|
+
Follow this priority order. Explicit user preference always beats observed filesystem state.
|
|
66
|
+
|
|
67
|
+
1. **Check your instructions for a declared worktree directory preference.** If the user has already specified one, use it without asking.
|
|
68
|
+
|
|
69
|
+
2. **Check for an existing project-local worktree directory:**
|
|
70
|
+
```bash
|
|
71
|
+
ls -d .worktrees 2>/dev/null # Preferred (hidden)
|
|
72
|
+
ls -d worktrees 2>/dev/null # Alternative
|
|
73
|
+
```
|
|
74
|
+
If found, use it. If both exist, `.worktrees` wins.
|
|
75
|
+
|
|
76
|
+
3. **If there is no other guidance available**, default to `.worktrees/` at the project root.
|
|
77
|
+
|
|
78
|
+
#### Safety Verification (project-local directories only)
|
|
79
|
+
|
|
80
|
+
**MUST verify directory is ignored before creating worktree:**
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
git check-ignore -q .worktrees 2>/dev/null || git check-ignore -q worktrees 2>/dev/null
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**If NOT ignored:** Add to .gitignore, commit the change, then proceed.
|
|
87
|
+
|
|
88
|
+
**Why critical:** Prevents accidentally committing worktree contents to repository.
|
|
89
|
+
|
|
90
|
+
#### Create the Worktree
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Determine path based on chosen location
|
|
94
|
+
path="$LOCATION/$BRANCH_NAME"
|
|
95
|
+
|
|
96
|
+
git worktree add "$path" -b "$BRANCH_NAME"
|
|
97
|
+
cd "$path"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Sandbox fallback:** If `git worktree add` fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.
|
|
101
|
+
|
|
102
|
+
## Step 2: Project Setup
|
|
103
|
+
|
|
104
|
+
Auto-detect and run appropriate setup:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Node.js
|
|
108
|
+
if [ -f package.json ]; then npm install; fi
|
|
109
|
+
|
|
110
|
+
# Rust
|
|
111
|
+
if [ -f Cargo.toml ]; then cargo build; fi
|
|
112
|
+
|
|
113
|
+
# Python
|
|
114
|
+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
|
115
|
+
if [ -f pyproject.toml ]; then poetry install; fi
|
|
116
|
+
|
|
117
|
+
# Go
|
|
118
|
+
if [ -f go.mod ]; then go mod download; fi
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Step 3: Verify Clean Baseline
|
|
122
|
+
|
|
123
|
+
Run tests to ensure workspace starts clean:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Use project-appropriate command
|
|
127
|
+
npm test / cargo test / pytest / go test ./...
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**If tests fail:** Report failures, ask whether to proceed or investigate.
|
|
131
|
+
|
|
132
|
+
**If tests pass:** Report ready.
|
|
133
|
+
|
|
134
|
+
### Report
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
Worktree ready at <full-path>
|
|
138
|
+
Tests passing (<N> tests, 0 failures)
|
|
139
|
+
Ready to implement <feature-name>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Quick Reference
|
|
143
|
+
|
|
144
|
+
| Situation | Action |
|
|
145
|
+
|-----------|--------|
|
|
146
|
+
| Already in linked worktree | Skip creation (Step 0) |
|
|
147
|
+
| In a submodule | Treat as normal repo (Step 0 guard) |
|
|
148
|
+
| Native worktree tool available | Use it (Step 1a) |
|
|
149
|
+
| No native tool | Git worktree fallback (Step 1b) |
|
|
150
|
+
| `.worktrees/` exists | Use it (verify ignored) |
|
|
151
|
+
| `worktrees/` exists | Use it (verify ignored) |
|
|
152
|
+
| Both exist | Use `.worktrees/` |
|
|
153
|
+
| Neither exists | Check instruction file, then default `.worktrees/` |
|
|
154
|
+
| Directory not ignored | Add to .gitignore + commit |
|
|
155
|
+
| Permission error on create | Sandbox fallback, work in place |
|
|
156
|
+
| Tests fail during baseline | Report failures + ask |
|
|
157
|
+
| No package.json/Cargo.toml | Skip dependency install |
|
|
158
|
+
|
|
159
|
+
## Common Rationalizations
|
|
160
|
+
|
|
161
|
+
| Excuse | Reality |
|
|
162
|
+
|--------|---------|
|
|
163
|
+
| "I'm obviously not in a worktree — no need to check" | Run Step 0. Harness-created isolation and submodules both fool eyeballing; the detection commands settle it. |
|
|
164
|
+
| "`git worktree add` is quicker than hunting for a native tool" | A native tool (e.g. `EnterWorktree`) owns placement, branching, and cleanup. Bypassing it is the #1 mistake — it creates phantom state your harness can't see or manage. |
|
|
165
|
+
| "The worktree directory is surely ignored already" | Run `git check-ignore`. An unignored worktree directory commits the whole tree into the repo. |
|
|
166
|
+
| "Any directory name works" | Explicit instructions beat an existing project-local directory, which beats the `.worktrees/` default. |
|
|
167
|
+
| "The workspace is fresh — baseline tests can wait" | A dirty baseline makes every later failure ambiguous. Run the tests now; proceeding past failures is your human partner's call. |
|