@bitfab/sdk 0.71.0 → 0.72.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.
@@ -1,5 +1,5 @@
1
1
  const require_bamlPeer = require("./bamlPeer-5Ohpq8q9.cjs");
2
- const require_http = require("./http-D2Rgpq7_.cjs");
2
+ const require_http = require("./http-C07Y93Ss.cjs");
3
3
  const require_autoTrace = require("./autoTrace-DPWV1Xzr.cjs");
4
4
  const require_optionalPeer = require("./optionalPeer-CUH756lt.cjs");
5
5
  let superjson = require("superjson");
@@ -3010,20 +3010,24 @@ const CODE_CHANGE_TYPES = [
3010
3010
  "working-tree",
3011
3011
  "last-branch",
3012
3012
  "default-branch",
3013
+ "ref",
3013
3014
  "skip",
3014
3015
  "manual"
3015
3016
  ];
3016
- const CODE_CHANGE_CHOICES = "\"working-tree\" (uncommitted changes vs HEAD), \"last-branch\" (the diff against the branch this one was cut from), \"default-branch\" (the diff against the default branch), \"skip\" (no code change), or \"manual\" (pass the files yourself)";
3017
+ const CODE_CHANGE_CHOICES = "\"working-tree\" (uncommitted changes vs HEAD), \"last-branch\" (the diff against the branch this one was cut from), \"default-branch\" (the diff against the default branch), \"ref\" (the diff against a branch or commit you name), \"skip\" (no code change), or \"manual\" (pass the files yourself)";
3017
3018
  function isCodeChangeType(value) {
3018
3019
  return CODE_CHANGE_TYPES.includes(value);
3019
3020
  }
3020
3021
  function validateCodeChange(request) {
3021
- const { codeChange, codeChangeDescription, codeChangeFiles } = request;
3022
+ const { codeChange, codeChangeDescription, codeChangeFiles, codeChangeBase } = request;
3022
3023
  if (codeChange === void 0 || codeChange === null) throw new require_http.BitfabError(`replay needs a codeChange naming the code this run tests: ${CODE_CHANGE_CHOICES}.`);
3023
3024
  if (!isCodeChangeType(codeChange)) throw new require_http.BitfabError(`Unknown codeChange ${JSON.stringify(codeChange)}. Pass ${CODE_CHANGE_CHOICES}.`);
3024
3025
  const hasFiles = codeChangeFiles !== void 0 && codeChangeFiles !== null;
3025
3026
  if (codeChange === "manual" && !hasFiles) throw new require_http.BitfabError("codeChange \"manual\" needs codeChangeFiles: the path and before/after contents of each edited file.");
3026
3027
  if (codeChange !== "manual" && hasFiles) throw new require_http.BitfabError(`codeChangeFiles only applies with codeChange "manual" (got "${codeChange}").`);
3028
+ const hasBase = codeChangeBase !== void 0 && codeChangeBase !== null;
3029
+ if (codeChange === "ref" && (typeof codeChangeBase !== "string" || codeChangeBase.trim() === "" || codeChangeBase.trim().startsWith("-"))) throw new require_http.BitfabError("codeChange \"ref\" needs codeChangeBase: the branch or commit to diff against, such as \"dev\" or a commit SHA.");
3030
+ if (codeChange !== "ref" && hasBase) throw new require_http.BitfabError(`codeChangeBase only applies with codeChange "ref" (got "${codeChange}").`);
3027
3031
  if (codeChange === "skip" && codeChangeDescription !== void 0 && codeChangeDescription !== null) throw new require_http.BitfabError("codeChange \"skip\" attaches no code change, so it cannot take a codeChangeDescription.");
3028
3032
  return codeChange;
3029
3033
  }
@@ -3035,7 +3039,7 @@ async function resolveCodeChange(request, label) {
3035
3039
  description,
3036
3040
  files: request.codeChangeFiles ?? []
3037
3041
  };
