@ronkovic/aad 0.3.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.
Files changed (195) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +312 -0
  3. package/bin/aad.js +2 -0
  4. package/package.json +78 -0
  5. package/src/__tests__/e2e/pipeline-e2e.test.ts +279 -0
  6. package/src/__tests__/e2e/resume-e2e.test.ts +200 -0
  7. package/src/__tests__/integration/cli-smoke.test.ts +175 -0
  8. package/src/__tests__/integration/pipeline.test.ts +346 -0
  9. package/src/bun-imports.d.ts +14 -0
  10. package/src/main.ts +52 -0
  11. package/src/modules/claude-provider/__tests__/claude-cli.adapter.test.ts +277 -0
  12. package/src/modules/claude-provider/__tests__/claude-sdk-real-env.test.ts +127 -0
  13. package/src/modules/claude-provider/__tests__/claude-sdk.adapter.test.ts +347 -0
  14. package/src/modules/claude-provider/__tests__/effort-strategy.test.ts +212 -0
  15. package/src/modules/claude-provider/__tests__/provider-registry.test.ts +251 -0
  16. package/src/modules/claude-provider/__tests__/retry.test.ts +201 -0
  17. package/src/modules/claude-provider/claude-cli.adapter.ts +156 -0
  18. package/src/modules/claude-provider/claude-provider.port.ts +35 -0
  19. package/src/modules/claude-provider/claude-sdk.adapter.ts +217 -0
  20. package/src/modules/claude-provider/effort-strategy.ts +94 -0
  21. package/src/modules/claude-provider/index.ts +32 -0
  22. package/src/modules/claude-provider/provider-registry.ts +92 -0
  23. package/src/modules/claude-provider/retry.ts +81 -0
  24. package/src/modules/cli/__tests__/app.test.ts +160 -0
  25. package/src/modules/cli/__tests__/cleanup.test.ts +111 -0
  26. package/src/modules/cli/__tests__/commands.test.ts +186 -0
  27. package/src/modules/cli/__tests__/output.test.ts +329 -0
  28. package/src/modules/cli/__tests__/resume.test.ts +324 -0
  29. package/src/modules/cli/__tests__/run.test.ts +168 -0
  30. package/src/modules/cli/__tests__/shutdown.test.ts +168 -0
  31. package/src/modules/cli/__tests__/status.test.ts +144 -0
  32. package/src/modules/cli/app.ts +241 -0
  33. package/src/modules/cli/commands/cleanup.ts +120 -0
  34. package/src/modules/cli/commands/resume.ts +156 -0
  35. package/src/modules/cli/commands/run.ts +322 -0
  36. package/src/modules/cli/commands/status.ts +101 -0
  37. package/src/modules/cli/index.ts +29 -0
  38. package/src/modules/cli/output.ts +256 -0
  39. package/src/modules/cli/shutdown.ts +122 -0
  40. package/src/modules/dashboard/__tests__/api-routes.test.ts +204 -0
  41. package/src/modules/dashboard/__tests__/file-watcher.test.ts +34 -0
  42. package/src/modules/dashboard/__tests__/server.test.ts +120 -0
  43. package/src/modules/dashboard/__tests__/sse-broadcaster.test.ts +163 -0
  44. package/src/modules/dashboard/__tests__/sse-routes.test.ts +58 -0
  45. package/src/modules/dashboard/__tests__/state-aggregator.test.ts +330 -0
  46. package/src/modules/dashboard/index.ts +8 -0
  47. package/src/modules/dashboard/routes/api.ts +84 -0
  48. package/src/modules/dashboard/routes/sse.ts +37 -0
  49. package/src/modules/dashboard/server.ts +111 -0
  50. package/src/modules/dashboard/services/file-watcher.ts +36 -0
  51. package/src/modules/dashboard/services/sse-broadcaster.ts +81 -0
  52. package/src/modules/dashboard/services/state-aggregator.ts +132 -0
  53. package/src/modules/dashboard/ui/dashboard.html +405 -0
  54. package/src/modules/git-workspace/__tests__/branch-manager.test.ts +335 -0
  55. package/src/modules/git-workspace/__tests__/git-exec.test.ts +91 -0
  56. package/src/modules/git-workspace/__tests__/memory-sync.test.ts +273 -0
  57. package/src/modules/git-workspace/__tests__/merge-service.test.ts +286 -0
  58. package/src/modules/git-workspace/__tests__/settings-merge.test.ts +163 -0
  59. package/src/modules/git-workspace/__tests__/worktree-manager.test.ts +247 -0
  60. package/src/modules/git-workspace/branch-manager.ts +191 -0
  61. package/src/modules/git-workspace/git-exec.ts +124 -0
  62. package/src/modules/git-workspace/index.ts +17 -0
  63. package/src/modules/git-workspace/memory-sync.ts +89 -0
  64. package/src/modules/git-workspace/merge-service.ts +156 -0
  65. package/src/modules/git-workspace/settings-merge.ts +95 -0
  66. package/src/modules/git-workspace/worktree-manager.ts +199 -0
  67. package/src/modules/logging/__tests__/log-store.test.ts +242 -0
  68. package/src/modules/logging/__tests__/logger.test.ts +81 -0
  69. package/src/modules/logging/__tests__/sse-transport.test.ts +93 -0
  70. package/src/modules/logging/index.ts +7 -0
  71. package/src/modules/logging/log-store.ts +80 -0
  72. package/src/modules/logging/logger.ts +55 -0
  73. package/src/modules/logging/transports/sse-transport.ts +28 -0
  74. package/src/modules/multi-repo/__tests__/multi-repo-planner.test.ts +93 -0
  75. package/src/modules/multi-repo/__tests__/repo-context.test.ts +79 -0
  76. package/src/modules/multi-repo/index.ts +12 -0
  77. package/src/modules/multi-repo/multi-repo-planner.ts +112 -0
  78. package/src/modules/multi-repo/repo-context.ts +71 -0
  79. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/progress.json +10 -0
  80. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/queue/completed/task-getall-2.json +10 -0
  81. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/queue/pending/task-1.json +13 -0
  82. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/queue/pending/task-getall-1.json +10 -0
  83. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/queue/pending/task-status-change.json +10 -0
  84. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/workers/worker-1.json +5 -0
  85. package/src/modules/persistence/__tests__/.tmp-stores-test-81991/workers/worker-2.json +5 -0
  86. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/progress.json +10 -0
  87. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/queue/completed/task-getall-2.json +10 -0
  88. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/queue/pending/task-1.json +13 -0
  89. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/queue/pending/task-getall-1.json +10 -0
  90. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/queue/pending/task-status-change.json +10 -0
  91. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/workers/worker-1.json +5 -0
  92. package/src/modules/persistence/__tests__/.tmp-stores-test-82469/workers/worker-2.json +5 -0
  93. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/progress.json +10 -0
  94. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/queue/completed/task-getall-2.json +10 -0
  95. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/queue/pending/task-1.json +13 -0
  96. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/queue/pending/task-getall-1.json +10 -0
  97. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/queue/pending/task-status-change.json +10 -0
  98. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/workers/worker-1.json +5 -0
  99. package/src/modules/persistence/__tests__/.tmp-stores-test-85301/workers/worker-2.json +5 -0
  100. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/progress.json +10 -0
  101. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/queue/completed/task-getall-2.json +10 -0
  102. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/queue/pending/task-1.json +13 -0
  103. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/queue/pending/task-getall-1.json +10 -0
  104. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/queue/pending/task-status-change.json +10 -0
  105. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/workers/worker-1.json +5 -0
  106. package/src/modules/persistence/__tests__/.tmp-stores-test-85759/workers/worker-2.json +5 -0
  107. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/progress.json +10 -0
  108. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/queue/completed/task-getall-2.json +10 -0
  109. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/queue/pending/task-1.json +13 -0
  110. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/queue/pending/task-getall-1.json +10 -0
  111. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/queue/pending/task-status-change.json +10 -0
  112. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/workers/worker-1.json +5 -0
  113. package/src/modules/persistence/__tests__/.tmp-stores-test-86184/workers/worker-2.json +5 -0
  114. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/progress.json +10 -0
  115. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/queue/completed/task-getall-2.json +10 -0
  116. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/queue/pending/task-1.json +13 -0
  117. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/queue/pending/task-getall-1.json +10 -0
  118. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/queue/pending/task-status-change.json +10 -0
  119. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/workers/worker-1.json +5 -0
  120. package/src/modules/persistence/__tests__/.tmp-stores-test-88026/workers/worker-2.json +5 -0
  121. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/progress.json +10 -0
  122. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/queue/completed/task-getall-2.json +10 -0
  123. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/queue/pending/task-1.json +13 -0
  124. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/queue/pending/task-getall-1.json +10 -0
  125. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/queue/pending/task-status-change.json +10 -0
  126. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/workers/worker-1.json +5 -0
  127. package/src/modules/persistence/__tests__/.tmp-stores-test-89475/workers/worker-2.json +5 -0
  128. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/progress.json +10 -0
  129. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/queue/completed/task-getall-2.json +10 -0
  130. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/queue/pending/task-1.json +13 -0
  131. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/queue/pending/task-getall-1.json +10 -0
  132. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/queue/pending/task-status-change.json +10 -0
  133. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/workers/worker-1.json +5 -0
  134. package/src/modules/persistence/__tests__/.tmp-stores-test-89924/workers/worker-2.json +5 -0
  135. package/src/modules/persistence/__tests__/file-lock.test.ts +141 -0
  136. package/src/modules/persistence/__tests__/index.test.ts +38 -0
  137. package/src/modules/persistence/__tests__/stores.test.ts +594 -0
  138. package/src/modules/persistence/file-lock.ts +158 -0
  139. package/src/modules/persistence/fs-run-store.ts +73 -0
  140. package/src/modules/persistence/fs-task-store.ts +152 -0
  141. package/src/modules/persistence/fs-worker-store.ts +116 -0
  142. package/src/modules/persistence/in-memory-stores.ts +98 -0
  143. package/src/modules/persistence/index.ts +60 -0
  144. package/src/modules/persistence/stores.port.ts +60 -0
  145. package/src/modules/planning/__tests__/file-conflict-validator.test.ts +256 -0
  146. package/src/modules/planning/__tests__/planning-service.test.ts +366 -0
  147. package/src/modules/planning/__tests__/project-detection.test.ts +707 -0
  148. package/src/modules/planning/file-conflict-validator.ts +135 -0
  149. package/src/modules/planning/index.ts +40 -0
  150. package/src/modules/planning/planning.service.ts +262 -0
  151. package/src/modules/planning/project-detection.ts +525 -0
  152. package/src/modules/plugin/__tests__/plugin-loader.test.ts +83 -0
  153. package/src/modules/plugin/__tests__/plugin-manager.test.ts +187 -0
  154. package/src/modules/plugin/index.ts +3 -0
  155. package/src/modules/plugin/plugin-loader.ts +46 -0
  156. package/src/modules/plugin/plugin-manager.ts +90 -0
  157. package/src/modules/plugin/plugin.types.ts +37 -0
  158. package/src/modules/process-manager/__tests__/process-manager.test.ts +210 -0
  159. package/src/modules/process-manager/__tests__/worker.test.ts +89 -0
  160. package/src/modules/process-manager/index.ts +5 -0
  161. package/src/modules/process-manager/process-manager.ts +193 -0
  162. package/src/modules/process-manager/worker.ts +106 -0
  163. package/src/modules/task-execution/__tests__/default-spawner.test.ts +154 -0
  164. package/src/modules/task-execution/__tests__/executor.test.ts +760 -0
  165. package/src/modules/task-execution/__tests__/implementer-green.test.ts +286 -0
  166. package/src/modules/task-execution/__tests__/merge-phase.test.ts +368 -0
  167. package/src/modules/task-execution/__tests__/reviewer.test.ts +302 -0
  168. package/src/modules/task-execution/__tests__/tester-red.test.ts +281 -0
  169. package/src/modules/task-execution/__tests__/tester-verify.test.ts +313 -0
  170. package/src/modules/task-execution/executor.ts +303 -0
  171. package/src/modules/task-execution/index.ts +45 -0
  172. package/src/modules/task-execution/phases/default-spawner.ts +49 -0
  173. package/src/modules/task-execution/phases/implementer-green.ts +100 -0
  174. package/src/modules/task-execution/phases/merge.ts +122 -0
  175. package/src/modules/task-execution/phases/reviewer.ts +160 -0
  176. package/src/modules/task-execution/phases/tester-red.ts +100 -0
  177. package/src/modules/task-execution/phases/tester-verify.ts +120 -0
  178. package/src/modules/task-queue/__tests__/dependency-resolver.test.ts +456 -0
  179. package/src/modules/task-queue/__tests__/dispatcher.test.ts +824 -0
  180. package/src/modules/task-queue/__tests__/task-plan.test.ts +122 -0
  181. package/src/modules/task-queue/__tests__/task.test.ts +130 -0
  182. package/src/modules/task-queue/dependency-resolver.ts +171 -0
  183. package/src/modules/task-queue/dispatcher.ts +372 -0
  184. package/src/modules/task-queue/index.ts +16 -0
  185. package/src/modules/task-queue/task-plan.ts +40 -0
  186. package/src/modules/task-queue/task.ts +67 -0
  187. package/src/shared/__tests__/config.test.ts +204 -0
  188. package/src/shared/__tests__/errors.test.ts +285 -0
  189. package/src/shared/__tests__/events.test.ts +496 -0
  190. package/src/shared/__tests__/types.test.ts +360 -0
  191. package/src/shared/config.ts +133 -0
  192. package/src/shared/errors.ts +128 -0
  193. package/src/shared/events.ts +171 -0
  194. package/src/shared/types.ts +143 -0
  195. package/tsconfig.json +30 -0
