blastproof 0.31.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,9 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ allowedOriginsFor,
4
+ bindTarget,
5
+ describeBoundary,
3
6
  indexRefs,
7
+ isOriginAllowed,
8
+ performAction,
4
9
  snapshotCutAt,
5
10
  withoutRefs
6
- } from "./chunk-DO4WZKLT.js";
11
+ } from "./chunk-O6UTUPT6.js";
7
12
 
8
13
  // src/cli.ts
9
14
  import { Command, InvalidArgumentError } from "commander";
@@ -494,195 +499,6 @@ var SecretsMask = class {
494
499
  import { mkdir as mkdir2 } from "fs/promises";
495
500
  import path2 from "path";
496
501
 
497
- // src/runner/actions.ts
498
- var ActionError = class extends Error {
499
- constructor(message) {
500
- super(message);
501
- this.name = "ActionError";
502
- }
503
- };
504
- var BLANK_PAGE = "about:blank";
505
- function allowedOriginsFor(baseUrl, allowedOrigins) {
506
- const allowed = /* @__PURE__ */ new Set([new URL(baseUrl).origin]);
507
- for (const origin of allowedOrigins ?? []) {
508
- allowed.add(new URL(origin).origin);
509
- }
510
- return allowed;
511
- }
512
- function isOriginAllowed(url, allowed) {
513
- if (url === BLANK_PAGE) return true;
514
- let origin;
515
- try {
516
- origin = new URL(url).origin;
517
- } catch {
518
- return false;
519
- }
520
- if (origin === "null") return false;
521
- return allowed.has(origin);
522
- }
523
- function describeBoundary(allowed) {
524
- return [...allowed].join(" or ");
525
- }
526
- function assertAllowedOrigin(url, ctx) {
527
- const allowed = allowedOriginsFor(ctx.baseUrl, ctx.allowedOrigins);
528
- if (!isOriginAllowed(url.toString(), allowed)) {
529
- throw new ActionError(
530
- `Refusing to navigate outside the application: ${url.origin} is not ${describeBoundary(allowed)}. Add it to allowed_origins in .blastproof/config.yaml if the app legitimately spans hosts.`
531
- );
532
- }
533
- }
534
- function describeTarget(target) {
535
- const parts = [];
536
- if (target.role) parts.push(`role=${target.role}`);
537
- if (target.name) parts.push(`name="${target.name}"`);
538
- return parts.join(" ") || "(no target)";
539
- }
540
- function normaliseName(text) {
541
- return (text ?? "").replace(/\s+/g, " ").trim().toLowerCase();
542
- }
543
- function bareRef(ref) {
544
- return ref.trim().replace(/^\[/, "").replace(/^ref=/, "").replace(/\]$/, "");
545
- }
546
- function describeElement(element) {
547
- const name = element.name ?? element.text;
548
- return name === void 0 ? element.role : `${element.role} "${name}"`;
549
- }
550
- function bindTarget(action, refs) {
551
- const target = action.target;
552
- if (!target || !target.ref && !target.role && !target.name) return { ...action, target: void 0 };
553
- const fix = "Use the [ref=\u2026] on the line of the element you mean in the current snapshot.";
554
- if (!target.ref) {
555
- throw new ActionError(`refused: the target names no ref, so nothing was done. ${fix}`);
556
- }
557
- const ref = bareRef(target.ref);
558
- const element = refs.get(ref);
559
- if (!element) {
560
- throw new ActionError(`refused: no element in the current snapshot has ref "${ref}". ${fix}`);
561
- }
562
- const shown = element.name ?? element.text;
563
- const sameRole = normaliseName(target.role) === normaliseName(element.role);
564
- const sameName = normaliseName(target.name) === normaliseName(shown);
565
- if (!sameRole || !sameName) {
566
- const said = [target.role ?? "(no role)", target.name === void 0 ? "" : `"${target.name}"`].filter(Boolean).join(" ");
567
- throw new ActionError(
568
- `refused: ref ${ref} is ${describeElement(element)}, not ${said}, so nothing was done. ${fix}`
569
- );
570
- }
571
- return { ...action, target: { ref, role: element.role, name: shown } };
572
- }
573
- async function resolveTarget(page, target, resolveTimeoutMs = 2e3) {
574
- if (!target.ref) throw new ActionError(`Element not found: ${describeTarget(target)} has no ref`);
575
- const ref = bareRef(target.ref);
576
- const locator = page.locator(`aria-ref=${ref}`);
577
- let count2;
578
- try {
579
- count2 = await locator.count();
580
- } catch {
581
- count2 = 0;
582
- }
583
- if (count2 === 0) {
584
- throw new ActionError(
585
- `Element not found: ${describeTarget(target)} (ref ${ref}) is no longer on the page; it changed since the snapshot. Choose the element again from the fresh snapshot.`
586
- );
587
- }
588
- try {
589
- await locator.waitFor({ state: "visible", timeout: resolveTimeoutMs });
590
- } catch {
591
- throw new ActionError(
592
- `Element not found: ${describeTarget(target)} (ref ${ref}) is on the page but did not become visible within ${resolveTimeoutMs}ms.`
593
- );
594
- }
595
- return locator;
596
- }
597
- function requireTarget(action) {
598
- if (!action.target?.ref) {
599
- throw new ActionError(`Action "${action.action}" requires a target (its ref in the snapshot)`);
600
- }
601
- return action.target;
602
- }
603
- function resolve(value, ctx) {
604
- return ctx.resolveValue ? ctx.resolveValue(value) : value;
605
- }
606
- function requireValue(action) {
607
- if (action.value === void 0 || action.value === "") {
608
- throw new ActionError(`Action "${action.action}" requires a value`);
609
- }
610
- return action.value;
611
- }
612
- var INTERCEPTS_POINTER = /(<[^>\n]{1,400}>)[^\n]{0,400}?intercepts pointer events/;
613
- var MAX_BLOCKER_LENGTH = 80;
614
- function truncateBlocker(tag) {
615
- return tag.length <= MAX_BLOCKER_LENGTH ? tag : `${tag.slice(0, MAX_BLOCKER_LENGTH)}\u2026>`;
616
- }
617
- function obstructionFor(error, action) {
618
- const message = error instanceof Error ? error.message : String(error);
619
- const match = INTERCEPTS_POINTER.exec(message);
620
- if (!match) return void 0;
621
- const where = action.target ? ` on ${describeTarget(action.target)}` : "";
622
- return new ActionError(
623
- `blocked: the ${action.action}${where} was NOT performed. The target was found and is visible, enabled and stable \u2014 nothing about it is wrong. ${truncateBlocker(match[1])} is on top of it and received the pointer event instead. Something is covering the page: find it in the snapshot \u2014 a dialog, a cookie banner, an onboarding overlay \u2014 and dismiss it first, using its own close or accept control, or by pressing Escape with no target. Then act on this target again. Choosing a different name for the same target cannot help.`
624
- );
625
- }
626
- async function performAction(page, action, ctx) {
627
- try {
628
- return await performResolvedAction(page, action, ctx);
629
- } catch (error) {
630
- throw obstructionFor(error, action) ?? error;
631
- }
632
- }
633
- async function performResolvedAction(page, action, ctx) {
634
- switch (action.action) {
635
- case "navigate": {
636
- const value = resolve(requireValue(action), ctx);
637
- const url = new URL(value, ctx.baseUrl);
638
- assertAllowedOrigin(url, ctx);
639
- await page.goto(url.toString(), { timeout: ctx.resolveTimeoutMs ?? 3e4 });
640
- const landed = page.url();
641
- return landed === url.toString() ? `ok: navigated to ${url.toString()}` : `ok: navigated to ${url.toString()}, which redirected to ${landed}`;
642
- }
643
- case "click": {
644
- const target = requireTarget(action);
645
- const locator = await resolveTarget(page, target, ctx.resolveTimeoutMs);
646
- await locator.click();
647
- return `ok: clicked ${describeTarget(target)}`;
648
- }
649
- case "hover": {
650
- const target = requireTarget(action);
651
- const locator = await resolveTarget(page, target, ctx.resolveTimeoutMs);
652
- await locator.hover();
653
- return `ok: hovered ${describeTarget(target)}`;
654
- }
655
- case "fill": {
656
- const target = requireTarget(action);
657
- const value = resolve(requireValue(action), ctx);
658
- const locator = await resolveTarget(page, target, ctx.resolveTimeoutMs);
659
- await locator.fill(value);
660
- return `ok: filled ${describeTarget(target)}`;
661
- }
662
- case "press": {
663
- const key = action.value ? resolve(action.value, ctx) : "Enter";
664
- if (action.target?.ref) {
665
- const locator = await resolveTarget(page, action.target, ctx.resolveTimeoutMs);
666
- await locator.press(key);
667
- return `ok: pressed ${key} on ${describeTarget(action.target)}`;
668
- }
669
- await page.keyboard.press(key);
670
- return `ok: pressed ${key}`;
671
- }
672
- case "select": {
673
- const target = requireTarget(action);
674
- const value = resolve(requireValue(action), ctx);
675
- const locator = await resolveTarget(page, target, ctx.resolveTimeoutMs);
676
- await locator.selectOption({ label: value });
677
- return `ok: selected "${value}" in ${describeTarget(target)}`;
678
- }
679
- case "assert":
680
- case "done":
681
- case "fail":
682
- throw new ActionError(`Action "${action.action}" is handled by the executor, not the page`);
683
- }
684
- }
685
-
686
502
  // src/runner/authoring.ts
687
503
  var VALUE_VERBS = ["fill", "enter", "type", "input", "set"];
688
504
  var LEADING_VALUE_VERB = new RegExp(`^\\s*(?:${VALUE_VERBS.join("|")})\\b`, "i");
@@ -970,9 +786,9 @@ async function waitForSettled(page) {
970
786
  });
