blastproof 0.35.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 +561 -32
- 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";
|
|
@@ -703,11 +704,13 @@ var StepRecovery = class {
|
|
|
703
704
|
return this.history.length > 0;
|
|
704
705
|
}
|
|
705
706
|
/** Records an action that was actually performed and succeeded. */
|
|
706
|
-
record(action, description, result, activates) {
|
|
707
|
+
record(action, description, result, activates, answers) {
|
|
707
708
|
const commit = commitIdentity(action, activates);
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
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
|
+
}
|
|
711
714
|
const named = activatedControl(action, activates) !== void 0;
|
|
712
715
|
this.lastSuccess = { commit, own: identity(action), named, page: this.lastObserved, action };
|
|
713
716
|
this.history.push({ action: description, result });
|
|
@@ -729,8 +732,12 @@ var StepRecovery = class {
|
|
|
729
732
|
* allowed duplicate commit costs a silent extra row in someone's database,
|
|
730
733
|
* and #28 has now produced one on three applications.
|
|
731
734
|
*/
|
|
732
|
-
refusalFor(action, activates) {
|
|
733
|
-
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
|
+
);
|
|
734
741
|
}
|
|
735
742
|
/**
|
|
736
743
|
* Refuses a typed value containing a redaction label (design
|
|
@@ -862,6 +869,346 @@ var StepRecovery = class {
|
|
|
862
869
|
}
|
|
863
870
|
};
|
|
864
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
|
+
|
|
865
1212
|
// src/runner/replay.ts
|
|
866
1213
|
import { createHash } from "crypto";
|
|
867
1214
|
import { mkdir as mkdir2, readFile, rename, writeFile as writeFile2 } from "fs/promises";
|
|
@@ -884,11 +1231,13 @@ function refOf(saved, refs) {
|
|
|
884
1231
|
return found;
|
|
885
1232
|
}
|
|
886
1233
|
var REPLAYED = "replayed from the last passing run";
|
|
887
|
-
function replayedDecision(entry, at, refs) {
|
|
1234
|
+
function replayedDecision(entry, at, refs, openDialog) {
|
|
888
1235
|
const saved = entry.actions[at];
|
|
889
1236
|
if (saved === void 0) {
|
|
890
1237
|
return entry.close.by === "done" ? { action: "done", reasoning: REPLAYED } : { action: "assert", expectation: entry.close.claim, reasoning: REPLAYED };
|
|
891
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;
|
|
892
1241
|
const action = saved.action;
|
|
893
1242
|
if (saved.role === void 0) return { action, value: saved.value, reasoning: REPLAYED };
|
|
894
1243
|
const ref = refOf(saved, refs);
|
|
@@ -915,7 +1264,7 @@ var optionalString = (value) => value === void 0 || typeof value === "string";
|
|
|
915
1264
|
function isSavedAction(value) {
|
|
916
1265
|
if (typeof value !== "object" || value === null) return false;
|
|
917
1266
|
const action = value;
|
|
918
|
-
return typeof action.action === "string" && PERFORMED_ACTIONS.has(action.action) && typeof action.changed === "boolean" && optionalString(action.role) && optionalString(action.name) && optionalString(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);
|
|
919
1268
|
}
|
|
920
1269
|
function isSavedStep(value) {
|
|
921
1270
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -973,7 +1322,7 @@ async function waitForSettled(page) {
|
|
|
973
1322
|
}
|
|
974
1323
|
}
|
|
975
1324
|
async function defaultSnapshot(page, maxLines, frames) {
|
|
976
|
-
const { captureSnapshot } = await import("./snapshot-
|
|
1325
|
+
const { captureSnapshot } = await import("./snapshot-RHSNLK3X.js");
|
|
977
1326
|
return captureSnapshot(page, { maxLines, frames });
|
|
978
1327
|
}
|
|
979
1328
|
function slugify(text) {
|
|
@@ -1008,6 +1357,11 @@ function pageChangeNote(before, after) {
|
|
|
1008
1357
|
const lines = [...removed.map((line) => `- ${line.trim()}`), ...added.map((line) => `+ ${line.trim()}`)];
|
|
1009
1358
|
return ` (after it, the only change on the page: ${lines.join("; ")})`;
|
|
1010
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
|
+
}
|
|
1011
1365
|
function pageDiffers(before, after) {
|
|
1012
1366
|
const lines = (page) => new Set(page.replace(/ \[active\]/g, "").split("\n"));
|
|
1013
1367
|
const a = lines(before);
|
|
@@ -1017,6 +1371,18 @@ function pageDiffers(before, after) {
|
|
|
1017
1371
|
return false;
|
|
1018
1372
|
}
|
|
1019
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) {
|
|
1020
1386
|
const {
|
|
1021
1387
|
brain,
|
|
1022
1388
|
sessionDir,
|
|
@@ -1039,7 +1405,32 @@ async function executeTest(page, test, options) {
|
|
|
1039
1405
|
const savedByKey = new Map((replay?.saved ?? []).map((entry) => [entry.key, entry]));
|
|
1040
1406
|
const replayOutcome = { steps: [], ended: [] };
|
|
1041
1407
|
const boundary = allowedOriginsFor(baseUrl, allowedOrigins);
|
|
1042
|
-
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
|
+
};
|
|
1043
1434
|
const startedAt = Date.now();
|
|
1044
1435
|
const stepResults = [];
|
|
1045
1436
|
const allSteps = [
|
|
@@ -1056,7 +1447,8 @@ async function executeTest(page, test, options) {
|
|
|
1056
1447
|
onEvent({ type: "action", index, action: maskedAction, result: mask(result) });
|
|
1057
1448
|
};
|
|
1058
1449
|
let failure;
|
|
1059
|
-
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);
|
|
1060
1452
|
const usedEarlier = /* @__PURE__ */ new Set();
|
|
1061
1453
|
for (let index = 0; index < allSteps.length; index++) {
|
|
1062
1454
|
const { step: written, setup } = allSteps[index];
|
|
@@ -1066,6 +1458,12 @@ async function executeTest(page, test, options) {
|
|
|
1066
1458
|
onEvent({ type: "step-start", index, total: allSteps.length, step: mask(written), setup });
|
|
1067
1459
|
let iterations = 0;
|
|
1068
1460
|
let failedAttempts = 0;
|
|
1461
|
+
let failuresOnPage = 0;
|
|
1462
|
+
let firstFailure;
|
|
1463
|
+
const failedOnPage = (result) => {
|
|
1464
|
+
failuresOnPage++;
|
|
1465
|
+
firstFailure ??= mask(result ?? "");
|
|
1466
|
+
};
|
|
1069
1467
|
let lastResult;
|
|
1070
1468
|
let stepFailedReason;
|
|
1071
1469
|
let lastSnapshot;
|
|
@@ -1073,6 +1471,7 @@ async function executeTest(page, test, options) {
|
|
|
1073
1471
|
const recovery = new StepRecovery(written, step);
|
|
1074
1472
|
const agentRecord = [];
|
|
1075
1473
|
let pageActedOn;
|
|
1474
|
+
let answeredDialog = false;
|
|
1076
1475
|
const key = stepKey(index, setup, written, step);
|
|
1077
1476
|
let live = replay ? savedByKey.get(key) : void 0;
|
|
1078
1477
|
const hadSaved = live !== void 0;
|
|
@@ -1093,7 +1492,14 @@ async function executeTest(page, test, options) {
|
|
|
1093
1492
|
if (iterations >= maxIterationsPerStep) {
|
|
1094
1493
|
throw new StepFailure(`step exceeded ${maxIterationsPerStep} actions without completing`);
|
|
1095
1494
|
}
|
|
1096
|
-
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
|
+
}
|
|
1097
1503
|
if (!isOriginAllowed(page.url(), boundary)) {
|
|
1098
1504
|
throw new StepFailure(
|
|
1099
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.`
|
|
@@ -1125,7 +1531,8 @@ async function executeTest(page, test, options) {
|
|
|
1125
1531
|
lastReplayed = void 0;
|
|
1126
1532
|
}
|
|
1127
1533
|
if (pageActedOn !== void 0) {
|
|
1128
|
-
const note = pageChangeNote(pageActedOn, pageSnap);
|
|
1534
|
+
const note = answeredDialog ? dialogs.isOpen ? void 0 : dialogAnswerNote(pageActedOn, pageSnap) : pageChangeNote(pageActedOn, pageSnap);
|
|
1535
|
+
answeredDialog = false;
|
|
1129
1536
|
const acted = agentRecord[agentRecord.length - 1];
|
|
1130
1537
|
if (note !== void 0 && acted !== void 0 && lastResult !== void 0) {
|
|
1131
1538
|
acted.result += note;
|
|
@@ -1134,7 +1541,7 @@ async function executeTest(page, test, options) {
|
|
|
1134
1541
|
pageActedOn = void 0;
|
|
1135
1542
|
}
|
|
1136
1543
|
let action;
|
|
1137
|
-
const saved = live === void 0 ? void 0 : replayedDecision(live, replayAt, refs);
|
|
1544
|
+
const saved = live === void 0 ? void 0 : replayedDecision(live, replayAt, refs, dialogs.isOpen ? mask(dialogs.name()) : void 0);
|
|
1138
1545
|
if (live !== void 0 && saved === void 0) endReplay("a saved element is not on the page exactly once");
|
|
1139
1546
|
const replayed = saved !== void 0;
|
|
1140
1547
|
if (saved !== void 0) action = saved;
|
|
@@ -1164,6 +1571,19 @@ async function executeTest(page, test, options) {
|
|
|
1164
1571
|
iterations++;
|
|
1165
1572
|
let judgingDone = false;
|
|
1166
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
|
+
}
|
|
1167
1587
|
if (action.action === "done") {
|
|
1168
1588
|
if (!recovery.acted || recovery.verifies) {
|
|
1169
1589
|
lastResult = recovery.verifies ? VERIFICATION_DONE_REFUSAL : NOTHING_DONE_REFUSAL;
|
|
@@ -1173,6 +1593,7 @@ async function executeTest(page, test, options) {
|
|
|
1173
1593
|
continue;
|
|
1174
1594
|
}
|
|
1175
1595
|
failedAttempts++;
|
|
1596
|
+
failedOnPage(lastResult);
|
|
1176
1597
|
emitAction(index, action, lastResult);
|
|
1177
1598
|
if (failedAttempts >= maxRetries) {
|
|
1178
1599
|
throw new StepFailure(lastResult);
|
|
@@ -1214,7 +1635,7 @@ async function executeTest(page, test, options) {
|
|
|
1214
1635
|
[...usedEarlier]
|
|
1215
1636
|
);
|
|
1216
1637
|
if (!judgment.pass) {
|
|
1217
|
-
await
|
|
1638
|
+
await settle();
|
|
1218
1639
|
const freshSnap = await takeSnapshot(page);
|
|
1219
1640
|
lastSnapshot = freshSnap;
|
|
1220
1641
|
const maskedFresh = withoutRefs(mask(freshSnap));
|
|
@@ -1257,6 +1678,7 @@ async function executeTest(page, test, options) {
|
|
|
1257
1678
|
continue;
|
|
1258
1679
|
}
|
|
1259
1680
|
failedAttempts++;
|
|
1681
|
+
failedOnPage(result);
|
|
1260
1682
|
lastResult = result;
|
|
1261
1683
|
if (failedAttempts >= maxRetries) {
|
|
1262
1684
|
throw new StepFailure(judgment.reason);
|
|
@@ -1273,14 +1695,21 @@ async function executeTest(page, test, options) {
|
|
|
1273
1695
|
continue;
|
|
1274
1696
|
}
|
|
1275
1697
|
failedAttempts++;
|
|
1698
|
+
failedOnPage(lastResult);
|
|
1276
1699
|
emitAction(index, action, lastResult);
|
|
1277
1700
|
if (failedAttempts >= maxRetries) {
|
|
1278
1701
|
throw new StepFailure(lastResult);
|
|
1279
1702
|
}
|
|
1280
1703
|
continue;
|
|
1281
1704
|
}
|
|
1282
|
-
const
|
|
1283
|
-
|
|
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);
|
|
1284
1713
|
if (refusal && replayed) {
|
|
1285
1714
|
void activates?.activated();
|
|
1286
1715
|
endReplay(`a saved action was refused (${refusal})`);
|
|
@@ -1288,7 +1717,11 @@ async function executeTest(page, test, options) {
|
|
|
1288
1717
|
}
|
|
1289
1718
|
if (refusal) {
|
|
1290
1719
|
void activates?.activated();
|
|
1291
|
-
|
|
1720
|
+
const unseenDialog = answers === void 0 && dialogs.isOpen && ![...refs.keys()].some(isDialogRef);
|
|
1721
|
+
if (!unseenDialog) {
|
|
1722
|
+
failedAttempts++;
|
|
1723
|
+
failedOnPage(refusal);
|
|
1724
|
+
}
|
|
1292
1725
|
lastResult = refusal;
|
|
1293
1726
|
emitAction(index, action, refusal);
|
|
1294
1727
|
if (failedAttempts >= maxRetries) {
|
|
@@ -1296,25 +1729,56 @@ async function executeTest(page, test, options) {
|
|
|
1296
1729
|
}
|
|
1297
1730
|
continue;
|
|
1298
1731
|
}
|
|
1732
|
+
const answeredName = answers === void 0 ? void 0 : dialogs.name();
|
|
1299
1733
|
try {
|
|
1300
|
-
const
|
|
1734
|
+
const performing = performAction(page, action, {
|
|
1301
1735
|
baseUrl,
|
|
1302
1736
|
allowedOrigins,
|
|
1303
1737
|
resolveValue,
|
|
1304
|
-
resolveTimeoutMs: timeoutMs
|
|
1738
|
+
resolveTimeoutMs: timeoutMs,
|
|
1739
|
+
dialogs
|
|
1305
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
|
+
}
|
|
1306
1765
|
lastResult = result;
|
|
1307
|
-
|
|
1308
|
-
recovery.record(action, mask(describeAction(action)), mask(result), activated);
|
|
1766
|
+
recovery.record(action, mask(describeAction(action)), mask(result), activated, answers);
|
|
1309
1767
|
agentRecord.push({ action: mask(describeAction(action)), result: mask(result) });
|
|
1310
1768
|
pageActedOn = pageSnap;
|
|
1769
|
+
if (answers !== void 0 && pageBeforeDialog !== void 0 && !dialogs.isOpen) {
|
|
1770
|
+
pageActedOn = pageBeforeDialog;
|
|
1771
|
+
pageBeforeDialog = void 0;
|
|
1772
|
+
answeredDialog = true;
|
|
1773
|
+
}
|
|
1311
1774
|
emitAction(index, action, result);
|
|
1312
1775
|
performed.push({
|
|
1313
1776
|
action: action.action,
|
|
1314
1777
|
...action.target?.role === void 0 ? {} : { role: action.target.role },
|
|
1315
1778
|
...action.target?.name === void 0 ? {} : { name: mask(action.target.name) },
|
|
1316
1779
|
...action.value === void 0 ? {} : { value: mask(action.value) },
|
|
1317
|
-
changed: false
|
|
1780
|
+
changed: false,
|
|
1781
|
+
...answeredName === void 0 ? {} : { dialog: mask(answeredName) }
|
|
1318
1782
|
});
|
|
1319
1783
|
if (replayed && live !== void 0) {
|
|
1320
1784
|
lastReplayed = live.actions[replayAt];
|
|
@@ -1329,6 +1793,7 @@ async function executeTest(page, test, options) {
|
|
|
1329
1793
|
continue;
|
|
1330
1794
|
}
|
|
1331
1795
|
failedAttempts++;
|
|
1796
|
+
failedOnPage(lastResult);
|
|
1332
1797
|
if (failedAttempts >= maxRetries) {
|
|
1333
1798
|
throw new StepFailure(lastResult);
|
|
1334
1799
|
}
|
|
@@ -1340,7 +1805,7 @@ async function executeTest(page, test, options) {
|
|
|
1340
1805
|
if (step !== written && error instanceof StepFailure && recovery.acted) {
|
|
1341
1806
|
const check = following.step;
|
|
1342
1807
|
try {
|
|
1343
|
-
await
|
|
1808
|
+
await settle();
|
|
1344
1809
|
if (isOriginAllowed(page.url(), boundary)) {
|
|
1345
1810
|
const snap = await takeSnapshot(page);
|
|
1346
1811
|
lastSnapshot = snap;
|
|
@@ -1356,6 +1821,7 @@ async function executeTest(page, test, options) {
|
|
|
1356
1821
|
};
|
|
1357
1822
|
if (judgment.pass) {
|
|
1358
1823
|
emitAction(index, asked, `ok: the check after this step holds: ${judgment.reason}`);
|
|
1824
|
+
if (failuresOnPage === 0) failedOnPage(stepFailedReason);
|
|
1359
1825
|
stepFailedReason = void 0;
|
|
1360
1826
|
const acted = performed[performed.length - 1];
|
|
1361
1827
|
if (acted !== void 0 && pageActedOn !== void 0) acted.changed = pageDiffers(pageActedOn, pageSnap);
|
|
@@ -1391,7 +1857,8 @@ async function executeTest(page, test, options) {
|
|
|
1391
1857
|
failedAttempts,
|
|
1392
1858
|
reason: stepFailedReason,
|
|
1393
1859
|
durationMs: Date.now() - stepStartedAt,
|
|
1394
|
-
...decidedBy ? { decidedBy } : {}
|
|
1860
|
+
...decidedBy ? { decidedBy } : {},
|
|
1861
|
+
...status === "passed" && failuresOnPage > 0 ? { recovered: { attempts: failuresOnPage, first: firstFailure } } : {}
|
|
1395
1862
|
});
|
|
1396
1863
|
onEvent({ type: "step-end", index, status, reason: stepFailedReason });
|
|
1397
1864
|
if (stepFailedReason) {
|
|
@@ -1401,6 +1868,7 @@ async function executeTest(page, test, options) {
|
|
|
1401
1868
|
}
|
|
1402
1869
|
let screenshot;
|
|
1403
1870
|
if (failure) {
|
|
1871
|
+
await dialogs.dismissOpen();
|
|
1404
1872
|
try {
|
|
1405
1873
|
await mkdir3(sessionDir, { recursive: true });
|
|
1406
1874
|
const stem = `${slugify(test.summary)}-${slugify(path3.basename(test.path))}`;
|
|
@@ -1683,7 +2151,8 @@ async function fromSteps(options) {
|
|
|
1683
2151
|
timeoutMs,
|
|
1684
2152
|
mask: (text) => mask.mask(text),
|
|
1685
2153
|
snapshot: takeSnapshot,
|
|
1686
|
-
onEvent
|
|
2154
|
+
onEvent,
|
|
2155
|
+
onHiddenDialog: options.onHiddenDialog
|
|
1687
2156
|
}
|
|
1688
2157
|
);
|
|
1689
2158
|
if (result.status === "failed") {
|
|
@@ -2171,6 +2640,20 @@ function hiddenFrameWarning(origin) {
|
|
|
2171
2640
|
lines: [`Add it to allowed_origins in .blastproof/config.yaml if the agent should read and act on it.`]
|
|
2172
2641
|
};
|
|
2173
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
|
+
}
|
|
2174
2657
|
|
|
2175
2658
|
// src/report/uncommitted.ts
|
|
2176
2659
|
function printUncommitted(uncommitted, changedFiles, config, baseRef, into) {
|
|
@@ -2211,6 +2694,7 @@ Rules:
|
|
|
2211
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.
|
|
2212
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.
|
|
2213
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.
|
|
2214
2698
|
- Use "assert" with an expectation to verify page state (visible text, counts, URLs). Assertions never modify the page.
|
|
2215
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.
|
|
2216
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.
|
|
@@ -3099,6 +3583,27 @@ import path11 from "path";
|
|
|
3099
3583
|
// src/report/html.ts
|
|
3100
3584
|
import { mkdir as mkdir6, readFile as readFile5, writeFile as writeFile5 } from "fs/promises";
|
|
3101
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
|
+
}
|
|
3605
|
+
|
|
3606
|
+
// src/report/html.ts
|
|
3102
3607
|
var ESCAPES = {
|
|
3103
3608
|
"&": "&",
|
|
3104
3609
|
"<": "<",
|
|
@@ -3172,7 +3677,7 @@ function seconds(ms) {
|
|
|
3172
3677
|
function renderSteps(steps) {
|
|
3173
3678
|
if (steps.length === 0) return "";
|
|
3174
3679
|
const items = steps.map(
|
|
3175
|
-
(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>` : ""}</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>`
|
|
3176
3681
|
).join("\n ");
|
|
3177
3682
|
return `<ol class="steps">
|
|
3178
3683
|
${items}
|
|
@@ -3343,6 +3848,9 @@ function renderJUnit(results, skipped, meta) {
|
|
|
3343
3848
|
// Emitted as 0 too (design D2): unlike a token count nobody reported, 0 is
|
|
3344
3849
|
// a true claim here, that the run printed no warning.
|
|
3345
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)}"/>`,
|
|
3346
3854
|
` <property name="warnings" value="${warnings.length}"/>`,
|
|
3347
3855
|
" </properties>"
|
|
3348
3856
|
];
|
|
@@ -3357,7 +3865,14 @@ function renderJUnit(results, skipped, meta) {
|
|
|
3357
3865
|
}
|
|
3358
3866
|
const open = ` <testcase classname="${escapeXml(relative(result.file))}" name="${escapeXml(result.summary)}" time="${seconds2(result.durationMs)}"`;
|
|
3359
3867
|
if (result.status === "passed") {
|
|
3360
|
-
|
|
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
|
+
}
|
|
3361
3876
|
continue;
|
|
3362
3877
|
}
|
|
3363
3878
|
const reason = result.reason ?? "test failed";
|
|
@@ -3567,6 +4082,13 @@ X ${r.summary} (${r.file})`);
|
|
|
3567
4082
|
if (r.reason) console.log(` reason: ${r.reason}`);
|
|
3568
4083
|
if (r.screenshot) console.log(` screenshot: ${r.screenshot}`);
|
|
3569
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
|
+
}
|
|
3570
4092
|
if (notRun.length > 0) {
|
|
3571
4093
|
console.log(`
|
|
3572
4094
|
${notRun.length} test(s) not run (run stopped: ${notRun[0].reason}):`);
|
|
@@ -3577,7 +4099,7 @@ function deviceTag(test, config) {
|
|
|
3577
4099
|
const device = test.device ?? config.browser.device;
|
|
3578
4100
|
return device ? ` [${device}]` : "";
|
|
3579
4101
|
}
|
|
3580
|
-
async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, onHiddenFrame, firstJudge, replayCwd) {
|
|
4102
|
+
async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, onHiddenFrame, onHiddenDialog, firstJudge, replayCwd) {
|
|
3581
4103
|
const brain = createBrain(createModel(config.llm).model, void 0, budget, firstJudge);
|
|
3582
4104
|
let resolved;
|
|
3583
4105
|
const mask = runMask;
|
|
@@ -3617,6 +4139,7 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3617
4139
|
mask: (text) => mask.mask(text),
|
|
3618
4140
|
onEvent: (event) => printEvent(event, write),
|
|
3619
4141
|
onHiddenFrame,
|
|
4142
|
+
onHiddenDialog,
|
|
3620
4143
|
...saved ? { replay: { saved } } : {}
|
|
3621
4144
|
});
|
|
3622
4145
|
if (replayCwd !== void 0 && saved && result.replay) {
|
|
@@ -3815,6 +4338,8 @@ async function runCommand(options) {
|
|
|
3815
4338
|
const warnings = [];
|
|
3816
4339
|
const hiddenFrames = /* @__PURE__ */ new Set();
|
|
3817
4340
|
const onHiddenFrame = (origin) => hiddenFrames.add(origin);
|
|
4341
|
+
const hiddenDialogs = /* @__PURE__ */ new Set();
|
|
4342
|
+
const onHiddenDialog = (origin) => hiddenDialogs.add(origin);
|
|
3818
4343
|
const impacted = options.impacted ?? false;
|
|
3819
4344
|
const base = options.base ?? "main";
|
|
3820
4345
|
if (options.failOnUnmapped && !impacted) {
|
|
@@ -3961,7 +4486,8 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3961
4486
|
device: config.browser.device,
|
|
3962
4487
|
mask: runMask,
|
|
3963
4488
|
onEvent: printEvent,
|
|
3964
|
-
onHiddenFrame
|
|
4489
|
+
onHiddenFrame,
|
|
4490
|
+
onHiddenDialog
|
|
3965
4491
|
});
|
|
3966
4492
|
} catch (error) {
|
|
3967
4493
|
if (error instanceof RunStoppedError) {
|
|
@@ -3969,6 +4495,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3969
4495
|
} else if (error instanceof AuthError) {
|
|
3970
4496
|
console.error(`error: ${error.message}`);
|
|
3971
4497
|
for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin), warnings);
|
|
4498
|
+
for (const origin of hiddenDialogs) emitWarning(hiddenDialogWarning(origin), warnings);
|
|
3972
4499
|
return EXIT_USAGE;
|
|
3973
4500
|
} else {
|
|
3974
4501
|
throw error;
|
|
@@ -4001,6 +4528,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
4001
4528
|
budget,
|
|
4002
4529
|
write,
|
|
4003
4530
|
onHiddenFrame,
|
|
4531
|
+
onHiddenDialog,
|
|
4004
4532
|
firstJudgeFor(path11.relative(options.cwd, test.path)),
|
|
4005
4533
|
options.replay ?? config.replay ? options.cwd : void 0
|
|
4006
4534
|
);
|
|
@@ -4028,6 +4556,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
4028
4556
|
await browser.close();
|
|
4029
4557
|
}
|
|
4030
4558
|
for (const origin of hiddenFrames) emitWarning(hiddenFrameWarning(origin), warnings);
|
|
4559
|
+
for (const origin of hiddenDialogs) emitWarning(hiddenDialogWarning(origin), warnings);
|
|
4031
4560
|
return finalize(
|
|
4032
4561
|
results,
|
|
4033
4562
|
selection.unroutedSkipped,
|
|
@@ -4380,7 +4909,7 @@ function parsePositiveNumber(flag) {
|
|
|
4380
4909
|
};
|
|
4381
4910
|
}
|
|
4382
4911
|
var program = new Command();
|
|
4383
|
-
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");
|
|
4384
4913
|
program.command("init").description("Scaffold .blastproof/ (config, tests, sample tests) in the current directory").action(async () => {
|
|
4385
4914
|
try {
|
|
4386
4915
|
const result = await initProject(process.cwd());
|