bitfab 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.d.cts CHANGED
@@ -182,8 +182,9 @@ interface MockOverride {
182
182
  * A single span entry in the mock tree.
183
183
  *
184
184
  * Under the eager path (`mock: "all"`) `output`/`outputMeta` are populated
185
- * inline. Under the lazy path (`marked` / overrides) they are absent and the
186
- * recorded output is fetched on demand via `externalSpanId` - see
185
+ * inline, even when overrides are present. Under a non-`all` path that needs a
186
+ * tree (`marked`, or `none` with overrides), they are absent and the recorded
187
+ * output is fetched on demand via `externalSpanId` - see
187
188
  * {@link ReplayContext.fetchSpanOutput}.
188
189
  */
189
190
  interface MockSpan {
@@ -267,9 +268,10 @@ interface ReplayContext {
267
268
  mockOverrides?: MockOverride[];
268
269
  /**
269
270
  * Memoized lazy fetch of a span's recorded output (deserialized), keyed by
270
- * `externalSpanId`. Present ONLY on the lazy path (`marked` / overrides);
271
- * absent under `mock: "all"`, where outputs are inline on the mock tree. Its
272
- * presence is the signal that outputs must be fetched rather than read inline.
271
+ * `externalSpanId`. Present ONLY on a non-`all` path that needs a tree
272
+ * (`marked`, or `none` with overrides); absent under `mock: "all"`, where
273
+ * outputs are inline even when overrides are present. Its presence is the
274
+ * signal that outputs must be fetched rather than read inline.
273
275
  */
274
276
  fetchSpanOutput?: (externalSpanId: string) => Promise<unknown>;
275
277
  dbBranchLease?: DbBranchLease;
@@ -1177,9 +1179,9 @@ interface DbBranchOptions {
1177
1179
  }
1178
1180
  interface ReplayOptions {
1179
1181
  /**
1180
- * Maximum number of traces to replay (1-100, default 5). Ignored when
1181
- * `traceIds` is passed (with a warning): an explicit ID list already
1182
- * determines how many traces replay.
1182
+ * Maximum number of traces to replay (1-5,000, default 5). Ignored when
1183
+ * `traceIds` is passed (with a warning), or when `datasetId` is passed,
1184
+ * because either source already determines how many traces replay.
1183
1185
  */
1184
1186
  limit?: number;
1185
1187
  /** Optional list of specific trace IDs to replay (max 100). */
@@ -1209,7 +1211,8 @@ interface ReplayOptions {
1209
1211
  * Mock strategy for child spans during replay.
1210
1212
  * - "marked": only spans tagged with { mockOnReplay: true } in SpanOptions are mocked (default)
1211
1213
  * - "none": everything runs real code
1212
- * - "all": every child withSpan returns historical output
1214
+ * - "all": every matched recorded child withSpan returns historical output;
1215
+ * a missing occurrence fails the replay item closed
1213
1216
  */
1214
1217
  mock?: MockStrategy;
1215
1218
  /**
@@ -1229,9 +1232,10 @@ interface ReplayOptions {
1229
1232
  * branch with `getCurrentReplayBranch()`.
1230
1233
  *
1231
1234
  * Items whose source trace carried no DB snapshot reference get no branch and
1232
- * run against the live database. An item whose branch was requested but could
1233
- * not be resolved fails instead of running, so a replay never silently
1234
- * reports a result that did not use the historical data you asked for.
1235
+ * use the app's normal database path. Unsafe calls on that path still require
1236
+ * replay mocking. An item whose branch was requested but could not be resolved
1237
+ * fails instead of running, so replay never silently reports a result that did
1238
+ * not use the historical data you asked for.
1235
1239
  */
1236
1240
  dbBranch?: DbBranchOptions | boolean;
1237
1241
  /** Group ID to associate this replay with an experiment group for live streaming in Studio. */
@@ -1966,7 +1970,9 @@ interface SpanOptions {
1966
1970
  *
1967
1971
  * Use this for child spans that are expensive (paid LLM/API calls),
1968
1972
  * slow, or non-deterministic - the root function still runs real code,
1969
- * only the marked descendants return their recorded output.
1973
+ * only the marked descendants return their recorded output. If a selected
1974
+ * occurrence is unavailable, replay fails the item without executing the
1975
+ * real child.
1970
1976
  */
1971
1977
  mockOnReplay?: boolean;
1972
1978
  /**
@@ -2575,7 +2581,7 @@ declare class BitfabFunction {
2575
2581
  /**
2576
2582
  * SDK version from package.json (injected at build time)
2577
2583
  */
2578
- declare const __version__ = "0.36.11";
2584
+ declare const __version__ = "0.36.13";
2579
2585
 
2580
2586
  /**
2581
2587
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -182,8 +182,9 @@ interface MockOverride {
182
182
  * A single span entry in the mock tree.
183
183
  *
184
184
  * Under the eager path (`mock: "all"`) `output`/`outputMeta` are populated
185
- * inline. Under the lazy path (`marked` / overrides) they are absent and the
186
- * recorded output is fetched on demand via `externalSpanId` - see
185
+ * inline, even when overrides are present. Under a non-`all` path that needs a
186
+ * tree (`marked`, or `none` with overrides), they are absent and the recorded
187
+ * output is fetched on demand via `externalSpanId` - see
187
188
  * {@link ReplayContext.fetchSpanOutput}.
188
189
  */
189
190
  interface MockSpan {
@@ -267,9 +268,10 @@ interface ReplayContext {
267
268
  mockOverrides?: MockOverride[];
268
269
  /**
269
270
  * Memoized lazy fetch of a span's recorded output (deserialized), keyed by
270
- * `externalSpanId`. Present ONLY on the lazy path (`marked` / overrides);
271
- * absent under `mock: "all"`, where outputs are inline on the mock tree. Its
272
- * presence is the signal that outputs must be fetched rather than read inline.
271
+ * `externalSpanId`. Present ONLY on a non-`all` path that needs a tree
272
+ * (`marked`, or `none` with overrides); absent under `mock: "all"`, where
273
+ * outputs are inline even when overrides are present. Its presence is the
274
+ * signal that outputs must be fetched rather than read inline.
273
275
  */
274
276
  fetchSpanOutput?: (externalSpanId: string) => Promise<unknown>;
275
277
  dbBranchLease?: DbBranchLease;
@@ -1177,9 +1179,9 @@ interface DbBranchOptions {
1177
1179
  }
1178
1180
  interface ReplayOptions {
1179
1181
  /**
1180
- * Maximum number of traces to replay (1-100, default 5). Ignored when
1181
- * `traceIds` is passed (with a warning): an explicit ID list already
1182
- * determines how many traces replay.
1182
+ * Maximum number of traces to replay (1-5,000, default 5). Ignored when
1183
+ * `traceIds` is passed (with a warning), or when `datasetId` is passed,
1184
+ * because either source already determines how many traces replay.
1183
1185
  */
1184
1186
  limit?: number;
1185
1187
  /** Optional list of specific trace IDs to replay (max 100). */
@@ -1209,7 +1211,8 @@ interface ReplayOptions {
1209
1211
  * Mock strategy for child spans during replay.
1210
1212
  * - "marked": only spans tagged with { mockOnReplay: true } in SpanOptions are mocked (default)
1211
1213
  * - "none": everything runs real code
1212
- * - "all": every child withSpan returns historical output
1214
+ * - "all": every matched recorded child withSpan returns historical output;
1215
+ * a missing occurrence fails the replay item closed
1213
1216
  */
1214
1217
  mock?: MockStrategy;
1215
1218
  /**
@@ -1229,9 +1232,10 @@ interface ReplayOptions {
1229
1232
  * branch with `getCurrentReplayBranch()`.
1230
1233
  *
1231
1234
  * Items whose source trace carried no DB snapshot reference get no branch and
1232
- * run against the live database. An item whose branch was requested but could
1233
- * not be resolved fails instead of running, so a replay never silently
1234
- * reports a result that did not use the historical data you asked for.
1235
+ * use the app's normal database path. Unsafe calls on that path still require
1236
+ * replay mocking. An item whose branch was requested but could not be resolved
1237
+ * fails instead of running, so replay never silently reports a result that did
1238
+ * not use the historical data you asked for.
1235
1239
  */
1236
1240
  dbBranch?: DbBranchOptions | boolean;
1237
1241
  /** Group ID to associate this replay with an experiment group for live streaming in Studio. */
@@ -1966,7 +1970,9 @@ interface SpanOptions {
1966
1970
  *
1967
1971
  * Use this for child spans that are expensive (paid LLM/API calls),
1968
1972
  * slow, or non-deterministic - the root function still runs real code,
1969
- * only the marked descendants return their recorded output.
1973
+ * only the marked descendants return their recorded output. If a selected
1974
+ * occurrence is unavailable, replay fails the item without executing the
1975
+ * real child.
1970
1976
  */
1971
1977
  mockOnReplay?: boolean;
1972
1978
  /**
@@ -2575,7 +2581,7 @@ declare class BitfabFunction {
2575
2581
  /**
2576
2582
  * SDK version from package.json (injected at build time)
2577
2583
  */
2578
- declare const __version__ = "0.36.11";
2584
+ declare const __version__ = "0.36.13";
2579
2585
 
2580
2586
  /**
2581
2587
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  getCurrentReplayBranch,
21
21
  getCurrentSpan,
22
22
  getCurrentTrace
23
- } from "./chunk-VDFPZYLH.js";
23
+ } from "./chunk-XAQJOZMJ.js";
24
24
  import {
25
25
  BITFAB_PROGRESS_PREFIX,
26
26
  BitfabError,
@@ -32,7 +32,7 @@ import {
32
32
  flushTraces,
33
33
  reportReplayProgress,
34
34
  serializeReplayResult
35
- } from "./chunk-EKOAKLZC.js";
35
+ } from "./chunk-VOUV7ZTS.js";
36
36
  export {
37
37
  BITFAB_PROGRESS_PREFIX,
38
38
  Bitfab,
package/dist/node.cjs CHANGED
@@ -97,7 +97,7 @@ var __version__;
97
97
  var init_version_generated = __esm({
98
98
  "src/version.generated.ts"() {
99
99
  "use strict";
100
- __version__ = "0.36.11";
100
+ __version__ = "0.36.13";
101
101
  }
102
102
  });
103
103
 
@@ -2602,20 +2602,17 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
2602
2602
  includeOutputs,
2603
2603
  includeRootOutput: false
2604
2604
  });
2605
- if (treeResponse.root) {
2606
- mockTree = buildMockTree(treeResponse.root);
2607
- } else if (mockStrategy === "all" || hasOverrides) {
2605
+ if (!treeResponse.root) {
2608
2606
  throw new BitfabError(
2609
2607
  `Replay mock strategy "${mockStrategy}"${hasOverrides ? " with overrides" : ""} requires a span tree root for original span ${originalSpanId}.`
2610
2608
  );
2611
- } else {
2612
- mockTree = void 0;
2613
2609
  }
2614
- } catch (e) {
2615
- if (mockStrategy === "all" || hasOverrides) {
2616
- throw e;
2610
+ mockTree = buildMockTree(treeResponse.root);
2611
+ } catch (error2) {
2612
+ if (mockStrategy !== "marked" || hasOverrides) {
2613
+ throw error2;
2617
2614
  }
2618
- mockTree = void 0;
2615
+ mockTree = { spans: /* @__PURE__ */ new Map() };
2619
2616
  }
2620
2617
  }
2621
2618
  const outputCache = /* @__PURE__ */ new Map();
@@ -6124,14 +6121,19 @@ var Bitfab = class {
6124
6121
  counters.set(counterKey, callIndex + 1);
6125
6122
  const mockKey = `${counterKey}:${callIndex}`;
6126
6123
  const mockSpan = replayCtxForMock.mockTree.spans.get(mockKey);
6127
- const emitMock = (output) => {
6128
- void sendSpan({ result: output, mocked: true });
6124
+ const emitMock = (output, mockSource) => {
6125
+ void sendSpan({
6126
+ result: output,
6127
+ mocked: true,
6128
+ mockTarget: "output",
6129
+ mockSource
6130
+ });
6129
6131
  if (fnReturnsPromise) {
6130
6132
  return Promise.resolve(output);
6131
6133
  }
6132
6134
  return output;
6133
6135
  };
6134
- const emitMockAsync = (pending) => {
6136
+ const emitMockAsync = (pending, mockSource) => {
6135
6137
  if (!fnReturnsPromise) {
6136
6138
  throw new BitfabError(
6137
6139
  `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.`
@@ -6139,7 +6141,12 @@ var Bitfab = class {
6139
6141
  }
6140
6142
  return (async () => {
6141
6143
  const output = await pending;
6142
- void sendSpan({ result: output, mocked: true });
6144
+ void sendSpan({
6145
+ result: output,
6146
+ mocked: true,
6147
+ mockTarget: "output",
6148
+ mockSource
6149
+ });
6143
6150
  return output;
6144
6151
  })();
6145
6152
  };
@@ -6181,18 +6188,23 @@ var Bitfab = class {
6181
6188
  getOriginalOutput: () => Promise.resolve(resolveRecordedOutput())
6182
6189
  });
6183
6190
  if (injected instanceof Promise) {
6184
- return emitMockAsync(injected);
6191
+ return emitMockAsync(injected, "override");
6185
6192
  }
6186
- return emitMock(injected);
6193
+ return emitMock(injected, "override");
6187
6194
  }
6188
6195
  }
6189
6196
  const shouldMock = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
6190
- if (shouldMock && mockSpan) {
6197
+ if (shouldMock && !mockSpan) {
6198
+ throw new BitfabError(
6199
+ `Replay selected span "${traceFunctionKey}:${baseSpanParams.spanName}" for mocking, but recorded occurrence ${callIndex + 1} is unavailable. The real span was not executed.`
6200
+ );
6201
+ }
6202
+ if (shouldMock) {
6191
6203
  const recorded = resolveRecordedOutput();
6192
6204
  if (recorded instanceof Promise) {
6193
- return emitMockAsync(recorded);
6205
+ return emitMockAsync(recorded, "recorded");
6194
6206
  }
6195
- return emitMock(recorded);
6207
+ return emitMock(recorded, "recorded");
6196
6208
  }
6197
6209
  }
6198
6210
  const recordSpan = (result) => {
@@ -6492,7 +6504,9 @@ var Bitfab = class {
6492
6504
  traceFunctionKey: params.traceFunctionKey,
6493
6505
  rawSpan: externalSpan,
6494
6506
  ...params.testRunId && { testRunId: params.testRunId },
6495
- ...params.mocked && { mocked: true }
6507
+ ...params.mocked && { mocked: true },
6508
+ ...params.mockTarget && { mockTarget: params.mockTarget },
6509
+ ...params.mockSource && { mockSource: params.mockSource }
6496
6510
  });
6497
6511
  }
6498
6512
  registerMockOverride(overrideOrMatch, value) {