@bitfab/sdk 0.69.0 → 0.71.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/cloudReplay.py CHANGED
@@ -147,8 +147,9 @@ RENAMED_FLAGS = {
147
147
  "--cloud-include": "nothing: new files that git does not ignore are already in the snapshot",
148
148
  }
149
149
  SEED_FLAGS = ("--seed", "--cases", "--from-trace", "--run")
150
- PATH_FLAGS = ("--registry", "--params", "--code-change")
151
- CODE_CHANGE_FLAGS = ("--code-change", "--no-code-change")
150
+ PATH_FLAGS = ("--registry", "--params", "--code-change-file")
151
+ CODE_CHANGE_FLAG = "--code-change"
152
+ BRANCH_CODE_CHANGES = ("last-branch", "default-branch")
152
153
  CHECKOUT_DEPTH = 2
153
154
  CODE_CHANGE_PATH_ENV = "BITFAB_CODE_CHANGE_PATH"
154
155
  CODE_CHANGE_MAX_FILES = 60
@@ -1022,6 +1023,21 @@ def branch_point(root):
1022
1023
  return None
1023
1024
 
1024
1025
 
1026
+ def default_branch_point(root):
1027
+ default = default_branch(root)
1028
+ sha = quiet_git(root, "merge-base", "HEAD", default) if default else ""
1029
+ return {"sha": sha, "ref": default} if sha else None
1030
+
1031
+
1032
+ def code_change_base(root, replay):
1033
+ kind = flag_value(replay, CODE_CHANGE_FLAG)
1034
+ if kind == "last-branch":
1035
+ return branch_point(root)
1036
+ if kind == "default-branch":
1037
+ return default_branch_point(root)
1038
+ return None
1039
+
1040
+
1025
1041
  def replay_artifact(path):
1026
1042
  return path == ".bitfab" or path.startswith(".bitfab/")
1027
1043
 
@@ -1126,11 +1142,10 @@ def snapshot(
1126
1142
  }
1127
1143
  if preview:
1128
1144
  return summary
1129
- code_change_base = request.get("codeChangeBase") or {}
1145
+ branch_base = str((request.get("codeChangeBase") or {}).get("sha", ""))
1130
1146
  extra_parent = (
1131
- ["-p", code_change_base["sha"]]
1132
- if not any(not replay_artifact(path) for _, path in changes)
1133
- and SHA.fullmatch(str(code_change_base.get("sha", "")))
1147
+ ["-p", branch_base]
1148
+ if SHA.fullmatch(branch_base) and branch_base != head
1134
1149
  else []
1135
1150
  )
1136
1151
  sha = git(
@@ -1461,9 +1476,9 @@ def submit(root, repo, workflow, parsed, path):
1461
1476
  branch = current_branch(root)
1462
1477
  if branch:
1463
1478
  request["branch"] = branch
1464
- code_change_base = branch_point(root)
1465
- if code_change_base:
1466
- request["codeChangeBase"] = code_change_base
1479
+ base = code_change_base(root, parsed["replay"])
1480
+ if base:
1481
+ request["codeChangeBase"] = base
1467
1482
  check_arguments(parsed["replay"])
1468
1483
  allowed = allowed_files(root, parsed)
1469
1484
  if "--cloud-preview" in parsed["switches"]:
@@ -2121,15 +2136,19 @@ def check_out_snapshot_base(root, commit, branch):
2121
2136
  return base
2122
2137
 
2123
2138
 
2124
- def replay_name(args):
2139
+ def flag_value(args, flag):
2125
2140
  for index, value in enumerate(args):
2126
- if value.startswith("--name="):
2141
+ if value.startswith(f"{flag}="):
2127
2142
  return value.partition("=")[2]
2128
- if value == "--name" and index + 1 < len(args):
2143
+ if value == flag and index + 1 < len(args):
2129
2144
  return args[index + 1]
2130
2145
  return None
2131
2146
 
2132
2147
 
2148
+ def replay_name(args):
2149
+ return flag_value(args, "--name")
2150
+
2151
+
2133
2152
  def git_blob(root, ref, path):
2134
2153
  try:
2135
2154
  size = int(git(root, "cat-file", "-s", f"{ref}:{path}"))
@@ -2209,7 +2228,10 @@ def branch_code_change(root, base, commit, request):
2209
2228
  and SHA.fullmatch(sha)
2210
2229
  and isinstance(ref, str)
2211
2230
  and BRANCH_NAME.fullmatch(ref)
2212
- and quiet_git(root, "rev-parse", "--verify", "-q", f"{commit}^2") == sha
2231
+ and (
2232
+ sha == base
2233
+ or quiet_git(root, "rev-parse", "--verify", "-q", f"{commit}^2") == sha
2234
+ )
2213
2235
  ):
