blastproof 0.34.0 → 0.36.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 +2 -2
- package/dist/{chunk-7UQT6SVD.js → chunk-VBWOSSGY.js} +5 -1
- package/dist/chunk-VBWOSSGY.js.map +1 -0
- package/dist/cli.js +871 -112
- package/dist/cli.js.map +1 -1
- package/dist/{snapshot-6C7FIWW7.js → snapshot-RHSNLK3X.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-7UQT6SVD.js.map +0 -1
- /package/dist/{snapshot-6C7FIWW7.js.map → snapshot-RHSNLK3X.js.map} +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
ActionError,
|
|
3
4
|
FIELD_ROLES,
|
|
4
5
|
allowedOriginsFor,
|
|
5
6
|
bindTarget,
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
snapshotFields,
|
|
12
13
|
submitControlOf,
|
|
13
14
|
withoutRefs
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-VBWOSSGY.js";
|
|
15
16
|
|
|
16
17
|
// src/cli.ts
|
|
17
18
|
import { Command, InvalidArgumentError } from "commander";
|
|
@@ -121,6 +122,7 @@ steps:
|
|
|
121
122
|
var GITIGNORE = `# blastproof runtime artifacts
|
|
122
123
|
reports/
|
|
123
124
|
sessions/
|
|
125
|
+
cache/
|
|
124
126
|
|
|
125
127
|
# Captured sessions are live credentials \u2014 never commit them.
|
|
126
128
|
.auth-state.json
|
|
@@ -215,11 +217,11 @@ function formatInitGuidance(result) {
|
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
// src/commands/plan.ts
|
|
218
|
-
import
|
|
220
|
+
import path12 from "path";
|
|
219
221
|
|
|
220
222
|
// src/auth.ts
|
|
221
|
-
import { readFile, writeFile as
|
|
222
|
-
import
|
|
223
|
+
import { readFile as readFile2, writeFile as writeFile3, mkdir as mkdir4 } from "fs/promises";
|
|
224
|
+
import path4 from "path";
|
|
223
225
|
|
|
224
226
|
// src/runner/authoring.ts
|
|
225
227
|
var VALUE_VERBS = ["fill", "enter", "type", "input", "set"];
|
|
@@ -556,8 +558,8 @@ var SecretsMask = class {
|
|
|
556
558
|
};
|
|
557
559
|
|
|
558
560
|
// src/runner/executor.ts
|
|
559
|
-
import { mkdir as
|
|
560
|
-
import
|
|
561
|
+
import { mkdir as mkdir3 } from "fs/promises";
|
|
562
|
+
import path3 from "path";
|
|
561
563
|
|
|
562
564
|
// src/runner/recovery.ts
|
|
563
565
|
var COMMIT_ACTIONS = /* @__PURE__ */ new Set(["click", "press"]);
|
|
@@ -702,11 +704,13 @@ var StepRecovery = class {
|
|
|
702
704
|
return this.history.length > 0;
|
|
703
705
|
}
|
|
704
706
|
/** Records an action that was actually performed and succeeded. */
|
|
705
|
-
record(action, description, result, activates) {
|
|
707
|
+
record(action, description, result, activates, answers) {
|
|
706
708
|
const commit = commitIdentity(action, activates);
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
709
|
+
if (answers === void 0) {
|
|
710
|
+
this.performed.add(identity(action));
|
|
711
|
+
this.performed.add(commit);
|
|
712
|
+
if (isCommit(action)) this.commitPages.set(commit, this.lastObserved);
|
|
713
|
+
}
|
|
710
714
|
const named = activatedControl(action, activates) !== void 0;
|
|
711
715
|
this.lastSuccess = { commit, own: identity(action), named, page: this.lastObserved, action };
|
|
712
716
|
this.history.push({ action: description, result });
|
|
@@ -728,8 +732,12 @@ var StepRecovery = class {
|
|
|
728
732
|
* allowed duplicate commit costs a silent extra row in someone's database,
|
|
729
733
|
* and #28 has now produced one on three applications.
|
|
730
734
|
*/
|
|
731
|
-
refusalFor(action, activates) {
|
|
732
|
-
return
|
|
735
|
+
refusalFor(action, activates, answers) {
|
|
736
|
+
return (
|
|
737
|
+
// A check may answer an alert, which has one button and decides nothing
|
|
738
|
+
// (design answer-native-dialogs, D6); no other dialog.
|
|
739
|
+
(answers === "alert" ? void 0 : this.verificationRefusal(action)) ?? (answers === void 0 ? this.repeatedCommitRefusal(action, activates) : void 0) ?? this.redactionLabelRefusal(action) ?? this.unsourcedValueRefusal(action)
|
|
740
|
+
);
|
|
733
741
|
}
|
|
734
742
|
/**
|
|
735
743
|
* Refuses a typed value containing a redaction label (design
|
|
@@ -861,6 +869,441 @@ var StepRecovery = class {
|
|
|
861
869
|
}
|
|
862
870
|
};
|
|
863
871
|
|
|
872
|
+
// src/runner/dialog.ts
|
|
873
|
+
var FrameMap = class {
|
|
874
|
+
frames = /* @__PURE__ */ new Map();
|
|
875
|
+
load(tree, parent) {
|
|
876
|
+
this.frames.set(tree.frame.id, { parent, url: tree.frame.url });
|
|
877
|
+
for (const child of tree.childFrames ?? []) this.load(child, tree.frame.id);
|
|
878
|
+
}
|
|
879
|
+
attached(id, parent) {
|
|
880
|
+
const known = this.frames.get(id);
|
|
881
|
+
this.frames.set(id, { ...known, parent });
|
|
882
|
+
}
|
|
883
|
+
navigated(id, parent, url) {
|
|
884
|
+
this.frames.set(id, { parent, url });
|
|
885
|
+
}
|
|
886
|
+
detached(id) {
|
|
887
|
+
this.frames.delete(id);
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* The URL a frame's origin is judged by: its own, or for an `about:` frame,
|
|
891
|
+
* or one created and not yet navigated, the first ancestor's that is not
|
|
892
|
+
* `about:`. Such a frame inherits the origin of the page that made it, so a
|
|
893
|
+
* frame of another origin could otherwise open a dialog from a child it
|
|
894
|
+
* created and be judged as `about:blank`. `undefined` for an unknown frame.
|
|
895
|
+
*/
|
|
896
|
+
urlFor(id) {
|
|
897
|
+
const seen = /* @__PURE__ */ new Set();
|
|
898
|
+
let at = id;
|
|
899
|
+
while (at !== void 0 && !seen.has(at)) {
|
|
900
|
+
seen.add(at);
|
|
901
|
+
const frame = this.frames.get(at);
|
|
902
|
+
if (!frame) return void 0;
|
|
903
|
+
if (frame.url !== void 0 && !frame.url.startsWith("about:")) return frame.url;
|
|
904
|
+
if (frame.parent === void 0) return frame.url;
|
|
905
|
+
at = frame.parent;
|
|
906
|
+
}
|
|
907
|
+
return void 0;
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
var DIALOG_ATTRIBUTION_MS = 1e3;
|
|
911
|
+
var BEFOREUNLOAD_NAME = "This page asks you to confirm that you want to leave";
|
|
912
|
+
var KINDS = /* @__PURE__ */ new Set(["alert", "confirm", "prompt", "beforeunload"]);
|
|
913
|
+
var DIALOG_REF = /^d\d+b\d+$/;
|
|
914
|
+
function isDialogRef(ref) {
|
|
915
|
+
if (ref === void 0) return false;
|
|
916
|
+
return DIALOG_REF.test(ref.trim().replace(/^\[/, "").replace(/^ref=/, "").replace(/\]$/, ""));
|
|
917
|
+
}
|
|
918
|
+
function quoted(text) {
|
|
919
|
+
return `"${text.replace(/\s*\n\s*/g, " ").replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
920
|
+
}
|
|
921
|
+
function controlsOf(open) {
|
|
922
|
+
const ref = (n) => `d${open.seq}b${n}`;
|
|
923
|
+
switch (open.kind) {
|
|
924
|
+
case "alert":
|
|
925
|
+
return [{ ref: ref(1), role: "button", name: "OK", answer: "accept" }];
|
|
926
|
+
case "confirm":
|
|
927
|
+
return [
|
|
928
|
+
{ ref: ref(1), role: "button", name: "OK", answer: "accept" },
|
|
929
|
+
{ ref: ref(2), role: "button", name: "Cancel", answer: "dismiss" }
|
|
930
|
+
];
|
|
931
|
+
case "prompt":
|
|
932
|
+
return [
|
|
933
|
+
{ ref: ref(1), role: "textbox", name: open.message },
|
|
934
|
+
{ ref: ref(2), role: "button", name: "OK", answer: "accept" },
|
|
935
|
+
{ ref: ref(3), role: "button", name: "Cancel", answer: "dismiss" }
|
|
936
|
+
];
|
|
937
|
+
case "beforeunload":
|
|
938
|
+
return [
|
|
939
|
+
{ ref: ref(1), role: "button", name: "Leave", answer: "accept" },
|
|
940
|
+
{ ref: ref(2), role: "button", name: "Stay", answer: "dismiss" }
|
|
941
|
+
];
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
function nameOf(open) {
|
|
945
|
+
return open.kind === "beforeunload" ? BEFOREUNLOAD_NAME : open.message;
|
|
946
|
+
}
|
|
947
|
+
var DialogWatch = class {
|
|
948
|
+
constructor(allowed, onHidden, attributionMs = DIALOG_ATTRIBUTION_MS, resolveFrame) {
|
|
949
|
+
this.allowed = allowed;
|
|
950
|
+
this.onHidden = onHidden;
|
|
951
|
+
this.attributionMs = attributionMs;
|
|
952
|
+
this.resolveFrame = resolveFrame;
|
|
953
|
+
}
|
|
954
|
+
allowed;
|
|
955
|
+
onHidden;
|
|
956
|
+
attributionMs;
|
|
957
|
+
resolveFrame;
|
|
958
|
+
open;
|
|
959
|
+
seq = 0;
|
|
960
|
+
openers = /* @__PURE__ */ new Set();
|
|
961
|
+
sources = [];
|
|
962
|
+
/** Dialogs still being attributed, so a dismissal can wait for them (finding 6). */
|
|
963
|
+
attributing = /* @__PURE__ */ new Set();
|
|
964
|
+
closed = false;
|
|
965
|
+
sourceWaiters = /* @__PURE__ */ new Set();
|
|
966
|
+
/** The rest of each action a dialog interrupted (D4), settled after the answer. */
|
|
967
|
+
pending = [];
|
|
968
|
+
closers = [];
|
|
969
|
+
get isOpen() {
|
|
970
|
+
return this.open !== void 0;
|
|
971
|
+
}
|
|
972
|
+
/** Records the frame Chromium says opened a dialog (D5). */
|
|
973
|
+
noteSource(source) {
|
|
974
|
+
this.sources.push({ ...source, at: Date.now() });
|
|
975
|
+
for (const wake of this.sourceWaiters) wake();
|
|
976
|
+
}
|
|
977
|
+
/** Playwright's `dialog` event: hold it, or dismiss it unseen (D5). */
|
|
978
|
+
receive(dialog) {
|
|
979
|
+
const receiving = this.hold(dialog);
|
|
980
|
+
this.attributing.add(receiving);
|
|
981
|
+
void receiving.finally(() => this.attributing.delete(receiving));
|
|
982
|
+
return receiving;
|
|
983
|
+
}
|
|
984
|
+
async hold(dialog) {
|
|
985
|
+
const kind = dialog.type();
|
|
986
|
+
const url = await this.sourceOf(dialog);
|
|
987
|
+
if (this.closed) {
|
|
988
|
+
await dialog.dismiss().catch(() => void 0);
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
if (!KINDS.has(kind) || url === void 0 || !isOriginAllowed(url, this.allowed)) {
|
|
992
|
+
this.onHidden?.(url === void 0 ? void 0 : originOf(url));
|
|
993
|
+
await dialog.dismiss().catch(() => void 0);
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
const previous = this.open;
|
|
997
|
+
this.seq++;
|
|
998
|
+
this.open = { dialog, kind, message: dialog.message(), seq: this.seq, value: dialog.defaultValue() };
|
|
999
|
+
if (previous) await previous.dialog.dismiss().catch(() => void 0);
|
|
1000
|
+
for (const wake of this.openers) wake();
|
|
1001
|
+
}
|
|
1002
|
+
async sourceOf(dialog) {
|
|
1003
|
+
const deadline = Date.now() + this.attributionMs;
|
|
1004
|
+
while (true) {
|
|
1005
|
+
const stale = Date.now() - 2 * this.attributionMs;
|
|
1006
|
+
this.sources = this.sources.filter((source) => source.at >= stale);
|
|
1007
|
+
const at = this.sources.findIndex((source) => source.type === dialog.type() && source.message === dialog.message());
|
|
1008
|
+
if (at >= 0) {
|
|
1009
|
+
const source = this.sources.splice(at, 1)[0];
|
|
1010
|
+
if (!source.url.startsWith("about:")) return source.url;
|
|
1011
|
+
if (source.frameId === void 0 || this.resolveFrame === void 0) return void 0;
|
|
1012
|
+
return this.resolveFrame(source.frameId);
|
|
1013
|
+
}
|
|
1014
|
+
const left = deadline - Date.now();
|
|
1015
|
+
if (left <= 0) return void 0;
|
|
1016
|
+
await new Promise((resolve) => {
|
|
1017
|
+
const wake = () => {
|
|
1018
|
+
clearTimeout(timer);
|
|
1019
|
+
this.sourceWaiters.delete(wake);
|
|
1020
|
+
resolve();
|
|
1021
|
+
};
|
|
1022
|
+
const timer = setTimeout(wake, left);
|
|
1023
|
+
this.sourceWaiters.add(wake);
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Waits for `work`, or for a dialog to open, whichever comes first (D4). When
|
|
1029
|
+
* a dialog opens, `work` is left running and handed back as `rest`: it
|
|
1030
|
+
* settles once the dialog is answered.
|
|
1031
|
+
*/
|
|
1032
|
+
async race(work) {
|
|
1033
|
+
if (this.open) {
|
|
1034
|
+
work.catch(() => void 0);
|
|
1035
|
+
return { opened: true, rest: work };
|
|
1036
|
+
}
|
|
1037
|
+
let wake = () => void 0;
|
|
1038
|
+
const opened = new Promise((resolve) => {
|
|
1039
|
+
wake = () => resolve("opened");
|
|
1040
|
+
this.openers.add(wake);
|
|
1041
|
+
});
|
|
1042
|
+
try {
|
|
1043
|
+
const first = await Promise.race([work.then((value) => ({ value })), opened]);
|
|
1044
|
+
if (first === "opened") {
|
|
1045
|
+
work.catch(() => void 0);
|
|
1046
|
+
return { opened: true, rest: work };
|
|
1047
|
+
}
|
|
1048
|
+
return { opened: false, value: first.value };
|
|
1049
|
+
} finally {
|
|
1050
|
+
this.openers.delete(wake);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
/** Keeps the rest of an interrupted action, to settle after the answer (D4). */
|
|
1054
|
+
keep(rest) {
|
|
1055
|
+
this.pending.push(
|
|
1056
|
+
rest.then(
|
|
1057
|
+
() => void 0,
|
|
1058
|
+
(error) => error instanceof Error ? error.message : String(error)
|
|
1059
|
+
)
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Settles the rest of every interrupted action, unless another dialog opens
|
|
1064
|
+
* first, and returns what any of them failed with. Called after an answer and
|
|
1065
|
+
* before every wait for the page, so nothing of an action is still running
|
|
1066
|
+
* when the page is read (D4).
|
|
1067
|
+
*/
|
|
1068
|
+
async drain() {
|
|
1069
|
+
if (this.pending.length === 0 || this.open) return void 0;
|
|
1070
|
+
const waiting = this.pending;
|
|
1071
|
+
const raced = await this.race(Promise.all(waiting));
|
|
1072
|
+
if (raced.opened) return void 0;
|
|
1073
|
+
this.pending = this.pending.filter((entry) => !waiting.includes(entry));
|
|
1074
|
+
const errors = raced.value.filter((error) => error !== void 0);
|
|
1075
|
+
return errors.length === 0 ? void 0 : errors.join("; ");
|
|
1076
|
+
}
|
|
1077
|
+
/** The open dialog as snapshot lines, or `undefined` when none is open (D2). */
|
|
1078
|
+
lines() {
|
|
1079
|
+
const open = this.open;
|
|
1080
|
+
if (!open) return void 0;
|
|
1081
|
+
const out = [
|
|
1082
|
+
`- alertdialog ${quoted(nameOf(open))} [native ${open.kind}]:`,
|
|
1083
|
+
// The judge reads this too: a claim about the page cannot pass on it.
|
|
1084
|
+
" - text: The page behind this dialog cannot be seen until the dialog is answered."
|
|
1085
|
+
];
|
|
1086
|
+
for (const control of controlsOf(open)) {
|
|
1087
|
+
const value = control.role === "textbox" && open.value !== "" ? `: ${open.value.replace(/\s*\n\s*/g, " ")}` : "";
|
|
1088
|
+
out.push(` - ${control.role} ${quoted(control.name)} [ref=${control.ref}]${value}`);
|
|
1089
|
+
}
|
|
1090
|
+
return out.join("\n");
|
|
1091
|
+
}
|
|
1092
|
+
/** The open dialog's name, as its line shows it. */
|
|
1093
|
+
name() {
|
|
1094
|
+
return this.open ? nameOf(this.open) : void 0;
|
|
1095
|
+
}
|
|
1096
|
+
/** The kind of the open dialog. */
|
|
1097
|
+
kind() {
|
|
1098
|
+
return this.open?.kind;
|
|
1099
|
+
}
|
|
1100
|
+
/** The open dialog, as an action's result names it. */
|
|
1101
|
+
describe() {
|
|
1102
|
+
const open = this.open;
|
|
1103
|
+
return open ? `a native ${open.kind} dialog ${quoted(nameOf(open))}` : "a native dialog";
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* How the step's rules treat `action` (D6): `'alert'` or `'dialog'` when it
|
|
1107
|
+
* answers the open dialog, `undefined` when it acts on the page.
|
|
1108
|
+
*/
|
|
1109
|
+
answering(action) {
|
|
1110
|
+
if (!isDialogRef(action.target?.ref)) return void 0;
|
|
1111
|
+
return this.open?.kind === "alert" ? "alert" : "dialog";
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Performs an action on the open dialog (D3): a click on a button answers it,
|
|
1115
|
+
* a fill of a prompt's textbox sets the value its OK will send. `value` is
|
|
1116
|
+
* already resolved from its placeholder.
|
|
1117
|
+
*/
|
|
1118
|
+
async perform(action, value) {
|
|
1119
|
+
const open = this.open;
|
|
1120
|
+
const ref = action.target?.ref?.trim().replace(/^\[/, "").replace(/^ref=/, "").replace(/\]$/, "");
|
|
1121
|
+
const control = open ? controlsOf(open).find((candidate) => candidate.ref === ref) : void 0;
|
|
1122
|
+
if (!open || !control) {
|
|
1123
|
+
throw new ActionError(
|
|
1124
|
+
`Element not found: ref ${ref ?? "(none)"} belonged to a native dialog that is no longer open. Choose the element again from the fresh snapshot.`
|
|
1125
|
+
);
|
|
1126
|
+
}
|
|
1127
|
+
if (action.action === "fill" && control.role === "textbox") {
|
|
1128
|
+
open.value = value ?? "";
|
|
1129
|
+
return `ok: filled the textbox of ${this.describe()}`;
|
|
1130
|
+
}
|
|
1131
|
+
if (action.action === "click" && control.answer !== void 0) {
|
|
1132
|
+
const described = this.describe();
|
|
1133
|
+
this.open = void 0;
|
|
1134
|
+
if (control.answer === "accept") {
|
|
1135
|
+
await open.dialog.accept(open.kind === "prompt" ? open.value : void 0);
|
|
1136
|
+
return `ok: accepted ${described} (clicked "${control.name}")`;
|
|
1137
|
+
}
|
|
1138
|
+
await open.dialog.dismiss();
|
|
1139
|
+
return `ok: dismissed ${described} (clicked "${control.name}")`;
|
|
1140
|
+
}
|
|
1141
|
+
throw new ActionError(
|
|
1142
|
+
`${action.action} cannot act on ${control.role} "${control.name}" of ${this.describe()}: a native dialog is answered by clicking one of its buttons${open.kind === "prompt" ? ", after filling its textbox if the step gives a value" : ""}.`
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
/** Dismisses a dialog still open, so the page can close or be captured (D8). */
|
|
1146
|
+
async dismissOpen() {
|
|
1147
|
+
await Promise.all([...this.attributing]);
|
|
1148
|
+
const open = this.open;
|
|
1149
|
+
if (!open) return;
|
|
1150
|
+
this.open = void 0;
|
|
1151
|
+
await open.dialog.dismiss().catch(() => void 0);
|
|
1152
|
+
}
|
|
1153
|
+
/** Dismisses what is open and stops listening (D8). */
|
|
1154
|
+
async close() {
|
|
1155
|
+
this.closed = true;
|
|
1156
|
+
await this.dismissOpen();
|
|
1157
|
+
for (const closer of this.closers.splice(0)) {
|
|
1158
|
+
try {
|
|
1159
|
+
await closer();
|
|
1160
|
+
} catch {
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
/** Registers what {@link close} undoes. */
|
|
1165
|
+
onClose(closer) {
|
|
1166
|
+
this.closers.push(closer);
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
function originOf(url) {
|
|
1170
|
+
try {
|
|
1171
|
+
const origin = new URL(url).origin;
|
|
1172
|
+
return origin === "null" ? void 0 : origin;
|
|
1173
|
+
} catch {
|
|
1174
|
+
return void 0;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
async function watchDialogs(page, allowed, onHidden, attributionMs = DIALOG_ATTRIBUTION_MS) {
|
|
1178
|
+
const target = page;
|
|
1179
|
+
if (typeof target.on !== "function") return new DialogWatch(allowed, onHidden, attributionMs);
|
|
1180
|
+
let session;
|
|
1181
|
+
try {
|
|
1182
|
+
session = await target.context().newCDPSession(page);
|
|
1183
|
+
} catch {
|
|
1184
|
+
}
|
|
1185
|
+
const frames = new FrameMap();
|
|
1186
|
+
const watch = new DialogWatch(allowed, onHidden, attributionMs, session ? (id) => frames.urlFor(id) : void 0);
|
|
1187
|
+
if (session) {
|
|
1188
|
+
watch.onClose(() => session.detach());
|
|
1189
|
+
try {
|
|
1190
|
+
session.on("Page.javascriptDialogOpening", (source) => watch.noteSource(source));
|
|
1191
|
+
session.on(
|
|
1192
|
+
"Page.frameAttached",
|
|
1193
|
+
(event) => frames.attached(event.frameId, event.parentFrameId)
|
|
1194
|
+
);
|
|
1195
|
+
session.on(
|
|
1196
|
+
"Page.frameNavigated",
|
|
1197
|
+
(event) => frames.navigated(event.frame.id, event.frame.parentId, event.frame.url)
|
|
1198
|
+
);
|
|
1199
|
+
session.on("Page.frameDetached", (event) => frames.detached(event.frameId));
|
|
1200
|
+
await session.send("Page.enable");
|
|
1201
|
+
const { frameTree } = await session.send("Page.getFrameTree");
|
|
1202
|
+
frames.load(frameTree);
|
|
1203
|
+
} catch {
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
const listener = (dialog) => void watch.receive(dialog);
|
|
1207
|
+
target.on("dialog", listener);
|
|
1208
|
+
watch.onClose(() => target.off?.("dialog", listener));
|
|
1209
|
+
return watch;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// src/runner/replay.ts
|
|
1213
|
+
import { createHash } from "crypto";
|
|
1214
|
+
import { mkdir as mkdir2, readFile, rename, writeFile as writeFile2 } from "fs/promises";
|
|
1215
|
+
import path2 from "path";
|
|
1216
|
+
var REPLAY_VERSION = 1;
|
|
1217
|
+
function stepKey(index, setup, written, judged) {
|
|
1218
|
+
return createHash("sha256").update(JSON.stringify([index, setup, written, judged])).digest("hex").slice(0, 32);
|
|
1219
|
+
}
|
|
1220
|
+
function normalise2(text) {
|
|
1221
|
+
return (text ?? "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
1222
|
+
}
|
|
1223
|
+
function refOf(saved, refs) {
|
|
1224
|
+
let found;
|
|
1225
|
+
for (const [ref, element] of refs) {
|
|
1226
|
+
if (normalise2(element.role) !== normalise2(saved.role)) continue;
|
|
1227
|
+
if (normalise2(element.name ?? element.text) !== normalise2(saved.name)) continue;
|
|
1228
|
+
if (found !== void 0) return void 0;
|
|
1229
|
+
found = ref;
|
|
1230
|
+
}
|
|
1231
|
+
return found;
|
|
1232
|
+
}
|
|
1233
|
+
var REPLAYED = "replayed from the last passing run";
|
|
1234
|
+
function replayedDecision(entry, at, refs, openDialog) {
|
|
1235
|
+
const saved = entry.actions[at];
|
|
1236
|
+
if (saved === void 0) {
|
|
1237
|
+
return entry.close.by === "done" ? { action: "done", reasoning: REPLAYED } : { action: "assert", expectation: entry.close.claim, reasoning: REPLAYED };
|
|
1238
|
+
}
|
|
1239
|
+
if (saved.dialog === void 0 !== (openDialog === void 0)) return void 0;
|
|
1240
|
+
if (saved.dialog !== void 0 && normalise2(saved.dialog) !== normalise2(openDialog)) return void 0;
|
|
1241
|
+
const action = saved.action;
|
|
1242
|
+
if (saved.role === void 0) return { action, value: saved.value, reasoning: REPLAYED };
|
|
1243
|
+
const ref = refOf(saved, refs);
|
|
1244
|
+
if (ref === void 0) return void 0;
|
|
1245
|
+
const element = refs.get(ref);
|
|
1246
|
+
return {
|
|
1247
|
+
action,
|
|
1248
|
+
target: { ref, role: element.role, name: element.name ?? element.text },
|
|
1249
|
+
value: saved.value,
|
|
1250
|
+
reasoning: REPLAYED
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
function replayDir(cwd) {
|
|
1254
|
+
return path2.join(cwd, ".blastproof", "cache", "replay");
|
|
1255
|
+
}
|
|
1256
|
+
function replayFile(cwd, testPath) {
|
|
1257
|
+
const relative = path2.relative(cwd, testPath).split(path2.sep).join("/");
|
|
1258
|
+
const stem = path2.basename(testPath).replace(/\.ya?ml$/i, "").replace(/[^a-zA-Z0-9_-]+/g, "-").slice(0, 60);
|
|
1259
|
+
const hash = createHash("sha256").update(relative).digest("hex").slice(0, 12);
|
|
1260
|
+
return path2.join(replayDir(cwd), `${stem}-${hash}.json`);
|
|
1261
|
+
}
|
|
1262
|
+
var PERFORMED_ACTIONS = /* @__PURE__ */ new Set(["navigate", "click", "fill", "press", "select", "hover"]);
|
|
1263
|
+
var optionalString = (value) => value === void 0 || typeof value === "string";
|
|
1264
|
+
function isSavedAction(value) {
|
|
1265
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1266
|
+
const action = value;
|
|
1267
|
+
return typeof action.action === "string" && PERFORMED_ACTIONS.has(action.action) && typeof action.changed === "boolean" && optionalString(action.role) && optionalString(action.name) && optionalString(action.value) && optionalString(action.dialog);
|
|
1268
|
+
}
|
|
1269
|
+
function isSavedStep(value) {
|
|
1270
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1271
|
+
const step = value;
|
|
1272
|
+
const close = step.close;
|
|
1273
|
+
return typeof step.key === "string" && Array.isArray(step.actions) && step.actions.every(isSavedAction) && typeof close === "object" && close !== null && (close.by === "done" || close.by === "judgment" && typeof close.claim === "string");
|
|
1274
|
+
}
|
|
1275
|
+
async function loadReplay(file, device) {
|
|
1276
|
+
try {
|
|
1277
|
+
const parsed = JSON.parse(await readFile(file, "utf8"));
|
|
1278
|
+
if (parsed.version !== REPLAY_VERSION || !Array.isArray(parsed.steps)) return [];
|
|
1279
|
+
if ((parsed.device ?? void 0) !== device) return [];
|
|
1280
|
+
return parsed.steps.filter(isSavedStep);
|
|
1281
|
+
} catch {
|
|
1282
|
+
return [];
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
function stepsToSave(passed, before, outcome) {
|
|
1286
|
+
if (passed) return outcome.steps;
|
|
1287
|
+
if (outcome.ended.length === 0) return void 0;
|
|
1288
|
+
const ended = new Set(outcome.ended);
|
|
1289
|
+
return before.filter((step) => !ended.has(step.key));
|
|
1290
|
+
}
|
|
1291
|
+
async function saveReplay(file, device, steps) {
|
|
1292
|
+
const body = { version: REPLAY_VERSION, ...device ? { device } : {}, steps };
|
|
1293
|
+
await mkdir2(path2.dirname(file), { recursive: true });
|
|
1294
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
1295
|
+
await writeFile2(temporary, `${JSON.stringify(body, null, 2)}
|
|
1296
|
+
`, "utf8");
|
|
1297
|
+
await rename(temporary, file);
|
|
1298
|
+
}
|
|
1299
|
+
function replaySummary(decided) {
|
|
1300
|
+
const replayed = decided.filter((d) => d === "replayed").length;
|
|
1301
|
+
const healed = decided.filter((d) => d === "healed").length;
|
|
1302
|
+
const model = decided.filter((d) => d === "model").length + healed;
|
|
1303
|
+
const steps = (n) => `${n} ${n === 1 ? "step" : "steps"}`;
|
|
1304
|
+
return `Replay: ${steps(replayed)} replayed, ${model} resolved by the model${healed > 0 ? ` (${healed} healed)` : ""}`;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
864
1307
|
// src/runner/executor.ts
|
|
865
1308
|
var DEFAULT_MAX_ITERATIONS_PER_STEP = 15;
|
|
866
1309
|
var SETTLE_TIMEOUT_MS = 2e3;
|
|
@@ -879,7 +1322,7 @@ async function waitForSettled(page) {
|
|
|
879
1322
|
}
|
|
880
1323
|
}
|
|
881
1324
|
async function defaultSnapshot(page, maxLines, frames) {
|
|
882
|
-
const { captureSnapshot } = await import("./snapshot-
|
|
1325
|
+
const { captureSnapshot } = await import("./snapshot-RHSNLK3X.js");
|
|
883
1326
|
return captureSnapshot(page, { maxLines, frames });
|
|
884
1327
|
}
|
|
885
1328
|
function slugify(text) {
|
|
@@ -914,7 +1357,32 @@ function pageChangeNote(before, after) {
|
|
|
914
1357
|
const lines = [...removed.map((line) => `- ${line.trim()}`), ...added.map((line) => `+ ${line.trim()}`)];
|
|
915
1358
|
return ` (after it, the only change on the page: ${lines.join("; ")})`;
|
|
916
1359
|
}
|
|
1360
|
+
function dialogAnswerNote(before, after) {
|
|
1361
|
+
const unfocused = (page) => page.replace(/ \[active\]/g, "");
|
|
1362
|
+
const note = pageChangeNote(unfocused(before), unfocused(after));
|
|
1363
|
+
return note === " (after it, the page did not change at all)" ? " (the dialog is closed, and the page behind it is as it was before the dialog opened)" : note?.replace(" (after it, the only change on the page:", " (the dialog is closed; the only change on the page since before it opened:");
|
|
1364
|
+
}
|
|
1365
|
+
function pageDiffers(before, after) {
|
|
1366
|
+
const lines = (page) => new Set(page.replace(/ \[active\]/g, "").split("\n"));
|
|
1367
|
+
const a = lines(before);
|
|
1368
|
+
const b = lines(after);
|
|
1369
|
+
if (a.size !== b.size) return true;
|
|
1370
|
+
for (const line of a) if (!b.has(line)) return true;
|
|
1371
|
+
return false;
|
|
1372
|
+
}
|
|
917
1373
|
async function executeTest(page, test, options) {
|
|
1374
|
+
const dialogs = await watchDialogs(
|
|
1375
|
+
page,
|
|
1376
|
+
allowedOriginsFor(options.baseUrl, options.allowedOrigins),
|
|
1377
|
+
options.onHiddenDialog
|
|
1378
|
+
);
|
|
1379
|
+
try {
|
|
1380
|
+
return await runTest(page, test, options, dialogs);
|
|
1381
|
+
} finally {
|
|
1382
|
+
await dialogs.close();
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
async function runTest(page, test, options, dialogs) {
|
|
918
1386
|
const {
|
|
919
1387
|
brain,
|
|
920
1388
|
sessionDir,
|
|
@@ -931,10 +1399,38 @@ async function executeTest(page, test, options) {
|
|
|
931
1399
|
onEvent = () => {
|
|
932
1400
|
},
|
|
933
1401
|
onHiddenFrame,
|
|
934
|
-
submitControl = submitControlOf
|
|
1402
|
+
submitControl = submitControlOf,
|
|
1403
|
+
replay
|
|
935
1404
|
} = options;
|
|
1405
|
+
const savedByKey = new Map((replay?.saved ?? []).map((entry) => [entry.key, entry]));
|
|
1406
|
+
const replayOutcome = { steps: [], ended: [] };
|
|
936
1407
|
const boundary = allowedOriginsFor(baseUrl, allowedOrigins);
|
|
937
|
-
const
|
|
1408
|
+
const pageSnapshot = snapshot ?? ((page2) => defaultSnapshot(page2, maxSnapshotLines, { allowed: boundary, onHidden: onHiddenFrame }));
|
|
1409
|
+
let lastPageView;
|
|
1410
|
+
let pageBeforeDialog;
|
|
1411
|
+
const takeSnapshot = async (page2) => {
|
|
1412
|
+
const shown = dialogs.lines();
|
|
1413
|
+
if (shown !== void 0) {
|
|
1414
|
+
pageBeforeDialog ??= lastPageView;
|
|
1415
|
+
return shown;
|
|
1416
|
+
}
|
|
1417
|
+
const raced = await dialogs.race(pageSnapshot(page2));
|
|
1418
|
+
if (raced.opened) {
|
|
1419
|
+
dialogs.keep(raced.rest);
|
|
1420
|
+
pageBeforeDialog ??= lastPageView;
|
|
1421
|
+
return dialogs.lines();
|
|
1422
|
+
}
|
|
1423
|
+
lastPageView = withoutRefs(mask(raced.value));
|
|
1424
|
+
return raced.value;
|
|
1425
|
+
};
|
|
1426
|
+
const settle = async () => {
|
|
1427
|
+
const late = await dialogs.drain();
|
|
1428
|
+
if (!dialogs.isOpen) {
|
|
1429
|
+
const raced = await dialogs.race(waitForSettled(page));
|
|
1430
|
+
if (raced.opened) dialogs.keep(raced.rest);
|
|
1431
|
+
}
|
|
1432
|
+
return late;
|
|
1433
|
+
};
|
|
938
1434
|
const startedAt = Date.now();
|
|
939
1435
|
const stepResults = [];
|
|
940
1436
|
const allSteps = [
|
|
@@ -951,7 +1447,8 @@ async function executeTest(page, test, options) {
|
|
|
951
1447
|
onEvent({ type: "action", index, action: maskedAction, result: mask(result) });
|
|
952
1448
|
};
|
|
953
1449
|
let failure;
|
|
954
|
-
await page.goto(new URL(baseUrl).toString());
|
|
1450
|
+
const opening = await dialogs.race(page.goto(new URL(baseUrl).toString()));
|
|
1451
|
+
if (opening.opened) dialogs.keep(opening.rest);
|
|
955
1452
|
const usedEarlier = /* @__PURE__ */ new Set();
|
|
956
1453
|
for (let index = 0; index < allSteps.length; index++) {
|
|
957
1454
|
const { step: written, setup } = allSteps[index];
|
|
@@ -961,6 +1458,12 @@ async function executeTest(page, test, options) {
|
|
|
961
1458
|
onEvent({ type: "step-start", index, total: allSteps.length, step: mask(written), setup });
|
|
962
1459
|
let iterations = 0;
|
|
963
1460
|
let failedAttempts = 0;
|
|
1461
|
+
let failuresOnPage = 0;
|
|
1462
|
+
let firstFailure;
|
|
1463
|
+
const failedOnPage = (result) => {
|
|
1464
|
+
failuresOnPage++;
|
|
1465
|
+
firstFailure ??= mask(result ?? "");
|
|
1466
|
+
};
|
|
964
1467
|
let lastResult;
|
|
965
1468
|
let stepFailedReason;
|
|
966
1469
|
let lastSnapshot;
|
|
@@ -968,25 +1471,68 @@ async function executeTest(page, test, options) {
|
|
|
968
1471
|
const recovery = new StepRecovery(written, step);
|
|
969
1472
|
const agentRecord = [];
|
|
970
1473
|
let pageActedOn;
|
|
1474
|
+
let answeredDialog = false;
|
|
1475
|
+
const key = stepKey(index, setup, written, step);
|
|
1476
|
+
let live = replay ? savedByKey.get(key) : void 0;
|
|
1477
|
+
const hadSaved = live !== void 0;
|
|
1478
|
+
let replayAt = 0;
|
|
1479
|
+
const performed = [];
|
|
1480
|
+
let closed;
|
|
1481
|
+
let lastReplayed;
|
|
1482
|
+
let watchedAfter = -1;
|
|
1483
|
+
const endReplay = (why) => {
|
|
1484
|
+
if (live === void 0) return;
|
|
1485
|
+
live = void 0;
|
|
1486
|
+
lastReplayed = void 0;
|
|
1487
|
+
replayOutcome.ended.push(key);
|
|
1488
|
+
onEvent({ type: "replay-ended", index, reason: mask(why) });
|
|
1489
|
+
};
|
|
971
1490
|
try {
|
|
972
1491
|
while (true) {
|
|
973
1492
|
if (iterations >= maxIterationsPerStep) {
|
|
974
1493
|
throw new StepFailure(`step exceeded ${maxIterationsPerStep} actions without completing`);
|
|
975
1494
|
}
|
|
976
|
-
await
|
|
1495
|
+
const late = await settle();
|
|
1496
|
+
if (late !== void 0 && lastResult !== void 0) {
|
|
1497
|
+
const failed = `; after the dialog was answered, the action that opened it failed: ${mask(late)}`;
|
|
1498
|
+
failedOnPage(`error: ${late}`);
|
|
1499
|
+
lastResult += failed;
|
|
1500
|
+
const acted = agentRecord[agentRecord.length - 1];
|
|
1501
|
+
if (acted !== void 0) acted.result += failed;
|
|
1502
|
+
}
|
|
977
1503
|
if (!isOriginAllowed(page.url(), boundary)) {
|
|
978
1504
|
throw new StepFailure(
|
|
979
1505
|
`The page left the application: ${page.url()} is outside ${describeBoundary(boundary)}. Add it to allowed_origins in .blastproof/config.yaml if the app legitimately spans hosts.`
|
|
980
1506
|
);
|
|
981
1507
|
}
|
|
982
1508
|
const snap = await takeSnapshot(page);
|
|
1509
|
+
if (pageActedOn !== void 0 && lastReplayed?.changed && !pageDiffers(pageActedOn, withoutRefs(mask(snap)))) {
|
|
1510
|
+
if (watchedAfter !== performed.length) {
|
|
1511
|
+
watchedAfter = performed.length;
|
|
1512
|
+
const deadline = Date.now() + renderWatchMs;
|
|
1513
|
+
let moved = false;
|
|
1514
|
+
while (!moved && Date.now() < deadline) {
|
|
1515
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(RENDER_POLL_MS, Math.max(0, deadline - Date.now()))));
|
|
1516
|
+
if (!isOriginAllowed(page.url(), boundary)) break;
|
|
1517
|
+
moved = pageDiffers(pageActedOn, withoutRefs(mask(await takeSnapshot(page))));
|
|
1518
|
+
}
|
|
1519
|
+
if (moved || !isOriginAllowed(page.url(), boundary)) continue;
|
|
1520
|
+
}
|
|
1521
|
+
endReplay("the page did not change after an action that had changed it");
|
|
1522
|
+
}
|
|
983
1523
|
lastSnapshot = snap;
|
|
984
1524
|
const maskedSnap = mask(snap);
|
|
985
1525
|
const refs = indexRefs(maskedSnap);
|
|
986
1526
|
const pageSnap = withoutRefs(maskedSnap);
|
|
987
1527
|
recovery.observe(pageSnap);
|
|
988
1528
|
if (pageActedOn !== void 0) {
|
|
989
|
-
const
|
|
1529
|
+
const acted = performed[performed.length - 1];
|
|
1530
|
+
if (acted !== void 0) acted.changed = pageDiffers(pageActedOn, pageSnap);
|
|
1531
|
+
lastReplayed = void 0;
|
|
1532
|
+
}
|
|
1533
|
+
if (pageActedOn !== void 0) {
|
|
1534
|
+
const note = answeredDialog ? dialogs.isOpen ? void 0 : dialogAnswerNote(pageActedOn, pageSnap) : pageChangeNote(pageActedOn, pageSnap);
|
|
1535
|
+
answeredDialog = false;
|
|
990
1536
|
const acted = agentRecord[agentRecord.length - 1];
|
|
991
1537
|
if (note !== void 0 && acted !== void 0 && lastResult !== void 0) {
|
|
992
1538
|
acted.result += note;
|
|
@@ -995,7 +1541,11 @@ async function executeTest(page, test, options) {
|
|
|
995
1541
|
pageActedOn = void 0;
|
|
996
1542
|
}
|
|
997
1543
|
let action;
|
|
998
|
-
|
|
1544
|
+
const saved = live === void 0 ? void 0 : replayedDecision(live, replayAt, refs, dialogs.isOpen ? mask(dialogs.name()) : void 0);
|
|
1545
|
+
if (live !== void 0 && saved === void 0) endReplay("a saved element is not on the page exactly once");
|
|
1546
|
+
const replayed = saved !== void 0;
|
|
1547
|
+
if (saved !== void 0) action = saved;
|
|
1548
|
+
else try {
|
|
999
1549
|
action = await brain.nextAction({
|
|
1000
1550
|
// As written, never joined (design an-action-step-takes-the-next-check,
|
|
1001
1551
|
// D2): a model told the check acts to make it true (#139).
|
|
@@ -1021,10 +1571,29 @@ async function executeTest(page, test, options) {
|
|
|
1021
1571
|
iterations++;
|
|
1022
1572
|
let judgingDone = false;
|
|
1023
1573
|
const shown = () => judgingDone ? { ...action, action: "done" } : action;
|
|
1574
|
+
if (action.action === "done" && dialogs.isOpen && dialogs.kind() !== "alert") {
|
|
1575
|
+
lastResult = `refused: ${dialogs.describe()} is still open, so the step was NOT closed. If this step says how to answer it, click that button. If it does not, assert that the dialog is shown, and leave the answer to the step that names it.`;
|
|
1576
|
+
if (replayed) {
|
|
1577
|
+
endReplay("its saved close came while a dialog was open");
|
|
1578
|
+
lastResult = void 0;
|
|
1579
|
+
continue;
|
|
1580
|
+
}
|
|
1581
|
+
failedAttempts++;
|
|
1582
|
+
failedOnPage(lastResult);
|
|
1583
|
+
emitAction(index, action, lastResult);
|
|
1584
|
+
if (failedAttempts >= maxRetries) throw new StepFailure(lastResult);
|
|
1585
|
+
continue;
|
|
1586
|
+
}
|
|
1024
1587
|
if (action.action === "done") {
|
|
1025
1588
|
if (!recovery.acted || recovery.verifies) {
|
|
1026
|
-
failedAttempts++;
|
|
1027
1589
|
lastResult = recovery.verifies ? VERIFICATION_DONE_REFUSAL : NOTHING_DONE_REFUSAL;
|
|
1590
|
+
if (replayed) {
|
|
1591
|
+
endReplay("its saved close is not allowed for this step");
|
|
1592
|
+
lastResult = void 0;
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
failedAttempts++;
|
|
1596
|
+
failedOnPage(lastResult);
|
|
1028
1597
|
emitAction(index, action, lastResult);
|
|
1029
1598
|
if (failedAttempts >= maxRetries) {
|
|
1030
1599
|
throw new StepFailure(lastResult);
|
|
@@ -1033,6 +1602,7 @@ async function executeTest(page, test, options) {
|
|
|
1033
1602
|
}
|
|
1034
1603
|
if (!recovery.checksAfterActing) {
|
|
1035
1604
|
emitAction(index, action, action.reasoning);
|
|
1605
|
+
closed = { by: "done" };
|
|
1036
1606
|
break;
|
|
1037
1607
|
}
|
|
1038
1608
|
judgingDone = true;
|
|
@@ -1065,7 +1635,7 @@ async function executeTest(page, test, options) {
|
|
|
1065
1635
|
[...usedEarlier]
|
|
1066
1636
|
);
|
|
1067
1637
|
if (!judgment.pass) {
|
|
1068
|
-
await
|
|
1638
|
+
await settle();
|
|
1069
1639
|
const freshSnap = await takeSnapshot(page);
|
|
1070
1640
|
lastSnapshot = freshSnap;
|
|
1071
1641
|
const maskedFresh = withoutRefs(mask(freshSnap));
|
|
@@ -1080,9 +1650,13 @@ async function executeTest(page, test, options) {
|
|
|
1080
1650
|
}
|
|
1081
1651
|
} catch (error) {
|
|
1082
1652
|
if (error instanceof RunStoppedError) throw error;
|
|
1083
|
-
failedAttempts++;
|
|
1084
1653
|
lastResult = `error: ${error instanceof Error ? error.message : String(error)}`;
|
|
1085
1654
|
emitAction(index, shown(), lastResult);
|
|
1655
|
+
if (replayed) {
|
|
1656
|
+
endReplay("its judgment gave no answer");
|
|
1657
|
+
continue;
|
|
1658
|
+
}
|
|
1659
|
+
failedAttempts++;
|
|
1086
1660
|
if (failedAttempts >= maxRetries) {
|
|
1087
1661
|
throw new StepFailure(lastResult);
|
|
1088
1662
|
}
|
|
@@ -1095,9 +1669,16 @@ async function executeTest(page, test, options) {
|
|
|
1095
1669
|
emitAction(index, shown(), result);
|
|
1096
1670
|
if (judgment.pass) {
|
|
1097
1671
|
lastResult = result;
|
|
1672
|
+
closed = { by: "judgment", claim: mask(expectation) };
|
|
1098
1673
|
break;
|
|
1099
1674
|
}
|
|
1675
|
+
if (replayed) {
|
|
1676
|
+
lastResult = result;
|
|
1677
|
+
endReplay("the judgment of its saved claim failed");
|
|
1678
|
+
continue;
|
|
1679
|
+
}
|
|
1100
1680
|
failedAttempts++;
|
|
1681
|
+
failedOnPage(result);
|
|
1101
1682
|
lastResult = result;
|
|
1102
1683
|
if (failedAttempts >= maxRetries) {
|
|
1103
1684
|
throw new StepFailure(judgment.reason);
|
|
@@ -1107,19 +1688,40 @@ async function executeTest(page, test, options) {
|
|
|
1107
1688
|
try {
|
|
1108
1689
|
action = bindTarget(action, refs);
|
|
1109
1690
|
} catch (error) {
|
|
1110
|
-
failedAttempts++;
|
|
1111
1691
|
lastResult = error instanceof Error ? error.message : String(error);
|
|
1692
|
+
if (replayed) {
|
|
1693
|
+
endReplay(`a saved action was refused (${lastResult})`);
|
|
1694
|
+
lastResult = void 0;
|
|
1695
|
+
continue;
|
|
1696
|
+
}
|
|
1697
|
+
failedAttempts++;
|
|
1698
|
+
failedOnPage(lastResult);
|
|
1112
1699
|
emitAction(index, action, lastResult);
|
|
1113
1700
|
if (failedAttempts >= maxRetries) {
|
|
1114
1701
|
throw new StepFailure(lastResult);
|
|
1115
1702
|
}
|
|
1116
1703
|
continue;
|
|
1117
1704
|
}
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1705
|
+
const answers = dialogs.answering(action);
|
|
1706
|
+
let activates;
|
|
1707
|
+
if (answers === void 0 && !dialogs.isOpen) {
|
|
1708
|
+
const looked = await dialogs.race(submitControl(page, action, refs));
|
|
1709
|
+
activates = looked.opened ? void 0 : looked.value;
|
|
1710
|
+
if (looked.opened) void looked.rest.then((control) => control?.activated());
|
|
1711
|
+
}
|
|
1712
|
+
const refusal = answers === void 0 && dialogs.isOpen ? `refused: ${dialogs.describe()} is open, and nothing on the page can be reached until it is answered, so nothing was done. Click the dialog button the step calls for.` : recovery.refusalFor(action, activates, answers);
|
|
1713
|
+
if (refusal && replayed) {
|
|
1714
|
+
void activates?.activated();
|
|
1715
|
+
endReplay(`a saved action was refused (${refusal})`);
|
|
1716
|
+
continue;
|
|
1717
|
+
}
|
|
1120
1718
|
if (refusal) {
|
|
1121
1719
|
void activates?.activated();
|
|
1122
|
-
|
|
1720
|
+
const unseenDialog = answers === void 0 && dialogs.isOpen && ![...refs.keys()].some(isDialogRef);
|
|
1721
|
+
if (!unseenDialog) {
|
|
1722
|
+
failedAttempts++;
|
|
1723
|
+
failedOnPage(refusal);
|
|
1724
|
+
}
|
|
1123
1725
|
lastResult = refusal;
|
|
1124
1726
|
emitAction(index, action, refusal);
|
|
1125
1727
|
if (failedAttempts >= maxRetries) {
|
|
@@ -1127,24 +1729,71 @@ async function executeTest(page, test, options) {
|
|
|
1127
1729
|
}
|
|
1128
1730
|
continue;
|
|
1129
1731
|
}
|
|
1732
|
+
const answeredName = answers === void 0 ? void 0 : dialogs.name();
|
|
1130
1733
|
try {
|
|
1131
|
-
const
|
|
1734
|
+
const performing = performAction(page, action, {
|
|
1132
1735
|
baseUrl,
|
|
1133
1736
|
allowedOrigins,
|
|
1134
1737
|
resolveValue,
|
|
1135
|
-
resolveTimeoutMs: timeoutMs
|
|
1738
|
+
resolveTimeoutMs: timeoutMs,
|
|
1739
|
+
dialogs
|
|
1136
1740
|
});
|
|
1741
|
+
const raced = answers === void 0 ? await dialogs.race(performing) : { opened: false, value: await performing };
|
|
1742
|
+
let result;
|
|
1743
|
+
let activated;
|
|
1744
|
+
if (raced.opened) {
|
|
1745
|
+
result = `ok: ${describeAction(action)}, which opened ${dialogs.describe()}`;
|
|
1746
|
+
activated = activates;
|
|
1747
|
+
dialogs.keep(raced.rest.then(() => activates?.activated()));
|
|
1748
|
+
} else {
|
|
1749
|
+
result = raced.value;
|
|
1750
|
+
if (activates === void 0) {
|
|
1751
|
+
activated = void 0;
|
|
1752
|
+
} else {
|
|
1753
|
+
const asked = await dialogs.race(activates.activated());
|
|
1754
|
+
if (asked.opened) dialogs.keep(asked.rest);
|
|
1755
|
+
activated = asked.opened || asked.value ? activates : void 0;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
if (answers !== void 0) {
|
|
1759
|
+
const after = await dialogs.drain();
|
|
1760
|
+
if (after !== void 0) {
|
|
1761
|
+
result += `; after the answer, the action that opened it failed: ${after}`;
|
|
1762
|
+
failedOnPage(`error: ${after}`);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1137
1765
|
lastResult = result;
|
|
1138
|
-
|
|
1139
|
-
recovery.record(action, mask(describeAction(action)), mask(result), activated);
|
|
1766
|
+
recovery.record(action, mask(describeAction(action)), mask(result), activated, answers);
|
|
1140
1767
|
agentRecord.push({ action: mask(describeAction(action)), result: mask(result) });
|
|
1141
1768
|
pageActedOn = pageSnap;
|
|
1769
|
+
if (answers !== void 0 && pageBeforeDialog !== void 0 && !dialogs.isOpen) {
|
|
1770
|
+
pageActedOn = pageBeforeDialog;
|
|
1771
|
+
pageBeforeDialog = void 0;
|
|
1772
|
+
answeredDialog = true;
|
|
1773
|
+
}
|
|
1142
1774
|
emitAction(index, action, result);
|
|
1775
|
+
performed.push({
|
|
1776
|
+
action: action.action,
|
|
1777
|
+
...action.target?.role === void 0 ? {} : { role: action.target.role },
|
|
1778
|
+
...action.target?.name === void 0 ? {} : { name: mask(action.target.name) },
|
|
1779
|
+
...action.value === void 0 ? {} : { value: mask(action.value) },
|
|
1780
|
+
changed: false,
|
|
1781
|
+
...answeredName === void 0 ? {} : { dialog: mask(answeredName) }
|
|
1782
|
+
});
|
|
1783
|
+
if (replayed && live !== void 0) {
|
|
1784
|
+
lastReplayed = live.actions[replayAt];
|
|
1785
|
+
replayAt++;
|
|
1786
|
+
}
|
|
1143
1787
|
} catch (error) {
|
|
1144
1788
|
void activates?.activated();
|
|
1145
|
-
failedAttempts++;
|
|
1146
1789
|
lastResult = `error: ${error instanceof Error ? error.message : String(error)}`;
|
|
1147
1790
|
emitAction(index, action, lastResult);
|
|
1791
|
+
if (replayed) {
|
|
1792
|
+
endReplay(`a saved action failed (${lastResult})`);
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1795
|
+
failedAttempts++;
|
|
1796
|
+
failedOnPage(lastResult);
|
|
1148
1797
|
if (failedAttempts >= maxRetries) {
|
|
1149
1798
|
throw new StepFailure(lastResult);
|
|
1150
1799
|
}
|
|
@@ -1156,7 +1805,7 @@ async function executeTest(page, test, options) {
|
|
|
1156
1805
|
if (step !== written && error instanceof StepFailure && recovery.acted) {
|
|
1157
1806
|
const check = following.step;
|
|
1158
1807
|
try {
|
|
1159
|
-
await
|
|
1808
|
+
await settle();
|
|
1160
1809
|
if (isOriginAllowed(page.url(), boundary)) {
|
|
1161
1810
|
const snap = await takeSnapshot(page);
|
|
1162
1811
|
lastSnapshot = snap;
|
|
@@ -1172,7 +1821,11 @@ async function executeTest(page, test, options) {
|
|
|
1172
1821
|
};
|
|
1173
1822
|
if (judgment.pass) {
|
|
1174
1823
|
emitAction(index, asked, `ok: the check after this step holds: ${judgment.reason}`);
|
|
1824
|
+
if (failuresOnPage === 0) failedOnPage(stepFailedReason);
|
|
1175
1825
|
stepFailedReason = void 0;
|
|
1826
|
+
const acted = performed[performed.length - 1];
|
|
1827
|
+
if (acted !== void 0 && pageActedOn !== void 0) acted.changed = pageDiffers(pageActedOn, pageSnap);
|
|
1828
|
+
closed = { by: "judgment", claim: mask(check) };
|
|
1176
1829
|
} else {
|
|
1177
1830
|
emitAction(index, asked, `the check after this step does not hold either: ${judgment.reason}`);
|
|
1178
1831
|
}
|
|
@@ -1190,6 +1843,11 @@ async function executeTest(page, test, options) {
|
|
|
1190
1843
|
for (const name of referencedEnvVars(entry.action)) usedEarlier.add(name);
|
|
1191
1844
|
}
|
|
1192
1845
|
const status = stepFailedReason ? "failed" : "passed";
|
|
1846
|
+
if (status === "failed" && live !== void 0) replayOutcome.ended.push(key);
|
|
1847
|
+
const decidedBy = !replay ? void 0 : hadSaved && live !== void 0 && status === "passed" ? "replayed" : hadSaved && status === "passed" ? "healed" : "model";
|
|
1848
|
+
if (replay && status === "passed" && closed !== void 0) {
|
|
1849
|
+
replayOutcome.steps.push({ key, actions: performed, close: closed });
|
|
1850
|
+
}
|
|
1193
1851
|
stepResults.push({
|
|
1194
1852
|
step: mask(written),
|
|
1195
1853
|
// results are a report channel — never store substituted secrets
|
|
@@ -1198,7 +1856,9 @@ async function executeTest(page, test, options) {
|
|
|
1198
1856
|
iterations,
|
|
1199
1857
|
failedAttempts,
|
|
1200
1858
|
reason: stepFailedReason,
|
|
1201
|
-
durationMs: Date.now() - stepStartedAt
|
|
1859
|
+
durationMs: Date.now() - stepStartedAt,
|
|
1860
|
+
...decidedBy ? { decidedBy } : {},
|
|
1861
|
+
...status === "passed" && failuresOnPage > 0 ? { recovered: { attempts: failuresOnPage, first: firstFailure } } : {}
|
|
1202
1862
|
});
|
|
1203
1863
|
onEvent({ type: "step-end", index, status, reason: stepFailedReason });
|
|
1204
1864
|
if (stepFailedReason) {
|
|
@@ -1208,10 +1868,11 @@ async function executeTest(page, test, options) {
|
|
|
1208
1868
|
}
|
|
1209
1869
|
let screenshot;
|
|
1210
1870
|
if (failure) {
|
|
1871
|
+
await dialogs.dismissOpen();
|
|
1211
1872
|
try {
|
|
1212
|
-
await
|
|
1213
|
-
const stem = `${slugify(test.summary)}-${slugify(
|
|
1214
|
-
const file =
|
|
1873
|
+
await mkdir3(sessionDir, { recursive: true });
|
|
1874
|
+
const stem = `${slugify(test.summary)}-${slugify(path3.basename(test.path))}`;
|
|
1875
|
+
const file = path3.join(sessionDir, `${stem}.png`);
|
|
1215
1876
|
await page.screenshot({ path: file, fullPage: true });
|
|
1216
1877
|
screenshot = file;
|
|
1217
1878
|
} catch {
|
|
@@ -1227,6 +1888,7 @@ async function executeTest(page, test, options) {
|
|
|
1227
1888
|
failedStep: failure?.step,
|
|
1228
1889
|
reason: failure?.reason,
|
|
1229
1890
|
screenshot,
|
|
1891
|
+
...replay ? { replay: replayOutcome } : {},
|
|
1230
1892
|
durationMs: Date.now() - startedAt
|
|
1231
1893
|
};
|
|
1232
1894
|
}
|
|
@@ -1386,7 +2048,7 @@ function isSessionStorageSeed(value) {
|
|
|
1386
2048
|
}
|
|
1387
2049
|
|
|
1388
2050
|
// src/auth.ts
|
|
1389
|
-
var AUTH_STATE_RELATIVE_PATH =
|
|
2051
|
+
var AUTH_STATE_RELATIVE_PATH = path4.join(".blastproof", ".auth-state.json");
|
|
1390
2052
|
var AuthError = class extends Error {
|
|
1391
2053
|
constructor(message) {
|
|
1392
2054
|
super(message);
|
|
@@ -1399,7 +2061,7 @@ function isStorageState(value) {
|
|
|
1399
2061
|
async function fromStorageState(file) {
|
|
1400
2062
|
let raw;
|
|
1401
2063
|
try {
|
|
1402
|
-
raw = await
|
|
2064
|
+
raw = await readFile2(file, "utf8");
|
|
1403
2065
|
} catch {
|
|
1404
2066
|
throw new AuthError(
|
|
1405
2067
|
`Cannot read auth.storage_state at ${file}. Capture a session first, or switch to an auth.steps recipe.`
|
|
@@ -1481,7 +2143,7 @@ async function fromSteps(options) {
|
|
|
1481
2143
|
},
|
|
1482
2144
|
{
|
|
1483
2145
|
brain,
|
|
1484
|
-
sessionDir:
|
|
2146
|
+
sessionDir: path4.join(options.cwd, ".blastproof", "reports", "auth"),
|
|
1485
2147
|
baseUrl,
|
|
1486
2148
|
allowedOrigins: options.allowedOrigins,
|
|
1487
2149
|
resolveValue: (value) => substituteEnv(value),
|
|
@@ -1489,7 +2151,8 @@ async function fromSteps(options) {
|
|
|
1489
2151
|
timeoutMs,
|
|
1490
2152
|
mask: (text) => mask.mask(text),
|
|
1491
2153
|
snapshot: takeSnapshot,
|
|
1492
|
-
onEvent
|
|
2154
|
+
onEvent,
|
|
2155
|
+
onHiddenDialog: options.onHiddenDialog
|
|
1493
2156
|
}
|
|
1494
2157
|
);
|
|
1495
2158
|
if (result.status === "failed") {
|
|
@@ -1565,17 +2228,17 @@ async function checkWhereUsed(options, session, loginPage, takeSnapshot) {
|
|
|
1565
2228
|
}
|
|
1566
2229
|
async function readCached(cwd) {
|
|
1567
2230
|
try {
|
|
1568
|
-
return await fromStorageState(
|
|
2231
|
+
return await fromStorageState(path4.join(cwd, AUTH_STATE_RELATIVE_PATH));
|
|
1569
2232
|
} catch {
|
|
1570
2233
|
return void 0;
|
|
1571
2234
|
}
|
|
1572
2235
|
}
|
|
1573
2236
|
async function writeCached(cwd, session) {
|
|
1574
2237
|
if (!session.storageState) return;
|
|
1575
|
-
const file =
|
|
1576
|
-
await
|
|
2238
|
+
const file = path4.join(cwd, AUTH_STATE_RELATIVE_PATH);
|
|
2239
|
+
await mkdir4(path4.dirname(file), { recursive: true });
|
|
1577
2240
|
const cached = session.sessionStorage ? { ...session.storageState, sessionStorage: session.sessionStorage } : session.storageState;
|
|
1578
|
-
await
|
|
2241
|
+
await writeFile3(file, JSON.stringify(cached), "utf8");
|
|
1579
2242
|
}
|
|
1580
2243
|
async function authenticate(options) {
|
|
1581
2244
|
const { auth, cwd } = options;
|
|
@@ -1584,7 +2247,7 @@ async function authenticate(options) {
|
|
|
1584
2247
|
if (cached) return cached;
|
|
1585
2248
|
}
|
|
1586
2249
|
if (auth.storage_state) {
|
|
1587
|
-
return fromStorageState(
|
|
2250
|
+
return fromStorageState(path4.resolve(cwd, auth.storage_state));
|
|
1588
2251
|
}
|
|
1589
2252
|
if (auth.headers || auth.cookies) {
|
|
1590
2253
|
return fromStatic(auth, options.mask);
|
|
@@ -1606,11 +2269,11 @@ async function seedContext(context, session) {
|
|
|
1606
2269
|
}
|
|
1607
2270
|
|
|
1608
2271
|
// src/config.ts
|
|
1609
|
-
import { readFile as
|
|
1610
|
-
import
|
|
2272
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
2273
|
+
import path5 from "path";
|
|
1611
2274
|
import { parse as parseYaml } from "yaml";
|
|
1612
2275
|
import { z } from "zod";
|
|
1613
|
-
var CONFIG_RELATIVE_PATH =
|
|
2276
|
+
var CONFIG_RELATIVE_PATH = path5.join(".blastproof", "config.yaml");
|
|
1614
2277
|
var llmSchema = z.object({
|
|
1615
2278
|
provider: z.enum(["anthropic", "openai", "ollama"]).default("anthropic"),
|
|
1616
2279
|
model: z.string().min(1).optional(),
|
|
@@ -1755,6 +2418,13 @@ var configSchema = z.object({
|
|
|
1755
2418
|
* those tests, not of the runner. Opted into by the person who knows.
|
|
1756
2419
|
*/
|
|
1757
2420
|
concurrency: z.number().int().min(1, "concurrency must be at least 1").default(1),
|
|
2421
|
+
/**
|
|
2422
|
+
* Replays the actions of a step that passed instead of asking the model again
|
|
2423
|
+
* (design replay-the-actions-of-a-passing-step, D8). Off by default: a gate
|
|
2424
|
+
* must not start deciding differently on an upgrade. `BLASTPROOF_REPLAY` is
|
|
2425
|
+
* text, so the two words a boolean is written with are read as one.
|
|
2426
|
+
*/
|
|
2427
|
+
replay: z.preprocess((value) => value === "true" ? true : value === "false" ? false : value, z.boolean()).default(false),
|
|
1758
2428
|
budget: budgetSchema.optional(),
|
|
1759
2429
|
first_judge: firstJudgeSchema.optional()
|
|
1760
2430
|
});
|
|
@@ -1770,7 +2440,8 @@ var ENV_OVERRIDES = {
|
|
|
1770
2440
|
BLASTPROOF_MAX_DURATION_S: ["budget", "max_duration_s"],
|
|
1771
2441
|
BLASTPROOF_FIRST_JUDGE_MODEL: ["first_judge", "model"],
|
|
1772
2442
|
BLASTPROOF_FIRST_JUDGE_THRESHOLD: ["first_judge", "threshold"],
|
|
1773
|
-
BLASTPROOF_BROWSER_DEVICE: ["browser", "device"]
|
|
2443
|
+
BLASTPROOF_BROWSER_DEVICE: ["browser", "device"],
|
|
2444
|
+
BLASTPROOF_REPLAY: ["replay"]
|
|
1774
2445
|
};
|
|
1775
2446
|
function applyEnvOverrides(data, env = process.env) {
|
|
1776
2447
|
const merged = data && typeof data === "object" ? { ...data } : {};
|
|
@@ -1816,13 +2487,13 @@ function unwrapToObjectSchema(schema) {
|
|
|
1816
2487
|
}
|
|
1817
2488
|
return current instanceof z.ZodObject ? current : void 0;
|
|
1818
2489
|
}
|
|
1819
|
-
function findUnknownConfigKeys(data, schema = configSchema,
|
|
2490
|
+
function findUnknownConfigKeys(data, schema = configSchema, path13 = []) {
|
|
1820
2491
|
const object = unwrapToObjectSchema(schema);
|
|
1821
2492
|
if (!object || data === null || typeof data !== "object" || Array.isArray(data)) return [];
|
|
1822
2493
|
const shape = object.shape;
|
|
1823
2494
|
const warnings = [];
|
|
1824
2495
|
for (const key of Object.keys(data)) {
|
|
1825
|
-
const fieldPath = [...
|
|
2496
|
+
const fieldPath = [...path13, key];
|
|
1826
2497
|
const fieldSchema = shape[key];
|
|
1827
2498
|
if (!fieldSchema) {
|
|
1828
2499
|
warnings.push(fieldPath.join("."));
|
|
@@ -1833,10 +2504,10 @@ function findUnknownConfigKeys(data, schema = configSchema, path12 = []) {
|
|
|
1833
2504
|
return warnings;
|
|
1834
2505
|
}
|
|
1835
2506
|
async function loadConfig(cwd = process.cwd(), env = process.env) {
|
|
1836
|
-
const configPath =
|
|
2507
|
+
const configPath = path5.join(cwd, CONFIG_RELATIVE_PATH);
|
|
1837
2508
|
let raw;
|
|
1838
2509
|
try {
|
|
1839
|
-
raw = await
|
|
2510
|
+
raw = await readFile3(configPath, "utf8");
|
|
1840
2511
|
} catch {
|
|
1841
2512
|
throw new ConfigError(
|
|
1842
2513
|
`No config found at ${CONFIG_RELATIVE_PATH}. Run \`blastproof init\` to scaffold one.`
|
|
@@ -1969,6 +2640,20 @@ function hiddenFrameWarning(origin) {
|
|
|
1969
2640
|
lines: [`Add it to allowed_origins in .blastproof/config.yaml if the agent should read and act on it.`]
|
|
1970
2641
|
};
|
|
1971
2642
|
}
|
|
2643
|
+
function hiddenDialogWarning(origin) {
|
|
2644
|
+
if (origin === void 0) {
|
|
2645
|
+
return {
|
|
2646
|
+
kind: "hidden-dialog",
|
|
2647
|
+
title: "warning: a native dialog was dismissed without being shown to the agent: the browser did not say which frame opened it.",
|
|
2648
|
+
lines: ["Dialogs are attributed through Chromium; a step that needed this one failed or was decided without it."]
|
|
2649
|
+
};
|
|
2650
|
+
}
|
|
2651
|
+
return {
|
|
2652
|
+
kind: "hidden-dialog",
|
|
2653
|
+
title: `warning: a native dialog from ${origin} was dismissed without being shown to the agent: it came from a frame not in allowed_origins.`,
|
|
2654
|
+
lines: ["Add it to allowed_origins in .blastproof/config.yaml if the agent should read and answer it."]
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
1972
2657
|
|
|
1973
2658
|
// src/report/uncommitted.ts
|
|
1974
2659
|
function printUncommitted(uncommitted, changedFiles, config, baseRef, into) {
|
|
@@ -2009,6 +2694,7 @@ Rules:
|
|
|
2009
2694
|
- Placeholders like {{env.SOME_NAME}} are secrets that are filled in after you answer. Pass them through in your action exactly as written, never expanded, never guessed at.
|
|
2010
2695
|
- Pick target elements exclusively from the current snapshot. Every element there carries a ref, like \`[ref=f1e25]\`: name your target by that ref, and give its role and name exactly as that same line shows them (the text after the colon when it has no quoted name). The ref decides which element is acted on, so copy it from the line of the element you mean; a role or name that does not match that line is refused. Refs change when the page changes, so always take them from the current snapshot. Never invent CSS selectors or guess elements not in the snapshot.
|
|
2011
2696
|
- Use "navigate" only with a URL or path as value. Use "fill" to type into textboxes/inputs. Use "press" for keyboard keys (value e.g. "Enter"). Use "select" for dropdowns (value = option label). Use "hover" to point at an element without clicking it, when a menu, tooltip or control appears only on hover.
|
|
2697
|
+
- A native browser dialog (alert, confirm, prompt, or one asking to leave the page) shows as an "alertdialog" line marked [native \u2026] with its buttons, and while it is open nothing else on the page can be reached. Answer it by clicking the button the step calls for; for a prompt, fill its textbox first when the step gives a value. In a step that only looks, answer only an alert.
|
|
2012
2698
|
- Use "assert" with an expectation to verify page state (visible text, counts, URLs). Assertions never modify the page.
|
|
2013
2699
|
- A step that begins with "verify", "check", "confirm", "ensure", "assert", "expect", "validate", "make sure" or "see that" only looks. Never click or press in it: making the page show what the step checks would hide the very thing it checks. Assert what the page shows, navigate if what it names is on another page, or fail. It closes on a passing assertion, never on "done". This is enforced: a click, a press or "done" in such a step is refused.
|
|
2014
2700
|
- Return "done" when the current step's outcome holds \u2014 including when it already held before you acted, or was achieved by your previous action. "Already true" is done, never failure. Do not return "done" for work belonging to later steps.
|
|
@@ -2122,7 +2808,7 @@ function plannerUserPrompt(input) {
|
|
|
2122
2808
|
|
|
2123
2809
|
// src/llm/decision.ts
|
|
2124
2810
|
import { appendFileSync, mkdirSync } from "fs";
|
|
2125
|
-
import
|
|
2811
|
+
import path6 from "path";
|
|
2126
2812
|
import { APICallError } from "ai";
|
|
2127
2813
|
|
|
2128
2814
|
// src/llm/provider.ts
|
|
@@ -2307,7 +2993,7 @@ var FirstJudgeLog = class {
|
|
|
2307
2993
|
else this.toLlm++;
|
|
2308
2994
|
if (entry.outcome === "too-large" || !this.file) return;
|
|
2309
2995
|
if (!this.dirReady) {
|
|
2310
|
-
mkdirSync(
|
|
2996
|
+
mkdirSync(path6.dirname(this.file), { recursive: true });
|
|
2311
2997
|
this.dirReady = true;
|
|
2312
2998
|
}
|
|
2313
2999
|
const line = {
|
|
@@ -2329,7 +3015,7 @@ var FirstJudgeLog = class {
|
|
|
2329
3015
|
}
|
|
2330
3016
|
};
|
|
2331
3017
|
function firstJudgeLogPath(sessionDir) {
|
|
2332
|
-
return
|
|
3018
|
+
return path6.join(sessionDir, "first-judge.jsonl");
|
|
2333
3019
|
}
|
|
2334
3020
|
function createFirstJudgeClient(config, env = process.env, fetchImpl) {
|
|
2335
3021
|
const apiKey = env[config.api_key_env];
|
|
@@ -2571,16 +3257,16 @@ function createPlanner(model, generate = generateObject, budget) {
|
|
|
2571
3257
|
}
|
|
2572
3258
|
|
|
2573
3259
|
// src/planner.ts
|
|
2574
|
-
import { mkdir as
|
|
2575
|
-
import
|
|
3260
|
+
import { mkdir as mkdir5, writeFile as writeFile4 } from "fs/promises";
|
|
3261
|
+
import path8 from "path";
|
|
2576
3262
|
import { stringify } from "yaml";
|
|
2577
3263
|
|
|
2578
3264
|
// src/runner/testfile.ts
|
|
2579
|
-
import { readFile as
|
|
2580
|
-
import
|
|
3265
|
+
import { readFile as readFile4, readdir } from "fs/promises";
|
|
3266
|
+
import path7 from "path";
|
|
2581
3267
|
import { parse as parseYaml2 } from "yaml";
|
|
2582
3268
|
import { z as z3 } from "zod";
|
|
2583
|
-
var TESTS_RELATIVE_DIR =
|
|
3269
|
+
var TESTS_RELATIVE_DIR = path7.join(".blastproof", "tests");
|
|
2584
3270
|
var prioritySchema = z3.enum(["P0", "P1", "P2"]);
|
|
2585
3271
|
var testFileSchema = z3.object({
|
|
2586
3272
|
summary: z3.string().min(1),
|
|
@@ -2604,7 +3290,7 @@ function formatIssues2(error) {
|
|
|
2604
3290
|
async function parseTestFile(filePath) {
|
|
2605
3291
|
let raw;
|
|
2606
3292
|
try {
|
|
2607
|
-
raw = await
|
|
3293
|
+
raw = await readFile4(filePath, "utf8");
|
|
2608
3294
|
} catch {
|
|
2609
3295
|
throw new TestFileError(`Cannot read test file: ${filePath}`);
|
|
2610
3296
|
}
|
|
@@ -2628,7 +3314,7 @@ async function discoverTestFiles(root) {
|
|
|
2628
3314
|
async function walk(dir) {
|
|
2629
3315
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
2630
3316
|
for (const entry of entries) {
|
|
2631
|
-
const full =
|
|
3317
|
+
const full = path7.join(dir, entry.name);
|
|
2632
3318
|
if (entry.isDirectory()) {
|
|
2633
3319
|
await walk(full);
|
|
2634
3320
|
} else if (/\.ya?ml$/i.test(entry.name)) {
|
|
@@ -2716,20 +3402,20 @@ async function generateForRoute(page, options) {
|
|
|
2716
3402
|
};
|
|
2717
3403
|
}
|
|
2718
3404
|
async function writeDraft(cwd, draft, meta) {
|
|
2719
|
-
const dir =
|
|
2720
|
-
const file =
|
|
3405
|
+
const dir = path8.join(cwd, TESTS_RELATIVE_DIR);
|
|
3406
|
+
const file = path8.join(dir, `${routeToSlug(meta.route)}.yaml`);
|
|
2721
3407
|
try {
|
|
2722
|
-
await
|
|
2723
|
-
await
|
|
3408
|
+
await mkdir5(dir, { recursive: true });
|
|
3409
|
+
await writeFile4(file, renderTestYaml(draft, meta), { flag: "wx" });
|
|
2724
3410
|
} catch (error) {
|
|
2725
3411
|
const err = error;
|
|
2726
3412
|
if (err.code === "EEXIST" && err.syscall !== "mkdir") {
|
|
2727
3413
|
throw new PlannerError(
|
|
2728
|
-
`Refusing to overwrite ${
|
|
3414
|
+
`Refusing to overwrite ${path8.relative(cwd, file)} (route ${meta.route}). Delete or rename it to regenerate.`
|
|
2729
3415
|
);
|
|
2730
3416
|
}
|
|
2731
3417
|
throw new PlannerError(
|
|
2732
|
-
`Cannot write draft to ${file}: ${fsReason(error)}. Check that ${
|
|
3418
|
+
`Cannot write draft to ${file}: ${fsReason(error)}. Check that ${path8.dirname(file)} is a directory you can write to, not a file.`
|
|
2733
3419
|
);
|
|
2734
3420
|
}
|
|
2735
3421
|
return file;
|
|
@@ -2892,11 +3578,32 @@ function formatSpendLine(spend) {
|
|
|
2892
3578
|
}
|
|
2893
3579
|
|
|
2894
3580
|
// src/commands/run.ts
|
|
2895
|
-
import
|
|
3581
|
+
import path11 from "path";
|
|
3582
|
+
|
|
3583
|
+
// src/report/html.ts
|
|
3584
|
+
import { mkdir as mkdir6, readFile as readFile5, writeFile as writeFile5 } from "fs/promises";
|
|
3585
|
+
import path9 from "path";
|
|
3586
|
+
|
|
3587
|
+
// src/report/recovered.ts
|
|
3588
|
+
function recoveredLines(result) {
|
|
3589
|
+
if (result.status !== "passed") return [];
|
|
3590
|
+
return result.steps.flatMap(
|
|
3591
|
+
(step) => step.recovered === void 0 ? [] : [
|
|
3592
|
+
`step passed after ${attempts(step.recovered.attempts)}: ${step.step}`,
|
|
3593
|
+
// Its first line: a browser error carries a call log under it,
|
|
3594
|
+
// which the HTML report keeps (design D2).
|
|
3595
|
+
`first: ${step.recovered.first.split(/\r?\n/).find((line) => line.trim() !== "") ?? ""}`
|
|
3596
|
+
]
|
|
3597
|
+
);
|
|
3598
|
+
}
|
|
3599
|
+
function attempts(count2) {
|
|
3600
|
+
return `${count2} failed attempt${count2 === 1 ? "" : "s"}`;
|
|
3601
|
+
}
|
|
3602
|
+
function recoveredCount(results) {
|
|
3603
|
+
return results.reduce((sum, result) => sum + (result.status === "passed" ? result.steps.filter((step) => step.recovered).length : 0), 0);
|
|
3604
|
+
}
|
|
2896
3605
|
|
|
2897
3606
|
// src/report/html.ts
|
|
2898
|
-
import { mkdir as mkdir5, readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
|
|
2899
|
-
import path8 from "path";
|
|
2900
3607
|
var ESCAPES = {
|
|
2901
3608
|
"&": "&",
|
|
2902
3609
|
"<": "<",
|
|
@@ -2909,7 +3616,7 @@ function escapeHtml(text) {
|
|
|
2909
3616
|
}
|
|
2910
3617
|
async function embedScreenshot(file) {
|
|
2911
3618
|
try {
|
|
2912
|
-
const bytes = await
|
|
3619
|
+
const bytes = await readFile5(file);
|
|
2913
3620
|
return `data:image/png;base64,${bytes.toString("base64")}`;
|
|
2914
3621
|
} catch {
|
|
2915
3622
|
return void 0;
|
|
@@ -2970,14 +3677,14 @@ function seconds(ms) {
|
|
|
2970
3677
|
function renderSteps(steps) {
|
|
2971
3678
|
if (steps.length === 0) return "";
|
|
2972
3679
|
const items = steps.map(
|
|
2973
|
-
(step) => `<li class="${step.status === "failed" ? "failed" : ""}">${escapeHtml(step.step)}${step.setup ? ' <span class="note">(setup)</span>' : ""}</li>`
|
|
3680
|
+
(step) => `<li class="${step.status === "failed" ? "failed" : ""}">${escapeHtml(step.step)}${step.setup ? ' <span class="note">(setup)</span>' : ""}${step.decidedBy === "replayed" || step.decidedBy === "healed" ? ` <span class="note">(${step.decidedBy})</span>` : ""}${step.recovered ? ` <span class="note">(passed after ${attempts(step.recovered.attempts)}: ${escapeHtml(step.recovered.first)})</span>` : ""}</li>`
|
|
2974
3681
|
).join("\n ");
|
|
2975
3682
|
return `<ol class="steps">
|
|
2976
3683
|
${items}
|
|
2977
3684
|
</ol>`;
|
|
2978
3685
|
}
|
|
2979
3686
|
function withheldScreenshot(file, reportDir) {
|
|
2980
|
-
const href =
|
|
3687
|
+
const href = path9.relative(reportDir, file).split(path9.sep).join("/");
|
|
2981
3688
|
return ` <p class="note">Screenshot withheld: this run handled secrets ({{env.*}}), and a screenshot cannot be masked. <a href="${escapeHtml(href)}">${escapeHtml(href)}</a></p>`;
|
|
2982
3689
|
}
|
|
2983
3690
|
async function renderTest(result, screenshots, cwd) {
|
|
@@ -2985,7 +3692,7 @@ async function renderTest(result, screenshots, cwd) {
|
|
|
2985
3692
|
const notRun = result.status === "not-run";
|
|
2986
3693
|
const tagClass = failed ? "fail" : notRun ? "skip" : "pass";
|
|
2987
3694
|
const label = failed ? "FAIL" : notRun ? "NOT RUN" : "PASS";
|
|
2988
|
-
const file = cwd ?
|
|
3695
|
+
const file = cwd ? path9.relative(cwd, result.file) : result.file;
|
|
2989
3696
|
const device = result.device ? ` \xB7 ${escapeHtml(result.device)}` : "";
|
|
2990
3697
|
const parts = [
|
|
2991
3698
|
` <details${failed || notRun ? " open" : ""}>`,
|
|
@@ -3033,14 +3740,14 @@ async function renderHtml(results, skipped, meta) {
|
|
|
3033
3740
|
<pre>${escapeHtml(w.lines.join("\n"))}</pre>` : "")
|
|
3034
3741
|
).join("\n") + "\n </section>\n\n";
|
|
3035
3742
|
const rows = results.map((r) => {
|
|
3036
|
-
const file = meta.cwd ?
|
|
3743
|
+
const file = meta.cwd ? path9.relative(meta.cwd, r.file) : r.file;
|
|
3037
3744
|
const tagClass = r.status === "failed" ? "fail" : r.status === "not-run" ? "skip" : "pass";
|
|
3038
3745
|
const label = r.status === "failed" ? "FAIL" : r.status === "not-run" ? "NOT RUN" : "PASS";
|
|
3039
3746
|
const time = r.status === "not-run" ? "\u2014" : seconds(r.durationMs);
|
|
3040
3747
|
return ` <tr><td><span class="tag ${tagClass}">${label}</span></td><td>${escapeHtml(r.priority)}</td><td>${escapeHtml(r.summary)}</td><td>${escapeHtml(file)}</td><td class="num">${time}</td></tr>`;
|
|
3041
3748
|
}).join("\n");
|
|
3042
3749
|
const skippedRows = skipped.map((s) => {
|
|
3043
|
-
const file = meta.cwd ?
|
|
3750
|
+
const file = meta.cwd ? path9.relative(meta.cwd, s.path) : s.path;
|
|
3044
3751
|
return ` <tr><td><span class="tag skip">SKIP</span></td><td>\u2014</td><td>${escapeHtml(s.summary)}</td><td>${escapeHtml(file)}</td><td class="num">\u2014</td></tr>`;
|
|
3045
3752
|
}).join("\n");
|
|
3046
3753
|
return `<!doctype html>
|
|
@@ -3079,8 +3786,8 @@ ${detail}
|
|
|
3079
3786
|
}
|
|
3080
3787
|
async function writeHtml(file, html) {
|
|
3081
3788
|
try {
|
|
3082
|
-
await
|
|
3083
|
-
await
|
|
3789
|
+
await mkdir6(path9.dirname(file), { recursive: true });
|
|
3790
|
+
await writeFile5(file, html, "utf8");
|
|
3084
3791
|
return file;
|
|
3085
3792
|
} catch (error) {
|
|
3086
3793
|
throw new ReportError(
|
|
@@ -3090,8 +3797,8 @@ async function writeHtml(file, html) {
|
|
|
3090
3797
|
}
|
|
3091
3798
|
|
|
3092
3799
|
// src/report/junit.ts
|
|
3093
|
-
import { mkdir as
|
|
3094
|
-
import
|
|
3800
|
+
import { mkdir as mkdir7, writeFile as writeFile6 } from "fs/promises";
|
|
3801
|
+
import path10 from "path";
|
|
3095
3802
|
var ESCAPES2 = {
|
|
3096
3803
|
"&": "&",
|
|
3097
3804
|
"<": "<",
|
|
@@ -3105,8 +3812,19 @@ function escapeXml(text) {
|
|
|
3105
3812
|
function seconds2(ms) {
|
|
3106
3813
|
return (ms / 1e3).toFixed(3);
|
|
3107
3814
|
}
|
|
3815
|
+
function replayProperties(results) {
|
|
3816
|
+
const decided = results.flatMap((result) => result.steps.map((step) => step.decidedBy));
|
|
3817
|
+
if (!decided.some((by) => by !== void 0)) return [];
|
|
3818
|
+
const count2 = (by) => decided.filter((d) => d === by).length;
|
|
3819
|
+
const healed = count2("healed");
|
|
3820
|
+
return [
|
|
3821
|
+
` <property name="replayed_steps" value="${count2("replayed")}"/>`,
|
|
3822
|
+
` <property name="model_steps" value="${count2("model") + healed}"/>`,
|
|
3823
|
+
` <property name="healed_steps" value="${healed}"/>`
|
|
3824
|
+
];
|
|
3825
|
+
}
|
|
3108
3826
|
function renderJUnit(results, skipped, meta) {
|
|
3109
|
-
const relative = (file) => meta.cwd ?
|
|
3827
|
+
const relative = (file) => meta.cwd ? path10.relative(meta.cwd, file) : file;
|
|
3110
3828
|
const warnings = meta.warnings ?? [];
|
|
3111
3829
|
const failures = results.filter((result) => result.status === "failed").length;
|
|
3112
3830
|
const notRun = results.filter((result) => result.status === "not-run");
|
|
@@ -3129,6 +3847,10 @@ function renderJUnit(results, skipped, meta) {
|
|
|
3129
3847
|
] : [],
|
|
3130
3848
|
// Emitted as 0 too (design D2): unlike a token count nobody reported, 0 is
|
|
3131
3849
|
// a true claim here, that the run printed no warning.
|
|
3850
|
+
...replayProperties(results),
|
|
3851
|
+
// Always, as `warnings` (design show-a-step-that-recovered, D3): 0 is a
|
|
3852
|
+
// true claim.
|
|
3853
|
+
` <property name="recovered_steps" value="${recoveredCount(results)}"/>`,
|
|
3132
3854
|
` <property name="warnings" value="${warnings.length}"/>`,
|
|
3133
3855
|
" </properties>"
|
|
3134
3856
|
];
|
|
@@ -3143,7 +3865,14 @@ function renderJUnit(results, skipped, meta) {
|
|
|
3143
3865
|
}
|
|
3144
3866
|
const open = ` <testcase classname="${escapeXml(relative(result.file))}" name="${escapeXml(result.summary)}" time="${seconds2(result.durationMs)}"`;
|
|
3145
3867
|
if (result.status === "passed") {
|
|
3146
|
-
|
|
3868
|
+
const recovered = recoveredLines(result);
|
|
3869
|
+
if (recovered.length === 0) {
|
|
3870
|
+
lines.push(`${open}/>`);
|
|
3871
|
+
} else {
|
|
3872
|
+
lines.push(`${open}>`);
|
|
3873
|
+
lines.push(` <system-out>${escapeXml(recovered.join("\n"))}</system-out>`);
|
|
3874
|
+
lines.push(" </testcase>");
|
|
3875
|
+
}
|
|
3147
3876
|
continue;
|
|
3148
3877
|
}
|
|
3149
3878
|
const reason = result.reason ?? "test failed";
|
|
@@ -3168,8 +3897,8 @@ ${reason}` : reason;
|
|
|
3168
3897
|
}
|
|
3169
3898
|
async function writeJUnit(file, xml) {
|
|
3170
3899
|
try {
|
|
3171
|
-
await
|
|
3172
|
-
await
|
|
3900
|
+
await mkdir7(path10.dirname(file), { recursive: true });
|
|
3901
|
+
await writeFile6(file, xml, "utf8");
|
|
3173
3902
|
return file;
|
|
3174
3903
|
} catch (error) {
|
|
3175
3904
|
throw new ReportError(
|
|
@@ -3314,6 +4043,9 @@ function printEvent(event, write = console.log) {
|
|
|
3314
4043
|
write(` X step failed: ${event.reason ?? "unknown reason"}`);
|
|
3315
4044
|
}
|
|
3316
4045
|
break;
|
|
4046
|
+
case "replay-ended":
|
|
4047
|
+
write(` ~ replay ended: ${event.reason}; the model takes over`);
|
|
4048
|
+
break;
|
|
3317
4049
|
}
|
|
3318
4050
|
}
|
|
3319
4051
|
function statusLabel(status) {
|
|
@@ -3350,6 +4082,13 @@ X ${r.summary} (${r.file})`);
|
|
|
3350
4082
|
if (r.reason) console.log(` reason: ${r.reason}`);
|
|
3351
4083
|
if (r.screenshot) console.log(` screenshot: ${r.screenshot}`);
|
|
3352
4084
|
}
|
|
4085
|
+
for (const r of passed) {
|
|
4086
|
+
const lines = recoveredLines(r);
|
|
4087
|
+
if (lines.length === 0) continue;
|
|
4088
|
+
console.log(`
|
|
4089
|
+
~ ${r.summary} (${r.file})`);
|
|
4090
|
+
for (const line of lines) console.log(` ${line}`);
|
|
4091
|
+
}
|
|
3353
4092
|
if (notRun.length > 0) {
|
|
3354
4093
|
console.log(`
|
|
3355
4094
|
${notRun.length} test(s) not run (run stopped: ${notRun[0].reason}):`);
|
|
@@ -3360,7 +4099,7 @@ function deviceTag(test, config) {
|
|
|
3360
4099
|
const device = test.device ?? config.browser.device;
|
|
3361
4100
|
return device ? ` [${device}]` : "";
|
|
3362
4101
|
}
|
|
3363
|
-
async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, onHiddenFrame, firstJudge) {
|
|
4102
|
+
async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, onHiddenFrame, onHiddenDialog, firstJudge, replayCwd) {
|
|
3364
4103
|
const brain = createBrain(createModel(config.llm).model, void 0, budget, firstJudge);
|
|
3365
4104
|
let resolved;
|
|
3366
4105
|
const mask = runMask;
|
|
@@ -3382,6 +4121,7 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3382
4121
|
throw error;
|
|
3383
4122
|
}
|
|
3384
4123
|
const device = test.device ?? config.browser.device;
|
|
4124
|
+
const saved = replayCwd === void 0 ? void 0 : await loadReplay(replayFile(replayCwd, test.path), device);
|
|
3385
4125
|
const context = await browser.newContext(contextOptions(test.auth ? session : void 0, device));
|
|
3386
4126
|
try {
|
|
3387
4127
|
await seedContext(context, test.auth ? session : void 0);
|
|
@@ -3398,8 +4138,15 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3398
4138
|
maxSnapshotLines: config.browser.max_snapshot_lines,
|
|
3399
4139
|
mask: (text) => mask.mask(text),
|
|
3400
4140
|
onEvent: (event) => printEvent(event, write),
|
|
3401
|
-
onHiddenFrame
|
|
4141
|
+
onHiddenFrame,
|
|
4142
|
+
onHiddenDialog,
|
|
4143
|
+
...saved ? { replay: { saved } } : {}
|
|
3402
4144
|
});
|
|
4145
|
+
if (replayCwd !== void 0 && saved && result.replay) {
|
|
4146
|
+
const steps = stepsToSave(result.status === "passed", saved, result.replay);
|
|
4147
|
+
if (steps) await saveReplay(replayFile(replayCwd, test.path), device, steps).catch(() => {
|
|
4148
|
+
});
|
|
4149
|
+
}
|
|
3403
4150
|
return device ? { ...result, device } : result;
|
|
3404
4151
|
} finally {
|
|
3405
4152
|
await context.close();
|
|
@@ -3440,7 +4187,7 @@ Changed files: ${changedCount}`);
|
|
|
3440
4187
|
console.log(`Tests: ${selection.selected.length} selected`);
|
|
3441
4188
|
if (unrouted.length > 0) {
|
|
3442
4189
|
console.log(` ${unrouted.length} ${unrouted.length === 1 ? "declares" : "declare"} no routes:, so --impacted cannot select ${unrouted.length === 1 ? "it" : "them"}:`);
|
|
3443
|
-
for (const test of unrouted) console.log(` ${test.summary} (${
|
|
4190
|
+
for (const test of unrouted) console.log(` ${test.summary} (${path11.relative(cwd, test.path)})`);
|
|
3444
4191
|
}
|
|
3445
4192
|
console.log("---------------------------------------------------------------");
|
|
3446
4193
|
}
|
|
@@ -3461,12 +4208,14 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3461
4208
|
reportNearMissedSecrets(nearMissedSecrets, warnings);
|
|
3462
4209
|
if (spend) console.log(formatSpendLine(spend));
|
|
3463
4210
|
if (firstJudgeLog) console.log(firstJudgeLog.summaryLine());
|
|
4211
|
+
const decided = results.flatMap((result) => result.steps.map((step) => step.decidedBy));
|
|
4212
|
+
if (decided.some((by) => by !== void 0)) console.log(replaySummary(decided));
|
|
3464
4213
|
const score = scoreOf(results, incomplete !== void 0);
|
|
3465
4214
|
console.log(
|
|
3466
4215
|
incomplete ? formatIncompleteLine(score, incomplete.message) : formatScoreLine(computeScore(results), results, options.minScore)
|
|
3467
4216
|
);
|
|
3468
4217
|
if (options.junit) {
|
|
3469
|
-
const target = typeof options.junit === "string" ?
|
|
4218
|
+
const target = typeof options.junit === "string" ? path11.resolve(options.cwd, options.junit) : path11.join(sessionDir, "junit.xml");
|
|
3470
4219
|
const xml = renderJUnit(results, skipped, {
|
|
3471
4220
|
score,
|
|
3472
4221
|
durationMs,
|
|
@@ -3476,10 +4225,10 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3476
4225
|
warnings
|
|
3477
4226
|
});
|
|
3478
4227
|
await writeJUnit(target, xml);
|
|
3479
|
-
console.log(`JUnit report: ${
|
|
4228
|
+
console.log(`JUnit report: ${path11.relative(options.cwd, target)}`);
|
|
3480
4229
|
}
|
|
3481
4230
|
if (options.html) {
|
|
3482
|
-
const target = typeof options.html === "string" ?
|
|
4231
|
+
const target = typeof options.html === "string" ? path11.resolve(options.cwd, options.html) : path11.join(sessionDir, "report.html");
|
|
3483
4232
|
const html = await renderHtml(results, skipped, {
|
|
3484
4233
|
score,
|
|
3485
4234
|
durationMs,
|
|
@@ -3493,10 +4242,10 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3493
4242
|
// withhold-a-screenshot-that-saw-a-secret, D1): the run's mask, not the
|
|
3494
4243
|
// failed test's own placeholders, because a login credential is echoed by
|
|
3495
4244
|
// the pages of every test that comes after it.
|
|
3496
|
-
screenshots: secretsHeld ? { withheldRelativeTo:
|
|
4245
|
+
screenshots: secretsHeld ? { withheldRelativeTo: path11.dirname(target) } : "embed"
|
|
3497
4246
|
});
|
|
3498
4247
|
await writeHtml(target, html);
|
|
3499
|
-
console.log(`HTML report: ${
|
|
4248
|
+
console.log(`HTML report: ${path11.relative(options.cwd, target)}`);
|
|
3500
4249
|
}
|
|
3501
4250
|
if (incomplete) return EXIT_FAILED;
|
|
3502
4251
|
if (reportUnclassified(options, impact)) return EXIT_FAILED;
|
|
@@ -3527,7 +4276,7 @@ function routeDriftWarning(drift, cwd) {
|
|
|
3527
4276
|
kind: "route-drift",
|
|
3528
4277
|
title: "Route drift (test routes declared by no routes: mapping \u2014 contribute nothing to --impacted selection):",
|
|
3529
4278
|
lines: [
|
|
3530
|
-
...drift.drifted.map(({ test, routes }) => ` ${test.summary} (${
|
|
4279
|
+
...drift.drifted.map(({ test, routes }) => ` ${test.summary} (${path11.relative(cwd, test.path)}): ${routes.join(", ")}`),
|
|
3531
4280
|
"Fix the route typo, or add the route to a routes: mapping in .blastproof/config.yaml."
|
|
3532
4281
|
]
|
|
3533
4282
|
};
|
|
@@ -3541,7 +4290,7 @@ function authoringWarning(result, cwd) {
|
|
|
3541
4290
|
...result.findings.flatMap(({ test, origin, index, step }) => {
|
|
3542
4291
|
const where = origin === "setup" ? `setup step ${index}` : `step ${index}`;
|
|
3543
4292
|
return [
|
|
3544
|
-
` ${test.summary} (${
|
|
4293
|
+
` ${test.summary} (${path11.relative(cwd, test.path)}) ${where}:`,
|
|
3545
4294
|
` ${step}`,
|
|
3546
4295
|
` \u2192 ${suggestValueClause(step)}`
|
|
3547
4296
|
];
|
|
@@ -3556,7 +4305,7 @@ function printDryRun(selected, config, cwd) {
|
|
|
3556
4305
|
console.log(`
|
|
3557
4306
|
Dry run: ${selected.length} test(s) selected, base_url=${config.base_url}`);
|
|
3558
4307
|
for (const test of selected) {
|
|
3559
|
-
console.log(` ${test.summary} [${test.priority}]${deviceTag(test, config)} (${
|
|
4308
|
+
console.log(` ${test.summary} [${test.priority}]${deviceTag(test, config)} (${path11.relative(cwd, test.path)})`);
|
|
3560
4309
|
}
|
|
3561
4310
|
const needsLogin = selected.some((test) => test.auth);
|
|
3562
4311
|
const authSteps = needsLogin ? config.auth?.steps ?? [] : [];
|
|
@@ -3589,6 +4338,8 @@ async function runCommand(options) {
|
|
|
3589
4338
|
const warnings = [];
|
|
3590
4339
|
const hiddenFrames = /* @__PURE__ */ new Set();
|
|
3591
4340
|
const onHiddenFrame = (origin) => hiddenFrames.add(origin);
|
|
4341
|
+
const hiddenDialogs = /* @__PURE__ */ new Set();
|
|
4342
|
+
const onHiddenDialog = (origin) => hiddenDialogs.add(origin);
|
|
3592
4343
|
const impacted = options.impacted ?? false;
|
|
3593
4344
|
const base = options.base ?? "main";
|
|
3594
4345
|
if (options.failOnUnmapped && !impacted) {
|
|
@@ -3614,7 +4365,7 @@ async function runCommand(options) {
|
|
|
3614
4365
|
changedCount = changedFiles.length;
|
|
3615
4366
|
printUncommitted(await getUncommittedFiles(options.cwd), changedFiles, config, base, warnings);
|
|
3616
4367
|
}
|
|
3617
|
-
const testsDir =
|
|
4368
|
+
const testsDir = path11.join(options.cwd, TESTS_RELATIVE_DIR);
|
|
3618
4369
|
let files;
|
|
3619
4370
|
try {
|
|
3620
4371
|
files = await discoverTestFiles(testsDir);
|
|
@@ -3630,8 +4381,8 @@ async function runCommand(options) {
|
|
|
3630
4381
|
} catch (error) {
|
|
3631
4382
|
if (error instanceof TestFileError) {
|
|
3632
4383
|
results.push({
|
|
3633
|
-
file:
|
|
3634
|
-
summary:
|
|
4384
|
+
file: path11.relative(options.cwd, file),
|
|
4385
|
+
summary: path11.basename(file),
|
|
3635
4386
|
priority: "P1",
|
|
3636
4387
|
tags: [],
|
|
3637
4388
|
status: "failed",
|
|
@@ -3673,7 +4424,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3673
4424
|
}
|
|
3674
4425
|
return reportUnclassified(options, impact) ? EXIT_FAILED : EXIT_OK;
|
|
3675
4426
|
}
|
|
3676
|
-
const sessionDir =
|
|
4427
|
+
const sessionDir = path11.join(options.cwd, ".blastproof", "reports", sessionId());
|
|
3677
4428
|
const startedAt = Date.now();
|
|
3678
4429
|
if (selected.length === 0) {
|
|
3679
4430
|
console.log(
|
|
@@ -3705,7 +4456,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3705
4456
|
} : void 0;
|
|
3706
4457
|
if (firstJudgeLog) {
|
|
3707
4458
|
console.log(
|
|
3708
|
-
`First judge (experimental): ${firstJudgeLog.model}, passing at p(yes) >= ${firstJudgeLog.threshold}; its decisions are kept in ${
|
|
4459
|
+
`First judge (experimental): ${firstJudgeLog.model}, passing at p(yes) >= ${firstJudgeLog.threshold}; its decisions are kept in ${path11.relative(options.cwd, firstJudgeLogPath(sessionDir))}`
|
|
3709
4460
|
);
|
|
3710
4461
|
}
|
|
3711
4462
|
const runMask = buildRunMask(config, parsed);
|
|
@@ -3735,7 +4486,8 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3735
4486
|
device: config.browser.device,
|
|
3736
4487
|
mask: runMask,
|
|
3737
4488
|
onEvent: printEvent,
|
|
3738
|
-
onHiddenFrame
|
|
4489
|
+
onHiddenFrame,
|
|
4490
|
+
onHiddenDialog
|
|
3739
4491
|
});
|
|
3740
4492
|
} catch (error) {
|
|
3741
4493
|
if (error instanceof RunStoppedError) {
|
|
@@ -3743,6 +4495,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3743
4495
|
} else if (error instanceof AuthError) {
|
|
3744
4496
|
console.error(`error: ${error.message}`);
|
|
3745
4497
|
for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin), warnings);
|
|
4498
|
+
for (const origin of hiddenDialogs) emitWarning(hiddenDialogWarning(origin), warnings);
|
|
3746
4499
|
return EXIT_USAGE;
|
|
3747
4500
|
} else {
|
|
3748
4501
|
throw error;
|
|
@@ -3759,7 +4512,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3759
4512
|
if (stoppedBy) return { index, stopped: stoppedBy };
|
|
3760
4513
|
const lines = [];
|
|
3761
4514
|
const header = `
|
|
3762
|
-
> ${test.summary} [${test.priority}]${deviceTag(test, config)} (${
|
|
4515
|
+
> ${test.summary} [${test.priority}]${deviceTag(test, config)} (${path11.relative(options.cwd, test.path)})`;
|
|
3763
4516
|
const write = streaming ? console.log : (line) => lines.push(line);
|
|
3764
4517
|
if (streaming) console.log(header);
|
|
3765
4518
|
else lines.push(header);
|
|
@@ -3775,7 +4528,9 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3775
4528
|
budget,
|
|
3776
4529
|
write,
|
|
3777
4530
|
onHiddenFrame,
|
|
3778
|
-
|
|
4531
|
+
onHiddenDialog,
|
|
4532
|
+
firstJudgeFor(path11.relative(options.cwd, test.path)),
|
|
4533
|
+
options.replay ?? config.replay ? options.cwd : void 0
|
|
3779
4534
|
);
|
|
3780
4535
|
if (!streaming) for (const line of lines) console.log(line);
|
|
3781
4536
|
return { index, result };
|
|
@@ -3801,6 +4556,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3801
4556
|
await browser.close();
|
|
3802
4557
|
}
|
|
3803
4558
|
for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin), warnings);
|
|
4559
|
+
for (const origin of hiddenDialogs) emitWarning(hiddenDialogWarning(origin), warnings);
|
|
3804
4560
|
return finalize(
|
|
3805
4561
|
results,
|
|
3806
4562
|
selection.unroutedSkipped,
|
|
@@ -3828,12 +4584,12 @@ function printAuthEvent(event) {
|
|
|
3828
4584
|
console.log(` step ${event.index + 1}/${event.total}: ${event.step}`);
|
|
3829
4585
|
} else if (event.type === "action") {
|
|
3830
4586
|
console.log(` -> ${event.action.action} :: ${event.result}`);
|
|
3831
|
-
} else if (event.status === "failed") {
|
|
4587
|
+
} else if (event.type === "step-end" && event.status === "failed") {
|
|
3832
4588
|
console.log(` X step failed: ${event.reason ?? "unknown reason"}`);
|
|
3833
4589
|
}
|
|
3834
4590
|
}
|
|
3835
4591
|
async function loadSuite(cwd) {
|
|
3836
|
-
const testsDir =
|
|
4592
|
+
const testsDir = path12.join(cwd, TESTS_RELATIVE_DIR);
|
|
3837
4593
|
let files;
|
|
3838
4594
|
try {
|
|
3839
4595
|
files = await discoverTestFiles(testsDir);
|
|
@@ -4023,8 +4779,8 @@ async function planCommand(options) {
|
|
|
4023
4779
|
if (options.write) {
|
|
4024
4780
|
try {
|
|
4025
4781
|
const file = await writeDraft(options.cwd, draft, { route, base });
|
|
4026
|
-
written.push(
|
|
4027
|
-
console.log(` wrote ${
|
|
4782
|
+
written.push(path12.relative(options.cwd, file));
|
|
4783
|
+
console.log(` wrote ${path12.relative(options.cwd, file)}`);
|
|
4028
4784
|
} catch (error) {
|
|
4029
4785
|
generated.pop();
|
|
4030
4786
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -4096,6 +4852,7 @@ async function testCommand(options) {
|
|
|
4096
4852
|
html: options.html,
|
|
4097
4853
|
failOnUnmapped: options.failOnUnmapped,
|
|
4098
4854
|
failOnAuthoring: options.failOnAuthoring,
|
|
4855
|
+
replay: options.replay,
|
|
4099
4856
|
budget
|
|
4100
4857
|
});
|
|
4101
4858
|
if (runCode === EXIT_USAGE) return EXIT_USAGE;
|
|
@@ -4152,7 +4909,7 @@ function parsePositiveNumber(flag) {
|
|
|
4152
4909
|
};
|
|
4153
4910
|
}
|
|
4154
4911
|
var program = new Command();
|
|
4155
|
-
program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.
|
|
4912
|
+
program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.36.0");
|
|
4156
4913
|
program.command("init").description("Scaffold .blastproof/ (config, tests, sample tests) in the current directory").action(async () => {
|
|
4157
4914
|
try {
|
|
4158
4915
|
const result = await initProject(process.cwd());
|
|
@@ -4167,7 +4924,7 @@ program.command("run").description("Discover and run all tests under .blastproof
|
|
|
4167
4924
|
"--min-score <n>",
|
|
4168
4925
|
"require a weighted score of at least n (0-100); replaces the all-must-pass rule",
|
|
4169
4926
|
parseMinScore
|
|
4170
|
-
).option("--junit [path]", "write a JUnit XML report (default: .blastproof/reports/<session>/junit.xml)").option("--html [path]", "write a self-contained HTML report (default: .blastproof/reports/<session>/report.html)").option("--fail-on-unmapped", "fail when a changed file matches no routes: or ignore: glob").option("--fail-on-authoring", "fail when a step enters a value but names none (warns by default)").option(
|
|
4927
|
+
).option("--junit [path]", "write a JUnit XML report (default: .blastproof/reports/<session>/junit.xml)").option("--html [path]", "write a self-contained HTML report (default: .blastproof/reports/<session>/report.html)").option("--fail-on-unmapped", "fail when a changed file matches no routes: or ignore: glob").option("--fail-on-authoring", "fail when a step enters a value but names none (warns by default)").option("--replay", "replay the actions of steps that passed last time instead of asking the model (overrides config)").option("--no-replay", "ask the model for every action, and read or write no saved actions (overrides config)").option(
|
|
4171
4928
|
"--concurrency <n>",
|
|
4172
4929
|
"run this many tests at once (overrides config; default 1 \u2014 see the README on when this is safe)",
|
|
4173
4930
|
parsePositiveInt("--concurrency")
|
|
@@ -4201,6 +4958,7 @@ program.command("run").description("Discover and run all tests under .blastproof
|
|
|
4201
4958
|
failOnUnmapped: options.failOnUnmapped,
|
|
4202
4959
|
failOnAuthoring: options.failOnAuthoring,
|
|
4203
4960
|
concurrency: options.concurrency,
|
|
4961
|
+
replay: options.replay,
|
|
4204
4962
|
maxLlmCalls: options.maxLlmCalls,
|
|
4205
4963
|
maxTokens: options.maxTokens,
|
|
4206
4964
|
maxDuration: options.maxDuration
|
|
@@ -4258,7 +5016,7 @@ program.command("test").description("Full PR pipeline: run the tests covering th
|
|
|
4258
5016
|
"--max-tokens <n>",
|
|
4259
5017
|
"stop the pipeline after this many tokens, shared by both phases (overrides config)",
|
|
4260
5018
|
parsePositiveInt("--max-tokens")
|
|
4261
|
-
).option(
|
|
5019
|
+
).option("--replay", "replay the actions of steps that passed last time instead of asking the model (overrides config)").option("--no-replay", "ask the model for every action, and read or write no saved actions (overrides config)").option(
|
|
4262
5020
|
"--max-duration <seconds>",
|
|
4263
5021
|
"stop the pipeline after this many seconds of wall-clock time (overrides config)",
|
|
4264
5022
|
parsePositiveNumber("--max-duration")
|
|
@@ -4275,6 +5033,7 @@ program.command("test").description("Full PR pipeline: run the tests covering th
|
|
|
4275
5033
|
write: options.write,
|
|
4276
5034
|
failOnUnmapped: options.failOnUnmapped,
|
|
4277
5035
|
failOnAuthoring: options.failOnAuthoring,
|
|
5036
|
+
replay: options.replay,
|
|
4278
5037
|
maxLlmCalls: options.maxLlmCalls,
|
|
4279
5038
|
maxTokens: options.maxTokens,
|
|
4280
5039
|
maxDuration: options.maxDuration
|