@swmansion/argent 0.35.1-next.10 → 0.35.1-next.12

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.
@@ -63391,12 +63391,12 @@ async function hasDefaultBootSnapshot(avdName) {
63391
63391
  return false;
63392
63392
  }
63393
63393
  }
63394
- var import_node_child_process18, import_node_util13, import_node_os5, import_node_path10, import_ini, execFileAsync13, emulatorFlagSupportCache, ADB_KILL_SIGNAL, ADB_DEVICE_STATES, ADB_DEVICES_TIMEOUT_MS, ENRICH_TIMEOUT_MS, androidRuntimeKindCache, TERMINAL_ADB_ERROR_PATTERNS, AVD_NAME_PATTERN;
63394
+ var import_node_child_process18, import_node_util14, import_node_os5, import_node_path10, import_ini, execFileAsync13, emulatorFlagSupportCache, ADB_KILL_SIGNAL, ADB_DEVICE_STATES, ADB_DEVICES_TIMEOUT_MS, ENRICH_TIMEOUT_MS, androidRuntimeKindCache, TERMINAL_ADB_ERROR_PATTERNS, AVD_NAME_PATTERN;
63395
63395
  var init_adb = __esm({
63396
63396
  "../tool-server/src/utils/adb.ts"() {
63397
63397
  "use strict";
63398
63398
  import_node_child_process18 = require("node:child_process");
63399
- import_node_util13 = require("node:util");
63399
+ import_node_util14 = require("node:util");
63400
63400
  import_node_os5 = require("node:os");
63401
63401
  import_node_path10 = require("node:path");
63402
63402
  import_ini = __toESM(require_ini());
@@ -63404,7 +63404,7 @@ var init_adb = __esm({
63404
63404
  init_android_binary();
63405
63405
  init_subprocess_error();
63406
63406
  init_external_devices();
63407
- execFileAsync13 = (0, import_node_util13.promisify)(import_node_child_process18.execFile);
63407
+ execFileAsync13 = (0, import_node_util14.promisify)(import_node_child_process18.execFile);
63408
63408
  emulatorFlagSupportCache = /* @__PURE__ */ new Map();
63409
63409
  ADB_KILL_SIGNAL = "SIGKILL";
63410
63410
  ADB_DEVICE_STATES = /* @__PURE__ */ new Set([
@@ -72957,7 +72957,7 @@ function isCi(env = process.env) {
72957
72957
  var SESSION_ID = (0, import_node_crypto3.randomUUID)();
72958
72958
  function readCliVersion() {
72959
72959
  if (true) {
72960
- return "0.35.1-next.8";
72960
+ return "0.35.1-next.10";
72961
72961
  }
72962
72962
  return "0.0.0";
72963
72963
  }
@@ -75203,6 +75203,7 @@ function buildScreenRecordingNote(recordings2, nowMs) {
75203
75203
  var path14 = __toESM(require("node:path"));
75204
75204
  var fs14 = __toESM(require("node:fs/promises"));
75205
75205
  var import_node_fs7 = require("node:fs");
75206
+ var import_node_util6 = require("node:util");
75206
75207
  init_src();
75207
75208
  init_src2();
75208
75209
  var import_yaml = __toESM(require_dist8());
@@ -78520,9 +78521,11 @@ async function writeNewFlowFile(filePath, content) {
78520
78521
  }
78521
78522
  await writeFlowFile(filePath, content);
78522
78523
  }
78523
- async function countStepsOnDisk(filePath) {
78524
+ async function countStepsOnDisk(filePath, block = "steps") {
78524
78525
  try {
78525
- return parseFlow(await fs14.readFile(filePath, "utf8")).steps.length;
78526
+ const flow = parseFlow(await fs14.readFile(filePath, "utf8"));
78527
+ const shutdown2 = flow.shutdown?.length ?? 0;
78528
+ return block === "steps" ? flow.steps.length : block === "shutdown" ? shutdown2 : flow.steps.length + shutdown2;
78526
78529
  } catch {
78527
78530
  return void 0;
78528
78531
  }
@@ -78552,13 +78555,11 @@ async function setRecordingEnv(session, changes) {
78552
78555
  }
78553
78556
  session.lastTouchedSeq = touch();
78554
78557
  if (session.persist === "host") {
78555
- const before = session.flow.steps;
78556
78558
  const flow2 = apply(parseFlow(await fs14.readFile(session.filePath, "utf8")));
78557
78559
  validateFlow(flow2);
78558
78560
  const updated = serializeFlow(flow2);
78559
78561
  await writeFlowFile(session.filePath, updated);
78560
- session.flow = parseFlow(updated);
78561
- session.discardedWarnings = (session.discardedWarnings ?? 0) + dropMovedWarnings(session.stepWarnings, session.flow.steps, before);
78562
+ adoptRecordedFile(session, parseFlow(updated));
78562
78563
  return { env: session.flow.env ?? {}, savedTo: session.filePath };
78563
78564
  }
78564
78565
  const flow = apply(session.flow);
@@ -78568,10 +78569,10 @@ async function setRecordingEnv(session, changes) {
78568
78569
  return { env: flow.env ?? {}, savedTo };
78569
78570
  });
78570
78571
  }
78571
- async function appendStep(filePath, step) {
78572
+ async function appendStep(filePath, step, block) {
78572
78573
  const content = await fs14.readFile(filePath, "utf8");
78573
78574
  const flow = parseFlow(content);
78574
- flow.steps.push(step);
78575
+ (block === "shutdown" ? flow.shutdown ??= [] : flow.steps).push(step);
78575
78576
  validateFlow(flow);
78576
78577
  const updated = serializeFlow(flow);
78577
78578
  await writeFlowFile(filePath, updated);
@@ -78645,31 +78646,134 @@ function dropMovedWarnings(warnings, now, before) {
78645
78646
  }
78646
78647
  return dropped;
78647
78648
  }
78648
- async function appendStepToFlow(session, step) {
78649
+ function adoptRecordedFile(session, flow, appended) {
78650
+ const before = session.flow;
78651
+ session.flow = flow;
78652
+ const { steps, shutdown: shutdown2 = [] } = flow;
78653
+ session.discardedWarnings = (session.discardedWarnings ?? 0) + dropMovedWarnings(
78654
+ session.stepWarnings,
78655
+ appended === "steps" ? steps.slice(0, -1) : steps,
78656
+ before.steps
78657
+ ) + dropMovedWarnings(
78658
+ session.shutdownStepWarnings,
78659
+ appended === "shutdown" ? shutdown2.slice(0, -1) : shutdown2,
78660
+ before.shutdown ?? []
78661
+ );
78662
+ }
78663
+ async function appendStepToFlow(session, step, block = "steps") {
78649
78664
  return withFlowLock(session.key, async () => {
78650
78665
  assertSessionStillLive(session, step);
78651
78666
  session.lastTouchedSeq = touch();
78652
78667
  if (session.persist === "host") {
78653
- const before = session.flow.steps;
78654
- const flowFile = await appendStep(session.filePath, step);
78655
- session.flow = parseFlow(flowFile);
78656
- session.discardedWarnings = (session.discardedWarnings ?? 0) + dropMovedWarnings(session.stepWarnings, session.flow.steps.slice(0, -1), before);
78657
- return { savedTo: session.filePath, stepCount: session.flow.steps.length };
78668
+ adoptRecordedFile(session, parseFlow(await appendStep(session.filePath, step, block)), block);
78669
+ return { savedTo: session.filePath, stepCount: recordedCount(session.flow, block) };
78658
78670
  }
78659
- session.flow.steps.push(step);
78671
+ const list = block === "shutdown" ? session.flow.shutdown ??= [] : session.flow.steps;
78672
+ list.push(step);
78660
78673
  try {
78661
78674
  validateFlow(session.flow);
78662
78675
  const flowFile = serializeFlow(session.flow);
78663
78676
  return {
78664
78677
  savedTo: clientFileDirective(session.filePath, flowFile),
78665
- stepCount: session.flow.steps.length
78678
+ stepCount: list.length
78666
78679
  };
78667
78680
  } catch (err) {
78668
- session.flow.steps.pop();
78681
+ list.pop();
78682
+ if (session.flow.shutdown?.length === 0) delete session.flow.shutdown;
78669
78683
  throw err;
78670
78684
  }
78671
78685
  });
78672
78686
  }
78687
+ var REMOVED_OUTPUT_KEY = /* @__PURE__ */ Symbol("removed");
78688
+ function recordingOutput(session, block) {
78689
+ const doc = session.output ?? {};
78690
+ if (block !== "shutdown" || !session.shutdownChanges) return doc;
78691
+ const merged = { ...doc };
78692
+ for (const [key2, value] of session.shutdownChanges) {
78693
+ if (value === REMOVED_OUTPUT_KEY) delete merged[key2];
78694
+ else merged[key2] = value;
78695
+ }
78696
+ return merged;
78697
+ }
78698
+ function keepRecordingOutput(session, block, doc, ranAgainst) {
78699
+ if (block === "steps") {
78700
+ session.output = doc;
78701
+ return;
78702
+ }
78703
+ const changes = session.shutdownChanges ??= /* @__PURE__ */ new Map();
78704
+ for (const key2 of Object.keys(ranAgainst)) {
78705
+ if (!Object.hasOwn(doc, key2)) changes.set(key2, REMOVED_OUTPUT_KEY);
78706
+ }
78707
+ for (const [key2, value] of Object.entries(doc)) {
78708
+ if (!Object.hasOwn(ranAgainst, key2) || !(0, import_node_util6.isDeepStrictEqual)(ranAgainst[key2], value)) {
78709
+ changes.set(key2, value);
78710
+ }
78711
+ }
78712
+ }
78713
+ async function runDeferredShutdown(session, ctx) {
78714
+ const queued = session.deferredShutdown;
78715
+ if (!queued?.length) return void 0;
78716
+ delete session.deferredShutdown;
78717
+ const ranAgainst = recordingOutput(session, "shutdown");
78718
+ const output2 = { doc: structuredClone(ranAgainst) };
78719
+ const steps = [];
78720
+ const kept = [];
78721
+ let thrown;
78722
+ for (const run2 of [...queued].reverse()) {
78723
+ if (!ctx?.signal?.aborted) {
78724
+ try {
78725
+ await run2(ctx, output2, steps);
78726
+ } catch (error63) {
78727
+ thrown ??= { error: error63 };
78728
+ }
78729
+ }
78730
+ if (ctx?.signal?.aborted) kept.unshift(run2);
78731
+ }
78732
+ if (kept.length > 0) session.deferredShutdown = [...kept, ...session.deferredShutdown ?? []];
78733
+ keepRecordingOutput(session, "shutdown", output2.doc, ranAgainst);
78734
+ if (thrown) throw thrown.error;
78735
+ if (steps.length === 0) return void 0;
78736
+ const failed3 = steps.some((s) => {
78737
+ const status = s.status;
78738
+ return status === "fail" || status === "error";
78739
+ });
78740
+ return { ok: !failed3, steps };
78741
+ }
78742
+ function fragmentShutdownNote(report) {
78743
+ const total = report.steps.length;
78744
+ const count2 = (...statuses) => report.steps.filter((s) => statuses.includes(s.status ?? "")).length;
78745
+ const failed3 = count2("fail", "error");
78746
+ const skipped = count2("skip");
78747
+ return `Separately, the recording ran the kept shutdown: of the fragments recorded as run: steps, as a replay does before the shutdown steps (${total} ${total === 1 ? "step" : "steps"}` + (failed3 === 0 ? "" : `, ${failed3} failed; see fragmentShutdown`) + (skipped === 0 ? "" : `, ${skipped} skipped as cancelled, which a later shutdown call or the finish runs again`) + `).`;
78748
+ }
78749
+ async function afterDeferredShutdown(session, ctx, call) {
78750
+ const report = await runDeferredShutdown(session, ctx);
78751
+ if (!report) return call();
78752
+ const note = fragmentShutdownNote(report);
78753
+ let result;
78754
+ try {
78755
+ result = await call();
78756
+ } catch (err) {
78757
+ if (err instanceof Error) err.message = `${err.message} ${note}`;
78758
+ throw err;
78759
+ }
78760
+ const lead = /[.!?]$/.test(result.message) ? result.message : `${result.message}.`;
78761
+ return { ...result, message: `${lead} ${note}`, fragmentShutdown: report };
78762
+ }
78763
+ function deferredShutdownFirst(tool) {
78764
+ const record2 = tool.execute.bind(tool);
78765
+ return {
78766
+ ...tool,
78767
+ async execute(services, params, ctx) {
78768
+ if (!params.shutdown) return record2(services, params, ctx);
78769
+ const session = await requireRecordingSession(params.project_root, params.name);
78770
+ return afterDeferredShutdown(session, ctx, () => record2(services, params, ctx));
78771
+ }
78772
+ };
78773
+ }
78774
+ function recordedCount(flow, block) {
78775
+ return block === "shutdown" ? flow.shutdown?.length ?? 0 : flow.steps.length;
78776
+ }
78673
78777
 
78674
78778
  // ../tool-server/src/tools/system/update-argent.ts
78675
78779
  function resolveCliEntry() {
@@ -78899,9 +79003,9 @@ This reminder comes from Argent itself. It will not repeat for the next 30 minut
78899
79003
 
78900
79004
  // ../tool-server/src/utils/ios-device/team-detect.ts
78901
79005
  var import_node_child_process10 = require("node:child_process");
78902
- var import_node_util6 = require("node:util");
79006
+ var import_node_util7 = require("node:util");
78903
79007
  var import_node_crypto5 = require("node:crypto");
78904
- var execFileAsync6 = (0, import_node_util6.promisify)(import_node_child_process10.execFile);
79008
+ var execFileAsync6 = (0, import_node_util7.promisify)(import_node_child_process10.execFile);
78905
79009
  var SIGNING_CERT_COMMON_NAMES = ["Apple Development", "iPhone Developer"];
78906
79010
  var SECURITY_TIMEOUT_MS = 15e3;
78907
79011
  async function listCertificatePem(commonName) {
@@ -79056,7 +79160,7 @@ var fsAsync = __toESM(require("node:fs/promises"));
79056
79160
  var os5 = __toESM(require("node:os"));
79057
79161
  var path18 = __toESM(require("node:path"));
79058
79162
  var import_node_child_process12 = require("node:child_process");
79059
- var import_node_util8 = require("node:util");
79163
+ var import_node_util9 = require("node:util");
79060
79164
 
79061
79165
  // ../tool-server/src/utils/simctl-config.ts
79062
79166
  var SIMCTL_SPAWN_TIMEOUT_MS = 1e4;
@@ -79065,11 +79169,11 @@ var SIMCTL_KILL_SIGNAL = "SIGKILL";
79065
79169
  // ../tool-server/src/utils/ios-device-sets.ts
79066
79170
  var fs18 = __toESM(require("node:fs"));
79067
79171
  var import_node_child_process11 = require("node:child_process");
79068
- var import_node_util7 = require("node:util");
79172
+ var import_node_util8 = require("node:util");
79069
79173
  init_src2();
79070
79174
  init_src();
79071
79175
  init_external_devices();
79072
- var execFileAsync7 = (0, import_node_util7.promisify)(import_node_child_process11.execFile);
79176
+ var execFileAsync7 = (0, import_node_util8.promisify)(import_node_child_process11.execFile);
79073
79177
  var deviceSetByUdid = /* @__PURE__ */ new Map();
79074
79178
  function configuredAdditionalDeviceSets() {
79075
79179
  try {
@@ -79424,7 +79528,7 @@ var PRE_BOOT_ACCESSIBILITY_KEYS = [
79424
79528
  "AccessibilityEnabled",
79425
79529
  "ApplicationAccessibilityEnabled"
79426
79530
  ];
79427
- var execFileAsync8 = (0, import_node_util8.promisify)(import_node_child_process12.execFile);
79531
+ var execFileAsync8 = (0, import_node_util9.promisify)(import_node_child_process12.execFile);
79428
79532
  async function accessibilityDefaults(udid, verb, ...args) {
79429
79533
  const { stdout } = await execFileAsync8(
79430
79534
  "xcrun",
@@ -79494,10 +79598,10 @@ async function setAccessibilityPrefsPreBoot(udid, { isTvOs }) {
79494
79598
  var fs19 = __toESM(require("node:fs"));
79495
79599
  var path19 = __toESM(require("node:path"));
79496
79600
  var import_node_child_process13 = require("node:child_process");
79497
- var import_node_util9 = require("node:util");
79601
+ var import_node_util10 = require("node:util");
79498
79602
  init_external_devices();
79499
79603
  init_device_info();
79500
- var execFileAsync9 = (0, import_node_util9.promisify)(import_node_child_process13.execFile);
79604
+ var execFileAsync9 = (0, import_node_util10.promisify)(import_node_child_process13.execFile);
79501
79605
  var SIMCTL_LIST_TIMEOUT_MS = 1e4;
79502
79606
  function simctlListTimeoutAdvice(retry) {
79503
79607
  return `\`xcrun simctl list\` did not answer within ${SIMCTL_LIST_TIMEOUT_MS / 1e3}s. CoreSimulatorService is probably still starting, which can take about a minute after a reboot, so call ${retry} again shortly. If it keeps timing out and Xcode was just updated, ask the user to ${xcodeInstallInstruction()}; otherwise restart CoreSimulatorService.`;
@@ -97688,9 +97792,9 @@ function installNodeWebTransport() {
97688
97792
 
97689
97793
  // ../tool-server/src/utils/sim-remote.ts
97690
97794
  var import_node_child_process14 = require("node:child_process");
97691
- var import_node_util10 = require("node:util");
97795
+ var import_node_util11 = require("node:util");
97692
97796
  init_device_info();
97693
- var execFileAsync10 = (0, import_node_util10.promisify)(import_node_child_process14.execFile);
97797
+ var execFileAsync10 = (0, import_node_util11.promisify)(import_node_child_process14.execFile);
97694
97798
  var SIM_REMOTE_TIMEOUT_MS = 3e4;
97695
97799
  function simRemoteExecError(err) {
97696
97800
  return err.cause ?? err;
@@ -98202,9 +98306,9 @@ function captureOnDemandDropped(deviceId, endpoint) {
98202
98306
  // ../tool-server/src/utils/foldable.ts
98203
98307
  var import_node_child_process15 = require("node:child_process");
98204
98308
  var fs20 = __toESM(require("node:fs"));
98205
- var import_node_util11 = require("node:util");
98309
+ var import_node_util12 = require("node:util");
98206
98310
  init_external_devices();
98207
- var execFileAsync11 = (0, import_node_util11.promisify)(import_node_child_process15.execFile);
98311
+ var execFileAsync11 = (0, import_node_util12.promisify)(import_node_child_process15.execFile);
98208
98312
  var MAIN_SCREEN_ID = 1;
98209
98313
  var AX_LIVE_PANEL_TIMEOUT_MS = 2e3;
98210
98314
  var DEVICECTL_TIMEOUT_MS = 5e3;
@@ -99503,7 +99607,7 @@ var import_node_child_process16 = require("node:child_process");
99503
99607
  var import_node_events = require("node:events");
99504
99608
  var fs24 = __toESM(require("node:fs"));
99505
99609
  var path22 = __toESM(require("node:path"));
99506
- var import_node_util12 = require("node:util");
99610
+ var import_node_util13 = require("node:util");
99507
99611
  init_src();
99508
99612
 
99509
99613
  // ../tool-server/src/utils/ios-audio-leftovers.ts
@@ -99790,7 +99894,7 @@ async function clearAudioLeftovers(dir) {
99790
99894
  }
99791
99895
 
99792
99896
  // ../tool-server/src/utils/ios-host.ts
99793
- var execFileAsync12 = (0, import_node_util12.promisify)(import_node_child_process16.execFile);
99897
+ var execFileAsync12 = (0, import_node_util13.promisify)(import_node_child_process16.execFile);
99794
99898
  var ARGENT_BOOTSTRAP_DYLIB_BASENAMES = /* @__PURE__ */ new Set(["libArgentInjectionBootstrap.dylib"]);
99795
99899
  var RECOGNISED_BOOTSTRAP_DYLIB_BASENAMES = /* @__PURE__ */ new Set([
99796
99900
  ...ARGENT_BOOTSTRAP_DYLIB_BASENAMES,
@@ -102444,10 +102548,10 @@ function classifyDeviceForTelemetry(deviceId) {
102444
102548
 
102445
102549
  // ../tool-server/src/utils/device-shutdown.ts
102446
102550
  var import_node_child_process20 = require("node:child_process");
102447
- var import_node_util14 = require("node:util");
102551
+ var import_node_util15 = require("node:util");
102448
102552
  init_device_info();
102449
102553
  init_android_binary();
102450
- var execFileAsync14 = (0, import_node_util14.promisify)(import_node_child_process20.execFile);
102554
+ var execFileAsync14 = (0, import_node_util15.promisify)(import_node_child_process20.execFile);
102451
102555
  var SHUTDOWN_EXEC_OPTIONS = { timeout: 3e4, killSignal: "SIGKILL" };
102452
102556
  async function shutdownOwnedDevice(id) {
102453
102557
  let platform;
@@ -102598,14 +102702,14 @@ function adbCommandPrefix(env) {
102598
102702
 
102599
102703
  // ../tool-server/src/utils/ios-device/devicectl.ts
102600
102704
  var import_node_child_process21 = require("node:child_process");
102601
- var import_node_util15 = require("node:util");
102705
+ var import_node_util16 = require("node:util");
102602
102706
  var fs27 = __toESM(require("node:fs/promises"));
102603
102707
  var os8 = __toESM(require("node:os"));
102604
102708
  var path24 = __toESM(require("node:path"));
102605
102709
  var import_node_crypto8 = require("node:crypto");
102606
102710
  var import_node_net = require("node:net");
102607
102711
  init_src2();
102608
- var execFileAsync15 = (0, import_node_util15.promisify)(import_node_child_process21.execFile);
102712
+ var execFileAsync15 = (0, import_node_util16.promisify)(import_node_child_process21.execFile);
102609
102713
  var DEVICECTL_TIMEOUT_MS2 = 2e4;
102610
102714
  var DEVICECTL_INSTALL_TIMEOUT_MS = 12e4;
102611
102715
  var DEVICECTL_LIST_TIMEOUT_MS = 8e3;
@@ -102938,13 +103042,13 @@ var import_node_crypto9 = require("node:crypto");
102938
103042
  var fs28 = __toESM(require("node:fs"));
102939
103043
  var os9 = __toESM(require("node:os"));
102940
103044
  var path25 = __toESM(require("node:path"));
102941
- var import_node_util16 = require("node:util");
103045
+ var import_node_util17 = require("node:util");
102942
103046
  init_src();
102943
103047
  init_src2();
102944
103048
  init_capability();
102945
103049
  init_device_info();
102946
103050
  init_macos_app_kind();
102947
- var execFileAsync16 = (0, import_node_util16.promisify)(import_node_child_process22.execFile);
103051
+ var execFileAsync16 = (0, import_node_util17.promisify)(import_node_child_process22.execFile);
102948
103052
  function isMacosAppsEnabled() {
102949
103053
  return isFeatureEnabled(MACOS_APPS_FLAG);
102950
103054
  }
@@ -105833,8 +105937,8 @@ async function resolveRunningVvdSerial() {
105833
105937
  // ../tool-server/src/tools/devices/list-devices.ts
105834
105938
  init_external_devices();
105835
105939
  var import_node_child_process23 = require("node:child_process");
105836
- var import_node_util17 = require("node:util");
105837
- var execFileAsync17 = (0, import_node_util17.promisify)(import_node_child_process23.execFile);
105940
+ var import_node_util18 = require("node:util");
105941
+ var execFileAsync17 = (0, import_node_util18.promisify)(import_node_child_process23.execFile);
105838
105942
  var ARGENT_CLOUD_URL = "https://argent.swmansion.com/cloud/";
105839
105943
  var ARGENT_CLOUD_OFFER = `Argent Cloud, a hosted service that is not set up here, runs iOS simulators on remote Macs; once the user sets it up with their API key and the sim-remote CLI, they are listed as platform 'ios-remote'. ` + ARGENT_CLOUD_URL;
105840
105944
  function iosReachNote(host, cloud) {
@@ -114680,7 +114784,7 @@ function reserveLaunchMeasurement(udid) {
114680
114784
 
114681
114785
  // ../tool-server/src/utils/ios-device/runner-artifact.ts
114682
114786
  var import_node_child_process28 = require("node:child_process");
114683
- var import_node_util19 = require("node:util");
114787
+ var import_node_util20 = require("node:util");
114684
114788
  var import_node_crypto10 = require("node:crypto");
114685
114789
  var fs37 = __toESM(require("node:fs"));
114686
114790
  var fsp = __toESM(require("node:fs/promises"));
@@ -114696,8 +114800,8 @@ var import_node_child_process27 = require("node:child_process");
114696
114800
  var import_node_fs12 = require("node:fs");
114697
114801
  var import_node_os9 = require("node:os");
114698
114802
  var path32 = __toESM(require("node:path"));
114699
- var import_node_util18 = require("node:util");
114700
- var execFileAsync18 = (0, import_node_util18.promisify)(import_node_child_process27.execFile);
114803
+ var import_node_util19 = require("node:util");
114804
+ var execFileAsync18 = (0, import_node_util19.promisify)(import_node_child_process27.execFile);
114701
114805
  var PROFILE_DIRECTORIES = [
114702
114806
  path32.join("Library", "Developer", "Xcode", "UserData", "Provisioning Profiles"),
114703
114807
  path32.join("Library", "MobileDevice", "Provisioning Profiles")
@@ -114806,7 +114910,7 @@ function resolveSigningHint(output2) {
114806
114910
  }
114807
114911
 
114808
114912
  // ../tool-server/src/utils/ios-device/runner-artifact.ts
114809
- var execFileAsync19 = (0, import_node_util19.promisify)(import_node_child_process28.execFile);
114913
+ var execFileAsync19 = (0, import_node_util20.promisify)(import_node_child_process28.execFile);
114810
114914
  var PROJECT_SUFFIX = "ios-device-runner/ArgentRunner/ArgentRunner.xcodeproj";
114811
114915
  function resolveRunnerProjectPath() {
114812
114916
  const override = process.env.ARGENT_IOS_RUNNER_PROJECT;
@@ -115080,9 +115184,9 @@ var fs38 = __toESM(require("node:fs"));
115080
115184
  var fsp2 = __toESM(require("node:fs/promises"));
115081
115185
  var os15 = __toESM(require("node:os"));
115082
115186
  var path34 = __toESM(require("node:path"));
115083
- var import_node_util20 = require("node:util");
115187
+ var import_node_util21 = require("node:util");
115084
115188
  init_src2();
115085
- var execFileAsync20 = (0, import_node_util20.promisify)(import_node_child_process29.execFile);
115189
+ var execFileAsync20 = (0, import_node_util21.promisify)(import_node_child_process29.execFile);
115086
115190
  function logsRoot() {
115087
115191
  return path34.join(os15.homedir(), ".argent", "ios-device-runner", "logs");
115088
115192
  }
@@ -115211,9 +115315,9 @@ function killRunnerProcess(child) {
115211
115315
 
115212
115316
  // ../tool-server/src/utils/ios-device/runner-sweep.ts
115213
115317
  var import_node_child_process30 = require("node:child_process");
115214
- var import_node_util21 = require("node:util");
115318
+ var import_node_util22 = require("node:util");
115215
115319
  var path35 = __toESM(require("node:path"));
115216
- var execFileAsync21 = (0, import_node_util21.promisify)(import_node_child_process30.execFile);
115320
+ var execFileAsync21 = (0, import_node_util22.promisify)(import_node_child_process30.execFile);
115217
115321
  var PROCESS_TABLE_MAX_BYTES = 16 * 1024 * 1024;
115218
115322
  var STALE_EXIT_TIMEOUT_MS = 5e3;
115219
115323
  var STALE_EXIT_POLL_INTERVAL_MS = 100;
@@ -115648,9 +115752,9 @@ function defaultSendViaUsbmux(udid, port, body, deadline) {
115648
115752
 
115649
115753
  // ../tool-server/src/utils/ios-device/runner-crash.ts
115650
115754
  var import_node_child_process31 = require("node:child_process");
115651
- var import_node_util22 = require("node:util");
115755
+ var import_node_util23 = require("node:util");
115652
115756
  var fs39 = __toESM(require("node:fs/promises"));
115653
- var execFileAsync22 = (0, import_node_util22.promisify)(import_node_child_process31.execFile);
115757
+ var execFileAsync22 = (0, import_node_util23.promisify)(import_node_child_process31.execFile);
115654
115758
  var XCRESULTTOOL_TIMEOUT_MS = 15e3;
115655
115759
  var XCRESULTTOOL_MAX_JSON_BYTES = 32 * 1024 * 1024;
115656
115760
  function extractCrashFailureText(summary) {
@@ -129664,9 +129768,9 @@ init_external_devices();
129664
129768
  // ../tool-server/src/utils/debugger/runtime-device.ts
129665
129769
  var import_node_crypto16 = require("node:crypto");
129666
129770
  var import_node_child_process33 = require("node:child_process");
129667
- var import_node_util23 = require("node:util");
129771
+ var import_node_util24 = require("node:util");
129668
129772
  init_adb();
129669
- var execFileAsync23 = (0, import_node_util23.promisify)(import_node_child_process33.execFile);
129773
+ var execFileAsync23 = (0, import_node_util24.promisify)(import_node_child_process33.execFile);
129670
129774
  var LOG_READ_TIMEOUT_MS = 5e3;
129671
129775
  var RETRY_DELAY_MS = 300;
129672
129776
  var OTHER_TRANSPORTS_GRACE_MS = 500;
@@ -132770,7 +132874,7 @@ var import_promises15 = require("node:fs/promises");
132770
132874
  var import_node_net4 = require("node:net");
132771
132875
  var import_node_os16 = require("node:os");
132772
132876
  var import_node_path20 = require("node:path");
132773
- var import_node_util26 = require("node:util");
132877
+ var import_node_util27 = require("node:util");
132774
132878
  init_zod();
132775
132879
  init_src();
132776
132880
  init_src2();
@@ -132836,8 +132940,8 @@ function readOnlyBootEntries() {
132836
132940
  var import_node_child_process34 = require("node:child_process");
132837
132941
  var import_node_fs17 = require("node:fs");
132838
132942
  var import_promises14 = require("node:fs/promises");
132839
- var import_node_util24 = require("node:util");
132840
- var execFileAsync24 = (0, import_node_util24.promisify)(import_node_child_process34.execFile);
132943
+ var import_node_util25 = require("node:util");
132944
+ var execFileAsync24 = (0, import_node_util25.promisify)(import_node_child_process34.execFile);
132841
132945
  var EMULATOR_PROCESS_RE = /(?:^|\/)(?:qemu-system-[\w-]+|emulator|emulator64-[\w-]+)\s/;
132842
132946
  function escapeRegExp(value) {
132843
132947
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -133072,8 +133176,8 @@ var import_node_child_process35 = require("node:child_process");
133072
133176
  var import_node_fs18 = __toESM(require("node:fs"));
133073
133177
  var import_node_os15 = __toESM(require("node:os"));
133074
133178
  var import_node_path19 = __toESM(require("node:path"));
133075
- var import_node_util25 = require("node:util");
133076
- var execFileAsync25 = (0, import_node_util25.promisify)(import_node_child_process35.execFile);
133179
+ var import_node_util26 = require("node:util");
133180
+ var execFileAsync25 = (0, import_node_util26.promisify)(import_node_child_process35.execFile);
133077
133181
  var CORE_SIMULATOR_INFO_PLIST = "/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Versions/A/Resources/Info.plist";
133078
133182
  var LAUNCH_WATCH_MS = 1e4;
133079
133183
  var LAUNCH_POLL_MS = 250;
@@ -133542,7 +133646,7 @@ async function bootMacosApp(registry2, opts) {
133542
133646
  }
133543
133647
 
133544
133648
  // ../tool-server/src/tools/devices/boot-device.ts
133545
- var execFileAsync26 = (0, import_node_util26.promisify)(import_node_child_process37.execFile);
133649
+ var execFileAsync26 = (0, import_node_util27.promisify)(import_node_child_process37.execFile);
133546
133650
  function bootTarget(params) {
133547
133651
  return params.udid ?? params.avdName ?? params.vvdImage ?? params.harmonyInstance ?? params.electronAppPath ?? params.macosAppPath ?? "device";
133548
133652
  }
@@ -135380,7 +135484,7 @@ function dispatchByPlatform(opts) {
135380
135484
 
135381
135485
  // ../tool-server/src/tools/launch-app/platforms/ios.ts
135382
135486
  var import_node_child_process38 = require("node:child_process");
135383
- var import_node_util27 = require("node:util");
135487
+ var import_node_util28 = require("node:util");
135384
135488
  init_src2();
135385
135489
  init_external_devices();
135386
135490
 
@@ -135414,7 +135518,7 @@ async function awaitIosAppInFront(registry2, device, bundleId, signal) {
135414
135518
  }
135415
135519
 
135416
135520
  // ../tool-server/src/tools/launch-app/platforms/ios.ts
135417
- var execFileAsync27 = (0, import_node_util27.promisify)(import_node_child_process38.execFile);
135521
+ var execFileAsync27 = (0, import_node_util28.promisify)(import_node_child_process38.execFile);
135418
135522
  function makeIosImpl(registry2) {
135419
135523
  return {
135420
135524
  requires: ["xcrun"],
@@ -135965,10 +136069,10 @@ init_device_info();
135965
136069
 
135966
136070
  // ../tool-server/src/tools/restart-app/platforms/ios.ts
135967
136071
  var import_node_child_process39 = require("node:child_process");
135968
- var import_node_util28 = require("node:util");
136072
+ var import_node_util29 = require("node:util");
135969
136073
  init_src2();
135970
136074
  init_external_devices();
135971
- var execFileAsync28 = (0, import_node_util28.promisify)(import_node_child_process39.execFile);
136075
+ var execFileAsync28 = (0, import_node_util29.promisify)(import_node_child_process39.execFile);
135972
136076
  function makeIosImpl2(registry2) {
135973
136077
  return {
135974
136078
  requires: ["xcrun"],
@@ -136256,11 +136360,11 @@ For Mac apps, kind is 'catalyst' or 'app'. Check appPath and args to confirm the
136256
136360
 
136257
136361
  // ../tool-server/src/tools/terminate-app/index.ts
136258
136362
  var import_node_child_process40 = require("node:child_process");
136259
- var import_node_util29 = require("node:util");
136363
+ var import_node_util30 = require("node:util");
136260
136364
  init_zod();
136261
136365
  init_src2();
136262
136366
  init_adb();
136263
- var execFileAsync29 = (0, import_node_util29.promisify)(import_node_child_process40.execFile);
136367
+ var execFileAsync29 = (0, import_node_util30.promisify)(import_node_child_process40.execFile);
136264
136368
  var capability5 = {
136265
136369
  apple: { simulator: true },
136266
136370
  appleRemote: { simulator: true },
@@ -136350,7 +136454,7 @@ init_zod();
136350
136454
 
136351
136455
  // ../tool-server/src/tools/reinstall-app/platforms/ios.ts
136352
136456
  var import_node_child_process42 = require("node:child_process");
136353
- var import_node_util31 = require("node:util");
136457
+ var import_node_util32 = require("node:util");
136354
136458
  var import_node_path22 = require("node:path");
136355
136459
  init_src2();
136356
136460
 
@@ -136358,7 +136462,7 @@ init_src2();
136358
136462
  var import_node_child_process41 = require("node:child_process");
136359
136463
  var import_promises17 = require("node:fs/promises");
136360
136464
  var import_node_path21 = require("node:path");
136361
- var import_node_util30 = require("node:util");
136465
+ var import_node_util31 = require("node:util");
136362
136466
  init_capability();
136363
136467
 
136364
136468
  // ../tool-server/src/utils/apk-package.ts
@@ -136457,7 +136561,7 @@ function readStringPool(xml, chunk) {
136457
136561
  }
136458
136562
 
136459
136563
  // ../tool-server/src/tools/reinstall-app/validate-app.ts
136460
- var execFileAsync30 = (0, import_node_util30.promisify)(import_node_child_process41.execFile);
136564
+ var execFileAsync30 = (0, import_node_util31.promisify)(import_node_child_process41.execFile);
136461
136565
  async function requirePath(absolute, kind, what) {
136462
136566
  const info = await (0, import_promises17.stat)(absolute).catch(() => null);
136463
136567
  if (!info) {
@@ -136534,7 +136638,7 @@ async function assertHap(absolute, bundleName) {
136534
136638
  }
136535
136639
 
136536
136640
  // ../tool-server/src/tools/reinstall-app/platforms/ios.ts
136537
- var execFileAsync31 = (0, import_node_util31.promisify)(import_node_child_process42.execFile);
136641
+ var execFileAsync31 = (0, import_node_util32.promisify)(import_node_child_process42.execFile);
136538
136642
  var iosImpl = {
136539
136643
  requires: ["xcrun"],
136540
136644
  handler: async (_services, params) => {
@@ -136832,10 +136936,10 @@ var PERMISSION_NAMES = [
136832
136936
 
136833
136937
  // ../tool-server/src/tools/settings-permissions/platforms/ios.ts
136834
136938
  var import_node_child_process43 = require("node:child_process");
136835
- var import_node_util32 = require("node:util");
136939
+ var import_node_util33 = require("node:util");
136836
136940
  init_src2();
136837
136941
  init_capability();
136838
- var execFileAsync32 = (0, import_node_util32.promisify)(import_node_child_process43.execFile);
136942
+ var execFileAsync32 = (0, import_node_util33.promisify)(import_node_child_process43.execFile);
136839
136943
  var SIMCTL_ACTION = {
136840
136944
  grant: "grant",
136841
136945
  deny: "revoke",
@@ -137153,7 +137257,7 @@ init_device_info();
137153
137257
 
137154
137258
  // ../tool-server/src/tools/open-url/platforms/ios.ts
137155
137259
  var import_node_child_process44 = require("node:child_process");
137156
- var import_node_util33 = require("node:util");
137260
+ var import_node_util34 = require("node:util");
137157
137261
  init_src2();
137158
137262
 
137159
137263
  // ../tool-server/src/tools/open-url/deep-link-note.ts
@@ -137163,7 +137267,7 @@ function httpDeepLinkNote(url2) {
137163
137267
  }
137164
137268
 
137165
137269
  // ../tool-server/src/tools/open-url/platforms/ios.ts
137166
- var execFileAsync33 = (0, import_node_util33.promisify)(import_node_child_process44.execFile);
137270
+ var execFileAsync33 = (0, import_node_util34.promisify)(import_node_child_process44.execFile);
137167
137271
  var iosImpl3 = {
137168
137272
  requires: ["xcrun"],
137169
137273
  handler: async (_services, params) => {
@@ -137293,10 +137397,10 @@ var chromiumImpl2 = {
137293
137397
  // ../tool-server/src/tools/open-url/platforms/macos.ts
137294
137398
  var import_node_child_process45 = require("node:child_process");
137295
137399
  var path43 = __toESM(require("node:path"));
137296
- var import_node_util34 = require("node:util");
137400
+ var import_node_util35 = require("node:util");
137297
137401
  init_src2();
137298
137402
  init_capability();
137299
- var execFileAsync34 = (0, import_node_util34.promisify)(import_node_child_process45.execFile);
137403
+ var execFileAsync34 = (0, import_node_util35.promisify)(import_node_child_process45.execFile);
137300
137404
  var WEB_URL_NOTE = "The URL went to the app of the device, not to the default browser. The app shows it only if it handles that URL.";
137301
137405
  async function declaredSchemes(appPath) {
137302
137406
  try {
@@ -137434,7 +137538,7 @@ Returns { opened, url, note? }. \`note\` explains the routing caveat when a web
137434
137538
 
137435
137539
  // ../tool-server/src/tools/screenshot/index.ts
137436
137540
  var import_node_child_process46 = require("node:child_process");
137437
- var import_node_util35 = require("node:util");
137541
+ var import_node_util36 = require("node:util");
137438
137542
  var os20 = __toESM(require("node:os"));
137439
137543
  var path44 = __toESM(require("node:path"));
137440
137544
  init_zod();
@@ -137694,7 +137798,7 @@ async function captureHarmonyScreenshotPng(opts) {
137694
137798
  // ../tool-server/src/tools/screenshot/index.ts
137695
137799
  init_capability();
137696
137800
  var fs50 = __toESM(require("node:fs/promises"));
137697
- var execFileAsync35 = (0, import_node_util35.promisify)(import_node_child_process46.execFile);
137801
+ var execFileAsync35 = (0, import_node_util36.promisify)(import_node_child_process46.execFile);
137698
137802
  var capability9 = {
137699
137803
  apple: { simulator: true, device: true },
137700
137804
  appleRemote: { simulator: true },
@@ -140434,7 +140538,7 @@ var shakeZodSchema = external_exports.object({
140434
140538
 
140435
140539
  // ../tool-server/src/tools/shake/platforms/ios.ts
140436
140540
  var import_node_child_process48 = require("node:child_process");
140437
- var import_node_util36 = require("node:util");
140541
+ var import_node_util37 = require("node:util");
140438
140542
  init_src2();
140439
140543
  init_capability();
140440
140544
 
@@ -140639,7 +140743,7 @@ async function prepareHostWindowShake(target) {
140639
140743
  }
140640
140744
 
140641
140745
  // ../tool-server/src/tools/shake/platforms/ios.ts
140642
- var execFileAsync36 = (0, import_node_util36.promisify)(import_node_child_process48.execFile);
140746
+ var execFileAsync36 = (0, import_node_util37.promisify)(import_node_child_process48.execFile);
140643
140747
  var SHAKE_NOTIFICATION = "com.apple.UIKit.SimulatorShake";
140644
140748
  var SHAKE_INTERVAL_MS = 400;
140645
140749
  var sleep13 = (ms3) => new Promise((r) => setTimeout(r, ms3));
@@ -153581,7 +153685,7 @@ function inFlightGuardMessage(state3, retryAction) {
153581
153685
  // ../tool-server/src/tools/profiler/native-profiler/platforms/xctrace.ts
153582
153686
  var import_child_process5 = require("child_process");
153583
153687
  var import_node_fs21 = require("node:fs");
153584
- var import_node_util37 = require("node:util");
153688
+ var import_node_util38 = require("node:util");
153585
153689
  init_src2();
153586
153690
  var import_node_fs22 = require("node:fs");
153587
153691
  var path47 = __toESM(require("path"));
@@ -153942,7 +154046,7 @@ function commitXctraceRecording(api, started, capture) {
153942
154046
  traceFile: capture.traceFile
153943
154047
  };
153944
154048
  }
153945
- var execFileAsync37 = (0, import_node_util37.promisify)(import_child_process5.execFile);
154049
+ var execFileAsync37 = (0, import_node_util38.promisify)(import_child_process5.execFile);
153946
154050
  function xctraceProgressProbe(child, traceFile) {
153947
154051
  return async () => {
153948
154052
  if (!child.pid) return null;
@@ -156238,7 +156342,7 @@ init_zod();
156238
156342
 
156239
156343
  // ../tool-server/src/tools/profiler/native-profiler/launch-analysis/measure.ts
156240
156344
  var import_node_child_process50 = require("node:child_process");
156241
- var import_node_util39 = require("node:util");
156345
+ var import_node_util40 = require("node:util");
156242
156346
  var fsp5 = __toESM(require("node:fs/promises"));
156243
156347
  var path53 = __toESM(require("node:path"));
156244
156348
  var import_node_crypto19 = require("node:crypto");
@@ -156246,14 +156350,14 @@ init_src2();
156246
156350
 
156247
156351
  // ../tool-server/src/utils/ios-launch-time/workflow.ts
156248
156352
  var import_node_child_process49 = require("node:child_process");
156249
- var import_node_util38 = require("node:util");
156353
+ var import_node_util39 = require("node:util");
156250
156354
  var import_promises20 = require("node:timers/promises");
156251
156355
  var fs64 = __toESM(require("node:fs"));
156252
156356
  var fsp4 = __toESM(require("node:fs/promises"));
156253
156357
  var path52 = __toESM(require("node:path"));
156254
156358
  init_src();
156255
156359
  init_src2();
156256
- var execFileAsync38 = (0, import_node_util38.promisify)(import_node_child_process49.execFile);
156360
+ var execFileAsync38 = (0, import_node_util39.promisify)(import_node_child_process49.execFile);
156257
156361
  var BUILD_TIMEOUT_MS2 = 60 * 6e4;
156258
156362
  var BOOTSTATUS_TIMEOUT_MS = 18e4;
156259
156363
  function runnerBuildCacheDir(key2) {
@@ -156792,7 +156896,7 @@ function optionalExportCrashNote(tables, xcodeVersion2, options = {}) {
156792
156896
  }
156793
156897
 
156794
156898
  // ../tool-server/src/tools/profiler/native-profiler/launch-analysis/measure.ts
156795
- var execFileAsync39 = (0, import_node_util39.promisify)(import_node_child_process50.execFile);
156899
+ var execFileAsync39 = (0, import_node_util40.promisify)(import_node_child_process50.execFile);
156796
156900
  var LAUNCH_ITERATIONS = 5;
156797
156901
  async function measureLaunch(params, ctx) {
156798
156902
  let release2;
@@ -156964,7 +157068,7 @@ async function measurePreparedLaunch(context2, ctx) {
156964
157068
  // ../tool-server/src/tools/profiler/native-profiler/launch-analysis/profile.ts
156965
157069
  var import_node_child_process51 = require("node:child_process");
156966
157070
  var import_node_crypto20 = require("node:crypto");
156967
- var import_node_util40 = require("node:util");
157071
+ var import_node_util41 = require("node:util");
156968
157072
  var fsp6 = __toESM(require("node:fs/promises"));
156969
157073
  var path54 = __toESM(require("node:path"));
156970
157074
  init_src2();
@@ -157206,7 +157310,7 @@ function cpuTableXpath(tocXml) {
157206
157310
  }
157207
157311
 
157208
157312
  // ../tool-server/src/tools/profiler/native-profiler/launch-analysis/profile.ts
157209
- var execFileAsync40 = (0, import_node_util40.promisify)(import_node_child_process51.execFile);
157313
+ var execFileAsync40 = (0, import_node_util41.promisify)(import_node_child_process51.execFile);
157210
157314
  var TABLE_XPATH = (schema) => `/trace-toc/run[@number="1"]/data/table[@schema="${schema}"]`;
157211
157315
  async function writeProfilerSession(xml) {
157212
157316
  const debugDir = await getDebugDir();
@@ -157552,11 +157656,11 @@ var import_node_child_process52 = require("node:child_process");
157552
157656
  var fs65 = __toESM(require("node:fs"));
157553
157657
  var path55 = __toESM(require("node:path"));
157554
157658
  var import_node_crypto21 = require("node:crypto");
157555
- var import_node_util41 = require("node:util");
157659
+ var import_node_util42 = require("node:util");
157556
157660
  init_src2();
157557
157661
  init_capability();
157558
157662
  init_external_devices();
157559
- var execFileAsync41 = (0, import_node_util41.promisify)(import_node_child_process52.execFile);
157663
+ var execFileAsync41 = (0, import_node_util42.promisify)(import_node_child_process52.execFile);
157560
157664
  var AUDIO_DIR_ENV = "ARGENT_AUDIO_DIR";
157561
157665
  var AUDIO_HOOK_PROTO = 1;
157562
157666
  var MAX_CLIP_SECONDS = 600;
@@ -164442,7 +164546,7 @@ var zodSchema70 = external_exports.object({
164442
164546
  });
164443
164547
  var flowStartRecordingTool = {
164444
164548
  id: "e2e-start-recording",
164445
- description: `Start recording a new e2e test, resetting .argent/e2e/<name>.yaml to an empty e2e test and replacing any existing one.
164549
+ description: `Start recording a new e2e test, resetting .argent/e2e/<name>.yaml to an empty e2e test and replacing any existing one. A restart runs pending fragment cleanup from the discarded recording and reports it in \`fragmentShutdown\`.
164446
164550
  Use when you want to capture a reusable sequence of device interactions for later replay. Load the argent-create-e2e skill first: it holds the polish, audit and replay steps. Not for Apple TV or Android TV.
164447
164551
  Returns { message, e2eTestFile, savedTo } and optionally { restarted, discardedSteps } if a live recording of the same e2e test was discarded.
164448
164552
  Without a link, it creates that file and fails if the .argent/e2e/ directory cannot be created or the file cannot be written. Over a link (argent link or ARGENT_TOOLS_URL, also to 127.0.0.1), your client writes the file, and \`savedTo\` is its path on your computer, or null when that write failed.
@@ -164481,6 +164585,8 @@ and without a link, an edit that renumbers the steps drops their warnings.`,
164481
164585
  failedMsg: ({ params, failureSignal: failureSignal2 }) => `Failed to start recording of e2e test ${params.name}: ${failureSignal2.error_code}`
164482
164586
  },
164483
164587
  fileInputs: fileInputs3,
164588
+ // A restart may run the discarded take's fragment shutdown, on the device.
164589
+ longRunning: true,
164484
164590
  services: () => ({}),
164485
164591
  async execute(_services, params, ctx) {
164486
164592
  if (params.env) {
@@ -164504,7 +164610,7 @@ and without a link, an edit that renumbers the steps drops their warnings.`,
164504
164610
  params.name,
164505
164611
  async () => {
164506
164612
  const replaced2 = await getRecordingSession(params.project_root, params.name) ?? null;
164507
- const discardedSteps2 = replaced2 === null ? void 0 : replaced2.persist === "host" ? await countStepsOnDisk(replaced2.filePath) : replaced2.flow.steps.length;
164613
+ const discardedSteps2 = replaced2 === null ? void 0 : replaced2.persist === "host" ? await countStepsOnDisk(replaced2.filePath, "both") : replaced2.flow.steps.length + (replaced2.flow.shutdown?.length ?? 0);
164508
164614
  let savedTo2;
164509
164615
  if (persist2 === "host") {
164510
164616
  await writeNewFlowFile(filePath, flowFile);
@@ -164523,11 +164629,13 @@ and without a link, an edit that renumbers the steps drops their warnings.`,
164523
164629
  }
164524
164630
  );
164525
164631
  if (replaced) {
164632
+ const fragmentShutdown = await runDeferredShutdown(replaced, ctx);
164526
164633
  const reset = persist2 === "host" ? `${filePath} reset to an empty e2e test.` : `${filePath} is reset to an empty e2e test once your client applies \`savedTo\` (a null \`savedTo\` means it did not).`;
164527
164634
  const lost = discardedSteps === void 0 ? "the previous take" : `the previous take (${discardedSteps} step${discardedSteps === 1 ? "" : "s"})`;
164528
164635
  return {
164529
- message: `Restarted recording "${params.name}" \u2014 ${lost} was discarded and ` + reset,
164636
+ message: `Restarted recording "${params.name}" \u2014 ${lost} was discarded and ` + reset + (fragmentShutdown ? ` ${fragmentShutdownNote(fragmentShutdown)}` : ""),
164530
164637
  restarted: true,
164638
+ ...fragmentShutdown ? { fragmentShutdown } : {},
164531
164639
  ...discardedSteps === void 0 ? {} : { discardedSteps },
164532
164640
  e2eTestFile: flowFile,
164533
164641
  flowFile,
@@ -167292,6 +167400,9 @@ function summarizeStep(step, n) {
167292
167400
  function summarizeSteps(flow) {
167293
167401
  return flow.steps.map((step, i) => summarizeStep(step, i + 1));
167294
167402
  }
167403
+ function summarizeShutdownStep(step, n) {
167404
+ return `shutdown ${summarizeStep(step, n)}`;
167405
+ }
167295
167406
  function stepAnchor(step) {
167296
167407
  return summarizeStep(step, 0);
167297
167408
  }
@@ -167305,9 +167416,10 @@ var REPLAY_TREE_SOURCES = {
167305
167416
  android: "android-devtools",
167306
167417
  macos: "macos-devtools"
167307
167418
  };
167308
- function recordedLaunchedApp(session, platform) {
167309
- for (let i = session.flow.steps.length - 1; i >= 0; i--) {
167310
- const step = session.flow.steps[i];
167419
+ function recordedLaunchedApp(session, platform, block) {
167420
+ const steps = block === "shutdown" ? [...session.flow.steps, ...session.flow.shutdown ?? []] : session.flow.steps;
167421
+ for (let i = steps.length - 1; i >= 0; i--) {
167422
+ const step = steps[i];
167311
167423
  if (step.kind === "launch") return appIdForPlatform(step.app, platform) ?? void 0;
167312
167424
  }
167313
167425
  return void 0;
@@ -167405,13 +167517,13 @@ function textTieClause(udid) {
167405
167517
  return ` Check FIRST whether the selector matches more than one element, because a \`text\` check reads only one of them \u2014 the first visible match in reading order \u2014 and the two sides can elect DIFFERENT ones from the very same nodes: an exact frame tie is settled by which node its tree listed first, ${order}. The reason above quotes whichever element the RUNNER elected, so compare it against the one you meant. If that is what happened, both trees hold both elements and neither the tree differences nor a changed screen below explains anything \u2014 narrow the selector until it resolves a single node, and note that a longer \`await:\` timeout cannot help, since the text it read is already final.`;
167406
167518
  }
167407
167519
  var SPELLING_CLAUSE = "Both of those are about the selector exactly as recorded, so convert it in the strict map spelling (`{ text: \u2026 }` / `{ id: \u2026 }`, a straight copy of the step's `selector:`): a bare-string conversion (`{ visible: Continue }`) re-parses as a LOOSE selector \u2014 identifier first, text only as a fallback \u2014 which is a different check this probe never made.";
167408
- var UNMET_WAIT_WARNING = "recorded, but the wait itself never held \u2014 `await-ui-element` reports an unmet condition by returning success:false instead of failing, so the step was written to the e2e test anyway. At replay an unmet wait FAILS the step and stops the run there, so re-record it once the condition can actually hold, and delete the failed step after `e2e-finish-recording` rather than mid-recording: over a link the in-memory copy is authoritative and the next append writes the step straight back, and without a link the recorder re-reads the file before each append, so an edit that renumbers the steps costs the finish the verdicts it would otherwise carry. The cross-tree re-probe was skipped: it asks whether a check that PASSED would survive conversion to `await:`/`assert:`, and this one did not pass";
167520
+ var unmetWaitWarning = (block) => `recorded, but the wait itself never held \u2014 \`await-ui-element\` reports an unmet condition by returning success:false instead of failing, so the step was written to the e2e test anyway. At replay an unmet wait FAILS the step and ${block === "shutdown" ? "the run" : "stops the run there"}, so re-record it once the condition can actually hold, and delete the failed step after \`e2e-finish-recording\` rather than mid-recording: over a link the in-memory copy is authoritative and the next append writes the step straight back, and without a link the recorder re-reads the file before each append, so an edit that renumbers the steps costs the finish the verdicts it would otherwise carry. The cross-tree re-probe was skipped: it asks whether a check that PASSED would survive conversion to \`await:\`/\`assert:\`, and this one did not pass`;
167409
167521
  var UNREADABLE_WAIT_WARNING = "recorded, but this wait reached its deadline without a trustworthy read of the UI tree, so the condition was never judged \u2014 `await-ui-element` returns success:false for that too, and the step was written to the e2e test anyway. Either no read in the window could be trusted, or the reads went dark before the end and what they saw no longer describes it. Whether the condition holds is UNKNOWN, not known-bad: `toolResult.note` names the tree-source error where a fetch threw, and describes what was seen where the tree was merely empty or degraded. Get that source back and re-record the step to find out. Do not delete the step on this warning alone. The cross-tree re-probe was skipped: it asks whether a check that PASSED would survive conversion to `await:`/`assert:`, and this one never got an answer";
167410
167522
  var CANCELLED_WAIT_WARNING = "recorded, but this wait was cancelled before its deadline, so the condition was never settled \u2014 `await-ui-element` reports a cancelled wait as success:false, and the step was written to the e2e test anyway. Whether it holds is UNKNOWN, not known-bad: re-record the step to find out. The cross-tree re-probe was skipped for the same reason";
167411
- function unmetWaitWarningFor(cause) {
167523
+ function unmetWaitWarningFor(cause, block) {
167412
167524
  if (cause === "unreadable") return UNREADABLE_WAIT_WARNING;
167413
167525
  if (cause === "cancelled") return CANCELLED_WAIT_WARNING;
167414
- return UNMET_WAIT_WARNING;
167526
+ return unmetWaitWarning(block);
167415
167527
  }
167416
167528
  var UNMET_NETWORK_WAIT_WARNING = "recorded, but the wait never held: `await-network-request` returned success:false, and at replay an unmet wait FAILS the step. `toolResult.nearMisses` lists the closest requests and the criteria each missed: fix the matcher, or record the action that sends the request, then record the wait again. Delete the failed step after `e2e-finish-recording`, not mid-recording";
167417
167529
  var UNREADABLE_NETWORK_WAIT_WARNING = "recorded, but no armed capture layer was read near the deadline, so the request was never judged and whether it is sent is UNKNOWN: `toolResult.layers` says why. Get the layer back (for example call network-capture-start again once the app's JavaScript has loaded) and record the wait again. Do not delete the step on this warning alone";
@@ -167526,10 +167638,10 @@ function innermostTreeReason(message) {
167526
167638
  function withoutTypedText(node2, { source }) {
167527
167639
  return source === "native-devtools" && node2.role === IOS_TEXT_INPUT_ROLE ? { ...node2, value: void 0 } : node2;
167528
167640
  }
167529
- async function captureTapSelector(registry2, session, udid, point) {
167641
+ async function captureTapSelector(registry2, session, udid, point, block) {
167530
167642
  try {
167531
167643
  const device = resolveDevice(udid);
167532
- const launched = recordedLaunchedApp(session, device.platform);
167644
+ const launched = recordedLaunchedApp(session, device.platform, block);
167533
167645
  const data = await fetchFlowTree(
167534
167646
  registry2,
167535
167647
  device,
@@ -167573,21 +167685,28 @@ async function captureTapSelector(registry2, session, udid, point) {
167573
167685
  };
167574
167686
  }
167575
167687
  }
167576
- async function activeFlowState(session) {
167688
+ async function activeFlowState(session, block) {
167577
167689
  if (session.persist === "host") {
167578
167690
  try {
167579
- session.flow = parseFlow(await fs80.readFile(session.filePath, "utf8"));
167691
+ adoptRecordedFile(session, parseFlow(await fs80.readFile(session.filePath, "utf8")));
167580
167692
  } catch (err) {
167581
167693
  return {
167582
- stepCount: session.flow.steps.length,
167694
+ stepCount: recordedCount(session.flow, block),
167583
167695
  note: `The persisted e2e test could not be read and parsed (${err instanceof Error ? err.message : String(err)}); the step count is from the last valid in-memory snapshot.`
167584
167696
  };
167585
167697
  }
167586
167698
  }
167587
- return { stepCount: session.flow.steps.length };
167699
+ return { stepCount: recordedCount(session.flow, block) };
167700
+ }
167701
+ function reportsShutdown(result) {
167702
+ const steps = result?.steps;
167703
+ return Array.isArray(steps) && steps.some((s) => {
167704
+ const step = s;
167705
+ return step?.shutdown === true && step.status !== "skip";
167706
+ });
167588
167707
  }
167589
- async function recordNothing(session, guidance) {
167590
- const { stepCount, note } = await activeFlowState(session);
167708
+ async function recordNothing(session, guidance, block) {
167709
+ const { stepCount, note } = await activeFlowState(session, block);
167591
167710
  return {
167592
167711
  message: `${guidance} Nothing was executed and no step was recorded.${note ? ` ${note}` : ""}`,
167593
167712
  toolResult: void 0,
@@ -167839,13 +167958,17 @@ var zodSchema71 = external_exports.object({
167839
167958
  args: external_exports.string().optional().describe(
167840
167959
  `Tool arguments as a JSON string, e.g. '{"udid": "ABC", "x": 0.5, "y": 0.3}'. Omit for tools with no arguments.`
167841
167960
  ),
167842
- delayMs: external_exports.number().int().min(0).optional().describe("Milliseconds to sleep before executing this step during replay.")
167961
+ delayMs: external_exports.number().int().min(0).optional().describe("Milliseconds to sleep before executing this step during replay."),
167962
+ shutdown: external_exports.boolean().optional().describe(
167963
+ "Save the call in the shutdown list. Pending fragment cleanup runs before the call. stepCount counts shutdown entries."
167964
+ )
167843
167965
  });
167844
167966
  function createFlowAddStepTool(registry2) {
167845
- return {
167967
+ return deferredShutdownFirst({
167846
167968
  id: "e2e-add-step",
167847
167969
  description: `Execute one MCP tool and record its step in the e2e test named by \`name\` + \`project_root\`. Use when recording and you want each action run and captured; the recording must already be open.
167848
167970
  A coordinate \`gesture-tap\` records as a portable \`tap\` selector step; \`restart-app\` as a \`launch\`. Use \`{{output:PATH}}\` in arguments to read prior script output. The tool resolves the values for the live call and saves the references in a \`tool:\` step.
167971
+ Use \`shutdown: true\` for cleanup actions such as logging out.
167849
167972
  Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status, says whether a step was appended. Fails with an error, recording nothing. Call recording tools, including \`e2e-add-script\`, directly.`,
167850
167973
  zodSchema: zodSchema71,
167851
167974
  aliases: ["flow-add-step"],
@@ -167866,16 +167989,17 @@ Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status,
167866
167989
  services: () => ({}),
167867
167990
  async execute(_services, params, ctx) {
167868
167991
  const session = await requireRecordingSession(params.project_root, params.name);
167992
+ const block = params.shutdown ? "shutdown" : "steps";
167869
167993
  const command = canonicalToolId(params.command);
167870
167994
  const nested = Object.hasOwn(NESTED_RECORDER_TOOLS, command) ? NESTED_RECORDER_TOOLS[command] : void 0;
167871
- if (nested) return recordNothing(session, nested);
167995
+ if (nested) return recordNothing(session, nested, block);
167872
167996
  let args;
167873
167997
  try {
167874
167998
  args = params.args ? JSON.parse(params.args) : {};
167875
167999
  } catch (err) {
167876
168000
  if (registry2.getTool(params.command) === void 0) {
167877
168001
  const hint = directiveCommandHint(params.command);
167878
- if (hint) return recordNothing(session, hint);
168002
+ if (hint) return recordNothing(session, hint, block);
167879
168003
  }
167880
168004
  throw err;
167881
168005
  }
@@ -167897,7 +168021,7 @@ Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status,
167897
168021
  if (problem)
167898
168022
  throw new InvalidToolInputError(`Nothing ran and no step was recorded: ${problem}`);
167899
168023
  try {
167900
- args = resolveStepOutputs(authored, session.output ?? {}).args;
168024
+ args = resolveStepOutputs(authored, recordingOutput(session, block)).args;
167901
168025
  } catch (err) {
167902
168026
  if (!(err instanceof OutputReferenceError)) throw err;
167903
168027
  throw new InvalidToolInputError(`Nothing ran and no step was recorded: ${err.message}`);
@@ -167915,13 +168039,32 @@ Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status,
167915
168039
  const isTap = !referencedArgs && command === "gesture-tap" && params.delayMs === void 0 && typeof args.udid === "string" && typeof args.x === "number" && typeof args.y === "number";
167916
168040
  let captured;
167917
168041
  if (isTap) {
167918
- captured = await captureTapSelector(registry2, session, args.udid, {
167919
- x: args.x,
167920
- y: args.y
167921
- });
168042
+ captured = await captureTapSelector(
168043
+ registry2,
168044
+ session,
168045
+ args.udid,
168046
+ { x: args.x, y: args.y },
168047
+ block
168048
+ );
167922
168049
  }
167923
168050
  const runTarget = command === RUN_TARGET_COMMAND && params.delayMs === void 0 && !referencedArgs ? await captureRunTarget(session, args, project) : void 0;
167924
- const sharedOutput = runTarget?.flow ? { doc: structuredClone(session.output ?? {}) } : void 0;
168051
+ const ranAgainst = recordingOutput(session, block);
168052
+ const sharedOutput = runTarget?.flow ? { doc: structuredClone(ranAgainst), deferShutdown: block === "steps" } : void 0;
168053
+ let queued = false;
168054
+ const runUnrecordedShutdown = async () => {
168055
+ const run2 = sharedOutput?.deferredShutdown;
168056
+ if (!run2) return "";
168057
+ delete sharedOutput.deferredShutdown;
168058
+ const at = session.deferredShutdown?.indexOf(run2) ?? -1;
168059
+ if (at >= 0) session.deferredShutdown.splice(at, 1);
168060
+ else if (queued) return "";
168061
+ const steps = [];
168062
+ await run2(ctx, { doc: sharedOutput.doc }, steps).catch(() => void 0);
168063
+ const ok = !steps.some(
168064
+ (s) => ["fail", "error"].includes(s.status ?? "")
168065
+ );
168066
+ return ` No step was recorded, so the shutdown: of the fragment ran now (${ok ? "it passed" : "a step failed"}), and the device is as it would be after a replay of it.`;
168067
+ };
167925
168068
  let prepared;
167926
168069
  let toolResult;
167927
168070
  try {
@@ -167942,7 +168085,7 @@ Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status,
167942
168085
  });
167943
168086
  } catch (err) {
167944
168087
  const hint = isToolNotFound(err, params.command) ? directiveCommandHint(params.command) : void 0;
167945
- if (hint) return recordNothing(session, hint);
168088
+ if (hint) return recordNothing(session, hint, block);
167946
168089
  const reframed = describeNestedParamError(
167947
168090
  registry2,
167948
168091
  err,
@@ -167967,8 +168110,9 @@ Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status,
167967
168110
  if (linked && command === RUN_TARGET_COMMAND) {
167968
168111
  const outcome = nestedOrchestratorOutcome(RUN_TARGET_COMMAND, toolResult);
167969
168112
  if (outcome) {
168113
+ const ranShutdown = await runUnrecordedShutdown();
167970
168114
  throw new FailureError(
167971
- outcome.status === "fail" ? `Cannot record this call: the nested e2e test did not pass (${outcome.reason}). A replay over the same link fails at the same step. No step was recorded. Fix the nested e2e test, then call e2e-add-step again.` : `Cannot record this call: the nested e2e test did not run (${outcome.reason}). No step was recorded.`,
168115
+ (outcome.status === "fail" ? `Cannot record this call: the nested e2e test did not pass (${outcome.reason}). A replay over the same link fails at the same step. No step was recorded. Fix the nested e2e test, then call e2e-add-step again.` : `Cannot record this call: the nested e2e test did not run (${outcome.reason}). No step was recorded.`) + ranShutdown,
167972
168116
  {
167973
168117
  error_code: FAILURE_CODES.FLOW_FILE_INVALID,
167974
168118
  failure_stage: "flow_add_step_nested_failed",
@@ -168005,7 +168149,7 @@ Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status,
168005
168149
  if (isUnmetWaitResult(command, toolResult)) {
168006
168150
  const cause = unmetWaitCause(command, toolResult);
168007
168151
  waitWarning = {
168008
- warning: command === AWAIT_NETWORK_REQUEST_TOOL_ID ? unmetNetworkWaitWarningFor(cause) : unmetWaitWarningFor(cause),
168152
+ warning: command === AWAIT_NETWORK_REQUEST_TOOL_ID ? unmetNetworkWaitWarningFor(cause) : unmetWaitWarningFor(cause, block),
168009
168153
  kind: "wait"
168010
168154
  };
168011
168155
  } else if (command === AWAIT_UI_ELEMENT_TOOL_ID) {
@@ -168078,13 +168222,21 @@ Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status,
168078
168222
  delayMs: params.delayMs
168079
168223
  };
168080
168224
  }
168225
+ if (step.kind === "run" && sharedOutput?.deferredShutdown) {
168226
+ (session.deferredShutdown ??= []).push(sharedOutput.deferredShutdown);
168227
+ queued = true;
168228
+ }
168081
168229
  let savedTo;
168082
168230
  let stepCount;
168083
168231
  try {
168084
- ({ savedTo, stepCount } = await appendStepToFlow(session, step));
168232
+ ({ savedTo, stepCount } = await appendStepToFlow(session, step, block));
168085
168233
  } catch (err) {
168086
- if (getFailureSignal(err)?.failure_stage !== "flow_output_reference") throw err;
168087
- const refused = err instanceof Error ? err.message : String(err);
168234
+ const ranShutdown = await runUnrecordedShutdown();
168235
+ if (getFailureSignal(err)?.failure_stage !== "flow_output_reference") {
168236
+ if (err instanceof Error) err.message += ranShutdown;
168237
+ throw err;
168238
+ }
168239
+ const refused = (err instanceof Error ? err.message : String(err)) + ranShutdown;
168088
168240
  throw wrapFailure(
168089
168241
  err,
168090
168242
  {
@@ -168096,24 +168248,31 @@ Returns { message, stepCount, recorded, savedTo }; \`recorded\`, not the status,
168096
168248
  `The \`${params.command}\` call ran, but an existing e2e test step failed validation. Fix the step named below. Check the call's changes before you retry. ${refused}`
168097
168249
  );
168098
168250
  }
168099
- if (step.kind === "run" && sharedOutput) session.output = sharedOutput.doc;
168251
+ if (step.kind === "run" && sharedOutput) {
168252
+ const { doc, shutdownDoc = doc } = sharedOutput;
168253
+ if (block === "shutdown") keepRecordingOutput(session, "shutdown", shutdownDoc, ranAgainst);
168254
+ else keepRecordingOutput(session, "steps", doc, ranAgainst);
168255
+ }
168100
168256
  if (waitWarning) {
168101
- (session.stepWarnings ??= /* @__PURE__ */ new Map()).set(stepCount, {
168257
+ const verdicts = block === "shutdown" ? "shutdownStepWarnings" : "stepWarnings";
168258
+ (session[verdicts] ??= /* @__PURE__ */ new Map()).set(stepCount, {
168102
168259
  ...waitWarning,
168103
168260
  step: stepAnchor(step)
168104
168261
  });
168105
168262
  }
168106
168263
  const baselineWrites = project instanceof ClientProjectAccess && ctx?.flowStack === void 0 ? project.baselineDirectives() : [];
168264
+ const ranShutdownNow = block === "steps" && step.kind === "run" && reportsShutdown(toolResult) ? `${step.flow} ran its shutdown: steps at the end of this call (its files came with the call, or it started its own chromium app); a replay runs them at the end of the e2e test` : void 0;
168265
+ const notes = [warning, ranShutdownNow].filter((n) => n !== void 0).join("; ");
168107
168266
  return {
168108
- message: `Step added to "${params.name}" e2e test${warning ? ` \u2014 ${warning}` : ""}`,
168267
+ message: `${params.shutdown ? "Shutdown step" : "Step"} added to "${params.name}" e2e test${notes ? ` \u2014 ${notes}` : ""}`,
168109
168268
  toolResult,
168110
168269
  stepCount,
168111
- recorded: summarizeStep(step, stepCount),
168270
+ recorded: (params.shutdown ? summarizeShutdownStep : summarizeStep)(step, stepCount),
168112
168271
  savedTo,
168113
168272
  ...baselineWrites.length > 0 ? { baselineWrites } : {}
168114
168273
  };
168115
168274
  }
168116
- };
168275
+ });
168117
168276
  }
168118
168277
 
168119
168278
  // ../tool-server/src/tools/flows/flow-insert-echo.ts
@@ -168123,12 +168282,13 @@ var zodSchema72 = external_exports.object({
168123
168282
  project_root: external_exports.string().describe(
168124
168283
  "Absolute path to the project root of the e2e test being recorded: the same value passed to e2e-start-recording."
168125
168284
  ),
168126
- message: external_exports.string().describe("Text the echo step prints")
168285
+ message: external_exports.string().describe("Text the echo step prints"),
168286
+ shutdown: external_exports.boolean().optional().describe("Save the message in the shutdown list. stepCount counts shutdown entries.")
168127
168287
  });
168128
168288
  var flowInsertEchoTool = {
168129
168289
  id: "e2e-add-echo",
168130
168290
  description: `Record an echo step in the e2e test named by \`name\` + \`project_root\`. Echo steps print a message when the e2e test is replayed, useful as labels between tool calls.
168131
- Use when you want to annotate a recorded e2e test with a human-readable label or checkpoint message.
168291
+ Use when you want to annotate a recorded e2e test with a human-readable label or checkpoint message; pass \`shutdown: true\` to label its shutdown steps.
168132
168292
  Returns { message, stepCount, savedTo }. Fails if that e2e test has no recording in progress.`,
168133
168293
  zodSchema: zodSchema72,
168134
168294
  fileInputs: PROJECT_ROOT_INPUT,
@@ -168142,12 +168302,13 @@ Returns { message, stepCount, savedTo }. Fails if that e2e test has no recording
168142
168302
  services: () => ({}),
168143
168303
  async execute(_services, params) {
168144
168304
  const session = await requireRecordingSession(params.project_root, params.name);
168145
- const { savedTo, stepCount } = await appendStepToFlow(session, {
168146
- kind: "echo",
168147
- message: params.message
168148
- });
168305
+ const { savedTo, stepCount } = await appendStepToFlow(
168306
+ session,
168307
+ { kind: "echo", message: params.message },
168308
+ params.shutdown ? "shutdown" : "steps"
168309
+ );
168149
168310
  return {
168150
- message: `Echo added to "${params.name}" e2e test`,
168311
+ message: `${params.shutdown ? "Shutdown echo" : "Echo"} added to "${params.name}" e2e test`,
168151
168312
  stepCount,
168152
168313
  savedTo
168153
168314
  };
@@ -168203,11 +168364,11 @@ init_src2();
168203
168364
  var fs81 = __toESM(require("node:fs/promises"));
168204
168365
  init_capability();
168205
168366
  var OUTPUT_RENDER_LIMIT_BYTES = 64 * 1024;
168206
- async function recordedStepCount(session) {
168207
- const onDisk = await countStepsOnDisk(session.filePath);
168367
+ async function recordedStepCount(session, block) {
168368
+ const onDisk = await countStepsOnDisk(session.filePath, block);
168208
168369
  if (onDisk !== void 0) return { stepCount: onDisk };
168209
168370
  return {
168210
- stepCount: session.flow.steps.length,
168371
+ stepCount: recordedCount(session.flow, block),
168211
168372
  note: `Could not verify stepCount from ${session.filePath}.`
168212
168373
  };
168213
168374
  }
@@ -168260,11 +168421,14 @@ var zodSchema74 = external_exports.object({
168260
168421
  timeout: external_exports.number().optional().describe("Time limit in milliseconds. The default is 30000 and the minimum is 100."),
168261
168422
  env: envRecordSchema(external_exports.string()).optional().describe(
168262
168423
  "Environment overrides for this script. Argent uses them immediately and saves them on the step. Values can include {{secret:NAME}} or {{output:PATH}}."
168424
+ ),
168425
+ shutdown: external_exports.boolean().optional().describe(
168426
+ "Save the script in the shutdown list. Pending fragment cleanup runs before the script. The script's output reaches only later shutdown steps. stepCount counts shutdown entries."
168263
168427
  )
168264
168428
  });
168265
- var flowAddScriptTool = {
168429
+ var flowAddScriptTool = deferredShutdownFirst({
168266
168430
  id: "e2e-add-script",
168267
- description: `Run a local JavaScript (.mjs, .js) or TypeScript (.mts, .ts) file and record it as a script step. Use when the user requests a local script in an active recording. Call it where the script must run. A successful script updates the shared output and returns it as \`outputJson\`. Later steps can read it with \`{{output:PATH}}\`. Returns \`status\`, \`reason\` and \`stepCount\`. A failed script is not recorded. Check \`reason\` and the affected state before retrying. Record without a link (argent link or ARGENT_TOOLS_URL).`,
168431
+ description: `Run a local JavaScript (.mjs, .js) or TypeScript (.mts, .ts) file and record it as a script step. Use when the user requests a local script in an active recording. Call it where the script must run. A successful script updates the shared output and returns it as \`outputJson\`. Later steps can read it with \`{{output:PATH}}\`. Use \`shutdown: true\` for cleanup scripts. Returns \`status\`, \`reason\` and \`stepCount\`. A failed script is not recorded. Check \`reason\` and the affected state before retrying. Record without a link (argent link or ARGENT_TOOLS_URL).`,
168268
168432
  zodSchema: zodSchema74,
168269
168433
  fileInputs: PROJECT_ROOT_INPUT,
168270
168434
  aliases: ["flow-add-script"],
@@ -168285,6 +168449,7 @@ var flowAddScriptTool = {
168285
168449
  services: () => ({}),
168286
168450
  async execute(_services, params, ctx) {
168287
168451
  const session = await requireRecordingSession(params.project_root, params.name);
168452
+ const block = params.shutdown ? "shutdown" : "steps";
168288
168453
  if (isLinkedRecorderCall(session, ctx)) {
168289
168454
  throw new FailureError(
168290
168455
  `Cannot add a script step to e2e test "${params.name}": the recording is over a link (argent link or ARGENT_TOOLS_URL), and an e2e test cannot run script steps over a link. Nothing ran and no step was recorded. To record a script step, record the e2e test on the computer that runs the tool-server, with no link and no ARGENT_TOOLS_URL.`,
@@ -168313,12 +168478,13 @@ var flowAddScriptTool = {
168313
168478
  };
168314
168479
  const flowDir = nodePath.dirname(await canonicalFlowPath(session.filePath));
168315
168480
  const env = mergeScriptEnv(await recordedFileEnv(session), step.env);
168481
+ const ranAgainst = recordingOutput(session, block);
168316
168482
  const { outcome, result, ran } = await runFlowScriptStep({
168317
168483
  flowDir,
168318
168484
  step,
168319
168485
  projectRoot: params.project_root,
168320
168486
  env,
168321
- output: session.output ?? {},
168487
+ output: ranAgainst,
168322
168488
  ...ctx?.clientSecrets ? { clientSecrets: ctx.clientSecrets } : {},
168323
168489
  ...ctx?.signal ? { signal: ctx.signal } : {}
168324
168490
  });
@@ -168337,10 +168503,10 @@ var flowAddScriptTool = {
168337
168503
  return {
168338
168504
  ...common,
168339
168505
  message: `Script "${step.path}" ${lead}; no step was recorded. ${lost} ${leftBehind} Use a new e2e test name because e2e-start-recording overwrites the existing file. stepCount is from the ended recording.`,
168340
- stepCount: session.flow.steps.length
168506
+ stepCount: recordedCount(session.flow, block)
168341
168507
  };
168342
168508
  }
168343
- const { stepCount: stepCount2, note } = await recordedStepCount(session);
168509
+ const { stepCount: stepCount2, note } = await recordedStepCount(session, block);
168344
168510
  return {
168345
168511
  ...common,
168346
168512
  message: `Script "${step.path}" ${lead}; no step was recorded. ${nextMove}` + (note ? ` ${note}` : ""),
@@ -168350,7 +168516,7 @@ var flowAddScriptTool = {
168350
168516
  let savedTo;
168351
168517
  let stepCount;
168352
168518
  try {
168353
- ({ savedTo, stepCount } = await appendStepToFlow(session, step));
168519
+ ({ savedTo, stepCount } = await appendStepToFlow(session, step, block));
168354
168520
  } catch (err) {
168355
168521
  const refusedAnEarlierStep = getFailureSignal(err)?.failure_stage === "flow_output_reference";
168356
168522
  throw wrapFailure(
@@ -168364,18 +168530,18 @@ var flowAddScriptTool = {
168364
168530
  `Script "${step.path}" passed, but the step was not recorded. ` + (refusedAnEarlierStep ? `Fix the existing step named below in ${session.filePath}. ` : "Check the script's changes before you retry. ") + `${err instanceof Error ? err.message : String(err)}`
168365
168531
  );
168366
168532
  }
168367
- if (result?.output) session.output = result.output;
168533
+ if (result?.output) keepRecordingOutput(session, block, result.output, ranAgainst);
168368
168534
  const rendered = result?.output ? renderOutput(result.output) : void 0;
168369
168535
  return {
168370
168536
  ...common,
168371
- message: `Added script step to "${params.name}" e2e test.`,
168537
+ message: `Added ${params.shutdown ? "shutdown " : ""}script step to "${params.name}" e2e test.`,
168372
168538
  ...rendered ?? {},
168373
168539
  stepCount,
168374
- recorded: summarizeStep(step, stepCount),
168540
+ recorded: (params.shutdown ? summarizeShutdownStep : summarizeStep)(step, stepCount),
168375
168541
  savedTo
168376
168542
  };
168377
168543
  }
168378
- };
168544
+ });
168379
168545
 
168380
168546
  // ../tool-server/src/tools/flows/flow-finish-recording.ts
168381
168547
  init_zod();
@@ -168389,7 +168555,7 @@ function attachStepWarnings(summary, warnings) {
168389
168555
  }
168390
168556
  function warningHeadline(warnings, discarded) {
168391
168557
  const counts = { conversion: 0, wait: 0 };
168392
- for (const { kind } of warnings.values()) counts[kind] += 1;
168558
+ for (const { kind } of warnings) counts[kind] += 1;
168393
168559
  const clauses = [];
168394
168560
  if (counts.conversion > 0) {
168395
168561
  clauses.push(
@@ -168407,12 +168573,11 @@ function warningHeadline(warnings, discarded) {
168407
168573
  const drop = `${discarded} ${one ? "warning" : "warnings"} raised during this recording ${one ? "is" : "are"} NOT in \`summary\`: a hand edit to the .yaml moved the ${one ? "step it judged" : "steps they judged"}, so which step ${one ? "it belongs" : "they belong"} to is no longer knowable \u2014 re-record ${one ? "that wait" : "those waits"} to see ${one ? "it" : "them"} again`;
168408
168574
  return carried === "" ? ` \u2014 ${drop}` : `${carried}. ${drop}`;
168409
168575
  }
168410
- function anchoredWarnings(session, steps) {
168576
+ function anchoredWarnings(recorded, warnings, steps) {
168411
168577
  const kept = /* @__PURE__ */ new Map();
168412
- const recorded = session.flow.steps;
168413
168578
  if (recorded.length !== steps.length) return kept;
168414
168579
  if (!steps.every((step, i) => stepAnchor(step) === stepAnchor(recorded[i]))) return kept;
168415
- for (const [n, verdict] of session.stepWarnings ?? []) {
168580
+ for (const [n, verdict] of warnings ?? []) {
168416
168581
  const step = steps[n - 1];
168417
168582
  if (step !== void 0 && stepAnchor(step) === verdict.step) kept.set(n, verdict);
168418
168583
  }
@@ -168426,12 +168591,14 @@ var zodSchema75 = external_exports.object({
168426
168591
  });
168427
168592
  var flowFinishRecordingTool = {
168428
168593
  id: "e2e-finish-recording",
168429
- description: `Finish recording the e2e test named by \`name\` + \`project_root\`, leaving recordings under any other key untouched. Returns { message, path, executionPrerequisite, steps, summary, e2eTestFile, savedTo } - a summary of all recorded steps plus the final YAML. Use when you have added all desired steps and want to finalize the e2e test file. Fails if that e2e test has no recording in progress.
168594
+ description: `Finish recording the e2e test named by \`name\` + \`project_root\`, leaving recordings under any other key untouched. Returns the final YAML and a step summary, including \`shutdownSteps\` when shutdown has entries. Runs any pending fragment cleanup first and reports it in \`fragmentShutdown\`. Use when you have added all desired steps and want to finalize the e2e test file. Fails if that e2e test has no recording in progress.
168430
168595
  A warning e2e-add-step raised on a recorded \`await-ui-element\` is repeated in \`summary\` as a \`warning:\` line right below its step, and \`message\` counts them by kind. Read them before you convert a wait to \`await:\`/\`assert:\` or replay the e2e test.
168431
168596
  You can still edit the .yaml file directly afterwards to remove or reorder steps.`,
168432
168597
  zodSchema: zodSchema75,
168433
168598
  fileInputs: PROJECT_ROOT_INPUT,
168434
168599
  aliases: ["flow-finish-recording"],
168600
+ // It may run the fragments' shutdown, on the device.
168601
+ longRunning: true,
168435
168602
  interaction: {
168436
168603
  // Name the flow: other recordings stay live, so an unqualified message would
168437
168604
  // not identify which one.
@@ -168443,12 +168610,19 @@ You can still edit the .yaml file directly afterwards to remove or reorder steps
168443
168610
  failedMsg: ({ params, failureSignal: failureSignal2 }) => `Failed to finish recording of e2e test ${params.name}: ${failureSignal2.error_code}`
168444
168611
  },
168445
168612
  services: () => ({}),
168446
- async execute(_services, params) {
168613
+ async execute(_services, params, ctx) {
168614
+ let fragmentShutdown;
168447
168615
  const { filePath, flowFile, savedTo, flow, summary, headline } = await withFlowFileLock(
168448
168616
  params.project_root,
168449
168617
  params.name,
168450
168618
  async () => {
168451
168619
  const session = await requireRecordingSession(params.project_root, params.name);
168620
+ fragmentShutdown = await runDeferredShutdown(session, ctx);
168621
+ if (ctx?.signal?.aborted && session.deferredShutdown?.length) {
168622
+ throw new Error(
168623
+ `The finish was cancelled before the kept shutdown: of the fragments recorded as run: steps ran, so the recording "${params.name}" is still open. Call e2e-finish-recording again.`
168624
+ );
168625
+ }
168452
168626
  const filePath2 = session.filePath;
168453
168627
  let flowFile2;
168454
168628
  let savedTo2;
@@ -168460,21 +168634,43 @@ You can still edit the .yaml file directly afterwards to remove or reorder steps
168460
168634
  savedTo2 = filePath2;
168461
168635
  }
168462
168636
  const flow2 = parseFlow(flowFile2);
168463
- const anchored = anchoredWarnings(session, flow2.steps);
168464
- const summary2 = attachStepWarnings(summarizeSteps(flow2), anchored);
168465
- const discarded = (session.discardedWarnings ?? 0) + (session.stepWarnings?.size ?? 0) - anchored.size;
168466
- const headline2 = warningHeadline(anchored, discarded);
168637
+ const anchored = anchoredWarnings(session.flow.steps, session.stepWarnings, flow2.steps);
168638
+ const shutdownAnchored = anchoredWarnings(
168639
+ session.flow.shutdown ?? [],
168640
+ session.shutdownStepWarnings,
168641
+ flow2.shutdown ?? []
168642
+ );
168643
+ const summary2 = [
168644
+ ...attachStepWarnings(summarizeSteps(flow2), anchored),
168645
+ ...attachStepWarnings(
168646
+ (flow2.shutdown ?? []).map((step, i) => summarizeShutdownStep(step, i + 1)),
168647
+ shutdownAnchored
168648
+ )
168649
+ ];
168650
+ const discarded = (session.discardedWarnings ?? 0) + (session.stepWarnings?.size ?? 0) + (session.shutdownStepWarnings?.size ?? 0) - anchored.size - shutdownAnchored.size;
168651
+ const headline2 = warningHeadline(
168652
+ [...anchored.values(), ...shutdownAnchored.values()],
168653
+ discarded
168654
+ );
168467
168655
  clearRecordingSession(session);
168468
168656
  return { filePath: filePath2, flowFile: flowFile2, savedTo: savedTo2, flow: flow2, summary: summary2, headline: headline2 };
168469
168657
  }
168470
- );
168658
+ ).catch((err) => {
168659
+ if (fragmentShutdown && err instanceof Error) {
168660
+ err.message = `${err.message} ${fragmentShutdownNote(fragmentShutdown)}`;
168661
+ }
168662
+ throw err;
168663
+ });
168664
+ const ran = fragmentShutdown;
168471
168665
  return {
168472
168666
  // Name the counts in `message` as well. A caller that reads only
168473
168667
  // `message` would otherwise polish blind.
168474
- message: `Finished recording "${params.name}" e2e test (${flow.steps.length} steps)` + headline,
168668
+ message: `Finished recording "${params.name}" e2e test (${flow.steps.length} steps` + (flow.shutdown ? `, ${flow.shutdown.length} shutdown steps` : "") + `)` + headline + (ran ? `. ${fragmentShutdownNote(ran)}` : ""),
168475
168669
  path: filePath,
168476
168670
  executionPrerequisite: flow.executionPrerequisite,
168477
168671
  steps: flow.steps.length,
168672
+ ...flow.shutdown ? { shutdownSteps: flow.shutdown.length } : {},
168673
+ ...ran ? { fragmentShutdown: ran } : {},
168478
168674
  summary,
168479
168675
  e2eTestFile: flowFile,
168480
168676
  flowFile,
@@ -170919,10 +171115,10 @@ async function turnPngToNative(src, dest, orientation) {
170919
171115
 
170920
171116
  // ../tool-server/src/utils/status-bar.ts
170921
171117
  var import_node_child_process55 = require("node:child_process");
170922
- var import_node_util42 = require("node:util");
171118
+ var import_node_util43 = require("node:util");
170923
171119
  init_adb();
170924
171120
  init_device_info();
170925
- var execFileAsync46 = (0, import_node_util42.promisify)(import_node_child_process55.execFile);
171121
+ var execFileAsync46 = (0, import_node_util43.promisify)(import_node_child_process55.execFile);
170926
171122
  var DEMO_BROADCAST = "am broadcast -a com.android.systemui.demo";
170927
171123
  var IOS_STATUS_BAR_OVERRIDE = [
170928
171124
  "override",
@@ -171774,10 +171970,17 @@ Without a link, every step kind runs.`,
171774
171970
  } catch (error63) {
171775
171971
  thrown = { error: error63 };
171776
171972
  }
171777
- try {
171778
- await execShutdown(state3);
171779
- } catch (error63) {
171780
- thrown ??= { error: error63 };
171973
+ const caller = ctx?.flowOutput;
171974
+ if (caller) state3.output = { doc: caller.doc };
171975
+ if (caller?.deferShutdown && !thrown && canDeferShutdown(state3, viaUpload)) {
171976
+ caller.deferredShutdown = deferShutdown(state3);
171977
+ } else {
171978
+ try {
171979
+ await execShutdown(state3);
171980
+ } catch (error63) {
171981
+ thrown ??= { error: error63 };
171982
+ }
171983
+ if (caller) caller.shutdownDoc = state3.output.doc;
171781
171984
  }
171782
171985
  if (thrown) throw thrown.error;
171783
171986
  } finally {
@@ -172169,6 +172372,36 @@ async function execShutdown(state3) {
172169
172372
  await drainShutdown(state3, 0, thrown);
172170
172373
  if (thrown.length > 0) throw thrown[0];
172171
172374
  }
172375
+ function canDeferShutdown(state3, viaUpload) {
172376
+ return state3.shutdownQueue.length > 0 && !state3.signal?.aborted && !viaUpload && state3.owned.length === 0;
172377
+ }
172378
+ function deferShutdown(state3) {
172379
+ const queue = state3.shutdownQueue;
172380
+ return async (ctx, output2, reports) => {
172381
+ const { onStepReport: _, ...rest } = state3;
172382
+ const later = {
172383
+ ...rest,
172384
+ ctx,
172385
+ signal: ctx?.signal,
172386
+ reports,
172387
+ stopped: false,
172388
+ pinned: false,
172389
+ owned: [],
172390
+ output: output2,
172391
+ scriptLogBudget: createScriptLogBudget(),
172392
+ ...ctx?.emitProgress ? { onStepReport: ctx.emitProgress } : {},
172393
+ shutdownQueue: [...queue],
172394
+ inShutdown: false
172395
+ };
172396
+ try {
172397
+ await execShutdown(later);
172398
+ } finally {
172399
+ for (let i = later.owned.length - 1; i >= 0; i--) {
172400
+ await teardownBootedChromium(state3.registry, later.owned[i]);
172401
+ }
172402
+ }
172403
+ };
172404
+ }
172172
172405
  async function drainShutdown(state3, floor, thrown) {
172173
172406
  while (state3.shutdownQueue.length > floor) {
172174
172407
  const next = state3.shutdownQueue.pop();
@@ -174602,9 +174835,9 @@ function createLensTools(registry2) {
174602
174835
  var import_node_child_process57 = require("node:child_process");
174603
174836
  var import_node_fs24 = require("node:fs");
174604
174837
  var import_node_path33 = require("node:path");
174605
- var import_node_util43 = require("node:util");
174838
+ var import_node_util44 = require("node:util");
174606
174839
  init_android_binary();
174607
- var execFileAsync47 = (0, import_node_util43.promisify)(import_node_child_process57.execFile);
174840
+ var execFileAsync47 = (0, import_node_util44.promisify)(import_node_child_process57.execFile);
174608
174841
  async function activeDeveloperDir2() {
174609
174842
  try {
174610
174843
  const { stdout } = await execFileAsync47("xcode-select", ["-p"], { timeout: 5e3 });