@bitfab/sdk 0.36.11 → 0.36.13

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/dist/index.cjs CHANGED
@@ -42,7 +42,7 @@ var __version__;
42
42
  var init_version_generated = __esm({
43
43
  "src/version.generated.ts"() {
44
44
  "use strict";
45
- __version__ = "0.36.11";
45
+ __version__ = "0.36.13";
46
46
  }
47
47
  });
48
48
 
@@ -2586,20 +2586,17 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2586
2586
  includeOutputs,
2587
2587
  includeRootOutput: false
2588
2588
  });
2589
- if (treeResponse.root) {
2590
- mockTree = buildMockTree(treeResponse.root);
2591
- } else if (mockStrategy === "all" || hasOverrides) {
2589
+ if (!treeResponse.root) {
2592
2590
  throw new BitfabError(
2593
2591
  `Replay mock strategy "${mockStrategy}"${hasOverrides ? " with overrides" : ""} requires a span tree root for original span ${originalSpanId}.`
2594
2592
  );
2595
- } else {
2596
- mockTree = void 0;
2597
2593
  }
2598
- } catch (e) {
2599
- if (mockStrategy === "all" || hasOverrides) {
2600
- throw e;
2594
+ mockTree = buildMockTree(treeResponse.root);
2595
+ } catch (error2) {
2596
+ if (mockStrategy !== "marked" || hasOverrides) {
2597
+ throw error2;
2601
2598
  }
2602
- mockTree = void 0;
2599
+ mockTree = { spans: /* @__PURE__ */ new Map() };
2603
2600
  }
2604
2601
  }
2605
2602
  const outputCache = /* @__PURE__ */ new Map();
@@ -6101,14 +6098,19 @@ var Bitfab = class {
6101
6098
  counters.set(counterKey, callIndex + 1);
6102
6099
  const mockKey = `${counterKey}:${callIndex}`;
6103
6100
  const mockSpan = replayCtxForMock.mockTree.spans.get(mockKey);
6104
- const emitMock = (output) => {
6105
- void sendSpan({ result: output, mocked: true });
6101
+ const emitMock = (output, mockSource) => {
6102
+ void sendSpan({
6103
+ result: output,
6104
+ mocked: true,
6105
+ mockTarget: "output",
6106
+ mockSource
6107
+ });
6106
6108
  if (fnReturnsPromise) {
6107
6109
  return Promise.resolve(output);
6108
6110
  }
6109
6111
  return output;
6110
6112
  };
6111
- const emitMockAsync = (pending) => {
6113
+ const emitMockAsync = (pending, mockSource) => {
6112
6114
  if (!fnReturnsPromise) {
6113
6115
  throw new BitfabError(
6114
6116
  `Cannot mock synchronous span "${traceFunctionKey}" with an asynchronously-resolved value (lazy recorded-output fetch or an async value function). Make the wrapped function async, or use mock: "all" so recorded outputs are fetched eagerly.`
@@ -6116,7 +6118,12 @@ var Bitfab = class {
6116
6118
  }
6117
6119
  return (async () => {
6118
6120
  const output = await pending;
6119
- void sendSpan({ result: output, mocked: true });
6121
+ void sendSpan({
6122
+ result: output,
6123
+ mocked: true,
6124
+ mockTarget: "output",
6125
+ mockSource
6126
+ });
6120
6127
  return output;
6121
6128
  })();
6122
6129
  };
@@ -6158,18 +6165,23 @@ var Bitfab = class {
6158
6165
  getOriginalOutput: () => Promise.resolve(resolveRecordedOutput())
6159
6166
  });
6160
6167
  if (injected instanceof Promise) {
6161
- return emitMockAsync(injected);
6168
+ return emitMockAsync(injected, "override");
6162
6169
  }
6163
- return emitMock(injected);
6170
+ return emitMock(injected, "override");
6164
6171
  }
6165
6172
  }
6166
6173
  const shouldMock = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
6167
- if (shouldMock && mockSpan) {
6174
+ if (shouldMock && !mockSpan) {
6175
+ throw new BitfabError(
6176
+ `Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
6177
+ );
6178
+ }
6179
+ if (shouldMock) {
6168
6180
  const recorded = resolveRecordedOutput();
6169
6181
  if (recorded instanceof Promise) {
6170
- return emitMockAsync(recorded);
6182
+ return emitMockAsync(recorded, "recorded");
6171
6183
  }
6172
- return emitMock(recorded);
6184
+ return emitMock(recorded, "recorded");
6173
6185
  }
6174
6186
  }
6175
6187
  const recordSpan = (result) => {
@@ -6469,7 +6481,9 @@ var Bitfab = class {
6469
6481
  traceFunctionKey: params.traceFunctionKey,
6470
6482
  rawSpan: externalSpan,
6471
6483
  ...params.testRunId && { testRunId: params.testRunId },
6472
- ...params.mocked && { mocked: true }
6484
+ ...params.mocked && { mocked: true },
6485
+ ...params.mockTarget && { mockTarget: params.mockTarget },
6486
+ ...params.mockSource && { mockSource: params.mockSource }
6473
6487
  });
6474
6488
  }
6475
6489
  registerMockOverride(overrideOrMatch, value) {