blastproof 0.25.0 → 0.26.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/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  [![CI](https://github.com/hamc/blastproof/actions/workflows/ci.yml/badge.svg)](https://github.com/hamc/blastproof/actions/workflows/ci.yml)
10
10
  [![Dogfood](https://github.com/hamc/blastproof/actions/workflows/dogfood.yml/badge.svg)](https://github.com/hamc/blastproof/actions/workflows/dogfood.yml)
11
+ [![GitHub Marketplace](https://img.shields.io/badge/Marketplace-blastproof%20e2e%20AI%20testing-blue?logo=github)](https://github.com/marketplace/actions/blastproof-e2e-ai-testing)
11
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
12
13
 
13
14
  **Open-source AI testing agent for pull requests.** Write end-to-end tests as plain English. An agent drives a real browser to run them, selects only the ones your diff can affect, and scores the result before merge.
@@ -106,7 +107,7 @@ If a critical journey needs one of these, that journey stays with your existing
106
107
 
107
108
  **Use a seeded database, a staging environment you can reset, or a throwaway account. Do not gate on a run against production data.**
108
109
 
109
- Within a step, an action that commits — a click, or pressing Enter — is never performed twice: the runner refuses the repeat and tells the agent it already did that. This closes the case that used to produce duplicate records, where a submit answered by a redirect came back to a reset form and the agent, seeing no evidence of its own work, submitted again.
110
+ Within a step, an action that commits — a click, or pressing Enter — is not performed twice: the runner refuses the repeat and tells the agent it already did that. This closes the case that used to produce duplicate records, where a submit answered by a redirect came back to a reset form and the agent, seeing no evidence of its own work, refilled it and submitted again. One repeat goes through: the same control pressed again right after itself, with nothing else done in between, when the page changed after the last press — a tour's "Next", a wizard, "load more".
110
111
 
111
112
  It is **not** a guarantee of zero duplicate writes. An agent that reaches the same effect by a genuinely different route — another control that does the same thing — is not caught.
112
113
 
@@ -252,7 +253,7 @@ blastproof run --min-score 80 # one failing P2 is tolerated
252
253
 
253
254
  The calls that *choose* an action, and the one that drafts a test, are deliberately left free — that latitude is what re-resolves a control after a redesign instead of failing on it.
254
255
 
255
- Wiring this into a pipeline, with the gating patterns worth knowing: [Running in CI](./docs/ci.md).
256
+ Wiring this into a pipeline, with the gating patterns worth knowing: [Running in CI](./docs/ci.md). The Action is listed on the GitHub Marketplace as [blastproof e2e AI testing](https://github.com/marketplace/actions/blastproof-e2e-ai-testing).
256
257
 
257
258
  ## Without a browser or a key
258
259
 
@@ -305,17 +306,17 @@ A merge gate is judged by two numbers. A **false PASS** is a test that passes on
305
306
 
306
307
  | | `claude-haiku-4.5` | `gpt-6-luna` |
307
308
  | --- | --- | --- |
308
- | false FAIL, correct app (40 test runs) | 0 (≤ 8.8%) | 0 (≤ 8.8%) |
309
+ | false FAIL, correct app (40 test runs) | 1 (≤ 12.9%) | 0 (≤ 8.8%) |
309
310
  | false PASS, literal bugs (30) | 0 (≤ 11.4%) | 0 (≤ 11.4%) |
310
311
  | false PASS, subtle bugs (20) | 0 (≤ 16.1%) | 0 (≤ 16.1%) |
311
312
 
312
- The bounds are 95% upper bounds: zero errors in 40 runs means "below about 9%", not "never". The first run of this table found a false PASS on Haiku, 2 subtle runs in 20. The confirmation showed order `#BP-1002`, another paragraph mentioned `#BP-1001` as a previous order, and a step checking for `#BP-1001` *in the confirmation* passed. That was fixed in the judge ([#147](https://github.com/hamc/blastproof/issues/147)), and this is the run after the fix.
313
+ The bounds are 95% upper bounds: zero errors in 40 runs means "below about 9%", not "never". The first run of this table found a false PASS on Haiku, 2 subtle runs in 20. The confirmation showed order `#BP-1002`, another paragraph mentioned `#BP-1001` as a previous order, and a step checking for `#BP-1001` *in the confirmation* passed. That was fixed in the judge ([#147](https://github.com/hamc/blastproof/issues/147)). The false FAIL on Haiku is in the notes test: the note was listed and counted, but the model had typed it into the empty field again, and the judge read the filled field as a form not yet submitted.
313
314
 
314
315
  The demo app is small and well labelled, so these numbers flatter. Expect a real application to do worse. The point of this table is that it can be reproduced, and that every change claiming better verdicts has to move it.
315
316
 
316
317
  The same benchmark over seven more models, and why it chose the OpenAI and Ollama defaults, is in [Choosing a model](./docs/configuration.md#choosing-a-model).
317
318
 
318
- Measured 2026-10-07 on `main` after 0.23.0 with #147's fix, 5 samples, through OpenRouter. To reproduce:
319
+ Measured 2026-10-12 on 0.26.0, 5 samples, through OpenRouter. To reproduce:
319
320
 
320
321
  ```bash
321
322
  npm run build
@@ -5,6 +5,39 @@ var DEFAULT_MAX_LINES = 200;
5
5
  function indentOf(line) {
6
6
  return line.length - line.trimStart().length;
7
7
  }
8
+ var DIALOG_LINE = /^\s*- '?(?:dialog|alertdialog)(?=[\s:"']|$)/;
9
+ var OMITTED_LINE = /^\s*- \.\.\. \(\d+ lines? omitted: max_snapshot_lines is (\d+)\)$/m;
10
+ function snapshotCutAt(snapshot) {
11
+ const match = OMITTED_LINE.exec(snapshot);
12
+ return match ? Number(match[1]) : void 0;
13
+ }
14
+ function linesToKeep(lines, maxLines) {
15
+ const keep = /* @__PURE__ */ new Set();
16
+ const subtreeEnd = (i) => {
17
+ let j = i + 1;
18
+ while (j < lines.length && indentOf(lines[j]) > indentOf(lines[i])) j++;
19
+ return j;
20
+ };
21
+ const ancestors = (i) => {
22
+ const found = [];
23
+ let indent = indentOf(lines[i]);
24
+ for (let j = i - 1; j >= 0 && indent > 0; j--) {
25
+ if (indentOf(lines[j]) < indent) {
26
+ found.unshift(j);
27
+ indent = indentOf(lines[j]);
28
+ }
29
+ }
30
+ return found;
31
+ };
32
+ const dialogs = lines.flatMap((line, i) => DIALOG_LINE.test(line) ? [i] : []).reverse();
33
+ const focused = lines.flatMap((line, i) => line.includes("[active]") ? [i] : []);
34
+ for (const anchor of [...dialogs.slice(0, 1), ...focused, ...dialogs.slice(1)]) {
35
+ for (const line of ancestors(anchor)) if (keep.size < maxLines) keep.add(line);
36
+ for (let line = anchor; line < subtreeEnd(anchor) && keep.size < maxLines; line++) keep.add(line);
37
+ }
38
+ for (let line = 0; line < lines.length && keep.size < maxLines; line++) keep.add(line);
39
+ return keep;
40
+ }
8
41
  function trimSnapshot(snapshotYaml, maxLines = DEFAULT_MAX_LINES) {
9
42
  let lines = snapshotYaml.split("\n").filter((line) => line.trim().length > 0);
10
43
  for (let pass = 0; pass < 5; pass++) {
@@ -26,10 +59,23 @@ function trimSnapshot(snapshotYaml, maxLines = DEFAULT_MAX_LINES) {
26
59
  lines = kept;
27
60
  if (removed === 0) break;
28
61
  }
29
- if (lines.length > maxLines) {
30
- lines = [...lines.slice(0, maxLines), `- ... (snapshot truncated after ${maxLines} lines)`];
62
+ if (lines.length <= maxLines) return lines.join("\n");
63
+ const keep = linesToKeep(lines, maxLines);
64
+ const out = [];
65
+ let omitted = 0;
66
+ for (let i = 0; i <= lines.length; i++) {
67
+ if (i < lines.length && !keep.has(i)) {
68
+ omitted++;
69
+ continue;
70
+ }
71
+ if (omitted > 0) {
72
+ const indent = " ".repeat(indentOf(lines[i - omitted]));
73
+ out.push(`${indent}- ... (${omitted} ${omitted === 1 ? "line" : "lines"} omitted: max_snapshot_lines is ${maxLines})`);
74
+ omitted = 0;
75
+ }
76
+ if (i < lines.length) out.push(lines[i]);
31
77
  }
32
- return lines.join("\n");
78
+ return out.join("\n");
33
79
  }
34
80
  async function captureSnapshot(page, options = {}) {
35
81
  const raw = await page.locator("body").ariaSnapshot({ mode: "ai" });
@@ -69,9 +115,10 @@ function indexRefs(snapshot) {
69
115
  }
70
116
 
71
117
  export {
118
+ snapshotCutAt,
72
119
  trimSnapshot,
73
120
  captureSnapshot,
74
121
  withoutRefs,
75
122
  indexRefs
76
123
  };
77
- //# sourceMappingURL=chunk-RA4N57HA.js.map
124
+ //# sourceMappingURL=chunk-DO4WZKLT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/runner/snapshot.ts"],"sourcesContent":["import type { Page } from 'playwright';\n\nexport interface SnapshotOptions {\n /** Maximum number of snapshot lines sent to the LLM. Default 200. */\n maxLines?: number;\n}\n\nconst DEFAULT_MAX_LINES = 200;\n\nfunction indentOf(line: string): number {\n return line.length - line.trimStart().length;\n}\n\n// A line whose role is a dialog, YAML single-quoted or not.\nconst DIALOG_LINE = /^\\s*- '?(?:dialog|alertdialog)(?=[\\s:\"']|$)/;\nconst OMITTED_LINE = /^\\s*- \\.\\.\\. \\(\\d+ lines? omitted: max_snapshot_lines is (\\d+)\\)$/m;\n\n/**\n * The cap a snapshot was cut at, read from its markers, or `undefined` when\n * nothing was omitted (design keep-the-open-dialog-in-the-snapshot, D3). Read\n * from the text so a step's reason cannot disagree with what the model saw.\n */\nexport function snapshotCutAt(snapshot: string): number | undefined {\n const match = OMITTED_LINE.exec(snapshot);\n return match ? Number(match[1]) : undefined;\n}\n\n/**\n * Which lines of an over-cap snapshot to keep (design\n * keep-the-open-dialog-in-the-snapshot, D1). Frameworks render dialogs, menus\n * and palettes in a portal at the end of `<body>`, so a cut from the top\n * dropped first the element the last action opened (#162). The open dialogs\n * (the last one, on top, first) and the focused element are kept with their\n * subtree and the lines they sit under; the rest of the cap is filled from the\n * top, as before. Never more than `maxLines`.\n */\nfunction linesToKeep(lines: string[], maxLines: number): Set<number> {\n const keep = new Set<number>();\n const subtreeEnd = (i: number): number => {\n let j = i + 1;\n while (j < lines.length && indentOf(lines[j]!) > indentOf(lines[i]!)) j++;\n return j;\n };\n const ancestors = (i: number): number[] => {\n const found: number[] = [];\n let indent = indentOf(lines[i]!);\n for (let j = i - 1; j >= 0 && indent > 0; j--) {\n if (indentOf(lines[j]!) < indent) {\n found.unshift(j);\n indent = indentOf(lines[j]!);\n }\n }\n return found;\n };\n\n const dialogs = lines.flatMap((line, i) => (DIALOG_LINE.test(line) ? [i] : [])).reverse();\n const focused = lines.flatMap((line, i) => (line.includes('[active]') ? [i] : []));\n for (const anchor of [...dialogs.slice(0, 1), ...focused, ...dialogs.slice(1)]) {\n for (const line of ancestors(anchor)) if (keep.size < maxLines) keep.add(line);\n for (let line = anchor; line < subtreeEnd(anchor) && keep.size < maxLines; line++) keep.add(line);\n }\n for (let line = 0; line < lines.length && keep.size < maxLines; line++) keep.add(line);\n return keep;\n}\n\n/**\n * Trims an aria snapshot: drops empty containers (e.g. `- group:` with no children)\n * and caps the line count. Over the cap, each run of omitted lines is replaced in\n * place by a marker naming the setting that cut it (design\n * keep-the-open-dialog-in-the-snapshot, D2). Pure function, exported for tests.\n */\nexport function trimSnapshot(snapshotYaml: string, maxLines: number = DEFAULT_MAX_LINES): string {\n let lines = snapshotYaml.split('\\n').filter((line) => line.trim().length > 0);\n\n // Removing empty containers can empty their parents; iterate until stable (bounded).\n for (let pass = 0; pass < 5; pass++) {\n const kept: string[] = [];\n let removed = 0;\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!;\n const isContainer = line.trimEnd().endsWith(':');\n if (isContainer) {\n const next = lines[i + 1];\n const hasChildren = next !== undefined && indentOf(next) > indentOf(line);\n if (!hasChildren) {\n removed++;\n continue;\n }\n }\n kept.push(line);\n }\n lines = kept;\n if (removed === 0) break;\n }\n\n if (lines.length <= maxLines) return lines.join('\\n');\n\n const keep = linesToKeep(lines, maxLines);\n const out: string[] = [];\n let omitted = 0;\n for (let i = 0; i <= lines.length; i++) {\n if (i < lines.length && !keep.has(i)) {\n omitted++;\n continue;\n }\n if (omitted > 0) {\n const indent = ' '.repeat(indentOf(lines[i - omitted]!));\n out.push(`${indent}- ... (${omitted} ${omitted === 1 ? 'line' : 'lines'} omitted: max_snapshot_lines is ${maxLines})`);\n omitted = 0;\n }\n if (i < lines.length) out.push(lines[i]!);\n }\n return out.join('\\n');\n}\n\n/**\n * Captures the current page as a compact accessibility snapshot (design D1),\n * prefixed with the page URL so the model can reason about navigation.\n *\n * Always in AI mode (design act-on-the-element-the-model-read, D3): every\n * element carries the `[ref=…]` an action names it by, and a plain\n * `ariaSnapshot()` invalidates the refs of the last AI-mode one, measured. The\n * `[cursor=pointer]` marker it adds is dropped: it is about the mouse, not the\n * element, and it was most of the growth that was not a ref.\n */\nexport async function captureSnapshot(page: Page, options: SnapshotOptions = {}): Promise<string> {\n const raw = await page.locator('body').ariaSnapshot({ mode: 'ai' });\n return `url: ${page.url()}\\n${trimSnapshot(raw.replace(/ \\[cursor=pointer\\]/g, ''), options.maxLines)}`;\n}\n\nconst REF_MARKER = / \\[ref=[A-Za-z0-9_-]+\\]/g;\n\n/**\n * The snapshot as a reader that chooses no element sees it: the judge and the\n * planner (design act-on-the-element-the-model-read, D3). Refs are ids, not\n * page content, and the judge corpus's stored snapshots have none.\n */\nexport function withoutRefs(snapshot: string): string {\n return snapshot.replace(REF_MARKER, '');\n}\n\n/** What the snapshot line holding a ref shows about its element. */\nexport interface SnapshotElement {\n role: string;\n /** The accessible name, unquoted; absent when the line has none. */\n name?: string;\n /** Inline text after the colon (`- generic [ref=e4]: Promo code`), unquoted. */\n text?: string;\n}\n\n/** Undoes YAML double-quote escaping, the form a name containing `\"` is printed in. */\nfunction unquote(value: string): string {\n const trimmed = value.trim();\n if (trimmed.length >= 2 && trimmed.startsWith('\"') && trimmed.endsWith('\"')) {\n return trimmed.slice(1, -1).replace(/\\\\([\"\\\\])/g, '$1');\n }\n if (trimmed.length >= 2 && trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\")) {\n return trimmed.slice(1, -1).replace(/''/g, \"'\");\n }\n return trimmed;\n}\n\n// `- role \"name\" [attr] [ref=x] [attr]: inline text`, every part after the role optional.\nconst ELEMENT_LINE =\n /^\\s*- ([a-z][a-zA-Z]*)(?: (\"(?:[^\"\\\\]|\\\\.)*\"))?((?: \\[[^\\]]*\\])*)(?::(?: (.*))?)?$/;\n\n/**\n * Each ref in a snapshot, with the role and name its line shows (design\n * act-on-the-element-the-model-read, D2). Read from the snapshot text the model\n * was given, masked as it was, so what is checked and recorded is what the\n * model read and no secret enters the record.\n */\nexport function indexRefs(snapshot: string): Map<string, SnapshotElement> {\n const index = new Map<string, SnapshotElement>();\n for (const raw of snapshot.split('\\n')) {\n // YAML single-quotes a whole entry whose text holds `: `, as in\n // `- 'heading \"Notes on file: 1\" [level=2] [ref=e16]'`.\n const quoted = /^(\\s*- )'((?:[^']|'')*)'(:.*)?$/.exec(raw);\n const line = quoted ? `${quoted[1]}${quoted[2]!.replace(/''/g, \"'\")}${quoted[3] ?? ''}` : raw;\n const match = ELEMENT_LINE.exec(line);\n if (!match) continue;\n const ref = /\\[ref=([A-Za-z0-9_-]+)\\]/.exec(match[3] ?? '')?.[1];\n if (!ref) continue;\n const element: SnapshotElement = { role: match[1]! };\n if (match[2] !== undefined) element.name = unquote(match[2]);\n if (match[4] !== undefined && match[4].trim() !== '') element.text = unquote(match[4]);\n index.set(ref, element);\n }\n return index;\n}\n"],"mappings":";;;AAOA,IAAM,oBAAoB;AAE1B,SAAS,SAAS,MAAsB;AACtC,SAAO,KAAK,SAAS,KAAK,UAAU,EAAE;AACxC;AAGA,IAAM,cAAc;AACpB,IAAM,eAAe;AAOd,SAAS,cAAc,UAAsC;AAClE,QAAM,QAAQ,aAAa,KAAK,QAAQ;AACxC,SAAO,QAAQ,OAAO,MAAM,CAAC,CAAC,IAAI;AACpC;AAWA,SAAS,YAAY,OAAiB,UAA+B;AACnE,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,aAAa,CAAC,MAAsB;AACxC,QAAI,IAAI,IAAI;AACZ,WAAO,IAAI,MAAM,UAAU,SAAS,MAAM,CAAC,CAAE,IAAI,SAAS,MAAM,CAAC,CAAE,EAAG;AACtE,WAAO;AAAA,EACT;AACA,QAAM,YAAY,CAAC,MAAwB;AACzC,UAAM,QAAkB,CAAC;AACzB,QAAI,SAAS,SAAS,MAAM,CAAC,CAAE;AAC/B,aAAS,IAAI,IAAI,GAAG,KAAK,KAAK,SAAS,GAAG,KAAK;AAC7C,UAAI,SAAS,MAAM,CAAC,CAAE,IAAI,QAAQ;AAChC,cAAM,QAAQ,CAAC;AACf,iBAAS,SAAS,MAAM,CAAC,CAAE;AAAA,MAC7B;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,QAAM,UAAU,MAAM,QAAQ,CAAC,MAAM,MAAO,YAAY,KAAK,IAA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M,eACJ;AAQK,SAAS,UAAU,UAAgD;AACxE,QAAM,QAAQ,oBAAI,IAA6B;AAC/C,aAAW,OAAO,SAAS,MAAM,IAAI,GAAG;AAGtC,UAAM,SAAS,kCAAkC,KAAK,GAAG;AACzD,UAAM,OAAO,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,EAAG,QAAQ,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,KAAK;AAC1F,UAAM,QAAQ,aAAa,KAAK,IAAI;AACpC,QAAI,CAAC,MAAO;AACZ,UAAM,MAAM,2BAA2B,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC;AAC/D,QAAI,CAAC,IAAK;AACV,UAAM,UAA2B,EAAE,MAAM,MAAM,CAAC,EAAG;AACnD,QAAI,MAAM,CAAC,MAAM,OAAW,SAAQ,OAAO,QAAQ,MAAM,CAAC,CAAC;AAC3D,QAAI,MAAM,CAAC,MAAM,UAAa,MAAM,CAAC,EAAE,KAAK,MAAM,GAAI,SAAQ,OAAO,QAAQ,MAAM,CAAC,CAAC;AACrF,UAAM,IAAI,KAAK,OAAO;AAAA,EACxB;AACA,SAAO;AACT;","names":[]}
package/dist/cli.js CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  indexRefs,
4
+ snapshotCutAt,
4
5
  withoutRefs
5
- } from "./chunk-RA4N57HA.js";
6
+ } from "./chunk-DO4WZKLT.js";
6
7
 
7
8
  // src/cli.ts
8
9
  import { Command, InvalidArgumentError } from "commander";
@@ -328,6 +329,16 @@ var RunBudget = class {
328
329
  if (this.maxDurationMs === void 0) return void 0;
329
330
  return Math.max(0, this.maxDurationMs - (this.now() - this.startedAt));
330
331
  }
332
+ /**
333
+ * The deadline's stop, for a call its timer aborted (design
334
+ * bound-every-model-call, D3). Not `check()`: a timer can fire a millisecond
335
+ * before the clock `check()` reads has reached the deadline, and that call
336
+ * then left as a timeout, failing a test in the 0.25.0 release workflow.
337
+ */
338
+ deadlineReached() {
339
+ const configured = this.maxDurationMs ?? 0;
340
+ return new BudgetExhaustedError("duration", Math.max(this.now() - this.startedAt, configured), configured);
341
+ }
331
342
  /** Records what a completed model call spent. */
332
343
  record(usage) {
333
344
  this.calls += 1;
@@ -732,6 +743,14 @@ function identity(action) {
732
743
  var StepRecovery = class {
733
744
  performed = /* @__PURE__ */ new Set();
734
745
  history = [];
746
+ /** The last page the model was shown, as given to `observe` (masked, without refs). */
747
+ lastObserved;
748
+ /**
749
+ * The last action that succeeded, with the page it was decided on (design
750
+ * repeat-a-click-that-moves-the-page, D1/D2). A commit that follows itself
751
+ * on a page that moved is a tour's "Next", not a duplicate.
752
+ */
753
+ lastSuccess;
735
754
  /**
736
755
  * Everything the model has been allowed to read this step, normalised: the
737
756
  * step's own text, plus every snapshot it has been shown, plus every value it
@@ -776,6 +795,7 @@ var StepRecovery = class {
776
795
  */
777
796
  observe(maskedSnapshot) {
778
797
  this.readable.push(normalise(maskedSnapshot));
798
+ this.lastObserved = maskedSnapshot;
779
799
  }
780
800
  /**
781
801
  * Whether anything succeeded during this step (design close-a-step D1).
@@ -797,6 +817,7 @@ var StepRecovery = class {
797
817
  /** Records an action that was actually performed and succeeded. */
798
818
  record(action, description, result) {
799
819
  this.performed.add(identity(action));
820
+ this.lastSuccess = { identity: identity(action), page: this.lastObserved };
800
821
  this.history.push({ action: description, result });
801
822
  if (action.value) this.readable.push(normalise(action.value));
802
823
  }
@@ -854,9 +875,25 @@ var StepRecovery = class {
854
875
  repeatedCommitRefusal(action) {
855
876
  if (!isCommit(action)) return void 0;
856
877
  if (!this.performed.has(identity(action))) return void 0;
878
+ if (this.followsItselfOnAMovedPage(action)) return void 0;
857
879
  const target = action.target ? ` on ${action.target.role ?? ""} "${action.target.name ?? ""}"` : "";
858
880
  return `refused: this ${action.action}${target} already succeeded earlier in this step, so it was NOT performed again. It is the same control even under a new ref: refs are renumbered when the page changes. Repeating something that commits repeats whatever it changed in the application. If the page no longer shows that it worked, that is normal for a submit answered by a redirect \u2014 check the record of what you have already done. Verify the step's outcome another way, or fail the step.`;
859
881
  }
882
+ /**
883
+ * The one repeat performed (design repeat-a-click-that-moves-the-page): the
884
+ * same commit as the last action that succeeded, with nothing in between, on
885
+ * a page that differs from the one that success was decided on. A tour's
886
+ * "Next" or a "load more" needs it (#164). Both measured duplicates did
887
+ * something else in between to restore the form, a `fill` (#124) or a click
888
+ * on "New Issue" (#28), and a press that moved nothing is still refused.
889
+ * Compared exactly on the ref-less text `observe` receives, so a re-render
890
+ * alone is no change.
891
+ */
892
+ followsItselfOnAMovedPage(action) {
893
+ const last = this.lastSuccess;
894
+ if (last === void 0 || last.identity !== identity(action)) return false;
895
+ return last.page !== void 0 && this.lastObserved !== void 0 && last.page !== this.lastObserved;
896
+ }
860
897
  /**
861
898
  * Refuses a typed value that came from nowhere the model was entitled to read
862
899
  * (design refuse-an-invented-value).
@@ -899,6 +936,8 @@ var StepRecovery = class {
899
936
  // src/runner/executor.ts
900
937
  var DEFAULT_MAX_ITERATIONS_PER_STEP = 15;
901
938
  var SETTLE_TIMEOUT_MS = 2e3;
939
+ var RENDER_WATCH_MS = 3e3;
940
+ var RENDER_POLL_MS = 250;
902
941
  async function waitForSettled(page) {
903
942
  const deadline = Date.now() + SETTLE_TIMEOUT_MS;
904
943
  const urlBefore = page.url();
@@ -912,7 +951,7 @@ async function waitForSettled(page) {
912
951
  }
913
952
  }
914
953
  async function defaultSnapshot(page, maxLines) {
915
- const { captureSnapshot } = await import("./snapshot-PYB4N7E7.js");
954
+ const { captureSnapshot } = await import("./snapshot-JISKGGMN.js");
916
955
  return captureSnapshot(page, { maxLines });
917
956
  }
918
957
  function slugify(text) {
@@ -920,9 +959,20 @@ function slugify(text) {
920
959
  return slug || "test";
921
960
  }
922
961
  var NOTHING_DONE_REFUSAL = "refused: nothing succeeded during this step, so it was NOT closed. A step closes on what was done in it, not on being declared finished. If the outcome already holds \u2014 there was nothing left to do \u2014 assert that it holds and let the judgment close the step; an assertion is evidence, a declaration is not. If the step cannot be carried out at all, fail it and say why.";
962
+ var FAIL_ON_A_CHANGING_PAGE = "not accepted yet: the page changed after the snapshot you answered fail on, so it may still have been loading. Decide again on the page as it is now.";
923
963
  var VERIFICATION_DONE_REFUSAL = "refused: this step only verifies, so it closes on a passing assertion, not on being declared finished. Assert what the page shows; if it does not show what the step names, fail the step and say why.";
924
964
  var StepFailure = class extends Error {
925
965
  };
966
+ async function pageChangedWithin(page, takeSnapshot, view, seen, withinMs) {
967
+ const deadline = Date.now() + withinMs;
968
+ while (Date.now() < deadline) {
969
+ await new Promise((resolve2) => setTimeout(resolve2, Math.min(RENDER_POLL_MS, Math.max(0, deadline - Date.now()))));
970
+ const raw = await takeSnapshot(page);
971
+ const current = view(raw);
972
+ if (current !== seen) return { raw, page: current };
973
+ }
974
+ return void 0;
975
+ }
926
976
  async function executeTest(page, test, options) {
927
977
  const {
928
978
  brain,
@@ -936,6 +986,7 @@ async function executeTest(page, test, options) {
936
986
  mask = (s) => s,
937
987
  snapshot,
938
988
  maxSnapshotLines,
989
+ renderWatchMs = RENDER_WATCH_MS,
939
990
  onEvent = () => {
940
991
  }
941
992
  } = options;
@@ -967,6 +1018,8 @@ async function executeTest(page, test, options) {
967
1018
  let failedAttempts = 0;
968
1019
  let lastResult;
969
1020
  let stepFailedReason;
1021
+ let lastSnapshot;
1022
+ let lookedAgain = false;
970
1023
  const recovery = new StepRecovery(step);
971
1024
  try {
972
1025
  while (true) {
@@ -980,6 +1033,7 @@ async function executeTest(page, test, options) {
980
1033
  );
981
1034
  }
982
1035
  const snap = await takeSnapshot(page);
1036
+ lastSnapshot = snap;
983
1037
  const maskedSnap = mask(snap);
984
1038
  const refs = indexRefs(maskedSnap);
985
1039
  const pageSnap = withoutRefs(maskedSnap);
@@ -1021,6 +1075,17 @@ async function executeTest(page, test, options) {
1021
1075
  break;
1022
1076
  }
1023
1077
  if (action.action === "fail") {
1078
+ if (!recovery.acted && !lookedAgain) {
1079
+ lookedAgain = true;
1080
+ const moved = await pageChangedWithin(page, takeSnapshot, (snap2) => withoutRefs(mask(snap2)), pageSnap, renderWatchMs);
1081
+ if (moved !== void 0) {
1082
+ lastSnapshot = moved.raw;
1083
+ recovery.observe(moved.page);
1084
+ lastResult = FAIL_ON_A_CHANGING_PAGE;
1085
+ emitAction(index, action, `${action.reasoning} :: ${FAIL_ON_A_CHANGING_PAGE}`);
1086
+ continue;
1087
+ }
1088
+ }
1024
1089
  emitAction(index, action, action.reasoning);
1025
1090
  throw new StepFailure(action.reasoning);
1026
1091
  }
@@ -1038,6 +1103,7 @@ async function executeTest(page, test, options) {
1038
1103
  if (!judgment.pass) {
1039
1104
  await waitForSettled(page);
1040
1105
  const freshSnap = await takeSnapshot(page);
1106
+ lastSnapshot = freshSnap;
1041
1107
  const maskedFresh = withoutRefs(mask(freshSnap));
1042
1108
  recovery.observe(maskedFresh);
1043
1109
  judgment = await brain.judge(
@@ -1114,6 +1180,10 @@ async function executeTest(page, test, options) {
1114
1180
  } catch (error) {
1115
1181
  if (error instanceof RunStoppedError) throw error;
1116
1182
  stepFailedReason = mask(error instanceof Error ? error.message : String(error));
1183
+ const cutAt = lastSnapshot === void 0 ? void 0 : snapshotCutAt(lastSnapshot);
1184
+ if (cutAt !== void 0) {
1185
+ stepFailedReason += ` (The page's snapshot was cut at max_snapshot_lines (${cutAt}); what the step looks for may be in the part left out.)`;
1186
+ }
1117
1187
  }
1118
1188
  for (const entry of recovery.stepHistory()) {
1119
1189
  for (const name of referencedEnvVars(entry.action)) usedEarlier.add(name);
@@ -1881,11 +1951,13 @@ function asProviderRefusal(error) {
1881
1951
  return new ProviderRefusedError(cause.statusCode, cause.message);
1882
1952
  }
1883
1953
  function callAbort(budget) {
1884
- const limits = [budget.callTimeoutMs, budget.remainingMs()].filter((ms) => ms !== void 0);
1885
- if (limits.length === 0) return void 0;
1954
+ const timeout = budget.callTimeoutMs;
1955
+ const remaining = budget.remainingMs();
1956
+ if (timeout === void 0 && remaining === void 0) return void 0;
1957
+ const byDeadline = remaining !== void 0 && (timeout === void 0 || remaining <= timeout);
1886
1958
  const controller = new AbortController();
1887
- const timer = setTimeout(() => controller.abort(), Math.min(...limits));
1888
- return { signal: controller.signal, clear: () => clearTimeout(timer) };
1959
+ const timer = setTimeout(() => controller.abort(), byDeadline ? remaining : timeout);
1960
+ return { signal: controller.signal, byDeadline, clear: () => clearTimeout(timer) };
1889
1961
  }
1890
1962
  function spentAndExplained(error, budget) {
1891
1963
  if (!NoObjectGeneratedError.isInstance(error)) return error;
@@ -1903,7 +1975,7 @@ async function countedGenerate(generate, budget, options) {
1903
1975
  result = await generate({ ...options, maxOutputTokens: MAX_OUTPUT_TOKENS, abortSignal: abort?.signal });
1904
1976
  } catch (error) {
1905
1977
  if (abort?.signal.aborted) {
1906
- budget.check();
1978
+ if (abort.byDeadline) throw budget.deadlineReached();
1907
1979
  if (budget.callTimeoutMs !== void 0) throw new ModelCallTimeoutError(budget.callTimeoutMs);
1908
1980
  }
1909
1981
  throw asProviderRefusal(withProviderDetail(spentAndExplained(error, budget)));
@@ -2364,6 +2436,10 @@ function computeScore(results) {
2364
2436
  if (total === 0) return 100;
2365
2437
  return Math.round(100 * passed / total);
2366
2438
  }
2439
+ function scoreOf(results, incomplete) {
2440
+ if (incomplete && results.every((result) => result.status === "not-run")) return void 0;
2441
+ return computeScore(results);
2442
+ }
2367
2443
  function formatScoreLine(score, results, threshold) {
2368
2444
  if (results.length === 0) {
2369
2445
  const base = "Score: 100 (no tests executed)";
@@ -2374,7 +2450,7 @@ function formatScoreLine(score, results, threshold) {
2374
2450
  }
2375
2451
  function formatIncompleteLine(score, reason) {
2376
2452
  return `Run incomplete: ${reason}
2377
- Score over executed tests: ${score} (not a verdict \u2014 exit code 1 regardless of --min-score)`;
2453
+ ` + (score === void 0 ? "Score: none (no test executed before the stop)" : `Score over executed tests: ${score} (not a verdict \u2014 exit code 1 regardless of --min-score)`);
2378
2454
  }
2379
2455
  function formatSpendLine(spend) {
2380
2456
  const calls = spend.maxCalls === void 0 ? `${spend.calls} model call(s)` : `${spend.calls} of ${spend.maxCalls} model call(s)`;
@@ -2510,7 +2586,7 @@ async function renderHtml(results, skipped, meta) {
2510
2586
  const generatedAt = (meta.generatedAt ?? /* @__PURE__ */ new Date()).toISOString();
2511
2587
  const ordered = [...failures, ...notRun, ...results.filter((r) => r.status === "passed")];
2512
2588
  const detail = (await Promise.all(ordered.map((r) => renderTest(r, meta.screenshots, meta.cwd)))).join("\n");
2513
- const verdict = meta.minScore === void 0 ? "" : meta.score >= meta.minScore ? `<span class="verdict pass">min-score ${meta.minScore}: pass</span>` : `<span class="verdict fail">min-score ${meta.minScore}: FAIL</span>`;
2589
+ const verdict = meta.minScore === void 0 || meta.score === void 0 ? "" : meta.score >= meta.minScore ? `<span class="verdict pass">min-score ${meta.minScore}: pass</span>` : `<span class="verdict fail">min-score ${meta.minScore}: FAIL</span>`;
2514
2590
  const banner = meta.incomplete === void 0 ? "" : ` <section class="incomplete">Run stopped: ${escapeHtml(meta.incomplete)}</section>
2515
2591
 
2516
2592
  `;
@@ -2539,7 +2615,7 @@ async function renderHtml(results, skipped, meta) {
2539
2615
  <p class="sub">${escapeHtml(generatedAt)} \xB7 ${seconds(meta.durationMs)}${meta.spend ? ` \xB7 ${escapeHtml(formatSpendLine(meta.spend))}` : ""}</p>
2540
2616
 
2541
2617
  ${banner} <section class="score">
2542
- <b>${meta.score}</b>
2618
+ <b>${meta.score ?? "\u2014"}</b>${meta.score === void 0 ? '\n <span class="counts">no score: no test executed</span>' : ""}
2543
2619
  ${verdict}
2544
2620
  <span class="counts">${passed} passed \xB7 ${failures.length} failed${notRun.length > 0 ? ` \xB7 ${notRun.length} not run` : ""}${skipped.length > 0 ? ` \xB7 ${skipped.length} skipped` : ""}</span>
2545
2621
  </section>
@@ -2595,7 +2671,10 @@ function renderJUnit(results, skipped, meta) {
2595
2671
  '<?xml version="1.0" encoding="UTF-8"?>',
2596
2672
  `<testsuite name="blastproof" tests="${results.length + skipped.length}" failures="${failures}" skipped="${skipped.length + notRun.length}" time="${seconds2(meta.durationMs)}">`,
2597
2673
  " <properties>",
2598
- ` <property name="score" value="${meta.score}"/>`,
2674
+ // Absent rather than a placeholder (design no-score-when-nothing-ran, D2):
2675
+ // the action reads this property as its `score` output, and an empty output
2676
+ // is how it already says "no score". A sentinel would be a number to compare.
2677
+ ...meta.score === void 0 ? [] : [` <property name="score" value="${meta.score}"/>`],
2599
2678
  ...meta.spend ? [` <property name="llm_calls" value="${meta.spend.calls}"/>`] : [],
2600
2679
  // Omitted rather than emitted as zero when no call reported usage: a
2601
2680
  // property carrying 0 would be read by a pipeline as "this run spent no
@@ -2905,9 +2984,9 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
2905
2984
  if (results.length > 0) printSummary(results);
2906
2985
  reportNearMissedSecrets(nearMissedSecrets);
2907
2986
  if (spend) console.log(formatSpendLine(spend));
2908
- const score = computeScore(results);
2987
+ const score = scoreOf(results, incomplete !== void 0);
2909
2988
  console.log(
2910
- incomplete ? formatIncompleteLine(score, incomplete.message) : formatScoreLine(score, results, options.minScore)
2989
+ incomplete ? formatIncompleteLine(score, incomplete.message) : formatScoreLine(computeScore(results), results, options.minScore)
2911
2990
  );
2912
2991
  if (options.junit) {
2913
2992
  const target = typeof options.junit === "string" ? path9.resolve(options.cwd, options.junit) : path9.join(sessionDir, "junit.xml");
@@ -2943,7 +3022,7 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
2943
3022
  if (incomplete) return EXIT_FAILED;
2944
3023
  if (reportUnclassified(options, impact)) return EXIT_FAILED;
2945
3024
  if (options.minScore !== void 0) {
2946
- return score >= options.minScore ? EXIT_OK : EXIT_FAILED;
3025
+ return computeScore(results) >= options.minScore ? EXIT_OK : EXIT_FAILED;
2947
3026
  }
2948
3027
  return results.some((result) => result.status === "failed") ? EXIT_FAILED : EXIT_OK;
2949
3028
  }
@@ -3539,7 +3618,7 @@ function parsePositiveNumber(flag) {
3539
3618
  };
3540
3619
  }
3541
3620
  var program = new Command();
3542
- program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.25.0");
3621
+ program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.26.0");
3543
3622
  program.command("init").description("Scaffold .blastproof/ (config, tests, sample tests) in the current directory").action(async () => {
3544
3623
  try {
3545
3624
  const result = await initProject(process.cwd());