@boyingliu01/opencode-plugin 0.8.6 → 0.8.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,9 +4,21 @@ OpenCode plugin exposing xp-gate quality gates and AI workflow skills.
4
4
 
5
5
  ## Tools
6
6
 
7
- - **gate-check**: Run all 6 quality gates on a file/directory
8
- - **gate-principles**: Run Clean Code + SOLID principles checker
9
- - **gate-arch**: Run architecture validation
7
+ These three tools are **dual-surface**: callable both as OpenCode tools (from
8
+ inside an OpenCode session) and as `xp-gate` CLI subcommands (from any shell).
9
+ Both paths produce identical output. See repo README for the matching CLI table.
10
+
11
+ - **gate-check** ⇄ `xp-gate check <path>`: Run user-invokable quality gates
12
+ (Gate 4 Principles + Gate 6 Architecture) on a file or directory.
13
+ - **gate-principles** ⇄ `xp-gate principles <path>`: Run Clean Code + SOLID
14
+ principles checker (Gate 4 standalone).
15
+ - **gate-arch** ⇄ `xp-gate arch`: Run architecture validation (Gate 6
16
+ standalone, layer boundary checks).
17
+
18
+ > Earlier docs said "all 6 quality gates" — that was inaccurate. `gate-check`
19
+ > intentionally runs only the two user-invokable gates (Principles + Arch); the
20
+ > full 10-gate pre-commit suite (Gate 0-9) is enforced by `xp-gate init`'s git
21
+ > hooks, not by this tool. Fixes #208.
10
22
 
11
23
  ## Installation
12
24
 
@@ -29,10 +41,14 @@ Or via local path (development):
29
41
  ## Requirements
30
42
 
31
43
  - OpenCode v0.11+
32
- - xp-gate npm package installed globally (for `gate-check` tool)
33
- - Repository with `src/principles/index.ts` (for `gate-principles` tool)
34
- - `architecture.yaml` in repo root (for `gate-arch` tool)
44
+ - One of:
45
+ - `xp-gate` CLI installed globally (`npm install -g @boyingliu01/xp-gate`) — **preferred**, or
46
+ - the xp-gate repo checked out locally with `src/principles/index.ts` reachable **fallback** (the tool will shell out via `npx -y tsx`)
47
+ - `architecture.yaml` in repo root (for `gate-arch` only)
35
48
 
36
49
  ## Graceful Degradation
37
50
 
38
- If xp-gate CLI is unavailable, tools return helpful install instructions instead of failing.
51
+ Every tool runs a chained shell-out: it first tries `xp-gate <subcommand>` and,
52
+ only if that's not on `PATH`, falls back to invoking the underlying checker
53
+ source directly. If both paths fail, the tool returns install instructions
54
+ instead of throwing.
package/index.ts CHANGED
@@ -1,75 +1,91 @@
1
1
  /**
2
2
  * XP-Gate OpenCode Plugin
3
3
  *
4
- * Exposes 3 custom tools for OpenCode users:
5
- * - gate-check: Run all xp-gate quality checks on a file or directory
6
- * - gate-principles: Run Clean Code + SOLID principles checker
7
- * - gate-arch: Run architecture validation
4
+ * Exposes 3 OpenCode tools that mirror the equivalent `xp-gate` CLI subcommands:
5
+ * - gate-check: Run user-invokable quality gates (Gate 4 Principles + Gate 6 Arch) on a path
6
+ * - gate-principles: Run Clean Code + SOLID principles checker (Gate 4 standalone)
7
+ * - gate-arch: Run architecture validation (Gate 6 standalone)
8
8
  *
9
- * Graceful degradation: if xp-gate CLI not installed, tools return install instructions.
9
+ * Dual-surface design (fixes #208): every tool is callable BOTH from inside an
10
+ * OpenCode session (as these tools) AND from a plain shell (as `xp-gate check`,
11
+ * `xp-gate principles`, `xp-gate arch`). The tools prefer the global `xp-gate`
12
+ * CLI when available, but fall back to running the checker source directly via
13
+ * `npx -y tsx` so they work even before `npm install -g @boyingliu01/xp-gate`.
10
14
  */
11
- import type { Plugin, PluginModule } from "@opencode-ai/plugin"
12
15
  import { tool } from "@opencode-ai/plugin"
13
16
  import { z } from "zod"
14
17
 
