-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnode-executor.test.ts
More file actions
254 lines (233 loc) · 8.62 KB
/
Copy pathnode-executor.test.ts
File metadata and controls
254 lines (233 loc) · 8.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import { describe, it, expect } from 'vitest';
import {
WaitEventTypeSchema,
WaitResumePayloadSchema,
WaitTimeoutBehaviorSchema,
WaitExecutorConfigSchema,
NodeExecutorDescriptorSchema,
WAIT_EXECUTOR_DESCRIPTOR,
type WaitResumePayload,
type WaitExecutorConfig,
type NodeExecutorDescriptor,
} from './node-executor.zod';
// ---------------------------------------------------------------------------
// WaitEventTypeSchema
// ---------------------------------------------------------------------------
describe('WaitEventTypeSchema', () => {
it('should accept all event types', () => {
const types = ['timer', 'signal', 'webhook', 'manual', 'condition'];
types.forEach(t => {
expect(WaitEventTypeSchema.parse(t)).toBe(t);
});
});
it('should reject invalid event type', () => {
expect(() => WaitEventTypeSchema.parse('unknown')).toThrow();
});
});
// ---------------------------------------------------------------------------
// WaitResumePayloadSchema
// ---------------------------------------------------------------------------
describe('WaitResumePayloadSchema', () => {
it('should accept minimal timer resume payload', () => {
const payload: WaitResumePayload = WaitResumePayloadSchema.parse({
executionId: 'exec_001',
checkpointId: 'cp_001',
nodeId: 'wait_timer',
eventType: 'timer',
resumedAt: '2026-02-22T10:00:00Z',
});
expect(payload.executionId).toBe('exec_001');
expect(payload.eventType).toBe('timer');
});
it('should accept signal resume with signal name', () => {
const payload = WaitResumePayloadSchema.parse({
executionId: 'exec_002',
checkpointId: 'cp_002',
nodeId: 'wait_signal',
eventType: 'signal',
signalName: 'payment_received',
resumedBy: 'system',
resumedAt: '2026-02-22T10:05:00Z',
});
expect(payload.signalName).toBe('payment_received');
expect(payload.resumedBy).toBe('system');
});
it('should accept webhook resume with payload data', () => {
const payload = WaitResumePayloadSchema.parse({
executionId: 'exec_003',
checkpointId: 'cp_003',
nodeId: 'wait_webhook',
eventType: 'webhook',
webhookPayload: {
status: 'approved',
approver: 'user_123',
timestamp: '2026-02-22T11:00:00Z',
},
resumedAt: '2026-02-22T11:00:00Z',
});
expect(payload.webhookPayload?.status).toBe('approved');
});
it('should accept manual resume with variables', () => {
const payload = WaitResumePayloadSchema.parse({
executionId: 'exec_004',
checkpointId: 'cp_004',
nodeId: 'wait_manual',
eventType: 'manual',
resumedBy: 'admin_user',
resumedAt: '2026-02-22T12:00:00Z',
variables: {
approved: true,
reason: 'Looks good',
},
});
expect(payload.variables?.approved).toBe(true);
expect(payload.resumedBy).toBe('admin_user');
});
it('should accept condition resume', () => {
const payload = WaitResumePayloadSchema.parse({
executionId: 'exec_005',
checkpointId: 'cp_005',
nodeId: 'wait_condition',
eventType: 'condition',
resumedAt: '2026-02-22T13:00:00Z',
});
expect(payload.eventType).toBe('condition');
});
it('should reject without required fields', () => {
expect(() => WaitResumePayloadSchema.parse({})).toThrow();
expect(() => WaitResumePayloadSchema.parse({
executionId: 'exec_001',
})).toThrow();
});
});
// ---------------------------------------------------------------------------
// WaitTimeoutBehaviorSchema
// ---------------------------------------------------------------------------
describe('WaitTimeoutBehaviorSchema', () => {
it('should accept all timeout behaviors', () => {
['fail', 'continue', 'fallback'].forEach(b => {
expect(WaitTimeoutBehaviorSchema.parse(b)).toBe(b);
});
});
});
// ---------------------------------------------------------------------------
// WaitExecutorConfigSchema
// ---------------------------------------------------------------------------
describe('WaitExecutorConfigSchema', () => {
it('should accept empty config with defaults', () => {
const config: WaitExecutorConfig = WaitExecutorConfigSchema.parse({});
expect(config.defaultTimeoutMs).toBe(86400000);
expect(config.defaultTimeoutBehavior).toBe('fail');
expect(config.conditionPollIntervalMs).toBe(30000);
expect(config.conditionMaxPolls).toBe(0);
expect(config.webhookUrlPattern).toBe('/api/v1/automation/resume/{executionId}/{nodeId}');
expect(config.persistCheckpoints).toBe(true);
expect(config.maxPausedExecutions).toBe(0);
});
it('should accept custom config', () => {
const config = WaitExecutorConfigSchema.parse({
defaultTimeoutMs: 3600000,
defaultTimeoutBehavior: 'continue',
conditionPollIntervalMs: 10000,
conditionMaxPolls: 100,
webhookUrlPattern: '/hooks/resume/{executionId}',
persistCheckpoints: true,
maxPausedExecutions: 500,
});
expect(config.defaultTimeoutMs).toBe(3600000);
expect(config.conditionPollIntervalMs).toBe(10000);
expect(config.maxPausedExecutions).toBe(500);
});
it('should reject polling interval below minimum', () => {
expect(() => WaitExecutorConfigSchema.parse({
conditionPollIntervalMs: 500,
})).toThrow();
});
});
// ---------------------------------------------------------------------------
// NodeExecutorDescriptorSchema
// ---------------------------------------------------------------------------
describe('NodeExecutorDescriptorSchema', () => {
it('should accept a valid executor descriptor', () => {
const desc: NodeExecutorDescriptor = NodeExecutorDescriptorSchema.parse({
id: 'custom:script-executor',
name: 'Script Executor',
nodeTypes: ['script'],
version: '1.0.0',
});
expect(desc.id).toBe('custom:script-executor');
expect(desc.supportsPause).toBe(false); // default
expect(desc.supportsRetry).toBe(true); // default
});
it('should accept executor with all features', () => {
const desc = NodeExecutorDescriptorSchema.parse({
id: 'objectstack:http-executor',
name: 'HTTP Request Executor',
nodeTypes: ['http', 'connector_action'],
version: '2.0.0',
description: 'Executes HTTP requests and connector actions',
supportsPause: false,
supportsCancellation: true,
supportsRetry: true,
configSchemaRef: '#/definitions/HttpExecutorConfig',
});
expect(desc.nodeTypes).toContain('http');
expect(desc.nodeTypes).toContain('connector_action');
expect(desc.supportsCancellation).toBe(true);
});
it('should reject empty nodeTypes', () => {
expect(() => NodeExecutorDescriptorSchema.parse({
id: 'bad',
name: 'Bad',
nodeTypes: [],
version: '1.0.0',
})).toThrow();
});
});
// ---------------------------------------------------------------------------
// WAIT_EXECUTOR_DESCRIPTOR
// ---------------------------------------------------------------------------
describe('WAIT_EXECUTOR_DESCRIPTOR', () => {
it('should be a valid NodeExecutorDescriptor', () => {
expect(() => NodeExecutorDescriptorSchema.parse(WAIT_EXECUTOR_DESCRIPTOR)).not.toThrow();
});
it('should handle wait node type', () => {
expect(WAIT_EXECUTOR_DESCRIPTOR.nodeTypes).toContain('wait');
});
it('should support pause and cancellation', () => {
expect(WAIT_EXECUTOR_DESCRIPTOR.supportsPause).toBe(true);
expect(WAIT_EXECUTOR_DESCRIPTOR.supportsCancellation).toBe(true);
});
});
// ---------------------------------------------------------------------------
// Scenario: Wait Pause/Resume Flow
// ---------------------------------------------------------------------------
describe('Wait Executor — pause/resume scenario', () => {
it('should model a full wait → checkpoint → resume lifecycle', () => {
// 1. Configure the wait executor
const config = WaitExecutorConfigSchema.parse({
defaultTimeoutMs: 3600000,
conditionPollIntervalMs: 15000,
persistCheckpoints: true,
});
expect(config.persistCheckpoints).toBe(true);
// 2. Simulate a webhook resume
const resume = WaitResumePayloadSchema.parse({
executionId: 'exec_lifecycle_001',
checkpointId: 'cp_lifecycle_001',
nodeId: 'wait_webhook_approval',
eventType: 'webhook',
webhookPayload: {
decision: 'approved',
comments: 'All checks passed',
},
resumedBy: 'webhook_service',
resumedAt: '2026-02-22T14:00:00Z',
variables: {
approval_status: 'approved',
},
});
expect(resume.eventType).toBe('webhook');
expect(resume.variables?.approval_status).toBe('approved');
});
});