971
787
  }
972
788
  }
973
- async function defaultSnapshot(page, maxLines) {
974
- const { captureSnapshot } = await import("./snapshot-JISKGGMN.js");
975
- return captureSnapshot(page, { maxLines });
789
+ async function defaultSnapshot(page, maxLines, frames) {
790
+ const { captureSnapshot } = await import("./snapshot-ECNLGVUG.js");
791
+ return captureSnapshot(page, { maxLines, frames });
976
792
  }
977
793
  function slugify(text) {
978
794
  const slug = text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
@@ -986,7 +802,7 @@ var StepFailure = class extends Error {
986
802
  async function pageChangedWithin(page, takeSnapshot, view, seen, withinMs) {
987
803
  const deadline = Date.now() + withinMs;
988
804
  while (Date.now() < deadline) {
989
- await new Promise((resolve2) => setTimeout(resolve2, Math.min(RENDER_POLL_MS, Math.max(0, deadline - Date.now()))));
805
+ await new Promise((resolve) => setTimeout(resolve, Math.min(RENDER_POLL_MS, Math.max(0, deadline - Date.now()))));
990
806
  const raw = await takeSnapshot(page);
991
807
  const current = view(raw);
992
808
  if (current !== seen) return { raw, page: current };
@@ -1021,9 +837,11 @@ async function executeTest(page, test, options) {
1021
837
  maxSnapshotLines,
1022
838
  renderWatchMs = RENDER_WATCH_MS,
1023
839
  onEvent = () => {
1024
- }
840
+ },
841
+ onHiddenFrame
1025
842
  } = options;
1026
- const takeSnapshot = snapshot ?? ((page2) => defaultSnapshot(page2, maxSnapshotLines));
843
+ const boundary = allowedOriginsFor(baseUrl, allowedOrigins);
844
+ const takeSnapshot = snapshot ?? ((page2) => defaultSnapshot(page2, maxSnapshotLines, { allowed: boundary, onHidden: onHiddenFrame }));
1027
845
  const startedAt = Date.now();
1028
846
  const stepResults = [];
1029
847
  const allSteps = [
@@ -1040,7 +858,6 @@ async function executeTest(page, test, options) {
1040
858
  onEvent({ type: "action", index, action: maskedAction, result: mask(result) });
1041
859
  };
1042
860
  let failure;
1043
- const boundary = allowedOriginsFor(baseUrl, allowedOrigins);
1044
861
  await page.goto(new URL(baseUrl).toString());
1045
862
  const usedEarlier = /* @__PURE__ */ new Set();
1046
863
  for (let index = 0; index < allSteps.length; index++) {
@@ -1308,8 +1125,8 @@ function deviceOptions(name) {
1308
1125
  var SESSION_SEEDED_MARKER = "blastproof:session-seeded";
1309
1126
  async function readFalsyRecords() {
1310
1127
  const g = globalThis;
1311
- const done = (request) => new Promise((resolve2, reject) => {
1312
- request.onsuccess = () => resolve2(request.result);
1128
+ const done = (request) => new Promise((resolve, reject) => {
1129
+ request.onsuccess = () => resolve(request.result);
1313
1130
  request.onerror = () => reject(request.error);
1314
1131
  });
1315
1132
  const encode = (value) => {
@@ -1517,7 +1334,8 @@ async function verifyJudgment(brain, verify, snapshot, maskText, maxRetries = 3)
1517
1334
  async function fromSteps(options) {
1518
1335
  const { auth, baseUrl, browser, brain, maxRetries, snapshot, timeoutMs, maxSnapshotLines, onEvent, mask } = options;
1519
1336
  const steps = auth.steps;
1520
- const takeSnapshot = snapshot ?? ((page) => defaultSnapshot(page, maxSnapshotLines));
1337
+ const frames = { allowed: allowedOriginsFor(baseUrl, options.allowedOrigins), onHidden: options.onHiddenFrame };
1338
+ const takeSnapshot = snapshot ?? ((page) => defaultSnapshot(page, maxSnapshotLines, frames));
1521
1339
  const context = await browser.newContext(deviceOptions(options.device));
1522
1340
  try {
1523
1341
  const page = await context.newPage();
@@ -2015,6 +1833,13 @@ function emitWarning(warning, into) {
2015
1833
  function warningText(warning) {
2016
1834
  return [warning.title, ...warning.lines].join("\n");
2017
1835
  }
1836
+ function hiddenFrameWarning(origin) {
1837
+ return {
1838
+ kind: "hidden-frame",
1839
+ title: `warning: content from ${origin} was not shown to the agent: it is in a frame on a page under test, and not in allowed_origins.`,
1840
+ lines: [`Add it to allowed_origins in .blastproof/config.yaml if the agent should read and act on it.`]
1841
+ };
1842
+ }
2018
1843
 
2019
1844
  // src/report/uncommitted.ts
2020
1845
  function printUncommitted(uncommitted, changedFiles, config, baseRef, into) {
@@ -2250,9 +2075,9 @@ function createModel(llm, env = process.env) {
2250
2075
  var DECISIONS_ENDPOINT = "https://openrouter.ai/api/alpha/decisions";
2251
2076
  var MAX_DECISION_CHARS = 6e4;
2252
2077
  var RETRY_DELAYS_MS = [2e3, 4e3];
2253
- var sleep = (ms, signal) => new Promise((resolve2, reject) => {
2078
+ var sleep = (ms, signal) => new Promise((resolve, reject) => {
2254
2079
  if (signal?.aborted) return reject(signal.reason);
2255
- const timer = setTimeout(resolve2, ms);
2080
+ const timer = setTimeout(resolve, ms);
2256
2081
  signal?.addEventListener(
2257
2082
  "abort",
2258
2083
  () => {
@@ -2733,7 +2558,8 @@ function renderTestYaml(draft, meta) {
2733
2558
  }
2734
2559
  async function generateForRoute(page, options) {
2735
2560
  const { route, baseUrl, changedFiles, brain, mask, snapshot, maxSnapshotLines, timeoutMs } = options;
2736
- const takeSnapshot = snapshot ?? ((p) => defaultSnapshot(p, maxSnapshotLines));
2561
+ const frames = { allowed: allowedOriginsFor(baseUrl, options.allowedOrigins), onHidden: options.onHiddenFrame };
2562
+ const takeSnapshot = snapshot ?? ((p) => defaultSnapshot(p, maxSnapshotLines, frames));
2737
2563
  const url = new URL(route, baseUrl).toString();
2738
2564
  try {
2739
2565
  await page.goto(url, { timeout: timeoutMs });
@@ -3405,7 +3231,7 @@ function deviceTag(test, config) {
3405
3231
  const device = test.device ?? config.browser.device;
3406
3232
  return device ? ` [${device}]` : "";
3407
3233
  }
3408
- async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, firstJudge) {
3234
+ async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, onHiddenFrame, firstJudge) {
3409
3235
  const brain = createBrain(createModel(config.llm).model, void 0, budget, firstJudge);
3410
3236
  let resolved;
3411
3237
  const mask = runMask;
@@ -3442,7 +3268,8 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
3442
3268
  timeoutMs: config.browser.timeout_ms,
3443
3269
  maxSnapshotLines: config.browser.max_snapshot_lines,
3444
3270
  mask: (text) => mask.mask(text),
3445
- onEvent: (event) => printEvent(event, write)
3271
+ onEvent: (event) => printEvent(event, write),
3272
+ onHiddenFrame
3446
3273
  });
3447
3274
  return device ? { ...result, device } : result;
3448
3275
  } finally {
@@ -3631,6 +3458,8 @@ async function runCommand(options) {
3631
3458
  throw error;
3632
3459
  }
3633
3460
  const warnings = [];
3461
+ const hiddenFrames = /* @__PURE__ */ new Set();
3462
+ const onHiddenFrame = (origin) => hiddenFrames.add(origin);
3634
3463
  const impacted = options.impacted ?? false;
3635
3464
  const base = options.base ?? "main";
3636
3465
  if (options.failOnUnmapped && !impacted) {
@@ -3776,13 +3605,15 @@ ${results.length} test file(s) could not be parsed:`);
3776
3605
  maxSnapshotLines: config.browser.max_snapshot_lines,
3777
3606
  device: config.browser.device,
3778
3607
  mask: runMask,
3779
- onEvent: printEvent
3608
+ onEvent: printEvent,
3609
+ onHiddenFrame
3780
3610
  });
3781
3611
  } catch (error) {
3782
3612
  if (error instanceof RunStoppedError) {
3783
3613
  incomplete = error;
3784
3614
  } else if (error instanceof AuthError) {
3785
3615
  console.error(`error: ${error.message}`);
3616
+ for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin), warnings);
3786
3617
  return EXIT_USAGE;
3787
3618
  } else {
3788
3619
  throw error;
@@ -3814,6 +3645,7 @@ ${results.length} test file(s) could not be parsed:`);
3814
3645
  runMask,
3815
3646
  budget,
3816
3647
  write,
3648
+ onHiddenFrame,
3817
3649
  firstJudgeFor(path10.relative(options.cwd, test.path))
3818
3650
  );
3819
3651
  if (!streaming) for (const line of lines) console.log(line);
@@ -3839,6 +3671,7 @@ ${results.length} test file(s) could not be parsed:`);
3839
3671
  } finally {
3840
3672
  await browser.close();
3841
3673
  }
3674
+ for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin), warnings);
3842
3675
  return finalize(
3843
3676
  results,
3844
3677
  selection.unroutedSkipped,
@@ -3986,6 +3819,8 @@ async function planCommand(options) {
3986
3819
  return EXIT_USAGE;
3987
3820
  }
3988
3821
  const browser = preflight.browser;
3822
+ const hiddenFrames = /* @__PURE__ */ new Set();
3823
+ const onHiddenFrame = (origin) => hiddenFrames.add(origin);
3989
3824
  try {
3990
3825
  let session;
3991
3826
  if (config.auth) {
@@ -4003,13 +3838,15 @@ async function planCommand(options) {
4003
3838
  maxSnapshotLines: config.browser.max_snapshot_lines,
4004
3839
  device: config.browser.device,
4005
3840
  mask,
4006
- onEvent: printAuthEvent
3841
+ onEvent: printAuthEvent,
3842
+ onHiddenFrame
4007
3843
  });
4008
3844
  } catch (error) {
4009
3845
  if (error instanceof RunStoppedError) {
4010
3846
  incomplete = error;
4011
3847
  } else if (error instanceof AuthError) {
4012
3848
  console.error(`error: ${error.message}`);
3849
+ for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin));
4013
3850
  return EXIT_USAGE;
4014
3851
  } else {
4015
3852
  throw error;
@@ -4030,6 +3867,8 @@ async function planCommand(options) {
4030
3867
  baseUrl: config.base_url,
4031
3868
  changedFiles,
4032
3869
  brain,
3870
+ allowedOrigins: config.allowed_origins,
3871
+ onHiddenFrame,
4033
3872
  mask: (text) => mask.mask(text),
4034
3873
  maxSnapshotLines: config.browser.max_snapshot_lines,
4035
3874
  timeoutMs: config.browser.timeout_ms
@@ -4072,6 +3911,7 @@ ${renderTestYaml(draft, { route, base })}`);
4072
3911
  } finally {
4073
3912
  await browser.close();
4074
3913
  }
3914
+ for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin));
4075
3915
  const notAttempted = incomplete ? work.map((item) => item.route).filter((route) => !generated.includes(route) && !failed.some((f) => f.route === route)) : [];
4076
3916
  console.log("\n--- Plan -------------------------------------------------------");
4077
3917
  console.log(`Generated: ${generated.length > 0 ? generated.join(", ") : "none"}`);
@@ -4183,7 +4023,7 @@ function parsePositiveNumber(flag) {
4183
4023
  };
4184
4024
  }
4185
4025
  var program = new Command();
4186
- program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.31.0");
4026
+ program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.32.0");
4187
4027
  program.command("init").description("Scaffold .blastproof/ (config, tests, sample tests) in the current directory").action(async () => {
4188
4028
  try {
4189
4029
  const result = await initProject(process.cwd());