bitfab 0.64.5 → 0.64.7

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,12 +1,14 @@
1
1
  import {
2
2
  BitfabError,
3
3
  MAX_COMPRESSIBLE_SPAN_CARRIER_BYTES,
4
+ __version__,
4
5
  flushTraces,
5
6
  gitRunner,
7
+ readEnv,
6
8
  replayContextReady,
7
9
  runWithReplayContext,
8
10
  unrefTimer
9
- } from "./chunk-LRY4Y7HE.js";
11
+ } from "./chunk-TAGNRN6F.js";
10
12
  import {
11
13
  runWithCaptureSuppressed,
12
14
  warnOnce,
@@ -520,6 +522,105 @@ function installReplayInterruptHandlers(target) {
520
522
  return { remove: removeHandlers, interrupted: () => interrupting };
521
523
  }
522
524
 
525
+ // src/replayInvocation.ts
526
+ var REPLAY_EXECUTION_TARGET_ENV = "BITFAB_REPLAY_EXECUTION_TARGET";
527
+ var HOSTED_EXECUTION_TARGET = "hosted";
528
+ var CI_ENV = "CI";
529
+ var CI_TRUE_VALUES = /* @__PURE__ */ new Set(["true", "1"]);
530
+ var CI_PRESENCE_ENV_VARS = [
531
+ "GITHUB_ACTIONS",
532
+ "GITLAB_CI",
533
+ "CIRCLECI",
534
+ "BUILDKITE",
535
+ "JENKINS_URL",
536
+ "TF_BUILD"
537
+ ];
538
+ var MAX_FLAGS = 100;
539
+ var MAX_FLAG_NAME_LENGTH = 100;
540
+ var MAX_FLAG_STRING_LENGTH = 1e3;
541
+ var MAX_FLAG_LIST_LENGTH = 100;
542
+ var SECRET_FLAG_NAME = /key|token|secret|password/i;
543
+ var CLI_FLAGS = /* @__PURE__ */ Symbol("bitfab.replayCliFlags");
544
+ var METADATA_FLAG = "metadata";
545
+ var OPTION_FLAG_NAMES = {
546
+ maxConcurrency: "concurrency",
547
+ datasetId: "dataset-ids",
548
+ datasetIds: "dataset-ids"
549
+ };
550
+ function replayEnvironment() {
551
+ if (readEnv(REPLAY_EXECUTION_TARGET_ENV) === HOSTED_EXECUTION_TARGET) {
552
+ return "cloud_replay";
553
+ }
554
+ if (CI_TRUE_VALUES.has((readEnv(CI_ENV) ?? "").toLowerCase())) {
555
+ return "ci";
556
+ }
557
+ if (CI_PRESENCE_ENV_VARS.some((name) => (readEnv(name) ?? "") !== "")) {
558
+ return "ci";
559
+ }
560
+ return "local";
561
+ }
562
+ function flagScalar(value) {
563
+ if (typeof value === "string") {
564
+ return value.slice(0, MAX_FLAG_STRING_LENGTH);
565
+ }
566
+ if (typeof value === "number") {
567
+ return Number.isFinite(value) ? value : void 0;
568
+ }
569
+ if (typeof value === "boolean" || value === null) {
570
+ return value;
571
+ }
572
+ return void 0;
573
+ }
574
+ function flagValue(value) {
575
+ if (Array.isArray(value)) {
576
+ const items = value.slice(0, MAX_FLAG_LIST_LENGTH).map(flagScalar);
577
+ return items.every((item) => item !== void 0) ? items : true;
578
+ }
579
+ const scalar = flagScalar(value);
580
+ return scalar === void 0 ? true : scalar;
581
+ }
582
+ function optionFlagName(option) {
583
+ return OPTION_FLAG_NAMES[option] ?? option.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
584
+ }
585
+ function metadataKeys(value) {
586
+ const keys = Array.isArray(value) ? value.map((pair) => String(pair).split("=")[0]) : typeof value === "object" && value !== null ? Object.keys(value) : void 0;
587
+ return keys === void 0 ? true : [...new Set(keys)].sort();
588
+ }
589
+ function invocationFlags(entries) {
590
+ const flags = {};
591
+ const seen = /* @__PURE__ */ new Set();
592
+ for (const [name, value] of entries) {
593
+ if (seen.size >= MAX_FLAGS) {
594
+ break;
595
+ }
596
+ if (value === void 0 || seen.has(name) || name.length === 0 || name.length > MAX_FLAG_NAME_LENGTH || SECRET_FLAG_NAME.test(name)) {
597
+ continue;
598
+ }
599
+ flags[name] = flagValue(
600
+ name === METADATA_FLAG ? metadataKeys(value) : value
601
+ );
602
+ seen.add(name);
603
+ }
604
+ return flags;
605
+ }
606
+ function buildReplayInvocation(entries = []) {
607
+ return {
608
+ flags: invocationFlags(entries),
609
+ sdk: { language: "typescript", version: __version__ },
610
+ environment: replayEnvironment()
611
+ };
612
+ }
613
+ function safeReplayInvocation(build) {
614
+ try {
615
+ return build();
616
+ } catch {
617
+ return void 0;
618
+ }
619
+ }
620
+ function cliFlags(options) {
621
+ return options?.[CLI_FLAGS];
622
+ }
623
+
523
624
  // src/selectiveReplay.ts
524
625
  function replayNodeKey(node) {
525
626
  return JSON.stringify([node.traceFunctionKey, node.spanName]);
@@ -936,6 +1037,47 @@ function resolveDbBranchSettings(dbBranch) {
936
1037
  };
937
1038
  return Object.keys(settings).length === 0 ? void 0 : settings;
938
1039
  }
1040
+ var REPLAY_OPTION_NAMES = [
1041
+ "experimentalSelectiveReplay",
1042
+ "limit",
1043
+ "attempts",
1044
+ "traceIds",
1045
+ "name",
1046
+ "notes",
1047
+ "metadata",
1048
+ "maxConcurrency",
1049
+ "codeChangeDescription",
1050
+ "codeChangeFiles",
1051
+ "mock",
1052
+ "mockOverride",
1053
+ "dbBranch",
1054
+ "experimentGroupId",
1055
+ "datasetId",
1056
+ "datasetIds",
1057
+ "graderIds",
1058
+ "onlyWithAssertions",
1059
+ "skipAssertionJudging",
1060
+ "judgeAssertions",
1061
+ "adaptInputs",
1062
+ "dryRun",
1063
+ "onItemFinish",
1064
+ "onProgress",
1065
+ "onItemStart",
1066
+ "onExperimentStart",
1067
+ "onInterrupt",
1068
+ "resume",
1069
+ "force"
1070
+ ];
1071
+ function explicitReplayOptions(options) {
1072
+ var _a;
1073
+ const explicit = {};
1074
+ for (const name of REPLAY_OPTION_NAMES) {
1075
+ if (options?.[name] !== void 0) {
1076
+ explicit[_a = optionFlagName(name)] ?? (explicit[_a] = options[name]);
1077
+ }
1078
+ }
1079
+ return explicit;
1080
+ }
939
1081
  var BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
940
1082
  function reportReplayProgress(progress) {
941
1083
  const stderr = typeof process !== "undefined" ? process.stderr : void 0;
@@ -1470,7 +1612,12 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
1470
1612
  options?.experimentalSelectiveReplay,
1471
1613
  options?.notes,
1472
1614
  options?.metadata,
1473
- options?.dryRun === true
1615
+ options?.dryRun === true,
1616
+ safeReplayInvocation(
1617
+ () => buildReplayInvocation(
1618
+ Object.entries(cliFlags(options) ?? explicitReplayOptions(options))
1619
+ )
1620
+ )
1474
1621
  );
1475
1622
  if (started.items.length === 0) {
1476
1623
  try {
@@ -1884,4 +2031,4 @@ export {
1884
2031
  warnJudgeAssertionsDeprecated,
1885
2032
  replay
1886
2033
  };
1887
- //# sourceMappingURL=chunk-QF7FLTXB.js.map
2034
+ //# sourceMappingURL=chunk-SZVZU3F6.js.map