3038
- const captured = await captureCodeChange(codeChange, label);
3042
+ const captured = await captureCodeChange(codeChange, label, request.codeChangeBase?.trim());
3039
3043
  if (captured?.files === void 0 || captured.files.length === 0) {
3040
3044
  try {
3041
3045
  console.warn(`Bitfab: codeChange "${codeChange}" found no changed files, so this replay has no code change attached.`);
@@ -3052,11 +3056,11 @@ const MAX_FILE_BYTES = 5e5;
3052
3056
  const MAX_TOTAL_BYTES = 2e6;
3053
3057
  const MAX_BRANCH_WALK = 1e3;
3054
3058
  const NUL = String.fromCharCode(0);
3055
- async function captureCodeChange(type, label) {
3059
+ async function captureCodeChange(type, label, base) {
3056
3060
  if (typeof process === "undefined") return null;
3057
3061
  const fromEnv = await readCodeChangeFile();
3058
3062
  if (fromEnv) return fromEnv;
3059
- return captureCodeChangeFromGit(process.cwd?.() ?? ".", type, label);
3063
+ return captureCodeChangeFromGit(process.cwd?.() ?? ".", type, label, base);
3060
3064
  }
3061
3065
  async function readCodeChangeFile() {
3062
3066
  const path = process.env?.BITFAB_CODE_CHANGE_PATH;
@@ -3075,7 +3079,7 @@ async function readCodeChangeFile() {
3075
3079
  return null;
3076
3080
  }
3077
3081
  }
3078
- async function captureCodeChangeFromGit(cwd, type, label) {
3082
+ async function captureCodeChangeFromGit(cwd, type, label, chosenBase) {
3079
3083
  let readFile;
3080
3084
  try {
3081
3085
  ({readFile} = await import("fs/promises"));
@@ -3091,7 +3095,7 @@ async function captureCodeChangeFromGit(cwd, type, label) {
3091
3095
  try {
3092
3096
  const root = (await git(cwd, ["rev-parse", "--show-toplevel"]))?.trim();
3093
3097
  if (!root) return null;
3094
- const resolved = await resolveBase(git, root, type);
3098
+ const resolved = await resolveBase(git, root, type, chosenBase);
3095
3099
  if (!resolved) return null;
3096
3100
  const entries = await listChanges(git, root, resolved.base);
3097
3101
  if (entries.length === 0) return null;
@@ -3145,7 +3149,8 @@ async function captureCodeChangeFromGit(cwd, type, label) {
3145
3149
  description: `${label?.trim() || subject || "Working-tree change"} (${files.length} ${fileWord} changed ${against})`,
3146
3150
  files
3147
3151
  };
3148
- } catch {
3152
+ } catch (error) {
3153
+ if (error instanceof require_http.BitfabError) throw error;
3149
3154
  return null;
3150
3155
  }
3151
3156
  }
@@ -3285,7 +3290,22 @@ async function resolveDefaultBranchPoint(git, root) {
3285
3290
  against: `vs ${defaultBranch}`
3286
3291
  } : null;
3287
3292
  }
3288
- async function resolveBase(git, root, type) {
3293
+ async function resolveChosenBase(git, root, chosen) {
3294
+ for (const ref of [chosen, `origin/${chosen}`]) if (await refExists(git, root, `${ref}^{commit}`)) {
3295
+ const base = (await git(root, [
3296
+ "merge-base",
3297
+ "HEAD",
3298
+ ref
3299
+ ]))?.trim();
3300
+ return base ? {
3301
+ base,
3302
+ against: `vs ${chosen}`
3303
+ } : null;
3304
+ }
3305
+ throw new require_http.BitfabError(`codeChangeBase "${chosen}" names no branch or commit in this repository. Pass a branch name, such as "dev", or a commit SHA; fetch it first if it only exists on the remote.`);
3306
+ }
3307
+ async function resolveBase(git, root, type, chosenBase) {
3308
+ if (type === "ref") return chosenBase ? resolveChosenBase(git, root, chosenBase) : null;
3289
3309
  if (type === "last-branch") return resolveBranchPoint(git, root);
3290
3310
  if (type === "default-branch") return resolveDefaultBranchPoint(git, root);
3291
3311
  return await refExists(git, root, "HEAD") ? {
@@ -3812,6 +3832,7 @@ const REPLAY_OPTION_NAMES = [
3812
3832
  "codeChange",
3813
3833
  "codeChangeDescription",
3814
3834
  "codeChangeFiles",
3835
+ "codeChangeBase",
3815
3836
  "mock",
3816
3837
  "mockOverride",
3817
3838
  "dbBranch",
@@ -7038,7 +7059,7 @@ var Bitfab = class {
7038
7059
  await runWithSeedContext({ traceId }, async () => target(...args));
7039
7060
  } finally {
7040
7061
  try {
7041
- const { flushTraces } = await Promise.resolve().then(() => require("./http-D2Rgpq7_.cjs")).then((n) => n.http_exports);
7062
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-C07Y93Ss.cjs")).then((n) => n.http_exports);
7042
7063
  await flushTraces(3e4);
7043
7064
  } finally {
7044
7065
  unrecorded = activeTraceStates.delete(traceId);
@@ -7244,7 +7265,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
7244
7265
  metadata: seedCase.metadata,
7245
7266
  sessionId: seedCase.sessionId
7246
7267
  }));
7247
- const { flushTraces } = await Promise.resolve().then(() => require("./http-D2Rgpq7_.cjs")).then((n) => n.http_exports);
7268
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-C07Y93Ss.cjs")).then((n) => n.http_exports);
7248
7269
  await flushTraces(3e4);
7249
7270
  return {
7250
7271
  pipeline,
@@ -7494,4 +7515,4 @@ Object.defineProperty(exports, "serializeReplayResult", {
7494
7515
  }
7495
7516
  });
7496
7517
 
7497
- //# sourceMappingURL=src-C2OX1CHX.cjs.map
7518
+ //# sourceMappingURL=src-DRC6OVjp.cjs.map