bitfab 0.30.2 → 0.31.0

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
@@ -533,6 +533,17 @@ __export(replay_exports, {
533
533
  replay: () => replay,
534
534
  reportReplayProgress: () => reportReplayProgress
535
535
  });
536
+ function resolveDbBranchSettings(dbBranch) {
537
+ if (!dbBranch) {
538
+ return void 0;
539
+ }
540
+ const settings = {
541
+ ...dbBranch.minCu === void 0 ? {} : { minCu: dbBranch.minCu },
542
+ ...dbBranch.maxCu === void 0 ? {} : { maxCu: dbBranch.maxCu },
543
+ ...dbBranch.warmupSql === void 0 ? {} : { warmupSql: dbBranch.warmupSql }
544
+ };
545
+ return Object.keys(settings).length === 0 ? void 0 : settings;
546
+ }
536
547
  function reportReplayProgress(progress) {
537
548
  const stderr = typeof process !== "undefined" ? process.stderr : void 0;
538
549
  if (!stderr) {
@@ -595,6 +606,7 @@ function buildMockTree(rootNode) {
595
606
  }
596
607
  async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy, resolvedOverrides, replayedTraceId, environment, adaptInputs) {
597
608
  const lease = environment ? serverItem.dbBranchLease : void 0;
609
+ const leaseError = environment ? serverItem.dbBranchLeaseError : void 0;
598
610
  let inputs = [];
599
611
  let originalOutput;
600
612
  let result;
@@ -603,6 +615,11 @@ async function processItem(httpClient, serverItem, fn, testRunId, mockStrategy,
603
615
  const originalTraceId = serverItem.originalTraceId ?? serverItem.sourceTraceId;
604
616
  const originalSpanId = serverItem.originalSpanId ?? serverItem.sourceSpanId;
605
617
  try {
618
+ if (leaseError) {
619
+ throw new BitfabError(
620
+ `Replay requested a database branch for trace ${originalTraceId} but it could not be resolved (${leaseError.code}): ${leaseError.message}. The function was not run, because replaying it against the live database would produce a result that looks valid but did not use the historical data you asked for.`
621
+ );
622
+ }
606
623
  const span = await httpClient.getExternalSpan(originalSpanId);
607
624
  const spanData = span.rawData?.span_data ?? {};
608
625
  inputs = deserializeInputs(spanData);
@@ -776,7 +793,8 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
776
793
  // includeDbBranchLease
777
794
  options?.experimentGroupId,
778
795
  options?.datasetId,
779
- options?.graderIds
796
+ options?.graderIds,
797
+ resolveDbBranchSettings(options?.dbBranch)
780
798
  );
781
799
  const mockStrategy = options?.mock ?? "marked";
782
800
  const maxConcurrency = options?.maxConcurrency ?? 10;
@@ -963,7 +981,7 @@ __export(index_exports, {
963
981
  module.exports = __toCommonJS(index_exports);
964
982
 
965
983
  // src/version.generated.ts
966
- var __version__ = "0.30.2";
984
+ var __version__ = "0.31.0";
967
985
 
968
986
  // src/constants.ts
969
987
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1322,7 +1340,7 @@ var HttpClient = class {
1322
1340
  * Start a replay session by fetching historical traces.
1323
1341
  * Blocking call - creates a test run and returns lightweight item references.
1324
1342
  */
1325
- async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId, graderIds) {
1343
+ async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetId, graderIds, dbBranchSettings) {
1326
1344
  const payload = { traceFunctionKey };
1327
1345
  if (limit !== void 0) {
1328
1346
  payload.limit = limit;
@@ -1351,6 +1369,9 @@ var HttpClient = class {
1351
1369
  if (graderIds !== void 0) {
1352
1370
  payload.graderIds = graderIds;
1353
1371
  }
1372
+ if (dbBranchSettings !== void 0) {
1373
+ payload.dbBranchSettings = dbBranchSettings;
1374
+ }
1354
1375
  const timeout = includeDbBranchLease ? 18e4 : 3e4;
1355
1376
  return this.request("/api/sdk/replay/start", payload, {
1356
1377
  timeout
@@ -3081,6 +3102,13 @@ var ReplayEnvironment = class {
3081
3102
  get readOnly() {
3082
3103
  return this.require().readOnly;
3083
3104
  }
3105
+ /**
3106
+ * The branch's region, e.g. `aws-us-east-1`. A compute runs in its project's
3107
+ * region, so a replay runner elsewhere pays that round trip on every query.
3108
+ */
3109
+ get region() {
3110
+ return this.require().region;
3111
+ }
3084
3112
  /** The historical trace ID that produced the input for this replay item. */
3085
3113
  get traceId() {
3086
3114
  return this.require().traceId;
@@ -3125,6 +3153,7 @@ var ReplayEnvironment = class {
3125
3153
  expiresAt: lease.expiresAt,
3126
3154
  providerConsoleUrl: lease.providerConsoleUrl,
3127
3155
  readOnly: lease.readOnly,
3156
+ region: lease.region,
3128
3157
  traceId
3129
3158
  };
3130
3159
  }