blastproof 0.31.0 → 0.33.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";
@@ -213,6 +218,59 @@ import path11 from "path";
213
218
  import { readFile, writeFile as writeFile2, mkdir as mkdir3 } from "fs/promises";
214
219
  import path3 from "path";
215
220
 
221
+ // src/runner/authoring.ts
222
+ var VALUE_VERBS = ["fill", "enter", "type", "input", "set"];
223
+ var LEADING_VALUE_VERB = new RegExp(`^\\s*(?:${VALUE_VERBS.join("|")})\\b`, "i");
224
+ var CONNECTOR_WORDS = ["with", "to", "as", "using", "into", "from", "in"];
225
+ var CONNECTOR_WORD = new RegExp(`\\b(?:${CONNECTOR_WORDS.join("|")})\\b`, "i");
226
+ var CONNECTOR_SYMBOL = /["'`:=]|\{\{env\./i;
227
+ var PHRASAL_IN = new RegExp(`^(\\s*(?:${VALUE_VERBS.join("|")}))\\s+in\\b`, "i");
228
+ function namesAValue(step) {
229
+ const withoutPhrasal = step.replace(PHRASAL_IN, "$1");
230
+ return CONNECTOR_WORD.test(withoutPhrasal) || CONNECTOR_SYMBOL.test(withoutPhrasal);
231
+ }
232
+ function namesNoValue(step) {
233
+ return LEADING_VALUE_VERB.test(step) && !namesAValue(step);
234
+ }
235
+ var CHECK_VERB = String.raw`(?:verify|check|confirm|ensure|assert|expect|validate|make\s+sure|see\s+that)\b`;
236
+ var LEADING_CHECK_VERB = new RegExp(String.raw`^\s*(?:(?:then|and)\s+)?` + CHECK_VERB, "i");
237
+ var CHECK_CLAUSE = new RegExp(String.raw`(?:\band\b|\bthen\b|[,;])\s+` + CHECK_VERB, "i");
238
+ function isVerificationStep(step) {
239
+ return LEADING_CHECK_VERB.test(step);
240
+ }
241
+ function hasVerificationClause(step) {
242
+ const unquoted = step.replace(/"[^"]*"|“[^”]*”/g, '""');
243
+ return !isVerificationStep(step) && CHECK_CLAUSE.test(unquoted);
244
+ }
245
+ function withNextCheck(step, next) {
246
+ if (next === void 0 || isVerificationStep(step) || hasVerificationClause(step) || !isVerificationStep(next)) {
247
+ return step;
248
+ }
249
+ const check = next.trim().replace(/^(?:and|then)\s+/i, "");
250
+ const lower = /^.[A-Z]/.test(check) ? check : `${check.charAt(0).toLowerCase()}${check.slice(1)}`;
251
+ return `${step.replace(/[\s.,;:!]+$/, "")} and ${lower}`;
252
+ }
253
+ function entersNamedValue(step) {
254
+ return LEADING_VALUE_VERB.test(step) && namesAValue(step);
255
+ }
256
+ function detectMissingValues(tests) {
257
+ const findings = [];
258
+ for (const test of tests) {
259
+ for (const origin of ["setup", "steps"]) {
260
+ const steps = origin === "setup" ? test.setup ?? [] : test.steps;
261
+ steps.forEach((step, position) => {
262
+ if (namesNoValue(step)) {
263
+ findings.push({ test, origin, index: position + 1, step });
264
+ }
265
+ });
266
+ }
267
+ }
268
+ return { findings };
269
+ }
270
+ function suggestValueClause(step) {
271
+ return `${step.trimEnd()} with <value>`;
272
+ }
273
+
216
274
  // src/runner/budget.ts
217
275
  function describeLimit(limit, observed, configured) {
218
276
  switch (limit) {
@@ -368,8 +426,12 @@ function estimateMaxModelCalls(tests, maxIterationsPerStep, maxRetriesPerStep, j
368
426
  (sum, test) => sum + (test.setup?.length ?? 0) + test.steps.length,
369
427
  0
370
428
  );
429
+ const judgedOnNext = tests.reduce(
430
+ (sum, test) => sum + [test.setup ?? [], test.steps].flatMap((list) => list.filter((step, i) => withNextCheck(step, list[i + 1]) !== step)).length,
431
+ 0
432
+ );
371
433
  const bundled = (2 * judgeCalls - 1) * Math.min(maxIterationsPerStep, maxRetriesPerStep);
372
- return totalSteps * (maxIterationsPerStep + maxRetriesPerStep + bundled);
434
+ return totalSteps * (maxIterationsPerStep + maxRetriesPerStep + bundled) + judgedOnNext * judgeCalls;
373
435
  }
374
436
 
375
437
  // src/runner/env.ts
@@ -494,240 +556,6 @@ var SecretsMask = class {
494
556
  import { mkdir as mkdir2 } from "fs/promises";
495
557
  import path2 from "path";
496
558
 
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
- // src/runner/authoring.ts
687
- var VALUE_VERBS = ["fill", "enter", "type", "input", "set"];
688
- var LEADING_VALUE_VERB = new RegExp(`^\\s*(?:${VALUE_VERBS.join("|")})\\b`, "i");
689
- var CONNECTOR_WORDS = ["with", "to", "as", "using", "into", "from", "in"];
690
- var CONNECTOR_WORD = new RegExp(`\\b(?:${CONNECTOR_WORDS.join("|")})\\b`, "i");
691
- var CONNECTOR_SYMBOL = /["'`:=]|\{\{env\./i;
692
- var PHRASAL_IN = new RegExp(`^(\\s*(?:${VALUE_VERBS.join("|")}))\\s+in\\b`, "i");
693
- function namesAValue(step) {
694
- const withoutPhrasal = step.replace(PHRASAL_IN, "$1");
695
- return CONNECTOR_WORD.test(withoutPhrasal) || CONNECTOR_SYMBOL.test(withoutPhrasal);
696
- }
697
- function namesNoValue(step) {
698
- return LEADING_VALUE_VERB.test(step) && !namesAValue(step);
699
- }
700
- var CHECK_VERB = String.raw`(?:verify|check|confirm|ensure|assert|expect|validate|make\s+sure|see\s+that)\b`;
701
- var LEADING_CHECK_VERB = new RegExp(String.raw`^\s*(?:(?:then|and)\s+)?` + CHECK_VERB, "i");
702
- var CHECK_CLAUSE = new RegExp(String.raw`(?:\band\b|\bthen\b|[,;])\s+` + CHECK_VERB, "i");
703
- function isVerificationStep(step) {
704
- return LEADING_CHECK_VERB.test(step);
705
- }
706
- function hasVerificationClause(step) {
707
- const unquoted = step.replace(/"[^"]*"|“[^”]*”/g, '""');
708
- return !isVerificationStep(step) && CHECK_CLAUSE.test(unquoted);
709
- }
710
- function entersNamedValue(step) {
711
- return LEADING_VALUE_VERB.test(step) && namesAValue(step);
712
- }
713
- function detectMissingValues(tests) {
714
- const findings = [];
715
- for (const test of tests) {
716
- for (const origin of ["setup", "steps"]) {
717
- const steps = origin === "setup" ? test.setup ?? [] : test.steps;
718
- steps.forEach((step, position) => {
719
- if (namesNoValue(step)) {
720
- findings.push({ test, origin, index: position + 1, step });
721
- }
722
- });
723
- }
724
- }
725
- return { findings };
726
- }
727
- function suggestValueClause(step) {
728
- return `${step.trimEnd()} with <value>`;
729
- }
730
-
731
559
  // src/runner/recovery.ts
732
560
  var COMMIT_ACTIONS = /* @__PURE__ */ new Set(["click", "press"]);
733
561
  var COMMIT_KEYS = /* @__PURE__ */ new Set(["Enter", "NumpadEnter", " ", "Space", "Spacebar"]);
@@ -798,11 +626,19 @@ var StepRecovery = class {
798
626
  * a step instead of closing it.
799
627
  */
800
628
  checksAfterActing;
801
- constructor(step) {
629
+ /**
630
+ * `step` is the step as written: the first source a typed value may come
631
+ * from, and the one that names which `{{env.*}}` variables may be typed.
632
+ * `judged` is the sentence the judge reads, which decides how
633
+ * the step closes. They differ only for an action step joined with the check
634
+ * after it (design an-action-step-takes-the-next-check, D4): a value only
635
+ * that check names is one the page should show, not one to type.
636
+ */
637
+ constructor(step, judged = step) {
802
638
  this.step = step;
803
639
  this.readable = [normalise(step)];
804
- this.verifies = isVerificationStep(step);
805
- this.checksAfterActing = hasVerificationClause(step);
640
+ this.verifies = isVerificationStep(judged);
641
+ this.checksAfterActing = judged !== step || hasVerificationClause(judged);
806
642
  }
807
643
  /**
808
644
  * Records a snapshot the model was shown, as a source it may quote from.
@@ -970,9 +806,9 @@ async function waitForSettled(page) {
970
806
  });
971
807
  }
972
808
  }
973
- async function defaultSnapshot(page, maxLines) {
974
- const { captureSnapshot } = await import("./snapshot-JISKGGMN.js");
975
- return captureSnapshot(page, { maxLines });
809
+ async function defaultSnapshot(page, maxLines, frames) {
810
+ const { captureSnapshot } = await import("./snapshot-ECNLGVUG.js");
811
+ return captureSnapshot(page, { maxLines, frames });
976
812
  }
977
813
  function slugify(text) {
978
814
  const slug = text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60);
@@ -986,7 +822,7 @@ var StepFailure = class extends Error {
986
822
  async function pageChangedWithin(page, takeSnapshot, view, seen, withinMs) {
987
823
  const deadline = Date.now() + withinMs;
988
824
  while (Date.now() < deadline) {
989
- await new Promise((resolve2) => setTimeout(resolve2, Math.min(RENDER_POLL_MS, Math.max(0, deadline - Date.now()))));
825
+ await new Promise((resolve) => setTimeout(resolve, Math.min(RENDER_POLL_MS, Math.max(0, deadline - Date.now()))));
990
826
  const raw = await takeSnapshot(page);
991
827
  const current = view(raw);
992
828
  if (current !== seen) return { raw, page: current };
@@ -1021,9 +857,11 @@ async function executeTest(page, test, options) {
1021
857
  maxSnapshotLines,
1022
858
  renderWatchMs = RENDER_WATCH_MS,
1023
859
  onEvent = () => {
1024
- }
860
+ },
861
+ onHiddenFrame
1025
862
  } = options;
1026
- const takeSnapshot = snapshot ?? ((page2) => defaultSnapshot(page2, maxSnapshotLines));
863
+ const boundary = allowedOriginsFor(baseUrl, allowedOrigins);
864
+ const takeSnapshot = snapshot ?? ((page2) => defaultSnapshot(page2, maxSnapshotLines, { allowed: boundary, onHidden: onHiddenFrame }));
1027
865
  const startedAt = Date.now();
1028
866
  const stepResults = [];
1029
867
  const allSteps = [
@@ -1040,20 +878,21 @@ async function executeTest(page, test, options) {
1040
878
  onEvent({ type: "action", index, action: maskedAction, result: mask(result) });
1041
879
  };
1042
880
  let failure;
1043
- const boundary = allowedOriginsFor(baseUrl, allowedOrigins);
1044
881
  await page.goto(new URL(baseUrl).toString());
1045
882
  const usedEarlier = /* @__PURE__ */ new Set();
1046
883
  for (let index = 0; index < allSteps.length; index++) {
1047
- const { step, setup } = allSteps[index];
884
+ const { step: written, setup } = allSteps[index];
885
+ const following = allSteps[index + 1];
886
+ const step = withNextCheck(written, following?.setup === setup ? following.step : void 0);
1048
887
  const stepStartedAt = Date.now();
1049
- onEvent({ type: "step-start", index, total: allSteps.length, step: mask(step), setup });
888
+ onEvent({ type: "step-start", index, total: allSteps.length, step: mask(written), setup });
1050
889
  let iterations = 0;
1051
890
  let failedAttempts = 0;
1052
891
  let lastResult;
1053
892
  let stepFailedReason;
1054
893
  let lastSnapshot;
1055
894
  let lookedAgain = false;
1056
- const recovery = new StepRecovery(step);
895
+ const recovery = new StepRecovery(written, step);
1057
896
  const agentRecord = [];
1058
897
  let pageActedOn;
1059
898
  try {
@@ -1085,7 +924,9 @@ async function executeTest(page, test, options) {
1085
924
  let action;
1086
925
  try {
1087
926
  action = await brain.nextAction({
1088
- step,
927
+ // As written, never joined (design an-action-step-takes-the-next-check,
928
+ // D2): a model told the check acts to make it true (#139).
929
+ step: written,
1089
930
  isSetup: setup,
1090
931
  snapshot: maskedSnap,
1091
932
  lastResult: lastResult === void 0 ? void 0 : mask(lastResult),
@@ -1235,8 +1076,36 @@ async function executeTest(page, test, options) {
1235
1076
  } catch (error) {
1236
1077
  if (error instanceof RunStoppedError) throw error;
1237
1078
  stepFailedReason = mask(error instanceof Error ? error.message : String(error));
1079
+ if (step !== written && error instanceof StepFailure && recovery.acted) {
1080
+ const check = following.step;
1081
+ try {
1082
+ await waitForSettled(page);
1083
+ if (isOriginAllowed(page.url(), boundary)) {
1084
+ const snap = await takeSnapshot(page);
1085
+ lastSnapshot = snap;
1086
+ const pageSnap = withoutRefs(mask(snap));
1087
+ recovery.observe(pageSnap);
1088
+ const judgment = await brain.judge(mask(step), mask(check), pageSnap, recovery.stepHistory(), [
1089
+ ...usedEarlier
1090
+ ]);
1091
+ const asked = {
1092
+ action: "assert",
1093
+ expectation: check,
1094
+ reasoning: "judged on the check that follows before failing"
1095
+ };
1096
+ if (judgment.pass) {
1097
+ emitAction(index, asked, `ok: the check after this step holds: ${judgment.reason}`);
1098
+ stepFailedReason = void 0;
1099
+ } else {
1100
+ emitAction(index, asked, `the check after this step does not hold either: ${judgment.reason}`);
1101
+ }
1102
+ }
1103
+ } catch (judgeError) {
1104
+ if (judgeError instanceof RunStoppedError) throw judgeError;
1105
+ }
1106
+ }
1238
1107
  const cutAt = lastSnapshot === void 0 ? void 0 : snapshotCutAt(lastSnapshot);
1239
- if (cutAt !== void 0) {
1108
+ if (stepFailedReason !== void 0 && cutAt !== void 0) {
1240
1109
  stepFailedReason += ` (The page's snapshot was cut at max_snapshot_lines (${cutAt}); what the step looks for may be in the part left out.)`;
1241
1110
  }
1242
1111
  }
@@ -1245,7 +1114,7 @@ async function executeTest(page, test, options) {
1245
1114
  }
1246
1115
  const status = stepFailedReason ? "failed" : "passed";
1247
1116
  stepResults.push({
1248
- step: mask(step),
1117
+ step: mask(written),
1249
1118
  // results are a report channel — never store substituted secrets
1250
1119
  setup,
1251
1120
  status,
@@ -1256,7 +1125,7 @@ async function executeTest(page, test, options) {
1256
1125
  });
1257
1126
  onEvent({ type: "step-end", index, status, reason: stepFailedReason });
1258
1127
  if (stepFailedReason) {
1259
- failure = { step: mask(step), reason: stepFailedReason };
1128
+ failure = { step: mask(written), reason: stepFailedReason };
1260
1129
  break;
1261
1130
  }
1262
1131
  }
@@ -1308,8 +1177,8 @@ function deviceOptions(name) {
1308
1177
  var SESSION_SEEDED_MARKER = "blastproof:session-seeded";
1309
1178
  async function readFalsyRecords() {
1310
1179
  const g = globalThis;
1311
- const done = (request) => new Promise((resolve2, reject) => {
1312
- request.onsuccess = () => resolve2(request.result);
1180
+ const done = (request) => new Promise((resolve, reject) => {
1181
+ request.onsuccess = () => resolve(request.result);
1313
1182
  request.onerror = () => reject(request.error);
1314
1183
  });
1315
1184
  const encode = (value) => {
@@ -1517,7 +1386,8 @@ async function verifyJudgment(brain, verify, snapshot, maskText, maxRetries = 3)
1517
1386
  async function fromSteps(options) {
1518
1387
  const { auth, baseUrl, browser, brain, maxRetries, snapshot, timeoutMs, maxSnapshotLines, onEvent, mask } = options;
1519
1388
  const steps = auth.steps;
1520
- const takeSnapshot = snapshot ?? ((page) => defaultSnapshot(page, maxSnapshotLines));
1389
+ const frames = { allowed: allowedOriginsFor(baseUrl, options.allowedOrigins), onHidden: options.onHiddenFrame };
1390
+ const takeSnapshot = snapshot ?? ((page) => defaultSnapshot(page, maxSnapshotLines, frames));
1521
1391
  const context = await browser.newContext(deviceOptions(options.device));
1522
1392
  try {
1523
1393
  const page = await context.newPage();
@@ -2015,6 +1885,13 @@ function emitWarning(warning, into) {
2015
1885
  function warningText(warning) {
2016
1886
  return [warning.title, ...warning.lines].join("\n");
2017
1887
  }
1888
+ function hiddenFrameWarning(origin) {
1889
+ return {
1890
+ kind: "hidden-frame",
1891
+ 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.`,
1892
+ lines: [`Add it to allowed_origins in .blastproof/config.yaml if the agent should read and act on it.`]
1893
+ };
1894
+ }
2018
1895
 
2019
1896
  // src/report/uncommitted.ts
2020
1897
  function printUncommitted(uncommitted, changedFiles, config, baseRef, into) {
@@ -2250,9 +2127,9 @@ function createModel(llm, env = process.env) {
2250
2127
  var DECISIONS_ENDPOINT = "https://openrouter.ai/api/alpha/decisions";
2251
2128
  var MAX_DECISION_CHARS = 6e4;
2252
2129
  var RETRY_DELAYS_MS = [2e3, 4e3];
2253
- var sleep = (ms, signal) => new Promise((resolve2, reject) => {
2130
+ var sleep = (ms, signal) => new Promise((resolve, reject) => {
2254
2131
  if (signal?.aborted) return reject(signal.reason);
2255
- const timer = setTimeout(resolve2, ms);
2132
+ const timer = setTimeout(resolve, ms);
2256
2133
  signal?.addEventListener(
2257
2134
  "abort",
2258
2135
  () => {
@@ -2733,7 +2610,8 @@ function renderTestYaml(draft, meta) {
2733
2610
  }
2734
2611
  async function generateForRoute(page, options) {
2735
2612
  const { route, baseUrl, changedFiles, brain, mask, snapshot, maxSnapshotLines, timeoutMs } = options;
2736
- const takeSnapshot = snapshot ?? ((p) => defaultSnapshot(p, maxSnapshotLines));
2613
+ const frames = { allowed: allowedOriginsFor(baseUrl, options.allowedOrigins), onHidden: options.onHiddenFrame };
2614
+ const takeSnapshot = snapshot ?? ((p) => defaultSnapshot(p, maxSnapshotLines, frames));
2737
2615
  const url = new URL(route, baseUrl).toString();
2738
2616
  try {
2739
2617
  await page.goto(url, { timeout: timeoutMs });
@@ -3405,7 +3283,7 @@ function deviceTag(test, config) {
3405
3283
  const device = test.device ?? config.browser.device;
3406
3284
  return device ? ` [${device}]` : "";
3407
3285
  }
3408
- async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, firstJudge) {
3286
+ async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, onHiddenFrame, firstJudge) {
3409
3287
  const brain = createBrain(createModel(config.llm).model, void 0, budget, firstJudge);
3410
3288
  let resolved;
3411
3289
  const mask = runMask;
@@ -3442,7 +3320,8 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
3442
3320
  timeoutMs: config.browser.timeout_ms,
3443
3321
  maxSnapshotLines: config.browser.max_snapshot_lines,
3444
3322
  mask: (text) => mask.mask(text),
3445
- onEvent: (event) => printEvent(event, write)
3323
+ onEvent: (event) => printEvent(event, write),
3324
+ onHiddenFrame
3446
3325
  });
3447
3326
  return device ? { ...result, device } : result;
3448
3327
  } finally {
@@ -3631,6 +3510,8 @@ async function runCommand(options) {
3631
3510
  throw error;
3632
3511
  }
3633
3512
  const warnings = [];
3513
+ const hiddenFrames = /* @__PURE__ */ new Set();
3514
+ const onHiddenFrame = (origin) => hiddenFrames.add(origin);
3634
3515
  const impacted = options.impacted ?? false;
3635
3516
  const base = options.base ?? "main";
3636
3517
  if (options.failOnUnmapped && !impacted) {
@@ -3776,13 +3657,15 @@ ${results.length} test file(s) could not be parsed:`);
3776
3657
  maxSnapshotLines: config.browser.max_snapshot_lines,
3777
3658
  device: config.browser.device,
3778
3659
  mask: runMask,
3779
- onEvent: printEvent
3660
+ onEvent: printEvent,
3661
+ onHiddenFrame
3780
3662
  });
3781
3663
  } catch (error) {
3782
3664
  if (error instanceof RunStoppedError) {
3783
3665
  incomplete = error;
3784
3666
  } else if (error instanceof AuthError) {
3785
3667
  console.error(`error: ${error.message}`);
3668
+ for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin), warnings);
3786
3669
  return EXIT_USAGE;
3787
3670
  } else {
3788
3671
  throw error;
@@ -3814,6 +3697,7 @@ ${results.length} test file(s) could not be parsed:`);
3814
3697
  runMask,
3815
3698
  budget,
3816
3699
  write,
3700
+ onHiddenFrame,
3817
3701
  firstJudgeFor(path10.relative(options.cwd, test.path))
3818
3702
  );
3819
3703
  if (!streaming) for (const line of lines) console.log(line);
@@ -3839,6 +3723,7 @@ ${results.length} test file(s) could not be parsed:`);
3839
3723
  } finally {
3840
3724
  await browser.close();
3841
3725
  }
3726
+ for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin), warnings);
3842
3727
  return finalize(
3843
3728
  results,
3844
3729
  selection.unroutedSkipped,
@@ -3986,6 +3871,8 @@ async function planCommand(options) {
3986
3871
  return EXIT_USAGE;
3987
3872
  }
3988
3873
  const browser = preflight.browser;
3874
+ const hiddenFrames = /* @__PURE__ */ new Set();
3875
+ const onHiddenFrame = (origin) => hiddenFrames.add(origin);
3989
3876
  try {
3990
3877
  let session;
3991
3878
  if (config.auth) {
@@ -4003,13 +3890,15 @@ async function planCommand(options) {
4003
3890
  maxSnapshotLines: config.browser.max_snapshot_lines,
4004
3891
  device: config.browser.device,
4005
3892
  mask,
4006
- onEvent: printAuthEvent
3893
+ onEvent: printAuthEvent,
3894
+ onHiddenFrame
4007
3895
  });
4008
3896
  } catch (error) {
4009
3897
  if (error instanceof RunStoppedError) {
4010
3898
  incomplete = error;
4011
3899
  } else if (error instanceof AuthError) {
4012
3900
  console.error(`error: ${error.message}`);
3901
+ for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin));
4013
3902
  return EXIT_USAGE;
4014
3903
  } else {
4015
3904
  throw error;
@@ -4030,6 +3919,8 @@ async function planCommand(options) {
4030
3919
  baseUrl: config.base_url,
4031
3920
  changedFiles,
4032
3921
  brain,
3922
+ allowedOrigins: config.allowed_origins,
3923
+ onHiddenFrame,
4033
3924
  mask: (text) => mask.mask(text),
4034
3925
  maxSnapshotLines: config.browser.max_snapshot_lines,
4035
3926
  timeoutMs: config.browser.timeout_ms
@@ -4072,6 +3963,7 @@ ${renderTestYaml(draft, { route, base })}`);
4072
3963
  } finally {
4073
3964
  await browser.close();
4074
3965
  }
3966
+ for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin));
4075
3967
  const notAttempted = incomplete ? work.map((item) => item.route).filter((route) => !generated.includes(route) && !failed.some((f) => f.route === route)) : [];
4076
3968
  console.log("\n--- Plan -------------------------------------------------------");
4077
3969
  console.log(`Generated: ${generated.length > 0 ? generated.join(", ") : "none"}`);
@@ -4183,7 +4075,7 @@ function parsePositiveNumber(flag) {
4183
4075
  };
4184
4076
  }
4185
4077
  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");
4078
+ program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.33.0");
4187
4079
  program.command("init").description("Scaffold .blastproof/ (config, tests, sample tests) in the current directory").action(async () => {
4188
4080
  try {
4189
4081
  const result = await initProject(process.cwd());