@@ -0,0 +1,302 @@
1
+ import { describe, test, expect } from "bun:test";
2
+ import {
3
+ runReviewer,
4
+ buildReviewPrompt,
5
+ buildTeamsReviewPrompt,
6
+ buildReviewerSubagents,
7
+ } from "../phases/reviewer";
8
+ import type { Task, WorkspaceInfo } from "@aad/shared/types";
9
+ import type { ClaudeProvider, ClaudeRequest, ClaudeResponse } from "@aad/claude-provider";
10
+ import { createTaskId, createRunId } from "@aad/shared/types";
11
+
12
+ describe("buildReviewPrompt (solo mode)", () => {
13
+ test("builds solo review prompt", () => {
14
+ const task: Task = {
15
+ taskId: createTaskId("task-001"),
16
+ title: "Add login endpoint",
17
+ description: "JWT-based auth",
18
+ filesToModify: ["src/auth.ts"],
19
+ dependsOn: [],
20
+ priority: 1,
21
+ status: "running",
22
+ retryCount: 0,
23
+ };
24
+
25
+ const prompt = buildReviewPrompt(task);
26
+
27
+ expect(prompt).toContain("reviewerエージェント");
28
+ expect(prompt).toContain("コードレビュー");
29
+ expect(prompt).toContain("task-001");
30
+ expect(prompt).toContain("Add login endpoint");
31
+ expect(prompt).toContain("品質・セキュリティ・パフォーマンス");
32
+ });
33
+ });
34
+
35
+ describe("buildTeamsReviewPrompt (teams mode)", () => {
36
+ test("builds teams review prompt with parallel reviewers", () => {
37
+ const task: Task = {
38
+ taskId: createTaskId("task-002"),
39
+ title: "API implementation",
40
+ description: "RESTful API",
41
+ filesToModify: ["src/api.ts"],
42
+ dependsOn: [],
43
+ priority: 1,
44
+ status: "running",
45
+ retryCount: 0,
46
+ };
47
+
48
+ const runId = createRunId("run-123");
49
+
50
+ const prompt = buildTeamsReviewPrompt(task, runId);
51
+
52
+ expect(prompt).toContain("reviewerチームリーダー");
53
+ expect(prompt).toContain("Agent Teamsを使った並列コードレビュー");
54
+ expect(prompt).toContain("quality-reviewer");
55
+ expect(prompt).toContain("security-reviewer");
56
+ expect(prompt).toContain("performance-reviewer");
57
+ expect(prompt).toContain("code_review.md");
58
+ expect(prompt).toContain("run-123");
59
+ });
60
+
61
+ test("includes review aspects for each role", () => {
62
+ const task: Task = {
63
+ taskId: createTaskId("task-003"),
64
+ title: "Test",
65
+ description: "Test",
66
+ filesToModify: [],
67
+ dependsOn: [],
68
+ priority: 1,
69
+ status: "running",
70
+ retryCount: 0,
71
+ };
72
+
73
+ const runId = createRunId("run-456");
74
+ const prompt = buildTeamsReviewPrompt(task, runId);
75
+
76
+ // Quality reviewer
77
+ expect(prompt).toContain("可読性");
78
+ expect(prompt).toContain("DRY原則");
79
+
80
+ // Security reviewer
81
+ expect(prompt).toContain("SQLインジェクション");
82
+ expect(prompt).toContain("認証・認可");
83
+
84
+ // Performance reviewer
85
+ expect(prompt).toContain("N+1クエリ");
86
+ expect(prompt).toContain("アルゴリズム");
87
+ });
88
+ });
89
+
90
+ describe("buildReviewerSubagents", () => {
91
+ test("returns 3 reviewer subagents", () => {
92
+ const subagents = buildReviewerSubagents();
93
+ expect(subagents).toHaveLength(3);
94
+ expect(subagents.map(s => s.name)).toEqual([
95
+ "quality-reviewer",
96
+ "security-reviewer",
97
+ "performance-reviewer",
98
+ ]);
99
+ });
100
+
101
+ test("each subagent has a non-empty prompt", () => {
102
+ const subagents = buildReviewerSubagents();
103
+ for (const sa of subagents) {
104
+ expect(sa.prompt.length).toBeGreaterThan(0);
105
+ }
106
+ });
107
+ });
108
+
109
+ describe("runReviewer", () => {
110
+ test("runs solo review by default", async () => {
111
+ const task: Task = {
112
+ taskId: createTaskId("task-004"),
113
+ title: "Add validation",
114
+ description: "Input validation",
115
+ filesToModify: ["src/validator.ts"],
116
+ dependsOn: [],
117
+ priority: 1,
118
+ status: "running",
119
+ retryCount: 0,
120
+ };
121
+
122
+ const workspace: WorkspaceInfo = {
123
+ path: "/workspace",
124
+ language: "typescript",
125
+ packageManager: "bun",
126
+ framework: "hono",
127
+ testFramework: "bun-test",
128
+ };
129
+
130
+ const config = {
131
+ teams: { reviewer: false },
132
+ };
133
+
134
+ const mockProvider: ClaudeProvider = {
135
+ async call(request: ClaudeRequest): Promise<ClaudeResponse> {
136
+ expect(request.prompt).toContain("reviewerエージェント");
137
+ expect(request.prompt).not.toContain("チームリーダー");
138
+ expect(request.cwd).toBe("/workspace");
139
+ expect(request.effortLevel).toBe("medium");
140
+
141
+ return {
142
+ result: "レビュー完了",
143
+ exitCode: 0,
144
+ model: "claude-sonnet-4-5",
145
+ effortLevel: "medium",
146
+ duration: 1000,
147
+ };
148
+ },
149
+ };
150
+
151
+ const runId = createRunId("run-001");
152
+ const result = await runReviewer(task, workspace, runId, config, mockProvider);
153
+
154
+ expect(result.success).toBe(true);
155
+ expect(result.output).toContain("レビュー完了");
156
+ });
157
+
158
+ test("runs teams review when config.teams.reviewer is true", async () => {
159
+ const task: Task = {
160
+ taskId: createTaskId("task-005"),
161
+ title: "Complex feature",
162
+ description: "Complex implementation",
163
+ filesToModify: ["src/feature.ts"],
164
+ dependsOn: [],
165
+ priority: 1,
166
+ status: "running",
167
+ retryCount: 0,
168
+ };
169
+
170
+ const workspace: WorkspaceInfo = {
171
+ path: "/workspace",
172
+ language: "typescript",
173
+ packageManager: "bun",
174
+ framework: "hono",
175
+ testFramework: "bun-test",
176
+ };
177
+
178
+ const config = {
179
+ teams: { reviewer: true },
180
+ };
181
+
182
+ const mockProvider: ClaudeProvider = {
183
+ async call(request: ClaudeRequest): Promise<ClaudeResponse> {
184
+ expect(request.prompt).toContain("reviewerチームリーダー");
185
+ expect(request.prompt).toContain("Agent Teams");
186
+ expect(request.effortLevel).toBe("high");
187
+ // Verify subagents are passed
188
+ expect(request.subagents).toBeDefined();
189
+ expect(request.subagents).toHaveLength(3);
190
+ expect(request.subagents?.map(s => s.name)).toEqual([
191
+ "quality-reviewer",
192
+ "security-reviewer",
193
+ "performance-reviewer",
194
+ ]);
195
+
196
+ return {
197
+ result: "並列レビュー完了",
198
+ exitCode: 0,
199
+ model: "claude-sonnet-4-5",
200
+ effortLevel: "high",
201
+ duration: 2500,
202
+ };
203
+ },
204
+ };
205
+
206
+ const runId = createRunId("run-002");
207
+ const result = await runReviewer(task, workspace, runId, config, mockProvider);
208
+
209
+ expect(result.success).toBe(true);
210
+ expect(result.output).toContain("並列レビュー完了");
211
+ });
212
+
213
+ test("handles review failure gracefully (non-fatal)", async () => {
214
+ const task: Task = {
215
+ taskId: createTaskId("task-006"),
216
+ title: "Test task",
217
+ description: "Test description",
218
+ filesToModify: [],
219
+ dependsOn: [],
220
+ priority: 1,
221
+ status: "running",
222
+ retryCount: 0,
223
+ };
224
+
225
+ const workspace: WorkspaceInfo = {
226
+ path: "/workspace",
227
+ language: "typescript",
228
+ packageManager: "bun",
229
+ framework: "hono",
230
+ testFramework: "bun-test",
231
+ };
232
+
233
+ const config = {
234
+ teams: { reviewer: false },
235
+ };
236
+
237
+ const mockProvider: ClaudeProvider = {
238
+ async call(): Promise<ClaudeResponse> {
239
+ return {
240
+ result: "レビューエラー",
241
+ exitCode: 1,
242
+ model: "claude-sonnet-4-5",
243
+ effortLevel: "medium",
244
+ duration: 500,
245
+ };
246
+ },
247
+ };
248
+
249
+ const runId = createRunId("run-003");
250
+ const result = await runReviewer(task, workspace, runId, config, mockProvider);
251
+
252
+ // Review failure is non-fatal; returns success but logs warning
253
+ expect(result.success).toBe(false);
254
+ expect(result.output).toContain("レビューエラー");
255
+ });
256
+
257
+ test("passes custom model and timeout", async () => {
258
+ const task: Task = {
259
+ taskId: createTaskId("task-007"),
260
+ title: "Test task",
261
+ description: "Test description",
262
+ filesToModify: [],
263
+ dependsOn: [],
264
+ priority: 1,
265
+ status: "running",
266
+ retryCount: 0,
267
+ };
268
+
269
+ const workspace: WorkspaceInfo = {
270
+ path: "/workspace",
271
+ language: "typescript",
272
+ packageManager: "bun",
273
+ framework: "hono",
274
+ testFramework: "bun-test",
275
+ };
276
+
277
+ const config = {
278
+ teams: { reviewer: false },
279
+ };
280
+
281
+ const mockProvider: ClaudeProvider = {
282
+ async call(request: ClaudeRequest): Promise<ClaudeResponse> {
283
+ expect(request.model).toBe("claude-opus-4-6");
284
+ expect(request.timeout).toBe(120000);
285
+
286
+ return {
287
+ result: "OK",
288
+ exitCode: 0,
289
+ model: "claude-opus-4-6",
290
+ effortLevel: "medium",
291
+ duration: 1000,
292
+ };
293
+ },
294
+ };
295
+
296
+ const runId = createRunId("run-004");
297
+ await runReviewer(task, workspace, runId, config, mockProvider, {
298
+ model: "claude-opus-4-6",
299
+ timeout: 120000,
300
+ });
301
+ });
302
+ });
@@ -0,0 +1,281 @@
1
+ import { describe, test, expect } from "bun:test";
2
+ import { runTesterRed, buildRedPhasePrompt } from "../phases/tester-red";
3
+ import type { Task, WorkspaceInfo } from "@aad/shared/types";
4
+ import type { ClaudeProvider, ClaudeRequest, ClaudeResponse } from "@aad/claude-provider";
5
+ import { createTaskId } from "@aad/shared/types";
6
+
7
+ describe("buildRedPhasePrompt", () => {
8
+ test("builds prompt with task info and workspace context", () => {
9
+ const task: Task = {
10
+ taskId: createTaskId("task-001"),
11
+ title: "Add user authentication",
12
+ description: "Implement JWT-based auth with refresh tokens",
13
+ filesToModify: ["src/auth.ts", "src/middleware.ts"],
14
+ dependsOn: [],
15
+ priority: 1,
16
+ status: "running",
17
+ retryCount: 0,
18
+ };
19
+
20
+ const workspace: WorkspaceInfo = {
21
+ path: "/workspace",
22
+ language: "typescript",
23
+ packageManager: "bun",
24
+ framework: "hono",
25
+ testFramework: "bun-test",
26
+ };
27
+
28
+ const prompt = buildRedPhasePrompt(task, workspace);
29
+
30
+ expect(prompt).toContain("TDD Red フェーズ");
31
+ expect(prompt).toContain("task-001");
32
+ expect(prompt).toContain("Add user authentication");
33
+ expect(prompt).toContain("JWT-based auth");
34
+ expect(prompt).toContain("typescript");
35
+ expect(prompt).toContain("bun-test");
36
+ expect(prompt).toContain("失敗するテストを作成");
37
+ });
38
+
39
+ test("includes language-specific test patterns", () => {
40
+ const task: Task = {
41
+ taskId: createTaskId("task-002"),
42
+ title: "Test task",
43
+ description: "Test description",
44
+ filesToModify: [],
45
+ dependsOn: [],
46
+ priority: 1,
47
+ status: "running",
48
+ retryCount: 0,
49
+ };
50
+
51
+ const workspaceGo: WorkspaceInfo = {
52
+ path: "/go-project",
53
+ language: "go",
54
+ packageManager: "go-modules",
55
+ framework: "gin",
56
+ testFramework: "go-test",
57
+ };
58
+
59
+ const promptGo = buildRedPhasePrompt(task, workspaceGo);
60
+ expect(promptGo).toContain("テーブル駆動テスト");
61
+
62
+ const workspacePython: WorkspaceInfo = {
63
+ path: "/py-project",
64
+ language: "python",
65
+ packageManager: "pip",
66
+ framework: "flask",
67
+ testFramework: "pytest",
68
+ };
69
+
70
+ const promptPython = buildRedPhasePrompt(task, workspacePython);
71
+ expect(promptPython).toContain("pytest parametrize");
72
+
73
+ const workspaceRust: WorkspaceInfo = {
74
+ path: "/rust-project",
75
+ language: "rust",
76
+ packageManager: "cargo",
77
+ framework: "axum",
78
+ testFramework: "cargo",
79
+ };
80
+ const promptRust = buildRedPhasePrompt(task, workspaceRust);
81
+ expect(promptRust).toContain("テストケースベクター");
82
+
83
+ const workspaceTerraform: WorkspaceInfo = {
84
+ path: "/tf-project",
85
+ language: "terraform",
86
+ packageManager: "unknown",
87
+ framework: "unknown",
88
+ testFramework: "pytest",
89
+ };
90
+ const promptTf = buildRedPhasePrompt(task, workspaceTerraform);
91
+ expect(promptTf).toContain("terraform validate");
92
+
93
+ const workspaceJava: WorkspaceInfo = {
94
+ path: "/java-project",
95
+ language: "java",
96
+ packageManager: "maven",
97
+ framework: "spring",
98
+ testFramework: "maven",
99
+ };
100
+ const promptJava = buildRedPhasePrompt(task, workspaceJava);
101
+ expect(promptJava).toContain("JUnit");
102
+
103
+ const workspaceUnknown: WorkspaceInfo = {
104
+ path: "/unknown-project",
105
+ language: "elixir",
106
+ packageManager: "mix",
107
+ framework: "phoenix",
108
+ testFramework: "unknown",
109
+ };
110
+ const promptUnknown = buildRedPhasePrompt(task, workspaceUnknown);
111
+ expect(promptUnknown).toContain("適切なテストパターン");
112
+ });
113
+ });
114
+
115
+ describe("runTesterRed", () => {
116
+ test("calls Claude provider with correct request", async () => {
117
+ const task: Task = {
118
+ taskId: createTaskId("task-003"),
119
+ title: "Add validation",
120
+ description: "Add input validation for user form",
121
+ filesToModify: ["src/validator.ts"],
122
+ dependsOn: [],
123
+ priority: 1,
124
+ status: "running",
125
+ retryCount: 0,
126
+ };
127
+
128
+ const workspace: WorkspaceInfo = {
129
+ path: "/workspace",
130
+ language: "typescript",
131
+ packageManager: "bun",
132
+ framework: "hono",
133
+ testFramework: "bun-test",
134
+ };
135
+
136
+ const mockProvider: ClaudeProvider = {
137
+ async call(request: ClaudeRequest): Promise<ClaudeResponse> {
138
+ expect(request.prompt).toContain("TDD Red");
139
+ expect(request.allowedTools).toEqual([
140
+ "Read",
141
+ "Write",
142
+ "Edit",
143
+ "Glob",
144
+ "Grep",
145
+ "Bash",
146
+ ]);
147
+ expect(request.permissionMode).toBe("bypassPermissions");
148
+ expect(request.cwd).toBe("/workspace");
149
+
150
+ return {
151
+ result: "テストを作成しました",
152
+ exitCode: 0,
153
+ model: "claude-sonnet-4-5",
154
+ effortLevel: "medium",
155
+ duration: 1200,
156
+ };
157
+ },
158
+ };
159
+
160
+ const result = await runTesterRed(task, workspace, mockProvider);
161
+
162
+ expect(result.success).toBe(true);
163
+ expect(result.output).toContain("テストを作成しました");
164
+ });
165
+
166
+ test("handles Claude provider failure", async () => {
167
+ const task: Task = {
168
+ taskId: createTaskId("task-004"),
169
+ title: "Test task",
170
+ description: "Test description",
171
+ filesToModify: [],
172
+ dependsOn: [],
173
+ priority: 1,
174
+ status: "running",
175
+ retryCount: 0,
176
+ };
177
+
178
+ const workspace: WorkspaceInfo = {
179
+ path: "/workspace",
180
+ language: "typescript",
181
+ packageManager: "bun",
182
+ framework: "hono",
183
+ testFramework: "bun-test",
184
+ };
185
+
186
+ const mockProvider: ClaudeProvider = {
187
+ async call(): Promise<ClaudeResponse> {
188
+ return {
189
+ result: "エラーが発生しました",
190
+ exitCode: 1,
191
+ model: "claude-sonnet-4-5",
192
+ effortLevel: "medium",
193
+ duration: 500,
194
+ };
195
+ },
196
+ };
197
+
198
+ const result = await runTesterRed(task, workspace, mockProvider);
199
+
200
+ expect(result.success).toBe(false);
201
+ expect(result.output).toContain("エラーが発生しました");
202
+ });
203
+
204
+ test("passes correct effort level and model", async () => {
205
+ const task: Task = {
206
+ taskId: createTaskId("task-005"),
207
+ title: "Complex task",
208
+ description: "Complex description",
209
+ filesToModify: [],
210
+ dependsOn: [],
211
+ priority: 1,
212
+ status: "running",
213
+ retryCount: 0,
214
+ };
215
+
216
+ const workspace: WorkspaceInfo = {
217
+ path: "/workspace",
218
+ language: "typescript",
219
+ packageManager: "bun",
220
+ framework: "hono",
221
+ testFramework: "bun-test",
222
+ };
223
+
224
+ const mockProvider: ClaudeProvider = {
225
+ async call(request: ClaudeRequest): Promise<ClaudeResponse> {
226
+ expect(request.effortLevel).toBe("high");
227
+ expect(request.model).toBe("claude-opus-4-6");
228
+
229
+ return {
230
+ result: "OK",
231
+ exitCode: 0,
232
+ model: "claude-opus-4-6",
233
+ effortLevel: "high",
234
+ duration: 2000,
235
+ };
236
+ },
237
+ };
238
+
239
+ await runTesterRed(task, workspace, mockProvider, {
240
+ effortLevel: "high",
241
+ model: "claude-opus-4-6",
242
+ });
243
+ });
244
+
245
+ test("respects timeout option", async () => {
246
+ const task: Task = {
247
+ taskId: createTaskId("task-006"),
248
+ title: "Test task",
249
+ description: "Test description",
250
+ filesToModify: [],
251
+ dependsOn: [],
252
+ priority: 1,
253
+ status: "running",
254
+ retryCount: 0,
255
+ };
256
+
257
+ const workspace: WorkspaceInfo = {
258
+ path: "/workspace",
259
+ language: "typescript",
260
+ packageManager: "bun",
261
+ framework: "hono",
262
+ testFramework: "bun-test",
263
+ };
264
+
265
+ const mockProvider: ClaudeProvider = {
266
+ async call(request: ClaudeRequest): Promise<ClaudeResponse> {
267
+ expect(request.timeout).toBe(60000);
268
+
269
+ return {
270
+ result: "OK",
271
+ exitCode: 0,
272
+ model: "claude-sonnet-4-5",
273
+ effortLevel: "medium",
274
+ duration: 1000,
275
+ };
276
+ },
277
+ };
278
+
279
+ await runTesterRed(task, workspace, mockProvider, { timeout: 60000 });
280
+ });
281
+ });