@abyss-project/runtime 3.12.0 → 3.13.0

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 (69) hide show
  1. package/.eslintrc.js +32 -32
  2. package/.prettierrc +5 -5
  3. package/README.md +88 -88
  4. package/dist/definition/definition.schema.js +6 -0
  5. package/dist/definition/definition.schema.js.map +1 -1
  6. package/dist/definition/definition.types.d.ts +11 -0
  7. package/dist/definition/definition.types.js +6 -1
  8. package/dist/definition/definition.types.js.map +1 -1
  9. package/dist/discord/discord.types.d.ts +2 -34
  10. package/dist/discord/discord.types.js +1 -9
  11. package/dist/discord/discord.types.js.map +1 -1
  12. package/dist/engine/engine-source.js +1 -1
  13. package/dist/errors/runtime-error-code.enum.d.ts +1 -0
  14. package/dist/errors/runtime-error-code.enum.js +1 -0
  15. package/dist/errors/runtime-error-code.enum.js.map +1 -1
  16. package/dist/runner-protocol/evaluation.types.d.ts +1 -0
  17. package/dist/steps/global-references.js +7 -0
  18. package/dist/steps/global-references.js.map +1 -1
  19. package/dist/steps/step-fields.js +10 -0
  20. package/dist/steps/step-fields.js.map +1 -1
  21. package/jest.config.ts +11 -11
  22. package/package.json +1 -1
  23. package/scripts/build-engine.cjs +70 -70
  24. package/src/__tests__/engine-bundle.test.ts +121 -121
  25. package/src/__tests__/surface.test.ts +81 -88
  26. package/src/access/__tests__/host-match.test.ts +24 -24
  27. package/src/access/access.types.ts +25 -25
  28. package/src/access/host-match.ts +13 -13
  29. package/src/cost/__tests__/execution-cost.test.ts +249 -249
  30. package/src/cost/execution-cost.ts +203 -203
  31. package/src/definition/__tests__/code-step.test.ts +56 -0
  32. package/src/definition/__tests__/validate-definition.test.ts +354 -354
  33. package/src/definition/definition.limits.ts +9 -9
  34. package/src/definition/definition.schema.ts +7 -0
  35. package/src/definition/definition.types.ts +21 -1
  36. package/src/definition/validate-definition.ts +206 -206
  37. package/src/definition/walk-steps.ts +44 -44
  38. package/src/discord/__tests__/discord-event-input.test.ts +90 -108
  39. package/src/discord/discord.types.ts +696 -738
  40. package/src/engine/__tests__/run-in-isolate.test.ts +519 -519
  41. package/src/engine/engine-entry.ts +3 -3
  42. package/src/engine/engine-global.ts +2 -2
  43. package/src/engine/run-in-isolate.ts +462 -462
  44. package/src/errors/runtime-error-code.enum.ts +5 -0
  45. package/src/index.ts +32 -32
  46. package/src/interpreter/__tests__/interpreter.test.ts +854 -854
  47. package/src/interpreter/__tests__/log-respond-resume.test.ts +271 -271
  48. package/src/interpreter/interpreter-error.ts +12 -12
  49. package/src/interpreter/interpreter.ts +483 -483
  50. package/src/interpreter/interpreter.types.ts +204 -204
  51. package/src/interpreter/sequence-path.ts +67 -67
  52. package/src/interpreter/test-host.ts +85 -85
  53. package/src/runner-protocol/__tests__/file-payload.test.ts +26 -26
  54. package/src/runner-protocol/evaluation.types.ts +2 -0
  55. package/src/runner-protocol/execution-protocol.types.ts +297 -297
  56. package/src/schedule/schedule.types.ts +100 -100
  57. package/src/server/__tests__/code-runner-session.test.ts +311 -311
  58. package/src/server/code-runner-error.ts +12 -12
  59. package/src/server/code-runner-session.ts +310 -310
  60. package/src/server/index.ts +11 -11
  61. package/src/steps/__tests__/global-references.test.ts +140 -124
  62. package/src/steps/__tests__/step-fields.test.ts +58 -0
  63. package/src/steps/execute-step.ts +186 -186
  64. package/src/steps/global-references.ts +56 -48
  65. package/src/steps/step-access.ts +56 -56
  66. package/src/steps/step-fields.ts +10 -0
  67. package/src/steps/value-source.ts +69 -69
  68. package/tsconfig.check.json +15 -15
  69. package/tsconfig.json +35 -35
