@marktoflow/gui 2.0.0-alpha.1

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 (165) hide show
  1. package/.turbo/turbo-build.log +26 -0
  2. package/.turbo/turbo-test.log +22 -0
  3. package/README.md +179 -0
  4. package/dist/client/assets/index-DwTI8opO.js +608 -0
  5. package/dist/client/assets/index-DwTI8opO.js.map +1 -0
  6. package/dist/client/assets/index-RoEdL6gO.css +1 -0
  7. package/dist/client/index.html +20 -0
  8. package/dist/client/vite.svg +9 -0
  9. package/dist/server/index.d.ts +3 -0
  10. package/dist/server/index.d.ts.map +1 -0
  11. package/dist/server/index.js +56 -0
  12. package/dist/server/index.js.map +1 -0
  13. package/dist/server/routes/ai.js +50 -0
  14. package/dist/server/routes/ai.js.map +1 -0
  15. package/dist/server/routes/execute.js +62 -0
  16. package/dist/server/routes/execute.js.map +1 -0
  17. package/dist/server/routes/workflows.js +99 -0
  18. package/dist/server/routes/workflows.js.map +1 -0
  19. package/dist/server/server/index.js +95 -0
  20. package/dist/server/server/index.js.map +1 -0
  21. package/dist/server/server/routes/ai.js +87 -0
  22. package/dist/server/server/routes/ai.js.map +1 -0
  23. package/dist/server/server/routes/execute.js +63 -0
  24. package/dist/server/server/routes/execute.js.map +1 -0
  25. package/dist/server/server/routes/tools.js +518 -0
  26. package/dist/server/server/routes/tools.js.map +1 -0
  27. package/dist/server/server/routes/workflows.js +99 -0
  28. package/dist/server/server/routes/workflows.js.map +1 -0
  29. package/dist/server/server/services/AIService.js +69 -0
  30. package/dist/server/server/services/AIService.js.map +1 -0
  31. package/dist/server/server/services/FileWatcher.js +60 -0
  32. package/dist/server/server/services/FileWatcher.js.map +1 -0
  33. package/dist/server/server/services/WorkflowService.js +363 -0
  34. package/dist/server/server/services/WorkflowService.js.map +1 -0
  35. package/dist/server/server/services/agents/claude-code-provider.js +250 -0
  36. package/dist/server/server/services/agents/claude-code-provider.js.map +1 -0
  37. package/dist/server/server/services/agents/claude-provider.js +204 -0
  38. package/dist/server/server/services/agents/claude-provider.js.map +1 -0
  39. package/dist/server/server/services/agents/copilot-provider.js +227 -0
  40. package/dist/server/server/services/agents/copilot-provider.js.map +1 -0
  41. package/dist/server/server/services/agents/demo-provider.js +167 -0
  42. package/dist/server/server/services/agents/demo-provider.js.map +1 -0
  43. package/dist/server/server/services/agents/index.js +31 -0
  44. package/dist/server/server/services/agents/index.js.map +1 -0
  45. package/dist/server/server/services/agents/ollama-provider.js +220 -0
  46. package/dist/server/server/services/agents/ollama-provider.js.map +1 -0
  47. package/dist/server/server/services/agents/prompts.js +436 -0
  48. package/dist/server/server/services/agents/prompts.js.map +1 -0
  49. package/dist/server/server/services/agents/registry.js +242 -0
  50. package/dist/server/server/services/agents/registry.js.map +1 -0
  51. package/dist/server/server/services/agents/types.js +6 -0
  52. package/dist/server/server/services/agents/types.js.map +1 -0
  53. package/dist/server/server/websocket/index.js +85 -0
  54. package/dist/server/server/websocket/index.js.map +1 -0
  55. package/dist/server/services/AIService.d.ts +30 -0
  56. package/dist/server/services/AIService.d.ts.map +1 -0
  57. package/dist/server/services/AIService.js +216 -0
  58. package/dist/server/services/AIService.js.map +1 -0
  59. package/dist/server/services/FileWatcher.d.ts +10 -0
  60. package/dist/server/services/FileWatcher.d.ts.map +1 -0
  61. package/dist/server/services/FileWatcher.js +62 -0
  62. package/dist/server/services/FileWatcher.js.map +1 -0
  63. package/dist/server/services/WorkflowService.d.ts +54 -0
  64. package/dist/server/services/WorkflowService.d.ts.map +1 -0
  65. package/dist/server/services/WorkflowService.js +323 -0
  66. package/dist/server/services/WorkflowService.js.map +1 -0
  67. package/dist/server/shared/constants.js +175 -0
  68. package/dist/server/shared/constants.js.map +1 -0
  69. package/dist/server/shared/types.js +3 -0
  70. package/dist/server/shared/types.js.map +1 -0
  71. package/dist/server/websocket/index.d.ts +10 -0
  72. package/dist/server/websocket/index.d.ts.map +1 -0
  73. package/dist/server/websocket/index.js +85 -0
  74. package/dist/server/websocket/index.js.map +1 -0
  75. package/index.html +19 -0
  76. package/package.json +96 -0
  77. package/playwright.config.ts +27 -0
  78. package/postcss.config.js +6 -0
  79. package/public/vite.svg +9 -0
  80. package/src/client/App.tsx +520 -0
  81. package/src/client/components/Canvas/Canvas.tsx +405 -0
  82. package/src/client/components/Canvas/ExecutionOverlay.tsx +847 -0
  83. package/src/client/components/Canvas/NodeContextMenu.tsx +188 -0
  84. package/src/client/components/Canvas/OutputNode.tsx +111 -0
  85. package/src/client/components/Canvas/StepNode.tsx +106 -0
  86. package/src/client/components/Canvas/SubWorkflowNode.tsx +141 -0
  87. package/src/client/components/Canvas/Toolbar.tsx +189 -0
  88. package/src/client/components/Canvas/TriggerNode.tsx +128 -0
  89. package/src/client/components/Editor/InputsEditor.tsx +458 -0
  90. package/src/client/components/Editor/NewStepWizard.tsx +344 -0
  91. package/src/client/components/Editor/StepEditor.tsx +532 -0
  92. package/src/client/components/Editor/YamlEditor.tsx +160 -0
  93. package/src/client/components/Panels/PropertiesPanel.tsx +589 -0
  94. package/src/client/components/Prompt/ChangePreview.tsx +281 -0
  95. package/src/client/components/Prompt/PromptHistoryPanel.tsx +209 -0
  96. package/src/client/components/Prompt/PromptInput.tsx +108 -0
  97. package/src/client/components/Sidebar/Sidebar.tsx +343 -0
  98. package/src/client/components/common/Breadcrumb.tsx +40 -0
  99. package/src/client/components/common/Button.tsx +68 -0
  100. package/src/client/components/common/ContextMenu.tsx +202 -0
  101. package/src/client/components/common/KeyboardShortcuts.tsx +143 -0
  102. package/src/client/components/common/Modal.tsx +93 -0
  103. package/src/client/components/common/Tabs.tsx +57 -0
  104. package/src/client/components/common/ThemeToggle.tsx +63 -0
  105. package/src/client/components/index.ts +32 -0
  106. package/src/client/hooks/index.ts +4 -0
  107. package/src/client/hooks/useAIPrompt.ts +108 -0
  108. package/src/client/hooks/useCanvas.ts +247 -0
  109. package/src/client/hooks/useWebSocket.ts +164 -0
  110. package/src/client/hooks/useWorkflow.ts +138 -0
  111. package/src/client/main.tsx +10 -0
  112. package/src/client/stores/canvasStore.ts +348 -0
  113. package/src/client/stores/editorStore.ts +133 -0
  114. package/src/client/stores/executionStore.ts +440 -0
  115. package/src/client/stores/index.ts +4 -0
  116. package/src/client/stores/layoutStore.ts +103 -0
  117. package/src/client/stores/navigationStore.ts +49 -0
  118. package/src/client/stores/promptStore.ts +113 -0
  119. package/src/client/stores/themeStore.ts +75 -0
  120. package/src/client/stores/workflowStore.ts +177 -0
  121. package/src/client/styles/globals.css +346 -0
  122. package/src/client/utils/cn.ts +9 -0
  123. package/src/client/utils/index.ts +4 -0
  124. package/src/client/utils/serviceIcons.tsx +64 -0
  125. package/src/client/utils/stepValidation.ts +155 -0
  126. package/src/client/utils/workflowToGraph.ts +299 -0
  127. package/src/server/index.ts +114 -0
  128. package/src/server/routes/ai.ts +91 -0
  129. package/src/server/routes/execute.ts +71 -0
  130. package/src/server/routes/tools.ts +564 -0
  131. package/src/server/routes/workflows.ts +106 -0
  132. package/src/server/services/AIService.ts +105 -0
  133. package/src/server/services/FileWatcher.ts +69 -0
  134. package/src/server/services/WorkflowService.ts +441 -0
  135. package/src/server/services/agents/claude-code-provider.ts +320 -0
  136. package/src/server/services/agents/claude-provider.ts +248 -0
  137. package/src/server/services/agents/copilot-provider.ts +311 -0
  138. package/src/server/services/agents/demo-provider.ts +184 -0
  139. package/src/server/services/agents/index.ts +31 -0
  140. package/src/server/services/agents/ollama-provider.ts +267 -0
  141. package/src/server/services/agents/prompts.ts +482 -0
  142. package/src/server/services/agents/registry.ts +289 -0
  143. package/src/server/services/agents/types.ts +146 -0
  144. package/src/server/websocket/index.ts +104 -0
  145. package/src/shared/constants.ts +180 -0
  146. package/src/shared/types.ts +179 -0
  147. package/tailwind.config.ts +73 -0
  148. package/tests/e2e/app.spec.ts +90 -0
  149. package/tests/e2e/canvas.spec.ts +128 -0
  150. package/tests/e2e/workflow.spec.ts +185 -0
  151. package/tests/integration/api.test.ts +250 -0
  152. package/tests/integration/testApp.ts +31 -0
  153. package/tests/setup.ts +37 -0
  154. package/tests/unit/canvasStore.test.ts +502 -0
  155. package/tests/unit/components.test.tsx +151 -0
  156. package/tests/unit/executionStore.test.ts +527 -0
  157. package/tests/unit/layoutStore.test.ts +194 -0
  158. package/tests/unit/navigationStore.test.ts +152 -0
  159. package/tests/unit/stepValidation.test.ts +226 -0
  160. package/tests/unit/themeStore.test.ts +141 -0
  161. package/tests/unit/workflowToGraph.test.ts +289 -0
  162. package/tsconfig.json +29 -0
  163. package/tsconfig.server.json +28 -0
  164. package/vite.config.ts +31 -0
  165. package/vitest.config.ts +26 -0
