vibeman 0.0.3 → 0.0.5

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 (184) hide show
  1. package/dist/index.js +3 -3
  2. package/dist/runtime/api/.tsbuildinfo +1 -1
  3. package/dist/runtime/api/agent/agent-service.d.ts +4 -0
  4. package/dist/runtime/api/agent/agent-service.js +62 -3
  5. package/dist/runtime/api/agent/ai-providers/amp-cli-provider.d.ts +38 -0
  6. package/dist/runtime/api/agent/ai-providers/amp-cli-provider.js +268 -0
  7. package/dist/runtime/api/agent/ai-providers/codex-cli-provider.js +40 -12
  8. package/dist/runtime/api/agent/ai-providers/gemini-cli-provider.d.ts +24 -0
  9. package/dist/runtime/api/agent/ai-providers/gemini-cli-provider.js +291 -0
  10. package/dist/runtime/api/agent/ai-providers/index.d.ts +3 -3
  11. package/dist/runtime/api/agent/ai-providers/index.js +3 -1
  12. package/dist/runtime/api/agent/ai-providers/types.d.ts +5 -2
  13. package/dist/runtime/api/agent/amp-cli-provider.test.d.ts +1 -0
  14. package/dist/runtime/api/agent/amp-cli-provider.test.js +99 -0
  15. package/dist/runtime/api/agent/codex-cli-provider.test.js +10 -8
  16. package/dist/runtime/api/agent/prompt-service.js +108 -105
  17. package/dist/runtime/api/agent/prompt-service.test.js +35 -0
  18. package/dist/runtime/api/agent/routing-policy.d.ts +2 -2
  19. package/dist/runtime/api/agent/routing-policy.test.js +4 -4
  20. package/dist/runtime/api/api/routers/ai.d.ts +3 -3
  21. package/dist/runtime/api/api/routers/executions.d.ts +2 -7
  22. package/dist/runtime/api/api/routers/executions.js +2 -2
  23. package/dist/runtime/api/api/routers/provider-config.d.ts +34 -0
  24. package/dist/runtime/api/api/routers/settings.d.ts +19 -0
  25. package/dist/runtime/api/api/routers/settings.js +16 -0
  26. package/dist/runtime/api/api/routers/tasks.d.ts +9 -9
  27. package/dist/runtime/api/api/routers/workflows.d.ts +12 -12
  28. package/dist/runtime/api/api/routers/worktrees.d.ts +2 -2
  29. package/dist/runtime/api/api/trpc.d.ts +16 -16
  30. package/dist/runtime/api/lib/local-config.d.ts +94 -4
  31. package/dist/runtime/api/lib/local-config.js +16 -0
  32. package/dist/runtime/api/lib/provider-detection.d.ts +2 -0
  33. package/dist/runtime/api/lib/provider-detection.js +83 -1
  34. package/dist/runtime/api/lib/server/vibeman-info.d.ts +5 -0
  35. package/dist/runtime/api/lib/server/vibeman-info.js +85 -0
  36. package/dist/runtime/api/lib/trpc/server.d.ts +63 -33
  37. package/dist/runtime/api/persistence/execution-log-persistence.d.ts +1 -1
  38. package/dist/runtime/api/persistence/execution-log-persistence.js +19 -3
  39. package/dist/runtime/api/router.d.ts +63 -33
  40. package/dist/runtime/api/settings-service.js +31 -14
  41. package/dist/runtime/api/tasks/task-file-parser.d.ts +1 -0
  42. package/dist/runtime/api/tasks/task-file-parser.js +20 -1
  43. package/dist/runtime/api/tasks/task-updater.d.ts +62 -0
  44. package/dist/runtime/api/tasks/task-updater.js +260 -0
  45. package/dist/runtime/api/tasks/task-updater.test.d.ts +1 -0
  46. package/dist/runtime/api/tasks/task-updater.test.js +303 -0
  47. package/dist/runtime/api/types/index.d.ts +1 -1
  48. package/dist/runtime/api/types/settings.d.ts +17 -6
  49. package/dist/runtime/api/vcs/git-service.d.ts +9 -0
  50. package/dist/runtime/api/vcs/git-service.js +23 -0
  51. package/dist/runtime/api/vcs/worktree-service.d.ts +1 -1
  52. package/dist/runtime/api/vcs/worktree-service.js +22 -10
  53. package/dist/runtime/api/workflows/quality-pipeline.js +2 -1
  54. package/dist/runtime/api/workflows/vibing-orchestrator.d.ts +93 -5
  55. package/dist/runtime/api/workflows/vibing-orchestrator.js +774 -203
  56. package/dist/runtime/api/workflows/workflow-effects.d.ts +45 -0
  57. package/dist/runtime/api/workflows/workflow-effects.js +49 -0
  58. package/dist/runtime/api/workflows/workflow-reconciler.d.ts +65 -0
  59. package/dist/runtime/api/workflows/workflow-reconciler.js +226 -0
  60. package/dist/runtime/api/workflows/workflow-reducer.d.ts +26 -0
  61. package/dist/runtime/api/workflows/workflow-reducer.js +288 -0
  62. package/dist/runtime/api/workflows/workflow-reducer.test.d.ts +1 -0
  63. package/dist/runtime/api/workflows/workflow-reducer.test.js +247 -0
  64. package/dist/runtime/api/workflows/workflow-schema.d.ts +546 -0
  65. package/dist/runtime/api/workflows/workflow-schema.js +256 -0
  66. package/dist/runtime/web/.next/BUILD_ID +1 -1
  67. package/dist/runtime/web/.next/app-build-manifest.json +50 -50
  68. package/dist/runtime/web/.next/app-path-routes-manifest.json +1 -1
  69. package/dist/runtime/web/.next/build-manifest.json +14 -14
  70. package/dist/runtime/web/.next/prerender-manifest.json +3 -3
  71. package/dist/runtime/web/.next/react-loadable-manifest.json +2 -33
  72. package/dist/runtime/web/.next/required-server-files.json +5 -5
  73. package/dist/runtime/web/.next/server/app/.vibeman/assets/images/[...path]/route.js +1 -1
  74. package/dist/runtime/web/.next/server/app/.vibeman/assets/images/[...path]/route.js.nft.json +1 -1
  75. package/dist/runtime/web/.next/server/app/.vibeman/assets/images/[...path]/route_client-reference-manifest.js +1 -1
  76. package/dist/runtime/web/.next/server/app/_not-found/page.js +2 -2
  77. package/dist/runtime/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  78. package/dist/runtime/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  79. package/dist/runtime/web/.next/server/app/_not-found.html +2 -2
  80. package/dist/runtime/web/.next/server/app/_not-found.rsc +12 -12
  81. package/dist/runtime/web/.next/server/app/api/health/route.js +1 -1
  82. package/dist/runtime/web/.next/server/app/api/health/route.js.nft.json +1 -1
  83. package/dist/runtime/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -1
  84. package/dist/runtime/web/.next/server/app/api/images/[...path]/route.js +1 -1
  85. package/dist/runtime/web/.next/server/app/api/images/[...path]/route.js.nft.json +1 -1
  86. package/dist/runtime/web/.next/server/app/api/images/[...path]/route_client-reference-manifest.js +1 -1
  87. package/dist/runtime/web/.next/server/app/api/upload/route.js +1 -1
  88. package/dist/runtime/web/.next/server/app/api/upload/route.js.nft.json +1 -1
  89. package/dist/runtime/web/.next/server/app/api/upload/route_client-reference-manifest.js +1 -1
  90. package/dist/runtime/web/.next/server/app/index.html +2 -2
  91. package/dist/runtime/web/.next/server/app/index.rsc +15 -15
  92. package/dist/runtime/web/.next/server/app/page.js +27 -62
  93. package/dist/runtime/web/.next/server/app/page.js.nft.json +1 -1
  94. package/dist/runtime/web/.next/server/app/page_client-reference-manifest.js +1 -1
  95. package/dist/runtime/web/.next/server/app-paths-manifest.json +1 -1
  96. package/dist/runtime/web/.next/server/chunks/210.js +1 -0
  97. package/dist/runtime/web/.next/server/chunks/291.js +18 -0
  98. package/dist/runtime/web/.next/server/chunks/552.js +22 -0
  99. package/dist/runtime/web/.next/server/chunks/780.js +1 -0
  100. package/dist/runtime/web/.next/server/chunks/905.js +6 -0
  101. package/dist/runtime/web/.next/server/chunks/98.js +1 -0
  102. package/dist/runtime/web/.next/server/middleware-build-manifest.js +1 -1
  103. package/dist/runtime/web/.next/server/middleware-react-loadable-manifest.js +1 -1
  104. package/dist/runtime/web/.next/server/pages/404.html +2 -2
  105. package/dist/runtime/web/.next/server/pages/500.html +1 -1
  106. package/dist/runtime/web/.next/server/pages/_app.js +1 -1
  107. package/dist/runtime/web/.next/server/pages/_app.js.nft.json +1 -1
  108. package/dist/runtime/web/.next/server/pages/_document.js +1 -1
  109. package/dist/runtime/web/.next/server/pages/_document.js.nft.json +1 -1
  110. package/dist/runtime/web/.next/server/pages/_error.js +9 -9
  111. package/dist/runtime/web/.next/server/pages/_error.js.nft.json +1 -1
  112. package/dist/runtime/web/.next/server/pages-manifest.json +1 -1
  113. package/dist/runtime/web/.next/server/server-reference-manifest.json +1 -1
  114. package/dist/runtime/web/.next/server/webpack-runtime.js +1 -1
  115. package/dist/runtime/web/.next/static/{5_15u1WQCxN1_eHZpldCv → LJFZk_8tvKFN_Ee4HqUuM}/_buildManifest.js +1 -1
  116. package/dist/runtime/web/.next/static/chunks/05c91ade-7d09b2b280adffd1.js +1 -0
  117. package/dist/runtime/web/.next/static/chunks/201-51bef3fa8c832e2e.js +1 -0
  118. package/dist/runtime/web/.next/static/chunks/524-89747ed9b0294f8a.js +1 -0
  119. package/dist/runtime/web/.next/static/chunks/554-8bec6e9cca6acc67.js +1 -0
  120. package/dist/runtime/web/.next/static/chunks/764.86e9503a69d45a85.js +1 -0
  121. package/dist/runtime/web/.next/static/chunks/{87c73c54-09e1ba5c70e60a51.js → 7ab4dc20-239138e0ae7af24a.js} +1 -1
  122. package/dist/runtime/web/.next/static/chunks/905-342391e3d3a3678f.js +20 -0
  123. package/dist/runtime/web/.next/static/chunks/a8a5ce16-4edea7df2d9b544a.js +79 -0
  124. package/dist/runtime/web/.next/static/chunks/{8bb4d8db-3e2aa02b0a2384b9.js → ad74d572-4c1b162e2c15acaa.js} +1 -1
  125. package/dist/runtime/web/.next/static/chunks/app/.vibeman/assets/images/[...path]/route-7b752a8641f96c1f.js +1 -0
  126. package/dist/runtime/web/.next/static/chunks/app/_not-found/page-34e66b251c2b5044.js +1 -0
  127. package/dist/runtime/web/.next/static/chunks/app/api/health/route-7b752a8641f96c1f.js +1 -0
  128. package/dist/runtime/web/.next/static/chunks/app/api/images/[...path]/route-7b752a8641f96c1f.js +1 -0
  129. package/dist/runtime/web/.next/static/chunks/app/api/upload/route-7b752a8641f96c1f.js +1 -0
  130. package/dist/runtime/web/.next/static/chunks/app/layout-df9ac93cb02b2385.js +1 -0
  131. package/dist/runtime/web/.next/static/chunks/app/page-6610743f7de5f92a.js +1 -0
  132. package/dist/runtime/web/.next/static/chunks/c25e0690-e9b798b8de667da1.js +1 -0
  133. package/dist/runtime/web/.next/static/chunks/framework-57157ec4d37f64aa.js +1 -0
  134. package/dist/runtime/web/.next/static/chunks/main-app-156cc0c60371bd78.js +1 -0
  135. package/dist/runtime/web/.next/static/chunks/main-df25d367c47b1fec.js +1 -0
  136. package/dist/runtime/web/.next/static/chunks/pages/_app-9f629a5e1131d19f.js +1 -0
  137. package/dist/runtime/web/.next/static/chunks/pages/_error-9238238274c7efcd.js +1 -0
  138. package/dist/runtime/web/.next/static/chunks/webpack-cd50e39b423d1808.js +1 -0
  139. package/dist/runtime/web/.next/static/css/4fbf378a264bd4ea.css +1 -0
  140. package/dist/runtime/web/package.json +8 -8
  141. package/dist/runtime/web/server.js +1 -1
  142. package/dist/tsconfig.tsbuildinfo +1 -1
  143. package/package.json +3 -37
  144. package/dist/runtime/api/lib/trpc/client.d.ts +0 -1
  145. package/dist/runtime/api/lib/trpc/client.js +0 -5
  146. package/dist/runtime/web/.next/server/chunks/217.js +0 -1
  147. package/dist/runtime/web/.next/server/chunks/383.js +0 -6
  148. package/dist/runtime/web/.next/server/chunks/458.js +0 -1
  149. package/dist/runtime/web/.next/server/chunks/576.js +0 -18
  150. package/dist/runtime/web/.next/server/chunks/635.js +0 -22
  151. package/dist/runtime/web/.next/server/chunks/761.js +0 -1
  152. package/dist/runtime/web/.next/server/chunks/777.js +0 -3
  153. package/dist/runtime/web/.next/server/chunks/825.js +0 -1
  154. package/dist/runtime/web/.next/server/chunks/838.js +0 -1
  155. package/dist/runtime/web/.next/server/chunks/973.js +0 -15
  156. package/dist/runtime/web/.next/static/chunks/18-15c10d3288afef2e.js +0 -1
  157. package/dist/runtime/web/.next/static/chunks/1c0ca389.537bbe362e3ffbd9.js +0 -3
  158. package/dist/runtime/web/.next/static/chunks/22747d63-ad5da0c19f4cfe41.js +0 -71
  159. package/dist/runtime/web/.next/static/chunks/355.056c2645878a799a.js +0 -1
  160. package/dist/runtime/web/.next/static/chunks/420.a5ccf151c9e2b2f1.js +0 -1
  161. package/dist/runtime/web/.next/static/chunks/439.1be0c6242fd248d5.js +0 -15
  162. package/dist/runtime/web/.next/static/chunks/440.c52e7c0f797e22b2.js +0 -1
  163. package/dist/runtime/web/.next/static/chunks/575-e2478287c27da87b.js +0 -1
  164. package/dist/runtime/web/.next/static/chunks/691.920d88c115087314.js +0 -1
  165. package/dist/runtime/web/.next/static/chunks/765-e838910065b50c3d.js +0 -1
  166. package/dist/runtime/web/.next/static/chunks/823-6f371a6e829adbba.js +0 -63
  167. package/dist/runtime/web/.next/static/chunks/891cff7f.0f71fc028f87e683.js +0 -1
  168. package/dist/runtime/web/.next/static/chunks/9af238c7-271a911d4e99ab18.js +0 -1
  169. package/dist/runtime/web/.next/static/chunks/app/.vibeman/assets/images/[...path]/route-751c9265a65409e5.js +0 -1
  170. package/dist/runtime/web/.next/static/chunks/app/_not-found/page-1cb74d1cba27d0ab.js +0 -1
  171. package/dist/runtime/web/.next/static/chunks/app/api/health/route-751c9265a65409e5.js +0 -1
  172. package/dist/runtime/web/.next/static/chunks/app/api/images/[...path]/route-751c9265a65409e5.js +0 -1
  173. package/dist/runtime/web/.next/static/chunks/app/api/upload/route-751c9265a65409e5.js +0 -1
  174. package/dist/runtime/web/.next/static/chunks/app/layout-8435322f09fd0975.js +0 -1
  175. package/dist/runtime/web/.next/static/chunks/app/page-9fe7d75095b4ccec.js +0 -1
  176. package/dist/runtime/web/.next/static/chunks/cac567b0-5b77dd12911823cd.js +0 -1
  177. package/dist/runtime/web/.next/static/chunks/framework-2518f1345b5b2806.js +0 -1
  178. package/dist/runtime/web/.next/static/chunks/main-17665e5e39de9a8a.js +0 -1
  179. package/dist/runtime/web/.next/static/chunks/main-app-c0b0f5ba4f7f9d75.js +0 -1
  180. package/dist/runtime/web/.next/static/chunks/pages/_app-d6f6b3bbc3d81ee1.js +0 -1
  181. package/dist/runtime/web/.next/static/chunks/pages/_error-75a96cf1997cc3b9.js +0 -1
  182. package/dist/runtime/web/.next/static/chunks/webpack-c8de37305b4635cf.js +0 -1
  183. package/dist/runtime/web/.next/static/css/08c950681f1a9a92.css +0 -1
  184. /package/dist/runtime/web/.next/static/{5_15u1WQCxN1_eHZpldCv → LJFZk_8tvKFN_Ee4HqUuM}/_ssgManifest.js +0 -0
