@workflow/world-testing 4.0.1-beta.30 → 4.0.1-beta.32

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.
@@ -1,5 +1,10 @@
1
1
  {
2
2
  "steps": {
3
+ "workflows/addition.ts": {
4
+ "add": {
5
+ "stepId": "step//workflows/addition.ts//add"
6
+ }
7
+ },
3
8
  "workflow/dist/internal/builtins.js": {
4
9
  "__builtin_response_array_buffer": {
5
10
  "stepId": "__builtin_response_array_buffer"
@@ -11,16 +16,6 @@
11
16
  "stepId": "__builtin_response_text"
12
17
  }
13
18
  },
14
- "workflows/null-byte.ts": {
15
- "nullByteStep": {
16
- "stepId": "step//workflows/null-byte.ts//nullByteStep"
17
- }
18
- },
19
- "workflows/addition.ts": {
20
- "add": {
21
- "stepId": "step//workflows/addition.ts//add"
22
- }
23
- },
24
19
  "workflows/noop.ts": {
25
20
  "noop": {
26
21
  "stepId": "step//workflows/noop.ts//noop"
@@ -34,31 +29,31 @@
34
29
  "stepId": "step//workflows/retriable-and-fatal.ts//stepThatThrowsRetryableError"
35
30
  }
36
31
  },
37
- "workflows/hooks.ts": {
38
- "writeEvent": {
39
- "stepId": "step//workflows/hooks.ts//writeEvent"
32
+ "workflows/null-byte.ts": {
33
+ "nullByteStep": {
34
+ "stepId": "step//workflows/null-byte.ts//nullByteStep"
40
35
  }
41
36
  },
42
37
  "workflow/dist/stdlib.js": {
43
38
  "fetch": {
44
39
  "stepId": "step//workflow/dist/stdlib.js//fetch"
45
40
  }
41
+ },
42
+ "workflows/hooks.ts": {
43
+ "writeEvent": {
44
+ "stepId": "step//workflows/hooks.ts//writeEvent"
45
+ }
46
46
  }
47
47
  },
48
48
  "workflows": {
49
- "workflows/null-byte.ts": {
50
- "nullByteWorkflow": {
51
- "workflowId": "workflow//workflows/null-byte.ts//nullByteWorkflow"
52
- }
53
- },
54
49
  "workflows/noop.ts": {
55
50
  "brokenWf": {
56
51
  "workflowId": "workflow//workflows/noop.ts//brokenWf"
57
52
  }
58
53
  },
59
- "workflows/addition.ts": {
60
- "addition": {
61
- "workflowId": "workflow//workflows/addition.ts//addition"
54
+ "workflows/null-byte.ts": {
55
+ "nullByteWorkflow": {
56
+ "workflowId": "workflow//workflows/null-byte.ts//nullByteWorkflow"
62
57
  }
63
58
  },
64
59
  "workflows/retriable-and-fatal.ts": {
@@ -70,6 +65,11 @@
70
65
  "collectWithHook": {
71
66
  "workflowId": "workflow//workflows/hooks.ts//collectWithHook"
72
67
  }
68
+ },
69
+ "workflows/addition.ts": {
70
+ "addition": {
71
+ "workflowId": "workflow//workflows/addition.ts//addition"
72
+ }
73
73
  }
74
74
  }
75
75
  }
@@ -24524,6 +24524,17 @@ async function brokenWf() {
24524
24524
  __name(brokenWf, "brokenWf");
24525
24525
  brokenWf.workflowId = "workflow//workflows/noop.ts//brokenWf";
24526
24526
  registerStepFunction("step//workflows/noop.ts//noop", noop);
24527
+ // workflows/null-byte.ts
24528
+ async function nullByteStep() {
24529
+ return "null byte \0";
24530
+ }
24531
+ __name(nullByteStep, "nullByteStep");
24532
+ async function nullByteWorkflow() {
24533
+ throw new Error("You attempted to execute workflow nullByteWorkflow function directly. To start a workflow, use start(nullByteWorkflow) from workflow/api");
24534
+ }
24535
+ __name(nullByteWorkflow, "nullByteWorkflow");
24536
+ nullByteWorkflow.workflowId = "workflow//workflows/null-byte.ts//nullByteWorkflow";
24537
+ registerStepFunction("step//workflows/null-byte.ts//nullByteStep", nullByteStep);
24527
24538
  // ../utils/dist/index.js
24528
24539
  var import_ms = __toESM(require_ms(), 1);
24529
24540
  function once(fn) {
@@ -25219,7 +25230,7 @@ var PROC_ROOT = join([
25219
25230
  "",
25220
25231
  "proc"
25221
25232
  ], "/");
25222
- async function getLinuxPort(pid) {
25233
+ async function getLinuxPorts(pid) {
25223
25234
  const listenState = "0A";
25224
25235
  const tcpFiles = [
25225
25236
  `${PROC_ROOT}/net/tcp`,
@@ -25248,16 +25259,16 @@ async function getLinuxPort(pid) {
25248
25259
  }
25249
25260
  }
25250
25261
  catch {
25251
- return void 0;
25262
+ return [];
25252
25263
  }
25253
25264
  if (socketInodes.length === 0) {
25254
- return void 0;
25265
+ return [];
25255
25266
  }
25267
+ const inodeToPort = /* @__PURE__ */ new Map();
25256
25268
  for (const tcpFile of tcpFiles) {
25257
25269
  try {
25258
25270
  const content = await (0, import_promises.readFile)(tcpFile, "utf8");
25259
25271
  const lines = content.split("\n").slice(1);
25260
- const inodeToPort = /* @__PURE__ */ new Map();
25261
25272
  for (const line of lines) {
25262
25273
  if (!line.trim())
25263
25274
  continue;
@@ -25282,87 +25293,152 @@ async function getLinuxPort(pid) {
25282
25293
  inodeToPort.set(inode, port);
25283
25294
  }
25284
25295
  }
25285
- for (const inode of socketInodes) {
25286
- const port = inodeToPort.get(inode);
25287
- if (port !== void 0) {
25288
- return port;
25289
- }
25290
- }
25291
25296
  }
25292
25297
  catch {
25293
25298
  continue;
25294
25299
  }
25295
25300
  }
25296
- return void 0;
25301
+ const ports = [];
25302
+ for (const inode of socketInodes) {
25303
+ const port = inodeToPort.get(inode);
25304
+ if (port !== void 0) {
25305
+ ports.push(port);
25306
+ }
25307
+ }
25308
+ return ports;
25297
25309
  }
25298
- __name(getLinuxPort, "getLinuxPort");
25299
- async function getPort() {
25300
- const { pid, platform } = process;
25301
- let port;
25310
+ __name(getLinuxPorts, "getLinuxPorts");
25311
+ async function getDarwinPorts(pid) {
25302
25312
  try {
25303
- switch (platform) {
25304
- case "linux": {
25305
- port = await getLinuxPort(pid);
25306
- break;
25307
- }
25308
- case "darwin": {
25309
- const { stdout } = await execFileAsync("lsof", [
25310
- "-a",
25311
- "-i",
25312
- "-P",
25313
- "-n",
25314
- "-p",
25315
- pid.toString()
25316
- ]);
25317
- const lines = stdout.split("\n");
25318
- for (const line of lines) {
25319
- if (line.includes("LISTEN")) {
25320
- const parts = line.trim().split(/\s+/);
25321
- const addr = parts[8];
25322
- if (addr) {
25323
- const colonIndex = addr.lastIndexOf(":");
25324
- if (colonIndex !== -1) {
25325
- port = parsePort(addr.slice(colonIndex + 1));
25326
- if (port !== void 0) {
25327
- break;
25328
- }
25329
- }
25313
+ const { stdout } = await execFileAsync("lsof", [
25314
+ "-a",
25315
+ "-i",
25316
+ "-P",
25317
+ "-n",
25318
+ "-p",
25319
+ pid.toString()
25320
+ ]);
25321
+ const ports = [];
25322
+ const lines = stdout.split("\n");
25323
+ for (const line of lines) {
25324
+ if (line.includes("LISTEN")) {
25325
+ const parts = line.trim().split(/\s+/);
25326
+ const addr = parts[8];
25327
+ if (addr) {
25328
+ const colonIndex = addr.lastIndexOf(":");
25329
+ if (colonIndex !== -1) {
25330
+ const port = parsePort(addr.slice(colonIndex + 1));
25331
+ if (port !== void 0) {
25332
+ ports.push(port);
25330
25333
  }
25331
25334
  }
25332
25335
  }
25333
- break;
25334
25336
  }
25335
- case "win32": {
25336
- const { stdout } = await execFileAsync("cmd", [
25337
- "/c",
25338
- `netstat -ano | findstr ${pid} | findstr LISTENING`
25339
- ]);
25340
- const trimmedOutput = stdout.trim();
25341
- if (trimmedOutput) {
25342
- const lines = trimmedOutput.split("\n");
25343
- for (const line of lines) {
25344
- const match = line.trim().match(/^\s*TCP\s+(?:\[[\da-f:]+\]|[\d.]+):(\d+)\s+/i);
25345
- if (match) {
25346
- port = parsePort(match[1]);
25347
- if (port !== void 0) {
25348
- break;
25349
- }
25350
- }
25337
+ }
25338
+ return ports;
25339
+ }
25340
+ catch {
25341
+ return [];
25342
+ }
25343
+ }
25344
+ __name(getDarwinPorts, "getDarwinPorts");
25345
+ async function getWindowsPorts(pid) {
25346
+ try {
25347
+ const { stdout } = await execFileAsync("cmd", [
25348
+ "/c",
25349
+ `netstat -ano | findstr ${pid} | findstr LISTENING`
25350
+ ]);
25351
+ const ports = [];
25352
+ const trimmedOutput = stdout.trim();
25353
+ if (trimmedOutput) {
25354
+ const lines = trimmedOutput.split("\n");
25355
+ for (const line of lines) {
25356
+ const match = line.trim().match(/^\s*TCP\s+(?:\[[\da-f:]+\]|[\d.]+):(\d+)\s+/i);
25357
+ if (match) {
25358
+ const port = parsePort(match[1]);
25359
+ if (port !== void 0) {
25360
+ ports.push(port);
25351
25361
  }
25352
25362
  }
25353
- break;
25354
25363
  }
25355
25364
  }
25365
+ return ports;
25366
+ }
25367
+ catch {
25368
+ return [];
25369
+ }
25370
+ }
25371
+ __name(getWindowsPorts, "getWindowsPorts");
25372
+ async function getAllPorts() {
25373
+ const { pid, platform } = process;
25374
+ try {
25375
+ switch (platform) {
25376
+ case "linux":
25377
+ return await getLinuxPorts(pid);
25378
+ case "darwin":
25379
+ return await getDarwinPorts(pid);
25380
+ case "win32":
25381
+ return await getWindowsPorts(pid);
25382
+ default:
25383
+ return [];
25384
+ }
25356
25385
  }
25357
25386
  catch (error45) {
25358
25387
  if (process.env.NODE_ENV === "development") {
25359
- console.debug("[getPort] Detection failed:", error45);
25388
+ console.debug("[getAllPorts] Detection failed:", error45);
25360
25389
  }
25361
- return void 0;
25390
+ return [];
25362
25391
  }
25363
- return Number.isNaN(port) ? void 0 : port;
25392
+ }
25393
+ __name(getAllPorts, "getAllPorts");
25394
+ async function getPort() {
25395
+ const ports = await getAllPorts();
25396
+ return ports[0];
25364
25397
  }
25365
25398
  __name(getPort, "getPort");
25399
+ var PROBE_TIMEOUT_MS = 1e3;
25400
+ var PROBE_ENDPOINT = "/.well-known/workflow/v1/flow";
25401
+ async function probePort(port, options = {}) {
25402
+ const { endpoint = PROBE_ENDPOINT, timeout = PROBE_TIMEOUT_MS } = options;
25403
+ const controller = new AbortController();
25404
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
25405
+ try {
25406
+ const response = await fetch(`http://localhost:${port}${endpoint}`, {
25407
+ method: "HEAD",
25408
+ signal: controller.signal
25409
+ });
25410
+ return response.status !== 404;
25411
+ }
25412
+ catch {
25413
+ return false;
25414
+ }
25415
+ finally {
25416
+ clearTimeout(timeoutId);
25417
+ }
25418
+ }
25419
+ __name(probePort, "probePort");
25420
+ async function getWorkflowPort(options) {
25421
+ const ports = await getAllPorts();
25422
+ if (ports.length === 0) {
25423
+ return void 0;
25424
+ }
25425
+ if (ports.length === 1) {
25426
+ return ports[0];
25427
+ }
25428
+ const probeResults = await Promise.all(ports.map(async (port) => ({
25429
+ port,
25430
+ isWorkflow: await probePort(port, options)
25431
+ })));
25432
+ const workflowPort = probeResults.find((r) => r.isWorkflow);
25433
+ if (workflowPort) {
25434
+ return workflowPort.port;
25435
+ }
25436
+ if (process.env.NODE_ENV === "development") {
25437
+ console.debug("[getWorkflowPort] Probing failed, falling back to first port:", ports[0]);
25438
+ }
25439
+ return ports[0];
25440
+ }
25441
+ __name(getWorkflowPort, "getWorkflowPort");
25366
25442
  // ../world-local/dist/util.js
25367
25443
  function once2(fn) {
25368
25444
  const result = {
@@ -25403,7 +25479,7 @@ async function resolveBaseUrl(config3) {
25403
25479
  if (process.env.PORT) {
25404
25480
  return `http://localhost:${process.env.PORT}`;
25405
25481
  }
25406
- const detectedPort = await getPort();
25482
+ const detectedPort = await getWorkflowPort();
25407
25483
  if (detectedPort) {
25408
25484
  return `http://localhost:${detectedPort}`;
25409
25485
  }
@@ -42289,7 +42365,7 @@ __name(createLocalWorld, "createLocalWorld");
42289
42365
  var import_node_os = __toESM(require("node:os"), 1);
42290
42366
  var import_oidc2 = __toESM(require_dist(), 1);
42291
42367
  // ../world-vercel/dist/version.js
42292
- var version2 = "4.0.1-beta.18";
42368
+ var version2 = "4.0.1-beta.19";
42293
42369
  // ../world-vercel/dist/utils.js
42294
42370
  var DEFAULT_RESOLVE_DATA_OPTION2 = "all";
42295
42371
  function dateToStringReplacer(_key, value) {
@@ -43963,52 +44039,6 @@ async function fetch2(...args) {
43963
44039
  }
43964
44040
  __name(fetch2, "fetch");
43965
44041
  registerStepFunction("step//workflow/dist/stdlib.js//fetch", fetch2);
43966
- // workflows/hooks.ts
43967
- var Hook = defineHook({
43968
- schema: object({
43969
- data: string2(),
43970
- done: boolean2().optional(),
43971
- metadata: unknown()
43972
- })
43973
- });
43974
- async function collectWithHook(token, customData) {
43975
- throw new Error("You attempted to execute workflow collectWithHook function directly. To start a workflow, use start(collectWithHook) from workflow/api");
43976
- }
43977
- __name(collectWithHook, "collectWithHook");
43978
- collectWithHook.workflowId = "workflow//workflows/hooks.ts//collectWithHook";
43979
- async function writeEvent(writable, event, payload) {
43980
- console.log("writing event", event, payload);
43981
- const writer = writable.getWriter();
43982
- await writer.write(new TextEncoder().encode(`${JSON.stringify({
43983
- event,
43984
- payload
43985
- })}\r
43986
- `));
43987
- }
43988
- __name(writeEvent, "writeEvent");
43989
- registerStepFunction("step//workflows/hooks.ts//writeEvent", writeEvent);
43990
- // workflows/null-byte.ts
43991
- async function nullByteStep() {
43992
- return "null byte \0";
43993
- }
43994
- __name(nullByteStep, "nullByteStep");
43995
- async function nullByteWorkflow() {
43996
- throw new Error("You attempted to execute workflow nullByteWorkflow function directly. To start a workflow, use start(nullByteWorkflow) from workflow/api");
43997
- }
43998
- __name(nullByteWorkflow, "nullByteWorkflow");
43999
- nullByteWorkflow.workflowId = "workflow//workflows/null-byte.ts//nullByteWorkflow";
44000
- registerStepFunction("step//workflows/null-byte.ts//nullByteStep", nullByteStep);
44001
- // workflows/addition.ts
44002
- async function add(num, num2) {
44003
- return num + num2;
44004
- }
44005
- __name(add, "add");
44006
- async function addition(num, num2) {
44007
- throw new Error("You attempted to execute workflow addition function directly. To start a workflow, use start(addition) from workflow/api");
44008
- }
44009
- __name(addition, "addition");
44010
- addition.workflowId = "workflow//workflows/addition.ts//addition";
44011
- registerStepFunction("step//workflows/addition.ts//add", add);
44012
44042
  // workflows/retriable-and-fatal.ts
44013
44043
  async function retryableAndFatalErrorWorkflow() {
44014
44044
  throw new Error("You attempted to execute workflow retryableAndFatalErrorWorkflow function directly. To start a workflow, use start(retryableAndFatalErrorWorkflow) from workflow/api");
@@ -44036,6 +44066,41 @@ async function stepThatFails() {
44036
44066
  __name(stepThatFails, "stepThatFails");
44037
44067
  registerStepFunction("step//workflows/retriable-and-fatal.ts//stepThatThrowsRetryableError", stepThatThrowsRetryableError);
44038
44068
  registerStepFunction("step//workflows/retriable-and-fatal.ts//stepThatFails", stepThatFails);
44069
+ // workflows/addition.ts
44070
+ async function add(num, num2) {
44071
+ return num + num2;
44072
+ }
44073
+ __name(add, "add");
44074
+ async function addition(num, num2) {
44075
+ throw new Error("You attempted to execute workflow addition function directly. To start a workflow, use start(addition) from workflow/api");
44076
+ }
44077
+ __name(addition, "addition");
44078
+ addition.workflowId = "workflow//workflows/addition.ts//addition";
44079
+ registerStepFunction("step//workflows/addition.ts//add", add);
44080
+ // workflows/hooks.ts
44081
+ var Hook = defineHook({
44082
+ schema: object({
44083
+ data: string2(),
44084
+ done: boolean2().optional(),
44085
+ metadata: unknown()
44086
+ })
44087
+ });
44088
+ async function collectWithHook(token, customData) {
44089
+ throw new Error("You attempted to execute workflow collectWithHook function directly. To start a workflow, use start(collectWithHook) from workflow/api");
44090
+ }
44091
+ __name(collectWithHook, "collectWithHook");
44092
+ collectWithHook.workflowId = "workflow//workflows/hooks.ts//collectWithHook";
44093
+ async function writeEvent(writable, event, payload) {
44094
+ console.log("writing event", event, payload);
44095
+ const writer = writable.getWriter();
44096
+ await writer.write(new TextEncoder().encode(`${JSON.stringify({
44097
+ event,
44098
+ payload
44099
+ })}\r
44100
+ `));
44101
+ }
44102
+ __name(writeEvent, "writeEvent");
44103
+ registerStepFunction("step//workflows/hooks.ts//writeEvent", writeEvent);
44039
44104
  // ../core/dist/runtime.js
44040
44105
  var import_functions4 = __toESM(require_functions(), 1);
44041
44106
  // ../core/dist/logger.js
@@ -44213,6 +44278,18 @@ var stepEntrypoint = /* @__PURE__ */ getWorldHandlers().createQueueHandler("__wk
44213
44278
  ...StepSkipped(true),
44214
44279
  ...StepSkipReason(step.status)
44215
44280
  });
44281
+ const isTerminalStep = [
44282
+ "completed",
44283
+ "failed",
44284
+ "cancelled"
44285
+ ].includes(step.status);
44286
+ if (isTerminalStep) {
44287
+ await queueMessage(world, `__wkf_workflow_${workflowName}`, {
44288
+ runId: workflowRunId,
44289
+ traceCarrier: await serializeTraceCarrier(),
44290
+ requestedAt: /* @__PURE__ */ new Date()
44291
+ });
44292
+ }
44216
44293
  return;
44217
44294
  }
44218
44295
  await world.events.create(workflowRunId, {