@workflow/world-testing 5.0.0-beta.42 → 5.0.0-beta.43

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.
@@ -17679,6 +17679,14 @@ var init_hooks = __esm({
17679
17679
  }
17680
17680
  });
17681
17681
 
17682
+ // ../world/dist/node-http-flag.js
17683
+ var init_node_http_flag = __esm({
17684
+ "../world/dist/node-http-flag.js"() {
17685
+ "use strict";
17686
+ init_env_config();
17687
+ }
17688
+ });
17689
+
17682
17690
  // ../world/dist/recovery.js
17683
17691
  var init_recovery = __esm({
17684
17692
  "../world/dist/recovery.js"() {
@@ -17918,6 +17926,7 @@ var init_dist4 = __esm({
17918
17926
  init_env_config();
17919
17927
  init_events();
17920
17928
  init_hooks();
17929
+ init_node_http_flag();
17921
17930
  init_queue();
17922
17931
  init_recovery();
17923
17932
  init_runs();
@@ -23428,7 +23437,7 @@ async function linkToTraceCarrier(carrier) {
23428
23437
  context
23429
23438
  };
23430
23439
  }
23431
- var OtelApi, Tracer, otelDiagLogged;
23440
+ var OtelApi, Tracer, StepExecutionDurationHistogram, otelDiagLogged;
23432
23441
  var init_telemetry = __esm({
23433
23442
  "../core/dist/telemetry.js"() {
23434
23443
  "use strict";
@@ -23453,6 +23462,14 @@ var init_telemetry = __esm({
23453
23462
  logOtelDiagnosticOnce(api, tracer);
23454
23463
  return tracer;
23455
23464
  });
23465
+ StepExecutionDurationHistogram = once(async () => {
23466
+ const otel = await OtelApi.value;
23467
+ if (!otel) return null;
23468
+ return otel.metrics.getMeter("workflow").createHistogram("workflow.step.execute.duration", {
23469
+ description: "Duration of user step execution",
23470
+ unit: "ms"
23471
+ });
23472
+ });
23456
23473
  otelDiagLogged = false;
23457
23474
  __name(logOtelDiagnosticOnce, "logOtelDiagnosticOnce");
23458
23475
  __name(trace, "trace");
@@ -25906,7 +25923,7 @@ var version2;
25906
25923
  var init_version = __esm({
25907
25924
  "../core/dist/version.js"() {
25908
25925
  "use strict";
25909
- version2 = "5.0.0-beta.42";
25926
+ version2 = "5.0.0-beta.43";
25910
25927
  }
25911
25928
  });
25912
25929
 
@@ -31668,6 +31685,16 @@ function createReconnectingFramedStream(runId, name, startIndex) {
31668
31685
  reader = stream.getReader();
31669
31686
  }
31670
31687
  __name(connect, "connect");
31688
+ async function isVerifiedComplete() {
31689
+ try {
31690
+ const world = await getWorldLazy();
31691
+ const info = await world.streams.getInfo(runId, name);
31692
+ return info.done && currentStartIndex + consumedFrames > info.tailIndex;
31693
+ } catch {
31694
+ return true;
31695
+ }
31696
+ }
31697
+ __name(isVerifiedComplete, "isVerifiedComplete");
31671
31698
  async function reconnect() {
31672
31699
  if (reader) {
31673
31700
  await reader.cancel().catch(() => {
@@ -31727,6 +31754,15 @@ function createReconnectingFramedStream(runId, name, startIndex) {
31727
31754
  }
31728
31755
  if (result.done || !result.value) {
31729
31756
  reader = void 0;
31757
+ if (reconnectSupported && !await isVerifiedComplete()) {
31758
+ try {
31759
+ await reconnect();
31760
+ } catch (reconnectErr) {
31761
+ controller.error(reconnectErr);
31762
+ return;
31763
+ }
31764
+ continue;
31765
+ }
31730
31766
  if (readStart !== void 0) {
31731
31767
  recordStreamReadComplete(readStart, runId, name, chunksDelivered, bytesDelivered, totalReconnectCount);
31732
31768
  }
@@ -33492,7 +33528,7 @@ __name(start, "start");
33492
33528
  value: "start",
33493
33529
  configurable: true
33494
33530
  });
33495
- })(start, "step//@workflow/core/runtime/start@5.0.0-beta.42//start");
33531
+ })(start, "step//@workflow/core/runtime/start@5.0.0-beta.43//start");
33496
33532
 
33497
33533
  // ../core/dist/runtime/runs.js
33498
33534
  async function wakeUpRun(world, runId, options) {
@@ -33579,6 +33615,10 @@ __name(wakeUpRun, "wakeUpRun");
33579
33615
 
33580
33616
  // ../core/dist/runtime/run.js
33581
33617
  var RETURN_VALUE_POLL_INTERVAL_MS = 1e3;
33618
+ var PAYLOAD_TERMINAL_RUN_STATUSES = /* @__PURE__ */ new Set([
33619
+ "completed",
33620
+ "failed"
33621
+ ]);
33582
33622
  function getReturnValuePollIntervalMs() {
33583
33623
  return envNumber("WORKFLOW_RETURN_VALUE_POLL_INTERVAL_MS", RETURN_VALUE_POLL_INTERVAL_MS, {
33584
33624
  integer: true,
@@ -33638,12 +33678,12 @@ var Run = class _Run {
33638
33678
  * to be resolved once.
33639
33679
  * @internal
33640
33680
  */
33641
- #getEncryptionKey() {
33681
+ #getEncryptionKey(run2) {
33642
33682
  if (!this.#encryptionKeyPromise) {
33643
33683
  this.#encryptionKeyPromise = (async () => {
33644
33684
  const world = await this.#lazyWorldPromise;
33645
- const run2 = await world.runs.get(this.runId);
33646
- const rawKey = await world.getEncryptionKeyForRun?.(run2);
33685
+ const runData = run2 ?? await world.runs.get(this.runId);
33686
+ const rawKey = await world.getEncryptionKeyForRun?.(runData);
33647
33687
  return rawKey ? await deriveRunPayloadKeys(rawKey) : void 0;
33648
33688
  })();
33649
33689
  }
@@ -33704,7 +33744,9 @@ var Run = class _Run {
33704
33744
  * The status of the workflow run.
33705
33745
  */
33706
33746
  get status() {
33707
- return this.#lazyWorldPromise.then((world) => world.runs.get(this.runId).then((run2) => run2.status));
33747
+ return this.#lazyWorldPromise.then((world) => world.runs.get(this.runId, {
33748
+ resolveData: "none"
33749
+ }).then((run2) => run2.status));
33708
33750
  }
33709
33751
  /**
33710
33752
  * The return value of the workflow run.
@@ -33775,6 +33817,29 @@ var Run = class _Run {
33775
33817
  }, "getTailIndex")
33776
33818
  });
33777
33819
  }
33820
+ /** @internal */
33821
+ async #resolveTerminalReturnValue(run2) {
33822
+ if (run2.status === "completed") {
33823
+ const encryptionKey = await this.#getEncryptionKey(run2);
33824
+ return await hydrateWorkflowReturnValue(run2.output, this.runId, encryptionKey);
33825
+ }
33826
+ if (run2.status === "cancelled") {
33827
+ throw new WorkflowRunCancelledError(this.runId);
33828
+ }
33829
+ if (run2.status === "failed") {
33830
+ const encryptionKey = await this.#getEncryptionKey(run2);
33831
+ let hydratedError;
33832
+ try {
33833
+ hydratedError = await hydrateRunError(run2.error, this.runId, encryptionKey);
33834
+ } catch {
33835
+ hydratedError = new Error("Failed to hydrate workflow run error");
33836
+ }
33837
+ throw new WorkflowRunFailedError(this.runId, hydratedError, {
33838
+ errorCode: run2.errorCode
33839
+ });
33840
+ }
33841
+ throw new WorkflowRunNotCompletedError(this.runId, run2.status);
33842
+ }
33778
33843
  /**
33779
33844
  * Polls the workflow return value until it is completed.
33780
33845
  * @internal
@@ -33791,27 +33856,19 @@ var Run = class _Run {
33791
33856
  ];
33792
33857
  while (true) {
33793
33858
  try {
33794
- const run2 = await world.runs.get(this.runId);
33795
- if (run2.status === "completed") {
33796
- const encryptionKey = await this.#getEncryptionKey();
33797
- return await hydrateWorkflowReturnValue(run2.output, this.runId, encryptionKey);
33798
- }
33799
- if (run2.status === "cancelled") {
33859
+ const runMetadata = await world.runs.get(this.runId, {
33860
+ resolveData: "none"
33861
+ });
33862
+ if (runMetadata.status === "cancelled") {
33800
33863
  throw new WorkflowRunCancelledError(this.runId);
33801
33864
  }
33802
- if (run2.status === "failed") {
33803
- const encryptionKey = await this.#getEncryptionKey();
33804
- let hydratedError;
33805
- try {
33806
- hydratedError = await hydrateRunError(run2.error, this.runId, encryptionKey);
33807
- } catch {
33808
- hydratedError = new Error("Failed to hydrate workflow run error");
33809
- }
33810
- throw new WorkflowRunFailedError(this.runId, hydratedError, {
33811
- errorCode: run2.errorCode
33865
+ if (PAYLOAD_TERMINAL_RUN_STATUSES.has(runMetadata.status)) {
33866
+ const run2 = await world.runs.get(this.runId, {
33867
+ resolveData: "all"
33812
33868
  });
33869
+ return await this.#resolveTerminalReturnValue(run2);
33813
33870
  }
33814
- throw new WorkflowRunNotCompletedError(this.runId, run2.status);
33871
+ throw new WorkflowRunNotCompletedError(this.runId, runMetadata.status);
33815
33872
  } catch (error48) {
33816
33873
  if (WorkflowRunNotCompletedError.is(error48)) {
33817
33874
  await new Promise((resolve) => setTimeout(resolve, getReturnValuePollIntervalMs()));
@@ -33836,7 +33893,7 @@ var Run = class _Run {
33836
33893
  value: "wakeUp",
33837
33894
  configurable: true
33838
33895
  });
33839
- })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#wakeUp");
33896
+ })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#wakeUp");
33840
33897
  (function(__wf_fn, __wf_id) {
33841
33898
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33842
33899
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33845,7 +33902,7 @@ var Run = class _Run {
33845
33902
  value: "cancel",
33846
33903
  configurable: true
33847
33904
  });
33848
- })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#cancel");
33905
+ })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#cancel");
33849
33906
  (function(__wf_fn, __wf_id) {
33850
33907
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33851
33908
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33854,7 +33911,7 @@ var Run = class _Run {
33854
33911
  value: "getReadable",
33855
33912
  configurable: true
33856
33913
  });
33857
- })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#getReadable");
33914
+ })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#getReadable");
33858
33915
  (function(__wf_fn, __wf_id) {
33859
33916
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33860
33917
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33863,7 +33920,7 @@ var Run = class _Run {
33863
33920
  value: "exists",
33864
33921
  configurable: true
33865
33922
  });
33866
- })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#exists");
33923
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#exists");
33867
33924
  (function(__wf_fn, __wf_id) {
33868
33925
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33869
33926
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33872,7 +33929,7 @@ var Run = class _Run {
33872
33929
  value: "status",
33873
33930
  configurable: true
33874
33931
  });
33875
- })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#status");
33932
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#status");
33876
33933
  (function(__wf_fn, __wf_id) {
33877
33934
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33878
33935
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33881,7 +33938,7 @@ var Run = class _Run {
33881
33938
  value: "returnValue",
33882
33939
  configurable: true
33883
33940
  });
33884
- })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#returnValue");
33941
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#returnValue");
33885
33942
  (function(__wf_fn, __wf_id) {
33886
33943
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33887
33944
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33890,7 +33947,7 @@ var Run = class _Run {
33890
33947
  value: "workflowName",
33891
33948
  configurable: true
33892
33949
  });
33893
- })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#workflowName");
33950
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#workflowName");
33894
33951
  (function(__wf_fn, __wf_id) {
33895
33952
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33896
33953
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33899,7 +33956,7 @@ var Run = class _Run {
33899
33956
  value: "createdAt",
33900
33957
  configurable: true
33901
33958
  });
33902
- })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#createdAt");
33959
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#createdAt");
33903
33960
  (function(__wf_fn, __wf_id) {
33904
33961
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33905
33962
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33908,7 +33965,7 @@ var Run = class _Run {
33908
33965
  value: "startedAt",
33909
33966
  configurable: true
33910
33967
  });
33911
- })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#startedAt");
33968
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#startedAt");
33912
33969
  (function(__wf_fn, __wf_id) {
33913
33970
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33914
33971
  __wf_reg.set(__wf_id, __wf_fn);
@@ -33917,7 +33974,7 @@ var Run = class _Run {
33917
33974
  value: "completedAt",
33918
33975
  configurable: true
33919
33976
  });
33920
- })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.42//Run#completedAt");
33977
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.43//Run#completedAt");
33921
33978
  (function(__wf_cls, __wf_id) {
33922
33979
  var __wf_sym = /* @__PURE__ */ Symbol.for("workflow-class-registry"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
33923
33980
  __wf_reg.set(__wf_id, __wf_cls);
@@ -33927,7 +33984,7 @@ var Run = class _Run {
33927
33984
  enumerable: false,
33928
33985
  configurable: false
33929
33986
  });
33930
- })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.42//Run");
33987
+ })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.43//Run");
33931
33988
 
33932
33989
  // ../workflow/dist/stdlib.js
33933
33990
  async function fetch2(...args) {