@@ -0,0 +1,247 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { reduce, computeNextAction, createInitialState } from './workflow-reducer.js';
3
+ const defaultConfig = {
4
+ autoQualityChecks: true,
5
+ requireHumanApproval: true,
6
+ aiCodeReview: true,
7
+ stepByStepMode: false,
8
+ autoCommit: false,
9
+ retryPolicy: { maxImplementationAttempts: 3 },
10
+ };
11
+ function createTestState(overrides = {}) {
12
+ const base = createInitialState('wf-test-1', 'task-test-1', defaultConfig);
13
+ return { ...base, ...overrides, config: { ...base.config, ...overrides.config } };
14
+ }
15
+ describe('workflow-reducer', () => {
16
+ describe('reduce()', () => {
17
+ describe('START event', () => {
18
+ it('transitions from draft to implementing', () => {
19
+ const state = createTestState({ phase: 'draft' });
20
+ const event = { type: 'START' };
21
+ const result = reduce(state, event);
22
+ expect(result.state.phase).toBe('implementing');
23
+ expect(result.effects).toContainEqual({ type: 'EXECUTE_IMPLEMENTATION' });
24
+ expect(result.effects).toContainEqual({ type: 'SAVE_WORKFLOW' });
25
+ });
26
+ it('does nothing if already implementing', () => {
27
+ const state = createTestState({ phase: 'implementing' });
28
+ const event = { type: 'START' };
29
+ const result = reduce(state, event);
30
+ expect(result.state.phase).toBe('implementing');
31
+ expect(result.effects).toHaveLength(0);
32
+ });
33
+ });
34
+ describe('IMPL_SUCCESS event', () => {
35
+ it('transitions from implementing to validating', () => {
36
+ const state = createTestState({ phase: 'implementing' });
37
+ const event = { type: 'IMPL_SUCCESS', executionId: 'exec-1' };
38
+ const result = reduce(state, event);
39
+ expect(result.state.phase).toBe('validating');
40
+ expect(result.state.executionIds.implementing).toContain('exec-1');
41
+ });
42
+ it('triggers validation in non-step-by-step mode', () => {
43
+ const state = createTestState({ phase: 'implementing' });
44
+ const event = { type: 'IMPL_SUCCESS' };
45
+ const result = reduce(state, event);
46
+ expect(result.effects).toContainEqual({ type: 'EXECUTE_VALIDATION' });
47
+ });
48
+ it('does not trigger validation in step-by-step mode', () => {
49
+ const state = createTestState({
50
+ phase: 'implementing',
51
+ config: { ...defaultConfig, stepByStepMode: true },
52
+ });
53
+ const event = { type: 'IMPL_SUCCESS' };
54
+ const result = reduce(state, event);
55
+ expect(result.effects).not.toContainEqual({ type: 'EXECUTE_VALIDATION' });
56
+ });
57
+ });
58
+ describe('IMPL_FAIL event', () => {
59
+ it('retries if under max attempts', () => {
60
+ const state = createTestState({
61
+ phase: 'implementing',
62
+ attempts: { implementing: 0 },
63
+ });
64
+ const event = { type: 'IMPL_FAIL', error: 'Test error', canRetry: true };
65
+ const result = reduce(state, event);
66
+ expect(result.state.phase).toBe('implementing');
67
+ expect(result.state.attempts.implementing).toBe(1);
68
+ expect(result.state.rerunContext?.reason).toBe('Test error');
69
+ });
70
+ it('fails if max attempts exceeded', () => {
71
+ const state = createTestState({
72
+ phase: 'implementing',
73
+ attempts: { implementing: 2 },
74
+ });
75
+ const event = { type: 'IMPL_FAIL', error: 'Test error', canRetry: true };
76
+ const result = reduce(state, event);
77
+ expect(result.state.terminalStatus).toBe('failed');
78
+ expect(result.state.error).toBe('Test error');
79
+ });
80
+ it('fails immediately if canRetry is false', () => {
81
+ const state = createTestState({
82
+ phase: 'implementing',
83
+ attempts: { implementing: 0 },
84
+ });
85
+ const event = { type: 'IMPL_FAIL', error: 'Test error', canRetry: false };
86
+ const result = reduce(state, event);
87
+ expect(result.state.terminalStatus).toBe('failed');
88
+ });
89
+ });
90
+ describe('VALID_SUCCESS event', () => {
91
+ it('transitions to approved when AI review is enabled', () => {
92
+ const state = createTestState({
93
+ phase: 'validating',
94
+ config: { ...defaultConfig, aiCodeReview: true },
95
+ });
96
+ const event = {
97
+ type: 'VALID_SUCCESS',
98
+ results: { overall: true, timestamp: new Date().toISOString(), details: {}, outputs: {} },
99
+ };
100
+ const result = reduce(state, event);
101
+ expect(result.state.phase).toBe('approved');
102
+ expect(result.state.qualityResults?.overall).toBe(true);
103
+ });
104
+ it('transitions to merging when no approval needed', () => {
105
+ const state = createTestState({
106
+ phase: 'validating',
107
+ config: { ...defaultConfig, aiCodeReview: false, requireHumanApproval: false },
108
+ });
109
+ const event = {
110
+ type: 'VALID_SUCCESS',
111
+ results: { overall: true, timestamp: new Date().toISOString(), details: {}, outputs: {} },
112
+ };
113
+ const result = reduce(state, event);
114
+ expect(result.state.phase).toBe('merging');
115
+ });
116
+ });
117
+ describe('PAUSE event', () => {
118
+ it('sets terminal status to paused from any active phase', () => {
119
+ const state = createTestState({ phase: 'implementing' });
120
+ const event = { type: 'PAUSE' };
121
+ const result = reduce(state, event);
122
+ expect(result.state.terminalStatus).toBe('paused');
123
+ expect(result.effects).toContainEqual({ type: 'STOP_EXECUTION' });
124
+ });
125
+ });
126
+ describe('RESUME event', () => {
127
+ it('clears terminal status and restores phase', () => {
128
+ const state = createTestState({
129
+ phase: 'implementing',
130
+ terminalStatus: 'paused',
131
+ });
132
+ const event = { type: 'RESUME' };
133
+ const result = reduce(state, event);
134
+ expect(result.state.terminalStatus).toBeNull();
135
+ expect(result.state.phase).toBe('implementing');
136
+ });
137
+ });
138
+ describe('APPROVE event', () => {
139
+ it('transitions from approved to merging', () => {
140
+ const state = createTestState({ phase: 'approved' });
141
+ const event = { type: 'APPROVE' };
142
+ const result = reduce(state, event);
143
+ expect(result.state.phase).toBe('merging');
144
+ });
145
+ });
146
+ describe('REJECT event', () => {
147
+ it('transitions from approved back to implementing', () => {
148
+ const state = createTestState({ phase: 'approved' });
149
+ const event = { type: 'REJECT', feedback: 'Please fix X' };
150
+ const result = reduce(state, event);
151
+ expect(result.state.phase).toBe('implementing');
152
+ expect(result.state.rerunContext?.feedback).toBe('Please fix X');
153
+ });
154
+ });
155
+ describe('MERGE_SUCCESS event', () => {
156
+ it('transitions from merging to done', () => {
157
+ const state = createTestState({ phase: 'merging' });
158
+ const event = {
159
+ type: 'MERGE_SUCCESS',
160
+ prUrl: 'https://github.com/pr/1',
161
+ prNumber: 1,
162
+ };
163
+ const result = reduce(state, event);
164
+ expect(result.state.phase).toBe('done');
165
+ expect(result.state.links.prUrl).toBe('https://github.com/pr/1');
166
+ expect(result.state.links.prNumber).toBe(1);
167
+ expect(result.state.endTime).toBeDefined();
168
+ });
169
+ });
170
+ describe('RETRY event', () => {
171
+ it('returns to implementing from failed state', () => {
172
+ const state = createTestState({
173
+ phase: 'implementing',
174
+ terminalStatus: 'failed',
175
+ });
176
+ const event = { type: 'RETRY' };
177
+ const result = reduce(state, event);
178
+ expect(result.state.phase).toBe('implementing');
179
+ expect(result.state.terminalStatus).toBeNull();
180
+ expect(result.effects).toContainEqual({ type: 'EXECUTE_IMPLEMENTATION' });
181
+ });
182
+ });
183
+ });
184
+ describe('computeNextAction()', () => {
185
+ it('returns implementing for draft phase', () => {
186
+ const state = createTestState({ phase: 'draft' });
187
+ const action = computeNextAction(state);
188
+ expect(action).toEqual({ action: 'implementing' });
189
+ });
190
+ it('returns validating for validating phase', () => {
191
+ const state = createTestState({ phase: 'validating' });
192
+ const action = computeNextAction(state);
193
+ expect(action).toEqual({ action: 'validating' });
194
+ });
195
+ it('returns ai-reviewing for approved phase with aiCodeReview enabled and no result', () => {
196
+ const state = createTestState({
197
+ phase: 'approved',
198
+ config: { ...defaultConfig, aiCodeReview: true },
199
+ });
200
+ const action = computeNextAction(state);
201
+ expect(action).toEqual({ action: 'ai-reviewing' });
202
+ });
203
+ it('returns awaiting-approval for approved phase with humanApproval required', () => {
204
+ const state = createTestState({
205
+ phase: 'approved',
206
+ config: { ...defaultConfig, aiCodeReview: false, requireHumanApproval: true },
207
+ });
208
+ const action = computeNextAction(state);
209
+ expect(action).toEqual({ action: 'awaiting-approval' });
210
+ });
211
+ it('returns merging for approved phase without approval requirements', () => {
212
+ const state = createTestState({
213
+ phase: 'approved',
214
+ config: { ...defaultConfig, aiCodeReview: false, requireHumanApproval: false },
215
+ });
216
+ const action = computeNextAction(state);
217
+ expect(action).toEqual({ action: 'merging' });
218
+ });
219
+ it('returns none for done phase', () => {
220
+ const state = createTestState({ phase: 'done' });
221
+ const action = computeNextAction(state);
222
+ expect(action).toEqual({ action: 'none', reason: 'Workflow completed' });
223
+ });
224
+ it('returns implementing with feedback for paused state', () => {
225
+ const state = createTestState({
226
+ phase: 'implementing',
227
+ terminalStatus: 'paused',
228
+ rerunContext: { reason: 'test', feedback: 'Fix the bug' },
229
+ });
230
+ const action = computeNextAction(state);
231
+ expect(action).toEqual({ action: 'implementing', feedback: 'Fix the bug' });
232
+ });
233
+ it('returns implementing with error for failed state', () => {
234
+ const state = createTestState({
235
+ phase: 'implementing',
236
+ terminalStatus: 'failed',
237
+ failureContext: {
238
+ atPhase: 'implementing',
239
+ error: 'Build failed',
240
+ timestamp: new Date().toISOString(),
241
+ },
242
+ });
243
+ const action = computeNextAction(state);
244
+ expect(action).toEqual({ action: 'implementing', feedback: 'Build failed' });
245
+ });
246
+ });
247
+ });