bitfab 0.29.0 → 0.29.1

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
@@ -785,6 +785,21 @@ interface ReplayOptions {
785
785
  }
786
786
  /** Running totals reported to {@link ReplayOptions.onProgress} as replay proceeds. */
787
787
  interface ReplayProgress {
788
+ /**
789
+ * Event kind. Omitted (or `"item"`) for the per-trace settle events streamed
790
+ * during the run. `"complete"` marks the single terminal event emitted once
791
+ * the run has settled and been enriched server-side; it carries the full
792
+ * {@link ReplayProgress.result} and has no `item`. The Bitfab plugin reads
793
+ * that terminal event to build the run's final result without parsing stdout.
794
+ */
795
+ type?: "item" | "complete";
796
+ /**
797
+ * The full {@link ReplayResult}, present only on the terminal `"complete"`
798
+ * event. Lets the plugin ingest the enriched result (server-aggregated tokens,
799
+ * server trace ids) over the same channel as progress, so a dependency logging
800
+ * to stdout can never block it.
801
+ */
802
+ result?: ReplayResult<unknown>;
788
803
  /** Test run ID created for this replay. */
789
804
  testRunId?: string;
790
805
  /** Items that have finished so far, whether they succeeded or errored. */
@@ -796,18 +811,25 @@ interface ReplayProgress {
796
811
  /** Of the completed items, how many threw (their `item.error` is set). */
797
812
  errored: number;
798
813
  /**
799
- * The single item that just settled to produce this event. `traceId` is the
800
- * source (historical) trace that was replayed (so a UI can identify or link
801
- * it); `error` is its replay error, or null when it ran ok; `durationMs` is how
802
- * long this one trace took to replay. Lets a progress UI show per-trace
803
- * pass/fail and timing as the run streams, without waiting for the full
804
- * {@link ReplayResult}.
814
+ * The single item that just settled to produce this event. `traceId` is null
815
+ * at this stage (the server replay id isn't known until the run completes);
816
+ * `originalTraceId` is the original (historical) trace that was replayed (so
817
+ * a UI can identify or link it); `error` is its replay error, or null when it
818
+ * ran ok; `durationMs` is how long this one trace took to replay. Lets a
819
+ * progress UI show per-trace pass/fail and timing as the run streams, without
820
+ * waiting for the full {@link ReplayResult}.
805
821
  */
806
822
  item?: {
807
- /** Source (historical) trace ID being replayed. */
808
- traceId: string | null;
809
- /** Local SDK replay trace ID, before the server maps it to a row ID. */
810
- replayTraceId?: string | null;
823
+ /** Trace ID of the new replay trace (null during the run; the server id arrives at completion). */
824
+ traceId?: string | null;
825
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
826
+ originalTraceId: string | null;
827
+ /** External span ID the recorded inputs were read from (the original root span). */
828
+ originalSpanId?: string | null;
829
+ /** @deprecated alias for `originalTraceId`. */
830
+ sourceTraceId: string | null;
831
+ /** @deprecated alias for `originalSpanId`. */
832
+ sourceSpanId?: string | null;
811
833
  /** Deserialized inputs from the original trace. */
812
834
  input?: unknown[];
813
835
  /** The result returned by the replayed function, or undefined on error. */
@@ -847,9 +869,13 @@ declare const BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
847
869
  declare function reportReplayProgress(progress: ReplayProgress): void;
848
870
  /** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
849
871
  interface AdaptContext {
850
- /** Bitfab trace ID of the historical trace being replayed. */
851
- traceId: string;
872
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
873
+ originalTraceId: string;
852
874
  /** External span ID the recorded inputs were read from. */
875
+ originalSpanId: string;
876
+ /** @deprecated alias for {@link AdaptContext.originalTraceId}. */
877
+ sourceTraceId: string;
878
+ /** @deprecated alias for {@link AdaptContext.originalSpanId}. */
853
879
  sourceSpanId: string;
854
880
  }
855
881
  /**
@@ -865,8 +891,23 @@ interface AdaptContext {
865
891
  */
866
892
  type AdaptInputsFn = (inputs: unknown[], ctx: AdaptContext) => unknown[];
867
893
  interface ReplayItem<T> {
868
- /** Trace ID of the new trace created during replay. */
894
+ /**
895
+ * Server trace ID of the new replay trace this item produced. Written in by
896
+ * `replay()` from the complete-replay response once the server has minted the
897
+ * trace row; the client-side id used to correlate spans during the run is
898
+ * never surfaced here. Null until completion, on older servers that omit the
899
+ * mapping, or if the item produced no trace. Not the verdict-persistence key:
900
+ * that is the original-trace lineage (`originalTraceId` + `testRunId`).
901
+ */
869
902
  traceId: string | null;
903
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
904
+ originalTraceId: string;
905
+ /** External span ID the recorded inputs were read from (the original root span). */
906
+ originalSpanId: string;
907
+ /** @deprecated alias for {@link ReplayItem.originalTraceId}. */
908
+ sourceTraceId: string;
909
+ /** @deprecated alias for {@link ReplayItem.originalSpanId}. */
910
+ sourceSpanId: string;
870
911
  /** Deserialized inputs from the original trace. */
871
912
  input: unknown[];
872
913
  /** The result returned by the function during replay, or undefined on error. */
@@ -1758,7 +1799,7 @@ declare class BitfabFunction {
1758
1799
  /**
1759
1800
  * SDK version from package.json (injected at build time)
1760
1801
  */
1761
- declare const __version__ = "0.29.0";
1802
+ declare const __version__ = "0.29.1";
1762
1803
 
1763
1804
  /**
1764
1805
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -785,6 +785,21 @@ interface ReplayOptions {
785
785
  }
786
786
  /** Running totals reported to {@link ReplayOptions.onProgress} as replay proceeds. */
787
787
  interface ReplayProgress {
788
+ /**
789
+ * Event kind. Omitted (or `"item"`) for the per-trace settle events streamed
790
+ * during the run. `"complete"` marks the single terminal event emitted once
791
+ * the run has settled and been enriched server-side; it carries the full
792
+ * {@link ReplayProgress.result} and has no `item`. The Bitfab plugin reads
793
+ * that terminal event to build the run's final result without parsing stdout.
794
+ */
795
+ type?: "item" | "complete";
796
+ /**
797
+ * The full {@link ReplayResult}, present only on the terminal `"complete"`
798
+ * event. Lets the plugin ingest the enriched result (server-aggregated tokens,
799
+ * server trace ids) over the same channel as progress, so a dependency logging
800
+ * to stdout can never block it.
801
+ */
802
+ result?: ReplayResult<unknown>;
788
803
  /** Test run ID created for this replay. */
789
804
  testRunId?: string;
790
805
  /** Items that have finished so far, whether they succeeded or errored. */
@@ -796,18 +811,25 @@ interface ReplayProgress {
796
811
  /** Of the completed items, how many threw (their `item.error` is set). */
797
812
  errored: number;
798
813
  /**
799
- * The single item that just settled to produce this event. `traceId` is the
800
- * source (historical) trace that was replayed (so a UI can identify or link
801
- * it); `error` is its replay error, or null when it ran ok; `durationMs` is how
802
- * long this one trace took to replay. Lets a progress UI show per-trace
803
- * pass/fail and timing as the run streams, without waiting for the full
804
- * {@link ReplayResult}.
814
+ * The single item that just settled to produce this event. `traceId` is null
815
+ * at this stage (the server replay id isn't known until the run completes);
816
+ * `originalTraceId` is the original (historical) trace that was replayed (so
817
+ * a UI can identify or link it); `error` is its replay error, or null when it
818
+ * ran ok; `durationMs` is how long this one trace took to replay. Lets a
819
+ * progress UI show per-trace pass/fail and timing as the run streams, without
820
+ * waiting for the full {@link ReplayResult}.
805
821
  */
806
822
  item?: {
807
- /** Source (historical) trace ID being replayed. */
808
- traceId: string | null;
809
- /** Local SDK replay trace ID, before the server maps it to a row ID. */
810
- replayTraceId?: string | null;
823
+ /** Trace ID of the new replay trace (null during the run; the server id arrives at completion). */
824
+ traceId?: string | null;
825
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
826
+ originalTraceId: string | null;
827
+ /** External span ID the recorded inputs were read from (the original root span). */
828
+ originalSpanId?: string | null;
829
+ /** @deprecated alias for `originalTraceId`. */
830
+ sourceTraceId: string | null;
831
+ /** @deprecated alias for `originalSpanId`. */
832
+ sourceSpanId?: string | null;
811
833
  /** Deserialized inputs from the original trace. */
812
834
  input?: unknown[];
813
835
  /** The result returned by the replayed function, or undefined on error. */
@@ -847,9 +869,13 @@ declare const BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
847
869
  declare function reportReplayProgress(progress: ReplayProgress): void;
848
870
  /** Per-trace context passed to {@link ReplayOptions.adaptInputs}. */
849
871
  interface AdaptContext {
850
- /** Bitfab trace ID of the historical trace being replayed. */
851
- traceId: string;
872
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
873
+ originalTraceId: string;
852
874
  /** External span ID the recorded inputs were read from. */
875
+ originalSpanId: string;
876
+ /** @deprecated alias for {@link AdaptContext.originalTraceId}. */
877
+ sourceTraceId: string;
878
+ /** @deprecated alias for {@link AdaptContext.originalSpanId}. */
853
879
  sourceSpanId: string;
854
880
  }
855
881
  /**
@@ -865,8 +891,23 @@ interface AdaptContext {
865
891
  */
866
892
  type AdaptInputsFn = (inputs: unknown[], ctx: AdaptContext) => unknown[];
867
893
  interface ReplayItem<T> {
868
- /** Trace ID of the new trace created during replay. */
894
+ /**
895
+ * Server trace ID of the new replay trace this item produced. Written in by
896
+ * `replay()` from the complete-replay response once the server has minted the
897
+ * trace row; the client-side id used to correlate spans during the run is
898
+ * never surfaced here. Null until completion, on older servers that omit the
899
+ * mapping, or if the item produced no trace. Not the verdict-persistence key:
900
+ * that is the original-trace lineage (`originalTraceId` + `testRunId`).
901
+ */
869
902
  traceId: string | null;
903
+ /** Bitfab trace ID of the original (historical) trace being replayed. */
904
+ originalTraceId: string;
905
+ /** External span ID the recorded inputs were read from (the original root span). */
906
+ originalSpanId: string;
907
+ /** @deprecated alias for {@link ReplayItem.originalTraceId}. */
908
+ sourceTraceId: string;
909
+ /** @deprecated alias for {@link ReplayItem.originalSpanId}. */
910
+ sourceSpanId: string;
870
911
  /** Deserialized inputs from the original trace. */
871
912
  input: unknown[];
872
913
  /** The result returned by the function during replay, or undefined on error. */
@@ -1758,7 +1799,7 @@ declare class BitfabFunction {
1758
1799
  /**
1759
1800
  * SDK version from package.json (injected at build time)
1760
1801
  */
1761
- declare const __version__ = "0.29.0";
1802
+ declare const __version__ = "0.29.1";
1762
1803
 
1763
1804
  /**
1764
1805
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -23,12 +23,12 @@ import {
23
23
  flushTraces,
24
24
  getCurrentSpan,
25
25
  getCurrentTrace
26
- } from "./chunk-2M5AWVVQ.js";
26
+ } from "./chunk-RTPEBWVO.js";
27
27
  import {
28
28
  BITFAB_PROGRESS_PREFIX,
29
29
  BitfabError,
30
30
  reportReplayProgress
31
- } from "./chunk-V3XORTWI.js";
31
+ } from "./chunk-YZU6WFG2.js";
32
32
  export {
33
33
  BITFAB_PROGRESS_PREFIX,
34
34
  Bitfab,
package/dist/node.cjs CHANGED
@@ -403,23 +403,27 @@ function buildMockTree(rootNode) {
403
403
  }
404
404
  return { spans };
405
405
  }
406
- async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, environment, adaptInputs) {
406
+ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, environment, adaptInputs) {
407
407
  const lease = environment ? serverItem.dbBranchLease : void 0;
408
408
  let inputs = [];
409
409
  let originalOutput;
410
410
  let result;
411
411
  let error = null;
412
- const replayedTraceId = randomUuid();
413
412
  const pendingPersistence = [];
413
+ const originalTraceId = serverItem.originalTraceId ?? serverItem.sourceTraceId;
414
+ const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
414
415
  try {
415
- const span = await httpClient.getExternalSpan(serverItem.externalSpanId);
416
+ const span = await httpClient.getExternalSpan(originalSpanId);
416
417
  const spanData = span.rawData?.span_data ?? {};
417
418
  inputs = deserializeInputs(spanData);
418
419
  originalOutput = deserializeOutput(spanData);
419
420
  if (adaptInputs) {
420
421
  inputs = adaptInputs(inputs, {
421
- traceId: serverItem.traceId,
422
- sourceSpanId: serverItem.externalSpanId
422
+ originalTraceId,
423
+ originalSpanId,
424
+ // Deprecated aliases for originalTraceId/originalSpanId.
425
+ sourceTraceId: originalTraceId,
426
+ sourceSpanId: originalSpanId
423
427
  });
424
428
  }
425
429
  const hasOverrides = resolvedOverrides.length > 0;
@@ -428,15 +432,14 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
428
432
  let mockTree;
429
433
  if (needTree) {
430
434
  try {
431
- const treeResponse = await httpClient.getSpanTree(
432
- serverItem.externalSpanId,
433
- { includeOutputs }
434
- );
435
+ const treeResponse = await httpClient.getSpanTree(originalSpanId, {
436
+ includeOutputs
437
+ });
435
438
  if (treeResponse.root) {
436
439
  mockTree = buildMockTree(treeResponse.root);
437
440
  } else if (mockStrategy === "all" || hasOverrides) {
438
441
  throw new BitfabError(
439
- `Replay mock strategy "${mockStrategy}"${hasOverrides ? " with overrides" : ""} requires a span tree root for source span ${serverItem.externalSpanId}.`
442
+ `Replay mock strategy "${mockStrategy}"${hasOverrides ? " with overrides" : ""} requires a span tree root for original span ${originalSpanId}.`
440
443
  );
441
444
  } else {
442
445
  mockTree = void 0;
@@ -467,7 +470,7 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
467
470
  traceId: replayedTraceId,
468
471
  inputSourceSpanId: span.id,
469
472
  inputSourceTraceId: span.externalTraceId,
470
- sourceBitfabTraceId: serverItem.traceId,
473
+ sourceBitfabTraceId: originalTraceId,
471
474
  mockTree,
472
475
  callCounters: mockTree ? /* @__PURE__ */ new Map() : void 0,
473
476
  mockStrategy,
@@ -497,7 +500,15 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
497
500
  }
498
501
  }
499
502
  return {
500
- traceId: replayedTraceId,
503
+ // Written in by replay() from the complete-replay response once the server
504
+ // has minted this replay trace's row. Null until then: the client-side
505
+ // correlation id (replayedTraceId) is never surfaced as the item's traceId.
506
+ traceId: null,
507
+ originalTraceId,
508
+ originalSpanId,
509
+ // Deprecated aliases for originalTraceId/originalSpanId.
510
+ sourceTraceId: originalTraceId,
511
+ sourceSpanId: originalSpanId,
501
512
  input: inputs,
502
513
  result,
503
514
  originalOutput,
@@ -573,14 +584,16 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
573
584
  ...normalizeMockOverrides(options?.mockOverride),
574
585
  ...registeredOverrides
575
586
  ];
587
+ const replayedTraceIds = serverItems.map(() => randomUuid());
576
588
  const tasks = serverItems.map(
577
- (serverItem) => () => processItem(
589
+ (serverItem, index) => () => processItem(
578
590
  httpClient,
579
591
  serverItem,
580
592
  fn,
581
593
  testRunId,
582
594
  mockStrategy,
583
595
  resolvedOverrides,
596
+ replayedTraceIds[index],
584
597
  options?.environment,
585
598
  options?.adaptInputs
586
599
  )
@@ -607,11 +620,17 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
607
620
  succeeded,
608
621
  errored,
609
622
  item: {
610
- // Source (historical) trace id, so a UI can identify the trace
611
- // that just settled. The item's own traceId is the new replay
612
- // trace and is assigned later (below), so use the server item.
613
- traceId: serverItems[index]?.traceId ?? null,
614
- replayTraceId: item.traceId,
623
+ // The server replay trace id isn't known until completeReplay
624
+ // runs (below), so it can't be reported mid-run and we never
625
+ // emit the client-side placeholder. originalTraceId (the
626
+ // historical trace) is known now and is what a UI keys on to
627
+ // identify what just settled.
628
+ traceId: null,
629
+ originalTraceId: item.originalTraceId ?? null,
630
+ originalSpanId: item.originalSpanId ?? null,
631
+ // Deprecated aliases for originalTraceId/originalSpanId.
632
+ sourceTraceId: item.originalTraceId ?? null,
633
+ sourceSpanId: item.originalSpanId ?? null,
615
634
  input: item.input,
616
635
  result: item.result,
617
636
  originalOutput: item.originalOutput,
@@ -629,56 +648,58 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
629
648
  const completeResult = await httpClient.completeReplay(testRunId);
630
649
  const serverTraceIds = completeResult.traceIds;
631
650
  const replayTokens = completeResult.tokens;
632
- if (serverTraceIds === void 0) {
633
- try {
634
- console.warn(
635
- "Bitfab: server did not return replay trace IDs; item.traceId will be null (server upgrade required for verdict persistence)"
636
- );
637
- } catch {
638
- }
639
- for (const item of resultItems) {
640
- item.traceId = null;
641
- }
642
- } else {
651
+ if (serverTraceIds !== void 0) {
643
652
  const missing = [];
644
653
  let completedCount = 0;
645
- for (const item of resultItems) {
646
- if (item.traceId) {
647
- const mapped = serverTraceIds[item.traceId];
648
- if (item.error === null) {
649
- completedCount += 1;
650
- if (mapped === void 0) {
651
- missing.push(item.traceId);
652
- }
653
- }
654
- if (mapped !== void 0) {
655
- item.tokens = replayTokens?.[mapped] ?? null;
654
+ for (let index = 0; index < resultItems.length; index += 1) {
655
+ const item = resultItems[index];
656
+ const localId = replayedTraceIds[index];
657
+ const mapped = localId ? serverTraceIds[localId] : void 0;
658
+ item.traceId = mapped ?? null;
659
+ if (item.error === null) {
660
+ completedCount += 1;
661
+ if (mapped === void 0) {
662
+ missing.push(localId ?? item.originalTraceId);
656
663
  }
657
- item.traceId = mapped ?? null;
664
+ }
665
+ if (mapped !== void 0) {
666
+ item.tokens = replayTokens?.[mapped] ?? null;
658
667
  }
659
668
  }
660
- if (missing.length > 0) {
669
+ if (completedCount > 0 && missing.length === completedCount) {
661
670
  const serverCount = completeResult.traceCount !== void 0 ? ` The server persisted ${completeResult.traceCount} trace(s) for this run.` : "";
662
- if (missing.length === completedCount) {
663
- throw new BitfabError(
664
- `Replay completed but the server has no persisted trace for any of the ${completedCount} completed item(s) (testRunId ${testRunId}).${serverCount} Trace uploads were awaited, so either the uploads failed (check for "Bitfab: Failed to create" errors above) or the replayed function is not wrapped with withSpan.`
665
- );
666
- }
671
+ throw new BitfabError(
672
+ `Replay completed but the server has no persisted trace for any of the ${completedCount} completed item(s) (testRunId ${testRunId}).${serverCount} Trace uploads were awaited, so either the uploads failed (check for "Bitfab: Failed to create" errors above) or the replayed function is not wrapped with withSpan.`
673
+ );
674
+ }
675
+ if (missing.length > 0) {
667
676
  try {
668
677
  console.error(
669
- `Bitfab: server has no persisted trace for ${missing.length} of ${completedCount} completed replay item(s) (testRunId ${testRunId}).${serverCount} Their traceId is null and verdicts cannot be persisted for them. Missing: ${missing.join(", ")}`
678
+ `Bitfab: server has no persisted trace for ${missing.length} of ${completedCount} completed replay item(s) (testRunId ${testRunId}). Their replay token usage is unavailable and they cannot be labeled.`
670
679
  );
671
680
  } catch {
672
681
  }
673
682
  }
674
683
  }
675
- const replayResult = {
684
+ const result = {
676
685
  items: resultItems,
677
686
  testRunId,
678
687
  testRunUrl: `${serviceUrl}${testRunUrl}`
679
688
  };
680
- await writeReplayResultFile(replayResult);
681
- return replayResult;
689
+ await writeReplayResultFile(result);
690
+ try {
691
+ options?.onProgress?.({
692
+ type: "complete",
693
+ testRunId,
694
+ completed: total,
695
+ total,
696
+ succeeded,
697
+ errored,
698
+ result
699
+ });
700
+ } catch {
701
+ }
702
+ return result;
682
703
  }
683
704
  async function writeReplayResultFile(result) {
684
705
  const resultPath = typeof process !== "undefined" ? process.env?.BITFAB_REPLAY_RESULT_PATH : void 0;
@@ -748,7 +769,7 @@ registerAsyncLocalStorageClass(
748
769
  );
749
770
 
750
771
  // src/version.generated.ts
751
- var __version__ = "0.29.0";
772
+ var __version__ = "0.29.1";
752
773
 
753
774
  // src/constants.ts
754
775
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -4178,7 +4199,7 @@ var Bitfab = class {
4178
4199
  dbSnapshotUsage: {
4179
4200
  neonBranchId: replayCtx.dbBranchLease.neonBranchId,
4180
4201
  snapshotTimestamp: replayCtx.dbBranchLease.snapshotTimestamp,
4181
- sourceTraceId: replayCtx.sourceBitfabTraceId,
4202
+ originalTraceId: replayCtx.sourceBitfabTraceId,
4182
4203
  accessed: replayCtx.dbSnapshotAccessed === true
4183
4204
  }
4184
4205
  }
@@ -4482,8 +4503,11 @@ var Bitfab = class {
4482
4503
  ...params.dbSnapshotUsage.snapshotTimestamp && {
4483
4504
  snapshot_timestamp: params.dbSnapshotUsage.snapshotTimestamp
4484
4505
  },
4485
- ...params.dbSnapshotUsage.sourceTraceId && {
4486
- source_trace_id: params.dbSnapshotUsage.sourceTraceId
4506
+ ...params.dbSnapshotUsage.originalTraceId && {
4507
+ original_trace_id: params.dbSnapshotUsage.originalTraceId,
4508
+ // Deprecated wire alias, kept so this SDK still reports usage
4509
+ // against servers that predate the rename.
4510
+ source_trace_id: params.dbSnapshotUsage.originalTraceId
4487
4511
  },
4488
4512
  accessed: params.dbSnapshotUsage.accessed
4489
4513
  };