@abyss-project/runtime 1.0.0 → 2.0.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.
- 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,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveStepFields = exports.collectStepItems = void 0;
|
|
4
|
-
const
|
|
4
|
+
const evaluation_types_1 = require("../runner-protocol/evaluation.types");
|
|
5
5
|
const definition_types_1 = require("../definition/definition.types");
|
|
6
6
|
const value_source_1 = require("./value-source");
|
|
7
7
|
const recordFields = (base, record) => Object.entries(record ?? {}).map(([key, source]) => ({ path: (0, value_source_1.propertyPath)(base, key), source }));
|
|
@@ -35,13 +35,21 @@ const stepFields = (step) => {
|
|
|
35
35
|
];
|
|
36
36
|
case definition_types_1.StepType.HOST:
|
|
37
37
|
return recordFields('input', step.input);
|
|
38
|
+
case definition_types_1.StepType.LOG:
|
|
39
|
+
return [{ path: 'message', source: step.message }, ...optionalField('data', step.data)];
|
|
40
|
+
case definition_types_1.StepType.RESPOND:
|
|
41
|
+
return [
|
|
42
|
+
{ path: 'status', source: step.status },
|
|
43
|
+
...recordFields('headers', step.headers),
|
|
44
|
+
...optionalField('body', step.body),
|
|
45
|
+
];
|
|
38
46
|
case definition_types_1.StepType.STOP:
|
|
39
47
|
return optionalField('output', step.output);
|
|
40
48
|
}
|
|
41
49
|
};
|
|
42
50
|
const collectStepItems = (step) => {
|
|
43
51
|
if (step.type === definition_types_1.StepType.CODE) {
|
|
44
|
-
return [{ id: 'source', kind:
|
|
52
|
+
return [{ id: 'source', kind: evaluation_types_1.EvaluationKind.CODE, source: step.source }];
|
|
45
53
|
}
|
|
46
54
|
const items = [];
|
|
47
55
|
for (const field of stepFields(step)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step-fields.js","sourceRoot":"","sources":["../../src/steps/step-fields.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"step-fields.js","sourceRoot":"","sources":["../../src/steps/step-fields.ts"],"names":[],"mappings":";;;AAAA,0EAAqE;AAErE,qEAA0D;AAE1D,iDAA0E;AAU1E,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,MAA+C,EAAe,EAAE,CAClG,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAA,2BAAY,EAAC,IAAI,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;AAEnG,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,MAA+B,EAAe,EAAE,CACnF,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AAGjD,MAAM,UAAU,GAAG,CAAC,IAAU,EAAe,EAAE;IAC7C,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,2BAA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AG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,IAAI,GAAG,CACZ,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,IAAA,2BAAY,EAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAC/F,CAAC;AACJ,CAAC,CAAC;AAVW,QAAA,iBAAiB,qBAU5B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EvaluationItem } from '../runner-protocol/
|
|
1
|
+
import type { EvaluationItem } from '../runner-protocol/evaluation.types';
|
|
2
2
|
import type { ExpressionValue, ValueSource } from '../definition/definition.types';
|
|
3
3
|
export declare const isExpressionValue: (value: ValueSource) => value is ExpressionValue;
|
|
4
4
|
export declare const propertyPath: (base: string, key: string) => string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveValue = exports.collectItems = exports.propertyPath = exports.isExpressionValue = void 0;
|
|
4
|
-
const
|
|
4
|
+
const evaluation_types_1 = require("../runner-protocol/evaluation.types");
|
|
5
5
|
const TEMPLATE_PATTERN = /\{\{[\s\S]*?\}\}/;
|
|
6
6
|
const IDENTIFIER_KEY = /^[A-Za-z_$][\w$-]*$/;
|
|
7
7
|
const isExpressionValue = (value) => typeof value === 'object' &&
|
|
@@ -16,7 +16,7 @@ const indexPath = (base, index) => `${base}[${index}]`;
|
|
|
16
16
|
const collectItems = (path, source, items) => {
|
|
17
17
|
if (typeof source === 'string') {
|
|
18
18
|
if (TEMPLATE_PATTERN.test(source)) {
|
|
19
|
-
items.push({ id: path, kind:
|
|
19
|
+
items.push({ id: path, kind: evaluation_types_1.EvaluationKind.TEMPLATE, source });
|
|
20
20
|
}
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
@@ -24,7 +24,7 @@ const collectItems = (path, source, items) => {
|
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
if ((0, exports.isExpressionValue)(source)) {
|
|
27
|
-
items.push({ id: path, kind:
|
|
27
|
+
items.push({ id: path, kind: evaluation_types_1.EvaluationKind.EXPRESSION, source: source.$expression });
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
if (Array.isArray(source)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"value-source.js","sourceRoot":"","sources":["../../src/steps/value-source.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"value-source.js","sourceRoot":"","sources":["../../src/steps/value-source.ts"],"names":[],"mappings":";;;AAAA,0EAAqE;AAIrE,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAC5C,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAEtC,MAAM,iBAAiB,GAAG,CAAC,KAAkB,EAA4B,EAAE,CAChF,OAAO,KAAK,KAAK,QAAQ;IACzB,KAAK,KAAK,IAAI;IACd,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IACrB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC;IAC/B,OAAQ,KAAyB,CAAC,WAAW,KAAK,QAAQ,CAAC;AALhD,QAAA,iBAAiB,qBAK+B;AAGtD,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,GAAW,EAAU,EAAE,CAChE,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;AADrE,QAAA,YAAY,gBACyD;AAElF,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CAAC,GAAG,IAAI,IAAI,KAAK,GAAG,CAAC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B,EACnB,OAAqC,EAC5B,EAAE;IACX,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACpE,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAClD,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,IAAI,IAAA,yBAAiB,EAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAA,oBAAY,EAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QAC3C,GAAG;QACH,IAAA,oBAAY,EAAC,IAAA,oBAAY,EAAC,IAAI,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC;KACtD,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,YAAY,gBAuBvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abyss-project/runtime",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Abyss automation core: definitions, interpreter, runner protocol",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,12 +12,19 @@
|
|
|
12
12
|
"./server": {
|
|
13
13
|
"types": "./dist/server/index.d.ts",
|
|
14
14
|
"default": "./dist/server/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./engine": {
|
|
17
|
+
"types": "./dist/engine/engine-source.d.ts",
|
|
18
|
+
"default": "./dist/engine/engine-source.js"
|
|
15
19
|
}
|
|
16
20
|
},
|
|
17
21
|
"typesVersions": {
|
|
18
22
|
"*": {
|
|
19
23
|
"server": [
|
|
20
24
|
"dist/server/index.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"engine": [
|
|
27
|
+
"dist/engine/engine-source.d.ts"
|
|
21
28
|
]
|
|
22
29
|
}
|
|
23
30
|
},
|
|
@@ -42,6 +49,7 @@
|
|
|
42
49
|
"@types/ws": "^8",
|
|
43
50
|
"@typescript-eslint/eslint-plugin": "8.71.0",
|
|
44
51
|
"@typescript-eslint/parser": "8.71.0",
|
|
52
|
+
"esbuild": "^0.28.2",
|
|
45
53
|
"eslint": "^8.57.1",
|
|
46
54
|
"eslint-config-prettier": "^8.3.0",
|
|
47
55
|
"eslint-plugin-filenames-simple": "^0.7.0",
|
|
@@ -56,7 +64,7 @@
|
|
|
56
64
|
"lint": "eslint \"{src,apps,libs,test,core}/**/*.ts\" --fix",
|
|
57
65
|
"lint:check": "eslint \"{src,apps,libs,test,core}/**/*.ts\" --max-warnings 0",
|
|
58
66
|
"tsc": "tsc",
|
|
59
|
-
"build": "tsc",
|
|
67
|
+
"build": "tsc && node scripts/build-engine.cjs",
|
|
60
68
|
"test": "jest",
|
|
61
69
|
"dev": "tsc --watch"
|
|
62
70
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* build-engine.cjs — bundles the isolate engine (ADR-0238) into one self-contained script and
|
|
4
|
+
* ships it as a string: `@abyss-project/runtime/engine` exports `ENGINE_SOURCE`.
|
|
5
|
+
*
|
|
6
|
+
* The script is an IIFE that defines one global (`ENGINE_GLOBAL_NAME`, `{ runInIsolate }`).
|
|
7
|
+
* `platform: 'neutral'` resolves no Node built-in: an import of `fs`, `net`... fails the build
|
|
8
|
+
* instead of slipping into the isolate. Runs after `tsc`, which emits the rest of `dist`.
|
|
9
|
+
*
|
|
10
|
+
* USAGE (from the package directory, what `build` does)
|
|
11
|
+
* node scripts/build-engine.cjs
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/* eslint-disable no-console */
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const fs = require('fs');
|
|
18
|
+
const path = require('path');
|
|
19
|
+
const esbuild = require('esbuild');
|
|
20
|
+
|
|
21
|
+
const PACKAGE_DIR = path.resolve(__dirname, '..');
|
|
22
|
+
const ENTRY = path.join(PACKAGE_DIR, 'src', 'engine', 'engine-entry.ts');
|
|
23
|
+
const OUT_DIR = path.join(PACKAGE_DIR, 'dist', 'engine');
|
|
24
|
+
|
|
25
|
+
/** The engine script, as a string; `globalName` is the global it defines. */
|
|
26
|
+
function bundleEngine(globalName) {
|
|
27
|
+
const result = esbuild.buildSync({
|
|
28
|
+
entryPoints: [ENTRY],
|
|
29
|
+
bundle: true,
|
|
30
|
+
format: 'iife',
|
|
31
|
+
globalName,
|
|
32
|
+
platform: 'neutral',
|
|
33
|
+
target: 'es2021',
|
|
34
|
+
write: false,
|
|
35
|
+
legalComments: 'none',
|
|
36
|
+
logLevel: 'silent',
|
|
37
|
+
});
|
|
38
|
+
return result.outputFiles[0].text;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function main() {
|
|
42
|
+
const globalPath = path.join(OUT_DIR, 'engine-global.js');
|
|
43
|
+
if (!fs.existsSync(globalPath)) {
|
|
44
|
+
throw new Error(`${globalPath} is missing: run tsc before this script`);
|
|
45
|
+
}
|
|
46
|
+
const { ENGINE_GLOBAL_NAME } = require(globalPath);
|
|
47
|
+
const source = bundleEngine(ENGINE_GLOBAL_NAME);
|
|
48
|
+
fs.writeFileSync(
|
|
49
|
+
path.join(OUT_DIR, 'engine-source.js'),
|
|
50
|
+
`"use strict";\nObject.defineProperty(exports, "__esModule", { value: true });\n` +
|
|
51
|
+
`exports.ENGINE_SOURCE = ${JSON.stringify(source)};\n`,
|
|
52
|
+
);
|
|
53
|
+
fs.writeFileSync(
|
|
54
|
+
path.join(OUT_DIR, 'engine-source.d.ts'),
|
|
55
|
+
'/** The isolate engine script: evaluating it defines the global `ENGINE_GLOBAL_NAME`. */\n' +
|
|
56
|
+
'export declare const ENGINE_SOURCE: string;\n',
|
|
57
|
+
);
|
|
58
|
+
console.log(`engine bundle: ${source.length} characters in dist/engine/engine-source.js`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (require.main === module) {
|
|
62
|
+
try {
|
|
63
|
+
main();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(error instanceof Error ? error.message : error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { bundleEngine };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import * as vm from 'vm';
|
|
2
|
+
import { AccessKind } from '../access/access.types';
|
|
3
|
+
import {
|
|
4
|
+
CURRENT_FORMAT_VERSION,
|
|
5
|
+
HttpMethod,
|
|
6
|
+
LogLevel,
|
|
7
|
+
StepType,
|
|
8
|
+
StopStatus,
|
|
9
|
+
} from '../definition/definition.types';
|
|
10
|
+
import type { RuntimeDefinition } from '../definition/definition.types';
|
|
11
|
+
import { ENGINE_GLOBAL_NAME } from '../engine/engine-global';
|
|
12
|
+
import { EngineResultKind } from '../engine/run-in-isolate';
|
|
13
|
+
import type { EngineHost, EngineRequest, EngineResult } from '../engine/run-in-isolate';
|
|
14
|
+
import type { EvaluationItem } from '../runner-protocol/evaluation.types';
|
|
15
|
+
import { CoreCapability, ExecutionStatus } from '../runner-protocol/execution-protocol.types';
|
|
16
|
+
|
|
17
|
+
// The build script is plain CommonJS, shared with `build`: the test bundles exactly what ships.
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
19
|
+
const { bundleEngine } = require('../../scripts/build-engine.cjs') as {
|
|
20
|
+
bundleEngine: (globalName: string) => string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type Engine = { runInIsolate: (request: EngineRequest, host: EngineHost) => Promise<EngineResult> };
|
|
24
|
+
|
|
25
|
+
const definition: RuntimeDefinition = {
|
|
26
|
+
formatVersion: CURRENT_FORMAT_VERSION,
|
|
27
|
+
accesses: [{ kind: AccessKind.HTTP, hosts: ['api.example.com'] }],
|
|
28
|
+
steps: [
|
|
29
|
+
{ id: 'double', type: StepType.SET, variable: 'n', value: { $expression: 'input.n * 2' } },
|
|
30
|
+
{
|
|
31
|
+
id: 'fetch',
|
|
32
|
+
type: StepType.HTTP,
|
|
33
|
+
method: HttpMethod.GET,
|
|
34
|
+
url: 'https://api.example.com/{{ vars.n }}',
|
|
35
|
+
},
|
|
36
|
+
{ id: 'note', type: StepType.LOG, level: LogLevel.INFO, message: 'fetched' },
|
|
37
|
+
{
|
|
38
|
+
id: 'end',
|
|
39
|
+
type: StepType.STOP,
|
|
40
|
+
status: StopStatus.SUCCEEDED,
|
|
41
|
+
output: { $expression: 'vars.n' },
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
describe('isolate engine bundle', () => {
|
|
47
|
+
let source: string;
|
|
48
|
+
|
|
49
|
+
beforeAll(() => {
|
|
50
|
+
source = bundleEngine(ENGINE_GLOBAL_NAME);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('carries no module loader and no Joi', () => {
|
|
54
|
+
expect(source).not.toMatch(/\brequire\s*\(/);
|
|
55
|
+
expect(source).not.toMatch(/joi/i);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('loads in a bare context and runs a definition with a fake evaluate and callHost', async () => {
|
|
59
|
+
// No `require`, `process`, `URL`, timers nor console: only the language built-ins.
|
|
60
|
+
const context = vm.createContext({});
|
|
61
|
+
vm.runInContext(source, context);
|
|
62
|
+
expect(vm.runInContext('typeof require + typeof process + typeof URL', context)).toBe(
|
|
63
|
+
'undefinedundefinedundefined',
|
|
64
|
+
);
|
|
65
|
+
const engine = (context as Record<string, unknown>)[ENGINE_GLOBAL_NAME] as Engine;
|
|
66
|
+
expect(typeof engine.runInIsolate).toBe('function');
|
|
67
|
+
|
|
68
|
+
const values: Record<string, unknown> = {
|
|
69
|
+
'input.n * 2': 42,
|
|
70
|
+
'https://api.example.com/{{ vars.n }}': 'https://api.example.com/42',
|
|
71
|
+
'vars.n': 42,
|
|
72
|
+
};
|
|
73
|
+
const calls: Array<{ stepId: string; capability: string; args: unknown }> = [];
|
|
74
|
+
const progress: string[] = [];
|
|
75
|
+
const host: EngineHost = {
|
|
76
|
+
evaluate: async (items: EvaluationItem[]) =>
|
|
77
|
+
items.map((item) => ({ id: item.id, ok: true as const, value: values[item.source] })),
|
|
78
|
+
callHost: async (stepId, capability, args) => {
|
|
79
|
+
calls.push({ stepId, capability, args });
|
|
80
|
+
return {
|
|
81
|
+
ok: true,
|
|
82
|
+
value:
|
|
83
|
+
capability === CoreCapability.HTTP_FETCH
|
|
84
|
+
? { status: 200, headers: {}, body: null }
|
|
85
|
+
: null,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
onProgress: (p) => progress.push(`${p.stepId}:${p.phase}`),
|
|
89
|
+
now: () => 0,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const result = await engine.runInIsolate(
|
|
93
|
+
{
|
|
94
|
+
definition,
|
|
95
|
+
input: { n: 21 },
|
|
96
|
+
capabilities: [CoreCapability.HTTP_FETCH, CoreCapability.LOG_WRITE],
|
|
97
|
+
budget: { maxSteps: 10, maxEffects: 10 },
|
|
98
|
+
},
|
|
99
|
+
host,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// Values built in the other realm: compare their JSON.
|
|
103
|
+
expect(JSON.parse(JSON.stringify(result))).toEqual({
|
|
104
|
+
kind: EngineResultKind.FINISHED,
|
|
105
|
+
outcome: { status: ExecutionStatus.SUCCEEDED, output: 42 },
|
|
106
|
+
});
|
|
107
|
+
expect(JSON.parse(JSON.stringify(calls))).toEqual([
|
|
108
|
+
{
|
|
109
|
+
stepId: 'fetch',
|
|
110
|
+
capability: CoreCapability.HTTP_FETCH,
|
|
111
|
+
args: { method: 'GET', url: 'https://api.example.com/42', headers: {} },
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
stepId: 'note',
|
|
115
|
+
capability: CoreCapability.LOG_WRITE,
|
|
116
|
+
args: { level: LogLevel.INFO, message: 'fetched' },
|
|
117
|
+
},
|
|
118
|
+
]);
|
|
119
|
+
expect(progress).toHaveLength(8);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COST_RATES,
|
|
3
|
+
CostedExecutionStatus,
|
|
4
|
+
RESOURCE_PROFILES,
|
|
5
|
+
ResourceProfile,
|
|
6
|
+
computeExecutionCost,
|
|
7
|
+
computeStepCost,
|
|
8
|
+
} from '../execution-cost';
|
|
9
|
+
import type { ExecutionCostInput, StepUsage } from '../execution-cost';
|
|
10
|
+
|
|
11
|
+
const NO_USAGE: StepUsage = { cpuMs: 0, wallMs: 0, netOutBytes: 0, httpCalls: 0, storeWrites: 0 };
|
|
12
|
+
|
|
13
|
+
const execution = (overrides: Partial<ExecutionCostInput> = {}): ExecutionCostInput => ({
|
|
14
|
+
...NO_USAGE,
|
|
15
|
+
status: CostedExecutionStatus.RAN,
|
|
16
|
+
profile: ResourceProfile.S,
|
|
17
|
+
guaranteedCpu: false,
|
|
18
|
+
...overrides,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const usage = (overrides: Partial<StepUsage>): StepUsage => ({ ...NO_USAGE, ...overrides });
|
|
22
|
+
|
|
23
|
+
const sum = (values: number[]): number => values.reduce((total, value) => total + value, 0);
|
|
24
|
+
|
|
25
|
+
describe('resource profiles and rates', () => {
|
|
26
|
+
it('follow ADR-0239', () => {
|
|
27
|
+
expect(RESOURCE_PROFILES).toEqual({
|
|
28
|
+
S: { memoryMb: 128, cpuCoefficient: 1 },
|
|
29
|
+
M: { memoryMb: 256, cpuCoefficient: 1.05 },
|
|
30
|
+
L: { memoryMb: 512, cpuCoefficient: 1.1 },
|
|
31
|
+
XL: { memoryMb: 1024, cpuCoefficient: 1.2 },
|
|
32
|
+
XXL: { memoryMb: 2048, cpuCoefficient: 1.35 },
|
|
33
|
+
});
|
|
34
|
+
expect(COST_RATES).toEqual({
|
|
35
|
+
executionMillicredits: 10,
|
|
36
|
+
cpuMillicreditsPerSecond: 500,
|
|
37
|
+
guaranteedCpuCoefficient: 1.5,
|
|
38
|
+
memoryMillicreditsPerGbSecond: 100,
|
|
39
|
+
networkOutMillicreditsPerMb: 1000,
|
|
40
|
+
httpCallMillicredits: 10,
|
|
41
|
+
storeWriteMillicredits: 10,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('computeExecutionCost', () => {
|
|
47
|
+
it('prices a 3 s wait in profile S at about 0.05 credit', () => {
|
|
48
|
+
// 10 + 0.125 GB × 3 s × 100 = 47.5, rounded half-up.
|
|
49
|
+
const cost = computeExecutionCost(execution({ wallMs: 3_000 }));
|
|
50
|
+
expect(cost).toBe(48);
|
|
51
|
+
expect(cost / 1000).toBeCloseTo(0.05, 2);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('prices 2 s of CPU in profile L at about 1.1 credits for the CPU part', () => {
|
|
55
|
+
const computing = computeExecutionCost(
|
|
56
|
+
execution({ profile: ResourceProfile.L, cpuMs: 2_000, wallMs: 2_000 }),
|
|
57
|
+
);
|
|
58
|
+
const waiting = computeExecutionCost(execution({ profile: ResourceProfile.L, wallMs: 2_000 }));
|
|
59
|
+
expect(computing - waiting).toBe(1_100);
|
|
60
|
+
// 10 + 1100 CPU + 0.5 GB × 2 s × 100 memory.
|
|
61
|
+
expect(computing).toBe(1_210);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('makes a computation cost more than a wait of the same duration', () => {
|
|
65
|
+
const wall = { wallMs: 3_000 };
|
|
66
|
+
expect(computeExecutionCost(execution({ ...wall, cpuMs: 3_000 }))).toBeGreaterThan(
|
|
67
|
+
computeExecutionCost(execution(wall)),
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('applies the profile coefficient and the guaranteed CPU coefficient to the CPU part', () => {
|
|
72
|
+
const cpu = { cpuMs: 1_000 };
|
|
73
|
+
expect(computeExecutionCost(execution(cpu))).toBe(10 + 500);
|
|
74
|
+
expect(computeExecutionCost(execution({ ...cpu, guaranteedCpu: true }))).toBe(10 + 750);
|
|
75
|
+
expect(computeExecutionCost(execution({ ...cpu, profile: ResourceProfile.XXL }))).toBe(
|
|
76
|
+
10 + 675,
|
|
77
|
+
);
|
|
78
|
+
expect(
|
|
79
|
+
computeExecutionCost(execution({ ...cpu, profile: ResourceProfile.M, guaranteedCpu: true })),
|
|
80
|
+
).toBe(10 + 788); // 500 × 1.05 × 1.5 = 787.5
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('prices the allocated memory, the network out and the effects', () => {
|
|
84
|
+
expect(computeExecutionCost(execution({ profile: ResourceProfile.XL, wallMs: 1_000 }))).toBe(
|
|
85
|
+
10 + 100,
|
|
86
|
+
);
|
|
87
|
+
expect(computeExecutionCost(execution({ netOutBytes: 1024 * 1024 }))).toBe(10 + 1_000);
|
|
88
|
+
expect(computeExecutionCost(execution({ httpCalls: 2, storeWrites: 3 }))).toBe(10 + 50);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('rounds half-up once, at the end', () => {
|
|
92
|
+
// 128 MB × 40 ms = 0.5 millicredit.
|
|
93
|
+
expect(computeExecutionCost(execution({ wallMs: 40 }))).toBe(11);
|
|
94
|
+
// Fractions of a millisecond count.
|
|
95
|
+
expect(computeExecutionCost(execution({ cpuMs: 0.999 }))).toBe(10);
|
|
96
|
+
expect(computeExecutionCost(execution({ cpuMs: 1 }))).toBe(11);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('makes an interrupted or refused execution free', () => {
|
|
100
|
+
const heavy = { cpuMs: 5_000, wallMs: 9_000, netOutBytes: 10_000_000, httpCalls: 4 };
|
|
101
|
+
expect(
|
|
102
|
+
computeExecutionCost(execution({ ...heavy, status: CostedExecutionStatus.INTERRUPTED })),
|
|
103
|
+
).toBe(0);
|
|
104
|
+
expect(
|
|
105
|
+
computeExecutionCost(execution({ ...heavy, status: CostedExecutionStatus.REFUSED })),
|
|
106
|
+
).toBe(0);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('charges the execution price once: a resumed segment adds only its measure', () => {
|
|
110
|
+
expect(computeExecutionCost(execution({ wallMs: 3_000, resumedSegment: true }))).toBe(38);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('refuses a negative or non-finite measure', () => {
|
|
114
|
+
expect(() => computeExecutionCost(execution({ cpuMs: -1 }))).toThrow(RangeError);
|
|
115
|
+
expect(() => computeExecutionCost(execution({ wallMs: Number.NaN }))).toThrow(RangeError);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('computeStepCost', () => {
|
|
120
|
+
it('gives each step its share, so that steps plus the execution price equal the total', () => {
|
|
121
|
+
const steps = [
|
|
122
|
+
usage({ cpuMs: 3.3, wallMs: 12.7 }),
|
|
123
|
+
usage({ cpuMs: 120.25, wallMs: 450, httpCalls: 1, netOutBytes: 2_345 }),
|
|
124
|
+
usage({ wallMs: 3_000 }),
|
|
125
|
+
usage({ cpuMs: 7.77, wallMs: 9.1, storeWrites: 2 }),
|
|
126
|
+
];
|
|
127
|
+
const total = execution({
|
|
128
|
+
profile: ResourceProfile.M,
|
|
129
|
+
guaranteedCpu: true,
|
|
130
|
+
// The engine between the steps adds CPU and time measured at the execution level only.
|
|
131
|
+
cpuMs: 140,
|
|
132
|
+
wallMs: 3_500,
|
|
133
|
+
httpCalls: 1,
|
|
134
|
+
storeWrites: 2,
|
|
135
|
+
netOutBytes: 2_345,
|
|
136
|
+
});
|
|
137
|
+
const costs = computeStepCost({ execution: total, steps });
|
|
138
|
+
expect(costs).toHaveLength(4);
|
|
139
|
+
costs.forEach((cost) => expect(Number.isInteger(cost)).toBe(true));
|
|
140
|
+
expect(sum(costs) + COST_RATES.executionMillicredits).toBe(computeExecutionCost(total));
|
|
141
|
+
expect(costs[2]).toBeGreaterThan(costs[0]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('holds the invariant over many shapes', () => {
|
|
145
|
+
for (let n = 1; n <= 40; n += 1) {
|
|
146
|
+
const steps = Array.from({ length: n }, (_, i) =>
|
|
147
|
+
usage({ cpuMs: (i * 7.3) % 11, wallMs: (i * 13.1) % 29, httpCalls: i % 3 === 0 ? 1 : 0 }),
|
|
148
|
+
);
|
|
149
|
+
const totals = steps.reduce(
|
|
150
|
+
(acc, step) => ({
|
|
151
|
+
cpuMs: acc.cpuMs + step.cpuMs,
|
|
152
|
+
wallMs: acc.wallMs + step.wallMs,
|
|
153
|
+
httpCalls: acc.httpCalls + step.httpCalls,
|
|
154
|
+
}),
|
|
155
|
+
{ cpuMs: 0.37 * n, wallMs: 1.9 * n, httpCalls: 0 },
|
|
156
|
+
);
|
|
157
|
+
for (const profile of Object.values(ResourceProfile)) {
|
|
158
|
+
const total = execution({ ...totals, profile, guaranteedCpu: n % 2 === 0 });
|
|
159
|
+
const costs = computeStepCost({ execution: total, steps });
|
|
160
|
+
expect(sum(costs) + COST_RATES.executionMillicredits).toBe(computeExecutionCost(total));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('rounds cumulatively instead of rounding each step', () => {
|
|
166
|
+
// Three steps of 0.4 millicredit each (128 MB × 32 ms): 1.2 in total.
|
|
167
|
+
const step = usage({ wallMs: 32 });
|
|
168
|
+
const total = execution({ wallMs: 96 });
|
|
169
|
+
expect(computeExecutionCost(total)).toBe(11);
|
|
170
|
+
expect(computeStepCost({ execution: total, steps: [step, step, step] })).toEqual([0, 1, 0]);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('carries no execution price on a resumed segment', () => {
|
|
174
|
+
const total = execution({ wallMs: 3_000, resumedSegment: true });
|
|
175
|
+
const costs = computeStepCost({ execution: total, steps: [usage({ wallMs: 3_000 })] });
|
|
176
|
+
expect(sum(costs)).toBe(computeExecutionCost(total));
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('is zero for every step of an interrupted execution', () => {
|
|
180
|
+
const total = execution({
|
|
181
|
+
status: CostedExecutionStatus.INTERRUPTED,
|
|
182
|
+
cpuMs: 900,
|
|
183
|
+
wallMs: 2_000,
|
|
184
|
+
});
|
|
185
|
+
expect(
|
|
186
|
+
computeStepCost({ execution: total, steps: [usage({ cpuMs: 400 }), usage({ cpuMs: 500 })] }),
|
|
187
|
+
).toEqual([0, 0]);
|
|
188
|
+
expect(computeExecutionCost(total)).toBe(0);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('returns nothing for an execution without step', () => {
|
|
192
|
+
expect(computeStepCost({ execution: execution({ wallMs: 10 }), steps: [] })).toEqual([]);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('refuses a negative step measure', () => {
|
|
196
|
+
expect(() =>
|
|
197
|
+
computeStepCost({ execution: execution(), steps: [usage({ httpCalls: -1 })] }),
|
|
198
|
+
).toThrow(RangeError);
|
|
199
|
+
});
|
|
200
|
+
});
|