@@ -1,133 +1,149 @@
1
- import { CURRENT_FORMAT_VERSION, HttpMethod, StepType } from '../../definition/definition.types';
2
- import type { RuntimeDefinition, Step } from '../../definition/definition.types';
3
- import { collectGlobalReferences } from '../global-references';
1
+ import { CURRENT_FORMAT_VERSION, HttpMethod, StepType } from '../../definition/definition.types';
2
+ import type { RuntimeDefinition, Step } from '../../definition/definition.types';
3
+ import { collectGlobalReferences } from '../global-references';
4
+
5
+ const definitionOf = (steps: Step[]): RuntimeDefinition => ({
6
+ formatVersion: CURRENT_FORMAT_VERSION,
7
+ accesses: [],
8
+ steps,
9
+ });
10
+
11
+ describe('collectGlobalReferences', () => {
12
+ it('finds a reference in a template placeholder, an expression and a CODE source', () => {
13
+ const definition = definitionOf([
14
+ {
15
+ id: 'call',
16
+ type: StepType.HTTP,
17
+ method: HttpMethod.GET,
18
+ url: 'https://api.example.com/{{ input.id }}',
19
+ headers: { Authorization: 'Bearer {{ secrets.API_KEY }}' },
20
+ body: { $expression: 'secrets.BODY_KEY + "x"' },
21
+ },
22
+ { id: 'code', type: StepType.CODE, source: 'const t = secrets.CODE_KEY; return t;' },
23
+ ]);
24
+ expect(collectGlobalReferences(definition, 'secrets')).toEqual([
25
+ 'API_KEY',
26
+ 'BODY_KEY',
27
+ 'CODE_KEY',
28
+ ]);
29
+ });
30
+
31
+ it('reads the references of the branches of CONDITION and SWITCH steps', () => {
32
+ const definition = definitionOf([
33
+ {
34
+ id: 'cond',
35
+ type: StepType.CONDITION,
36
+ if: { $expression: 'true' },
37
+ then: [{ id: 'a', type: StepType.SET, variable: 'a', value: '{{ secrets.THEN }}' }],
38
+ else: [{ id: 'b', type: StepType.SET, variable: 'b', value: '{{ secrets.ELSE }}' }],
39
+ },
40
+ {
41
+ id: 'sw',
42
+ type: StepType.SWITCH,
43
+ value: { $expression: 'input.kind' },
44
+ cases: [
45
+ {
46
+ match: 'x',
47
+ steps: [
48
+ {
49
+ id: 'deep',
50
+ type: StepType.CONDITION,
51
+ if: { $expression: 'secrets.CASE_CONDITION === "1"' },
52
+ then: [],
53
+ },
54
+ ],
55
+ },
56
+ ],
57
+ default: [{ id: 'c', type: StepType.SET, variable: 'c', value: '{{ secrets.DEFAULT }}' }],
58
+ },
59
+ ]);
60
+ expect(collectGlobalReferences(definition, 'secrets')).toEqual([
61
+ 'THEN',
62
+ 'ELSE',
63
+ 'CASE_CONDITION',
64
+ 'DEFAULT',
65
+ ]);
66
+ });
67
+
68
+ it('reads the bracket form with either quote, and the optional chain', () => {
69
+ const definition = definitionOf([
70
+ {
71
+ id: 'code',
72
+ type: StepType.CODE,
73
+ source: `return [secrets['A'], secrets["B"], secrets [ 'C' ], secrets?.D];`,
74
+ },
75
+ ]);
76
+ expect(collectGlobalReferences(definition, 'secrets')).toEqual(['A', 'B', 'C', 'D']);
77
+ });
78
+
79
+ it('lists a name once, in order of first appearance', () => {
80
+ const definition = definitionOf([
81
+ { id: 'one', type: StepType.SET, variable: 'x', value: '{{ secrets.B }}-{{ secrets.A }}' },
82
+ {
83
+ id: 'two',
84
+ type: StepType.SET,
85
+ variable: 'y',
86
+ value: { $expression: 'secrets.B + secrets["A"]' },
87
+ },
88
+ ]);
89
+ expect(collectGlobalReferences(definition, 'secrets')).toEqual(['B', 'A']);
90
+ });
91
+
92
+ it('ignores dynamic access, other globals, member chains and text outside placeholders', () => {
93
+ const definition = definitionOf([
94
+ {
95
+ id: 'code',
96
+ type: StepType.CODE,
97
+ source: 'const n = "K"; return [secrets[n], other.secrets.X, mysecrets.Y, secrets];',
98
+ },
99
+ { id: 'text', type: StepType.SET, variable: 't', value: 'secrets.OUTSIDE {{ input.x }}' },
100
+ { id: 'literal', type: StepType.SET, variable: 'l', value: 'secrets.LITERAL' },
101
+ ]);
102
+ expect(collectGlobalReferences(definition, 'secrets')).toEqual([]);
103
+ });
104
+
105
+ it('finds the config variables in fields, expressions and code, apart from the secrets', () => {
106
+ const definition = definitionOf([
107
+ {
108
+ id: 'http',
109
+ type: StepType.SET,
110
+ variable: 'u',
111
+ value: 'https://{{ config.HOST }}/x?k={{ secrets.KEY }}',
112
+ },
113
+ { id: 'expr', type: StepType.SET, variable: 'e', value: { $expression: 'config.MODE + 1' } },
114
+ { id: 'code', type: StepType.CODE, source: 'return [config["REGION"], config?.TIER];' },
115
+ ]);
116
+ expect(collectGlobalReferences(definition, 'config')).toEqual([
117
+ 'HOST',
118
+ 'MODE',
119
+ 'REGION',
120
+ 'TIER',
121
+ ]);
122
+ expect(collectGlobalReferences(definition, 'secrets')).toEqual(['KEY']);
123
+ });
124
+
125
+ it('works for any global name, and escapes it', () => {
126
+ const definition = definitionOf([
127
+ { id: 'a', type: StepType.SET, variable: 'a', value: '{{ workflow.project + secrets.S }}' },
128
+ ]);
129
+ expect(collectGlobalReferences(definition, 'workflow')).toEqual(['project']);
130
+ expect(collectGlobalReferences(definition, 'work.low')).toEqual([]);
131
+ expect(collectGlobalReferences(definition, '$')).toEqual([]);
132
+ });
4
133
 
5
- const definitionOf = (steps: Step[]): RuntimeDefinition => ({
6
- formatVersion: CURRENT_FORMAT_VERSION,
7
- accesses: [],
8
- steps,
9
- });
10
-
11
- describe('collectGlobalReferences', () => {
12
- it('finds a reference in a template placeholder, an expression and a CODE source', () => {
13
- const definition = definitionOf([
14
- {
15
- id: 'call',
16
- type: StepType.HTTP,
17
- method: HttpMethod.GET,
18
- url: 'https://api.example.com/{{ input.id }}',
19
- headers: { Authorization: 'Bearer {{ secrets.API_KEY }}' },
20
- body: { $expression: 'secrets.BODY_KEY + "x"' },
21
- },
22
- { id: 'code', type: StepType.CODE, source: 'const t = secrets.CODE_KEY; return t;' },
23
- ]);
24
- expect(collectGlobalReferences(definition, 'secrets')).toEqual([
25
- 'API_KEY',
26
- 'BODY_KEY',
27
- 'CODE_KEY',
28
- ]);
29
- });
30
-
31
- it('reads the references of the branches of CONDITION and SWITCH steps', () => {
32
- const definition = definitionOf([
33
- {
34
- id: 'cond',
35
- type: StepType.CONDITION,
36
- if: { $expression: 'true' },
37
- then: [{ id: 'a', type: StepType.SET, variable: 'a', value: '{{ secrets.THEN }}' }],
38
- else: [{ id: 'b', type: StepType.SET, variable: 'b', value: '{{ secrets.ELSE }}' }],
39
- },
40
- {
41
- id: 'sw',
42
- type: StepType.SWITCH,
43
- value: { $expression: 'input.kind' },
44
- cases: [
45
- {
46
- match: 'x',
47
- steps: [
48
- {
49
- id: 'deep',
50
- type: StepType.CONDITION,
51
- if: { $expression: 'secrets.CASE_CONDITION === "1"' },
52
- then: [],
53
- },
54
- ],
55
- },
56
- ],
57
- default: [{ id: 'c', type: StepType.SET, variable: 'c', value: '{{ secrets.DEFAULT }}' }],
58
- },
59
- ]);
60
- expect(collectGlobalReferences(definition, 'secrets')).toEqual([
61
- 'THEN',
62
- 'ELSE',
63
- 'CASE_CONDITION',
64
- 'DEFAULT',
65
- ]);
66
- });
67
-
68
- it('reads the bracket form with either quote, and the optional chain', () => {
134
+ it('reads the source of a compiled CODE step, never the embedded library code', () => {
69
135
  const definition = definitionOf([
70
136
  {
71
137
  id: 'code',
72
138
  type: StepType.CODE,
73
- source: `return [secrets['A'], secrets["B"], secrets [ 'C' ], secrets?.D];`,
139
+ source: 'return secrets.TOKEN;',
140
+ compiled: {
141
+ code: 'var lib = { config: {} }; secrets.LIBRARY_TEXT; return secrets.TOKEN;',
142
+ sourceMap: '{}',
143
+ toolchain: 'esbuild@0.28.2',
144
+ },
74
145
  },
75
146
  ]);
76
- expect(collectGlobalReferences(definition, 'secrets')).toEqual(['A', 'B', 'C', 'D']);
77
- });
78
-
79
- it('lists a name once, in order of first appearance', () => {
80
- const definition = definitionOf([
81
- { id: 'one', type: StepType.SET, variable: 'x', value: '{{ secrets.B }}-{{ secrets.A }}' },
82
- {
83
- id: 'two',
84
- type: StepType.SET,
85
- variable: 'y',
86
- value: { $expression: 'secrets.B + secrets["A"]' },
87
- },
88
- ]);
89
- expect(collectGlobalReferences(definition, 'secrets')).toEqual(['B', 'A']);
90
- });
91
-
92
- it('ignores dynamic access, other globals, member chains and text outside placeholders', () => {
93
- const definition = definitionOf([
94
- {
95
- id: 'code',
96
- type: StepType.CODE,
97
- source: 'const n = "K"; return [secrets[n], other.secrets.X, mysecrets.Y, secrets];',
98
- },
99
- { id: 'text', type: StepType.SET, variable: 't', value: 'secrets.OUTSIDE {{ input.x }}' },
100
- { id: 'literal', type: StepType.SET, variable: 'l', value: 'secrets.LITERAL' },
101
- ]);
102
- expect(collectGlobalReferences(definition, 'secrets')).toEqual([]);
103
- });
104
-
105
- it('finds the config variables in fields, expressions and code, apart from the secrets', () => {
106
- const definition = definitionOf([
107
- {
108
- id: 'http',
109
- type: StepType.SET,
110
- variable: 'u',
111
- value: 'https://{{ config.HOST }}/x?k={{ secrets.KEY }}',
112
- },
113
- { id: 'expr', type: StepType.SET, variable: 'e', value: { $expression: 'config.MODE + 1' } },
114
- { id: 'code', type: StepType.CODE, source: 'return [config["REGION"], config?.TIER];' },
115
- ]);
116
- expect(collectGlobalReferences(definition, 'config')).toEqual([
117
- 'HOST',
118
- 'MODE',
119
- 'REGION',
120
- 'TIER',
121
- ]);
122
- expect(collectGlobalReferences(definition, 'secrets')).toEqual(['KEY']);
123
- });
124
-
125
- it('works for any global name, and escapes it', () => {
126
- const definition = definitionOf([
127
- { id: 'a', type: StepType.SET, variable: 'a', value: '{{ workflow.project + secrets.S }}' },
128
- ]);
129
- expect(collectGlobalReferences(definition, 'workflow')).toEqual(['project']);
130
- expect(collectGlobalReferences(definition, 'work.low')).toEqual([]);
131
- expect(collectGlobalReferences(definition, '$')).toEqual([]);
147
+ expect(collectGlobalReferences(definition, 'secrets')).toEqual(['TOKEN']);
132
148
  });
133
149
  });
@@ -0,0 +1,58 @@
1
+ import { transformSync } from 'esbuild';
2
+ import { CodeLanguage, StepType } from '../../definition/definition.types';
3
+ import type { CodeStep } from '../../definition/definition.types';
4
+ import { EvaluationKind } from '../../runner-protocol/evaluation.types';
5
+ import { collectStepItems, resolveStepFields } from '../step-fields';
6
+
7
+ describe('collectStepItems for a CODE step', () => {
8
+ it('evaluates the source of a Flow-shaped step, without source map', () => {
9
+ const step: CodeStep = { id: 'c', type: StepType.CODE, source: 'return 1;' };
10
+ expect(collectStepItems(step)).toEqual([
11
+ { id: 'source', kind: EvaluationKind.CODE, source: 'return 1;' },
12
+ ]);
13
+ });
14
+
15
+ it('keeps evaluating the source when only the language is set', () => {
16
+ const step: CodeStep = {
17
+ id: 'c',
18
+ type: StepType.CODE,
19
+ source: 'return 1;',
20
+ language: CodeLanguage.TYPESCRIPT,
21
+ };
22
+ expect(collectStepItems(step)).toEqual([
23
+ { id: 'source', kind: EvaluationKind.CODE, source: 'return 1;' },
24
+ ]);
25
+ });
26
+
27
+ it('evaluates the compiled code with its source map instead of the source', () => {
28
+ const source = 'const n: number = 2;\nreturn n * 2;';
29
+ const output = transformSync(source, {
30
+ loader: 'ts',
31
+ sourcemap: 'external',
32
+ sourcefile: 'step.ts',
33
+ });
34
+ const step: CodeStep = {
35
+ id: 'c',
36
+ type: StepType.CODE,
37
+ source,
38
+ language: CodeLanguage.TYPESCRIPT,
39
+ compiled: { code: output.code, sourceMap: output.map, toolchain: 'esbuild' },
40
+ };
41
+ const items = collectStepItems(step);
42
+ expect(items).toEqual([
43
+ { id: 'source', kind: EvaluationKind.CODE, source: output.code, sourceMap: output.map },
44
+ ]);
45
+ expect(JSON.parse(items[0].sourceMap as string).version).toBe(3);
46
+ expect(items[0].source).not.toContain(': number');
47
+ });
48
+
49
+ it('resolves the single source item whatever the compiled code', () => {
50
+ const step: CodeStep = {
51
+ id: 'c',
52
+ type: StepType.CODE,
53
+ source: 'x',
54
+ compiled: { code: 'y', sourceMap: '{}', toolchain: 't' },
55
+ };
56
+ expect(resolveStepFields(step, new Map([['source', 42]]))).toEqual(new Map([['source', 42]]));
57
+ });
58
+ });