blastproof 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +318 -88
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -121,6 +121,7 @@ steps:
|
|
|
121
121
|
var GITIGNORE = `# blastproof runtime artifacts
|
|
122
122
|
reports/
|
|
123
123
|
sessions/
|
|
124
|
+
cache/
|
|
124
125
|
|
|
125
126
|
# Captured sessions are live credentials \u2014 never commit them.
|
|
126
127
|
.auth-state.json
|
|
@@ -215,11 +216,11 @@ function formatInitGuidance(result) {
|
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
// src/commands/plan.ts
|
|
218
|
-
import
|
|
219
|
+
import path12 from "path";
|
|
219
220
|
|
|
220
221
|
// src/auth.ts
|
|
221
|
-
import { readFile, writeFile as
|
|
222
|
-
import
|
|
222
|
+
import { readFile as readFile2, writeFile as writeFile3, mkdir as mkdir4 } from "fs/promises";
|
|
223
|
+
import path4 from "path";
|
|
223
224
|
|
|
224
225
|
// src/runner/authoring.ts
|
|
225
226
|
var VALUE_VERBS = ["fill", "enter", "type", "input", "set"];
|
|
@@ -556,8 +557,8 @@ var SecretsMask = class {
|
|
|
556
557
|
};
|
|
557
558
|
|
|
558
559
|
// src/runner/executor.ts
|
|
559
|
-
import { mkdir as
|
|
560
|
-
import
|
|
560
|
+
import { mkdir as mkdir3 } from "fs/promises";
|
|
561
|
+
import path3 from "path";
|
|
561
562
|
|
|
562
563
|
// src/runner/recovery.ts
|
|
563
564
|
var COMMIT_ACTIONS = /* @__PURE__ */ new Set(["click", "press"]);
|
|
@@ -861,6 +862,99 @@ var StepRecovery = class {
|
|
|
861
862
|
}
|
|
862
863
|
};
|
|
863
864
|
|
|
865
|
+
// src/runner/replay.ts
|
|
866
|
+
import { createHash } from "crypto";
|
|
867
|
+
import { mkdir as mkdir2, readFile, rename, writeFile as writeFile2 } from "fs/promises";
|
|
868
|
+
import path2 from "path";
|
|
869
|
+
var REPLAY_VERSION = 1;
|
|
870
|
+
function stepKey(index, setup, written, judged) {
|
|
871
|
+
return createHash("sha256").update(JSON.stringify([index, setup, written, judged])).digest("hex").slice(0, 32);
|
|
872
|
+
}
|
|
873
|
+
function normalise2(text) {
|
|
874
|
+
return (text ?? "").replace(/\s+/g, " ").trim().toLowerCase();
|
|
875
|
+
}
|
|
876
|
+
function refOf(saved, refs) {
|
|
877
|
+
let found;
|
|
878
|
+
for (const [ref, element] of refs) {
|
|
879
|
+
if (normalise2(element.role) !== normalise2(saved.role)) continue;
|
|
880
|
+
if (normalise2(element.name ?? element.text) !== normalise2(saved.name)) continue;
|
|
881
|
+
if (found !== void 0) return void 0;
|
|
882
|
+
found = ref;
|
|
883
|
+
}
|
|
884
|
+
return found;
|
|
885
|
+
}
|
|
886
|
+
var REPLAYED = "replayed from the last passing run";
|
|
887
|
+
function replayedDecision(entry, at, refs) {
|
|
888
|
+
const saved = entry.actions[at];
|
|
889
|
+
if (saved === void 0) {
|
|
890
|
+
return entry.close.by === "done" ? { action: "done", reasoning: REPLAYED } : { action: "assert", expectation: entry.close.claim, reasoning: REPLAYED };
|
|
891
|
+
}
|
|
892
|
+
const action = saved.action;
|
|
893
|
+
if (saved.role === void 0) return { action, value: saved.value, reasoning: REPLAYED };
|
|
894
|
+
const ref = refOf(saved, refs);
|
|
895
|
+
if (ref === void 0) return void 0;
|
|
896
|
+
const element = refs.get(ref);
|
|
897
|
+
return {
|
|
898
|
+
action,
|
|
899
|
+
target: { ref, role: element.role, name: element.name ?? element.text },
|
|
900
|
+
value: saved.value,
|
|
901
|
+
reasoning: REPLAYED
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
function replayDir(cwd) {
|
|
905
|
+
return path2.join(cwd, ".blastproof", "cache", "replay");
|
|
906
|
+
}
|
|
907
|
+
function replayFile(cwd, testPath) {
|
|
908
|
+
const relative = path2.relative(cwd, testPath).split(path2.sep).join("/");
|
|
909
|
+
const stem = path2.basename(testPath).replace(/\.ya?ml$/i, "").replace(/[^a-zA-Z0-9_-]+/g, "-").slice(0, 60);
|
|
910
|
+
const hash = createHash("sha256").update(relative).digest("hex").slice(0, 12);
|
|
911
|
+
return path2.join(replayDir(cwd), `${stem}-${hash}.json`);
|
|
912
|
+
}
|
|
913
|
+
var PERFORMED_ACTIONS = /* @__PURE__ */ new Set(["navigate", "click", "fill", "press", "select", "hover"]);
|
|
914
|
+
var optionalString = (value) => value === void 0 || typeof value === "string";
|
|
915
|
+
function isSavedAction(value) {
|
|
916
|
+
if (typeof value !== "object" || value === null) return false;
|
|
917
|
+
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);
|
|
919
|
+
}
|
|
920
|
+
function isSavedStep(value) {
|
|
921
|
+
if (typeof value !== "object" || value === null) return false;
|
|
922
|
+
const step = value;
|
|
923
|
+
const close = step.close;
|
|
924
|
+
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");
|
|
925
|
+
}
|
|
926
|
+
async function loadReplay(file, device) {
|
|
927
|
+
try {
|
|
928
|
+
const parsed = JSON.parse(await readFile(file, "utf8"));
|
|
929
|
+
if (parsed.version !== REPLAY_VERSION || !Array.isArray(parsed.steps)) return [];
|
|
930
|
+
if ((parsed.device ?? void 0) !== device) return [];
|
|
931
|
+
return parsed.steps.filter(isSavedStep);
|
|
932
|
+
} catch {
|
|
933
|
+
return [];
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
function stepsToSave(passed, before, outcome) {
|
|
937
|
+
if (passed) return outcome.steps;
|
|
938
|
+
if (outcome.ended.length === 0) return void 0;
|
|
939
|
+
const ended = new Set(outcome.ended);
|
|
940
|
+
return before.filter((step) => !ended.has(step.key));
|
|
941
|
+
}
|
|
942
|
+
async function saveReplay(file, device, steps) {
|
|
943
|
+
const body = { version: REPLAY_VERSION, ...device ? { device } : {}, steps };
|
|
944
|
+
await mkdir2(path2.dirname(file), { recursive: true });
|
|
945
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
946
|
+
await writeFile2(temporary, `${JSON.stringify(body, null, 2)}
|
|
947
|
+
`, "utf8");
|
|
948
|
+
await rename(temporary, file);
|
|
949
|
+
}
|
|
950
|
+
function replaySummary(decided) {
|
|
951
|
+
const replayed = decided.filter((d) => d === "replayed").length;
|
|
952
|
+
const healed = decided.filter((d) => d === "healed").length;
|
|
953
|
+
const model = decided.filter((d) => d === "model").length + healed;
|
|
954
|
+
const steps = (n) => `${n} ${n === 1 ? "step" : "steps"}`;
|
|
955
|
+
return `Replay: ${steps(replayed)} replayed, ${model} resolved by the model${healed > 0 ? ` (${healed} healed)` : ""}`;
|
|
956
|
+
}
|
|
957
|
+
|
|
864
958
|
// src/runner/executor.ts
|
|
865
959
|
var DEFAULT_MAX_ITERATIONS_PER_STEP = 15;
|
|
866
960
|
var SETTLE_TIMEOUT_MS = 2e3;
|
|
@@ -914,6 +1008,14 @@ function pageChangeNote(before, after) {
|
|
|
914
1008
|
const lines = [...removed.map((line) => `- ${line.trim()}`), ...added.map((line) => `+ ${line.trim()}`)];
|
|
915
1009
|
return ` (after it, the only change on the page: ${lines.join("; ")})`;
|
|
916
1010
|
}
|
|
1011
|
+
function pageDiffers(before, after) {
|
|
1012
|
+
const lines = (page) => new Set(page.replace(/ \[active\]/g, "").split("\n"));
|
|
1013
|
+
const a = lines(before);
|
|
1014
|
+
const b = lines(after);
|
|
1015
|
+
if (a.size !== b.size) return true;
|
|
1016
|
+
for (const line of a) if (!b.has(line)) return true;
|
|
1017
|
+
return false;
|
|
1018
|
+
}
|
|
917
1019
|
async function executeTest(page, test, options) {
|
|
918
1020
|
const {
|
|
919
1021
|
brain,
|
|
@@ -931,8 +1033,11 @@ async function executeTest(page, test, options) {
|
|
|
931
1033
|
onEvent = () => {
|
|
932
1034
|
},
|
|
933
1035
|
onHiddenFrame,
|
|
934
|
-
submitControl = submitControlOf
|
|
1036
|
+
submitControl = submitControlOf,
|
|
1037
|
+
replay
|
|
935
1038
|
} = options;
|
|
1039
|
+
const savedByKey = new Map((replay?.saved ?? []).map((entry) => [entry.key, entry]));
|
|
1040
|
+
const replayOutcome = { steps: [], ended: [] };
|
|
936
1041
|
const boundary = allowedOriginsFor(baseUrl, allowedOrigins);
|
|
937
1042
|
const takeSnapshot = snapshot ?? ((page2) => defaultSnapshot(page2, maxSnapshotLines, { allowed: boundary, onHidden: onHiddenFrame }));
|
|
938
1043
|
const startedAt = Date.now();
|
|
@@ -968,6 +1073,21 @@ async function executeTest(page, test, options) {
|
|
|
968
1073
|
const recovery = new StepRecovery(written, step);
|
|
969
1074
|
const agentRecord = [];
|
|
970
1075
|
let pageActedOn;
|
|
1076
|
+
const key = stepKey(index, setup, written, step);
|
|
1077
|
+
let live = replay ? savedByKey.get(key) : void 0;
|
|
1078
|
+
const hadSaved = live !== void 0;
|
|
1079
|
+
let replayAt = 0;
|
|
1080
|
+
const performed = [];
|
|
1081
|
+
let closed;
|
|
1082
|
+
let lastReplayed;
|
|
1083
|
+
let watchedAfter = -1;
|
|
1084
|
+
const endReplay = (why) => {
|
|
1085
|
+
if (live === void 0) return;
|
|
1086
|
+
live = void 0;
|
|
1087
|
+
lastReplayed = void 0;
|
|
1088
|
+
replayOutcome.ended.push(key);
|
|
1089
|
+
onEvent({ type: "replay-ended", index, reason: mask(why) });
|
|
1090
|
+
};
|
|
971
1091
|
try {
|
|
972
1092
|
while (true) {
|
|
973
1093
|
if (iterations >= maxIterationsPerStep) {
|
|
@@ -980,11 +1100,30 @@ async function executeTest(page, test, options) {
|
|
|
980
1100
|
);
|
|
981
1101
|
}
|
|
982
1102
|
const snap = await takeSnapshot(page);
|
|
1103
|
+
if (pageActedOn !== void 0 && lastReplayed?.changed && !pageDiffers(pageActedOn, withoutRefs(mask(snap)))) {
|
|
1104
|
+
if (watchedAfter !== performed.length) {
|
|
1105
|
+
watchedAfter = performed.length;
|
|
1106
|
+
const deadline = Date.now() + renderWatchMs;
|
|
1107
|
+
let moved = false;
|
|
1108
|
+
while (!moved && Date.now() < deadline) {
|
|
1109
|
+
await new Promise((resolve) => setTimeout(resolve, Math.min(RENDER_POLL_MS, Math.max(0, deadline - Date.now()))));
|
|
1110
|
+
if (!isOriginAllowed(page.url(), boundary)) break;
|
|
1111
|
+
moved = pageDiffers(pageActedOn, withoutRefs(mask(await takeSnapshot(page))));
|
|
1112
|
+
}
|
|
1113
|
+
if (moved || !isOriginAllowed(page.url(), boundary)) continue;
|
|
1114
|
+
}
|
|
1115
|
+
endReplay("the page did not change after an action that had changed it");
|
|
1116
|
+
}
|
|
983
1117
|
lastSnapshot = snap;
|
|
984
1118
|
const maskedSnap = mask(snap);
|
|
985
1119
|
const refs = indexRefs(maskedSnap);
|
|
986
1120
|
const pageSnap = withoutRefs(maskedSnap);
|
|
987
1121
|
recovery.observe(pageSnap);
|
|
1122
|
+
if (pageActedOn !== void 0) {
|
|
1123
|
+
const acted = performed[performed.length - 1];
|
|
1124
|
+
if (acted !== void 0) acted.changed = pageDiffers(pageActedOn, pageSnap);
|
|
1125
|
+
lastReplayed = void 0;
|
|
1126
|
+
}
|
|
988
1127
|
if (pageActedOn !== void 0) {
|
|
989
1128
|
const note = pageChangeNote(pageActedOn, pageSnap);
|
|
990
1129
|
const acted = agentRecord[agentRecord.length - 1];
|
|
@@ -995,7 +1134,11 @@ async function executeTest(page, test, options) {
|
|
|
995
1134
|
pageActedOn = void 0;
|
|
996
1135
|
}
|
|
997
1136
|
let action;
|
|
998
|
-
|
|
1137
|
+
const saved = live === void 0 ? void 0 : replayedDecision(live, replayAt, refs);
|
|
1138
|
+
if (live !== void 0 && saved === void 0) endReplay("a saved element is not on the page exactly once");
|
|
1139
|
+
const replayed = saved !== void 0;
|
|
1140
|
+
if (saved !== void 0) action = saved;
|
|
1141
|
+
else try {
|
|
999
1142
|
action = await brain.nextAction({
|
|
1000
1143
|
// As written, never joined (design an-action-step-takes-the-next-check,
|
|
1001
1144
|
// D2): a model told the check acts to make it true (#139).
|
|
@@ -1023,8 +1166,13 @@ async function executeTest(page, test, options) {
|
|
|
1023
1166
|
const shown = () => judgingDone ? { ...action, action: "done" } : action;
|
|
1024
1167
|
if (action.action === "done") {
|
|
1025
1168
|
if (!recovery.acted || recovery.verifies) {
|
|
1026
|
-
failedAttempts++;
|
|
1027
1169
|
lastResult = recovery.verifies ? VERIFICATION_DONE_REFUSAL : NOTHING_DONE_REFUSAL;
|
|
1170
|
+
if (replayed) {
|
|
1171
|
+
endReplay("its saved close is not allowed for this step");
|
|
1172
|
+
lastResult = void 0;
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
failedAttempts++;
|
|
1028
1176
|
emitAction(index, action, lastResult);
|
|
1029
1177
|
if (failedAttempts >= maxRetries) {
|
|
1030
1178
|
throw new StepFailure(lastResult);
|
|
@@ -1033,6 +1181,7 @@ async function executeTest(page, test, options) {
|
|
|
1033
1181
|
}
|
|
1034
1182
|
if (!recovery.checksAfterActing) {
|
|
1035
1183
|
emitAction(index, action, action.reasoning);
|
|
1184
|
+
closed = { by: "done" };
|
|
1036
1185
|
break;
|
|
1037
1186
|
}
|
|
1038
1187
|
judgingDone = true;
|
|
@@ -1080,9 +1229,13 @@ async function executeTest(page, test, options) {
|
|
|
1080
1229
|
}
|
|
1081
1230
|
} catch (error) {
|
|
1082
1231
|
if (error instanceof RunStoppedError) throw error;
|
|
1083
|
-
failedAttempts++;
|
|
1084
1232
|
lastResult = `error: ${error instanceof Error ? error.message : String(error)}`;
|
|
1085
1233
|
emitAction(index, shown(), lastResult);
|
|
1234
|
+
if (replayed) {
|
|
1235
|
+
endReplay("its judgment gave no answer");
|
|
1236
|
+
continue;
|
|
1237
|
+
}
|
|
1238
|
+
failedAttempts++;
|
|
1086
1239
|
if (failedAttempts >= maxRetries) {
|
|
1087
1240
|
throw new StepFailure(lastResult);
|
|
1088
1241
|
}
|
|
@@ -1095,8 +1248,14 @@ async function executeTest(page, test, options) {
|
|
|
1095
1248
|
emitAction(index, shown(), result);
|
|
1096
1249
|
if (judgment.pass) {
|
|
1097
1250
|
lastResult = result;
|
|
1251
|
+
closed = { by: "judgment", claim: mask(expectation) };
|
|
1098
1252
|
break;
|
|
1099
1253
|
}
|
|
1254
|
+
if (replayed) {
|
|
1255
|
+
lastResult = result;
|
|
1256
|
+
endReplay("the judgment of its saved claim failed");
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1100
1259
|
failedAttempts++;
|
|
1101
1260
|
lastResult = result;
|
|
1102
1261
|
if (failedAttempts >= maxRetries) {
|
|
@@ -1107,8 +1266,13 @@ async function executeTest(page, test, options) {
|
|
|
1107
1266
|
try {
|
|
1108
1267
|
action = bindTarget(action, refs);
|
|
1109
1268
|
} catch (error) {
|
|
1110
|
-
failedAttempts++;
|
|
1111
1269
|
lastResult = error instanceof Error ? error.message : String(error);
|
|
1270
|
+
if (replayed) {
|
|
1271
|
+
endReplay(`a saved action was refused (${lastResult})`);
|
|
1272
|
+
lastResult = void 0;
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
failedAttempts++;
|
|
1112
1276
|
emitAction(index, action, lastResult);
|
|
1113
1277
|
if (failedAttempts >= maxRetries) {
|
|
1114
1278
|
throw new StepFailure(lastResult);
|
|
@@ -1117,6 +1281,11 @@ async function executeTest(page, test, options) {
|
|
|
1117
1281
|
}
|
|
1118
1282
|
const activates = await submitControl(page, action, refs);
|
|
1119
1283
|
const refusal = recovery.refusalFor(action, activates);
|
|
1284
|
+
if (refusal && replayed) {
|
|
1285
|
+
void activates?.activated();
|
|
1286
|
+
endReplay(`a saved action was refused (${refusal})`);
|
|
1287
|
+
continue;
|
|
1288
|
+
}
|
|
1120
1289
|
if (refusal) {
|
|
1121
1290
|
void activates?.activated();
|
|
1122
1291
|
failedAttempts++;
|
|
@@ -1140,11 +1309,26 @@ async function executeTest(page, test, options) {
|
|
|
1140
1309
|
agentRecord.push({ action: mask(describeAction(action)), result: mask(result) });
|
|
1141
1310
|
pageActedOn = pageSnap;
|
|
1142
1311
|
emitAction(index, action, result);
|
|
1312
|
+
performed.push({
|
|
1313
|
+
action: action.action,
|
|
1314
|
+
...action.target?.role === void 0 ? {} : { role: action.target.role },
|
|
1315
|
+
...action.target?.name === void 0 ? {} : { name: mask(action.target.name) },
|
|
1316
|
+
...action.value === void 0 ? {} : { value: mask(action.value) },
|
|
1317
|
+
changed: false
|
|
1318
|
+
});
|
|
1319
|
+
if (replayed && live !== void 0) {
|
|
1320
|
+
lastReplayed = live.actions[replayAt];
|
|
1321
|
+
replayAt++;
|
|
1322
|
+
}
|
|
1143
1323
|
} catch (error) {
|
|
1144
1324
|
void activates?.activated();
|
|
1145
|
-
failedAttempts++;
|
|
1146
1325
|
lastResult = `error: ${error instanceof Error ? error.message : String(error)}`;
|
|
1147
1326
|
emitAction(index, action, lastResult);
|
|
1327
|
+
if (replayed) {
|
|
1328
|
+
endReplay(`a saved action failed (${lastResult})`);
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
failedAttempts++;
|
|
1148
1332
|
if (failedAttempts >= maxRetries) {
|
|
1149
1333
|
throw new StepFailure(lastResult);
|
|
1150
1334
|
}
|
|
@@ -1173,6 +1357,9 @@ async function executeTest(page, test, options) {
|
|
|
1173
1357
|
if (judgment.pass) {
|
|
1174
1358
|
emitAction(index, asked, `ok: the check after this step holds: ${judgment.reason}`);
|
|
1175
1359
|
stepFailedReason = void 0;
|
|
1360
|
+
const acted = performed[performed.length - 1];
|
|
1361
|
+
if (acted !== void 0 && pageActedOn !== void 0) acted.changed = pageDiffers(pageActedOn, pageSnap);
|
|
1362
|
+
closed = { by: "judgment", claim: mask(check) };
|
|
1176
1363
|
} else {
|
|
1177
1364
|
emitAction(index, asked, `the check after this step does not hold either: ${judgment.reason}`);
|
|
1178
1365
|
}
|
|
@@ -1190,6 +1377,11 @@ async function executeTest(page, test, options) {
|
|
|
1190
1377
|
for (const name of referencedEnvVars(entry.action)) usedEarlier.add(name);
|
|
1191
1378
|
}
|
|
1192
1379
|
const status = stepFailedReason ? "failed" : "passed";
|
|
1380
|
+
if (status === "failed" && live !== void 0) replayOutcome.ended.push(key);
|
|
1381
|
+
const decidedBy = !replay ? void 0 : hadSaved && live !== void 0 && status === "passed" ? "replayed" : hadSaved && status === "passed" ? "healed" : "model";
|
|
1382
|
+
if (replay && status === "passed" && closed !== void 0) {
|
|
1383
|
+
replayOutcome.steps.push({ key, actions: performed, close: closed });
|
|
1384
|
+
}
|
|
1193
1385
|
stepResults.push({
|
|
1194
1386
|
step: mask(written),
|
|
1195
1387
|
// results are a report channel — never store substituted secrets
|
|
@@ -1198,7 +1390,8 @@ async function executeTest(page, test, options) {
|
|
|
1198
1390
|
iterations,
|
|
1199
1391
|
failedAttempts,
|
|
1200
1392
|
reason: stepFailedReason,
|
|
1201
|
-
durationMs: Date.now() - stepStartedAt
|
|
1393
|
+
durationMs: Date.now() - stepStartedAt,
|
|
1394
|
+
...decidedBy ? { decidedBy } : {}
|
|
1202
1395
|
});
|
|
1203
1396
|
onEvent({ type: "step-end", index, status, reason: stepFailedReason });
|
|
1204
1397
|
if (stepFailedReason) {
|
|
@@ -1209,9 +1402,9 @@ async function executeTest(page, test, options) {
|
|
|
1209
1402
|
let screenshot;
|
|
1210
1403
|
if (failure) {
|
|
1211
1404
|
try {
|
|
1212
|
-
await
|
|
1213
|
-
const stem = `${slugify(test.summary)}-${slugify(
|
|
1214
|
-
const file =
|
|
1405
|
+
await mkdir3(sessionDir, { recursive: true });
|
|
1406
|
+
const stem = `${slugify(test.summary)}-${slugify(path3.basename(test.path))}`;
|
|
1407
|
+
const file = path3.join(sessionDir, `${stem}.png`);
|
|
1215
1408
|
await page.screenshot({ path: file, fullPage: true });
|
|
1216
1409
|
screenshot = file;
|
|
1217
1410
|
} catch {
|
|
@@ -1227,6 +1420,7 @@ async function executeTest(page, test, options) {
|
|
|
1227
1420
|
failedStep: failure?.step,
|
|
1228
1421
|
reason: failure?.reason,
|
|
1229
1422
|
screenshot,
|
|
1423
|
+
...replay ? { replay: replayOutcome } : {},
|
|
1230
1424
|
durationMs: Date.now() - startedAt
|
|
1231
1425
|
};
|
|
1232
1426
|
}
|
|
@@ -1386,7 +1580,7 @@ function isSessionStorageSeed(value) {
|
|
|
1386
1580
|
}
|
|
1387
1581
|
|
|
1388
1582
|
// src/auth.ts
|
|
1389
|
-
var AUTH_STATE_RELATIVE_PATH =
|
|
1583
|
+
var AUTH_STATE_RELATIVE_PATH = path4.join(".blastproof", ".auth-state.json");
|
|
1390
1584
|
var AuthError = class extends Error {
|
|
1391
1585
|
constructor(message) {
|
|
1392
1586
|
super(message);
|
|
@@ -1399,7 +1593,7 @@ function isStorageState(value) {
|
|
|
1399
1593
|
async function fromStorageState(file) {
|
|
1400
1594
|
let raw;
|
|
1401
1595
|
try {
|
|
1402
|
-
raw = await
|
|
1596
|
+
raw = await readFile2(file, "utf8");
|
|
1403
1597
|
} catch {
|
|
1404
1598
|
throw new AuthError(
|
|
1405
1599
|
`Cannot read auth.storage_state at ${file}. Capture a session first, or switch to an auth.steps recipe.`
|
|
@@ -1481,7 +1675,7 @@ async function fromSteps(options) {
|
|
|
1481
1675
|
},
|
|
1482
1676
|
{
|
|
1483
1677
|
brain,
|
|
1484
|
-
sessionDir:
|
|
1678
|
+
sessionDir: path4.join(options.cwd, ".blastproof", "reports", "auth"),
|
|
1485
1679
|
baseUrl,
|
|
1486
1680
|
allowedOrigins: options.allowedOrigins,
|
|
1487
1681
|
resolveValue: (value) => substituteEnv(value),
|
|
@@ -1565,17 +1759,17 @@ async function checkWhereUsed(options, session, loginPage, takeSnapshot) {
|
|
|
1565
1759
|
}
|
|
1566
1760
|
async function readCached(cwd) {
|
|
1567
1761
|
try {
|
|
1568
|
-
return await fromStorageState(
|
|
1762
|
+
return await fromStorageState(path4.join(cwd, AUTH_STATE_RELATIVE_PATH));
|
|
1569
1763
|
} catch {
|
|
1570
1764
|
return void 0;
|
|
1571
1765
|
}
|
|
1572
1766
|
}
|
|
1573
1767
|
async function writeCached(cwd, session) {
|
|
1574
1768
|
if (!session.storageState) return;
|
|
1575
|
-
const file =
|
|
1576
|
-
await
|
|
1769
|
+
const file = path4.join(cwd, AUTH_STATE_RELATIVE_PATH);
|
|
1770
|
+
await mkdir4(path4.dirname(file), { recursive: true });
|
|
1577
1771
|
const cached = session.sessionStorage ? { ...session.storageState, sessionStorage: session.sessionStorage } : session.storageState;
|
|
1578
|
-
await
|
|
1772
|
+
await writeFile3(file, JSON.stringify(cached), "utf8");
|
|
1579
1773
|
}
|
|
1580
1774
|
async function authenticate(options) {
|
|
1581
1775
|
const { auth, cwd } = options;
|
|
@@ -1584,7 +1778,7 @@ async function authenticate(options) {
|
|
|
1584
1778
|
if (cached) return cached;
|
|
1585
1779
|
}
|
|
1586
1780
|
if (auth.storage_state) {
|
|
1587
|
-
return fromStorageState(
|
|
1781
|
+
return fromStorageState(path4.resolve(cwd, auth.storage_state));
|
|
1588
1782
|
}
|
|
1589
1783
|
if (auth.headers || auth.cookies) {
|
|
1590
1784
|
return fromStatic(auth, options.mask);
|
|
@@ -1606,11 +1800,11 @@ async function seedContext(context, session) {
|
|
|
1606
1800
|
}
|
|
1607
1801
|
|
|
1608
1802
|
// src/config.ts
|
|
1609
|
-
import { readFile as
|
|
1610
|
-
import
|
|
1803
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1804
|
+
import path5 from "path";
|
|
1611
1805
|
import { parse as parseYaml } from "yaml";
|
|
1612
1806
|
import { z } from "zod";
|
|
1613
|
-
var CONFIG_RELATIVE_PATH =
|
|
1807
|
+
var CONFIG_RELATIVE_PATH = path5.join(".blastproof", "config.yaml");
|
|
1614
1808
|
var llmSchema = z.object({
|
|
1615
1809
|
provider: z.enum(["anthropic", "openai", "ollama"]).default("anthropic"),
|
|
1616
1810
|
model: z.string().min(1).optional(),
|
|
@@ -1755,6 +1949,13 @@ var configSchema = z.object({
|
|
|
1755
1949
|
* those tests, not of the runner. Opted into by the person who knows.
|
|
1756
1950
|
*/
|
|
1757
1951
|
concurrency: z.number().int().min(1, "concurrency must be at least 1").default(1),
|
|
1952
|
+
/**
|
|
1953
|
+
* Replays the actions of a step that passed instead of asking the model again
|
|
1954
|
+
* (design replay-the-actions-of-a-passing-step, D8). Off by default: a gate
|
|
1955
|
+
* must not start deciding differently on an upgrade. `BLASTPROOF_REPLAY` is
|
|
1956
|
+
* text, so the two words a boolean is written with are read as one.
|
|
1957
|
+
*/
|
|
1958
|
+
replay: z.preprocess((value) => value === "true" ? true : value === "false" ? false : value, z.boolean()).default(false),
|
|
1758
1959
|
budget: budgetSchema.optional(),
|
|
1759
1960
|
first_judge: firstJudgeSchema.optional()
|
|
1760
1961
|
});
|
|
@@ -1770,7 +1971,8 @@ var ENV_OVERRIDES = {
|
|
|
1770
1971
|
BLASTPROOF_MAX_DURATION_S: ["budget", "max_duration_s"],
|
|
1771
1972
|
BLASTPROOF_FIRST_JUDGE_MODEL: ["first_judge", "model"],
|
|
1772
1973
|
BLASTPROOF_FIRST_JUDGE_THRESHOLD: ["first_judge", "threshold"],
|
|
1773
|
-
BLASTPROOF_BROWSER_DEVICE: ["browser", "device"]
|
|
1974
|
+
BLASTPROOF_BROWSER_DEVICE: ["browser", "device"],
|
|
1975
|
+
BLASTPROOF_REPLAY: ["replay"]
|
|
1774
1976
|
};
|
|
1775
1977
|
function applyEnvOverrides(data, env = process.env) {
|
|
1776
1978
|
const merged = data && typeof data === "object" ? { ...data } : {};
|
|
@@ -1816,13 +2018,13 @@ function unwrapToObjectSchema(schema) {
|
|
|
1816
2018
|
}
|
|
1817
2019
|
return current instanceof z.ZodObject ? current : void 0;
|
|
1818
2020
|
}
|
|
1819
|
-
function findUnknownConfigKeys(data, schema = configSchema,
|
|
2021
|
+
function findUnknownConfigKeys(data, schema = configSchema, path13 = []) {
|
|
1820
2022
|
const object = unwrapToObjectSchema(schema);
|
|
1821
2023
|
if (!object || data === null || typeof data !== "object" || Array.isArray(data)) return [];
|
|
1822
2024
|
const shape = object.shape;
|
|
1823
2025
|
const warnings = [];
|
|
1824
2026
|
for (const key of Object.keys(data)) {
|
|
1825
|
-
const fieldPath = [...
|
|
2027
|
+
const fieldPath = [...path13, key];
|
|
1826
2028
|
const fieldSchema = shape[key];
|
|
1827
2029
|
if (!fieldSchema) {
|
|
1828
2030
|
warnings.push(fieldPath.join("."));
|
|
@@ -1833,10 +2035,10 @@ function findUnknownConfigKeys(data, schema = configSchema, path12 = []) {
|
|
|
1833
2035
|
return warnings;
|
|
1834
2036
|
}
|
|
1835
2037
|
async function loadConfig(cwd = process.cwd(), env = process.env) {
|
|
1836
|
-
const configPath =
|
|
2038
|
+
const configPath = path5.join(cwd, CONFIG_RELATIVE_PATH);
|
|
1837
2039
|
let raw;
|
|
1838
2040
|
try {
|
|
1839
|
-
raw = await
|
|
2041
|
+
raw = await readFile3(configPath, "utf8");
|
|
1840
2042
|
} catch {
|
|
1841
2043
|
throw new ConfigError(
|
|
1842
2044
|
`No config found at ${CONFIG_RELATIVE_PATH}. Run \`blastproof init\` to scaffold one.`
|
|
@@ -2122,7 +2324,7 @@ function plannerUserPrompt(input) {
|
|
|
2122
2324
|
|
|
2123
2325
|
// src/llm/decision.ts
|
|
2124
2326
|
import { appendFileSync, mkdirSync } from "fs";
|
|
2125
|
-
import
|
|
2327
|
+
import path6 from "path";
|
|
2126
2328
|
import { APICallError } from "ai";
|
|
2127
2329
|
|
|
2128
2330
|
// src/llm/provider.ts
|
|
@@ -2307,7 +2509,7 @@ var FirstJudgeLog = class {
|
|
|
2307
2509
|
else this.toLlm++;
|
|
2308
2510
|
if (entry.outcome === "too-large" || !this.file) return;
|
|
2309
2511
|
if (!this.dirReady) {
|
|
2310
|
-
mkdirSync(
|
|
2512
|
+
mkdirSync(path6.dirname(this.file), { recursive: true });
|
|
2311
2513
|
this.dirReady = true;
|
|
2312
2514
|
}
|
|
2313
2515
|
const line = {
|
|
@@ -2329,7 +2531,7 @@ var FirstJudgeLog = class {
|
|
|
2329
2531
|
}
|
|
2330
2532
|
};
|
|
2331
2533
|
function firstJudgeLogPath(sessionDir) {
|
|
2332
|
-
return
|
|
2534
|
+
return path6.join(sessionDir, "first-judge.jsonl");
|
|
2333
2535
|
}
|
|
2334
2536
|
function createFirstJudgeClient(config, env = process.env, fetchImpl) {
|
|
2335
2537
|
const apiKey = env[config.api_key_env];
|
|
@@ -2571,16 +2773,16 @@ function createPlanner(model, generate = generateObject, budget) {
|
|
|
2571
2773
|
}
|
|
2572
2774
|
|
|
2573
2775
|
// src/planner.ts
|
|
2574
|
-
import { mkdir as
|
|
2575
|
-
import
|
|
2776
|
+
import { mkdir as mkdir5, writeFile as writeFile4 } from "fs/promises";
|
|
2777
|
+
import path8 from "path";
|
|
2576
2778
|
import { stringify } from "yaml";
|
|
2577
2779
|
|
|
2578
2780
|
// src/runner/testfile.ts
|
|
2579
|
-
import { readFile as
|
|
2580
|
-
import
|
|
2781
|
+
import { readFile as readFile4, readdir } from "fs/promises";
|
|
2782
|
+
import path7 from "path";
|
|
2581
2783
|
import { parse as parseYaml2 } from "yaml";
|
|
2582
2784
|
import { z as z3 } from "zod";
|
|
2583
|
-
var TESTS_RELATIVE_DIR =
|
|
2785
|
+
var TESTS_RELATIVE_DIR = path7.join(".blastproof", "tests");
|
|
2584
2786
|
var prioritySchema = z3.enum(["P0", "P1", "P2"]);
|
|
2585
2787
|
var testFileSchema = z3.object({
|
|
2586
2788
|
summary: z3.string().min(1),
|
|
@@ -2604,7 +2806,7 @@ function formatIssues2(error) {
|
|
|
2604
2806
|
async function parseTestFile(filePath) {
|
|
2605
2807
|
let raw;
|
|
2606
2808
|
try {
|
|
2607
|
-
raw = await
|
|
2809
|
+
raw = await readFile4(filePath, "utf8");
|
|
2608
2810
|
} catch {
|
|
2609
2811
|
throw new TestFileError(`Cannot read test file: ${filePath}`);
|
|
2610
2812
|
}
|
|
@@ -2628,7 +2830,7 @@ async function discoverTestFiles(root) {
|
|
|
2628
2830
|
async function walk(dir) {
|
|
2629
2831
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
2630
2832
|
for (const entry of entries) {
|
|
2631
|
-
const full =
|
|
2833
|
+
const full = path7.join(dir, entry.name);
|
|
2632
2834
|
if (entry.isDirectory()) {
|
|
2633
2835
|
await walk(full);
|
|
2634
2836
|
} else if (/\.ya?ml$/i.test(entry.name)) {
|
|
@@ -2716,20 +2918,20 @@ async function generateForRoute(page, options) {
|
|
|
2716
2918
|
};
|
|
2717
2919
|
}
|
|
2718
2920
|
async function writeDraft(cwd, draft, meta) {
|
|
2719
|
-
const dir =
|
|
2720
|
-
const file =
|
|
2921
|
+
const dir = path8.join(cwd, TESTS_RELATIVE_DIR);
|
|
2922
|
+
const file = path8.join(dir, `${routeToSlug(meta.route)}.yaml`);
|
|
2721
2923
|
try {
|
|
2722
|
-
await
|
|
2723
|
-
await
|
|
2924
|
+
await mkdir5(dir, { recursive: true });
|
|
2925
|
+
await writeFile4(file, renderTestYaml(draft, meta), { flag: "wx" });
|
|
2724
2926
|
} catch (error) {
|
|
2725
2927
|
const err = error;
|
|
2726
2928
|
if (err.code === "EEXIST" && err.syscall !== "mkdir") {
|
|
2727
2929
|
throw new PlannerError(
|
|
2728
|
-
`Refusing to overwrite ${
|
|
2930
|
+
`Refusing to overwrite ${path8.relative(cwd, file)} (route ${meta.route}). Delete or rename it to regenerate.`
|
|
2729
2931
|
);
|
|
2730
2932
|
}
|
|
2731
2933
|
throw new PlannerError(
|
|
2732
|
-
`Cannot write draft to ${file}: ${fsReason(error)}. Check that ${
|
|
2934
|
+
`Cannot write draft to ${file}: ${fsReason(error)}. Check that ${path8.dirname(file)} is a directory you can write to, not a file.`
|
|
2733
2935
|
);
|
|
2734
2936
|
}
|
|
2735
2937
|
return file;
|
|
@@ -2892,11 +3094,11 @@ function formatSpendLine(spend) {
|
|
|
2892
3094
|
}
|
|
2893
3095
|
|
|
2894
3096
|
// src/commands/run.ts
|
|
2895
|
-
import
|
|
3097
|
+
import path11 from "path";
|
|
2896
3098
|
|
|
2897
3099
|
// src/report/html.ts
|
|
2898
|
-
import { mkdir as
|
|
2899
|
-
import
|
|
3100
|
+
import { mkdir as mkdir6, readFile as readFile5, writeFile as writeFile5 } from "fs/promises";
|
|
3101
|
+
import path9 from "path";
|
|
2900
3102
|
var ESCAPES = {
|
|
2901
3103
|
"&": "&",
|
|
2902
3104
|
"<": "<",
|
|
@@ -2909,7 +3111,7 @@ function escapeHtml(text) {
|
|
|
2909
3111
|
}
|
|
2910
3112
|
async function embedScreenshot(file) {
|
|
2911
3113
|
try {
|
|
2912
|
-
const bytes = await
|
|
3114
|
+
const bytes = await readFile5(file);
|
|
2913
3115
|
return `data:image/png;base64,${bytes.toString("base64")}`;
|
|
2914
3116
|
} catch {
|
|
2915
3117
|
return void 0;
|
|
@@ -2970,14 +3172,14 @@ function seconds(ms) {
|
|
|
2970
3172
|
function renderSteps(steps) {
|
|
2971
3173
|
if (steps.length === 0) return "";
|
|
2972
3174
|
const items = steps.map(
|
|
2973
|
-
(step) => `<li class="${step.status === "failed" ? "failed" : ""}">${escapeHtml(step.step)}${step.setup ? ' <span class="note">(setup)</span>' : ""}</li>`
|
|
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>`
|
|
2974
3176
|
).join("\n ");
|
|
2975
3177
|
return `<ol class="steps">
|
|
2976
3178
|
${items}
|
|
2977
3179
|
</ol>`;
|
|
2978
3180
|
}
|
|
2979
3181
|
function withheldScreenshot(file, reportDir) {
|
|
2980
|
-
const href =
|
|
3182
|
+
const href = path9.relative(reportDir, file).split(path9.sep).join("/");
|
|
2981
3183
|
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
3184
|
}
|
|
2983
3185
|
async function renderTest(result, screenshots, cwd) {
|
|
@@ -2985,7 +3187,7 @@ async function renderTest(result, screenshots, cwd) {
|
|
|
2985
3187
|
const notRun = result.status === "not-run";
|
|
2986
3188
|
const tagClass = failed ? "fail" : notRun ? "skip" : "pass";
|
|
2987
3189
|
const label = failed ? "FAIL" : notRun ? "NOT RUN" : "PASS";
|
|
2988
|
-
const file = cwd ?
|
|
3190
|
+
const file = cwd ? path9.relative(cwd, result.file) : result.file;
|
|
2989
3191
|
const device = result.device ? ` \xB7 ${escapeHtml(result.device)}` : "";
|
|
2990
3192
|
const parts = [
|
|
2991
3193
|
` <details${failed || notRun ? " open" : ""}>`,
|
|
@@ -3033,14 +3235,14 @@ async function renderHtml(results, skipped, meta) {
|
|
|
3033
3235
|
<pre>${escapeHtml(w.lines.join("\n"))}</pre>` : "")
|
|
3034
3236
|
).join("\n") + "\n </section>\n\n";
|
|
3035
3237
|
const rows = results.map((r) => {
|
|
3036
|
-
const file = meta.cwd ?
|
|
3238
|
+
const file = meta.cwd ? path9.relative(meta.cwd, r.file) : r.file;
|
|
3037
3239
|
const tagClass = r.status === "failed" ? "fail" : r.status === "not-run" ? "skip" : "pass";
|
|
3038
3240
|
const label = r.status === "failed" ? "FAIL" : r.status === "not-run" ? "NOT RUN" : "PASS";
|
|
3039
3241
|
const time = r.status === "not-run" ? "\u2014" : seconds(r.durationMs);
|
|
3040
3242
|
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
3243
|
}).join("\n");
|
|
3042
3244
|
const skippedRows = skipped.map((s) => {
|
|
3043
|
-
const file = meta.cwd ?
|
|
3245
|
+
const file = meta.cwd ? path9.relative(meta.cwd, s.path) : s.path;
|
|
3044
3246
|
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
3247
|
}).join("\n");
|
|
3046
3248
|
return `<!doctype html>
|
|
@@ -3079,8 +3281,8 @@ ${detail}
|
|
|
3079
3281
|
}
|
|
3080
3282
|
async function writeHtml(file, html) {
|
|
3081
3283
|
try {
|
|
3082
|
-
await
|
|
3083
|
-
await
|
|
3284
|
+
await mkdir6(path9.dirname(file), { recursive: true });
|
|
3285
|
+
await writeFile5(file, html, "utf8");
|
|
3084
3286
|
return file;
|
|
3085
3287
|
} catch (error) {
|
|
3086
3288
|
throw new ReportError(
|
|
@@ -3090,8 +3292,8 @@ async function writeHtml(file, html) {
|
|
|
3090
3292
|
}
|
|
3091
3293
|
|
|
3092
3294
|
// src/report/junit.ts
|
|
3093
|
-
import { mkdir as
|
|
3094
|
-
import
|
|
3295
|
+
import { mkdir as mkdir7, writeFile as writeFile6 } from "fs/promises";
|
|
3296
|
+
import path10 from "path";
|
|
3095
3297
|
var ESCAPES2 = {
|
|
3096
3298
|
"&": "&",
|
|
3097
3299
|
"<": "<",
|
|
@@ -3105,8 +3307,19 @@ function escapeXml(text) {
|
|
|
3105
3307
|
function seconds2(ms) {
|
|
3106
3308
|
return (ms / 1e3).toFixed(3);
|
|
3107
3309
|
}
|
|
3310
|
+
function replayProperties(results) {
|
|
3311
|
+
const decided = results.flatMap((result) => result.steps.map((step) => step.decidedBy));
|
|
3312
|
+
if (!decided.some((by) => by !== void 0)) return [];
|
|
3313
|
+
const count2 = (by) => decided.filter((d) => d === by).length;
|
|
3314
|
+
const healed = count2("healed");
|
|
3315
|
+
return [
|
|
3316
|
+
` <property name="replayed_steps" value="${count2("replayed")}"/>`,
|
|
3317
|
+
` <property name="model_steps" value="${count2("model") + healed}"/>`,
|
|
3318
|
+
` <property name="healed_steps" value="${healed}"/>`
|
|
3319
|
+
];
|
|
3320
|
+
}
|
|
3108
3321
|
function renderJUnit(results, skipped, meta) {
|
|
3109
|
-
const relative = (file) => meta.cwd ?
|
|
3322
|
+
const relative = (file) => meta.cwd ? path10.relative(meta.cwd, file) : file;
|
|
3110
3323
|
const warnings = meta.warnings ?? [];
|
|
3111
3324
|
const failures = results.filter((result) => result.status === "failed").length;
|
|
3112
3325
|
const notRun = results.filter((result) => result.status === "not-run");
|
|
@@ -3129,6 +3342,7 @@ function renderJUnit(results, skipped, meta) {
|
|
|
3129
3342
|
] : [],
|
|
3130
3343
|
// Emitted as 0 too (design D2): unlike a token count nobody reported, 0 is
|
|
3131
3344
|
// a true claim here, that the run printed no warning.
|
|
3345
|
+
...replayProperties(results),
|
|
3132
3346
|
` <property name="warnings" value="${warnings.length}"/>`,
|
|
3133
3347
|
" </properties>"
|
|
3134
3348
|
];
|
|
@@ -3168,8 +3382,8 @@ ${reason}` : reason;
|
|
|
3168
3382
|
}
|
|
3169
3383
|
async function writeJUnit(file, xml) {
|
|
3170
3384
|
try {
|
|
3171
|
-
await
|
|
3172
|
-
await
|
|
3385
|
+
await mkdir7(path10.dirname(file), { recursive: true });
|
|
3386
|
+
await writeFile6(file, xml, "utf8");
|
|
3173
3387
|
return file;
|
|
3174
3388
|
} catch (error) {
|
|
3175
3389
|
throw new ReportError(
|
|
@@ -3314,6 +3528,9 @@ function printEvent(event, write = console.log) {
|
|
|
3314
3528
|
write(` X step failed: ${event.reason ?? "unknown reason"}`);
|
|
3315
3529
|
}
|
|
3316
3530
|
break;
|
|
3531
|
+
case "replay-ended":
|
|
3532
|
+
write(` ~ replay ended: ${event.reason}; the model takes over`);
|
|
3533
|
+
break;
|
|
3317
3534
|
}
|
|
3318
3535
|
}
|
|
3319
3536
|
function statusLabel(status) {
|
|
@@ -3360,7 +3577,7 @@ function deviceTag(test, config) {
|
|
|
3360
3577
|
const device = test.device ?? config.browser.device;
|
|
3361
3578
|
return device ? ` [${device}]` : "";
|
|
3362
3579
|
}
|
|
3363
|
-
async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, onHiddenFrame, firstJudge) {
|
|
3580
|
+
async function runOne(browser, test, config, sessionDir, session, runMask, budget, write, onHiddenFrame, firstJudge, replayCwd) {
|
|
3364
3581
|
const brain = createBrain(createModel(config.llm).model, void 0, budget, firstJudge);
|
|
3365
3582
|
let resolved;
|
|
3366
3583
|
const mask = runMask;
|
|
@@ -3382,6 +3599,7 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3382
3599
|
throw error;
|
|
3383
3600
|
}
|
|
3384
3601
|
const device = test.device ?? config.browser.device;
|
|
3602
|
+
const saved = replayCwd === void 0 ? void 0 : await loadReplay(replayFile(replayCwd, test.path), device);
|
|
3385
3603
|
const context = await browser.newContext(contextOptions(test.auth ? session : void 0, device));
|
|
3386
3604
|
try {
|
|
3387
3605
|
await seedContext(context, test.auth ? session : void 0);
|
|
@@ -3398,8 +3616,14 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3398
3616
|
maxSnapshotLines: config.browser.max_snapshot_lines,
|
|
3399
3617
|
mask: (text) => mask.mask(text),
|
|
3400
3618
|
onEvent: (event) => printEvent(event, write),
|
|
3401
|
-
onHiddenFrame
|
|
3619
|
+
onHiddenFrame,
|
|
3620
|
+
...saved ? { replay: { saved } } : {}
|
|
3402
3621
|
});
|
|
3622
|
+
if (replayCwd !== void 0 && saved && result.replay) {
|
|
3623
|
+
const steps = stepsToSave(result.status === "passed", saved, result.replay);
|
|
3624
|
+
if (steps) await saveReplay(replayFile(replayCwd, test.path), device, steps).catch(() => {
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
3403
3627
|
return device ? { ...result, device } : result;
|
|
3404
3628
|
} finally {
|
|
3405
3629
|
await context.close();
|
|
@@ -3440,7 +3664,7 @@ Changed files: ${changedCount}`);
|
|
|
3440
3664
|
console.log(`Tests: ${selection.selected.length} selected`);
|
|
3441
3665
|
if (unrouted.length > 0) {
|
|
3442
3666
|
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} (${
|
|
3667
|
+
for (const test of unrouted) console.log(` ${test.summary} (${path11.relative(cwd, test.path)})`);
|
|
3444
3668
|
}
|
|
3445
3669
|
console.log("---------------------------------------------------------------");
|
|
3446
3670
|
}
|
|
@@ -3461,12 +3685,14 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3461
3685
|
reportNearMissedSecrets(nearMissedSecrets, warnings);
|
|
3462
3686
|
if (spend) console.log(formatSpendLine(spend));
|
|
3463
3687
|
if (firstJudgeLog) console.log(firstJudgeLog.summaryLine());
|
|
3688
|
+
const decided = results.flatMap((result) => result.steps.map((step) => step.decidedBy));
|
|
3689
|
+
if (decided.some((by) => by !== void 0)) console.log(replaySummary(decided));
|
|
3464
3690
|
const score = scoreOf(results, incomplete !== void 0);
|
|
3465
3691
|
console.log(
|
|
3466
3692
|
incomplete ? formatIncompleteLine(score, incomplete.message) : formatScoreLine(computeScore(results), results, options.minScore)
|
|
3467
3693
|
);
|
|
3468
3694
|
if (options.junit) {
|
|
3469
|
-
const target = typeof options.junit === "string" ?
|
|
3695
|
+
const target = typeof options.junit === "string" ? path11.resolve(options.cwd, options.junit) : path11.join(sessionDir, "junit.xml");
|
|
3470
3696
|
const xml = renderJUnit(results, skipped, {
|
|
3471
3697
|
score,
|
|
3472
3698
|
durationMs,
|
|
@@ -3476,10 +3702,10 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3476
3702
|
warnings
|
|
3477
3703
|
});
|
|
3478
3704
|
await writeJUnit(target, xml);
|
|
3479
|
-
console.log(`JUnit report: ${
|
|
3705
|
+
console.log(`JUnit report: ${path11.relative(options.cwd, target)}`);
|
|
3480
3706
|
}
|
|
3481
3707
|
if (options.html) {
|
|
3482
|
-
const target = typeof options.html === "string" ?
|
|
3708
|
+
const target = typeof options.html === "string" ? path11.resolve(options.cwd, options.html) : path11.join(sessionDir, "report.html");
|
|
3483
3709
|
const html = await renderHtml(results, skipped, {
|
|
3484
3710
|
score,
|
|
3485
3711
|
durationMs,
|
|
@@ -3493,10 +3719,10 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3493
3719
|
// withhold-a-screenshot-that-saw-a-secret, D1): the run's mask, not the
|
|
3494
3720
|
// failed test's own placeholders, because a login credential is echoed by
|
|
3495
3721
|
// the pages of every test that comes after it.
|
|
3496
|
-
screenshots: secretsHeld ? { withheldRelativeTo:
|
|
3722
|
+
screenshots: secretsHeld ? { withheldRelativeTo: path11.dirname(target) } : "embed"
|
|
3497
3723
|
});
|
|
3498
3724
|
await writeHtml(target, html);
|
|
3499
|
-
console.log(`HTML report: ${
|
|
3725
|
+
console.log(`HTML report: ${path11.relative(options.cwd, target)}`);
|
|
3500
3726
|
}
|
|
3501
3727
|
if (incomplete) return EXIT_FAILED;
|
|
3502
3728
|
if (reportUnclassified(options, impact)) return EXIT_FAILED;
|
|
@@ -3527,7 +3753,7 @@ function routeDriftWarning(drift, cwd) {
|
|
|
3527
3753
|
kind: "route-drift",
|
|
3528
3754
|
title: "Route drift (test routes declared by no routes: mapping \u2014 contribute nothing to --impacted selection):",
|
|
3529
3755
|
lines: [
|
|
3530
|
-
...drift.drifted.map(({ test, routes }) => ` ${test.summary} (${
|
|
3756
|
+
...drift.drifted.map(({ test, routes }) => ` ${test.summary} (${path11.relative(cwd, test.path)}): ${routes.join(", ")}`),
|
|
3531
3757
|
"Fix the route typo, or add the route to a routes: mapping in .blastproof/config.yaml."
|
|
3532
3758
|
]
|
|
3533
3759
|
};
|
|
@@ -3541,7 +3767,7 @@ function authoringWarning(result, cwd) {
|
|
|
3541
3767
|
...result.findings.flatMap(({ test, origin, index, step }) => {
|
|
3542
3768
|
const where = origin === "setup" ? `setup step ${index}` : `step ${index}`;
|
|
3543
3769
|
return [
|
|
3544
|
-
` ${test.summary} (${
|
|
3770
|
+
` ${test.summary} (${path11.relative(cwd, test.path)}) ${where}:`,
|
|
3545
3771
|
` ${step}`,
|
|
3546
3772
|
` \u2192 ${suggestValueClause(step)}`
|
|
3547
3773
|
];
|
|
@@ -3556,7 +3782,7 @@ function printDryRun(selected, config, cwd) {
|
|
|
3556
3782
|
console.log(`
|
|
3557
3783
|
Dry run: ${selected.length} test(s) selected, base_url=${config.base_url}`);
|
|
3558
3784
|
for (const test of selected) {
|
|
3559
|
-
console.log(` ${test.summary} [${test.priority}]${deviceTag(test, config)} (${
|
|
3785
|
+
console.log(` ${test.summary} [${test.priority}]${deviceTag(test, config)} (${path11.relative(cwd, test.path)})`);
|
|
3560
3786
|
}
|
|
3561
3787
|
const needsLogin = selected.some((test) => test.auth);
|
|
3562
3788
|
const authSteps = needsLogin ? config.auth?.steps ?? [] : [];
|
|
@@ -3614,7 +3840,7 @@ async function runCommand(options) {
|
|
|
3614
3840
|
changedCount = changedFiles.length;
|
|
3615
3841
|
printUncommitted(await getUncommittedFiles(options.cwd), changedFiles, config, base, warnings);
|
|
3616
3842
|
}
|
|
3617
|
-
const testsDir =
|
|
3843
|
+
const testsDir = path11.join(options.cwd, TESTS_RELATIVE_DIR);
|
|
3618
3844
|
let files;
|
|
3619
3845
|
try {
|
|
3620
3846
|
files = await discoverTestFiles(testsDir);
|
|
@@ -3630,8 +3856,8 @@ async function runCommand(options) {
|
|
|
3630
3856
|
} catch (error) {
|
|
3631
3857
|
if (error instanceof TestFileError) {
|
|
3632
3858
|
results.push({
|
|
3633
|
-
file:
|
|
3634
|
-
summary:
|
|
3859
|
+
file: path11.relative(options.cwd, file),
|
|
3860
|
+
summary: path11.basename(file),
|
|
3635
3861
|
priority: "P1",
|
|
3636
3862
|
tags: [],
|
|
3637
3863
|
status: "failed",
|
|
@@ -3673,7 +3899,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3673
3899
|
}
|
|
3674
3900
|
return reportUnclassified(options, impact) ? EXIT_FAILED : EXIT_OK;
|
|
3675
3901
|
}
|
|
3676
|
-
const sessionDir =
|
|
3902
|
+
const sessionDir = path11.join(options.cwd, ".blastproof", "reports", sessionId());
|
|
3677
3903
|
const startedAt = Date.now();
|
|
3678
3904
|
if (selected.length === 0) {
|
|
3679
3905
|
console.log(
|
|
@@ -3705,7 +3931,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3705
3931
|
} : void 0;
|
|
3706
3932
|
if (firstJudgeLog) {
|
|
3707
3933
|
console.log(
|
|
3708
|
-
`First judge (experimental): ${firstJudgeLog.model}, passing at p(yes) >= ${firstJudgeLog.threshold}; its decisions are kept in ${
|
|
3934
|
+
`First judge (experimental): ${firstJudgeLog.model}, passing at p(yes) >= ${firstJudgeLog.threshold}; its decisions are kept in ${path11.relative(options.cwd, firstJudgeLogPath(sessionDir))}`
|
|
3709
3935
|
);
|
|
3710
3936
|
}
|
|
3711
3937
|
const runMask = buildRunMask(config, parsed);
|
|
@@ -3759,7 +3985,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3759
3985
|
if (stoppedBy) return { index, stopped: stoppedBy };
|
|
3760
3986
|
const lines = [];
|
|
3761
3987
|
const header = `
|
|
3762
|
-
> ${test.summary} [${test.priority}]${deviceTag(test, config)} (${
|
|
3988
|
+
> ${test.summary} [${test.priority}]${deviceTag(test, config)} (${path11.relative(options.cwd, test.path)})`;
|
|
3763
3989
|
const write = streaming ? console.log : (line) => lines.push(line);
|
|
3764
3990
|
if (streaming) console.log(header);
|
|
3765
3991
|
else lines.push(header);
|
|
@@ -3775,7 +4001,8 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3775
4001
|
budget,
|
|
3776
4002
|
write,
|
|
3777
4003
|
onHiddenFrame,
|
|
3778
|
-
firstJudgeFor(
|
|
4004
|
+
firstJudgeFor(path11.relative(options.cwd, test.path)),
|
|
4005
|
+
options.replay ?? config.replay ? options.cwd : void 0
|
|
3779
4006
|
);
|
|
3780
4007
|
if (!streaming) for (const line of lines) console.log(line);
|
|
3781
4008
|
return { index, result };
|
|
@@ -3828,12 +4055,12 @@ function printAuthEvent(event) {
|
|
|
3828
4055
|
console.log(` step ${event.index + 1}/${event.total}: ${event.step}`);
|
|
3829
4056
|
} else if (event.type === "action") {
|
|
3830
4057
|
console.log(` -> ${event.action.action} :: ${event.result}`);
|
|
3831
|
-
} else if (event.status === "failed") {
|
|
4058
|
+
} else if (event.type === "step-end" && event.status === "failed") {
|
|
3832
4059
|
console.log(` X step failed: ${event.reason ?? "unknown reason"}`);
|
|
3833
4060
|
}
|
|
3834
4061
|
}
|
|
3835
4062
|
async function loadSuite(cwd) {
|
|
3836
|
-
const testsDir =
|
|
4063
|
+
const testsDir = path12.join(cwd, TESTS_RELATIVE_DIR);
|
|
3837
4064
|
let files;
|
|
3838
4065
|
try {
|
|
3839
4066
|
files = await discoverTestFiles(testsDir);
|
|
@@ -4023,8 +4250,8 @@ async function planCommand(options) {
|
|
|
4023
4250
|
if (options.write) {
|
|
4024
4251
|
try {
|
|
4025
4252
|
const file = await writeDraft(options.cwd, draft, { route, base });
|
|
4026
|
-
written.push(
|
|
4027
|
-
console.log(` wrote ${
|
|
4253
|
+
written.push(path12.relative(options.cwd, file));
|
|
4254
|
+
console.log(` wrote ${path12.relative(options.cwd, file)}`);
|
|
4028
4255
|
} catch (error) {
|
|
4029
4256
|
generated.pop();
|
|
4030
4257
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -4096,6 +4323,7 @@ async function testCommand(options) {
|
|
|
4096
4323
|
html: options.html,
|
|
4097
4324
|
failOnUnmapped: options.failOnUnmapped,
|
|
4098
4325
|
failOnAuthoring: options.failOnAuthoring,
|
|
4326
|
+
replay: options.replay,
|
|
4099
4327
|
budget
|
|
4100
4328
|
});
|
|
4101
4329
|
if (runCode === EXIT_USAGE) return EXIT_USAGE;
|
|
@@ -4152,7 +4380,7 @@ function parsePositiveNumber(flag) {
|
|
|
4152
4380
|
};
|
|
4153
4381
|
}
|
|
4154
4382
|
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.
|
|
4383
|
+
program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.35.0");
|
|
4156
4384
|
program.command("init").description("Scaffold .blastproof/ (config, tests, sample tests) in the current directory").action(async () => {
|
|
4157
4385
|
try {
|
|
4158
4386
|
const result = await initProject(process.cwd());
|
|
@@ -4167,7 +4395,7 @@ program.command("run").description("Discover and run all tests under .blastproof
|
|
|
4167
4395
|
"--min-score <n>",
|
|
4168
4396
|
"require a weighted score of at least n (0-100); replaces the all-must-pass rule",
|
|
4169
4397
|
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(
|
|
4398
|
+
).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
4399
|
"--concurrency <n>",
|
|
4172
4400
|
"run this many tests at once (overrides config; default 1 \u2014 see the README on when this is safe)",
|
|
4173
4401
|
parsePositiveInt("--concurrency")
|
|
@@ -4201,6 +4429,7 @@ program.command("run").description("Discover and run all tests under .blastproof
|
|
|
4201
4429
|
failOnUnmapped: options.failOnUnmapped,
|
|
4202
4430
|
failOnAuthoring: options.failOnAuthoring,
|
|
4203
4431
|
concurrency: options.concurrency,
|
|
4432
|
+
replay: options.replay,
|
|
4204
4433
|
maxLlmCalls: options.maxLlmCalls,
|
|
4205
4434
|
maxTokens: options.maxTokens,
|
|
4206
4435
|
maxDuration: options.maxDuration
|
|
@@ -4258,7 +4487,7 @@ program.command("test").description("Full PR pipeline: run the tests covering th
|
|
|
4258
4487
|
"--max-tokens <n>",
|
|
4259
4488
|
"stop the pipeline after this many tokens, shared by both phases (overrides config)",
|
|
4260
4489
|
parsePositiveInt("--max-tokens")
|
|
4261
|
-
).option(
|
|
4490
|
+
).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
4491
|
"--max-duration <seconds>",
|
|
4263
4492
|
"stop the pipeline after this many seconds of wall-clock time (overrides config)",
|
|
4264
4493
|
parsePositiveNumber("--max-duration")
|
|
@@ -4275,6 +4504,7 @@ program.command("test").description("Full PR pipeline: run the tests covering th
|
|
|
4275
4504
|
write: options.write,
|
|
4276
4505
|
failOnUnmapped: options.failOnUnmapped,
|
|
4277
4506
|
failOnAuthoring: options.failOnAuthoring,
|
|
4507
|
+
replay: options.replay,
|
|
4278
4508
|
maxLlmCalls: options.maxLlmCalls,
|
|
4279
4509
|
maxTokens: options.maxTokens,
|
|
4280
4510
|
maxDuration: options.maxDuration
|