@@ -0,0 +1,527 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import { useExecutionStore, formatDuration, formatRelativeTime } from '../../src/client/stores/executionStore';
3
+
4
+ describe('executionStore', () => {
5
+ beforeEach(() => {
6
+ // Reset store state before each test
7
+ useExecutionStore.setState({
8
+ runs: [],
9
+ currentRunId: null,
10
+ isExecuting: false,
11
+ isPaused: false,
12
+ debug: {
13
+ enabled: false,
14
+ breakpoints: new Set(),
15
+ currentStepId: null,
16
+ pausedAtBreakpoint: false,
17
+ stepOverPending: false,
18
+ watchExpressions: [],
19
+ callStack: [],
20
+ },
21
+ });
22
+ });
23
+
24
+ describe('startExecution', () => {
25
+ it('should create a new execution run', () => {
26
+ const { startExecution } = useExecutionStore.getState();
27
+
28
+ const runId = startExecution('workflow-1', 'Test Workflow');
29
+
30
+ const state = useExecutionStore.getState();
31
+ expect(runId).toBeDefined();
32
+ expect(state.currentRunId).toBe(runId);
33
+ expect(state.isExecuting).toBe(true);
34
+ expect(state.isPaused).toBe(false);
35
+ expect(state.runs).toHaveLength(1);
36
+ expect(state.runs[0].workflowId).toBe('workflow-1');
37
+ expect(state.runs[0].workflowName).toBe('Test Workflow');
38
+ expect(state.runs[0].status).toBe('running');
39
+ });
40
+
41
+ it('should include inputs in the run', () => {
42
+ const { startExecution } = useExecutionStore.getState();
43
+
44
+ const inputs = { repo: 'owner/repo', pr: 123 };
45
+ const runId = startExecution('workflow-1', 'Test', inputs);
46
+
47
+ const state = useExecutionStore.getState();
48
+ expect(state.runs[0].inputs).toEqual(inputs);
49
+ });
50
+
51
+ it('should limit runs to 50', () => {
52
+ const { startExecution } = useExecutionStore.getState();
53
+
54
+ // Create 55 runs
55
+ for (let i = 0; i < 55; i++) {
56
+ startExecution('wf-' + i, 'Workflow ' + i);
57
+ // Manually complete each run so we can start another
58
+ useExecutionStore.setState({ isExecuting: false, currentRunId: null });
59
+ }
60
+
61
+ const state = useExecutionStore.getState();
62
+ expect(state.runs).toHaveLength(50);
63
+ });
64
+ });
65
+
66
+ describe('updateStepStatus', () => {
67
+ it('should add a new step when it does not exist', () => {
68
+ const { startExecution, updateStepStatus } = useExecutionStore.getState();
69
+
70
+ const runId = startExecution('wf-1', 'Test');
71
+ updateStepStatus(runId, 'step-1', 'running');
72
+
73
+ const state = useExecutionStore.getState();
74
+ const run = state.runs.find(r => r.id === runId);
75
+ expect(run?.steps).toHaveLength(1);
76
+ expect(run?.steps[0].stepId).toBe('step-1');
77
+ expect(run?.steps[0].status).toBe('running');
78
+ });
79
+
80
+ it('should update an existing step', () => {
81
+ const { startExecution, updateStepStatus } = useExecutionStore.getState();
82
+
83
+ const runId = startExecution('wf-1', 'Test');
84
+ updateStepStatus(runId, 'step-1', 'running');
85
+ updateStepStatus(runId, 'step-1', 'completed');
86
+
87
+ const state = useExecutionStore.getState();
88
+ const run = state.runs.find(r => r.id === runId);
89
+ expect(run?.steps).toHaveLength(1);
90
+ expect(run?.steps[0].status).toBe('completed');
91
+ });
92
+
93
+ it('should record error on failed step', () => {
94
+ const { startExecution, updateStepStatus } = useExecutionStore.getState();
95
+
96
+ const runId = startExecution('wf-1', 'Test');
97
+ updateStepStatus(runId, 'step-1', 'running');
98
+ updateStepStatus(runId, 'step-1', 'failed', undefined, 'Something went wrong');
99
+
100
+ const state = useExecutionStore.getState();
101
+ const run = state.runs.find(r => r.id === runId);
102
+ expect(run?.steps[0].error).toBe('Something went wrong');
103
+ });
104
+ });
105
+
106
+ describe('completeExecution', () => {
107
+ it('should mark execution as completed', () => {
108
+ const { startExecution, completeExecution } = useExecutionStore.getState();
109
+
110
+ const runId = startExecution('wf-1', 'Test');
111
+ completeExecution(runId, 'completed', { result: 'success' });
112
+
113
+ const state = useExecutionStore.getState();
114
+ expect(state.isExecuting).toBe(false);
115
+ expect(state.currentRunId).toBeNull();
116
+
117
+ const run = state.runs.find(r => r.id === runId);
118
+ expect(run?.status).toBe('completed');
119
+ expect(run?.outputs).toEqual({ result: 'success' });
120
+ expect(run?.endTime).toBeDefined();
121
+ expect(run?.duration).toBeDefined();
122
+ });
123
+
124
+ it('should mark execution as failed', () => {
125
+ const { startExecution, completeExecution } = useExecutionStore.getState();
126
+
127
+ const runId = startExecution('wf-1', 'Test');
128
+ completeExecution(runId, 'failed');
129
+
130
+ const state = useExecutionStore.getState();
131
+ const run = state.runs.find(r => r.id === runId);
132
+ expect(run?.status).toBe('failed');
133
+ });
134
+ });
135
+
136
+ describe('addLog', () => {
137
+ it('should add a log message to the run', () => {
138
+ const { startExecution, addLog } = useExecutionStore.getState();
139
+
140
+ const runId = startExecution('wf-1', 'Test');
141
+ addLog(runId, 'Test message');
142
+
143
+ const state = useExecutionStore.getState();
144
+ const run = state.runs.find(r => r.id === runId);
145
+ const hasMessage = run?.logs.some(log => log.includes('Test message'));
146
+ expect(hasMessage).toBe(true);
147
+ });
148
+ });
149
+
150
+ describe('pauseExecution / resumeExecution', () => {
151
+ it('should pause execution', () => {
152
+ const { startExecution, pauseExecution } = useExecutionStore.getState();
153
+
154
+ startExecution('wf-1', 'Test');
155
+ pauseExecution();
156
+
157
+ const state = useExecutionStore.getState();
158
+ expect(state.isPaused).toBe(true);
159
+ });
160
+
161
+ it('should resume execution', () => {
162
+ const { startExecution, pauseExecution, resumeExecution } = useExecutionStore.getState();
163
+
164
+ startExecution('wf-1', 'Test');
165
+ pauseExecution();
166
+ resumeExecution();
167
+
168
+ const state = useExecutionStore.getState();
169
+ expect(state.isPaused).toBe(false);
170
+ });
171
+ });
172
+
173
+ describe('cancelExecution', () => {
174
+ it('should cancel and complete execution', () => {
175
+ const { startExecution, cancelExecution } = useExecutionStore.getState();
176
+
177
+ const runId = startExecution('wf-1', 'Test');
178
+ cancelExecution(runId);
179
+
180
+ const state = useExecutionStore.getState();
181
+ expect(state.isExecuting).toBe(false);
182
+
183
+ const run = state.runs.find(r => r.id === runId);
184
+ expect(run?.status).toBe('cancelled');
185
+ });
186
+ });
187
+
188
+ describe('clearHistory', () => {
189
+ it('should clear all runs', () => {
190
+ const { startExecution, clearHistory, completeExecution } = useExecutionStore.getState();
191
+
192
+ const runId = startExecution('wf-1', 'Test');
193
+ completeExecution(runId, 'completed');
194
+
195
+ clearHistory();
196
+
197
+ const state = useExecutionStore.getState();
198
+ expect(state.runs).toHaveLength(0);
199
+ });
200
+ });
201
+
202
+ describe('getRun', () => {
203
+ it('should return a run by ID', () => {
204
+ const { startExecution, getRun } = useExecutionStore.getState();
205
+
206
+ const runId = startExecution('wf-1', 'Test');
207
+ const run = getRun(runId);
208
+
209
+ expect(run).toBeDefined();
210
+ expect(run?.id).toBe(runId);
211
+ });
212
+
213
+ it('should return undefined for non-existent run', () => {
214
+ const { getRun } = useExecutionStore.getState();
215
+
216
+ const run = getRun('non-existent');
217
+ expect(run).toBeUndefined();
218
+ });
219
+ });
220
+
221
+ // Debug mode tests
222
+ describe('debug mode', () => {
223
+ describe('enableDebugMode / disableDebugMode', () => {
224
+ it('should enable debug mode', () => {
225
+ const { enableDebugMode } = useExecutionStore.getState();
226
+
227
+ enableDebugMode();
228
+
229
+ const state = useExecutionStore.getState();
230
+ expect(state.debug.enabled).toBe(true);
231
+ });
232
+
233
+ it('should disable debug mode but preserve breakpoints', () => {
234
+ const { enableDebugMode, disableDebugMode, toggleBreakpoint } = useExecutionStore.getState();
235
+
236
+ enableDebugMode();
237
+ toggleBreakpoint('step-1');
238
+ toggleBreakpoint('step-2');
239
+ disableDebugMode();
240
+
241
+ const state = useExecutionStore.getState();
242
+ expect(state.debug.enabled).toBe(false);
243
+ expect(state.debug.breakpoints.has('step-1')).toBe(true);
244
+ expect(state.debug.breakpoints.has('step-2')).toBe(true);
245
+ });
246
+
247
+ it('should reset other debug state when disabling', () => {
248
+ const { enableDebugMode, disableDebugMode, setCurrentDebugStep, addWatchExpression } = useExecutionStore.getState();
249
+
250
+ enableDebugMode();
251
+ setCurrentDebugStep('step-1');
252
+ addWatchExpression('variable.foo');
253
+
254
+ disableDebugMode();
255
+
256
+ const state = useExecutionStore.getState();
257
+ expect(state.debug.currentStepId).toBeNull();
258
+ expect(state.debug.pausedAtBreakpoint).toBe(false);
259
+ expect(state.debug.stepOverPending).toBe(false);
260
+ expect(state.debug.callStack).toHaveLength(0);
261
+ });
262
+ });
263
+
264
+ describe('toggleBreakpoint / hasBreakpoint / clearAllBreakpoints', () => {
265
+ it('should add a breakpoint', () => {
266
+ const { toggleBreakpoint, hasBreakpoint } = useExecutionStore.getState();
267
+
268
+ toggleBreakpoint('step-1');
269
+
270
+ expect(hasBreakpoint('step-1')).toBe(true);
271
+ expect(hasBreakpoint('step-2')).toBe(false);
272
+ });
273
+
274
+ it('should remove a breakpoint when toggled twice', () => {
275
+ const { toggleBreakpoint, hasBreakpoint } = useExecutionStore.getState();
276
+
277
+ toggleBreakpoint('step-1');
278
+ toggleBreakpoint('step-1');
279
+
280
+ expect(hasBreakpoint('step-1')).toBe(false);
281
+ });
282
+
283
+ it('should clear all breakpoints', () => {
284
+ const { toggleBreakpoint, clearAllBreakpoints, hasBreakpoint } = useExecutionStore.getState();
285
+
286
+ toggleBreakpoint('step-1');
287
+ toggleBreakpoint('step-2');
288
+ toggleBreakpoint('step-3');
289
+
290
+ clearAllBreakpoints();
291
+
292
+ const state = useExecutionStore.getState();
293
+ expect(state.debug.breakpoints.size).toBe(0);
294
+ expect(hasBreakpoint('step-1')).toBe(false);
295
+ });
296
+ });
297
+
298
+ describe('stepOver / stepInto / stepOut', () => {
299
+ it('should set stepOverPending when stepping over', () => {
300
+ const { enableDebugMode, startExecution, pauseExecution, stepOver } = useExecutionStore.getState();
301
+
302
+ enableDebugMode();
303
+ startExecution('wf-1', 'Test');
304
+ pauseExecution();
305
+
306
+ stepOver();
307
+
308
+ const state = useExecutionStore.getState();
309
+ expect(state.isPaused).toBe(false);
310
+ expect(state.debug.stepOverPending).toBe(true);
311
+ });
312
+
313
+ it('should not step over when not paused', () => {
314
+ const { enableDebugMode, startExecution, stepOver } = useExecutionStore.getState();
315
+
316
+ enableDebugMode();
317
+ startExecution('wf-1', 'Test');
318
+
319
+ stepOver();
320
+
321
+ const state = useExecutionStore.getState();
322
+ expect(state.debug.stepOverPending).toBe(false);
323
+ });
324
+
325
+ it('should not step over when debug mode is disabled', () => {
326
+ const { startExecution, pauseExecution, stepOver } = useExecutionStore.getState();
327
+
328
+ startExecution('wf-1', 'Test');
329
+ pauseExecution();
330
+
331
+ stepOver();
332
+
333
+ const state = useExecutionStore.getState();
334
+ expect(state.isPaused).toBe(true); // Should still be paused
335
+ });
336
+
337
+ it('stepInto should work like stepOver', () => {
338
+ const { enableDebugMode, startExecution, pauseExecution, stepInto } = useExecutionStore.getState();
339
+
340
+ enableDebugMode();
341
+ startExecution('wf-1', 'Test');
342
+ pauseExecution();
343
+
344
+ stepInto();
345
+
346
+ const state = useExecutionStore.getState();
347
+ expect(state.isPaused).toBe(false);
348
+ expect(state.debug.stepOverPending).toBe(true);
349
+ });
350
+
351
+ it('stepOut should resume without stepOverPending', () => {
352
+ const { enableDebugMode, startExecution, pauseExecution, stepOut } = useExecutionStore.getState();
353
+
354
+ enableDebugMode();
355
+ startExecution('wf-1', 'Test');
356
+ pauseExecution();
357
+
358
+ stepOut();
359
+
360
+ const state = useExecutionStore.getState();
361
+ expect(state.isPaused).toBe(false);
362
+ expect(state.debug.stepOverPending).toBe(false);
363
+ });
364
+ });
365
+
366
+ describe('setCurrentDebugStep', () => {
367
+ it('should set the current debug step', () => {
368
+ const { setCurrentDebugStep } = useExecutionStore.getState();
369
+
370
+ setCurrentDebugStep('step-5');
371
+
372
+ const state = useExecutionStore.getState();
373
+ expect(state.debug.currentStepId).toBe('step-5');
374
+ });
375
+
376
+ it('should clear the current debug step when set to null', () => {
377
+ const { setCurrentDebugStep } = useExecutionStore.getState();
378
+
379
+ setCurrentDebugStep('step-5');
380
+ setCurrentDebugStep(null);
381
+
382
+ const state = useExecutionStore.getState();
383
+ expect(state.debug.currentStepId).toBeNull();
384
+ });
385
+ });
386
+
387
+ describe('watch expressions', () => {
388
+ it('should add a watch expression', () => {
389
+ const { addWatchExpression } = useExecutionStore.getState();
390
+
391
+ addWatchExpression('variable.foo');
392
+
393
+ const state = useExecutionStore.getState();
394
+ expect(state.debug.watchExpressions).toContain('variable.foo');
395
+ });
396
+
397
+ it('should not add duplicate watch expressions', () => {
398
+ const { addWatchExpression } = useExecutionStore.getState();
399
+
400
+ addWatchExpression('variable.foo');
401
+ addWatchExpression('variable.foo');
402
+
403
+ const state = useExecutionStore.getState();
404
+ expect(state.debug.watchExpressions.filter(e => e === 'variable.foo')).toHaveLength(1);
405
+ });
406
+
407
+ it('should remove a watch expression', () => {
408
+ const { addWatchExpression, removeWatchExpression } = useExecutionStore.getState();
409
+
410
+ addWatchExpression('variable.foo');
411
+ addWatchExpression('variable.bar');
412
+ removeWatchExpression('variable.foo');
413
+
414
+ const state = useExecutionStore.getState();
415
+ expect(state.debug.watchExpressions).not.toContain('variable.foo');
416
+ expect(state.debug.watchExpressions).toContain('variable.bar');
417
+ });
418
+ });
419
+
420
+ describe('updateCallStack', () => {
421
+ it('should update the call stack', () => {
422
+ const { updateCallStack } = useExecutionStore.getState();
423
+
424
+ const stack = ['main', 'sub-workflow-1', 'step-3'];
425
+ updateCallStack(stack);
426
+
427
+ const state = useExecutionStore.getState();
428
+ expect(state.debug.callStack).toEqual(stack);
429
+ });
430
+
431
+ it('should clear the call stack with empty array', () => {
432
+ const { updateCallStack } = useExecutionStore.getState();
433
+
434
+ updateCallStack(['main', 'sub-workflow-1']);
435
+ updateCallStack([]);
436
+
437
+ const state = useExecutionStore.getState();
438
+ expect(state.debug.callStack).toHaveLength(0);
439
+ });
440
+ });
441
+
442
+ describe('breakpoint pause behavior', () => {
443
+ it('should pause at breakpoint when debug mode is enabled', () => {
444
+ const { enableDebugMode, toggleBreakpoint, startExecution, updateStepStatus } = useExecutionStore.getState();
445
+
446
+ enableDebugMode();
447
+ toggleBreakpoint('step-2');
448
+
449
+ const runId = startExecution('wf-1', 'Test');
450
+ updateStepStatus(runId, 'step-2', 'running');
451
+
452
+ const state = useExecutionStore.getState();
453
+ expect(state.isPaused).toBe(true);
454
+ expect(state.debug.pausedAtBreakpoint).toBe(true);
455
+ expect(state.debug.currentStepId).toBe('step-2');
456
+ });
457
+
458
+ it('should not pause at breakpoint when debug mode is disabled', () => {
459
+ const { toggleBreakpoint, startExecution, updateStepStatus } = useExecutionStore.getState();
460
+
461
+ toggleBreakpoint('step-2');
462
+
463
+ const runId = startExecution('wf-1', 'Test');
464
+ updateStepStatus(runId, 'step-2', 'running');
465
+
466
+ const state = useExecutionStore.getState();
467
+ expect(state.isPaused).toBe(false);
468
+ expect(state.debug.pausedAtBreakpoint).toBe(false);
469
+ });
470
+
471
+ it('should not pause at step without breakpoint', () => {
472
+ const { enableDebugMode, toggleBreakpoint, startExecution, updateStepStatus } = useExecutionStore.getState();
473
+
474
+ enableDebugMode();
475
+ toggleBreakpoint('step-1'); // Breakpoint on step-1, not step-2
476
+
477
+ const runId = startExecution('wf-1', 'Test');
478
+ updateStepStatus(runId, 'step-2', 'running');
479
+
480
+ const state = useExecutionStore.getState();
481
+ expect(state.isPaused).toBe(false);
482
+ expect(state.debug.pausedAtBreakpoint).toBe(false);
483
+ });
484
+ });
485
+ });
486
+ });
487
+
488
+ describe('formatDuration', () => {
489
+ it('should format milliseconds', () => {
490
+ expect(formatDuration(500)).toBe('500ms');
491
+ expect(formatDuration(999)).toBe('999ms');
492
+ });
493
+
494
+ it('should format seconds', () => {
495
+ expect(formatDuration(1000)).toBe('1.0s');
496
+ expect(formatDuration(2500)).toBe('2.5s');
497
+ expect(formatDuration(59999)).toBe('60.0s');
498
+ });
499
+
500
+ it('should format minutes and seconds', () => {
501
+ expect(formatDuration(60000)).toBe('1m 0s');
502
+ expect(formatDuration(90000)).toBe('1m 30s');
503
+ expect(formatDuration(125000)).toBe('2m 5s');
504
+ });
505
+ });
506
+
507
+ describe('formatRelativeTime', () => {
508
+ it('should format just now', () => {
509
+ const now = new Date().toISOString();
510
+ expect(formatRelativeTime(now)).toBe('just now');
511
+ });
512
+
513
+ it('should format minutes ago', () => {
514
+ const fiveMinAgo = new Date(Date.now() - 5 * 60 * 1000).toISOString();
515
+ expect(formatRelativeTime(fiveMinAgo)).toBe('5 min ago');
516
+ });
517
+
518
+ it('should format hours ago', () => {
519
+ const twoHoursAgo = new Date(Date.now() - 2 * 60 * 60 * 1000).toISOString();
520
+ expect(formatRelativeTime(twoHoursAgo)).toBe('2 hours ago');
521
+ });
522
+
523
+ it('should format days ago', () => {
524
+ const threeDaysAgo = new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString();
525
+ expect(formatRelativeTime(threeDaysAgo)).toBe('3 days ago');
526
+ });
527
+ });