@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.
package/cloudReplay.py CHANGED
@@ -149,7 +149,10 @@ RENAMED_FLAGS = {
149
149
  SEED_FLAGS = ("--seed", "--cases", "--from-trace", "--run")
150
150
  PATH_FLAGS = ("--registry", "--params", "--code-change-file")
151
151
  CODE_CHANGE_FLAG = "--code-change"
152
- BRANCH_CODE_CHANGES = ("last-branch", "default-branch")
152
+ CODE_CHANGE_BASE_FLAG = "--code-change-base"
153
+ BRANCH_CODE_CHANGES = ("last-branch", "default-branch", "ref")
154
+ GIT_CODE_CHANGES = ("working-tree", *BRANCH_CODE_CHANGES)
155
+ DESCRIBED_REF = re.compile(r"[^\x00-\x1f\x7f]{1,200}")
153
156
  CHECKOUT_DEPTH = 2
154
157
  CODE_CHANGE_PATH_ENV = "BITFAB_CODE_CHANGE_PATH"
155
158
  CODE_CHANGE_MAX_FILES = 60
@@ -220,7 +223,9 @@ Options added by --cloud:
220
223
  checkout of the repository, with GitHub access that can
221
224
  read it and run Actions (a job token needs contents: read
222
225
  and actions: write, passed as GH_TOKEN), and a workflow on
223
- BRANCH that declares a request input.
226
+ BRANCH that declares a request input. With no snapshot
227
+ there is nothing to diff against, so it takes
228
+ --code-change skip or manual, as does a dispatched run.
224
229
 
225
230
  A workflow can also dispatch bitfab-replay.yml itself on any branch other than a
226
231
  bitfab-replay/ snapshot branch, passing the replay as JSON in the request input:
@@ -1029,8 +1034,30 @@ def default_branch_point(root):
1029
1034
  return {"sha": sha, "ref": default} if sha else None
1030
1035
 
1031
1036
 
1037
+ def chosen_base_point(root, chosen):
1038
+ if not chosen or chosen.startswith("-"):
1039
+ return None
1040
+ for ref in (chosen, f"origin/{chosen}"):
1041
+ if quiet_git(root, "rev-parse", "--verify", "-q", f"{ref}^{{commit}}"):
1042
+ sha = quiet_git(root, "merge-base", "HEAD", ref)
1043
+ return {"sha": sha, "ref": chosen} if sha else None
1044
+ raise ValueError(
1045
+ f"{CODE_CHANGE_BASE_FLAG} {chosen} names no branch or commit in this repository; pass a branch name or a commit SHA, and fetch it first if it only exists on the remote"
1046
+ )
1047
+
1048
+
1049
+ def refuse_git_code_change(replay, where):
1050
+ kind = flag_value(replay, CODE_CHANGE_FLAG)
1051
+ if kind in GIT_CODE_CHANGES:
1052
+ raise ValueError(
1053
+ f"{where} as it is on GitHub, with no snapshot of a checkout, so --code-change {kind} has nothing to compare against there; pass --code-change skip, or --code-change manual with --code-change-file, or start it with bitfab-replay --cloud and no --cloud-ref, which resolves {kind} from your checkout before upload"
1054
+ )
1055
+
1056
+
1032
1057
  def code_change_base(root, replay):
1033
1058
  kind = flag_value(replay, CODE_CHANGE_FLAG)
1059
+ if kind == "ref":
1060
+ return chosen_base_point(root, flag_value(replay, CODE_CHANGE_BASE_FLAG))
1034
1061
  if kind == "last-branch":
1035
1062
  return branch_point(root)
1036
1063
  if kind == "default-branch":
@@ -1839,6 +1866,7 @@ def submit_as_is(root, repo, workflow, parsed, path):
1839
1866
  branch = parsed["cloud"]["--cloud-ref"]
1840
1867
  request, _ = replay_request(root, parsed)
1841
1868
  check_arguments(parsed["replay"])
1869
+ refuse_git_code_change(parsed["replay"], f"--cloud-ref replays {branch}")
1842
1870
  sha = branch_head(repo, branch)
1843
1871
  if "--cloud-preview" in parsed["switches"]:
1844
1872
  return {
@@ -2089,6 +2117,7 @@ def dispatched_request():
2089
2117
  raise ValueError("The request id does not match the execution_id input")
2090
2118
  args = request.get("args")
2091
2119
  validate_arguments(args)
2120
+ refuse_git_code_change(args, f"A dispatched replay runs {branch}")
2092
2121
  if request.get("check") is True and "--dry-run" not in args:
2093
2122
  args = [*args, "--dry-run"]
2094
2123
  normalized = {
@@ -2227,7 +2256,7 @@ def branch_code_change(root, base, commit, request):
2227
2256
  isinstance(sha, str)
2228
2257
  and SHA.fullmatch(sha)
2229
2258
  and isinstance(ref, str)
2230
- and BRANCH_NAME.fullmatch(ref)
2259
+ and DESCRIBED_REF.fullmatch(ref)
2231
2260
  and (
2232
2261
  sha == base
2233
2262
  or quiet_git(root, "rev-parse", "--verify", "-q", f"{commit}^2") == sha
@@ -5,7 +5,7 @@ import { ExportResultCode } from "@opentelemetry/core";
5
5
  import { resourceFromAttributes } from "@opentelemetry/resources";
6
6
  import { AlwaysOnSampler, BatchSpanProcessor, TracerProvider } from "@opentelemetry/sdk-trace";
7
7
  //#region src/version.generated.ts
8
- const __version__ = "0.71.0";
8
+ const __version__ = "0.72.0";
9
9
  const __packageName__ = "@bitfab/sdk";
10
10
  //#endregion
11
11
  //#region src/traceCompletion.ts
@@ -2164,4 +2164,4 @@ function experimentIdWireFields(experimentId) {
2164
2164
  //#endregion
2165
2165
  export { BitfabError as C, __version__ as E, gitRunner as S, readEnv as T, MAX_SPAN_CARRIER_BYTES as _, http_exports as a, replayContextReady as b, recordCallerTraceMetadata as c, DECLARED_NODE_FIELD as d, ROOT_TRACE_FUNCTION_KEY_FIELD as f, MAX_COMPRESSIBLE_SPAN_CARRIER_BYTES as g, makeSpanOrigin as h, flushTraces as i, retireTraceMetadata as l, isFrameworkInstrumentation as m, SPAN_TYPES as n, unrefTimer as o, SimulationPlan as p, experimentIdWireFields as r, callerTraceMetadata as s, HttpClient as t, CONTENT_OFF_KEY as u, byteLength as v, MixedTracingError as w, runWithReplayContext as x, getReplayContext as y };
2166
2166
 
2167
- //# sourceMappingURL=http-Dh6NfOpj.js.map
2167
+ //# sourceMappingURL=http-7rcRBbK-.js.map