@open-take/runtime 0.2.10 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -547,7 +547,7 @@ async function ffprobe(path) {
547
547
  }
548
548
  /** Drive `plan` against the live app over CDP, return the ground-truth log. */
549
549
  async function captureTake(plan, opts) {
550
- const { captureTakeCDP: captureTakeCDP$1 } = await import("./cdp-capture-CIDrD1-t.js");
550
+ const { captureTakeCDP: captureTakeCDP$1 } = await import("./cdp-capture-sAwkZN85.js");
551
551
  return captureTakeCDP$1(plan, {
552
552
  ...opts,
553
553
  fps: opts.fps ?? 60
@@ -1155,6 +1155,7 @@ async function captureTakeCDP(plan, opts) {
1155
1155
  await cdp.send("Runtime.enable");
1156
1156
  const inner = await fitViewport(cdp, browser.targetId, vw, vh);
1157
1157
  await installActivityProbe(cdp);
1158
+ if (!originAllowed(plan.url)) throw new Error(`captureTakeCDP: plan.url ${plan.url} is outside OPEN_TAKE_ALLOWED_ORIGINS — an unattended run only films the app it was pointed at`);
1158
1159
  await navigate(cdp, plan.url);
1159
1160
  await installActivityProbe(cdp);
1160
1161
  await awaitFonts(cdp);
@@ -1259,6 +1260,10 @@ async function captureTakeCDP(plan, opts) {
1259
1260
  skip("navigate", step.url ?? href ?? current, "destination is not a resolvable URL");
1260
1261
  continue;
1261
1262
  }
1263
+ if (!originAllowed(dest)) {
1264
+ skip("navigate", dest, "destination is outside OPEN_TAKE_ALLOWED_ORIGINS");
1265
+ continue;
1266
+ }
1262
1267
  await navigate(cdp, dest);
1263
1268
  await awaitFonts(cdp);
1264
1269
  await hold(1200);
@@ -1273,6 +1278,11 @@ async function captureTakeCDP(plan, opts) {
1273
1278
  await hold(600);
1274
1279
  continue;
1275
1280
  }
1281
+ if (process.env.OPEN_TAKE_CI && await evalString(cdp, credentialFieldProbeJs()) === "secret") {
1282
+ skip("type", label$1, "refusing to type into a credential field (OPEN_TAKE_CI)");
1283
+ await hold(600);
1284
+ continue;
1285
+ }
1276
1286
  if (step.clear) await evalAny(cdp, selectAllInFocusedJs());
1277
1287
  const chars = [...step.value];
1278
1288
  const cjk = chars.filter((c) => /[\u2E80-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF\uFF66-\uFF9F]/.test(c)).length;
@@ -1613,6 +1623,35 @@ async function captureTakeCDP(plan, opts) {
1613
1623
  });
1614
1624
  }
1615
1625
  }
1626
+ /** CI containment. A plan is agent-written, and the agent reads the very page
1627
+ * it films — a hostile string ON that page can talk its way into a plan step.
1628
+ * When OPEN_TAKE_ALLOWED_ORIGINS is set (comma-separated origins; `open-take
1629
+ * ci` sets it to the app's own origin), any navigation outside the list is a
1630
+ * skipped step, never a request. Unset (the interactive default), everything
1631
+ * is allowed — a human is watching. */
1632
+ function originAllowed(url) {
1633
+ const raw = process.env.OPEN_TAKE_ALLOWED_ORIGINS;
1634
+ if (!raw) return true;
1635
+ try {
1636
+ const origin = new URL(url).origin;
1637
+ return raw.split(",").some((entry) => entry.trim() === origin);
1638
+ } catch {
1639
+ return false;
1640
+ }
1641
+ }
1642
+ /** Runs in-page AFTER focus landed on the type target: names the field
1643
+ * "secret" when it is a password input or smells like a credential field.
1644
+ * Only consulted under OPEN_TAKE_CI — locally the human sees what is typed. */
1645
+ function credentialFieldProbeJs() {
1646
+ return `(() => {
1647
+ const el = document.activeElement;
1648
+ if (!el) return "ok";
1649
+ const type = (el.getAttribute("type") || "").toLowerCase();
1650
+ const smell = [el.getAttribute("name"), el.getAttribute("id"), el.getAttribute("autocomplete"), el.getAttribute("placeholder")]
1651
+ .filter(Boolean).join(" ").toLowerCase();
1652
+ return type === "password" || /passw|secret|api[-_]?key|access[-_]?token/.test(smell) ? "secret" : "ok";
1653
+ })()`;
1654
+ }
1616
1655
  async function navigate(cdp, url) {
1617
1656
  const loaded = new Promise((res) => {
1618
1657
  cdp.on("Page.loadEventFired", () => res());
@@ -1624,4 +1663,4 @@ async function navigate(cdp, url) {
1624
1663
 
1625
1664
  //#endregion
1626
1665
  export { captureTake, captureTakeCDP, ensureChrome, inspectPage, resolveChrome, resolveNavigateUrl };
1627
- //# sourceMappingURL=cdp-capture-DiHFRxLw.js.map
1666
+ //# sourceMappingURL=cdp-capture-CWNroQPQ.js.map