bitfab 0.12.1 → 0.12.2

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.
@@ -8,7 +8,7 @@ import {
8
8
  getReplayContext,
9
9
  isAsyncStorageInitDone,
10
10
  serializeValue
11
- } from "./chunk-OOKZ6S64.js";
11
+ } from "./chunk-HUSTKOQI.js";
12
12
 
13
13
  // src/claudeAgentSdk.ts
14
14
  function nowIso() {
@@ -1999,6 +1999,15 @@ var Bitfab = class {
1999
1999
  const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
2000
2000
  const fn = typeof optionsOrFn === "function" ? optionsOrFn : maybeFn;
2001
2001
  const self = this;
2002
+ const fnIsAsyncFunction = fn.constructor.name === "AsyncFunction";
2003
+ const fnReturnsPromise = fnIsAsyncFunction || (() => {
2004
+ try {
2005
+ const src = fn.toString();
2006
+ return /\b(?:Promise|await)\b/.test(src);
2007
+ } catch {
2008
+ return false;
2009
+ }
2010
+ })();
2002
2011
  const wrappedFn = function(...args) {
2003
2012
  if (!asyncLocalStorage && !isAsyncStorageInitDone()) {
2004
2013
  return asyncLocalStorageReady.then(
@@ -2092,11 +2101,12 @@ var Bitfab = class {
2092
2101
  const replayCtxForMock = getReplayContext();
2093
2102
  if (replayCtxForMock?.mockTree && !isRootSpan) {
2094
2103
  const counters = replayCtxForMock.callCounters;
2095
- const callIndex = counters.get(traceFunctionKey) ?? 0;
2096
- counters.set(traceFunctionKey, callIndex + 1);
2104
+ const counterKey = `${traceFunctionKey}:${baseSpanParams.spanName}`;
2105
+ const callIndex = counters.get(counterKey) ?? 0;
2106
+ counters.set(counterKey, callIndex + 1);
2097
2107
  const shouldMock = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
2098
2108
  if (shouldMock) {
2099
- const mockKey = `${traceFunctionKey}:${callIndex}`;
2109
+ const mockKey = `${counterKey}:${callIndex}`;
2100
2110
  const mockSpan = replayCtxForMock.mockTree.spans.get(mockKey);
2101
2111
  if (mockSpan) {
2102
2112
  let output = mockSpan.output;
@@ -2107,7 +2117,7 @@ var Bitfab = class {
2107
2117
  });
2108
2118
  }
2109
2119
  void sendSpan({ result: output });
2110
- if (fn.constructor.name === "AsyncFunction") {
2120
+ if (fnReturnsPromise) {
2111
2121
  return Promise.resolve(output);
2112
2122
  }
2113
2123
  return output;
@@ -2255,7 +2265,7 @@ var Bitfab = class {
2255
2265
  * @returns ReplayResult with items, testRunId, and testRunUrl
2256
2266
  */
2257
2267
  async replay(traceFunctionKey, fn, options) {
2258
- const { replay: doReplay } = await import("./replay-UQP2XXBZ.js");
2268
+ const { replay: doReplay } = await import("./replay-RJZGLEHI.js");
2259
2269
  return doReplay(
2260
2270
  this.httpClient,
2261
2271
  this.serviceUrl,
@@ -2323,4 +2333,4 @@ export {
2323
2333
  Bitfab,
2324
2334
  BitfabFunction
2325
2335
  };
2326
- //# sourceMappingURL=chunk-NU52P7HA.js.map
2336
+ //# sourceMappingURL=chunk-3HBV4GQO.js.map