@workflow/world-testing 4.0.1-beta.2 → 4.0.1-beta.20
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/LICENSE.md +201 -21
- package/dist/.well-known/workflow/v1/flow.d.ts +3 -0
- package/dist/.well-known/workflow/v1/flow.d.ts.map +1 -0
- package/dist/.well-known/workflow/v1/flow.js +48856 -0
- package/dist/.well-known/workflow/v1/flow.js.map +1 -0
- package/dist/.well-known/workflow/v1/manifest.debug.json +37 -0
- package/dist/.well-known/workflow/v1/step.d.ts +3 -0
- package/dist/.well-known/workflow/v1/step.d.ts.map +1 -0
- package/dist/.well-known/workflow/v1/step.js +50752 -0
- package/dist/.well-known/workflow/v1/step.js.map +1 -0
- package/dist/src/addition.d.mts +2 -0
- package/dist/src/addition.d.mts.map +1 -0
- package/dist/src/addition.mjs +20 -0
- package/dist/src/addition.mjs.map +1 -0
- package/dist/src/idempotency.d.mts +2 -0
- package/dist/src/idempotency.d.mts.map +1 -0
- package/dist/src/idempotency.mjs +25 -0
- package/dist/src/idempotency.mjs.map +1 -0
- package/dist/src/index.d.mts +2 -0
- package/dist/src/index.d.mts.map +1 -0
- package/dist/src/index.mjs +7 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/server.d.mts +2 -0
- package/dist/src/server.d.mts.map +1 -0
- package/dist/src/server.mjs +79 -0
- package/dist/src/server.mjs.map +1 -0
- package/dist/src/util.d.mts +87 -0
- package/dist/src/util.d.mts.map +1 -0
- package/dist/src/util.mjs +78 -0
- package/dist/src/util.mjs.map +1 -0
- package/package.json +15 -11
- package/CHANGELOG.md +0 -35
- package/src/addition.mts +0 -27
- package/src/idempotency.mts +0 -30
- package/src/index.mts +0 -7
- package/src/server.mts +0 -104
- package/src/util.mts +0 -99
- package/test/embedded.test.ts +0 -3
- package/tsconfig.json +0 -11
- package/turbo.json +0 -13
- package/workflows/addition.ts +0 -16
- package/workflows/noop.ts +0 -37
package/src/util.mts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import cp from 'node:child_process';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
3
|
-
import { WorkflowRunSchema } from '@workflow/world';
|
|
4
|
-
import chalk, { type ChalkInstance } from 'chalk';
|
|
5
|
-
import jsonlines from 'jsonlines';
|
|
6
|
-
import { assert, onTestFailed, onTestFinished } from 'vitest';
|
|
7
|
-
import * as z from 'zod';
|
|
8
|
-
import type manifest from '../.well-known/workflow/v1/manifest.debug.json';
|
|
9
|
-
|
|
10
|
-
export const Control = z.object({
|
|
11
|
-
state: z.literal('listening'),
|
|
12
|
-
info: z.object({
|
|
13
|
-
port: z.number(),
|
|
14
|
-
}),
|
|
15
|
-
});
|
|
16
|
-
type Control = z.infer<typeof Control>;
|
|
17
|
-
|
|
18
|
-
type Files = keyof typeof manifest.workflows;
|
|
19
|
-
type Workflows<F extends Files> = keyof (typeof manifest.workflows)[F];
|
|
20
|
-
|
|
21
|
-
export const Worlds = {
|
|
22
|
-
embedded: 'embedded',
|
|
23
|
-
postgres: '@workflow/world-postgres',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export async function startServer(opts: { world: string }) {
|
|
27
|
-
let serverPath = new URL('./server.mts', import.meta.url).pathname;
|
|
28
|
-
|
|
29
|
-
if (!existsSync(serverPath)) {
|
|
30
|
-
serverPath = new URL('./server.mjs', import.meta.url).pathname;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const proc = cp.spawn('node', [serverPath], {
|
|
34
|
-
stdio: ['ignore', 'pipe', 'pipe', 'pipe'],
|
|
35
|
-
env: {
|
|
36
|
-
...process.env,
|
|
37
|
-
WORKFLOW_TARGET_WORLD: opts.world,
|
|
38
|
-
CONTROL_FD: '3',
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
onTestFinished(() => {
|
|
42
|
-
proc.kill();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const stdio = [] as { stream: ChalkInstance; chunk: string }[];
|
|
46
|
-
proc.stdout?.on('data', (chunk) => {
|
|
47
|
-
stdio.push({ stream: chalk.white, chunk: chunk.toString() });
|
|
48
|
-
});
|
|
49
|
-
proc.stderr?.on('data', (chunk) => {
|
|
50
|
-
stdio.push({ stream: chalk.red, chunk: chunk.toString() });
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
onTestFailed(() => {
|
|
54
|
-
console.log('=== SERVER STDIO ===');
|
|
55
|
-
let buffer = '';
|
|
56
|
-
for (const { stream, chunk } of stdio) {
|
|
57
|
-
buffer += stream.inverse(chunk);
|
|
58
|
-
}
|
|
59
|
-
console.log(buffer);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const fd3 = proc.stdio[3];
|
|
63
|
-
assert(fd3, 'fd3 should be defined');
|
|
64
|
-
|
|
65
|
-
for await (const chunk of fd3.pipe(jsonlines.parse())) {
|
|
66
|
-
return Control.parse(chunk);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
throw new Error('Server did not start correctly');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const Invoke = z.object({ runId: z.coerce.string() });
|
|
73
|
-
|
|
74
|
-
export function createFetcher(control: Control) {
|
|
75
|
-
return {
|
|
76
|
-
async invoke<F extends Files, W extends Workflows<F>>(
|
|
77
|
-
file: F,
|
|
78
|
-
workflow: W,
|
|
79
|
-
args: unknown[]
|
|
80
|
-
) {
|
|
81
|
-
const x = await fetch(`http://localhost:${control.info.port}/invoke`, {
|
|
82
|
-
method: 'POST',
|
|
83
|
-
headers: {
|
|
84
|
-
'content-type': 'application/json',
|
|
85
|
-
},
|
|
86
|
-
body: JSON.stringify({ file, workflow, args }),
|
|
87
|
-
});
|
|
88
|
-
const data = await x.json().then(Invoke.parse);
|
|
89
|
-
return data;
|
|
90
|
-
},
|
|
91
|
-
async getRun(id: string) {
|
|
92
|
-
const x = await fetch(
|
|
93
|
-
`http://localhost:${control.info.port}/runs/${encodeURIComponent(id)}`
|
|
94
|
-
);
|
|
95
|
-
const data = await x.json();
|
|
96
|
-
return WorkflowRunSchema.parseAsync(data);
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
}
|
package/test/embedded.test.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@workflow/tsconfig/base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"moduleResolution": "NodeNext",
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"module": "NodeNext",
|
|
7
|
-
"outDir": "dist"
|
|
8
|
-
},
|
|
9
|
-
"include": ["src", ".well-known"],
|
|
10
|
-
"exclude": ["node_modules", "**/*.test.ts"]
|
|
11
|
-
}
|
package/turbo.json
DELETED
package/workflows/addition.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { RetryableError } from 'workflow';
|
|
2
|
-
|
|
3
|
-
async function add(num: number, num2: number): Promise<number> {
|
|
4
|
-
'use step';
|
|
5
|
-
if (Math.random() < 0.2) {
|
|
6
|
-
throw new RetryableError('Random failure, please retry');
|
|
7
|
-
}
|
|
8
|
-
return num + num2;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function addition(num: number, num2: number): Promise<number> {
|
|
12
|
-
'use workflow';
|
|
13
|
-
const result = await add(num, num2);
|
|
14
|
-
console.log({ result });
|
|
15
|
-
return result;
|
|
16
|
-
}
|
package/workflows/noop.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
let count = 0;
|
|
2
|
-
export async function noop(_i: number) {
|
|
3
|
-
'use step';
|
|
4
|
-
|
|
5
|
-
count++;
|
|
6
|
-
return count;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function brokenWf() {
|
|
10
|
-
'use workflow';
|
|
11
|
-
|
|
12
|
-
const numbers = [] as number[];
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
const promises: Promise<number>[] = [];
|
|
16
|
-
for (let i = 0; i < 10; i++) {
|
|
17
|
-
promises.push(noop(i));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
console.log('await 10');
|
|
21
|
-
numbers.push(...(await Promise.all(promises)));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
{
|
|
25
|
-
const promises: Promise<number>[] = [];
|
|
26
|
-
for (let i = 0; i < 100; i++) {
|
|
27
|
-
promises.push(noop(1000 + i));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
console.log('await 100');
|
|
31
|
-
numbers.push(...(await Promise.all(promises)));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
console.log('done.');
|
|
35
|
-
|
|
36
|
-
return { numbers };
|
|
37
|
-
}
|