@abyss-project/runtime 1.0.0 → 2.0.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.
- package/README.md +6 -3
- package/dist/cost/execution-cost.d.ts +45 -0
- package/dist/cost/execution-cost.js +114 -0
- package/dist/cost/execution-cost.js.map +1 -0
- package/dist/definition/definition.limits.d.ts +4 -0
- package/dist/definition/definition.limits.js +8 -0
- package/dist/definition/definition.limits.js.map +1 -0
- package/dist/definition/definition.schema.d.ts +2 -2
- package/dist/definition/definition.schema.js +20 -4
- package/dist/definition/definition.schema.js.map +1 -1
- package/dist/definition/definition.types.d.ts +20 -1
- package/dist/definition/definition.types.js +9 -1
- package/dist/definition/definition.types.js.map +1 -1
- package/dist/engine/engine-entry.d.ts +1 -0
- package/dist/engine/engine-entry.js +6 -0
- package/dist/engine/engine-entry.js.map +1 -0
- package/dist/engine/engine-global.d.ts +1 -0
- package/dist/engine/engine-global.js +5 -0
- package/dist/engine/engine-global.js.map +1 -0
- package/dist/engine/engine-source.d.ts +2 -0
- package/dist/engine/engine-source.js +3 -0
- package/dist/engine/run-in-isolate.d.ts +34 -0
- package/dist/engine/run-in-isolate.js +267 -0
- package/dist/engine/run-in-isolate.js.map +1 -0
- package/dist/errors/runtime-error-code.enum.d.ts +2 -2
- package/dist/errors/runtime-error-code.enum.js +1 -1
- package/dist/errors/runtime-error-code.enum.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/interpreter/interpreter.d.ts +27 -1
- package/dist/interpreter/interpreter.js +114 -42
- package/dist/interpreter/interpreter.js.map +1 -1
- package/dist/interpreter/interpreter.types.d.ts +35 -4
- package/dist/interpreter/interpreter.types.js +7 -1
- package/dist/interpreter/interpreter.types.js.map +1 -1
- package/dist/interpreter/test-host.d.ts +4 -2
- package/dist/interpreter/test-host.js +6 -0
- package/dist/interpreter/test-host.js.map +1 -1
- package/dist/runner-protocol/evaluation.types.d.ts +20 -0
- package/dist/runner-protocol/evaluation.types.js +10 -0
- package/dist/runner-protocol/evaluation.types.js.map +1 -0
- package/dist/runner-protocol/execution-protocol.types.d.ts +132 -0
- package/dist/runner-protocol/execution-protocol.types.js +48 -0
- package/dist/runner-protocol/execution-protocol.types.js.map +1 -0
- package/dist/server/code-runner-session.d.ts +28 -0
- package/dist/server/code-runner-session.js +208 -0
- package/dist/server/code-runner-session.js.map +1 -0
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +5 -3
- package/dist/server/index.js.map +1 -1
- package/dist/steps/execute-step.d.ts +12 -2
- package/dist/steps/execute-step.js +37 -0
- package/dist/steps/execute-step.js.map +1 -1
- package/dist/steps/global-references.d.ts +2 -0
- package/dist/steps/global-references.js +28 -0
- package/dist/steps/global-references.js.map +1 -0
- package/dist/steps/step-fields.d.ts +1 -1
- package/dist/steps/step-fields.js +10 -2
- package/dist/steps/step-fields.js.map +1 -1
- package/dist/steps/value-source.d.ts +1 -1
- package/dist/steps/value-source.js +3 -3
- package/dist/steps/value-source.js.map +1 -1
- package/package.json +10 -2
- package/scripts/build-engine.cjs +70 -0
- package/src/__tests__/engine-bundle.test.ts +121 -0
- package/src/cost/__tests__/execution-cost.test.ts +200 -0
- package/src/cost/execution-cost.ts +192 -0
- package/src/definition/__tests__/validate-definition.test.ts +354 -303
- package/src/definition/definition.limits.ts +9 -0
- package/src/definition/definition.schema.ts +172 -139
- package/src/definition/definition.types.ts +171 -143
- package/src/engine/__tests__/run-in-isolate.test.ts +468 -0
- package/src/engine/engine-entry.ts +3 -0
- package/src/engine/engine-global.ts +2 -0
- package/src/engine/run-in-isolate.ts +404 -0
- package/src/errors/runtime-error-code.enum.ts +37 -37
- package/src/index.ts +30 -18
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +223 -0
- package/src/interpreter/interpreter.ts +461 -342
- package/src/interpreter/interpreter.types.ts +192 -140
- package/src/interpreter/test-host.ts +85 -74
- package/src/runner-protocol/evaluation.types.ts +21 -0
- package/src/runner-protocol/execution-protocol.types.ts +221 -0
- package/src/server/__tests__/code-runner-session.test.ts +311 -0
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -0
- package/src/server/index.ts +11 -4
- package/src/steps/__tests__/global-references.test.ts +113 -0
- package/src/steps/execute-step.ts +186 -132
- package/src/steps/global-references.ts +48 -0
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +87 -79
- package/src/steps/value-source.ts +69 -69
- package/dist/runner-protocol/runner-protocol.types.d.ts +0 -92
- package/dist/runner-protocol/runner-protocol.types.js +0 -26
- package/dist/runner-protocol/runner-protocol.types.js.map +0 -1
- package/dist/server/code-runner-client.d.ts +0 -13
- package/dist/server/code-runner-client.js +0 -155
- package/dist/server/code-runner-client.js.map +0 -1
- package/src/runner-protocol/runner-protocol.types.ts +0 -117
- package/src/server/__tests__/code-runner-client.test.ts +0 -262
- package/src/server/code-runner-client.ts +0 -201
|
@@ -1,303 +1,354 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import { AccessKind } from '../../access/access.types';
|
|
3
|
-
import {
|
|
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
|
-
it('
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
expect(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
steps
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
expect(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
(
|
|
153
|
-
|
|
154
|
-
expect(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
(
|
|
166
|
-
expect(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
expect(
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('rejects an
|
|
207
|
-
const raw = validDefinition();
|
|
208
|
-
(raw.steps[
|
|
209
|
-
expect(pathsOf(raw)).toEqual(['steps[
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('rejects
|
|
213
|
-
const raw = validDefinition();
|
|
214
|
-
(raw.steps[
|
|
215
|
-
expect(pathsOf(raw)).toEqual(['steps[0]
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('
|
|
219
|
-
const raw = validDefinition();
|
|
220
|
-
(raw.steps[
|
|
221
|
-
(raw.steps[
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
expect(pathsOf(
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('rejects
|
|
244
|
-
const raw = validDefinition();
|
|
245
|
-
(raw.steps[1] as any).
|
|
246
|
-
expect(pathsOf(raw)).toEqual(['steps[1].
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it('rejects a
|
|
250
|
-
const raw = validDefinition();
|
|
251
|
-
(raw.
|
|
252
|
-
(raw.
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('
|
|
278
|
-
const raw = validDefinition();
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
expect(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
]);
|
|
302
|
-
|
|
303
|
-
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
import { AccessKind } from '../../access/access.types';
|
|
3
|
+
import {
|
|
4
|
+
CURRENT_FORMAT_VERSION,
|
|
5
|
+
HttpMethod,
|
|
6
|
+
LogLevel,
|
|
7
|
+
StepType,
|
|
8
|
+
StopStatus,
|
|
9
|
+
} from '../definition.types';
|
|
10
|
+
import type { HostActionCatalog } from '../definition.types';
|
|
11
|
+
import { MAX_WAIT_DURATION_MS } from '../definition.schema';
|
|
12
|
+
import { validateDefinition } from '../validate-definition';
|
|
13
|
+
import { walkSteps } from '../walk-steps';
|
|
14
|
+
|
|
15
|
+
const catalog: HostActionCatalog = new Map([
|
|
16
|
+
[
|
|
17
|
+
'send-email',
|
|
18
|
+
{
|
|
19
|
+
name: 'send-email',
|
|
20
|
+
inputSchema: Joi.object({ to: Joi.string().required(), subject: Joi.string() }),
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const clone = <T>(value: T): T => JSON.parse(JSON.stringify(value));
|
|
26
|
+
|
|
27
|
+
const validDefinition = () => ({
|
|
28
|
+
formatVersion: CURRENT_FORMAT_VERSION,
|
|
29
|
+
accesses: [
|
|
30
|
+
{ kind: AccessKind.HTTP, hosts: ['api.example.com', '*.hooks.example.com'] },
|
|
31
|
+
{ kind: AccessKind.HOST_ACTION, action: 'send-email' },
|
|
32
|
+
],
|
|
33
|
+
steps: [
|
|
34
|
+
{ id: 'init', type: StepType.SET, variable: 'count', value: 0 },
|
|
35
|
+
{
|
|
36
|
+
id: 'check',
|
|
37
|
+
type: StepType.CONDITION,
|
|
38
|
+
if: { $expression: 'input.amount > 10' },
|
|
39
|
+
then: [
|
|
40
|
+
{
|
|
41
|
+
id: 'fetch',
|
|
42
|
+
type: StepType.HTTP,
|
|
43
|
+
method: HttpMethod.POST,
|
|
44
|
+
url: 'https://api.example.com/v1/items',
|
|
45
|
+
headers: { Authorization: 'Bearer {{ input.token }}', 'X-List': ['a', { b: 1 }] },
|
|
46
|
+
body: { items: [1, 2, { $expression: 'input.items' }] },
|
|
47
|
+
timeoutMs: 5000,
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 'mail',
|
|
51
|
+
type: StepType.HOST,
|
|
52
|
+
action: 'send-email',
|
|
53
|
+
input: { to: '{{ input.email }}', subject: 'Hello' },
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
else: [
|
|
57
|
+
{ id: 'pause', type: StepType.WAIT, durationMs: 1000 },
|
|
58
|
+
{
|
|
59
|
+
id: 'note',
|
|
60
|
+
type: StepType.LOG,
|
|
61
|
+
level: LogLevel.WARN,
|
|
62
|
+
message: 'small amount: {{ input.amount }}',
|
|
63
|
+
data: { amount: { $expression: 'input.amount' } },
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'reply',
|
|
67
|
+
type: StepType.RESPOND,
|
|
68
|
+
status: 202,
|
|
69
|
+
headers: { 'Content-Type': 'application/json' },
|
|
70
|
+
body: { accepted: true },
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'route',
|
|
76
|
+
type: StepType.SWITCH,
|
|
77
|
+
value: '{{ input.kind }}',
|
|
78
|
+
cases: [
|
|
79
|
+
{
|
|
80
|
+
match: 'a',
|
|
81
|
+
steps: [
|
|
82
|
+
{ id: 'compute', type: StepType.CODE, source: 'return input.n * 2;' },
|
|
83
|
+
{ id: 'later', type: StepType.WAIT, until: '2026-12-31T00:00:00Z' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
match: null,
|
|
88
|
+
steps: [
|
|
89
|
+
{
|
|
90
|
+
id: 'hook',
|
|
91
|
+
type: StepType.HTTP,
|
|
92
|
+
method: HttpMethod.GET,
|
|
93
|
+
url: 'https://x.hooks.example.com/ping',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
default: [{ id: 'fail', type: StepType.STOP, status: StopStatus.FAILED, output: 'unknown' }],
|
|
99
|
+
},
|
|
100
|
+
{ id: 'done', type: StepType.STOP, status: StopStatus.SUCCEEDED },
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const errorsOf = (raw: unknown) => {
|
|
105
|
+
const result = validateDefinition(raw, catalog);
|
|
106
|
+
if (result.ok) {
|
|
107
|
+
throw new Error('expected a refusal');
|
|
108
|
+
}
|
|
109
|
+
return result.errors;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const pathsOf = (raw: unknown) => errorsOf(raw).map((error) => error.path);
|
|
113
|
+
|
|
114
|
+
describe('validateDefinition', () => {
|
|
115
|
+
it('accepts a complete definition with the 10 step types and nested branches', () => {
|
|
116
|
+
const raw = validDefinition();
|
|
117
|
+
const result = validateDefinition(raw, catalog);
|
|
118
|
+
expect(result).toEqual({ ok: true, definition: raw });
|
|
119
|
+
const types = new Set<string>();
|
|
120
|
+
walkSteps(raw.steps as never, (step) => types.add(step.type));
|
|
121
|
+
expect([...types].sort()).toEqual(Object.values(StepType).sort());
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('rejects an unknown formatVersion at "formatVersion"', () => {
|
|
125
|
+
const raw = { ...validDefinition(), formatVersion: 2 };
|
|
126
|
+
expect(pathsOf(raw)).toEqual(['formatVersion']);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('rejects a duplicated id on the second occurrence', () => {
|
|
130
|
+
const raw = validDefinition();
|
|
131
|
+
(raw.steps[1] as any).then[0].id = 'init';
|
|
132
|
+
expect(pathsOf(raw)).toEqual(['steps[1].then[0].id']);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('rejects __proto__, constructor and prototype as step id and as SET variable', () => {
|
|
136
|
+
for (const name of ['__proto__', 'constructor', 'prototype']) {
|
|
137
|
+
const asId = validDefinition();
|
|
138
|
+
(asId.steps[0] as any).id = name;
|
|
139
|
+
expect(pathsOf(asId)).toEqual(['steps[0].id']);
|
|
140
|
+
const asVariable = validDefinition();
|
|
141
|
+
(asVariable.steps[0] as any).variable = name;
|
|
142
|
+
expect(pathsOf(asVariable)).toEqual(['steps[0].variable']);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('bounds a literal WAIT duration to MAX_WAIT_DURATION_MS', () => {
|
|
147
|
+
expect(MAX_WAIT_DURATION_MS).toBe(30 * 24 * 60 * 60 * 1000);
|
|
148
|
+
const at = (durationMs: unknown) => ({
|
|
149
|
+
...validDefinition(),
|
|
150
|
+
steps: [{ id: 'w', type: StepType.WAIT, durationMs }],
|
|
151
|
+
});
|
|
152
|
+
expect(validateDefinition(at(MAX_WAIT_DURATION_MS), catalog).ok).toBe(true);
|
|
153
|
+
expect(validateDefinition(at({ $expression: 'input.d' }), catalog).ok).toBe(true);
|
|
154
|
+
expect(validateDefinition(at('{{ input.d }}'), catalog).ok).toBe(true);
|
|
155
|
+
for (const bad of [MAX_WAIT_DURATION_MS + 1, -1, 1.5]) {
|
|
156
|
+
expect(pathsOf(at(bad))).toEqual(['steps[0].durationMs']);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('requires a literal WAIT until to be an ISO 8601 date', () => {
|
|
161
|
+
const at = (until: unknown) => ({
|
|
162
|
+
...validDefinition(),
|
|
163
|
+
steps: [{ id: 'w', type: StepType.WAIT, until }],
|
|
164
|
+
});
|
|
165
|
+
expect(validateDefinition(at('2030-01-01T00:00:00.000Z'), catalog).ok).toBe(true);
|
|
166
|
+
expect(validateDefinition(at('{{ input.when }}'), catalog).ok).toBe(true);
|
|
167
|
+
expect(validateDefinition(at({ $expression: 'input.when' }), catalog).ok).toBe(true);
|
|
168
|
+
expect(pathsOf(at('tomorrow'))).toEqual(['steps[0].until']);
|
|
169
|
+
expect(pathsOf(at(12))).toEqual(['steps[0].until']);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('requires a LOG level among info, warn, error and a message', () => {
|
|
173
|
+
const at = (step: Record<string, unknown>) => ({
|
|
174
|
+
...validDefinition(),
|
|
175
|
+
steps: [{ id: 'l', type: StepType.LOG, ...step }],
|
|
176
|
+
});
|
|
177
|
+
expect(
|
|
178
|
+
validateDefinition(at({ level: 'info', message: { $expression: 'input' } }), catalog).ok,
|
|
179
|
+
).toBe(true);
|
|
180
|
+
expect(pathsOf(at({ level: 'debug', message: 'x' }))).toEqual(['steps[0].level']);
|
|
181
|
+
expect(pathsOf(at({ level: 'error' }))).toEqual(['steps[0].message']);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('requires a RESPOND status, a literal one from 200 to 599', () => {
|
|
185
|
+
const at = (status: unknown) => ({
|
|
186
|
+
...validDefinition(),
|
|
187
|
+
steps: [{ id: 'r', type: StepType.RESPOND, status }],
|
|
188
|
+
});
|
|
189
|
+
for (const good of [200, 201, 599, '{{ input.status }}', { $expression: 'input.status' }]) {
|
|
190
|
+
expect(validateDefinition(at(good), catalog).ok).toBe(true);
|
|
191
|
+
}
|
|
192
|
+
for (const bad of [100, 199, 600, 200.5, 'ok']) {
|
|
193
|
+
expect(pathsOf(at(bad))).toEqual(['steps[0].status']);
|
|
194
|
+
}
|
|
195
|
+
const missing = { ...validDefinition(), steps: [{ id: 'r', type: StepType.RESPOND }] };
|
|
196
|
+
expect(pathsOf(missing)).toEqual(['steps[0].status']);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('rejects an action absent from the catalog at the path of "action"', () => {
|
|
200
|
+
const raw = validDefinition();
|
|
201
|
+
(raw.steps[1] as any).then[1].action = 'send-sms';
|
|
202
|
+
const paths = pathsOf(raw);
|
|
203
|
+
expect(paths).toContain('steps[1].then[1].action');
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('rejects an input key outside the action schema', () => {
|
|
207
|
+
const raw = validDefinition();
|
|
208
|
+
(raw.steps[1] as any).then[1].input.cc = 'x@y.z';
|
|
209
|
+
expect(pathsOf(raw)).toEqual(['steps[1].then[1].input.cc']);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('rejects an HTTP step towards an undeclared host', () => {
|
|
213
|
+
const raw = validDefinition();
|
|
214
|
+
(raw.steps[1] as any).then[0].url = 'https://evil.example.org/x';
|
|
215
|
+
expect(pathsOf(raw)).toEqual(['steps[1].then[0]']);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('does not let a wildcard declaration cover the apex host', () => {
|
|
219
|
+
const raw = validDefinition();
|
|
220
|
+
(raw.steps[2] as any).cases[1].steps[0].url = 'https://hooks.example.com/ping';
|
|
221
|
+
expect(pathsOf(raw)).toEqual(['steps[2].cases[1].steps[0]']);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('skips the host check when the URL is a template', () => {
|
|
225
|
+
const raw = validDefinition();
|
|
226
|
+
(raw.steps[1] as any).then[0].url = 'https://{{ input.host }}/x';
|
|
227
|
+
expect(validateDefinition(raw, catalog).ok).toBe(true);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('requires an HTTP declaration for any HTTP step', () => {
|
|
231
|
+
const raw = validDefinition();
|
|
232
|
+
raw.accesses = raw.accesses.filter((access) => access.kind !== AccessKind.HTTP);
|
|
233
|
+
(raw.steps[1] as any).then[0].url = '{{ input.url }}';
|
|
234
|
+
expect(pathsOf(raw)).toContain('steps[1].then[0]');
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('rejects a HOST step whose action is not declared', () => {
|
|
238
|
+
const raw = validDefinition();
|
|
239
|
+
raw.accesses = raw.accesses.filter((access) => access.kind !== AccessKind.HOST_ACTION);
|
|
240
|
+
expect(pathsOf(raw)).toEqual(['steps[1].then[1]']);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('rejects a WAIT with both durationMs and until', () => {
|
|
244
|
+
const raw = validDefinition();
|
|
245
|
+
(raw.steps[1] as any).else[0].until = '2026-12-31T00:00:00Z';
|
|
246
|
+
expect(pathsOf(raw)).toEqual(['steps[1].else[0]']);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('rejects a WAIT with neither durationMs nor until', () => {
|
|
250
|
+
const raw = validDefinition();
|
|
251
|
+
delete (raw.steps[1] as any).else[0].durationMs;
|
|
252
|
+
expect(pathsOf(raw)).toEqual(['steps[1].else[0]']);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('rejects an object carrying $expression and another key', () => {
|
|
256
|
+
const raw = validDefinition();
|
|
257
|
+
(raw.steps[0] as any).value = { $expression: '1 + 1', other: 2 };
|
|
258
|
+
expect(pathsOf(raw)).toEqual(['steps[0].value']);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('rejects a $expression that is not a string', () => {
|
|
262
|
+
const raw = validDefinition();
|
|
263
|
+
(raw.steps[0] as any).value = { $expression: 3 };
|
|
264
|
+
expect(pathsOf(raw)).toEqual(['steps[0].value']);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('rejects an invalid SET variable, an empty id and an unknown STOP status', () => {
|
|
268
|
+
const raw = validDefinition();
|
|
269
|
+
(raw.steps[0] as any).variable = 'not valid';
|
|
270
|
+
(raw.steps[3] as any).id = '';
|
|
271
|
+
(raw.steps[2] as any).default[0].status = 'MAYBE';
|
|
272
|
+
expect(pathsOf(raw).sort()).toEqual(
|
|
273
|
+
['steps[0].variable', 'steps[2].default[0].status', 'steps[3].id'].sort(),
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('rejects a SWITCH without case', () => {
|
|
278
|
+
const raw = validDefinition();
|
|
279
|
+
(raw.steps[2] as any).cases = [];
|
|
280
|
+
expect(pathsOf(raw)).toEqual(['steps[2].cases']);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('bounds the HTTP timeout to a positive integer of at most 30000', () => {
|
|
284
|
+
const tooLong = validDefinition();
|
|
285
|
+
(tooLong.steps[1] as any).then[0].timeoutMs = 30001;
|
|
286
|
+
expect(pathsOf(tooLong)).toEqual(['steps[1].then[0].timeoutMs']);
|
|
287
|
+
const fractional = validDefinition();
|
|
288
|
+
(fractional.steps[1] as any).then[0].timeoutMs = 1.5;
|
|
289
|
+
expect(pathsOf(fractional)).toEqual(['steps[1].then[0].timeoutMs']);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('rejects HTTP headers that are not value sources', () => {
|
|
293
|
+
const raw = validDefinition();
|
|
294
|
+
(raw.steps[1] as any).then[0].headers = { 'X-Bad': { $expression: 'a', extra: 1 } };
|
|
295
|
+
expect(pathsOf(raw)).toEqual(['steps[1].then[0].headers.X-Bad']);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('rejects a malformed access declaration', () => {
|
|
299
|
+
const raw = validDefinition();
|
|
300
|
+
(raw.accesses[0] as any).hosts = ['https://api.example.com/'];
|
|
301
|
+
(raw.accesses as any[]).push({ kind: 'FTP' });
|
|
302
|
+
const paths = pathsOf(raw);
|
|
303
|
+
expect(paths).toContain('accesses[0].hosts[0]');
|
|
304
|
+
expect(paths).toContain('accesses[2].kind');
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('rejects an unknown step type and a non-object step', () => {
|
|
308
|
+
const raw = validDefinition();
|
|
309
|
+
(raw.steps as any[]).push({ id: 'x', type: 'LOOP' }, 'oops');
|
|
310
|
+
expect(pathsOf(raw)).toEqual(['steps[4].type', 'steps[5]']);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('collects every error instead of stopping at the first', () => {
|
|
314
|
+
const raw = validDefinition();
|
|
315
|
+
(raw.steps[1] as any).then[1].action = 'send-sms';
|
|
316
|
+
(raw.steps[1] as any).then[0].url = 'https://evil.example.org/x';
|
|
317
|
+
(raw.steps[0] as any).variable = '1x';
|
|
318
|
+
expect(errorsOf(raw).length).toBeGreaterThanOrEqual(3);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('rejects a document that is not an object', () => {
|
|
322
|
+
expect(pathsOf('nope')).toEqual(['']);
|
|
323
|
+
expect(pathsOf(null)).toEqual(['']);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('does not mutate its input', () => {
|
|
327
|
+
const raw = validDefinition();
|
|
328
|
+
const copy = clone(raw);
|
|
329
|
+
validateDefinition(raw, catalog);
|
|
330
|
+
expect(raw).toEqual(copy);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe('walkSteps', () => {
|
|
335
|
+
it('visits steps in document order with their JSON path', () => {
|
|
336
|
+
const visited: string[] = [];
|
|
337
|
+
walkSteps(validDefinition().steps as never, (step, path) => visited.push(`${path}:${step.id}`));
|
|
338
|
+
expect(visited).toEqual([
|
|
339
|
+
'steps[0]:init',
|
|
340
|
+
'steps[1]:check',
|
|
341
|
+
'steps[1].then[0]:fetch',
|
|
342
|
+
'steps[1].then[1]:mail',
|
|
343
|
+
'steps[1].else[0]:pause',
|
|
344
|
+
'steps[1].else[1]:note',
|
|
345
|
+
'steps[1].else[2]:reply',
|
|
346
|
+
'steps[2]:route',
|
|
347
|
+
'steps[2].cases[0].steps[0]:compute',
|
|
348
|
+
'steps[2].cases[0].steps[1]:later',
|
|
349
|
+
'steps[2].cases[1].steps[0]:hook',
|
|
350
|
+
'steps[2].default[0]:fail',
|
|
351
|
+
'steps[3]:done',
|
|
352
|
+
]);
|
|
353
|
+
});
|
|
354
|
+
});
|