@marktoflow/gui 2.0.0-alpha.1 → 2.0.0-alpha.3
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/.turbo/turbo-build.log +7 -7
- package/README.md +38 -2
- package/dist/client/assets/index-C90Y_aBX.js +678 -0
- package/dist/client/assets/index-C90Y_aBX.js.map +1 -0
- package/dist/client/assets/index-CRWeQ3NN.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/server/index.js +1 -1
- package/dist/server/server/routes/tools.js +406 -0
- package/dist/server/server/routes/tools.js.map +1 -1
- package/dist/server/server/services/agents/codex-provider.js +270 -0
- package/dist/server/server/services/agents/codex-provider.js.map +1 -0
- package/dist/server/server/services/agents/prompts.js +27 -0
- package/dist/server/server/services/agents/prompts.js.map +1 -1
- package/dist/server/server/services/agents/registry.js +20 -0
- package/dist/server/server/services/agents/registry.js.map +1 -1
- package/package.json +6 -6
- package/src/client/components/Canvas/Canvas.tsx +24 -6
- package/src/client/components/Canvas/ForEachNode.tsx +128 -0
- package/src/client/components/Canvas/IfElseNode.tsx +126 -0
- package/src/client/components/Canvas/ParallelNode.tsx +140 -0
- package/src/client/components/Canvas/SwitchNode.tsx +164 -0
- package/src/client/components/Canvas/TransformNode.tsx +185 -0
- package/src/client/components/Canvas/TryCatchNode.tsx +164 -0
- package/src/client/components/Canvas/WhileNode.tsx +129 -0
- package/src/client/components/Canvas/index.ts +24 -0
- package/src/client/utils/serviceIcons.tsx +33 -0
- package/src/server/index.ts +1 -1
- package/src/server/routes/tools.ts +406 -0
- package/src/server/services/agents/codex-provider.ts +398 -0
- package/src/server/services/agents/prompts.ts +27 -0
- package/src/server/services/agents/registry.ts +21 -0
- package/tailwind.config.ts +1 -1
- package/tests/integration/api.test.ts +203 -1
- package/tests/integration/testApp.ts +1 -1
- package/tests/setup.ts +35 -0
- package/tests/unit/ForEachNode.test.tsx +218 -0
- package/tests/unit/IfElseNode.test.tsx +188 -0
- package/tests/unit/ParallelNode.test.tsx +264 -0
- package/tests/unit/SwitchNode.test.tsx +252 -0
- package/tests/unit/TransformNode.test.tsx +386 -0
- package/tests/unit/TryCatchNode.test.tsx +243 -0
- package/tests/unit/WhileNode.test.tsx +226 -0
- package/tests/unit/codexProvider.test.ts +399 -0
- package/tests/unit/serviceIcons.test.ts +197 -0
- package/.turbo/turbo-test.log +0 -22
- package/dist/client/assets/index-DwTI8opO.js +0 -608
- package/dist/client/assets/index-DwTI8opO.js.map +0 -1
- package/dist/client/assets/index-RoEdL6gO.css +0 -1
- package/dist/server/index.d.ts +0 -3
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -56
- package/dist/server/index.js.map +0 -1
- package/dist/server/routes/ai.js +0 -50
- package/dist/server/routes/ai.js.map +0 -1
- package/dist/server/routes/execute.js +0 -62
- package/dist/server/routes/execute.js.map +0 -1
- package/dist/server/routes/workflows.js +0 -99
- package/dist/server/routes/workflows.js.map +0 -1
- package/dist/server/services/AIService.d.ts +0 -30
- package/dist/server/services/AIService.d.ts.map +0 -1
- package/dist/server/services/AIService.js +0 -216
- package/dist/server/services/AIService.js.map +0 -1
- package/dist/server/services/FileWatcher.d.ts +0 -10
- package/dist/server/services/FileWatcher.d.ts.map +0 -1
- package/dist/server/services/FileWatcher.js +0 -62
- package/dist/server/services/FileWatcher.js.map +0 -1
- package/dist/server/services/WorkflowService.d.ts +0 -54
- package/dist/server/services/WorkflowService.d.ts.map +0 -1
- package/dist/server/services/WorkflowService.js +0 -323
- package/dist/server/services/WorkflowService.js.map +0 -1
- package/dist/server/websocket/index.d.ts +0 -10
- package/dist/server/websocket/index.d.ts.map +0 -1
- package/dist/server/websocket/index.js +0 -85
- package/dist/server/websocket/index.js.map +0 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { ReactFlowProvider } from '@xyflow/react';
|
|
4
|
+
import { WhileNode, type WhileNodeData } from '../../src/client/components/Canvas/WhileNode';
|
|
5
|
+
|
|
6
|
+
const createMockNode = (data: Partial<WhileNodeData> = {}) => ({
|
|
7
|
+
id: 'while-1',
|
|
8
|
+
type: 'while' as const,
|
|
9
|
+
position: { x: 0, y: 0 },
|
|
10
|
+
data: {
|
|
11
|
+
id: 'while-1',
|
|
12
|
+
name: 'Retry API',
|
|
13
|
+
condition: '{{ retries < 3 }}',
|
|
14
|
+
maxIterations: 10,
|
|
15
|
+
status: 'pending' as const,
|
|
16
|
+
...data,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const renderNode = (data: Partial<WhileNodeData> = {}) => {
|
|
21
|
+
const node = createMockNode(data);
|
|
22
|
+
return render(
|
|
23
|
+
<ReactFlowProvider>
|
|
24
|
+
<WhileNode
|
|
25
|
+
id={node.id}
|
|
26
|
+
type={node.type}
|
|
27
|
+
data={node.data}
|
|
28
|
+
selected={false}
|
|
29
|
+
isConnectable={true}
|
|
30
|
+
zIndex={0}
|
|
31
|
+
positionAbsoluteX={0}
|
|
32
|
+
positionAbsoluteY={0}
|
|
33
|
+
dragging={false}
|
|
34
|
+
/>
|
|
35
|
+
</ReactFlowProvider>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe('WhileNode', () => {
|
|
40
|
+
it('should render node with name, condition, and max iterations', () => {
|
|
41
|
+
renderNode();
|
|
42
|
+
|
|
43
|
+
expect(screen.getByText('Retry API')).toBeInTheDocument();
|
|
44
|
+
expect(screen.getByText('Loop')).toBeInTheDocument();
|
|
45
|
+
expect(screen.getByText('{{ retries < 3 }}')).toBeInTheDocument();
|
|
46
|
+
expect(screen.getByText('10')).toBeInTheDocument();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should render default name when name is not provided', () => {
|
|
50
|
+
renderNode({ name: undefined });
|
|
51
|
+
|
|
52
|
+
expect(screen.getByText('While')).toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should display condition label', () => {
|
|
56
|
+
renderNode();
|
|
57
|
+
|
|
58
|
+
expect(screen.getByText('Condition:')).toBeInTheDocument();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should display "Not set" when condition is empty', () => {
|
|
62
|
+
renderNode({ condition: '' });
|
|
63
|
+
|
|
64
|
+
expect(screen.getByText('Not set')).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should display max iterations label', () => {
|
|
68
|
+
renderNode();
|
|
69
|
+
|
|
70
|
+
expect(screen.getByText('Max Iterations:')).toBeInTheDocument();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should display default max iterations when not provided', () => {
|
|
74
|
+
renderNode({ maxIterations: undefined });
|
|
75
|
+
|
|
76
|
+
expect(screen.getByText('100')).toBeInTheDocument();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('status states', () => {
|
|
80
|
+
it('should render pending status', () => {
|
|
81
|
+
renderNode({ status: 'pending' });
|
|
82
|
+
|
|
83
|
+
const node = screen.getByText('Retry API').closest('.control-flow-node');
|
|
84
|
+
expect(node).toBeInTheDocument();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should render running status with animation', () => {
|
|
88
|
+
renderNode({ status: 'running' });
|
|
89
|
+
|
|
90
|
+
const node = screen.getByText('Retry API').closest('.control-flow-node');
|
|
91
|
+
expect(node).toHaveClass('running');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should render completed status', () => {
|
|
95
|
+
renderNode({ status: 'completed' });
|
|
96
|
+
|
|
97
|
+
const node = screen.getByText('Retry API').closest('.control-flow-node');
|
|
98
|
+
expect(node).toBeInTheDocument();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should render failed status', () => {
|
|
102
|
+
renderNode({ status: 'failed' });
|
|
103
|
+
|
|
104
|
+
const node = screen.getByText('Retry API').closest('.control-flow-node');
|
|
105
|
+
expect(node).toBeInTheDocument();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe('iteration progress', () => {
|
|
110
|
+
it('should display current iteration when provided', () => {
|
|
111
|
+
renderNode({
|
|
112
|
+
currentIteration: 3,
|
|
113
|
+
maxIterations: 10,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
expect(screen.getByText('Iterations')).toBeInTheDocument();
|
|
117
|
+
expect(screen.getByText('3 / 10')).toBeInTheDocument();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should display progress bar with correct width', () => {
|
|
121
|
+
const { container } = renderNode({
|
|
122
|
+
currentIteration: 5,
|
|
123
|
+
maxIterations: 10,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const progressBar = container.querySelector('.bg-orange-400');
|
|
127
|
+
expect(progressBar).toHaveStyle({ width: '50%' });
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should display 0% progress when currentIteration is 0', () => {
|
|
131
|
+
const { container } = renderNode({
|
|
132
|
+
currentIteration: 0,
|
|
133
|
+
maxIterations: 10,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const progressBar = container.querySelector('.bg-orange-400');
|
|
137
|
+
expect(progressBar).toHaveStyle({ width: '0%' });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should display 100% progress when at max iterations', () => {
|
|
141
|
+
const { container } = renderNode({
|
|
142
|
+
currentIteration: 10,
|
|
143
|
+
maxIterations: 10,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const progressBar = container.querySelector('.bg-orange-400');
|
|
147
|
+
expect(progressBar).toHaveStyle({ width: '100%' });
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should not display progress when currentIteration is undefined', () => {
|
|
151
|
+
renderNode({ currentIteration: undefined });
|
|
152
|
+
|
|
153
|
+
expect(screen.queryByText('Iterations')).not.toBeInTheDocument();
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('warning message', () => {
|
|
158
|
+
it('should display exit condition warning', () => {
|
|
159
|
+
renderNode();
|
|
160
|
+
|
|
161
|
+
expect(screen.getByText('⚠️')).toBeInTheDocument();
|
|
162
|
+
expect(screen.getByText('Exits when condition becomes false')).toBeInTheDocument();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('visual styling', () => {
|
|
167
|
+
it('should have orange gradient background', () => {
|
|
168
|
+
renderNode();
|
|
169
|
+
|
|
170
|
+
const node = screen.getByText('Retry API').closest('.control-flow-node');
|
|
171
|
+
expect(node).toHaveStyle({
|
|
172
|
+
background: 'linear-gradient(135deg, #fb923c 0%, #f97316 100%)',
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should display condition with monospace font', () => {
|
|
177
|
+
renderNode();
|
|
178
|
+
|
|
179
|
+
const conditionElement = screen.getByText('{{ retries < 3 }}');
|
|
180
|
+
expect(conditionElement).toHaveClass('font-mono');
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('selection state', () => {
|
|
185
|
+
it('should apply selected class when selected', () => {
|
|
186
|
+
const node = createMockNode();
|
|
187
|
+
const { container } = render(
|
|
188
|
+
<ReactFlowProvider>
|
|
189
|
+
<WhileNode
|
|
190
|
+
id={node.id}
|
|
191
|
+
type={node.type}
|
|
192
|
+
data={node.data}
|
|
193
|
+
selected={true}
|
|
194
|
+
isConnectable={true}
|
|
195
|
+
zIndex={0}
|
|
196
|
+
positionAbsoluteX={0}
|
|
197
|
+
positionAbsoluteY={0}
|
|
198
|
+
dragging={false}
|
|
199
|
+
/>
|
|
200
|
+
</ReactFlowProvider>
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
const nodeElement = container.querySelector('.control-flow-node');
|
|
204
|
+
expect(nodeElement).toHaveClass('selected');
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('max iterations display', () => {
|
|
209
|
+
it('should handle custom max iterations', () => {
|
|
210
|
+
renderNode({ maxIterations: 50 });
|
|
211
|
+
|
|
212
|
+
expect(screen.getByText('50')).toBeInTheDocument();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should show progress against custom max iterations', () => {
|
|
216
|
+
const { container } = renderNode({
|
|
217
|
+
currentIteration: 25,
|
|
218
|
+
maxIterations: 50,
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
expect(screen.getByText('25 / 50')).toBeInTheDocument();
|
|
222
|
+
const progressBar = container.querySelector('.bg-orange-400');
|
|
223
|
+
expect(progressBar).toHaveStyle({ width: '50%' });
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
+
import { CodexProvider, createCodexProvider } from '../../src/server/services/agents/codex-provider.js';
|
|
3
|
+
import type { Workflow, AgentConfig } from '../../src/server/services/agents/types.js';
|
|
4
|
+
|
|
5
|
+
// Mock the Codex SDK
|
|
6
|
+
vi.mock('@openai/codex-sdk', () => ({
|
|
7
|
+
Codex: vi.fn().mockImplementation(() => ({
|
|
8
|
+
startThread: vi.fn().mockReturnValue({
|
|
9
|
+
id: 'test-thread-id',
|
|
10
|
+
run: vi.fn().mockResolvedValue({
|
|
11
|
+
items: [
|
|
12
|
+
{ type: 'agent_message', text: 'Test response with ```yaml\nmetadata:\n name: test\nsteps: []\n```' },
|
|
13
|
+
],
|
|
14
|
+
finalResponse: 'Test response with ```yaml\nmetadata:\n name: test\nsteps: []\n```',
|
|
15
|
+
usage: { input_tokens: 100, cached_input_tokens: 0, output_tokens: 50 },
|
|
16
|
+
}),
|
|
17
|
+
runStreamed: vi.fn().mockResolvedValue({
|
|
18
|
+
events: (async function* () {
|
|
19
|
+
yield { type: 'thread.started', thread_id: 'test-thread-id' };
|
|
20
|
+
yield {
|
|
21
|
+
type: 'item.completed',
|
|
22
|
+
item: { type: 'agent_message', text: 'Streamed response' },
|
|
23
|
+
};
|
|
24
|
+
yield {
|
|
25
|
+
type: 'turn.completed',
|
|
26
|
+
usage: { input_tokens: 100, cached_input_tokens: 0, output_tokens: 50 },
|
|
27
|
+
};
|
|
28
|
+
})(),
|
|
29
|
+
}),
|
|
30
|
+
}),
|
|
31
|
+
resumeThread: vi.fn().mockReturnValue({
|
|
32
|
+
id: 'test-thread-id',
|
|
33
|
+
run: vi.fn().mockResolvedValue({
|
|
34
|
+
items: [{ type: 'agent_message', text: 'Resumed response' }],
|
|
35
|
+
finalResponse: 'Resumed response',
|
|
36
|
+
usage: { input_tokens: 50, cached_input_tokens: 25, output_tokens: 25 },
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
})),
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
describe('CodexProvider', () => {
|
|
43
|
+
let provider: CodexProvider;
|
|
44
|
+
const testWorkflow: Workflow = {
|
|
45
|
+
metadata: { name: 'test-workflow', version: '1.0' },
|
|
46
|
+
steps: [
|
|
47
|
+
{ id: 'step-1', name: 'Test Step', action: 'test.action', inputs: { value: 1 } },
|
|
48
|
+
],
|
|
49
|
+
tools: {},
|
|
50
|
+
inputs: {},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
provider = new CodexProvider();
|
|
55
|
+
vi.clearAllMocks();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('Provider Properties', () => {
|
|
59
|
+
it('should have correct id', () => {
|
|
60
|
+
expect(provider.id).toBe('codex');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should have correct name', () => {
|
|
64
|
+
expect(provider.name).toBe('OpenAI Codex');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should have correct capabilities', () => {
|
|
68
|
+
expect(provider.capabilities.streaming).toBe(true);
|
|
69
|
+
expect(provider.capabilities.toolUse).toBe(true);
|
|
70
|
+
expect(provider.capabilities.codeExecution).toBe(true);
|
|
71
|
+
expect(provider.capabilities.systemPrompts).toBe(true);
|
|
72
|
+
expect(provider.capabilities.models).toContain('codex-1');
|
|
73
|
+
expect(provider.capabilities.models).toContain('o3');
|
|
74
|
+
expect(provider.capabilities.models).toContain('o3-mini');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('initialization', () => {
|
|
79
|
+
it('should not be ready before initialization', () => {
|
|
80
|
+
expect(provider.isReady()).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should initialize with default config', async () => {
|
|
84
|
+
await provider.initialize({});
|
|
85
|
+
expect(provider.isReady()).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should initialize with API key', async () => {
|
|
89
|
+
await provider.initialize({ apiKey: 'test-api-key' });
|
|
90
|
+
expect(provider.isReady()).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should initialize with custom model', async () => {
|
|
94
|
+
await provider.initialize({ model: 'o3' });
|
|
95
|
+
const status = provider.getStatus();
|
|
96
|
+
expect(status.model).toBe('o3');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should initialize with base URL', async () => {
|
|
100
|
+
await provider.initialize({ baseUrl: 'https://custom-api.example.com' });
|
|
101
|
+
expect(provider.isReady()).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should initialize with working directory option', async () => {
|
|
105
|
+
await provider.initialize({
|
|
106
|
+
options: { workingDirectory: '/custom/path' },
|
|
107
|
+
});
|
|
108
|
+
expect(provider.isReady()).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should initialize with cwd option', async () => {
|
|
112
|
+
await provider.initialize({
|
|
113
|
+
options: { cwd: '/custom/path' },
|
|
114
|
+
});
|
|
115
|
+
expect(provider.isReady()).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should initialize with codex path option', async () => {
|
|
119
|
+
await provider.initialize({
|
|
120
|
+
options: { codexPath: '/custom/codex' },
|
|
121
|
+
});
|
|
122
|
+
expect(provider.isReady()).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should initialize with environment variables option', async () => {
|
|
126
|
+
await provider.initialize({
|
|
127
|
+
options: { env: { DEBUG: 'true' } },
|
|
128
|
+
});
|
|
129
|
+
expect(provider.isReady()).toBe(true);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('getStatus', () => {
|
|
134
|
+
it('should return not ready status before initialization', () => {
|
|
135
|
+
const status = provider.getStatus();
|
|
136
|
+
expect(status.ready).toBe(false);
|
|
137
|
+
expect(status.model).toBe('codex-1');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should return ready status after initialization', async () => {
|
|
141
|
+
await provider.initialize({});
|
|
142
|
+
const status = provider.getStatus();
|
|
143
|
+
expect(status.ready).toBe(true);
|
|
144
|
+
expect(status.error).toBeUndefined();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('should return custom model in status', async () => {
|
|
148
|
+
await provider.initialize({ model: 'o4-mini' });
|
|
149
|
+
const status = provider.getStatus();
|
|
150
|
+
expect(status.model).toBe('o4-mini');
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('processPrompt', () => {
|
|
155
|
+
it('should return error when not initialized', async () => {
|
|
156
|
+
const result = await provider.processPrompt('test prompt', testWorkflow);
|
|
157
|
+
expect(result.error).toBeDefined();
|
|
158
|
+
expect(result.explanation).toContain('not available');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should process prompt after initialization', async () => {
|
|
162
|
+
await provider.initialize({});
|
|
163
|
+
const result = await provider.processPrompt('Add a new step', testWorkflow);
|
|
164
|
+
expect(result.explanation).toBeDefined();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should process prompt with context', async () => {
|
|
168
|
+
await provider.initialize({});
|
|
169
|
+
const result = await provider.processPrompt('Modify this step', testWorkflow, {
|
|
170
|
+
selectedStepId: 'step-1',
|
|
171
|
+
recentHistory: ['Previous change 1', 'Previous change 2'],
|
|
172
|
+
});
|
|
173
|
+
expect(result.explanation).toBeDefined();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('should parse YAML from response', async () => {
|
|
177
|
+
await provider.initialize({});
|
|
178
|
+
const result = await provider.processPrompt('Update workflow', testWorkflow);
|
|
179
|
+
// The mock returns a response with YAML, so workflow should be parsed
|
|
180
|
+
expect(result.workflow || result.explanation).toBeDefined();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe('getSuggestions', () => {
|
|
185
|
+
it('should return suggestions for empty workflow', async () => {
|
|
186
|
+
const emptyWorkflow: Workflow = {
|
|
187
|
+
metadata: {},
|
|
188
|
+
steps: [],
|
|
189
|
+
};
|
|
190
|
+
const suggestions = await provider.getSuggestions(emptyWorkflow);
|
|
191
|
+
expect(suggestions).toBeInstanceOf(Array);
|
|
192
|
+
expect(suggestions.length).toBeGreaterThan(0);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('should return suggestions for workflow with steps', async () => {
|
|
196
|
+
const suggestions = await provider.getSuggestions(testWorkflow);
|
|
197
|
+
expect(suggestions).toBeInstanceOf(Array);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('should return step-specific suggestions when step is selected', async () => {
|
|
201
|
+
const suggestions = await provider.getSuggestions(testWorkflow, 'step-1');
|
|
202
|
+
expect(suggestions).toBeInstanceOf(Array);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('streamPrompt', () => {
|
|
207
|
+
it('should fall back to processPrompt when not initialized', async () => {
|
|
208
|
+
const chunks: string[] = [];
|
|
209
|
+
const onChunk = (chunk: string) => chunks.push(chunk);
|
|
210
|
+
|
|
211
|
+
const result = await provider.streamPrompt('test', testWorkflow, onChunk);
|
|
212
|
+
expect(result.error).toBeDefined();
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should stream prompt after initialization', async () => {
|
|
216
|
+
await provider.initialize({});
|
|
217
|
+
const chunks: string[] = [];
|
|
218
|
+
const onChunk = (chunk: string) => chunks.push(chunk);
|
|
219
|
+
|
|
220
|
+
const result = await provider.streamPrompt('Add step', testWorkflow, onChunk);
|
|
221
|
+
expect(result.explanation).toBeDefined();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should stream with context', async () => {
|
|
225
|
+
await provider.initialize({});
|
|
226
|
+
const chunks: string[] = [];
|
|
227
|
+
const onChunk = (chunk: string) => chunks.push(chunk);
|
|
228
|
+
|
|
229
|
+
const result = await provider.streamPrompt('Modify step', testWorkflow, onChunk, {
|
|
230
|
+
selectedStepId: 'step-1',
|
|
231
|
+
});
|
|
232
|
+
expect(result.explanation).toBeDefined();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('cancel', () => {
|
|
237
|
+
it('should reset thread ID on cancel', async () => {
|
|
238
|
+
await provider.initialize({});
|
|
239
|
+
await provider.processPrompt('test', testWorkflow);
|
|
240
|
+
await provider.cancel();
|
|
241
|
+
expect(provider.getLastThreadId()).toBeNull();
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe('resumePrompt', () => {
|
|
246
|
+
it('should return error when not initialized', async () => {
|
|
247
|
+
const result = await provider.resumePrompt('thread-123', 'continue', testWorkflow);
|
|
248
|
+
expect(result.error).toBeDefined();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('should resume thread after initialization', async () => {
|
|
252
|
+
await provider.initialize({});
|
|
253
|
+
const result = await provider.resumePrompt('thread-123', 'Continue the task', testWorkflow);
|
|
254
|
+
expect(result.explanation).toBeDefined();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('should resume with context', async () => {
|
|
258
|
+
await provider.initialize({});
|
|
259
|
+
const result = await provider.resumePrompt(
|
|
260
|
+
'thread-123',
|
|
261
|
+
'Next step',
|
|
262
|
+
testWorkflow,
|
|
263
|
+
{ selectedStepId: 'step-1' }
|
|
264
|
+
);
|
|
265
|
+
expect(result.explanation).toBeDefined();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('getLastThreadId', () => {
|
|
270
|
+
it('should return null initially', () => {
|
|
271
|
+
expect(provider.getLastThreadId()).toBeNull();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('should return thread ID after processing', async () => {
|
|
275
|
+
await provider.initialize({});
|
|
276
|
+
await provider.processPrompt('test', testWorkflow);
|
|
277
|
+
// The mock sets thread ID to 'test-thread-id'
|
|
278
|
+
expect(provider.getLastThreadId()).toBe('test-thread-id');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('parseAIResponse', () => {
|
|
283
|
+
it('should extract workflow from YAML block', async () => {
|
|
284
|
+
await provider.initialize({});
|
|
285
|
+
const result = await provider.processPrompt('test', testWorkflow);
|
|
286
|
+
// The mock response contains YAML, so it should be parsed
|
|
287
|
+
expect(result.workflow || result.explanation).toBeDefined();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('should generate diff for modified workflow', async () => {
|
|
291
|
+
await provider.initialize({});
|
|
292
|
+
const result = await provider.processPrompt('test', testWorkflow);
|
|
293
|
+
// If workflow was parsed, diff should be generated
|
|
294
|
+
if (result.workflow) {
|
|
295
|
+
expect(result.diff).toBeDefined();
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe('createCodexProvider factory', () => {
|
|
301
|
+
it('should create provider instance', () => {
|
|
302
|
+
const provider = createCodexProvider();
|
|
303
|
+
expect(provider).toBeInstanceOf(CodexProvider);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('should create and initialize provider with config', () => {
|
|
307
|
+
const config: AgentConfig = {
|
|
308
|
+
apiKey: 'test-key',
|
|
309
|
+
model: 'o3',
|
|
310
|
+
};
|
|
311
|
+
const provider = createCodexProvider(config);
|
|
312
|
+
expect(provider).toBeInstanceOf(CodexProvider);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe('CodexProvider Error Handling', () => {
|
|
318
|
+
let provider: CodexProvider;
|
|
319
|
+
|
|
320
|
+
beforeEach(() => {
|
|
321
|
+
provider = new CodexProvider();
|
|
322
|
+
vi.clearAllMocks();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('should handle SDK import error gracefully', async () => {
|
|
326
|
+
// Reset the mock to simulate import failure
|
|
327
|
+
vi.doMock('@openai/codex-sdk', () => {
|
|
328
|
+
throw new Error('Module not found');
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
const errorProvider = new CodexProvider();
|
|
332
|
+
// This should handle the error gracefully
|
|
333
|
+
const status = errorProvider.getStatus();
|
|
334
|
+
expect(status.ready).toBe(false);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('should handle thread creation error', async () => {
|
|
338
|
+
// Create a provider and manually set error state
|
|
339
|
+
const errorProvider = new CodexProvider();
|
|
340
|
+
// Simulate error by not initializing
|
|
341
|
+
const result = await errorProvider.processPrompt('test', {
|
|
342
|
+
metadata: {},
|
|
343
|
+
steps: [],
|
|
344
|
+
});
|
|
345
|
+
expect(result.error).toBeDefined();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('should return error in status when initialization fails', async () => {
|
|
349
|
+
const errorProvider = new CodexProvider();
|
|
350
|
+
// Status should show not ready with potential error
|
|
351
|
+
const status = errorProvider.getStatus();
|
|
352
|
+
expect(status.ready).toBe(false);
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
describe('CodexProvider Response Parsing', () => {
|
|
357
|
+
let provider: CodexProvider;
|
|
358
|
+
const mockWorkflow: Workflow = {
|
|
359
|
+
metadata: { name: 'test' },
|
|
360
|
+
steps: [{ id: 'step-1', action: 'test' }],
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
beforeEach(async () => {
|
|
364
|
+
provider = new CodexProvider();
|
|
365
|
+
await provider.initialize({});
|
|
366
|
+
vi.clearAllMocks();
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('should handle response with YAML workflow', async () => {
|
|
370
|
+
// The default mock already returns a response with YAML
|
|
371
|
+
const result = await provider.processPrompt('test', mockWorkflow);
|
|
372
|
+
// Should either have a parsed workflow or explanation
|
|
373
|
+
expect(result.explanation || result.workflow).toBeDefined();
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it('should return explanation when response has content', async () => {
|
|
377
|
+
const result = await provider.processPrompt('test', mockWorkflow);
|
|
378
|
+
// The mock returns a response, so explanation should be defined
|
|
379
|
+
expect(result.explanation).toBeDefined();
|
|
380
|
+
expect(typeof result.explanation).toBe('string');
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('should handle processPrompt with empty workflow', async () => {
|
|
384
|
+
const emptyWorkflow: Workflow = {
|
|
385
|
+
metadata: {},
|
|
386
|
+
steps: [],
|
|
387
|
+
};
|
|
388
|
+
const result = await provider.processPrompt('test', emptyWorkflow);
|
|
389
|
+
expect(result.explanation || result.error).toBeDefined();
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('should generate diff when workflow is modified', async () => {
|
|
393
|
+
const result = await provider.processPrompt('test', mockWorkflow);
|
|
394
|
+
// If workflow was parsed successfully, diff should be generated
|
|
395
|
+
if (result.workflow) {
|
|
396
|
+
expect(result.diff).toBeDefined();
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
});
|