15
- export const XpGatePlugin: Plugin = async (input) => {
18
+ interface OpenCodePluginInput {
19
+ directory: string
20
+ $: (strings: TemplateStringsArray, ...values: unknown[]) => Promise<{ text(): Promise<string> }>
21
+ }
22
+
23
+ export const XpGatePlugin = async (input: OpenCodePluginInput) => {
16
24
  const { directory, $ } = input
17
25
 
18
26
  return {
19
27
  tool: {
20
28
  "gate-check": tool({
21
29
  description:
22
- "Run xp-gate quality checks on a file or directory. Requires xp-gate CLI installed globally.",
30
+ "Run xp-gate user-invokable quality gates (Gate 4 Principles + Gate 6 Architecture) on a file or directory. Prefers global xp-gate CLI; falls back to running checker source directly.",
23
31
  args: {
24
32
  path: z.string().describe("File or directory path (absolute or relative to workspace)"),
25
- gates: z.array(z.string()).optional().describe("Optional gate subset (e.g. ['principles', 'tests'])"),
33
+ gates: z.array(z.string()).optional().describe("Optional gate subset (e.g. ['principles', 'arch'])"),
26
34
  },
27
35
  async execute(args, ctx) {
28
36
  const cwd = ctx.directory || directory
29
37
  const target = args.path.startsWith("/") ? args.path : `${cwd}/${args.path}`
30
- const gates = args.gates?.length ? ` --gates ${args.gates.join(",")}` : ""
38
+ const gatesFlag = args.gates?.length ? ` --gates ${args.gates.join(",")}` : ""
39
+ // Prefer the installed xp-gate CLI. Fall back to invoking the same
40
+ // subcommand source directly via npx tsx so the tool still works in
41
+ // a fresh clone before `npm install -g @boyingliu01/xp-gate`.
42
+ const cmd = `cd "${cwd}" && (command -v xp-gate >/dev/null 2>&1 && xp-gate check "${target}"${gatesFlag} || node ${directory}/src/npm-package/bin/xp-gate.js check "${target}"${gatesFlag})`
31
43
  try {
32
- const result = await $`bash -c ${`cd "${cwd}" && command -v xp-gate >/dev/null 2>&1 && xp-gate check "${target}"${gates}`}`
44
+ const result = await $`bash -c ${cmd}`
33
45
  const text = await result.text()
34
- return text || "[XP-Gate] Check complete."
35
- } catch (err: unknown) {
36
- return `[XP-Gate] xp-gate CLI not found.\nInstall: npm install -g @boyingliu01/xp-gate\n${err instanceof Error ? err.message : ""}`
46
+ return text || "[XP-Gate] Check complete (no violations)."
47
+ } catch (err) {
48
+ return `[XP-Gate] gate-check failed.\nInstall xp-gate CLI: npm install -g @boyingliu01/xp-gate\n${err instanceof Error ? err.message : ""}`
37
49
  }
38
50
  },
39
51
  }),
40
52
  "gate-principles": tool({
41
53
  description:
42
- "Run Clean Code + SOLID principles checker on a file.",
54
+ "Run Clean Code + SOLID principles checker (Gate 4 standalone) on a file or directory.",
43
55
  args: {
44
- path: z.string().describe("Source file path to check"),
56
+ path: z.string().describe("Source file or directory path to check"),
45
57
  },
46
58
  async execute(args, ctx) {
47
59
  const cwd = ctx.directory || directory
48
60
  const target = args.path.startsWith("/") ? args.path : `${cwd}/${args.path}`
49
- const cmd = `cd "${cwd}" && npx -y tsx src/principles/index.ts --files "${target}" --format console`
61
+ // Try xp-gate CLI first, fall back to the principles source directly.
62
+ const cmd = `cd "${cwd}" && (command -v xp-gate >/dev/null 2>&1 && xp-gate principles "${target}" || npx -y tsx ${directory}/src/principles/index.ts --files "${target}" --format console)`
50
63
  try {
51
64
  const result = await $`bash -c ${cmd}`
52
65
  const text = await result.text()
53
- return text || "[XP-Gate] Principles check complete."
54
- } catch (err: unknown) {
55
- return `[XP-Gate] Principles checker failed.\nEnsure src/principles/index.ts exists.\n${err instanceof Error ? err.message : ""}`
66
+ return text || "[XP-Gate] Principles check complete (no violations)."
67
+ } catch (err) {
68
+ return `[XP-Gate] Principles checker failed.\nInstall xp-gate CLI: npm install -g @boyingliu01/xp-gate\n${err instanceof Error ? err.message : ""}`
56
69
  }
57
70
  },
58
71
  }),
59
72
  "gate-arch": tool({
60
73
  description:
61
- "Run architecture validation (layer boundary checks) on the repository.",
74
+ "Run architecture validation (Gate 6 standalone, layer boundary checks) on the repository.",
62
75
  args: {
63
76
  config: z.string().describe("Path to architecture config file").default("architecture.yaml"),
64
77
  },
65
78
  async execute(args, ctx) {
66
79
  const cwd = ctx.directory || directory
80
+ // Prefer xp-gate CLI; fall back to @archlinter/cli directly so the tool
81
+ // also works without xp-gate installed (matches gate-principles pattern).
82
+ const cmd = `cd "${cwd}" && (command -v xp-gate >/dev/null 2>&1 && xp-gate arch --config ${args.config} || npx -y @archlinter/cli scan . --config ${args.config})`
67
83
  try {
68
- const result = await $`bash -c ${`cd "${cwd}" && npx archlint check --config ${args.config}`}`
84
+ const result = await $`bash -c ${cmd}`
69
85
  const text = await result.text()
70
86
  return text || "[XP-Gate] Architecture check complete."
71
- } catch (err: unknown) {
72
- return `[XP-Gate] Architecture validation requires archlint + ${args.config}.\n${err instanceof Error ? err.message : ""}`
87
+ } catch (err) {
88
+ return `[XP-Gate] Architecture validation failed.\nRequires architecture.yaml in repo root.\nInstall xp-gate CLI: npm install -g @boyingliu01/xp-gate\n${err instanceof Error ? err.message : ""}`
73
89
  }
74
90
  },
75
91
  }),
@@ -77,7 +93,7 @@ export const XpGatePlugin: Plugin = async (input) => {
77
93
  }
78
94
  }
79
95
 
80
- const pluginModule: PluginModule = {
96
+ const pluginModule = {
81
97
  id: "xp-gate",
82
98
  server: XpGatePlugin,
83
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/opencode-plugin",
3
- "version": "0.8.6",
3
+ "version": "0.8.10",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "XP-Gate quality gates + AI workflow skills for OpenCode",
@@ -1,12 +1,12 @@
1
1
  # SKILLS/DELPHI-REVIEW KNOWLEDGE BASE
2
2
 
3
- **Generated:** 2026-05-30
4
- **Commit:** 4517f2b
3
+ **Generated:** 2026-06-14
4
+ **Commit:** e215a50
5
5
  **Branch:** main
6
- **Version:** v0.8.1
6
+ **Version:** 0.8.10.0
7
7
 
8
8
  ## OVERVIEW
9
- Delphi Consensus Review — multi-round anonymous expert review (≥91% threshold, 3 experts from ≥2 providers, domestic models only). Supports design + code-walkthrough modes.
9
+ Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, 3 experts from ≥2 providers, domestic models only). Supports design + code-walkthrough modes.
10
10
 
11
11
  ## STRUCTURE
12
12
  ```
@@ -30,7 +30,7 @@ skills/delphi-review/
30
30
 
31
31
  ## CONVENTIONS
32
32
  - 3 experts anonymous in Round 1 (no cross-expert bias)
33
- - ≥91% consensus threshold (was 95%, lowered to 91%)
33
+ - ≥90% consensus threshold (was 95%, now unified to 90%)
34
34
  - Max 5 rounds before forcing decision
35
35
  - Cross-provider required: experts from ≥2 different providers
36
36
  - Domestic models only: glm, kimi, minimax, qwen, deepseek
@@ -39,7 +39,7 @@ skills/delphi-review/
39
39
  - Code-walkthrough skipped on main/master pushes (by design)
40
40
 
41
41
  ## ANTI-PATTERNS (THIS PROJECT)
42
- - Do NOT terminate before achieving true consensus (≥91%)
42
+ - Do NOT terminate before achieving true consensus (≥90%)
43
43
  - Do NOT reveal other experts' opinions during Round 1
44
44
  - Do NOT accept partial agreement without resolution
45
45
  - Do NOT skip code-walkthrough when over thresholds (BLOCK + user decision)
@@ -49,7 +49,7 @@ skills/delphi-review/
49
49
 
50
50
  ## UNIQUE STYLES
51
51
  - Anonymous expert reviews (Round 1)
52
- - Statistical consensus measurement (≥91% threshold)
52
+ - Statistical consensus measurement (≥90% threshold)
53
53
  - Two modes: design review + code-walkthrough
54
54
  - Pre-push integration: .code-walkthrough-result.json stores commit hash + verdict
55
55
  - Delphi guard in claude-code plugin: blocks Edit/Write before APPROVAL
@@ -96,7 +96,7 @@ The skill requires at least 2 experts for code changes, 3 for architecture decis
96
96
  | `experts.architecture` | Architecture reviewer configuration | Required |
97
97
  | `experts.technical` | Technical reviewer configuration | Required |
98
98
  | `experts.feasibility` | Feasibility reviewer configuration | Required for 3-expert mode |
99
- | `consensus.threshold_percent` | Agreement threshold | 95 |
99
+ | `consensus.threshold_percent` | Agreement threshold | 90 |
100
100
  | `consensus.max_review_rounds` | Maximum review rounds | 5 |
101
101
  | `consensus.cross_provider_required` | Require different providers | true |
102
102
 
@@ -9,7 +9,7 @@ description: "Use when asked to review a design, plan, or architecture; before i
9
9
 
10
10
  **In Scope:**
11
11
  - Multi-round anonymous expert consensus review (design + code-walkthrough modes)
12
- - 2-3 experts from different providers with statistical consensus (>= 91%)
12
+ - 2-3 experts from different providers with statistical consensus (>= 90%)
13
13
  - Structured verdict: APPROVED / PASS_WITH_CAVEATS / REQUEST_CHANGES
14
14
  - Domestic models only (no Anthropic/OpenAI/Google)
15
15
 
@@ -27,7 +27,7 @@ description: "Use when asked to review a design, plan, or architecture; before i
27
27
  1. **匿名性** — Round 1 专家互不知道对方意见
28
28
  2. **迭代** — 多轮直到共识,不是固定轮数
29
29
  3. **受控反馈** — 每轮看到其他专家意见
30
- 4. **统计共识** — >=91% 一致才算共识
30
+ 4. **统计共识** — >=90% 一致才算共识
31
31
 
32
32
  ### 质量优先
33
33
 
@@ -95,7 +95,7 @@ description: "Use when asked to review a design, plan, or architecture; before i
95
95
 
96
96
  | 阈值 | 说明 |
97
97
  |------|------|
98
- | **>=91%** | 推荐默认 |
98
+ | **>=90%** | 推荐默认 |
99
99
  | 100% | 完全一致(更严格) |
100
100
 
101
101
  ---
@@ -105,14 +105,14 @@ description: "Use when asked to review a design, plan, or architecture; before i
105
105
  ```
106
106
  Phase 0: 准备 → Round 1: 匿名独立评审 → 共识检查
107
107
 
108
- ├─ 一致 + >=91% + APPROVED → ✅ 完成
108
+ ├─ 一致 + >=90% + APPROVED → ✅ 完成
109
109
 
110
- └─ 不一致 或 <91% 或 REQUEST_CHANGES
110
+ └─ 不一致 或 <90% 或 REQUEST_CHANGES
111
111
 
112
112
 
113
113
  Round 2: 交换意见 → 共识检查
114
114
 
115
- ├─ 一致 + >=91% + APPROVED → ✅ 完成
115
+ ├─ 一致 + >=90% + APPROVED → ✅ 完成
116
116
 
117
117
  └─ 仍分歧 或 REQUEST_CHANGES
118
118
 
@@ -248,11 +248,11 @@ This skill activates on any request for multi-expert review. Common triggers:
248
248
  2. **Dispatch anonymous experts** - 2-3 experts from ≥2 different domestic model providers
249
249
  3. **Collect Round 1 independent reviews** - Anonymous, no cross-expert bias
250
250
  4. **Synthesize feedback** - Measure consensus, identify disagreements
251
- 5. **Run Round 2+ until consensus** - Exchange opinions, iterate until ≥91% agreement
251
+ 5. **Run Round 2+ until consensus** - Exchange opinions, iterate until ≥90% agreement
252
252
  6. **Block on unresolved Critical/Major** - Zero-tolerance: all Critical/Major must be resolved
253
253
  7. **Emit verdict** - APPROVED (with specification.yaml) or REQUEST_CHANGES (fix + re-review)
254
254
 
255
- **Consensus threshold:** ≥91% (project standard for Delphi review approval)
255
+ **Consensus threshold:** ≥90% (project standard for Delphi review approval)
256
256
  **Model policy:** Domestic models only (DeepSeek, Qwen, Kimi, GLM, MiniMax). Foreign models (Anthropic/OpenAI/Google) forbidden.
257
257
 
258
258
  ---
@@ -340,7 +340,7 @@ Every review round output MUST follow this exact JSON structure for design mode:
340
340
  - [ ] Round 2+ 完成(交换意见 / 最终立场)
341
341
 
342
342
  **CRITICAL — 共识验证:**
343
- - [ ] 问题共识比例 >=91%
343
+ - [ ] 问题共识比例 >=90%
344
344
  - [ ] 所有 Critical Issues 已解决
345
345
  - [ ] 所有 Major Concerns 已处理
346
346
 
@@ -422,7 +422,7 @@ Every review round output MUST follow this exact JSON structure for design mode:
422
422
  | 只处理 Critical,忽略 Major | 零容忍:Critical/Major 全部必须处理,不可跳过或降级 |
423
423
  | 单专家自评 | 至少 2 位不同 provider 的专家 |
424
424
  | 用户说"时间紧急"就跳过 | 评审是投资不是开销,跳过后期返工成本更高 |
425
- | "专家几乎一致"就通过 | "几乎" = 不一致,继续到 >=91% |
425
+ | "专家几乎一致"就通过 | "几乎" = 不一致,继续到 >=90% |
426
426
  | 使用 Anthropic/GPT/Gemini 等国外昂贵模型 | 必须使用国产开源模型(DeepSeek, Qwen, Kimi, GLM, MiniMax) |
427
427
  | 三个专家使用同一厂家模型 | 必须来自至少 2 家不同厂家 |
428
428
 
@@ -437,7 +437,7 @@ Every review round output MUST follow this exact JSON structure for design mode:
437
437
  | "这只是小变更" | 所有变更都需要评审 |
438
438
  | "Round 1 就够了" | 不够,必须多轮直到共识 |
439
439
  | "生成报告就完成了" | APPROVED 才算完成 |
440
- | "2/3 同意就是共识" | 还要检查问题共识比例 >=91% |
440
+ | "2/3 同意就是共识" | 还要检查问题共识比例 >=90% |
441
441
 
442
442
  ---
443
443
 
@@ -445,7 +445,7 @@ Every review round output MUST follow this exact JSON structure for design mode:
445
445
 
446
446
  **Delphi 评审完成的唯一标准:**
447
447
  1. ✅ 所有专家裁决 APPROVED
448
- 2. ✅ 问题共识 >=91%
448
+ 2. ✅ 问题共识 >=90%
449
449
  3. ✅ 所有 Critical Issues 已修复验证
450
450
  4. ✅ 所有 Major Concerns 已处理
451
451
  5. ✅ 共识报告已生成
@@ -393,7 +393,7 @@ IF 任何检查失败:
393
393
  | `confidence` | number | 整体置信度 (1-10) |
394
394
  | `experts` | array | 专家评审结果 |
395
395
  | `issues` | array | 未解决的问题(如有) |
396
- | `consensus_ratio` | number | 问题共识比例 (≥0.95 为共识) |
396
+ | `consensus_ratio` | number | 问题共识比例 (≥0.90 为共识) |
397
397
 
398
398
  **有效期机制**:
399
399
 
@@ -1,68 +1,115 @@
1
1
  # SKILLS/SPRINT-FLOW KNOWLEDGE BASE
2
2
 
3
- **Generated:** 2026-05-30
4
- **Version:** v0.8.1
3
+ **Generated:** 2026-06-14
4
+ **Commit:** e215a50
5
+ **Branch:** main
6
+ **Version:** 0.8.10.0
5
7
 
6
8
  ## OVERVIEW
7
- 7-phase development pipeline: THINK→PLAN→BUILD→REVIEW→USER ACCEPT→FEEDBACK→SHIP, with ralph-loop default build mode.
9
+ **11-phase** development pipeline: ISOLATE → AUTO-ESTIMATE → THINK PLAN BUILD REVIEW USER ACCEPTANCE FEEDBACK SHIP LAND → CLEANUP. Phase 2 default build mode is **ralph-loop** (REQ-level iteration, 40-67% token savings vs parallel). HARD-GATE in Phase 1: design must pass Delphi review (≥90% consensus) before any coding.
10
+
11
+ > **Doc drift**: README/CAPABILITIES still describe a "7-phase" pipeline. The canonical 11-phase model lives in `SKILL.md` and is what actually executes. See root `AGENTS.md` → "Known Drift" #4.
8
12
 
9
13
  ## STRUCTURE
10
14
  ```
11
15
  skills/sprint-flow/
12
- ├── SKILL.md # 7-phase pipeline definition
16
+ ├── SKILL.md # 11-phase pipeline definition (canonical)
17
+ ├── AGENTS.md # This file (mirrored to 7 other locations — DO NOT edit mirrors)
13
18
  ├── evals/ # Evaluation test cases
14
- ├── evolution-history.json # Skill evolution tracking
15
- ├── evolution-log.md # Change history
16
- ├── references/ # Phase reference docs
17
- │ ├── phase-0-think.md # THINK phase guidelines
18
- └── ... # Other phase docs
19
- └── templates/ # Sprint templates
19
+ ├── evolution-history.json
20
+ ├── evolution-log.md
21
+ ├── references/
22
+ │ ├── phase-minus-0-5-auto-estimate.md # Phase -0.5: AUTO-ESTIMATE
23
+ ├── phase-0-think.md # Phase 0: brainstorming → CONTEXT.md + ADR
24
+ │ ├── phase-1-plan.md # Phase 1: autoplan + delphi-review (HARD-GATE)
25
+ │ ├── phase-2-build.md # Phase 2: ralph-loop default + TDD + test-align
26
+ │ ├── phase-3-review.md # Phase 3: code-walkthrough + QA + benchmark
27
+ │ ├── phase-4-uat.md # Phase 4: USER ACCEPTANCE
28
+ │ ├── phase-5-feedback.md # Phase 5: retro + debugging + learn
29
+ │ ├── phase-6-ship.md # Phase 6: finishing-dev-branch + PR
30
+ │ ├── phase-7-land.md # Phase 7: land + deploy
31
+ │ ├── phase-8-cleanup.md # Phase 8: sprint branch cleanup
32
+ │ ├── force-levels.md # Phase forcing rules
33
+ │ └── components/ # Reusable phase building blocks
34
+ └── templates/
35
+ ├── auto-estimate-output-template.md
36
+ ├── auto-estimate-learning-log.md
37
+ ├── pain-document-template.md
38
+ ├── sprint-progress-template.md
39
+ ├── sprint-summary-template.md
40
+ └── emergent-issues-template.md
20
41
  ```
21
42
 
22
43
  ## WHERE TO LOOK
23
44
  | Task | Location | Notes |
24
45
  |------|----------|-------|
25
- | Pipeline def | SKILL.md | 7 phases with hard gates |
46
+ | Pipeline definition | SKILL.md | 11 phases with HARD-GATE between Phase 1 and Phase 2 |
47
+ | Auto-estimate phase | references/phase-minus-0-5-auto-estimate.md | Sizing pass before THINK |
26
48
  | THINK phase | references/phase-0-think.md | brainstorming → CONTEXT.md + ADR |
27
- | Build mode | SKILL.md | ralph-loop (default) vs parallel |
49
+ | PLAN phase + HARD-GATE | references/phase-1-plan.md | autoplan → delphi-review specification.yaml |
50
+ | BUILD phase | references/phase-2-build.md | ralph-loop (default) vs parallel |
51
+ | Force-level rules | references/force-levels.md | Defines when each phase becomes mandatory |
52
+ | Templates | templates/ | Auto-estimate, sprint progress/summary, pain doc, emergent issues |
53
+
54
+ ## THE 11 PHASES
28
55
 
29
- ## 7 PHASES
30
56
  | Phase | Name | Key Action | Hard Gate |
31
57
  |-------|------|-----------|-----------|
32
- | 0 | THINK | brainstorming, CONTEXT.md, ADR | — |
33
- | 1 | PLAN | autoplan delphi-review specification.yaml | HARD-GATE: design must pass |
34
- | 2 | BUILD | ralph-loop (REQ-level iteration) + TDD + test-align | — |
58
+ | -1 | ISOLATE | Isolate working tree / worktree creation | — |
59
+ | -0.5 | AUTO-ESTIMATE | Sizing pass; emits estimate template | |
60
+ | 0 | THINK | brainstorming CONTEXT.md + ADR | — |
61
+ | 1 | PLAN | autoplan → delphi-review → specification.yaml | **HARD-GATE**: design must reach ≥90% Delphi consensus |
62
+ | 2 | BUILD | ralph-loop (REQ-level, default) + TDD + test-spec-alignment | — |
35
63
  | 3 | REVIEW | code-walkthrough + QA + benchmark | — |
36
- | 4 | USER ACCEPT | Manual verification | — |
37
- | 5 | FEEDBACK | Retro + debugging + learn | — |
38
- | 6 | SHIP | finishing-dev-branch + PR/merge | — |
64
+ | 4 | USER ACCEPTANCE | Manual verification | — |
65
+ | 5 | FEEDBACK | retro + debugging + `learn` (Sprint-level) | — |
66
+ | 6 | SHIP | finishing-a-development-branch PR | — |
67
+ | 7 | LAND | land + deploy + canary | — |
68
+ | 8 | CLEANUP | Sprint branch cleanup (per `docs/plans/2026-06-06-sprint-branch-cleanup-design.md`) | — |
39
69
 
40
70
  ## CONVENTIONS
41
- - ralph-loop is Phase 2 **default** mode (saves 40-67% tokens vs parallel)
42
- - delphi-review HARD-GATE in Phase 1: design unapproved → BLOCK coding
43
- - Each REQ in ralph-loop gets clean context (no linear accumulation)
44
- - `learn` called at Phase 5 + each REQ completion
71
+ - **ralph-loop is Phase 2 default**. Each REQ runs in a clean context (no linear accumulation), saving 40-67% tokens vs parallel mode.
72
+ - **delphi-review HARD-GATE in Phase 1**: design must reach ≥90% consensus across ≥2 model providers, domestic models only. Unapproved → BLOCK coding.
73
+ - **`learn` is called twice**: once per REQ in Phase 2 (ralph-loop internal, `progress.log` permanent/contextual classification) and once in Phase 5 (Sprint-level retro).
74
+ - **Phase isolation**: each phase has explicit entry/exit criteria documented in its `references/phase-*.md` file.
75
+ - **Emergent Requirements** discovered in Phase 4 (USER ACCEPTANCE) are explicitly captured via `templates/emergent-issues-template.md` — never silently merged.
76
+ - **Auto-detection**: Phase 0 uses `src/npm-package/lib/ui-detector.ts` to pick the right tech-stack templates.
45
77
 
46
78
  ## ANTI-PATTERNS (THIS PROJECT)
47
- - Do NOT skip delphi-review in Phase 1 — HARD-GATE blocks implementation
48
- - Do NOT use parallel build mode unless explicitly requested
49
- - Do NOT enter Phase 1 (PLAN) without completing THINK phase
50
- - DO NOT implement before design approval
79
+ - Do NOT skip `delphi-review` in Phase 1 — HARD-GATE blocks implementation.
80
+ - Do NOT use parallel build mode unless explicitly requested. Ralph-loop is the default for a reason.
81
+ - Do NOT enter Phase 1 (PLAN) without completing Phase 0 (THINK).
82
+ - Do NOT implement before design is APPROVED — Phase 1 must reach Delphi consensus first.
83
+ - Do NOT merge an Emergent Requirement into the original Sprint silently — capture it via the template.
84
+ - Do NOT terminate Delphi review before ≥90% consensus or 5 rounds, whichever first.
51
85
 
52
86
  ## UNIQUE STYLES
53
- - Auto-detects UI framework (ui-detector.ts in npm-package/lib/)
54
- - Supports --type and --lang flags for tech stack selection
55
- - Phase isolation: each phase has specific entry/exit criteria
56
- - Emergent Requirements acknowledged: user acceptance phase built in
87
+ - **11 phases** including negative-numbered pre-phases (-1, -0.5) intentional, captures the work that happens before "real" coding starts.
88
+ - **HARD-GATE** between PLAN and BUILD is enforced both in the SKILL.md instructions and in the Claude Code plugin's PreToolUse hook (`plugins/claude-code/bin/delphi-review-guard.sh`).
89
+ - **Per-REQ clean context in ralph-loop** = the core efficiency mechanism. Sprint-flow specifically chooses this over parallel mode.
90
+ - **Tech-stack auto-detection** via `--type` and `--lang` flags or `ui-detector.ts`.
57
91
 
58
92
  ## COMMANDS
59
93
  ```bash
94
+ /sprint-flow "开发用户登录" # Full 11-phase pipeline
95
+ /sprint-flow "开发用户登录" --type web-nextjs --lang typescript # Pin tech stack
96
+ /sprint-flow "开发用户登录" --phase build-only # Skip planning (advanced)
97
+ /sprint-flow "开发用户登录" --mode parallel # Legacy all-at-once (NOT default)
60
98
  /delphi-review "开发用户登录" --type web-nextjs --lang typescript
61
- /sprint-flow "开发用户登录" --phase build-only
62
- /sprint-flow "开发用户登录" --mode parallel # Legacy all-at-once
63
99
  ```
64
100
 
65
101
  ## NOTES
66
- - Integrates brainstorming, autoplan, delphi-review, TDD, test-specification-alignment
67
- - ralph-loop internal learnings via progress.log (permanent/contextual classification)
68
- - Phase 5 calls gstack/learn for Sprint-level retrospective
102
+ - Integrates: brainstorming, autoplan, delphi-review, TDD, test-specification-alignment, qa, design-review, benchmark, systematic-debugging, retro, learn, finishing-a-development-branch.
103
+ - ralph-loop's internal learnings are persisted via `progress.log` (permanent vs contextual classification).
104
+ - Phase 5 calls `gstack/learn` for Sprint-level retrospective.
105
+ - Phase 8 cleanup behavior is governed by `docs/plans/2026-06-06-sprint-branch-cleanup-design.md`.
106
+ - This `AGENTS.md` is the canonical version. **7 byte-identical mirrors** exist at:
107
+ - `plugins/claude-code/skills/sprint-flow/AGENTS.md`
108
+ - `plugins/opencode/skills/sprint-flow/AGENTS.md`
109
+ - `plugins/qoder/skills/sprint-flow/AGENTS.md`
110
+ - `src/npm-package/skills/sprint-flow/AGENTS.md`
111
+ - `src/npm-package/plugins/claude-code/skills/sprint-flow/AGENTS.md`
112
+ - `src/npm-package/plugins/opencode/skills/sprint-flow/AGENTS.md`
113
+ - `src/npm-package/plugins/qoder/skills/sprint-flow/AGENTS.md`
114
+ Mirrors are updated by `scripts/copy-skills.sh`. Do NOT edit them by hand.
115
+
@@ -247,7 +247,7 @@ ISOLATE → AUTO-ESTIMATE → THINK → PLAN → [GITHOOKS-GATE] → BUILD → R
247
247
  ```
248
248
 
249
249
  **Hard Gates**:
250
- - **Phase 0→1**: Design must be APPROVED by delphi-review (≥91% consensus)
250
+ - **Phase 0→1**: Design must be APPROVED by delphi-review (≥90% consensus)
251
251
  - **Phase 1→2**: GITHOOKS-GATE (hooks must be installed) + DELPHI-GATE (spec must be APPROVED)
252
252
  - **Phase 4→5**: User acceptance must be completed (mandatory manual step)
253
253
  - **Phase 5→6**: feedback-log.md must exist (HARD-GATE)
@@ -98,7 +98,7 @@ AUTO-ESTIMATE 输出 → Force Levels 执行 → 自动升级机制(如触发
98
98
 
99
99
  | 场景 | DELPHI-GATE | Force Levels |
100
100
  |------|------------|-------------|
101
- | Phase 1 设计评审 | 3 专家、≥95% 共识、生成 specification.yaml | 不适用(设计阶段) |
101
+ | Phase 1 设计评审 | 3 专家、≥90% 共识、生成 specification.yaml | 不适用(设计阶段) |
102
102
  | Phase 2 BUILD 入口 | **必须检查** `.sprint-state/delphi-reviewed.json` 中 `verdict=APPROVED` | 轻量/标准/复杂:通过对应强度的 delphi-review 生成该门禁文件 |
103
103
  | 轻量级评审 | 生成 `delphi-reviewed.json`(2 专家、1 轮、2/2 批准) | 2 专家、1 轮、写入门禁文件 |
104
104
  | 标准级评审 | 生成 `delphi-reviewed.json`(2 专家、最多 2 轮、2/2 批准) | 2 专家、最多 2 轮、写入门禁文件 |
@@ -11,7 +11,7 @@ Web 前端项目额外增加:系统化 QA、视觉审计、性能基线。
11
11
  ## 调用 Skills
12
12
 
13
13
  **所有项目**:
14
- - `delphi-review --mode code-walkthrough` — 多专家匿名代码走查(2-3 domestic models, >=95% consensus)
14
+ - `delphi-review --mode code-walkthrough` — 多专家匿名代码走查(2-3 domestic models, ≥90% consensus)
15
15
  - `test-specification-alignment` — 测试与 Spec 对齐验证
16
16
  - `browse` (gstack) — 浏览器自动化测试
17
17
 
@@ -43,7 +43,7 @@ delphi code-walkthrough 执行:
43
43
  - Round 1: 匿名独立评审(防止 anchoring bias)
44
44
  - Round 2: 交换意见,响应关切
45
45
  - Round 3: 最终立场(如需)
46
- - >=95% 共识 + APPROVED 才通过
46
+ - ≥90% 共识 + APPROVED 才通过
47
47
 
48
48
  **如果 REQUEST_CHANGES**:
49
49
  - ⚠️ 暂停等待用户修复 Critical Issues + 处理 Major Concerns
@@ -1,71 +1,371 @@
1
1
  ---
2
2
  name: test-driven-development
3
- description: >
4
- Test-Driven Development enforcement: RED → GREEN → REFACTOR cycle.
5
- Write failing test first, then minimum code to pass, then refactor.
6
- Includes Mock Usage Guidelines for integration-first testing.
7
-
8
- maturity: stable
3
+ description: Use when implementing any feature or bugfix, before writing implementation code
9
4
  ---
10
5
 
11
- # Test-Driven Development
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];
12
58
 
13
- ## Core Principles
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.
14
74
 
15
- | Principle | Description |
16
- |-----------|-------------|
17
- | **RED First** | Write a failing test before ANY implementation code |
18
- | **GREEN Minimum** | Write minimum code to pass the test — no extra features |
19
- | **REFACTOR** | Clean up code while keeping tests green |
20
- | **Delete & Restart** | If you write code before test — delete it and start over |
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
+ };
21
84
 
22
- ## Workflow
85
+ const result = await retryOperation(operation);
23
86
 
87
+ expect(result).toBe('success');
88
+ expect(attempts).toBe(3);
89
+ });
24
90
  ```
25
- 1. RED: Write failing test (describe/it + expect)
26
- 2. GREEN: Write minimum implementation to pass
27
- 3. REFACTOR: Clean up, extract, simplify — tests stay green
28
- 4. Repeat for next behavior
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
+ });
29
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.
30
182
 
31
- ## Mock Usage Guidelines (MANDATORY)
183
+ **Other tests fail?** Fix now.
32
184
 
33
- ### When to use mocks (ONLY these cases):
34
- 1. External API/HTTP calls — use testcontainers or nock
35
- 2. Database I/O — use in-memory DB (sqlite, testcontainers)
36
- 3. File system I/O — use tmpdir / memfs
37
- 4. Time-dependent code — inject clock dependency
38
- 5. Non-deterministic behavior (random, UUID) — inject dependency
185
+ ### REFACTOR - Clean Up
39
186
 
40
- ### When NOT to use mocks:
41
- - Pure business logic → test with real values
42
- - In-memory data transformations → test with real data
43
- - Validation logic → test with real input/output
44
- - State machines → test with real state transitions
187
+ After green only:
188
+ - Remove duplication
189
+ - Improve names
190
+ - Extract helpers
45
191
 
46
- ### Mock Density Rule:
47
- If > 30% of test lines contain mock/spy/fn references,
48
- you are likely over-mocking. Add `// @mock-justified: <reason>` comment
49
- explaining why integration test is not feasible.
192
+ Keep tests green. Don't add behavior.
50
193
 
51
- ### Annotation Format:
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
+ ## Why Order Matters
207
+
208
+ **"I'll write tests after to verify it works"**
209
+
210
+ Tests written after code pass immediately. Passing immediately proves nothing:
211
+ - Might test wrong thing
212
+ - Might test implementation, not behavior
213
+ - Might miss edge cases you forgot
214
+ - You never saw it catch the bug
215
+
216
+ Test-first forces you to see the test fail, proving it actually tests something.
217
+
218
+ **"I already manually tested all the edge cases"**
219
+
220
+ Manual testing is ad-hoc. You think you tested everything but:
221
+ - No record of what you tested
222
+ - Can't re-run when code changes
223
+ - Easy to forget cases under pressure
224
+ - "It worked when I tried it" ≠ comprehensive
225
+
226
+ Automated tests are systematic. They run the same way every time.
227
+
228
+ **"Deleting X hours of work is wasteful"**
229
+
230
+ Sunk cost fallacy. The time is already gone. Your choice now:
231
+ - Delete and rewrite with TDD (X more hours, high confidence)
232
+ - Keep it and add tests after (30 min, low confidence, likely bugs)
233
+
234
+ The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
235
+
236
+ **"TDD is dogmatic, being pragmatic means adapting"**
237
+
238
+ TDD IS pragmatic:
239
+ - Finds bugs before commit (faster than debugging after)
240
+ - Prevents regressions (tests catch breaks immediately)
241
+ - Documents behavior (tests show how to use code)
242
+ - Enables refactoring (change freely, tests catch breaks)
243
+
244
+ "Pragmatic" shortcuts = debugging in production = slower.
245
+
246
+ **"Tests after achieve the same goals - it's spirit not ritual"**
247
+
248
+ No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
249
+
250
+ Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
251
+
252
+ Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
253
+
254
+ 30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work.
255
+
256
+ ## Common Rationalizations
257
+
258
+ | Excuse | Reality |
259
+ |--------|---------|
260
+ | "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
261
+ | "I'll test after" | Tests passing immediately prove nothing. |
262
+ | "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
263
+ | "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
264
+ | "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
265
+ | "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
266
+ | "Need to explore first" | Fine. Throw away exploration, start with TDD. |
267
+ | "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
268
+ | "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
269
+ | "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
270
+ | "Existing code has no tests" | You're improving it. Add tests for existing code. |
271
+
272
+ ## Red Flags - STOP and Start Over
273
+
274
+ - Code before test
275
+ - Test after implementation
276
+ - Test passes immediately
277
+ - Can't explain why test failed
278
+ - Tests added "later"
279
+ - Rationalizing "just this once"
280
+ - "I already manually tested it"
281
+ - "Tests after achieve the same purpose"
282
+ - "It's about spirit not ritual"
283
+ - "Keep as reference" or "adapt existing code"
284
+ - "Already spent X hours, deleting is wasteful"
285
+ - "TDD is dogmatic, I'm being pragmatic"
286
+ - "This is different because..."
287
+
288
+ **All of these mean: Delete code. Start over with TDD.**
289
+
290
+ ## Example: Bug Fix
291
+
292
+ **Bug:** Empty email accepted
293
+
294
+ **RED**
52
295
  ```typescript
53
- // @mock-justified: external API wrapper, no sandbox environment available
296
+ test('rejects empty email', async () => {
297
+ const result = await submitForm({ email: '' });
298
+ expect(result.error).toBe('Email required');
299
+ });
54
300
  ```
55
- Reason text must be at least 10 characters. Bare `@mock-justified` without colon+reason is invalid.
56
301
 
57
- ## Test Annotations
302
+ **Verify RED**
303
+ ```bash
304
+ $ npm test
305
+ FAIL: expected 'Email required', got undefined
306
+ ```
58
307
 
308
+ **GREEN**
59
309
  ```typescript
60
- /**
61
- * @test REQ-XXX Feature name
62
- * @intent Verify specific behavior
63
- * @covers AC-XXX-01, AC-XXX-02
64
- */
310
+ function submitForm(data: FormData) {
311
+ if (!data.email?.trim()) {
312
+ return { error: 'Email required' };
313
+ }
314
+ // ...
315
+ }
65
316
  ```
66
317
 
67
- ## Coverage Requirements
318
+ **Verify GREEN**
319
+ ```bash
320
+ $ npm test
321
+ PASS
322
+ ```
323
+
324
+ **REFACTOR**
325
+ Extract validation for multiple fields if needed.
326
+
327
+ ## Verification Checklist
328
+
329
+ Before marking work complete:
330
+
331
+ - [ ] Every new function/method has a test
332
+ - [ ] Watched each test fail before implementing
333
+ - [ ] Each test failed for expected reason (feature missing, not typo)
334
+ - [ ] Wrote minimal code to pass each test
335
+ - [ ] All tests pass
336
+ - [ ] Output pristine (no errors, warnings)
337
+ - [ ] Tests use real code (mocks only if unavoidable)
338
+ - [ ] Edge cases and errors covered
339
+
340
+ Can't check all boxes? You skipped TDD. Start over.
341
+
342
+ ## When Stuck
343
+
344
+ | Problem | Solution |
345
+ |---------|----------|
346
+ | Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
347
+ | Test too complicated | Design too complicated. Simplify interface. |
348
+ | Must mock everything | Code too coupled. Use dependency injection. |
349
+ | Test setup huge | Extract helpers. Still complex? Simplify design. |
350
+
351
+ ## Debugging Integration
352
+
353
+ Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
354
+
355
+ Never fix bugs without a test.
356
+
357
+ ## Testing Anti-Patterns
358
+
359
+ When adding mocks or test utilities, read @testing-anti-patterns.md to avoid common pitfalls:
360
+ - Testing mock behavior instead of real behavior
361
+ - Adding test-only methods to production classes
362
+ - Mocking without understanding dependencies
363
+
364
+ ## Final Rule
365
+
366
+ ```
367
+ Production code → test exists and failed first
368
+ Otherwise → not TDD
369
+ ```
68
370
 
69
- - Minimum 80% line coverage
70
- - All acceptance criteria must have corresponding tests
71
- - Tests must survive mutation testing (Gate M pre-push)
371
+ No exceptions without your human partner's permission.
@@ -0,0 +1,299 @@
1
+ # Testing Anti-Patterns
2
+
3
+ **Load this reference when:** writing or changing tests, adding mocks, or tempted to add test-only methods to production code.
4
+
5
+ ## Overview
6
+
7
+ Tests must verify real behavior, not mock behavior. Mocks are a means to isolate, not the thing being tested.
8
+
9
+ **Core principle:** Test what the code does, not what the mocks do.
10
+
11
+ **Following strict TDD prevents these anti-patterns.**
12
+
13
+ ## The Iron Laws
14
+
15
+ ```
16
+ 1. NEVER test mock behavior
17
+ 2. NEVER add test-only methods to production classes
18
+ 3. NEVER mock without understanding dependencies
19
+ ```
20
+
21
+ ## Anti-Pattern 1: Testing Mock Behavior
22
+
23
+ **The violation:**
24
+ ```typescript
25
+ // ❌ BAD: Testing that the mock exists
26
+ test('renders sidebar', () => {
27
+ render(<Page />);
28
+ expect(screen.getByTestId('sidebar-mock')).toBeInTheDocument();
29
+ });
30
+ ```
31
+
32
+ **Why this is wrong:**
33
+ - You're verifying the mock works, not that the component works
34
+ - Test passes when mock is present, fails when it's not
35
+ - Tells you nothing about real behavior
36
+
37
+ **your human partner's correction:** "Are we testing the behavior of a mock?"
38
+
39
+ **The fix:**
40
+ ```typescript
41
+ // ✅ GOOD: Test real component or don't mock it
42
+ test('renders sidebar', () => {
43
+ render(<Page />); // Don't mock sidebar
44
+ expect(screen.getByRole('navigation')).toBeInTheDocument();
45
+ });
46
+
47
+ // OR if sidebar must be mocked for isolation:
48
+ // Don't assert on the mock - test Page's behavior with sidebar present
49
+ ```
50
+
51
+ ### Gate Function
52
+
53
+ ```
54
+ BEFORE asserting on any mock element:
55
+ Ask: "Am I testing real component behavior or just mock existence?"
56
+
57
+ IF testing mock existence:
58
+ STOP - Delete the assertion or unmock the component
59
+
60
+ Test real behavior instead
61
+ ```
62
+
63
+ ## Anti-Pattern 2: Test-Only Methods in Production
64
+
65
+ **The violation:**
66
+ ```typescript
67
+ // ❌ BAD: destroy() only used in tests
68
+ class Session {
69
+ async destroy() { // Looks like production API!
70
+ await this._workspaceManager?.destroyWorkspace(this.id);
71
+ // ... cleanup
72
+ }
73
+ }
74
+
75
+ // In tests
76
+ afterEach(() => session.destroy());
77
+ ```
78
+
79
+ **Why this is wrong:**
80
+ - Production class polluted with test-only code
81
+ - Dangerous if accidentally called in production
82
+ - Violates YAGNI and separation of concerns
83
+ - Confuses object lifecycle with entity lifecycle
84
+
85
+ **The fix:**
86
+ ```typescript
87
+ // ✅ GOOD: Test utilities handle test cleanup
88
+ // Session has no destroy() - it's stateless in production
89
+
90
+ // In test-utils/
91
+ export async function cleanupSession(session: Session) {
92
+ const workspace = session.getWorkspaceInfo();
93
+ if (workspace) {
94
+ await workspaceManager.destroyWorkspace(workspace.id);
95
+ }
96
+ }
97
+
98
+ // In tests
99
+ afterEach(() => cleanupSession(session));
100
+ ```
101
+
102
+ ### Gate Function
103
+
104
+ ```
105
+ BEFORE adding any method to production class:
106
+ Ask: "Is this only used by tests?"
107
+
108
+ IF yes:
109
+ STOP - Don't add it
110
+ Put it in test utilities instead
111
+
112
+ Ask: "Does this class own this resource's lifecycle?"
113
+
114
+ IF no:
115
+ STOP - Wrong class for this method
116
+ ```
117
+
118
+ ## Anti-Pattern 3: Mocking Without Understanding
119
+
120
+ **The violation:**
121
+ ```typescript
122
+ // ❌ BAD: Mock breaks test logic
123
+ test('detects duplicate server', () => {
124
+ // Mock prevents config write that test depends on!
125
+ vi.mock('ToolCatalog', () => ({
126
+ discoverAndCacheTools: vi.fn().mockResolvedValue(undefined)
127
+ }));
128
+
129
+ await addServer(config);
130
+ await addServer(config); // Should throw - but won't!
131
+ });
132
+ ```
133
+
134
+ **Why this is wrong:**
135
+ - Mocked method had side effect test depended on (writing config)
136
+ - Over-mocking to "be safe" breaks actual behavior
137
+ - Test passes for wrong reason or fails mysteriously
138
+
139
+ **The fix:**
140
+ ```typescript
141
+ // ✅ GOOD: Mock at correct level
142
+ test('detects duplicate server', () => {
143
+ // Mock the slow part, preserve behavior test needs
144
+ vi.mock('MCPServerManager'); // Just mock slow server startup
145
+
146
+ await addServer(config); // Config written
147
+ await addServer(config); // Duplicate detected ✓
148
+ });
149
+ ```
150
+
151
+ ### Gate Function
152
+
153
+ ```
154
+ BEFORE mocking any method:
155
+ STOP - Don't mock yet
156
+
157
+ 1. Ask: "What side effects does the real method have?"
158
+ 2. Ask: "Does this test depend on any of those side effects?"
159
+ 3. Ask: "Do I fully understand what this test needs?"
160
+
161
+ IF depends on side effects:
162
+ Mock at lower level (the actual slow/external operation)
163
+ OR use test doubles that preserve necessary behavior
164
+ NOT the high-level method the test depends on
165
+
166
+ IF unsure what test depends on:
167
+ Run test with real implementation FIRST
168
+ Observe what actually needs to happen
169
+ THEN add minimal mocking at the right level
170
+
171
+ Red flags:
172
+ - "I'll mock this to be safe"
173
+ - "This might be slow, better mock it"
174
+ - Mocking without understanding the dependency chain
175
+ ```
176
+
177
+ ## Anti-Pattern 4: Incomplete Mocks
178
+
179
+ **The violation:**
180
+ ```typescript
181
+ // ❌ BAD: Partial mock - only fields you think you need
182
+ const mockResponse = {
183
+ status: 'success',
184
+ data: { userId: '123', name: 'Alice' }
185
+ // Missing: metadata that downstream code uses
186
+ };
187
+
188
+ // Later: breaks when code accesses response.metadata.requestId
189
+ ```
190
+
191
+ **Why this is wrong:**
192
+ - **Partial mocks hide structural assumptions** - You only mocked fields you know about
193
+ - **Downstream code may depend on fields you didn't include** - Silent failures
194
+ - **Tests pass but integration fails** - Mock incomplete, real API complete
195
+ - **False confidence** - Test proves nothing about real behavior
196
+
197
+ **The Iron Rule:** Mock the COMPLETE data structure as it exists in reality, not just fields your immediate test uses.
198
+
199
+ **The fix:**
200
+ ```typescript
201
+ // ✅ GOOD: Mirror real API completeness
202
+ const mockResponse = {
203
+ status: 'success',
204
+ data: { userId: '123', name: 'Alice' },
205
+ metadata: { requestId: 'req-789', timestamp: 1234567890 }
206
+ // All fields real API returns
207
+ };
208
+ ```
209
+
210
+ ### Gate Function
211
+
212
+ ```
213
+ BEFORE creating mock responses:
214
+ Check: "What fields does the real API response contain?"
215
+
216
+ Actions:
217
+ 1. Examine actual API response from docs/examples
218
+ 2. Include ALL fields system might consume downstream
219
+ 3. Verify mock matches real response schema completely
220
+
221
+ Critical:
222
+ If you're creating a mock, you must understand the ENTIRE structure
223
+ Partial mocks fail silently when code depends on omitted fields
224
+
225
+ If uncertain: Include all documented fields
226
+ ```
227
+
228
+ ## Anti-Pattern 5: Integration Tests as Afterthought
229
+
230
+ **The violation:**
231
+ ```
232
+ ✅ Implementation complete
233
+ ❌ No tests written
234
+ "Ready for testing"
235
+ ```
236
+
237
+ **Why this is wrong:**
238
+ - Testing is part of implementation, not optional follow-up
239
+ - TDD would have caught this
240
+ - Can't claim complete without tests
241
+
242
+ **The fix:**
243
+ ```
244
+ TDD cycle:
245
+ 1. Write failing test
246
+ 2. Implement to pass
247
+ 3. Refactor
248
+ 4. THEN claim complete
249
+ ```
250
+
251
+ ## When Mocks Become Too Complex
252
+
253
+ **Warning signs:**
254
+ - Mock setup longer than test logic
255
+ - Mocking everything to make test pass
256
+ - Mocks missing methods real components have
257
+ - Test breaks when mock changes
258
+
259
+ **your human partner's question:** "Do we need to be using a mock here?"
260
+
261
+ **Consider:** Integration tests with real components often simpler than complex mocks
262
+
263
+ ## TDD Prevents These Anti-Patterns
264
+
265
+ **Why TDD helps:**
266
+ 1. **Write test first** → Forces you to think about what you're actually testing
267
+ 2. **Watch it fail** → Confirms test tests real behavior, not mocks
268
+ 3. **Minimal implementation** → No test-only methods creep in
269
+ 4. **Real dependencies** → You see what the test actually needs before mocking
270
+
271
+ **If you're testing mock behavior, you violated TDD** - you added mocks without watching test fail against real code first.
272
+
273
+ ## Quick Reference
274
+
275
+ | Anti-Pattern | Fix |
276
+ |--------------|-----|
277
+ | Assert on mock elements | Test real component or unmock it |
278
+ | Test-only methods in production | Move to test utilities |
279
+ | Mock without understanding | Understand dependencies first, mock minimally |
280
+ | Incomplete mocks | Mirror real API completely |
281
+ | Tests as afterthought | TDD - tests first |
282
+ | Over-complex mocks | Consider integration tests |
283
+
284
+ ## Red Flags
285
+
286
+ - Assertion checks for `*-mock` test IDs
287
+ - Methods only called in test files
288
+ - Mock setup is >50% of test
289
+ - Test fails when you remove mock
290
+ - Can't explain why mock is needed
291
+ - Mocking "just to be safe"
292
+
293
+ ## The Bottom Line
294
+
295
+ **Mocks are tools to isolate, not things to test.**
296
+
297
+ If TDD reveals you're testing mock behavior, you've gone wrong.
298
+
299
+ Fix: Test real behavior or question why you're mocking at all.
@@ -1,9 +1,9 @@
1
1
  # SKILLS/TEST-SPECIFICATION-ALIGNMENT KNOWLEDGE BASE
2
2
 
3
- **Generated:** 2026-05-30
4
- **Commit:** 4517f2b
3
+ **Generated:** 2026-06-14
4
+ **Commit:** e215a50
5
5
  **Branch:** main
6
- **Version:** v0.8.1
6
+ **Version:** 0.8.10.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.