2214
2236
  return None
2215
2237
  return snapshot_code_change(
@@ -2217,6 +2239,17 @@ def branch_code_change(root, base, commit, request):
2217
2239
  )
2218
2240
 
2219
2241
 
2242
+ def runner_code_change(root, base, commit, request):
2243
+ kind = flag_value(request["args"], CODE_CHANGE_FLAG)
2244
+ if kind == "working-tree":
2245
+ change = snapshot_code_change(root, base, commit, replay_name(request["args"]))
2246
+ elif kind in BRANCH_CODE_CHANGES:
2247
+ change = branch_code_change(root, base, commit, request)
2248
+ else:
2249
+ return None
2250
+ return change or {"files": []}
2251
+
2252
+
2220
2253
  def write_code_change(change):
2221
2254
  handle, path = tempfile.mkstemp(
2222
2255
  prefix="bitfab-code-change-",
@@ -2247,22 +2280,11 @@ def execute():
2247
2280
  if environment:
2248
2281
  workflow_environment_conflicts(root, environment)
2249
2282
  print(f"Setting {', '.join(sorted(environment))} from the request", flush=True)
2250
- names = {option_name(value) for value in request["args"]}
2251
- explicit_change = bool(names & set(CODE_CHANGE_FLAGS))
2252
- change = (
2253
- None
2254
- if explicit_change or base is None
2255
- else snapshot_code_change(root, base, commit, replay_name(request["args"]))
2256
- or branch_code_change(root, base, commit, request)
2257
- )
2283
+ change = None if base is None else runner_code_change(root, base, commit, request)
2258
2284
  run_environment = dict(environment)
2259
- if change:
2285
+ if change is not None:
2260
2286
  run_environment[CODE_CHANGE_PATH_ENV] = write_code_change(change)
2261
- args = [
2262
- *replay_command(),
2263
- *request["args"],
2264
- *([] if explicit_change or change else ["--no-code-change"]),
2265
- ]
2287
+ args = [*replay_command(), *request["args"]]
2266
2288
  if dry_run(request["args"]):
2267
2289
  run_check_command(directory, environment)
2268
2290
  experiment = {}
@@ -5,7 +5,7 @@ let _opentelemetry_core = require("@opentelemetry/core");
5
5
  let _opentelemetry_resources = require("@opentelemetry/resources");
6
6
  let _opentelemetry_sdk_trace = require("@opentelemetry/sdk-trace");
7
7
  //#region src/version.generated.ts
8
- const __version__ = "0.69.0";
8
+ const __version__ = "0.71.0";
9
9
  const __packageName__ = "@bitfab/sdk";
10
10
  //#endregion
11
11
  //#region src/traceCompletion.ts
@@ -1983,7 +1983,7 @@ var HttpClient = class {
1983
1983
  const endpoint = `/api/sdk/traces/${encodeURIComponent(traceId)}`;
1984
1984
  await this.request(endpoint, payload, { method: "PATCH" });
1985
1985
  }
1986
- async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetIds, graderIds, dbBranchSettings, attempts, includeOriginalMetadata, onlyWithAssertions, skipAssertionJudging, experimentalSelectiveReplay, notes, metadata, dryRun, experimentGroupName, invocation) {
1986
+ async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetIds, graderIds, dbBranchSettings, attempts, includeOriginalMetadata, onlyWithAssertions, skipAssertionJudging, experimentalSelectiveReplay, notes, metadata, dryRun, experimentGroupName, invocation, codeChangeType) {
1987
1987
  const payload = { traceFunctionKey };
1988
1988
  if (experimentalSelectiveReplay !== void 0) payload.experimentalSelectiveReplay = experimentalSelectiveReplay;
1989
1989
  if (limit !== void 0) payload.limit = limit;
@@ -1991,6 +1991,7 @@ var HttpClient = class {
1991
1991
  if (name !== void 0) payload.name = name;
1992
1992
  if (notes !== void 0) payload.notes = notes;
1993
1993
  if (metadata !== void 0) payload.metadata = metadata;
1994
+ if (codeChangeType !== void 0) payload.codeChangeType = codeChangeType;
1994
1995
  if (codeChangeDescription !== void 0) payload.codeChangeDescription = codeChangeDescription;
1995
1996
  if (codeChangeFiles !== void 0) payload.codeChangeFiles = codeChangeFiles;
1996
1997
  if (includeDbBranchLease) {
@@ -2318,4 +2319,4 @@ Object.defineProperty(exports, "unrefTimer", {
2318
2319
  }
2319
2320
  });
2320
2321
 
2321
- //# sourceMappingURL=http-C9icRaA3.cjs.map
2322
+ //# sourceMappingURL=http-D2Rgpq7_.cjs.map