context-mode 1.0.110 → 1.0.112
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/.openclaw-plugin/index.ts +3 -2
- package/.openclaw-plugin/openclaw.plugin.json +1 -1
- package/.openclaw-plugin/package.json +1 -1
- package/README.md +152 -34
- package/bin/statusline.mjs +144 -127
- package/build/adapters/base.d.ts +8 -5
- package/build/adapters/base.js +8 -18
- package/build/adapters/claude-code/index.d.ts +24 -3
- package/build/adapters/claude-code/index.js +44 -11
- package/build/adapters/codex/hooks.d.ts +10 -5
- package/build/adapters/codex/hooks.js +10 -5
- package/build/adapters/codex/index.d.ts +17 -5
- package/build/adapters/codex/index.js +337 -37
- package/build/adapters/codex/paths.d.ts +1 -0
- package/build/adapters/codex/paths.js +12 -0
- package/build/adapters/cursor/index.d.ts +6 -0
- package/build/adapters/cursor/index.js +83 -2
- package/build/adapters/detect.d.ts +1 -1
- package/build/adapters/detect.js +29 -6
- package/build/adapters/omp/index.d.ts +65 -0
- package/build/adapters/omp/index.js +182 -0
- package/build/adapters/omp/plugin.d.ts +75 -0
- package/build/adapters/omp/plugin.js +220 -0
- package/build/adapters/openclaw/mcp-tools.d.ts +54 -0
- package/build/adapters/openclaw/mcp-tools.js +198 -0
- package/build/adapters/openclaw/plugin.d.ts +130 -0
- package/build/adapters/openclaw/plugin.js +629 -0
- package/build/adapters/openclaw/workspace-router.d.ts +29 -0
- package/build/adapters/openclaw/workspace-router.js +64 -0
- package/build/adapters/opencode/plugin.d.ts +145 -0
- package/build/adapters/opencode/plugin.js +457 -0
- package/build/adapters/pi/extension.d.ts +26 -0
- package/build/adapters/pi/extension.js +552 -0
- package/build/adapters/pi/index.d.ts +57 -0
- package/build/adapters/pi/index.js +173 -0
- package/build/adapters/pi/mcp-bridge.d.ts +113 -0
- package/build/adapters/pi/mcp-bridge.js +251 -0
- package/build/adapters/types.d.ts +11 -6
- package/build/cli.js +186 -170
- package/build/db-base.d.ts +15 -2
- package/build/db-base.js +50 -5
- package/build/executor.d.ts +2 -0
- package/build/executor.js +15 -2
- package/build/opencode-plugin.js +1 -1
- package/build/runPool.d.ts +36 -0
- package/build/runPool.js +51 -0
- package/build/runtime.js +64 -5
- package/build/search/auto-memory.js +6 -4
- package/build/security.js +30 -10
- package/build/server.d.ts +23 -1
- package/build/server.js +652 -174
- package/build/session/analytics.d.ts +404 -1
- package/build/session/analytics.js +1347 -42
- package/build/session/db.d.ts +114 -5
- package/build/session/db.js +275 -27
- package/build/session/event-emit.d.ts +48 -0
- package/build/session/event-emit.js +101 -0
- package/build/session/extract.d.ts +1 -0
- package/build/session/extract.js +79 -12
- package/build/session/purge.d.ts +111 -0
- package/build/session/purge.js +138 -0
- package/build/store.d.ts +7 -0
- package/build/store.js +69 -6
- package/build/util/claude-config.d.ts +26 -0
- package/build/util/claude-config.js +91 -0
- package/build/util/hook-config.d.ts +4 -0
- package/build/util/hook-config.js +39 -0
- package/cli.bundle.mjs +411 -208
- package/configs/antigravity/GEMINI.md +0 -3
- package/configs/claude-code/CLAUDE.md +1 -4
- package/configs/codex/AGENTS.md +1 -4
- package/configs/codex/config.toml +3 -0
- package/configs/codex/hooks.json +8 -0
- package/configs/cursor/context-mode.mdc +0 -3
- package/configs/gemini-cli/GEMINI.md +0 -3
- package/configs/jetbrains-copilot/copilot-instructions.md +0 -3
- package/configs/kilo/AGENTS.md +0 -3
- package/configs/kiro/KIRO.md +0 -3
- package/configs/omp/SYSTEM.md +85 -0
- package/configs/omp/mcp.json +7 -0
- package/configs/openclaw/AGENTS.md +0 -3
- package/configs/opencode/AGENTS.md +0 -3
- package/configs/pi/AGENTS.md +0 -3
- package/configs/qwen-code/QWEN.md +1 -4
- package/configs/vscode-copilot/copilot-instructions.md +0 -3
- package/configs/zed/AGENTS.md +0 -3
- package/hooks/codex/posttooluse.mjs +9 -2
- package/hooks/codex/precompact.mjs +69 -0
- package/hooks/codex/sessionstart.mjs +13 -9
- package/hooks/codex/stop.mjs +1 -2
- package/hooks/codex/userpromptsubmit.mjs +1 -2
- package/hooks/core/routing.mjs +237 -18
- package/hooks/cursor/afteragentresponse.mjs +1 -1
- package/hooks/cursor/hooks.json +31 -0
- package/hooks/cursor/posttooluse.mjs +1 -1
- package/hooks/cursor/sessionstart.mjs +5 -5
- package/hooks/cursor/stop.mjs +1 -1
- package/hooks/ensure-deps.mjs +12 -13
- package/hooks/gemini-cli/aftertool.mjs +1 -1
- package/hooks/gemini-cli/beforeagent.mjs +1 -1
- package/hooks/gemini-cli/precompress.mjs +3 -2
- package/hooks/gemini-cli/sessionstart.mjs +9 -9
- package/hooks/jetbrains-copilot/posttooluse.mjs +1 -1
- package/hooks/jetbrains-copilot/precompact.mjs +3 -2
- package/hooks/jetbrains-copilot/sessionstart.mjs +9 -9
- package/hooks/kiro/agentspawn.mjs +5 -5
- package/hooks/kiro/posttooluse.mjs +2 -2
- package/hooks/kiro/userpromptsubmit.mjs +1 -1
- package/hooks/posttooluse.mjs +45 -0
- package/hooks/precompact.mjs +17 -0
- package/hooks/pretooluse.mjs +23 -0
- package/hooks/routing-block.mjs +0 -12
- package/hooks/run-hook.mjs +16 -3
- package/hooks/session-db.bundle.mjs +27 -18
- package/hooks/session-extract.bundle.mjs +2 -2
- package/hooks/session-helpers.mjs +101 -64
- package/hooks/sessionstart.mjs +51 -2
- package/hooks/vscode-copilot/posttooluse.mjs +1 -1
- package/hooks/vscode-copilot/precompact.mjs +3 -2
- package/hooks/vscode-copilot/sessionstart.mjs +9 -9
- package/openclaw.plugin.json +1 -1
- package/package.json +14 -8
- package/server.bundle.mjs +349 -147
- package/skills/UPSTREAM-CREDITS.md +0 -51
- package/skills/context-mode-ops/SKILL.md +0 -299
- package/skills/context-mode-ops/agent-teams.md +0 -198
- package/skills/context-mode-ops/communication.md +0 -224
- package/skills/context-mode-ops/marketing.md +0 -124
- package/skills/context-mode-ops/release.md +0 -214
- package/skills/context-mode-ops/review-pr.md +0 -269
- package/skills/context-mode-ops/tdd.md +0 -329
- package/skills/context-mode-ops/triage-issue.md +0 -266
- package/skills/context-mode-ops/validation.md +0 -307
- package/skills/diagnose/SKILL.md +0 -122
- package/skills/diagnose/scripts/hitl-loop.template.sh +0 -41
- package/skills/grill-me/SKILL.md +0 -15
- package/skills/grill-with-docs/ADR-FORMAT.md +0 -47
- package/skills/grill-with-docs/CONTEXT-FORMAT.md +0 -77
- package/skills/grill-with-docs/SKILL.md +0 -93
- package/skills/improve-codebase-architecture/DEEPENING.md +0 -37
- package/skills/improve-codebase-architecture/INTERFACE-DESIGN.md +0 -44
- package/skills/improve-codebase-architecture/LANGUAGE.md +0 -53
- package/skills/improve-codebase-architecture/SKILL.md +0 -76
- package/skills/tdd/SKILL.md +0 -114
- package/skills/tdd/deep-modules.md +0 -33
- package/skills/tdd/interface-design.md +0 -31
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/refactoring.md +0 -10
- package/skills/tdd/tests.md +0 -61
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
# Review PR Workflow
|
|
2
|
-
|
|
3
|
-
## Trigger
|
|
4
|
-
|
|
5
|
-
User says: "review PR #N", "merge PR #N", "check PR #N"
|
|
6
|
-
|
|
7
|
-
## Core Philosophy
|
|
8
|
-
|
|
9
|
-
**Merge first, fix on top.** Contributors ghost when you request changes. Merge their work (if not absurd), then fix issues in follow-up commits. This keeps momentum and respects their effort.
|
|
10
|
-
|
|
11
|
-
**Exception:** Only reject if the PR introduces a security vulnerability, breaks core functionality beyond repair, or is completely unrelated to the project.
|
|
12
|
-
|
|
13
|
-
## Step-by-Step
|
|
14
|
-
|
|
15
|
-
### 1. Gather Intelligence (ONE batch call)
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
commands: [
|
|
19
|
-
{ label: "pr-body", command: "gh pr view {N} --json title,body,state,author,baseRefName,headRefName,additions,deletions,files,reviews,comments,labels" },
|
|
20
|
-
{ label: "pr-diff", command: "gh pr diff {N}" },
|
|
21
|
-
{ label: "pr-comments", command: "gh pr view {N} --comments" },
|
|
22
|
-
{ label: "pr-checks", command: "gh pr checks {N}" },
|
|
23
|
-
{ label: "pr-files", command: "gh pr view {N} --json files --jq '.files[].path'" },
|
|
24
|
-
{ label: "related-issue", command: "gh pr view {N} --json body --jq '.body' | grep -oP '#\\d+' | head -5" }
|
|
25
|
-
],
|
|
26
|
-
queries: [
|
|
27
|
-
"PR title description changes",
|
|
28
|
-
"files modified adapter platform",
|
|
29
|
-
"diff code changes additions deletions",
|
|
30
|
-
"review comments feedback",
|
|
31
|
-
"CI check status pass fail",
|
|
32
|
-
"related issues referenced"
|
|
33
|
-
]
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### 2. Classify & Spawn Agents
|
|
37
|
-
|
|
38
|
-
Same classification as [triage-issue.md](triage-issue.md) step 2, but based on PR diff:
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
ALWAYS spawn:
|
|
42
|
-
├── Context Mode Architect (reviews all changes)
|
|
43
|
-
├── QA Engineer (tests everything)
|
|
44
|
-
├── DX Engineer (output quality check)
|
|
45
|
-
|
|
46
|
-
BASED ON FILES CHANGED:
|
|
47
|
-
├── {Platform} Architect (for each affected adapter)
|
|
48
|
-
├── Validation Engineer (verify ENV vars, hooks, configs via websearch)
|
|
49
|
-
|
|
50
|
-
BASED ON CONTENT:
|
|
51
|
-
├── {Domain} Architect (database, security, OS, hooks, session, etc.)
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Critical addition for PRs — Validation Engineer:**
|
|
55
|
-
|
|
56
|
-
This agent specifically validates claims made in the PR:
|
|
57
|
-
- ENV variables actually exist in the target platform
|
|
58
|
-
- Hook formats match the platform's actual API
|
|
59
|
-
- Config paths are real, not LLM hallucinations
|
|
60
|
-
- Features referenced actually exist in the platform's codebase
|
|
61
|
-
|
|
62
|
-
Uses WebSearch and Context7 to verify against official docs.
|
|
63
|
-
|
|
64
|
-
### 3. Validation Phase (Parallel)
|
|
65
|
-
|
|
66
|
-
All agents run simultaneously:
|
|
67
|
-
|
|
68
|
-
**Context Mode Architect:**
|
|
69
|
-
- Does the change align with project architecture?
|
|
70
|
-
- Does it follow existing patterns?
|
|
71
|
-
- Are there edge cases the author missed?
|
|
72
|
-
- Is session continuity preserved?
|
|
73
|
-
- **TDD compliance**: Does the PR include tests? Do tests verify behavior (not implementation)?
|
|
74
|
-
- If no tests: flag as CHANGES_NEEDED (but still merge + add tests in follow-up)
|
|
75
|
-
- If tests mock internal collaborators: flag — tests should use public interfaces per [tdd.md](tdd.md)
|
|
76
|
-
|
|
77
|
-
**QA Engineer:**
|
|
78
|
-
```shell
|
|
79
|
-
# Checkout PR locally
|
|
80
|
-
gh pr checkout {N}
|
|
81
|
-
|
|
82
|
-
# Run affected adapter tests
|
|
83
|
-
npx vitest run tests/adapters/{affected}.test.ts
|
|
84
|
-
|
|
85
|
-
# Run full suite
|
|
86
|
-
npm test
|
|
87
|
-
|
|
88
|
-
# TypeScript
|
|
89
|
-
npm run typecheck
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
**Validation Engineer:**
|
|
93
|
-
```javascript
|
|
94
|
-
// For each ENV var mentioned in the PR:
|
|
95
|
-
// 1. Grep for it in context-mode source
|
|
96
|
-
// 2. WebSearch: "{PLATFORM_NAME} {ENV_VAR} environment variable"
|
|
97
|
-
// 3. Context7: resolve-library-id for the platform, then query-docs
|
|
98
|
-
|
|
99
|
-
// Example: PR adds OPENCODE_CONFIG_PATH
|
|
100
|
-
// → Search OpenCode source: does this env var exist?
|
|
101
|
-
// → If not: flag as potential LLM hallucination
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
**Platform Architects:**
|
|
105
|
-
- Review changes specific to their platform
|
|
106
|
-
- Validate against platform's actual hook/config format
|
|
107
|
-
- Check backward compatibility
|
|
108
|
-
|
|
109
|
-
### 4. Merge Decision Matrix
|
|
110
|
-
|
|
111
|
-
```
|
|
112
|
-
All tests pass + All architects APPROVE?
|
|
113
|
-
├── YES → Merge immediately
|
|
114
|
-
│
|
|
115
|
-
├── TESTS FAIL but fix is trivial?
|
|
116
|
-
│ └── Merge → Fix on top in follow-up commit
|
|
117
|
-
│
|
|
118
|
-
├── ARCHITECT has minor concerns?
|
|
119
|
-
│ └── Merge → Fix concerns in follow-up commit
|
|
120
|
-
│
|
|
121
|
-
├── VALIDATION catches hallucinated ENV/feature?
|
|
122
|
-
│ └── Merge if core logic is sound → Remove hallucinated parts
|
|
123
|
-
│ └── OR: Comment explaining the issue, give 48h, then merge+fix
|
|
124
|
-
│
|
|
125
|
-
├── SECURITY issue found?
|
|
126
|
-
│ └── Do NOT merge. Comment with specific vulnerability.
|
|
127
|
-
│
|
|
128
|
-
└── PR is completely off-base?
|
|
129
|
-
└── Close with kind explanation. Rare — almost never do this.
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### 5. Merge to `next` & Fix Flow
|
|
133
|
-
|
|
134
|
-
Always use `gh` CLI. Always squash merge into `next`:
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
# Change PR base to next if needed
|
|
138
|
-
gh pr edit {N} --base next
|
|
139
|
-
|
|
140
|
-
# Squash merge into next
|
|
141
|
-
gh pr merge {N} --squash
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
If follow-up fixes needed, push directly to `next`:
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
git checkout next
|
|
148
|
-
git pull origin next
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
**Follow-up fixes MUST follow TDD** (per [tdd.md](tdd.md)):
|
|
152
|
-
|
|
153
|
-
```bash
|
|
154
|
-
# RED: Write failing test for the issue found during review
|
|
155
|
-
npx vitest run tests/{file}.test.ts # verify FAILS
|
|
156
|
-
|
|
157
|
-
# GREEN: Write minimal fix
|
|
158
|
-
# ... edit files ...
|
|
159
|
-
npx vitest run tests/{file}.test.ts # verify PASSES
|
|
160
|
-
|
|
161
|
-
# REFACTOR: Clean up
|
|
162
|
-
npm test # full suite still passes
|
|
163
|
-
|
|
164
|
-
# Commit
|
|
165
|
-
git add {files}
|
|
166
|
-
git commit -m "fix: address review findings from #{N}
|
|
167
|
-
|
|
168
|
-
- {fix 1}
|
|
169
|
-
- {fix 2}
|
|
170
|
-
|
|
171
|
-
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>"
|
|
172
|
-
|
|
173
|
-
git push origin next
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
### 6. Comment on PR
|
|
177
|
-
|
|
178
|
-
**After merge (standard):**
|
|
179
|
-
|
|
180
|
-
```bash
|
|
181
|
-
gh pr comment {N} --body "$(cat <<'EOF'
|
|
182
|
-
Thanks for this contribution, @{author}! 🎉
|
|
183
|
-
|
|
184
|
-
Merged into `next` — this will ship in the next release.
|
|
185
|
-
|
|
186
|
-
Could you please test it in your setup once the release is out? You know this area best, so your verification would be really valuable. 🙏
|
|
187
|
-
|
|
188
|
-
{IF follow-up fixes were made:}
|
|
189
|
-
I made a small follow-up adjustment in {commit_sha}:
|
|
190
|
-
- {what was adjusted and why}
|
|
191
|
-
EOF
|
|
192
|
-
)"
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
**After merge with concerns:**
|
|
196
|
-
|
|
197
|
-
```bash
|
|
198
|
-
gh pr comment {N} --body "$(cat <<'EOF'
|
|
199
|
-
Thanks @{author}! Merged this into `next`.
|
|
200
|
-
|
|
201
|
-
I made a few adjustments on top:
|
|
202
|
-
- {change 1}: {reason}
|
|
203
|
-
- {change 2}: {reason}
|
|
204
|
-
|
|
205
|
-
These are in {commit_sha}. Could you review those changes and test the complete flow in your environment? The responsibility for verifying this works end-to-end is on you since you're closest to the use case. 🙏
|
|
206
|
-
|
|
207
|
-
This will ship in the next release!
|
|
208
|
-
EOF
|
|
209
|
-
)"
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
**Rare: closing without merge:**
|
|
213
|
-
|
|
214
|
-
```bash
|
|
215
|
-
gh pr comment {N} --body "$(cat <<'EOF'
|
|
216
|
-
Hey @{author}, thanks for taking the time to put this together!
|
|
217
|
-
|
|
218
|
-
Unfortunately, we can't merge this as-is because:
|
|
219
|
-
- {specific technical reason}
|
|
220
|
-
|
|
221
|
-
{IF salvageable:}
|
|
222
|
-
If you'd like to take another pass, here's what would need to change:
|
|
223
|
-
- {specific guidance}
|
|
224
|
-
|
|
225
|
-
{IF not salvageable:}
|
|
226
|
-
The direction we're going with this area is {explanation}. I appreciate the effort though!
|
|
227
|
-
EOF
|
|
228
|
-
)"
|
|
229
|
-
gh pr close {N}
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
## ENV/Feature Validation Protocol
|
|
233
|
-
|
|
234
|
-
This is the most critical part of PR review. LLMs frequently hallucinate ENV vars, hooks, and features.
|
|
235
|
-
|
|
236
|
-
### Red Flags to Watch For
|
|
237
|
-
|
|
238
|
-
1. **New ENV variable** — Does this actually exist in the platform?
|
|
239
|
-
2. **New hook type** — Does the platform support this hook lifecycle?
|
|
240
|
-
3. **Config path** — Is this the real config location?
|
|
241
|
-
4. **API endpoint** — Does this API actually exist?
|
|
242
|
-
5. **Feature flag** — Is this a real feature of the platform?
|
|
243
|
-
|
|
244
|
-
### Verification Steps
|
|
245
|
-
|
|
246
|
-
For EACH claim in the PR:
|
|
247
|
-
|
|
248
|
-
1. **Grep source**: `rg "{CLAIM}" src/` — is it already used?
|
|
249
|
-
2. **WebSearch**: Search for official documentation of the claim
|
|
250
|
-
3. **Context7**: `resolve-library-id` → `query-docs` for the platform
|
|
251
|
-
4. **GitHub source**: Check the platform's actual repository if open source
|
|
252
|
-
|
|
253
|
-
### Example: Fake ENV Detection
|
|
254
|
-
|
|
255
|
-
```
|
|
256
|
-
PR adds: process.env.OPENCODE_HOOK_PATH
|
|
257
|
-
Step 1: rg "OPENCODE_HOOK_PATH" src/ → not found
|
|
258
|
-
Step 2: WebSearch "OpenCode OPENCODE_HOOK_PATH environment variable" → no results
|
|
259
|
-
Step 3: Context7 query OpenCode docs for "HOOK_PATH" → not documented
|
|
260
|
-
Verdict: HALLUCINATED — flag to EM, remove from PR
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
## Handling Stale PRs
|
|
264
|
-
|
|
265
|
-
If a PR has been open >7 days with no activity:
|
|
266
|
-
1. Check if it's still relevant
|
|
267
|
-
2. If yes: merge it, fix on top
|
|
268
|
-
3. If no: close with kind explanation
|
|
269
|
-
4. Never leave PRs in limbo
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
# Test-Driven Development
|
|
2
|
-
|
|
3
|
-
<tdd_enforcement>
|
|
4
|
-
THIS FILE IS MANDATORY. Every agent, every Staff Engineer, every Architect MUST follow this.
|
|
5
|
-
If you skip TDD, your work will be REJECTED. There are no exceptions.
|
|
6
|
-
Do NOT write implementation code before you have a failing test.
|
|
7
|
-
</tdd_enforcement>
|
|
8
|
-
|
|
9
|
-
> Source: [mattpocock/skills/tdd](https://github.com/mattpocock/skills/tree/main/tdd) — embedded with context-mode enforcement.
|
|
10
|
-
|
|
11
|
-
## Philosophy
|
|
12
|
-
|
|
13
|
-
**Core principle**: Tests should verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't.
|
|
14
|
-
|
|
15
|
-
**Good tests** are integration-style: they exercise real code paths through public APIs. They describe _what_ the system does, not _how_ it does it. A good test reads like a specification — "user can checkout with valid cart" tells you exactly what capability exists. These tests survive refactors because they don't care about internal structure.
|
|
16
|
-
|
|
17
|
-
**Bad tests** are coupled to implementation. They mock internal collaborators, test private methods, or verify through external means (like querying a database directly instead of using the interface). The warning sign: your test breaks when you refactor, but behavior hasn't changed. If you rename an internal function and tests fail, those tests were testing implementation, not behavior.
|
|
18
|
-
|
|
19
|
-
## Anti-Pattern: Horizontal Slices
|
|
20
|
-
|
|
21
|
-
**DO NOT write all tests first, then all implementation.** This is "horizontal slicing" — treating RED as "write all tests" and GREEN as "write all code."
|
|
22
|
-
|
|
23
|
-
This produces **crap tests**:
|
|
24
|
-
|
|
25
|
-
- Tests written in bulk test _imagined_ behavior, not _actual_ behavior
|
|
26
|
-
- You end up testing the _shape_ of things (data structures, function signatures) rather than user-facing behavior
|
|
27
|
-
- Tests become insensitive to real changes — they pass when behavior breaks, fail when behavior is fine
|
|
28
|
-
- You outrun your headlights, committing to test structure before understanding the implementation
|
|
29
|
-
|
|
30
|
-
**Correct approach**: Vertical slices via tracer bullets. One test → one implementation → repeat. Each test responds to what you learned from the previous cycle. Because you just wrote the code, you know exactly what behavior matters and how to verify it.
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
WRONG (horizontal):
|
|
34
|
-
RED: test1, test2, test3, test4, test5
|
|
35
|
-
GREEN: impl1, impl2, impl3, impl4, impl5
|
|
36
|
-
|
|
37
|
-
RIGHT (vertical):
|
|
38
|
-
RED→GREEN: test1→impl1
|
|
39
|
-
RED→GREEN: test2→impl2
|
|
40
|
-
RED→GREEN: test3→impl3
|
|
41
|
-
...
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Workflow
|
|
45
|
-
|
|
46
|
-
### 1. Planning
|
|
47
|
-
|
|
48
|
-
Before writing any code:
|
|
49
|
-
|
|
50
|
-
- [ ] Identify what behaviors need to change or be added
|
|
51
|
-
- [ ] List the behaviors to test (not implementation steps)
|
|
52
|
-
- [ ] Identify opportunities for deep modules (small interface, deep implementation)
|
|
53
|
-
- [ ] Design interfaces for testability
|
|
54
|
-
|
|
55
|
-
**You can't test everything.** Focus testing effort on critical paths and complex logic, not every possible edge case.
|
|
56
|
-
|
|
57
|
-
### 2. Tracer Bullet
|
|
58
|
-
|
|
59
|
-
For the first behavior:
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
RED: Write test for first behavior → test fails
|
|
63
|
-
GREEN: Write minimal code to pass → test passes
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Then refactor:
|
|
67
|
-
|
|
68
|
-
- [ ] Extract duplication
|
|
69
|
-
- [ ] Deepen modules (move complexity behind simple interfaces)
|
|
70
|
-
- [ ] Apply SOLID principles where natural
|
|
71
|
-
- [ ] Consider what new code reveals about existing code
|
|
72
|
-
- [ ] Run tests after each refactor step
|
|
73
|
-
|
|
74
|
-
**Never refactor while RED.** Get to GREEN first.
|
|
75
|
-
|
|
76
|
-
### 3. Next Behavior
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
RED: Write next test → fails
|
|
80
|
-
GREEN: Minimal code to pass → passes
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Refactor again. Repeat until all behaviors are covered.
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Good and Bad Tests
|
|
88
|
-
|
|
89
|
-
### Good Tests (Integration-Style)
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
// GOOD: Tests observable behavior
|
|
93
|
-
test("user can checkout with valid cart", async () => {
|
|
94
|
-
const cart = createCart();
|
|
95
|
-
cart.add(product);
|
|
96
|
-
const result = await checkout(cart, paymentMethod);
|
|
97
|
-
expect(result.status).toBe("confirmed");
|
|
98
|
-
});
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Characteristics:
|
|
102
|
-
|
|
103
|
-
- Tests behavior users/callers care about
|
|
104
|
-
- Uses public API only
|
|
105
|
-
- Survives internal refactors
|
|
106
|
-
- Describes WHAT, not HOW
|
|
107
|
-
- One logical assertion per test
|
|
108
|
-
|
|
109
|
-
### Bad Tests (Implementation-Coupled)
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
// BAD: Tests implementation details
|
|
113
|
-
test("checkout calls paymentService.process", async () => {
|
|
114
|
-
const mockPayment = jest.mock(paymentService);
|
|
115
|
-
await checkout(cart, payment);
|
|
116
|
-
expect(mockPayment.process).toHaveBeenCalledWith(cart.total);
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Red flags:
|
|
121
|
-
|
|
122
|
-
- Mocking internal collaborators
|
|
123
|
-
- Testing private methods
|
|
124
|
-
- Asserting on call counts/order
|
|
125
|
-
- Test breaks when refactoring without behavior change
|
|
126
|
-
- Test name describes HOW not WHAT
|
|
127
|
-
- Verifying through external means instead of interface
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
// BAD: Bypasses interface to verify
|
|
131
|
-
test("createUser saves to database", async () => {
|
|
132
|
-
await createUser({ name: "Alice" });
|
|
133
|
-
const row = await db.query("SELECT * FROM users WHERE name = ?", ["Alice"]);
|
|
134
|
-
expect(row).toBeDefined();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// GOOD: Verifies through interface
|
|
138
|
-
test("createUser makes user retrievable", async () => {
|
|
139
|
-
const user = await createUser({ name: "Alice" });
|
|
140
|
-
const retrieved = await getUser(user.id);
|
|
141
|
-
expect(retrieved.name).toBe("Alice");
|
|
142
|
-
});
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
---
|
|
146
|
-
|
|
147
|
-
## When to Mock
|
|
148
|
-
|
|
149
|
-
Mock at **system boundaries** only:
|
|
150
|
-
|
|
151
|
-
- External APIs (payment, email, etc.)
|
|
152
|
-
- Databases (sometimes — prefer test DB)
|
|
153
|
-
- Time/randomness
|
|
154
|
-
- File system (sometimes)
|
|
155
|
-
|
|
156
|
-
Don't mock:
|
|
157
|
-
|
|
158
|
-
- Your own classes/modules
|
|
159
|
-
- Internal collaborators
|
|
160
|
-
- Anything you control
|
|
161
|
-
|
|
162
|
-
### Designing for Mockability
|
|
163
|
-
|
|
164
|
-
**1. Use dependency injection**
|
|
165
|
-
|
|
166
|
-
Pass external dependencies in rather than creating them internally:
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
// Easy to mock
|
|
170
|
-
function processPayment(order, paymentClient) {
|
|
171
|
-
return paymentClient.charge(order.total);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Hard to mock
|
|
175
|
-
function processPayment(order) {
|
|
176
|
-
const client = new StripeClient(process.env.STRIPE_KEY);
|
|
177
|
-
return client.charge(order.total);
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
**2. Prefer SDK-style interfaces over generic fetchers**
|
|
182
|
-
|
|
183
|
-
Create specific functions for each external operation instead of one generic function with conditional logic:
|
|
184
|
-
|
|
185
|
-
```typescript
|
|
186
|
-
// GOOD: Each function is independently mockable
|
|
187
|
-
const api = {
|
|
188
|
-
getUser: (id) => fetch(`/users/${id}`),
|
|
189
|
-
getOrders: (userId) => fetch(`/users/${userId}/orders`),
|
|
190
|
-
createOrder: (data) => fetch('/orders', { method: 'POST', body: data }),
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// BAD: Mocking requires conditional logic inside the mock
|
|
194
|
-
const api = {
|
|
195
|
-
fetch: (endpoint, options) => fetch(endpoint, options),
|
|
196
|
-
};
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
The SDK approach means:
|
|
200
|
-
- Each mock returns one specific shape
|
|
201
|
-
- No conditional logic in test setup
|
|
202
|
-
- Easier to see which endpoints a test exercises
|
|
203
|
-
- Type safety per endpoint
|
|
204
|
-
|
|
205
|
-
---
|
|
206
|
-
|
|
207
|
-
## Interface Design for Testability
|
|
208
|
-
|
|
209
|
-
Good interfaces make testing natural:
|
|
210
|
-
|
|
211
|
-
1. **Accept dependencies, don't create them**
|
|
212
|
-
|
|
213
|
-
```typescript
|
|
214
|
-
// Testable
|
|
215
|
-
function processOrder(order, paymentGateway) {}
|
|
216
|
-
|
|
217
|
-
// Hard to test
|
|
218
|
-
function processOrder(order) {
|
|
219
|
-
const gateway = new StripeGateway();
|
|
220
|
-
}
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
2. **Return results, don't produce side effects**
|
|
224
|
-
|
|
225
|
-
```typescript
|
|
226
|
-
// Testable
|
|
227
|
-
function calculateDiscount(cart): Discount {}
|
|
228
|
-
|
|
229
|
-
// Hard to test
|
|
230
|
-
function applyDiscount(cart): void {
|
|
231
|
-
cart.total -= discount;
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
3. **Small surface area**
|
|
236
|
-
- Fewer methods = fewer tests needed
|
|
237
|
-
- Fewer params = simpler test setup
|
|
238
|
-
|
|
239
|
-
---
|
|
240
|
-
|
|
241
|
-
## Deep Modules
|
|
242
|
-
|
|
243
|
-
From "A Philosophy of Software Design":
|
|
244
|
-
|
|
245
|
-
**Deep module** = small interface + lots of implementation
|
|
246
|
-
|
|
247
|
-
```
|
|
248
|
-
┌─────────────────────┐
|
|
249
|
-
│ Small Interface │ ← Few methods, simple params
|
|
250
|
-
├─────────────────────┤
|
|
251
|
-
│ │
|
|
252
|
-
│ │
|
|
253
|
-
│ Deep Implementation│ ← Complex logic hidden
|
|
254
|
-
│ │
|
|
255
|
-
│ │
|
|
256
|
-
└─────────────────────┘
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
**Shallow module** = large interface + little implementation (avoid)
|
|
260
|
-
|
|
261
|
-
```
|
|
262
|
-
┌─────────────────────────────────┐
|
|
263
|
-
│ Large Interface │ ← Many methods, complex params
|
|
264
|
-
├─────────────────────────────────┤
|
|
265
|
-
│ Thin Implementation │ ← Just passes through
|
|
266
|
-
└─────────────────────────────────┘
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
When designing interfaces, ask:
|
|
270
|
-
|
|
271
|
-
- Can I reduce the number of methods?
|
|
272
|
-
- Can I simplify the parameters?
|
|
273
|
-
- Can I hide more complexity inside?
|
|
274
|
-
|
|
275
|
-
---
|
|
276
|
-
|
|
277
|
-
## Refactor Candidates
|
|
278
|
-
|
|
279
|
-
After TDD cycle, look for:
|
|
280
|
-
|
|
281
|
-
- **Duplication** → Extract function/class
|
|
282
|
-
- **Long methods** → Break into private helpers (keep tests on public interface)
|
|
283
|
-
- **Shallow modules** → Combine or deepen
|
|
284
|
-
- **Feature envy** → Move logic to where data lives
|
|
285
|
-
- **Primitive obsession** → Introduce value objects
|
|
286
|
-
- **Existing code** the new code reveals as problematic
|
|
287
|
-
|
|
288
|
-
---
|
|
289
|
-
|
|
290
|
-
## context-mode Specific Rules
|
|
291
|
-
|
|
292
|
-
### CONTRIBUTING.md Is the Authority
|
|
293
|
-
|
|
294
|
-
**Read `CONTRIBUTING.md` before writing any test.** It defines:
|
|
295
|
-
- Test file organization (which file to put your test in)
|
|
296
|
-
- TDD workflow (Red-Green-Refactor)
|
|
297
|
-
- Output quality comparison (before/after)
|
|
298
|
-
- Local development setup
|
|
299
|
-
|
|
300
|
-
**Do NOT create new test files.** `CONTRIBUTING.md` has the complete test file mapping. Add your tests to the existing file that covers the same domain. If no file fits, ask the maintainer.
|
|
301
|
-
|
|
302
|
-
### CI Builds Bundles — You Don't
|
|
303
|
-
|
|
304
|
-
**Do NOT run `npm run build` or `npm run bundle`.** Bundle files (`server.bundle.mjs`, `cli.bundle.mjs`) are generated by GitHub CI automatically. Never create, modify, or push bundle files. You only run:
|
|
305
|
-
|
|
306
|
-
```bash
|
|
307
|
-
npm test # vitest — validates behavior
|
|
308
|
-
npm run typecheck # tsc --noEmit — validates types
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
That's it. No build. No bundle. CI handles the rest.
|
|
312
|
-
|
|
313
|
-
### TDD Enforcement in Subagents
|
|
314
|
-
|
|
315
|
-
Every Staff Engineer agent MUST include this in their prompt:
|
|
316
|
-
|
|
317
|
-
```
|
|
318
|
-
MANDATORY TDD — your work will be REJECTED without this:
|
|
319
|
-
1. Read CONTRIBUTING.md for test file organization — do NOT create new test files
|
|
320
|
-
2. Write a failing test FIRST in the correct existing test file
|
|
321
|
-
3. Run: npx vitest run tests/{file} — MUST FAIL
|
|
322
|
-
4. Write minimal code to pass
|
|
323
|
-
5. Run: npx vitest run tests/{file} — MUST PASS
|
|
324
|
-
6. Refactor if needed, tests stay green
|
|
325
|
-
7. Report RED→GREEN evidence:
|
|
326
|
-
"RED: test 'detects opencode via env var' — FAIL (expected)"
|
|
327
|
-
"GREEN: added env check in detect.ts — PASS"
|
|
328
|
-
Without this evidence, your PR is auto-rejected.
|
|
329
|
-
```
|