@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.
- package/.eslintrc.js +32 -32
- package/.prettierrc +5 -5
- package/README.md +88 -88
- package/dist/definition/definition.schema.js +6 -0
- package/dist/definition/definition.schema.js.map +1 -1
- package/dist/definition/definition.types.d.ts +11 -0
- package/dist/definition/definition.types.js +6 -1
- package/dist/definition/definition.types.js.map +1 -1
- package/dist/discord/discord.types.d.ts +2 -34
- package/dist/discord/discord.types.js +1 -9
- package/dist/discord/discord.types.js.map +1 -1
- package/dist/engine/engine-source.js +1 -1
- package/dist/errors/runtime-error-code.enum.d.ts +1 -0
- package/dist/errors/runtime-error-code.enum.js +1 -0
- package/dist/errors/runtime-error-code.enum.js.map +1 -1
- package/dist/runner-protocol/evaluation.types.d.ts +1 -0
- package/dist/steps/global-references.js +7 -0
- package/dist/steps/global-references.js.map +1 -1
- package/dist/steps/step-fields.js +10 -0
- package/dist/steps/step-fields.js.map +1 -1
- package/jest.config.ts +11 -11
- package/package.json +1 -1
- package/scripts/build-engine.cjs +70 -70
- package/src/__tests__/engine-bundle.test.ts +121 -121
- package/src/__tests__/surface.test.ts +81 -88
- package/src/access/__tests__/host-match.test.ts +24 -24
- package/src/access/access.types.ts +25 -25
- package/src/access/host-match.ts +13 -13
- package/src/cost/__tests__/execution-cost.test.ts +249 -249
- package/src/cost/execution-cost.ts +203 -203
- package/src/definition/__tests__/code-step.test.ts +56 -0
- package/src/definition/__tests__/validate-definition.test.ts +354 -354
- package/src/definition/definition.limits.ts +9 -9
- package/src/definition/definition.schema.ts +7 -0
- package/src/definition/definition.types.ts +21 -1
- package/src/definition/validate-definition.ts +206 -206
- package/src/definition/walk-steps.ts +44 -44
- package/src/discord/__tests__/discord-event-input.test.ts +90 -108
- package/src/discord/discord.types.ts +696 -738
- package/src/engine/__tests__/run-in-isolate.test.ts +519 -519
- package/src/engine/engine-entry.ts +3 -3
- package/src/engine/engine-global.ts +2 -2
- package/src/engine/run-in-isolate.ts +462 -462
- package/src/errors/runtime-error-code.enum.ts +5 -0
- package/src/index.ts +32 -32
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +271 -271
- package/src/interpreter/interpreter-error.ts +12 -12
- package/src/interpreter/interpreter.ts +483 -483
- package/src/interpreter/interpreter.types.ts +204 -204
- package/src/interpreter/sequence-path.ts +67 -67
- package/src/interpreter/test-host.ts +85 -85
- package/src/runner-protocol/__tests__/file-payload.test.ts +26 -26
- package/src/runner-protocol/evaluation.types.ts +2 -0
- package/src/runner-protocol/execution-protocol.types.ts +297 -297
- package/src/schedule/schedule.types.ts +100 -100
- package/src/server/__tests__/code-runner-session.test.ts +311 -311
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -310
- package/src/server/index.ts +11 -11
- package/src/steps/__tests__/global-references.test.ts +140 -124
- package/src/steps/__tests__/step-fields.test.ts +58 -0
- package/src/steps/execute-step.ts +186 -186
- package/src/steps/global-references.ts +56 -48
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +10 -0
- package/src/steps/value-source.ts +69 -69
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +35 -35
|
@@ -1,121 +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
|
-
});
|
|
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
|
+
});
|
|
@@ -1,88 +1,81 @@
|
|
|
1
|
-
import { builtinModules } from 'module';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// `
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/\
|
|
32
|
-
/\bimport\s*['"]([^'"]+)['"]/g,
|
|
33
|
-
/\
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
expect(
|
|
58
|
-
expect(['
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
'
|
|
67
|
-
'
|
|
68
|
-
'
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expect(MAX_PROGRESS_OUTPUT_CHARS).toBe(4_096);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('exports the error stack bound of the execution protocol', () => {
|
|
86
|
-
expect(MAX_ERROR_STACK_CHARS).toBe(4096);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
1
|
+
import { builtinModules } from 'module';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DiscordEventType,
|
|
7
|
+
MAX_ERROR_STACK_CHARS,
|
|
8
|
+
MAX_PROGRESS_OUTPUT_BYTES,
|
|
9
|
+
MAX_PROGRESS_OUTPUT_CHARS,
|
|
10
|
+
isDiscordEventInput,
|
|
11
|
+
} from '../index';
|
|
12
|
+
const SRC_DIR = path.resolve(__dirname, '..');
|
|
13
|
+
const SERVER_DIR = path.join(SRC_DIR, 'server');
|
|
14
|
+
const TESTS_DIR = path.join(SRC_DIR, '__tests__');
|
|
15
|
+
|
|
16
|
+
// `ws` and every Node built-in module (`fs`, `net`, `http`, `node:*`...) are forbidden outside
|
|
17
|
+
// `src/server`, so that the package root stays usable in a browser.
|
|
18
|
+
const FORBIDDEN = new Set<string>(['ws', ...builtinModules]);
|
|
19
|
+
|
|
20
|
+
const walkTsFiles = (dir: string): string[] =>
|
|
21
|
+
fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
22
|
+
const full = path.join(dir, entry.name);
|
|
23
|
+
if (entry.isDirectory()) {
|
|
24
|
+
return full === SERVER_DIR || full === TESTS_DIR ? [] : walkTsFiles(full);
|
|
25
|
+
}
|
|
26
|
+
return entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts') ? [full] : [];
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const IMPORT_PATTERNS = [
|
|
30
|
+
/\bfrom\s*['"]([^'"]+)['"]/g,
|
|
31
|
+
/\bimport\s*['"]([^'"]+)['"]/g,
|
|
32
|
+
/\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
33
|
+
/\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const importedSpecifiers = (text: string): string[] =>
|
|
37
|
+
IMPORT_PATTERNS.flatMap((pattern) => [...text.matchAll(pattern)].map((match) => match[1]));
|
|
38
|
+
|
|
39
|
+
const isForbidden = (specifier: string): boolean => {
|
|
40
|
+
const bare = specifier.startsWith('node:') ? specifier.slice('node:'.length) : specifier;
|
|
41
|
+
return FORBIDDEN.has(bare) || FORBIDDEN.has(bare.split('/')[0]);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
describe('browser-compatible package root', () => {
|
|
45
|
+
it('imports no Node built-in nor ws outside src/server', () => {
|
|
46
|
+
const offenders = walkTsFiles(SRC_DIR).flatMap((file) =>
|
|
47
|
+
importedSpecifiers(fs.readFileSync(file, 'utf8'))
|
|
48
|
+
.filter(isForbidden)
|
|
49
|
+
.map((specifier) => `${path.relative(SRC_DIR, file)} imports ${specifier}`),
|
|
50
|
+
);
|
|
51
|
+
expect(offenders).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('detects forbidden imports (guard sanity)', () => {
|
|
55
|
+
const source = "import { WebSocket } from 'ws';\nconst n = require('node:net');";
|
|
56
|
+
expect(importedSpecifiers(source)).toEqual(['ws', 'node:net']);
|
|
57
|
+
expect(['ws', 'node:net', 'fs/promises', 'http'].every(isForbidden)).toBe(true);
|
|
58
|
+
expect(['joi', './steps', '../access'].some(isForbidden)).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('public surface of the package root', () => {
|
|
63
|
+
it('exports the Discord event input contract', () => {
|
|
64
|
+
expect(Object.values(DiscordEventType)).toEqual([
|
|
65
|
+
'GUILD_MEMBER_ADD',
|
|
66
|
+
'GUILD_MEMBER_REMOVE',
|
|
67
|
+
'MESSAGE_CREATE',
|
|
68
|
+
'MESSAGE_REACTION_ADD',
|
|
69
|
+
]);
|
|
70
|
+
expect(typeof isDiscordEventInput).toBe('function');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('exports the step output bounds of the execution protocol (64 KB whole, 4 KB preview)', () => {
|
|
74
|
+
expect(MAX_PROGRESS_OUTPUT_BYTES).toBe(65_536);
|
|
75
|
+
expect(MAX_PROGRESS_OUTPUT_CHARS).toBe(4_096);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('exports the error stack bound of the execution protocol', () => {
|
|
79
|
+
expect(MAX_ERROR_STACK_CHARS).toBe(4096);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { hostMatches } from '../host-match';
|
|
2
|
-
|
|
3
|
-
describe('hostMatches', () => {
|
|
4
|
-
it('matches an exact host', () => {
|
|
5
|
-
expect(hostMatches('api.example.com', 'api.example.com')).toBe(true);
|
|
6
|
-
expect(hostMatches('api.example.com', 'example.com')).toBe(false);
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it('lets a wildcard cover any sub-domain', () => {
|
|
10
|
-
expect(hostMatches('api.example.com', '*.example.com')).toBe(true);
|
|
11
|
-
expect(hostMatches('a.b.example.com', '*.example.com')).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('does not let a wildcard cover the apex domain', () => {
|
|
15
|
-
expect(hostMatches('example.com', '*.example.com')).toBe(false);
|
|
16
|
-
expect(hostMatches('.example.com', '*.example.com')).toBe(false);
|
|
17
|
-
expect(hostMatches('badexample.com', '*.example.com')).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('ignores case', () => {
|
|
21
|
-
expect(hostMatches('API.Example.COM', 'api.example.com')).toBe(true);
|
|
22
|
-
expect(hostMatches('api.example.com', '*.EXAMPLE.com')).toBe(true);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
1
|
+
import { hostMatches } from '../host-match';
|
|
2
|
+
|
|
3
|
+
describe('hostMatches', () => {
|
|
4
|
+
it('matches an exact host', () => {
|
|
5
|
+
expect(hostMatches('api.example.com', 'api.example.com')).toBe(true);
|
|
6
|
+
expect(hostMatches('api.example.com', 'example.com')).toBe(false);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('lets a wildcard cover any sub-domain', () => {
|
|
10
|
+
expect(hostMatches('api.example.com', '*.example.com')).toBe(true);
|
|
11
|
+
expect(hostMatches('a.b.example.com', '*.example.com')).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('does not let a wildcard cover the apex domain', () => {
|
|
15
|
+
expect(hostMatches('example.com', '*.example.com')).toBe(false);
|
|
16
|
+
expect(hostMatches('.example.com', '*.example.com')).toBe(false);
|
|
17
|
+
expect(hostMatches('badexample.com', '*.example.com')).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('ignores case', () => {
|
|
21
|
+
expect(hostMatches('API.Example.COM', 'api.example.com')).toBe(true);
|
|
22
|
+
expect(hostMatches('api.example.com', '*.EXAMPLE.com')).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export enum AccessKind {
|
|
2
|
-
/** Outbound HTTP to a list of host names (exact, or `*.domain` for any sub-domain). */
|
|
3
|
-
HTTP = 'HTTP',
|
|
4
|
-
/** One action of the host catalog, by name. */
|
|
5
|
-
HOST_ACTION = 'HOST_ACTION',
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface HttpAccess {
|
|
9
|
-
kind: AccessKind.HTTP;
|
|
10
|
-
hosts: string[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface HostActionAccess {
|
|
14
|
-
kind: AccessKind.HOST_ACTION;
|
|
15
|
-
action: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* What a definition declares it needs (like the `permissions:` block of GitHub Actions), and,
|
|
20
|
-
* with the same shape, what a run is actually granted. An effect is emitted only when both
|
|
21
|
-
* cover it.
|
|
22
|
-
*/
|
|
23
|
-
export type AccessDeclaration = HttpAccess | HostActionAccess;
|
|
24
|
-
|
|
25
|
-
export type AccessGrant = AccessDeclaration;
|
|
1
|
+
export enum AccessKind {
|
|
2
|
+
/** Outbound HTTP to a list of host names (exact, or `*.domain` for any sub-domain). */
|
|
3
|
+
HTTP = 'HTTP',
|
|
4
|
+
/** One action of the host catalog, by name. */
|
|
5
|
+
HOST_ACTION = 'HOST_ACTION',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface HttpAccess {
|
|
9
|
+
kind: AccessKind.HTTP;
|
|
10
|
+
hosts: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface HostActionAccess {
|
|
14
|
+
kind: AccessKind.HOST_ACTION;
|
|
15
|
+
action: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What a definition declares it needs (like the `permissions:` block of GitHub Actions), and,
|
|
20
|
+
* with the same shape, what a run is actually granted. An effect is emitted only when both
|
|
21
|
+
* cover it.
|
|
22
|
+
*/
|
|
23
|
+
export type AccessDeclaration = HttpAccess | HostActionAccess;
|
|
24
|
+
|
|
25
|
+
export type AccessGrant = AccessDeclaration;
|
package/src/access/host-match.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Whether `host` is covered by an access `pattern`: an exact host name, or `*.domain`, which
|
|
3
|
-
* covers any sub-domain of `domain` but not `domain` itself. Comparison ignores case.
|
|
4
|
-
*/
|
|
5
|
-
export const hostMatches = (host: string, pattern: string): boolean => {
|
|
6
|
-
const candidate = host.toLowerCase();
|
|
7
|
-
const expected = pattern.toLowerCase();
|
|
8
|
-
if (!expected.startsWith('*.')) {
|
|
9
|
-
return candidate === expected;
|
|
10
|
-
}
|
|
11
|
-
const suffix = expected.slice(1);
|
|
12
|
-
return candidate.length > suffix.length && candidate.endsWith(suffix);
|
|
13
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Whether `host` is covered by an access `pattern`: an exact host name, or `*.domain`, which
|
|
3
|
+
* covers any sub-domain of `domain` but not `domain` itself. Comparison ignores case.
|
|
4
|
+
*/
|
|
5
|
+
export const hostMatches = (host: string, pattern: string): boolean => {
|
|
6
|
+
const candidate = host.toLowerCase();
|
|
7
|
+
const expected = pattern.toLowerCase();
|
|
8
|
+
if (!expected.startsWith('*.')) {
|
|
9
|
+
return candidate === expected;
|
|
10
|
+
}
|
|
11
|
+
const suffix = expected.slice(1);
|
|
12
|
+
return candidate.length > suffix.length && candidate.endsWith(suffix);
|
|
13
|
+
};
|