liteagents 3.0.0 → 3.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/CHANGELOG.md +158 -1
- package/README.md +113 -169
- package/installer/cli.js +4 -2
- package/installer/package-manager.js +3 -1
- package/package.json +4 -3
- package/packages/ampcode/AGENT.md +10 -18
- package/packages/ampcode/agents/code-developer.md +11 -17
- package/packages/ampcode/agents/orchestrator.md +1 -1
- package/packages/ampcode/agents/quality-assurance.md +3 -1
- package/packages/ampcode/{commands/brainstorming.md → skills/brainstorming/SKILL.md} +2 -3
- package/packages/ampcode/{commands/branch-review.md → skills/branch-review/SKILL.md} +27 -13
- package/packages/{claude/commands/docs-builder.md → ampcode/skills/docs-builder/SKILL.md} +1 -1
- package/packages/ampcode/{commands/live-canvas.md → skills/live-canvas/SKILL.md} +8 -4
- package/packages/ampcode/{commands/refactor.md → skills/refactor/SKILL.md} +49 -7
- package/packages/ampcode/{commands/release.md → skills/release/SKILL.md} +4 -4
- package/packages/{claude/commands → ampcode/skills}/remember/AGENT_RULES.md +44 -84
- package/packages/ampcode/{commands/remember.md → skills/remember/SKILL.md} +11 -6
- package/packages/ampcode/{commands → skills}/remember/friction.cjs +0 -0
- package/packages/ampcode/{commands → skills}/remember/stub-check.cjs +28 -19
- package/packages/ampcode/{commands → skills}/remember/sync-rules.cjs +28 -19
- package/packages/{claude/commands → ampcode/skills}/remember/version-check.cjs +1 -1
- package/packages/ampcode/skills/root-cause/SKILL.md +220 -0
- package/packages/ampcode/{commands/trace-back → skills/root-cause}/find-polluter.sh +0 -0
- package/packages/{claude/commands/security.md → ampcode/skills/security/SKILL.md} +1 -1
- package/packages/{claude/commands/ship.md → ampcode/skills/ship/SKILL.md} +1 -1
- package/packages/ampcode/skills/skill-creator/LICENSE.txt +202 -0
- package/packages/ampcode/{commands/skill-creator.md → skills/skill-creator/SKILL.md} +1 -2
- package/packages/ampcode/{commands → skills}/skill-creator/scripts/init_skill.py +0 -0
- package/packages/ampcode/{commands → skills}/skill-creator/scripts/package_skill.py +0 -0
- package/packages/ampcode/{commands → skills}/skill-creator/scripts/quick_validate.py +0 -0
- package/packages/ampcode/{commands/stash.md → skills/stash/SKILL.md} +2 -1
- package/packages/{claude/commands/test-generate.md → ampcode/skills/test-generate/SKILL.md} +2 -2
- package/packages/ampcode/variants.json +2 -2
- package/packages/claude/CLAUDE.md +10 -17
- package/packages/claude/agents/code-developer.md +11 -17
- package/packages/claude/agents/orchestrator.md +2 -3
- package/packages/claude/agents/quality-assurance.md +3 -1
- package/packages/claude/skills/brainstorming/SKILL.md +1 -2
- package/packages/claude/{commands/branch-review.md → skills/branch-review/SKILL.md} +15 -1
- package/packages/{ampcode/commands/docs-builder.md → claude/skills/docs-builder/SKILL.md} +7 -7
- package/packages/claude/skills/live-canvas/SKILL.md +5 -1
- package/packages/claude/{commands/refactor.md → skills/refactor/SKILL.md} +45 -3
- package/packages/claude/{commands/release.md → skills/release/SKILL.md} +1 -1
- package/packages/{ampcode/commands → claude/skills}/remember/AGENT_RULES.md +38 -78
- package/packages/claude/{commands/remember.md → skills/remember/SKILL.md} +11 -6
- package/packages/claude/{commands → skills}/remember/friction.cjs +0 -0
- package/packages/claude/{commands → skills}/remember/stub-check.cjs +28 -19
- package/packages/claude/{commands → skills}/remember/sync-rules.cjs +28 -19
- package/packages/{ampcode/commands → claude/skills}/remember/version-check.cjs +3 -3
- package/packages/claude/skills/root-cause/SKILL.md +220 -0
- package/packages/{ampcode/commands/security.md → claude/skills/security/SKILL.md} +2 -2
- package/packages/{ampcode/commands/ship.md → claude/skills/ship/SKILL.md} +2 -2
- package/packages/claude/skills/skill-creator/SKILL.md +1 -2
- package/packages/claude/{commands/stash.md → skills/stash/SKILL.md} +2 -1
- package/packages/{ampcode/commands/test-generate.md → claude/skills/test-generate/SKILL.md} +3 -3
- package/packages/claude/variants.json +1 -2
- package/packages/droid/AGENTS.md +10 -15
- package/packages/droid/commands/brainstorming.md +1 -4
- package/packages/droid/commands/branch-review.md +25 -14
- package/packages/droid/commands/docs-builder.md +0 -3
- package/packages/droid/commands/live-canvas.md +7 -5
- package/packages/droid/commands/refactor.md +47 -8
- package/packages/droid/commands/release.md +2 -5
- package/packages/droid/commands/remember/AGENT_RULES.md +38 -78
- package/packages/droid/commands/remember/stub-check.cjs +28 -19
- package/packages/droid/commands/remember/sync-rules.cjs +28 -19
- package/packages/droid/commands/remember/version-check.cjs +1 -1
- package/packages/droid/commands/remember.md +6 -4
- package/packages/droid/commands/root-cause.md +218 -0
- package/packages/droid/commands/security.md +0 -3
- package/packages/droid/commands/ship.md +0 -3
- package/packages/droid/commands/skill-creator/LICENSE.txt +202 -0
- package/packages/droid/commands/skill-creator.md +0 -4
- package/packages/droid/commands/stash.md +0 -2
- package/packages/droid/commands/test-generate.md +1 -4
- package/packages/droid/droids/1-create-prd.md +6 -2
- package/packages/droid/droids/2-generate-tasks.md +1 -2
- package/packages/droid/droids/3-process-task-list.md +1 -2
- package/packages/droid/droids/code-developer.md +12 -19
- package/packages/droid/droids/feature-planner.md +1 -2
- package/packages/droid/droids/market-researcher.md +1 -2
- package/packages/droid/droids/orchestrator.md +1 -2
- package/packages/droid/droids/quality-assurance.md +4 -3
- package/packages/droid/droids/system-architect.md +1 -2
- package/packages/droid/droids/ui-designer.md +1 -2
- package/packages/opencode/AGENTS.md +10 -15
- package/packages/opencode/agent/code-developer.md +11 -17
- package/packages/opencode/agent/quality-assurance.md +3 -1
- package/packages/opencode/command/brainstorming.md +1 -4
- package/packages/opencode/command/branch-review.md +25 -15
- package/packages/opencode/command/docs-builder.md +0 -4
- package/packages/opencode/command/live-canvas.md +7 -5
- package/packages/opencode/command/refactor.md +47 -9
- package/packages/opencode/command/release.md +2 -5
- package/packages/opencode/command/remember/AGENT_RULES.md +38 -78
- package/packages/opencode/command/remember/stub-check.cjs +28 -19
- package/packages/opencode/command/remember/sync-rules.cjs +28 -19
- package/packages/opencode/command/remember/version-check.cjs +1 -1
- package/packages/opencode/command/remember.md +6 -4
- package/packages/opencode/command/root-cause.md +218 -0
- package/packages/opencode/command/security.md +0 -4
- package/packages/opencode/command/ship.md +0 -3
- package/packages/opencode/command/skill-creator/LICENSE.txt +202 -0
- package/packages/opencode/command/skill-creator.md +0 -4
- package/packages/opencode/command/stash.md +0 -3
- package/packages/opencode/command/test-generate.md +1 -5
- package/packages/opencode/opencode.jsonc +4 -24
- package/packages/subagentic-manual.md +147 -314
- package/tools/ampcode/manifest-template.json +0 -1
- package/tools/claude/manifest-template.json +0 -1
- package/tools/droid/manifest-template.json +0 -1
- package/tools/opencode/manifest-template.json +0 -1
- package/packages/ampcode/commands/debug-method.md +0 -297
- package/packages/ampcode/commands/live-canvas/README.md +0 -264
- package/packages/ampcode/commands/optimize.md +0 -61
- package/packages/ampcode/commands/tdd-flow.md +0 -390
- package/packages/ampcode/commands/test-traps/example.ts +0 -158
- package/packages/ampcode/commands/test-traps.md +0 -378
- package/packages/ampcode/commands/trace-back.md +0 -176
- package/packages/ampcode/commands/verify-done.md +0 -152
- package/packages/claude/commands/optimize.md +0 -61
- package/packages/claude/plugins/live-canvas-marketplace/plugins/live-canvas-channel/README.md +0 -89
- package/packages/claude/skills/debug-method/CREATION-LOG.md +0 -119
- package/packages/claude/skills/debug-method/SKILL.md +0 -296
- package/packages/claude/skills/debug-method/test-academic.md +0 -14
- package/packages/claude/skills/debug-method/test-pressure-1.md +0 -58
- package/packages/claude/skills/debug-method/test-pressure-2.md +0 -68
- package/packages/claude/skills/debug-method/test-pressure-3.md +0 -69
- package/packages/claude/skills/live-canvas/README.md +0 -269
- package/packages/claude/skills/tdd-flow/SKILL.md +0 -392
- package/packages/claude/skills/test-traps/SKILL.md +0 -378
- package/packages/claude/skills/test-traps/example.ts +0 -158
- package/packages/claude/skills/trace-back/SKILL.md +0 -176
- package/packages/claude/skills/verify-done/SKILL.md +0 -152
- package/packages/droid/commands/debug-method.md +0 -297
- package/packages/droid/commands/live-canvas/README.md +0 -264
- package/packages/droid/commands/optimize.md +0 -61
- package/packages/droid/commands/tdd-flow.md +0 -390
- package/packages/droid/commands/test-traps/example.ts +0 -158
- package/packages/droid/commands/test-traps.md +0 -378
- package/packages/droid/commands/trace-back.md +0 -176
- package/packages/droid/commands/verify-done.md +0 -152
- package/packages/opencode/command/debug-method.md +0 -297
- package/packages/opencode/command/live-canvas/README.md +0 -264
- package/packages/opencode/command/optimize.md +0 -61
- package/packages/opencode/command/tdd-flow.md +0 -390
- package/packages/opencode/command/test-traps/example.ts +0 -158
- package/packages/opencode/command/test-traps.md +0 -378
- package/packages/opencode/command/trace-back.md +0 -176
- package/packages/opencode/command/verify-done.md +0 -152
- /package/packages/ampcode/{commands → skills}/docs-builder/docs-builder.cjs +0 -0
- /package/packages/ampcode/{commands → skills}/live-canvas/DESIGN_PRINCIPLES.md +0 -0
- /package/packages/ampcode/{commands → skills}/live-canvas/dev/post-variants.html +0 -0
- /package/packages/ampcode/{commands → skills}/live-canvas/templates/lab-banner.html +0 -0
- /package/packages/ampcode/{commands → skills}/live-canvas/templates/overlay-vanilla.js +0 -0
- /package/packages/claude/{commands → skills}/docs-builder/docs-builder.cjs +0 -0
- /package/packages/claude/skills/{trace-back → root-cause}/find-polluter.sh +0 -0
- /package/packages/droid/commands/{trace-back → root-cause}/find-polluter.sh +0 -0
- /package/packages/opencode/command/{trace-back → root-cause}/find-polluter.sh +0 -0
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: test-traps
|
|
3
|
-
description: Use when writing or changing tests, adding mocks, or tempted to add test-only methods to production code - prevents testing mock behavior, production pollution with test-only methods, and mocking without understanding dependencies
|
|
4
|
-
usage: /test-traps <testing-scenario>
|
|
5
|
-
auto_trigger: true
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Test Traps
|
|
9
|
-
|
|
10
|
-
## Overview
|
|
11
|
-
|
|
12
|
-
Tests must verify real behavior, not mock behavior. Mocks are a means to isolate, not the thing being tested.
|
|
13
|
-
|
|
14
|
-
**Core principle:** Test what the code does, not what the mocks do.
|
|
15
|
-
|
|
16
|
-
**Following strict TDD prevents these anti-patterns.**
|
|
17
|
-
|
|
18
|
-
## The Iron Laws
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
1. NEVER test mock behavior
|
|
22
|
-
2. NEVER add test-only methods to production classes
|
|
23
|
-
3. NEVER mock without understanding dependencies
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Anti-Pattern 1: Testing Mock Behavior
|
|
27
|
-
|
|
28
|
-
**The violation:**
|
|
29
|
-
```typescript
|
|
30
|
-
// ❌ BAD: Testing that the mock exists
|
|
31
|
-
test('renders sidebar', () => {
|
|
32
|
-
render(<Page />);
|
|
33
|
-
expect(screen.getByTestId('sidebar-mock')).toBeInTheDocument();
|
|
34
|
-
});
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
**Why this is wrong:**
|
|
38
|
-
- You're verifying the mock works, not that the component works
|
|
39
|
-
- Test passes when mock is present, fails when it's not
|
|
40
|
-
- Tells you nothing about real behavior
|
|
41
|
-
|
|
42
|
-
**your human partner's correction:** "Are we testing the behavior of a mock?"
|
|
43
|
-
|
|
44
|
-
**The fix:**
|
|
45
|
-
```typescript
|
|
46
|
-
// ✅ GOOD: Test real component or don't mock it
|
|
47
|
-
test('renders sidebar', () => {
|
|
48
|
-
render(<Page />); // Don't mock sidebar
|
|
49
|
-
expect(screen.getByRole('navigation')).toBeInTheDocument();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// OR if sidebar must be mocked for isolation:
|
|
53
|
-
// Don't assert on the mock - test Page's behavior with sidebar present
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Gate Function
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
BEFORE asserting on any mock element:
|
|
60
|
-
Ask: "Am I testing real component behavior or just mock existence?"
|
|
61
|
-
|
|
62
|
-
IF testing mock existence:
|
|
63
|
-
STOP - Delete the assertion or unmock the component
|
|
64
|
-
|
|
65
|
-
Test real behavior instead
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## Anti-Pattern 2: Test-Only Methods in Production
|
|
69
|
-
|
|
70
|
-
**The violation:**
|
|
71
|
-
```typescript
|
|
72
|
-
// ❌ BAD: destroy() only used in tests
|
|
73
|
-
class Session {
|
|
74
|
-
async destroy() { // Looks like production API!
|
|
75
|
-
await this._workspaceManager?.destroyWorkspace(this.id);
|
|
76
|
-
// ... cleanup
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// In tests
|
|
81
|
-
afterEach(() => session.destroy());
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
**Why this is wrong:**
|
|
85
|
-
- Production class polluted with test-only code
|
|
86
|
-
- Dangerous if accidentally called in production
|
|
87
|
-
- Violates YAGNI and separation of concerns
|
|
88
|
-
- Confuses object lifecycle with entity lifecycle
|
|
89
|
-
|
|
90
|
-
**The fix:**
|
|
91
|
-
```typescript
|
|
92
|
-
// ✅ GOOD: Test utilities handle test cleanup
|
|
93
|
-
// Session has no destroy() - it's stateless in production
|
|
94
|
-
|
|
95
|
-
// In test-utils/
|
|
96
|
-
export async function cleanupSession(session: Session) {
|
|
97
|
-
const workspace = session.getWorkspaceInfo();
|
|
98
|
-
if (workspace) {
|
|
99
|
-
await workspaceManager.destroyWorkspace(workspace.id);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// In tests
|
|
104
|
-
afterEach(() => cleanupSession(session));
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Gate Function
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
BEFORE adding any method to production class:
|
|
111
|
-
Ask: "Is this only used by tests?"
|
|
112
|
-
|
|
113
|
-
IF yes:
|
|
114
|
-
STOP - Don't add it
|
|
115
|
-
Put it in test utilities instead
|
|
116
|
-
|
|
117
|
-
Ask: "Does this class own this resource's lifecycle?"
|
|
118
|
-
|
|
119
|
-
IF no:
|
|
120
|
-
STOP - Wrong class for this method
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Anti-Pattern 3: Mocking Without Understanding
|
|
124
|
-
|
|
125
|
-
**The violation:**
|
|
126
|
-
```typescript
|
|
127
|
-
// ❌ BAD: Mock breaks test logic
|
|
128
|
-
test('detects duplicate server', () => {
|
|
129
|
-
// Mock prevents config write that test depends on!
|
|
130
|
-
vi.mock('ToolCatalog', () => ({
|
|
131
|
-
discoverAndCacheTools: vi.fn().mockResolvedValue(undefined)
|
|
132
|
-
}));
|
|
133
|
-
|
|
134
|
-
await addServer(config);
|
|
135
|
-
await addServer(config); // Should throw - but won't!
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
**Why this is wrong:**
|
|
140
|
-
- Mocked method had side effect test depended on (writing config)
|
|
141
|
-
- Over-mocking to "be safe" breaks actual behavior
|
|
142
|
-
- Test passes for wrong reason or fails mysteriously
|
|
143
|
-
|
|
144
|
-
**The fix:**
|
|
145
|
-
```typescript
|
|
146
|
-
// ✅ GOOD: Mock at correct level
|
|
147
|
-
test('detects duplicate server', () => {
|
|
148
|
-
// Mock the slow part, preserve behavior test needs
|
|
149
|
-
vi.mock('MCPServerManager'); // Just mock slow server startup
|
|
150
|
-
|
|
151
|
-
await addServer(config); // Config written
|
|
152
|
-
await addServer(config); // Duplicate detected ✓
|
|
153
|
-
});
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
### Gate Function
|
|
157
|
-
|
|
158
|
-
```
|
|
159
|
-
BEFORE mocking any method:
|
|
160
|
-
STOP - Don't mock yet
|
|
161
|
-
|
|
162
|
-
1. Ask: "What side effects does the real method have?"
|
|
163
|
-
2. Ask: "Does this test depend on any of those side effects?"
|
|
164
|
-
3. Ask: "Do I fully understand what this test needs?"
|
|
165
|
-
|
|
166
|
-
IF depends on side effects:
|
|
167
|
-
Mock at lower level (the actual slow/external operation)
|
|
168
|
-
OR use test doubles that preserve necessary behavior
|
|
169
|
-
NOT the high-level method the test depends on
|
|
170
|
-
|
|
171
|
-
IF unsure what test depends on:
|
|
172
|
-
Run test with real implementation FIRST
|
|
173
|
-
Observe what actually needs to happen
|
|
174
|
-
THEN add minimal mocking at the right level
|
|
175
|
-
|
|
176
|
-
Red flags:
|
|
177
|
-
- "I'll mock this to be safe"
|
|
178
|
-
- "This might be slow, better mock it"
|
|
179
|
-
- Mocking without understanding the dependency chain
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
## Anti-Pattern 4: Incomplete Mocks
|
|
183
|
-
|
|
184
|
-
**The violation:**
|
|
185
|
-
```typescript
|
|
186
|
-
// ❌ BAD: Partial mock - only fields you think you need
|
|
187
|
-
const mockResponse = {
|
|
188
|
-
status: 'success',
|
|
189
|
-
data: { userId: '123', name: 'Alice' }
|
|
190
|
-
// Missing: metadata that downstream code uses
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// Later: breaks when code accesses response.metadata.requestId
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
**Why this is wrong:**
|
|
197
|
-
- **Partial mocks hide structural assumptions** - You only mocked fields you know about
|
|
198
|
-
- **Downstream code may depend on fields you didn't include** - Silent failures
|
|
199
|
-
- **Tests pass but integration fails** - Mock incomplete, real API complete
|
|
200
|
-
- **False confidence** - Test proves nothing about real behavior
|
|
201
|
-
|
|
202
|
-
**The Iron Rule:** Mock the COMPLETE data structure as it exists in reality, not just fields your immediate test uses.
|
|
203
|
-
|
|
204
|
-
**The fix:**
|
|
205
|
-
```typescript
|
|
206
|
-
// ✅ GOOD: Mirror real API completeness
|
|
207
|
-
const mockResponse = {
|
|
208
|
-
status: 'success',
|
|
209
|
-
data: { userId: '123', name: 'Alice' },
|
|
210
|
-
metadata: { requestId: 'req-789', timestamp: 1234567890 }
|
|
211
|
-
// All fields real API returns
|
|
212
|
-
};
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Gate Function
|
|
216
|
-
|
|
217
|
-
```
|
|
218
|
-
BEFORE creating mock responses:
|
|
219
|
-
Check: "What fields does the real API response contain?"
|
|
220
|
-
|
|
221
|
-
Actions:
|
|
222
|
-
1. Examine actual API response from docs/examples
|
|
223
|
-
2. Include ALL fields system might consume downstream
|
|
224
|
-
3. Verify mock matches real response schema completely
|
|
225
|
-
|
|
226
|
-
Critical:
|
|
227
|
-
If you're creating a mock, you must understand the ENTIRE structure
|
|
228
|
-
Partial mocks fail silently when code depends on omitted fields
|
|
229
|
-
|
|
230
|
-
If uncertain: Include all documented fields
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
## Anti-Pattern 5: Integration Tests as Afterthought
|
|
234
|
-
|
|
235
|
-
**The violation:**
|
|
236
|
-
```
|
|
237
|
-
✅ Implementation complete
|
|
238
|
-
❌ No tests written
|
|
239
|
-
"Ready for testing"
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
**Why this is wrong:**
|
|
243
|
-
- Testing is part of implementation, not optional follow-up
|
|
244
|
-
- TDD would have caught this
|
|
245
|
-
- Can't claim complete without tests
|
|
246
|
-
|
|
247
|
-
**The fix:**
|
|
248
|
-
```
|
|
249
|
-
TDD cycle:
|
|
250
|
-
1. Write failing test
|
|
251
|
-
2. Implement to pass
|
|
252
|
-
3. Refactor
|
|
253
|
-
4. THEN claim complete
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
## Anti-Pattern 6: Timeout-Based Waiting
|
|
257
|
-
|
|
258
|
-
**The violation:**
|
|
259
|
-
```typescript
|
|
260
|
-
// Wait an arbitrary amount of time, then check
|
|
261
|
-
await new Promise(r => setTimeout(r, 50));
|
|
262
|
-
const result = getResult();
|
|
263
|
-
expect(result).toBeDefined();
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
```python
|
|
267
|
-
time.sleep(0.5)
|
|
268
|
-
assert get_result() is not None
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
**Why this is wrong:**
|
|
272
|
-
- Passes on fast machines, fails in CI under load (or vice versa).
|
|
273
|
-
- Either too short (flaky) or too long (slow suite) — every value is wrong somewhere.
|
|
274
|
-
- Hides the actual condition the test cares about.
|
|
275
|
-
- A real bug in the async machinery looks identical to a "too-short sleep."
|
|
276
|
-
|
|
277
|
-
**The fix — poll for the actual condition:**
|
|
278
|
-
```typescript
|
|
279
|
-
await waitFor(() => getResult() !== undefined);
|
|
280
|
-
const result = getResult();
|
|
281
|
-
expect(result).toBeDefined();
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
| Scenario | Pattern |
|
|
285
|
-
|----------|---------|
|
|
286
|
-
| Wait for event | `waitFor(() => events.find(e => e.type === 'DONE'))` |
|
|
287
|
-
| Wait for state | `waitFor(() => machine.state === 'ready')` |
|
|
288
|
-
| Wait for count | `waitFor(() => items.length >= 5)` |
|
|
289
|
-
| Wait for file | `waitFor(() => fs.existsSync(path))` |
|
|
290
|
-
| Complex condition | `waitFor(() => obj.ready && obj.value > 10)` |
|
|
291
|
-
|
|
292
|
-
Minimal generic poller:
|
|
293
|
-
```typescript
|
|
294
|
-
async function waitFor<T>(
|
|
295
|
-
condition: () => T | undefined | null | false,
|
|
296
|
-
description = 'condition',
|
|
297
|
-
timeoutMs = 5000
|
|
298
|
-
): Promise<T> {
|
|
299
|
-
const start = Date.now();
|
|
300
|
-
while (true) {
|
|
301
|
-
const result = condition();
|
|
302
|
-
if (result) return result;
|
|
303
|
-
if (Date.now() - start > timeoutMs) {
|
|
304
|
-
throw new Error(`Timeout waiting for ${description} after ${timeoutMs}ms`);
|
|
305
|
-
}
|
|
306
|
-
await new Promise(r => setTimeout(r, 10));
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
See `example.ts` for domain-specific helpers (`waitForEvent`, `waitForEventCount`, `waitForEventMatch`) drawn from a real debugging session.
|
|
312
|
-
|
|
313
|
-
**Polling pitfalls:**
|
|
314
|
-
- **Polling too fast** (`setTimeout(check, 1)`) wastes CPU. **Fix:** poll every ~10ms.
|
|
315
|
-
- **No timeout** means a never-met condition hangs the suite forever. **Fix:** always include a timeout with a descriptive error.
|
|
316
|
-
- **Stale data** — if you read state once before the loop, you'll never see updates. **Fix:** call the getter *inside* the loop.
|
|
317
|
-
|
|
318
|
-
**When an arbitrary timeout IS correct:**
|
|
319
|
-
```typescript
|
|
320
|
-
// Tool ticks every 100ms; observe 2 ticks of partial output.
|
|
321
|
-
await waitForEvent(manager, 'TOOL_STARTED'); // condition first
|
|
322
|
-
await new Promise(r => setTimeout(r, 200)); // then a documented, calculated wait
|
|
323
|
-
// 200ms = 2 ticks at the documented 100ms cadence
|
|
324
|
-
```
|
|
325
|
-
Requirements: (1) wait for the triggering condition first, (2) the delay is based on a *known* interval (not a guess), (3) a comment explains why a sleep is correct here.
|
|
326
|
-
|
|
327
|
-
**Real-world impact** (debugging session, 2025-10-03): 15 flaky tests across 3 files, pass rate 60% → 100%, suite 40% faster, race conditions gone.
|
|
328
|
-
|
|
329
|
-
## When Mocks Become Too Complex
|
|
330
|
-
|
|
331
|
-
**Warning signs:**
|
|
332
|
-
- Mock setup longer than test logic
|
|
333
|
-
- Mocking everything to make test pass
|
|
334
|
-
- Mocks missing methods real components have
|
|
335
|
-
- Test breaks when mock changes
|
|
336
|
-
|
|
337
|
-
**your human partner's question:** "Do we need to be using a mock here?"
|
|
338
|
-
|
|
339
|
-
**Consider:** Integration tests with real components often simpler than complex mocks
|
|
340
|
-
|
|
341
|
-
## TDD Prevents These Anti-Patterns
|
|
342
|
-
|
|
343
|
-
**Why TDD helps:**
|
|
344
|
-
1. **Write test first** → Forces you to think about what you're actually testing
|
|
345
|
-
2. **Watch it fail** → Confirms test tests real behavior, not mocks
|
|
346
|
-
3. **Minimal implementation** → No test-only methods creep in
|
|
347
|
-
4. **Real dependencies** → You see what the test actually needs before mocking
|
|
348
|
-
|
|
349
|
-
**If you're testing mock behavior, you violated TDD** - you added mocks without watching test fail against real code first.
|
|
350
|
-
|
|
351
|
-
## Quick Reference
|
|
352
|
-
|
|
353
|
-
| Anti-Pattern | Fix |
|
|
354
|
-
|--------------|-----|
|
|
355
|
-
| Assert on mock elements | Test real component or unmock it |
|
|
356
|
-
| Test-only methods in production | Move to test utilities |
|
|
357
|
-
| Mock without understanding | Understand dependencies first, mock minimally |
|
|
358
|
-
| Incomplete mocks | Mirror real API completely |
|
|
359
|
-
| Tests as afterthought | TDD - tests first |
|
|
360
|
-
| Timeout-based waiting | Poll for the actual condition with `waitFor()` |
|
|
361
|
-
| Over-complex mocks | Consider integration tests |
|
|
362
|
-
|
|
363
|
-
## Red Flags
|
|
364
|
-
|
|
365
|
-
- Assertion checks for `*-mock` test IDs
|
|
366
|
-
- Methods only called in test files
|
|
367
|
-
- Mock setup is >50% of test
|
|
368
|
-
- Test fails when you remove mock
|
|
369
|
-
- Can't explain why mock is needed
|
|
370
|
-
- Mocking "just to be safe"
|
|
371
|
-
|
|
372
|
-
## The Bottom Line
|
|
373
|
-
|
|
374
|
-
**Mocks are tools to isolate, not things to test.**
|
|
375
|
-
|
|
376
|
-
If TDD reveals you're testing mock behavior, you've gone wrong.
|
|
377
|
-
|
|
378
|
-
Fix: Test real behavior or question why you're mocking at all.
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: trace-back
|
|
3
|
-
description: Use when errors occur deep in execution and you need to trace back to find the original trigger - systematically traces bugs backward through call stack, adding instrumentation when needed, to identify source of invalid data or incorrect behavior
|
|
4
|
-
usage: /trace-back <issue-description>
|
|
5
|
-
auto_trigger: false
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Trace Back
|
|
9
|
-
|
|
10
|
-
## Overview
|
|
11
|
-
|
|
12
|
-
Bugs often manifest deep in the call stack (git init in wrong directory, file created in wrong location, database opened with wrong path). Your instinct is to fix where the error appears, but that's treating a symptom.
|
|
13
|
-
|
|
14
|
-
**Core principle:** Trace backward through the call chain until you find the original trigger, then fix at the source.
|
|
15
|
-
|
|
16
|
-
## When to Use
|
|
17
|
-
|
|
18
|
-
```dot
|
|
19
|
-
digraph when_to_use {
|
|
20
|
-
"Bug appears deep in stack?" [shape=diamond];
|
|
21
|
-
"Can trace backwards?" [shape=diamond];
|
|
22
|
-
"Fix at symptom point" [shape=box];
|
|
23
|
-
"Trace to original trigger" [shape=box];
|
|
24
|
-
"BETTER: Also add defense-in-depth" [shape=box];
|
|
25
|
-
|
|
26
|
-
"Bug appears deep in stack?" -> "Can trace backwards?" [label="yes"];
|
|
27
|
-
"Can trace backwards?" -> "Trace to original trigger" [label="yes"];
|
|
28
|
-
"Can trace backwards?" -> "Fix at symptom point" [label="no - dead end"];
|
|
29
|
-
"Trace to original trigger" -> "BETTER: Also add defense-in-depth";
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
**Use when:**
|
|
34
|
-
- Error happens deep in execution (not at entry point)
|
|
35
|
-
- Stack trace shows long call chain
|
|
36
|
-
- Unclear where invalid data originated
|
|
37
|
-
- Need to find which test/code triggers the problem
|
|
38
|
-
|
|
39
|
-
## The Tracing Process
|
|
40
|
-
|
|
41
|
-
### 1. Observe the Symptom
|
|
42
|
-
```
|
|
43
|
-
Error: git init failed in /Users/jesse/project/packages/core
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
### 2. Find Immediate Cause
|
|
47
|
-
**What code directly causes this?**
|
|
48
|
-
```typescript
|
|
49
|
-
await execFileAsync('git', ['init'], { cwd: projectDir });
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 3. Ask: What Called This?
|
|
53
|
-
```typescript
|
|
54
|
-
WorktreeManager.createSessionWorktree(projectDir, sessionId)
|
|
55
|
-
→ called by Session.initializeWorkspace()
|
|
56
|
-
→ called by Session.create()
|
|
57
|
-
→ called by test at Project.create()
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 4. Keep Tracing Up
|
|
61
|
-
**What value was passed?**
|
|
62
|
-
- `projectDir = ''` (empty string!)
|
|
63
|
-
- Empty string as `cwd` resolves to `process.cwd()`
|
|
64
|
-
- That's the source code directory!
|
|
65
|
-
|
|
66
|
-
### 5. Find Original Trigger
|
|
67
|
-
**Where did empty string come from?**
|
|
68
|
-
```typescript
|
|
69
|
-
const context = setupCoreTest(); // Returns { tempDir: '' }
|
|
70
|
-
Project.create('name', context.tempDir); // Accessed before beforeEach!
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
## Adding Stack Traces
|
|
74
|
-
|
|
75
|
-
When you can't trace manually, add instrumentation:
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
// Before the problematic operation
|
|
79
|
-
async function gitInit(directory: string) {
|
|
80
|
-
const stack = new Error().stack;
|
|
81
|
-
console.error('DEBUG git init:', {
|
|
82
|
-
directory,
|
|
83
|
-
cwd: process.cwd(),
|
|
84
|
-
nodeEnv: process.env.NODE_ENV,
|
|
85
|
-
stack,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
await execFileAsync('git', ['init'], { cwd: directory });
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
**Critical:** Use `console.error()` in tests (not logger - may not show)
|
|
93
|
-
|
|
94
|
-
**Run and capture:**
|
|
95
|
-
```bash
|
|
96
|
-
npm test 2>&1 | grep 'DEBUG git init'
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
**Analyze stack traces:**
|
|
100
|
-
- Look for test file names
|
|
101
|
-
- Find the line number triggering the call
|
|
102
|
-
- Identify the pattern (same test? same parameter?)
|
|
103
|
-
|
|
104
|
-
## Finding Which Test Causes Pollution
|
|
105
|
-
|
|
106
|
-
If something appears during tests but you don't know which test:
|
|
107
|
-
|
|
108
|
-
Use the bisection script: @find-polluter.sh
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
./find-polluter.sh '.git' 'src/**/*.test.ts'
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Runs tests one-by-one, stops at first polluter. See script for usage.
|
|
115
|
-
|
|
116
|
-
## Real Example: Empty projectDir
|
|
117
|
-
|
|
118
|
-
**Symptom:** `.git` created in `packages/core/` (source code)
|
|
119
|
-
|
|
120
|
-
**Trace chain:**
|
|
121
|
-
1. `git init` runs in `process.cwd()` ← empty cwd parameter
|
|
122
|
-
2. WorktreeManager called with empty projectDir
|
|
123
|
-
3. Session.create() passed empty string
|
|
124
|
-
4. Test accessed `context.tempDir` before beforeEach
|
|
125
|
-
5. setupCoreTest() returns `{ tempDir: '' }` initially
|
|
126
|
-
|
|
127
|
-
**Root cause:** Top-level variable initialization accessing empty value
|
|
128
|
-
|
|
129
|
-
**Fix:** Made tempDir a getter that throws if accessed before beforeEach
|
|
130
|
-
|
|
131
|
-
**Also added defense-in-depth:**
|
|
132
|
-
- Layer 1: Project.create() validates directory
|
|
133
|
-
- Layer 2: WorkspaceManager validates not empty
|
|
134
|
-
- Layer 3: NODE_ENV guard refuses git init outside tmpdir
|
|
135
|
-
- Layer 4: Stack trace logging before git init
|
|
136
|
-
|
|
137
|
-
## Key Principle
|
|
138
|
-
|
|
139
|
-
```dot
|
|
140
|
-
digraph principle {
|
|
141
|
-
"Found immediate cause" [shape=ellipse];
|
|
142
|
-
"Can trace one level up?" [shape=diamond];
|
|
143
|
-
"Trace backwards" [shape=box];
|
|
144
|
-
"Is this the source?" [shape=diamond];
|
|
145
|
-
"Fix at source" [shape=box];
|
|
146
|
-
"Add validation at each layer" [shape=box];
|
|
147
|
-
"Bug impossible" [shape=doublecircle];
|
|
148
|
-
"NEVER fix just the symptom" [shape=octagon, style=filled, fillcolor=red, fontcolor=white];
|
|
149
|
-
|
|
150
|
-
"Found immediate cause" -> "Can trace one level up?";
|
|
151
|
-
"Can trace one level up?" -> "Trace backwards" [label="yes"];
|
|
152
|
-
"Can trace one level up?" -> "NEVER fix just the symptom" [label="no"];
|
|
153
|
-
"Trace backwards" -> "Is this the source?";
|
|
154
|
-
"Is this the source?" -> "Trace backwards" [label="no - keeps going"];
|
|
155
|
-
"Is this the source?" -> "Fix at source" [label="yes"];
|
|
156
|
-
"Fix at source" -> "Add validation at each layer";
|
|
157
|
-
"Add validation at each layer" -> "Bug impossible";
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
**NEVER fix just where the error appears.** Trace back to find the original trigger.
|
|
162
|
-
|
|
163
|
-
## Stack Trace Tips
|
|
164
|
-
|
|
165
|
-
**In tests:** Use `console.error()` not logger - logger may be suppressed
|
|
166
|
-
**Before operation:** Log before the dangerous operation, not after it fails
|
|
167
|
-
**Include context:** Directory, cwd, environment variables, timestamps
|
|
168
|
-
**Capture stack:** `new Error().stack` shows complete call chain
|
|
169
|
-
|
|
170
|
-
## Real-World Impact
|
|
171
|
-
|
|
172
|
-
From debugging session (2025-10-03):
|
|
173
|
-
- Found root cause through 5-level trace
|
|
174
|
-
- Fixed at source (getter validation)
|
|
175
|
-
- Added 4 layers of defense
|
|
176
|
-
- 1847 tests passed, zero pollution
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: verify-done
|
|
3
|
-
description: Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always
|
|
4
|
-
usage: /verify-done <work-to-verify>
|
|
5
|
-
auto_trigger: true
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Verify Done
|
|
9
|
-
|
|
10
|
-
## Auto-Trigger
|
|
11
|
-
|
|
12
|
-
**APPLIES WHEN:**
|
|
13
|
-
- About to say: done, fixed, complete, passing, success
|
|
14
|
-
- About to commit, push, create PR
|
|
15
|
-
- About to mark task [x]
|
|
16
|
-
|
|
17
|
-
**APPLIES TO:** All agents, all invocation paths
|
|
18
|
-
|
|
19
|
-
**NEVER SKIP:** Even for "obvious" tasks
|
|
20
|
-
|
|
21
|
-
## Overview
|
|
22
|
-
|
|
23
|
-
Claiming work is complete without verification is dishonesty, not efficiency.
|
|
24
|
-
|
|
25
|
-
**Core principle:** Evidence before claims, always.
|
|
26
|
-
|
|
27
|
-
**Violating the letter of this rule is violating the spirit of this rule.**
|
|
28
|
-
|
|
29
|
-
## The Iron Law
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
If you haven't run the verification command in this message, you cannot claim it passes.
|
|
36
|
-
|
|
37
|
-
## The Gate Function
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
BEFORE claiming any status or expressing satisfaction:
|
|
41
|
-
|
|
42
|
-
1. IDENTIFY: What command proves this claim?
|
|
43
|
-
2. RUN: Execute the FULL command (fresh, complete)
|
|
44
|
-
3. READ: Full output, check exit code, count failures
|
|
45
|
-
4. VERIFY: Does output confirm the claim?
|
|
46
|
-
- If NO: State actual status with evidence
|
|
47
|
-
- If YES: State claim WITH evidence
|
|
48
|
-
5. ONLY THEN: Make the claim
|
|
49
|
-
|
|
50
|
-
Skip any step = lying, not verifying
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
## Common Failures
|
|
54
|
-
|
|
55
|
-
| Claim | Requires | Not Sufficient |
|
|
56
|
-
|-------|----------|----------------|
|
|
57
|
-
| Tests pass | Test command output: 0 failures | Previous run, "should pass" |
|
|
58
|
-
| Linter clean | Linter output: 0 errors | Partial check, extrapolation |
|
|
59
|
-
| Build succeeds | Build command: exit 0 | Linter passing, logs look good |
|
|
60
|
-
| Bug fixed | Test original symptom: passes | Code changed, assumed fixed |
|
|
61
|
-
| Regression test works | Red-green cycle verified | Test passes once |
|
|
62
|
-
| Agent completed | VCS diff shows changes | Agent reports "success" |
|
|
63
|
-
| Requirements met | Line-by-line checklist | Tests passing |
|
|
64
|
-
|
|
65
|
-
## Red Flags - STOP
|
|
66
|
-
|
|
67
|
-
- Using "should", "probably", "seems to"
|
|
68
|
-
- Expressing satisfaction before verification ("Great!", "Perfect!", "Done!", etc.)
|
|
69
|
-
- About to commit/push/PR without verification
|
|
70
|
-
- Trusting agent success reports
|
|
71
|
-
- Relying on partial verification
|
|
72
|
-
- Thinking "just this once"
|
|
73
|
-
- Tired and wanting work over
|
|
74
|
-
- **ANY wording implying success without having run verification**
|
|
75
|
-
|
|
76
|
-
## Rationalization Prevention
|
|
77
|
-
|
|
78
|
-
| Excuse | Reality |
|
|
79
|
-
|--------|---------|
|
|
80
|
-
| "Should work now" | RUN the verification |
|
|
81
|
-
| "I'm confident" | Confidence ≠ evidence |
|
|
82
|
-
| "Just this once" | No exceptions |
|
|
83
|
-
| "Linter passed" | Linter ≠ compiler |
|
|
84
|
-
| "Agent said success" | Verify independently |
|
|
85
|
-
| "I'm tired" | Exhaustion ≠ excuse |
|
|
86
|
-
| "Partial check is enough" | Partial proves nothing |
|
|
87
|
-
| "Different words so rule doesn't apply" | Spirit over letter |
|
|
88
|
-
|
|
89
|
-
## Key Patterns
|
|
90
|
-
|
|
91
|
-
**Tests:**
|
|
92
|
-
```
|
|
93
|
-
✅ [Run test command] [See: 34/34 pass] "All tests pass"
|
|
94
|
-
❌ "Should pass now" / "Looks correct"
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
**Regression tests (TDD Red-Green):**
|
|
98
|
-
```
|
|
99
|
-
✅ Write → Run (pass) → Revert fix → Run (MUST FAIL) → Restore → Run (pass)
|
|
100
|
-
❌ "I've written a regression test" (without red-green verification)
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
**Build:**
|
|
104
|
-
```
|
|
105
|
-
✅ [Run build] [See: exit 0] "Build passes"
|
|
106
|
-
❌ "Linter passed" (linter doesn't check compilation)
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
**Requirements:**
|
|
110
|
-
```
|
|
111
|
-
✅ Re-read plan → Create checklist → Verify each → Report gaps or completion
|
|
112
|
-
❌ "Tests pass, phase complete"
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
**Agent delegation:**
|
|
116
|
-
```
|
|
117
|
-
✅ Agent reports success → Check VCS diff → Verify changes → Report actual state
|
|
118
|
-
❌ Trust agent report
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
## Why This Matters
|
|
122
|
-
|
|
123
|
-
From 24 failure memories:
|
|
124
|
-
- your human partner said "I don't believe you" - trust broken
|
|
125
|
-
- Undefined functions shipped - would crash
|
|
126
|
-
- Missing requirements shipped - incomplete features
|
|
127
|
-
- Time wasted on false completion → redirect → rework
|
|
128
|
-
- Violates: "Honesty is a core value. If you lie, you'll be replaced."
|
|
129
|
-
|
|
130
|
-
## When To Apply
|
|
131
|
-
|
|
132
|
-
**ALWAYS before:**
|
|
133
|
-
- ANY variation of success/completion claims
|
|
134
|
-
- ANY expression of satisfaction
|
|
135
|
-
- ANY positive statement about work state
|
|
136
|
-
- Committing, PR creation, task completion
|
|
137
|
-
- Moving to next task
|
|
138
|
-
- Delegating to agents
|
|
139
|
-
|
|
140
|
-
**Rule applies to:**
|
|
141
|
-
- Exact phrases
|
|
142
|
-
- Paraphrases and synonyms
|
|
143
|
-
- Implications of success
|
|
144
|
-
- ANY communication suggesting completion/correctness
|
|
145
|
-
|
|
146
|
-
## The Bottom Line
|
|
147
|
-
|
|
148
|
-
**No shortcuts for verification.**
|
|
149
|
-
|
|
150
|
-
Run the command. Read the output. THEN claim the result.
|
|
151
|
-
|
|
152
|
-
This is non-negotiable.
|