blastproof 0.33.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/{chunk-O6UTUPT6.js → chunk-7UQT6SVD.js} +113 -2
- package/dist/chunk-7UQT6SVD.js.map +1 -0
- package/dist/cli.js +413 -106
- package/dist/cli.js.map +1 -1
- package/dist/{snapshot-ECNLGVUG.js → snapshot-6C7FIWW7.js} +6 -2
- package/package.json +1 -1
- package/dist/chunk-O6UTUPT6.js.map +0 -1
- /package/dist/{snapshot-ECNLGVUG.js.map → snapshot-6C7FIWW7.js.map} +0 -0
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
FIELD_ROLES,
|
|
3
4
|
allowedOriginsFor,
|
|
4
5
|
bindTarget,
|
|
5
6
|
describeBoundary,
|
|
@@ -7,8 +8,10 @@ import {
|
|
|
7
8
|
isOriginAllowed,
|
|
8
9
|
performAction,
|
|
9
10
|
snapshotCutAt,
|
|
11
|
+
snapshotFields,
|
|
12
|
+
submitControlOf,
|
|
10
13
|
withoutRefs
|
|
11
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-7UQT6SVD.js";
|
|
12
15
|
|
|
13
16
|
// src/cli.ts
|
|
14
17
|
import { Command, InvalidArgumentError } from "commander";
|
|
@@ -118,6 +121,7 @@ steps:
|
|
|
118
121
|
var GITIGNORE = `# blastproof runtime artifacts
|
|
119
122
|
reports/
|
|
120
123
|
sessions/
|
|
124
|
+
cache/
|
|
121
125
|
|
|
122
126
|
# Captured sessions are live credentials \u2014 never commit them.
|
|
123
127
|
.auth-state.json
|
|
@@ -212,11 +216,11 @@ function formatInitGuidance(result) {
|
|
|
212
216
|
}
|
|
213
217
|
|
|
214
218
|
// src/commands/plan.ts
|
|
215
|
-
import
|
|
219
|
+
import path12 from "path";
|
|
216
220
|
|
|
217
221
|
// src/auth.ts
|
|
218
|
-
import { readFile, writeFile as
|
|
219
|
-
import
|
|
222
|
+
import { readFile as readFile2, writeFile as writeFile3, mkdir as mkdir4 } from "fs/promises";
|
|
223
|
+
import path4 from "path";
|
|
220
224
|
|
|
221
225
|
// src/runner/authoring.ts
|
|
222
226
|
var VALUE_VERBS = ["fill", "enter", "type", "input", "set"];
|
|
@@ -553,15 +557,19 @@ var SecretsMask = class {
|
|
|
553
557
|
};
|
|
554
558
|
|
|
555
559
|
// src/runner/executor.ts
|
|
556
|
-
import { mkdir as
|
|
557
|
-
import
|
|
560
|
+
import { mkdir as mkdir3 } from "fs/promises";
|
|
561
|
+
import path3 from "path";
|
|
558
562
|
|
|
559
563
|
// src/runner/recovery.ts
|
|
560
564
|
var COMMIT_ACTIONS = /* @__PURE__ */ new Set(["click", "press"]);
|
|
561
565
|
var COMMIT_KEYS = /* @__PURE__ */ new Set(["Enter", "NumpadEnter", " ", "Space", "Spacebar"]);
|
|
566
|
+
var ENTER_KEYS = /* @__PURE__ */ new Set(["Enter", "NumpadEnter"]);
|
|
567
|
+
function pressedKey(action) {
|
|
568
|
+
return action.value || "Enter";
|
|
569
|
+
}
|
|
562
570
|
function isCommit(action) {
|
|
563
571
|
if (!COMMIT_ACTIONS.has(action.action)) return false;
|
|
564
|
-
return action.action !== "press" || COMMIT_KEYS.has(action
|
|
572
|
+
return action.action !== "press" || COMMIT_KEYS.has(pressedKey(action));
|
|
565
573
|
}
|
|
566
574
|
var SOURCED_VALUE_ACTIONS = /* @__PURE__ */ new Set(["fill", "select"]);
|
|
567
575
|
function referencesOnlyNamedVars(value, step) {
|
|
@@ -579,7 +587,25 @@ function describeAction(action) {
|
|
|
579
587
|
function identity(action) {
|
|
580
588
|
const role = action.target?.role ?? "";
|
|
581
589
|
const name = action.target?.name ?? "";
|
|
582
|
-
|
|
590
|
+
const value = action.action === "press" ? pressedKey(action) : action.value ?? "";
|
|
591
|
+
return JSON.stringify([action.action, role, normalise(name), value]);
|
|
592
|
+
}
|
|
593
|
+
function activatedControl(action, activates) {
|
|
594
|
+
if (action.action !== "press" || !isCommit(action)) return void 0;
|
|
595
|
+
return normalise(action.target?.role ?? "") === "button" ? action.target : activates;
|
|
596
|
+
}
|
|
597
|
+
function commitIdentity(action, activates) {
|
|
598
|
+
const control = activatedControl(action, activates);
|
|
599
|
+
if (control === void 0) return identity(action);
|
|
600
|
+
return identity({ action: "click", target: { role: control.role, name: control.name }, reasoning: "" });
|
|
601
|
+
}
|
|
602
|
+
function fieldKey(field) {
|
|
603
|
+
return JSON.stringify([field.role ?? "", normalise(field.name ?? "")]);
|
|
604
|
+
}
|
|
605
|
+
function cameBackReset(before, after) {
|
|
606
|
+
const now = /* @__PURE__ */ new Map();
|
|
607
|
+
for (const field of snapshotFields(after)) now.set(fieldKey(field), (now.get(fieldKey(field)) ?? false) || field.filled);
|
|
608
|
+
return snapshotFields(before).some((field) => field.name !== "" && field.filled && now.get(fieldKey(field)) === false);
|
|
583
609
|
}
|
|
584
610
|
var StepRecovery = class {
|
|
585
611
|
performed = /* @__PURE__ */ new Set();
|
|
@@ -592,6 +618,12 @@ var StepRecovery = class {
|
|
|
592
618
|
* on a page that moved is a tour's "Next", not a duplicate.
|
|
593
619
|
*/
|
|
594
620
|
lastSuccess;
|
|
621
|
+
/**
|
|
622
|
+
* The page each commit was last decided on, by commit identity (design
|
|
623
|
+
* refuse-the-same-submit-twice, D6): what tells Enter in the next page of a
|
|
624
|
+
* form from Enter in the same form again.
|
|
625
|
+
*/
|
|
626
|
+
commitPages = /* @__PURE__ */ new Map();
|
|
595
627
|
/**
|
|
596
628
|
* Everything the model has been allowed to read this step, normalised: the
|
|
597
629
|
* step's own text, plus every snapshot it has been shown, plus every value it
|
|
@@ -671,9 +703,13 @@ var StepRecovery = class {
|
|
|
671
703
|
return this.history.length > 0;
|
|
672
704
|
}
|
|
673
705
|
/** Records an action that was actually performed and succeeded. */
|
|
674
|
-
record(action, description, result) {
|
|
706
|
+
record(action, description, result, activates) {
|
|
707
|
+
const commit = commitIdentity(action, activates);
|
|
675
708
|
this.performed.add(identity(action));
|
|
676
|
-
this.
|
|
709
|
+
this.performed.add(commit);
|
|
710
|
+
if (isCommit(action)) this.commitPages.set(commit, this.lastObserved);
|
|
711
|
+
const named = activatedControl(action, activates) !== void 0;
|
|
712
|
+
this.lastSuccess = { commit, own: identity(action), named, page: this.lastObserved, action };
|
|
677
713
|
this.history.push({ action: description, result });
|
|
678
714
|
if (action.value) this.readable.push(normalise(action.value));
|
|
679
715
|
}
|
|
@@ -693,8 +729,8 @@ var StepRecovery = class {
|
|
|
693
729
|
* allowed duplicate commit costs a silent extra row in someone's database,
|
|
694
730
|
* and #28 has now produced one on three applications.
|
|
695
731
|
*/
|
|
696
|
-
refusalFor(action) {
|
|
697
|
-
return this.verificationRefusal(action) ?? this.repeatedCommitRefusal(action) ?? this.redactionLabelRefusal(action) ?? this.unsourcedValueRefusal(action);
|
|
732
|
+
refusalFor(action, activates) {
|
|
733
|
+
return this.verificationRefusal(action) ?? this.repeatedCommitRefusal(action, activates) ?? this.redactionLabelRefusal(action) ?? this.unsourcedValueRefusal(action);
|
|
698
734
|
}
|
|
699
735
|
/**
|
|
700
736
|
* Refuses a typed value containing a redaction label (design
|
|
@@ -728,12 +764,21 @@ var StepRecovery = class {
|
|
|
728
764
|
if (!this.verifies || !isCommit(action)) return void 0;
|
|
729
765
|
return "refused: this step only verifies \u2014 it does not ask you to change anything, so clicking or pressing here could make the check pass by producing what it checks. Assert what the page shows. If what the step names is on another page, navigate there. If it is not shown, fail the step.";
|
|
730
766
|
}
|
|
731
|
-
repeatedCommitRefusal(action) {
|
|
767
|
+
repeatedCommitRefusal(action, activates) {
|
|
732
768
|
if (!isCommit(action)) return void 0;
|
|
733
|
-
|
|
734
|
-
|
|
769
|
+
const commit = commitIdentity(action, activates);
|
|
770
|
+
const own = this.performed.has(identity(action));
|
|
771
|
+
if (!own && !this.performed.has(commit)) return void 0;
|
|
772
|
+
const control = activatedControl(action, activates);
|
|
773
|
+
if (this.followsItselfOnAMovedPage(commit, identity(action), control !== void 0)) return void 0;
|
|
774
|
+
if (this.pressedInANewField(action, commit)) return void 0;
|
|
775
|
+
const rest = `It is the same control even under a new ref: refs are renumbered when the page changes. Repeating something that commits repeats whatever it changed in the application. If the page no longer shows that it worked, that is normal for a submit answered by a redirect \u2014 check the record of what you have already done. Verify the step's outcome another way, or fail the step.`;
|
|
776
|
+
if (!own && control !== void 0) {
|
|
777
|
+
const key = pressedKey(action).trim() === "" ? "Space" : pressedKey(action);
|
|
778
|
+
return `refused: pressing ${key} here activates ${control.role ?? ""} "${control.name ?? ""}", and the click on it already succeeded earlier in this step, so the key was NOT pressed. ${rest}`;
|
|
779
|
+
}
|
|
735
780
|
const target = action.target ? ` on ${action.target.role ?? ""} "${action.target.name ?? ""}"` : "";
|
|
736
|
-
return `refused: this ${action.action}${target} already succeeded earlier in this step, so it was NOT performed again.
|
|
781
|
+
return `refused: this ${action.action}${target} already succeeded earlier in this step, so it was NOT performed again. ${rest}`;
|
|
737
782
|
}
|
|
738
783
|
/**
|
|
739
784
|
* The one repeat performed (design repeat-a-click-that-moves-the-page): the
|
|
@@ -743,12 +788,40 @@ var StepRecovery = class {
|
|
|
743
788
|
* something else in between to restore the form, a `fill` (#124) or a click
|
|
744
789
|
* on "New Issue" (#28), and a press that moved nothing is still refused.
|
|
745
790
|
* Compared exactly on the ref-less text `observe` receives, so a re-render
|
|
746
|
-
* alone is no change.
|
|
791
|
+
* alone is no change. `commit` is the control activated, so "Next" clicked
|
|
792
|
+
* and "Next" entered are one control here.
|
|
747
793
|
*/
|
|
748
|
-
followsItselfOnAMovedPage(
|
|
794
|
+
followsItselfOnAMovedPage(commit, own, named) {
|
|
749
795
|
const last = this.lastSuccess;
|
|
750
|
-
if (last === void 0
|
|
751
|
-
|
|
796
|
+
if (last === void 0) return false;
|
|
797
|
+
const joinsAnother = last.named && named && this.performed.has(commit);
|
|
798
|
+
const same = last.commit === commit || last.own === own && !joinsAnother;
|
|
799
|
+
if (!same) return false;
|
|
800
|
+
if (last.page === void 0 || this.lastObserved === void 0 || last.page === this.lastObserved) return false;
|
|
801
|
+
return !cameBackReset(last.page, this.lastObserved);
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Enter in a field that was not on the page when the button it activates was
|
|
805
|
+
* last pressed (design refuse-the-same-submit-twice, D6): the next page of a
|
|
806
|
+
* form, not the same form again. A two-page sign-in is email, Enter,
|
|
807
|
+
* password, Enter, and both presses activate "Next". The duplicate has the
|
|
808
|
+
* opposite shape: the form came back, so its field was there. The field is
|
|
809
|
+
* the press's target, or for a press with no target the field the last
|
|
810
|
+
* action filled, which is where the focus is. Without a named field, on a
|
|
811
|
+
* page with an unnamed one, or while a field of that earlier page is still
|
|
812
|
+
* shown, nothing can be told and the press is refused.
|
|
813
|
+
*/
|
|
814
|
+
pressedInANewField(action, commit) {
|
|
815
|
+
if (action.action !== "press" || !ENTER_KEYS.has(pressedKey(action))) return false;
|
|
816
|
+
const last = this.lastSuccess?.action;
|
|
817
|
+
const field = action.target ?? (last !== void 0 && SOURCED_VALUE_ACTIONS.has(last.action) ? last.target : void 0);
|
|
818
|
+
if (field === void 0 || !field.name || !FIELD_ROLES.has(field.role ?? "")) return false;
|
|
819
|
+
const page = this.commitPages.get(commit);
|
|
820
|
+
if (page === void 0 || this.lastObserved === void 0) return false;
|
|
821
|
+
const then = snapshotFields(page);
|
|
822
|
+
if (then.some((one) => one.name === "" || fieldKey(one) === fieldKey(field))) return false;
|
|
823
|
+
const now = new Set(snapshotFields(this.lastObserved).map(fieldKey));
|
|
824
|
+
return !then.some((one) => now.has(fieldKey(one)));
|
|
752
825
|
}
|
|
753
826
|
/**
|
|
754
827
|
* Refuses a typed value that came from nowhere the model was entitled to read
|
|
@@ -789,6 +862,99 @@ var StepRecovery = class {
|
|
|
789
862
|
}
|
|
790
863
|
};
|
|
791
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
|
+
|
|
792
958
|
// src/runner/executor.ts
|
|
793
959
|
var DEFAULT_MAX_ITERATIONS_PER_STEP = 15;
|
|
794
960
|
var SETTLE_TIMEOUT_MS = 2e3;
|
|
@@ -807,7 +973,7 @@ async function waitForSettled(page) {
|
|
|
807
973
|
}
|
|
808
974
|
}
|
|
809
975
|
async function defaultSnapshot(page, maxLines, frames) {
|
|
810
|
-
const { captureSnapshot } = await import("./snapshot-
|
|
976
|
+
const { captureSnapshot } = await import("./snapshot-6C7FIWW7.js");
|
|
811
977
|
return captureSnapshot(page, { maxLines, frames });
|
|
812
978
|
}
|
|
813
979
|
function slugify(text) {
|
|
@@ -842,6 +1008,14 @@ function pageChangeNote(before, after) {
|
|
|
842
1008
|
const lines = [...removed.map((line) => `- ${line.trim()}`), ...added.map((line) => `+ ${line.trim()}`)];
|
|
843
1009
|
return ` (after it, the only change on the page: ${lines.join("; ")})`;
|
|
844
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
|
+
}
|
|
845
1019
|
async function executeTest(page, test, options) {
|
|
846
1020
|
const {
|
|
847
1021
|
brain,
|
|
@@ -858,8 +1032,12 @@ async function executeTest(page, test, options) {
|
|
|
858
1032
|
renderWatchMs = RENDER_WATCH_MS,
|
|
859
1033
|
onEvent = () => {
|
|
860
1034
|
},
|
|
861
|
-
onHiddenFrame
|
|
1035
|
+
onHiddenFrame,
|
|
1036
|
+
submitControl = submitControlOf,
|
|
1037
|
+
replay
|
|
862
1038
|
} = options;
|
|
1039
|
+
const savedByKey = new Map((replay?.saved ?? []).map((entry) => [entry.key, entry]));
|
|
1040
|
+
const replayOutcome = { steps: [], ended: [] };
|
|
863
1041
|
const boundary = allowedOriginsFor(baseUrl, allowedOrigins);
|
|
864
1042
|
const takeSnapshot = snapshot ?? ((page2) => defaultSnapshot(page2, maxSnapshotLines, { allowed: boundary, onHidden: onHiddenFrame }));
|
|
865
1043
|
const startedAt = Date.now();
|
|
@@ -895,6 +1073,21 @@ async function executeTest(page, test, options) {
|
|
|
895
1073
|
const recovery = new StepRecovery(written, step);
|
|
896
1074
|
const agentRecord = [];
|
|
897
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
|
+
};
|
|
898
1091
|
try {
|
|
899
1092
|
while (true) {
|
|
900
1093
|
if (iterations >= maxIterationsPerStep) {
|
|
@@ -907,11 +1100,30 @@ async function executeTest(page, test, options) {
|
|
|
907
1100
|
);
|
|
908
1101
|
}
|
|
909
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
|
+
}
|
|
910
1117
|
lastSnapshot = snap;
|
|
911
1118
|
const maskedSnap = mask(snap);
|
|
912
1119
|
const refs = indexRefs(maskedSnap);
|
|
913
1120
|
const pageSnap = withoutRefs(maskedSnap);
|
|
914
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
|
+
}
|
|
915
1127
|
if (pageActedOn !== void 0) {
|
|
916
1128
|
const note = pageChangeNote(pageActedOn, pageSnap);
|
|
917
1129
|
const acted = agentRecord[agentRecord.length - 1];
|
|
@@ -922,7 +1134,11 @@ async function executeTest(page, test, options) {
|
|
|
922
1134
|
pageActedOn = void 0;
|
|
923
1135
|
}
|
|
924
1136
|
let action;
|
|
925
|
-
|
|
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 {
|
|
926
1142
|
action = await brain.nextAction({
|
|
927
1143
|
// As written, never joined (design an-action-step-takes-the-next-check,
|
|
928
1144
|
// D2): a model told the check acts to make it true (#139).
|
|
@@ -950,8 +1166,13 @@ async function executeTest(page, test, options) {
|
|
|
950
1166
|
const shown = () => judgingDone ? { ...action, action: "done" } : action;
|
|
951
1167
|
if (action.action === "done") {
|
|
952
1168
|
if (!recovery.acted || recovery.verifies) {
|
|
953
|
-
failedAttempts++;
|
|
954
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++;
|
|
955
1176
|
emitAction(index, action, lastResult);
|
|
956
1177
|
if (failedAttempts >= maxRetries) {
|
|
957
1178
|
throw new StepFailure(lastResult);
|
|
@@ -960,6 +1181,7 @@ async function executeTest(page, test, options) {
|
|
|
960
1181
|
}
|
|
961
1182
|
if (!recovery.checksAfterActing) {
|
|
962
1183
|
emitAction(index, action, action.reasoning);
|
|
1184
|
+
closed = { by: "done" };
|
|
963
1185
|
break;
|
|
964
1186
|
}
|
|
965
1187
|
judgingDone = true;
|
|
@@ -1007,9 +1229,13 @@ async function executeTest(page, test, options) {
|
|
|
1007
1229
|
}
|
|
1008
1230
|
} catch (error) {
|
|
1009
1231
|
if (error instanceof RunStoppedError) throw error;
|
|
1010
|
-
failedAttempts++;
|
|
1011
1232
|
lastResult = `error: ${error instanceof Error ? error.message : String(error)}`;
|
|
1012
1233
|
emitAction(index, shown(), lastResult);
|
|
1234
|
+
if (replayed) {
|
|
1235
|
+
endReplay("its judgment gave no answer");
|
|
1236
|
+
continue;
|
|
1237
|
+
}
|
|
1238
|
+
failedAttempts++;
|
|
1013
1239
|
if (failedAttempts >= maxRetries) {
|
|
1014
1240
|
throw new StepFailure(lastResult);
|
|
1015
1241
|
}
|
|
@@ -1022,8 +1248,14 @@ async function executeTest(page, test, options) {
|
|
|
1022
1248
|
emitAction(index, shown(), result);
|
|
1023
1249
|
if (judgment.pass) {
|
|
1024
1250
|
lastResult = result;
|
|
1251
|
+
closed = { by: "judgment", claim: mask(expectation) };
|
|
1025
1252
|
break;
|
|
1026
1253
|
}
|
|
1254
|
+
if (replayed) {
|
|
1255
|
+
lastResult = result;
|
|
1256
|
+
endReplay("the judgment of its saved claim failed");
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1027
1259
|
failedAttempts++;
|
|
1028
1260
|
lastResult = result;
|
|
1029
1261
|
if (failedAttempts >= maxRetries) {
|
|
@@ -1034,16 +1266,28 @@ async function executeTest(page, test, options) {
|
|
|
1034
1266
|
try {
|
|
1035
1267
|
action = bindTarget(action, refs);
|
|
1036
1268
|
} catch (error) {
|
|
1037
|
-
failedAttempts++;
|
|
1038
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++;
|
|
1039
1276
|
emitAction(index, action, lastResult);
|
|
1040
1277
|
if (failedAttempts >= maxRetries) {
|
|
1041
1278
|
throw new StepFailure(lastResult);
|
|
1042
1279
|
}
|
|
1043
1280
|
continue;
|
|
1044
1281
|
}
|
|
1045
|
-
const
|
|
1282
|
+
const activates = await submitControl(page, action, refs);
|
|
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
|
+
}
|
|
1046
1289
|
if (refusal) {
|
|
1290
|
+
void activates?.activated();
|
|
1047
1291
|
failedAttempts++;
|
|
1048
1292
|
lastResult = refusal;
|
|
1049
1293
|
emitAction(index, action, refusal);
|
|
@@ -1060,14 +1304,31 @@ async function executeTest(page, test, options) {
|
|
|
1060
1304
|
resolveTimeoutMs: timeoutMs
|
|
1061
1305
|
});
|
|
1062
1306
|
lastResult = result;
|
|
1063
|
-
|
|
1307
|
+
const activated = activates !== void 0 && await activates.activated() ? activates : void 0;
|
|
1308
|
+
recovery.record(action, mask(describeAction(action)), mask(result), activated);
|
|
1064
1309
|
agentRecord.push({ action: mask(describeAction(action)), result: mask(result) });
|
|
1065
1310
|
pageActedOn = pageSnap;
|
|
1066
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
|
+
}
|
|
1067
1323
|
} catch (error) {
|
|
1068
|
-
|
|
1324
|
+
void activates?.activated();
|
|
1069
1325
|
lastResult = `error: ${error instanceof Error ? error.message : String(error)}`;
|
|
1070
1326
|
emitAction(index, action, lastResult);
|
|
1327
|
+
if (replayed) {
|
|
1328
|
+
endReplay(`a saved action failed (${lastResult})`);
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
failedAttempts++;
|
|
1071
1332
|
if (failedAttempts >= maxRetries) {
|
|
1072
1333
|
throw new StepFailure(lastResult);
|
|
1073
1334
|
}
|
|
@@ -1096,6 +1357,9 @@ async function executeTest(page, test, options) {
|
|
|
1096
1357
|
if (judgment.pass) {
|
|
1097
1358
|
emitAction(index, asked, `ok: the check after this step holds: ${judgment.reason}`);
|
|
1098
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) };
|
|
1099
1363
|
} else {
|
|
1100
1364
|
emitAction(index, asked, `the check after this step does not hold either: ${judgment.reason}`);
|
|
1101
1365
|
}
|
|
@@ -1113,6 +1377,11 @@ async function executeTest(page, test, options) {
|
|
|
1113
1377
|
for (const name of referencedEnvVars(entry.action)) usedEarlier.add(name);
|
|
1114
1378
|
}
|
|
1115
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
|
+
}
|
|
1116
1385
|
stepResults.push({
|
|
1117
1386
|
step: mask(written),
|
|
1118
1387
|
// results are a report channel — never store substituted secrets
|
|
@@ -1121,7 +1390,8 @@ async function executeTest(page, test, options) {
|
|
|
1121
1390
|
iterations,
|
|
1122
1391
|
failedAttempts,
|
|
1123
1392
|
reason: stepFailedReason,
|
|
1124
|
-
durationMs: Date.now() - stepStartedAt
|
|
1393
|
+
durationMs: Date.now() - stepStartedAt,
|
|
1394
|
+
...decidedBy ? { decidedBy } : {}
|
|
1125
1395
|
});
|
|
1126
1396
|
onEvent({ type: "step-end", index, status, reason: stepFailedReason });
|
|
1127
1397
|
if (stepFailedReason) {
|
|
@@ -1132,9 +1402,9 @@ async function executeTest(page, test, options) {
|
|
|
1132
1402
|
let screenshot;
|
|
1133
1403
|
if (failure) {
|
|
1134
1404
|
try {
|
|
1135
|
-
await
|
|
1136
|
-
const stem = `${slugify(test.summary)}-${slugify(
|
|
1137
|
-
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`);
|
|
1138
1408
|
await page.screenshot({ path: file, fullPage: true });
|
|
1139
1409
|
screenshot = file;
|
|
1140
1410
|
} catch {
|
|
@@ -1150,6 +1420,7 @@ async function executeTest(page, test, options) {
|
|
|
1150
1420
|
failedStep: failure?.step,
|
|
1151
1421
|
reason: failure?.reason,
|
|
1152
1422
|
screenshot,
|
|
1423
|
+
...replay ? { replay: replayOutcome } : {},
|
|
1153
1424
|
durationMs: Date.now() - startedAt
|
|
1154
1425
|
};
|
|
1155
1426
|
}
|
|
@@ -1309,7 +1580,7 @@ function isSessionStorageSeed(value) {
|
|
|
1309
1580
|
}
|
|
1310
1581
|
|
|
1311
1582
|
// src/auth.ts
|
|
1312
|
-
var AUTH_STATE_RELATIVE_PATH =
|
|
1583
|
+
var AUTH_STATE_RELATIVE_PATH = path4.join(".blastproof", ".auth-state.json");
|
|
1313
1584
|
var AuthError = class extends Error {
|
|
1314
1585
|
constructor(message) {
|
|
1315
1586
|
super(message);
|
|
@@ -1322,7 +1593,7 @@ function isStorageState(value) {
|
|
|
1322
1593
|
async function fromStorageState(file) {
|
|
1323
1594
|
let raw;
|
|
1324
1595
|
try {
|
|
1325
|
-
raw = await
|
|
1596
|
+
raw = await readFile2(file, "utf8");
|
|
1326
1597
|
} catch {
|
|
1327
1598
|
throw new AuthError(
|
|
1328
1599
|
`Cannot read auth.storage_state at ${file}. Capture a session first, or switch to an auth.steps recipe.`
|
|
@@ -1404,7 +1675,7 @@ async function fromSteps(options) {
|
|
|
1404
1675
|
},
|
|
1405
1676
|
{
|
|
1406
1677
|
brain,
|
|
1407
|
-
sessionDir:
|
|
1678
|
+
sessionDir: path4.join(options.cwd, ".blastproof", "reports", "auth"),
|
|
1408
1679
|
baseUrl,
|
|
1409
1680
|
allowedOrigins: options.allowedOrigins,
|
|
1410
1681
|
resolveValue: (value) => substituteEnv(value),
|
|
@@ -1488,17 +1759,17 @@ async function checkWhereUsed(options, session, loginPage, takeSnapshot) {
|
|
|
1488
1759
|
}
|
|
1489
1760
|
async function readCached(cwd) {
|
|
1490
1761
|
try {
|
|
1491
|
-
return await fromStorageState(
|
|
1762
|
+
return await fromStorageState(path4.join(cwd, AUTH_STATE_RELATIVE_PATH));
|
|
1492
1763
|
} catch {
|
|
1493
1764
|
return void 0;
|
|
1494
1765
|
}
|
|
1495
1766
|
}
|
|
1496
1767
|
async function writeCached(cwd, session) {
|
|
1497
1768
|
if (!session.storageState) return;
|
|
1498
|
-
const file =
|
|
1499
|
-
await
|
|
1769
|
+
const file = path4.join(cwd, AUTH_STATE_RELATIVE_PATH);
|
|
1770
|
+
await mkdir4(path4.dirname(file), { recursive: true });
|
|
1500
1771
|
const cached = session.sessionStorage ? { ...session.storageState, sessionStorage: session.sessionStorage } : session.storageState;
|
|
1501
|
-
await
|
|
1772
|
+
await writeFile3(file, JSON.stringify(cached), "utf8");
|
|
1502
1773
|
}
|
|
1503
1774
|
async function authenticate(options) {
|
|
1504
1775
|
const { auth, cwd } = options;
|
|
@@ -1507,7 +1778,7 @@ async function authenticate(options) {
|
|
|
1507
1778
|
if (cached) return cached;
|
|
1508
1779
|
}
|
|
1509
1780
|
if (auth.storage_state) {
|
|
1510
|
-
return fromStorageState(
|
|
1781
|
+
return fromStorageState(path4.resolve(cwd, auth.storage_state));
|
|
1511
1782
|
}
|
|
1512
1783
|
if (auth.headers || auth.cookies) {
|
|
1513
1784
|
return fromStatic(auth, options.mask);
|
|
@@ -1529,11 +1800,11 @@ async function seedContext(context, session) {
|
|
|
1529
1800
|
}
|
|
1530
1801
|
|
|
1531
1802
|
// src/config.ts
|
|
1532
|
-
import { readFile as
|
|
1533
|
-
import
|
|
1803
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
1804
|
+
import path5 from "path";
|
|
1534
1805
|
import { parse as parseYaml } from "yaml";
|
|
1535
1806
|
import { z } from "zod";
|
|
1536
|
-
var CONFIG_RELATIVE_PATH =
|
|
1807
|
+
var CONFIG_RELATIVE_PATH = path5.join(".blastproof", "config.yaml");
|
|
1537
1808
|
var llmSchema = z.object({
|
|
1538
1809
|
provider: z.enum(["anthropic", "openai", "ollama"]).default("anthropic"),
|
|
1539
1810
|
model: z.string().min(1).optional(),
|
|
@@ -1678,6 +1949,13 @@ var configSchema = z.object({
|
|
|
1678
1949
|
* those tests, not of the runner. Opted into by the person who knows.
|
|
1679
1950
|
*/
|
|
1680
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),
|
|
1681
1959
|
budget: budgetSchema.optional(),
|
|
1682
1960
|
first_judge: firstJudgeSchema.optional()
|
|
1683
1961
|
});
|
|
@@ -1693,7 +1971,8 @@ var ENV_OVERRIDES = {
|
|
|
1693
1971
|
BLASTPROOF_MAX_DURATION_S: ["budget", "max_duration_s"],
|
|
1694
1972
|
BLASTPROOF_FIRST_JUDGE_MODEL: ["first_judge", "model"],
|
|
1695
1973
|
BLASTPROOF_FIRST_JUDGE_THRESHOLD: ["first_judge", "threshold"],
|
|
1696
|
-
BLASTPROOF_BROWSER_DEVICE: ["browser", "device"]
|
|
1974
|
+
BLASTPROOF_BROWSER_DEVICE: ["browser", "device"],
|
|
1975
|
+
BLASTPROOF_REPLAY: ["replay"]
|
|
1697
1976
|
};
|
|
1698
1977
|
function applyEnvOverrides(data, env = process.env) {
|
|
1699
1978
|
const merged = data && typeof data === "object" ? { ...data } : {};
|
|
@@ -1739,13 +2018,13 @@ function unwrapToObjectSchema(schema) {
|
|
|
1739
2018
|
}
|
|
1740
2019
|
return current instanceof z.ZodObject ? current : void 0;
|
|
1741
2020
|
}
|
|
1742
|
-
function findUnknownConfigKeys(data, schema = configSchema,
|
|
2021
|
+
function findUnknownConfigKeys(data, schema = configSchema, path13 = []) {
|
|
1743
2022
|
const object = unwrapToObjectSchema(schema);
|
|
1744
2023
|
if (!object || data === null || typeof data !== "object" || Array.isArray(data)) return [];
|
|
1745
2024
|
const shape = object.shape;
|
|
1746
2025
|
const warnings = [];
|
|
1747
2026
|
for (const key of Object.keys(data)) {
|
|
1748
|
-
const fieldPath = [...
|
|
2027
|
+
const fieldPath = [...path13, key];
|
|
1749
2028
|
const fieldSchema = shape[key];
|
|
1750
2029
|
if (!fieldSchema) {
|
|
1751
2030
|
warnings.push(fieldPath.join("."));
|
|
@@ -1756,10 +2035,10 @@ function findUnknownConfigKeys(data, schema = configSchema, path12 = []) {
|
|
|
1756
2035
|
return warnings;
|
|
1757
2036
|
}
|
|
1758
2037
|
async function loadConfig(cwd = process.cwd(), env = process.env) {
|
|
1759
|
-
const configPath =
|
|
2038
|
+
const configPath = path5.join(cwd, CONFIG_RELATIVE_PATH);
|
|
1760
2039
|
let raw;
|
|
1761
2040
|
try {
|
|
1762
|
-
raw = await
|
|
2041
|
+
raw = await readFile3(configPath, "utf8");
|
|
1763
2042
|
} catch {
|
|
1764
2043
|
throw new ConfigError(
|
|
1765
2044
|
`No config found at ${CONFIG_RELATIVE_PATH}. Run \`blastproof init\` to scaffold one.`
|
|
@@ -2045,7 +2324,7 @@ function plannerUserPrompt(input) {
|
|
|
2045
2324
|
|
|
2046
2325
|
// src/llm/decision.ts
|
|
2047
2326
|
import { appendFileSync, mkdirSync } from "fs";
|
|
2048
|
-
import
|
|
2327
|
+
import path6 from "path";
|
|
2049
2328
|
import { APICallError } from "ai";
|
|
2050
2329
|
|
|
2051
2330
|
// src/llm/provider.ts
|
|
@@ -2230,7 +2509,7 @@ var FirstJudgeLog = class {
|
|
|
2230
2509
|
else this.toLlm++;
|
|
2231
2510
|
if (entry.outcome === "too-large" || !this.file) return;
|
|
2232
2511
|
if (!this.dirReady) {
|
|
2233
|
-
mkdirSync(
|
|
2512
|
+
mkdirSync(path6.dirname(this.file), { recursive: true });
|
|
2234
2513
|
this.dirReady = true;
|
|
2235
2514
|
}
|
|
2236
2515
|
const line = {
|
|
@@ -2252,7 +2531,7 @@ var FirstJudgeLog = class {
|
|
|
2252
2531
|
}
|
|
2253
2532
|
};
|
|
2254
2533
|
function firstJudgeLogPath(sessionDir) {
|
|
2255
|
-
return
|
|
2534
|
+
return path6.join(sessionDir, "first-judge.jsonl");
|
|
2256
2535
|
}
|
|
2257
2536
|
function createFirstJudgeClient(config, env = process.env, fetchImpl) {
|
|
2258
2537
|
const apiKey = env[config.api_key_env];
|
|
@@ -2494,16 +2773,16 @@ function createPlanner(model, generate = generateObject, budget) {
|
|
|
2494
2773
|
}
|
|
2495
2774
|
|
|
2496
2775
|
// src/planner.ts
|
|
2497
|
-
import { mkdir as
|
|
2498
|
-
import
|
|
2776
|
+
import { mkdir as mkdir5, writeFile as writeFile4 } from "fs/promises";
|
|
2777
|
+
import path8 from "path";
|
|
2499
2778
|
import { stringify } from "yaml";
|
|
2500
2779
|
|
|
2501
2780
|
// src/runner/testfile.ts
|
|
2502
|
-
import { readFile as
|
|
2503
|
-
import
|
|
2781
|
+
import { readFile as readFile4, readdir } from "fs/promises";
|
|
2782
|
+
import path7 from "path";
|
|
2504
2783
|
import { parse as parseYaml2 } from "yaml";
|
|
2505
2784
|
import { z as z3 } from "zod";
|
|
2506
|
-
var TESTS_RELATIVE_DIR =
|
|
2785
|
+
var TESTS_RELATIVE_DIR = path7.join(".blastproof", "tests");
|
|
2507
2786
|
var prioritySchema = z3.enum(["P0", "P1", "P2"]);
|
|
2508
2787
|
var testFileSchema = z3.object({
|
|
2509
2788
|
summary: z3.string().min(1),
|
|
@@ -2527,7 +2806,7 @@ function formatIssues2(error) {
|
|
|
2527
2806
|
async function parseTestFile(filePath) {
|
|
2528
2807
|
let raw;
|
|
2529
2808
|
try {
|
|
2530
|
-
raw = await
|
|
2809
|
+
raw = await readFile4(filePath, "utf8");
|
|
2531
2810
|
} catch {
|
|
2532
2811
|
throw new TestFileError(`Cannot read test file: ${filePath}`);
|
|
2533
2812
|
}
|
|
@@ -2551,7 +2830,7 @@ async function discoverTestFiles(root) {
|
|
|
2551
2830
|
async function walk(dir) {
|
|
2552
2831
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
2553
2832
|
for (const entry of entries) {
|
|
2554
|
-
const full =
|
|
2833
|
+
const full = path7.join(dir, entry.name);
|
|
2555
2834
|
if (entry.isDirectory()) {
|
|
2556
2835
|
await walk(full);
|
|
2557
2836
|
} else if (/\.ya?ml$/i.test(entry.name)) {
|
|
@@ -2639,20 +2918,20 @@ async function generateForRoute(page, options) {
|
|
|
2639
2918
|
};
|
|
2640
2919
|
}
|
|
2641
2920
|
async function writeDraft(cwd, draft, meta) {
|
|
2642
|
-
const dir =
|
|
2643
|
-
const file =
|
|
2921
|
+
const dir = path8.join(cwd, TESTS_RELATIVE_DIR);
|
|
2922
|
+
const file = path8.join(dir, `${routeToSlug(meta.route)}.yaml`);
|
|
2644
2923
|
try {
|
|
2645
|
-
await
|
|
2646
|
-
await
|
|
2924
|
+
await mkdir5(dir, { recursive: true });
|
|
2925
|
+
await writeFile4(file, renderTestYaml(draft, meta), { flag: "wx" });
|
|
2647
2926
|
} catch (error) {
|
|
2648
2927
|
const err = error;
|
|
2649
2928
|
if (err.code === "EEXIST" && err.syscall !== "mkdir") {
|
|
2650
2929
|
throw new PlannerError(
|
|
2651
|
-
`Refusing to overwrite ${
|
|
2930
|
+
`Refusing to overwrite ${path8.relative(cwd, file)} (route ${meta.route}). Delete or rename it to regenerate.`
|
|
2652
2931
|
);
|
|
2653
2932
|
}
|
|
2654
2933
|
throw new PlannerError(
|
|
2655
|
-
`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.`
|
|
2656
2935
|
);
|
|
2657
2936
|
}
|
|
2658
2937
|
return file;
|
|
@@ -2815,11 +3094,11 @@ function formatSpendLine(spend) {
|
|
|
2815
3094
|
}
|
|
2816
3095
|
|
|
2817
3096
|
// src/commands/run.ts
|
|
2818
|
-
import
|
|
3097
|
+
import path11 from "path";
|
|
2819
3098
|
|
|
2820
3099
|
// src/report/html.ts
|
|
2821
|
-
import { mkdir as
|
|
2822
|
-
import
|
|
3100
|
+
import { mkdir as mkdir6, readFile as readFile5, writeFile as writeFile5 } from "fs/promises";
|
|
3101
|
+
import path9 from "path";
|
|
2823
3102
|
var ESCAPES = {
|
|
2824
3103
|
"&": "&",
|
|
2825
3104
|
"<": "<",
|
|
@@ -2832,7 +3111,7 @@ function escapeHtml(text) {
|
|
|
2832
3111
|
}
|
|
2833
3112
|
async function embedScreenshot(file) {
|
|
2834
3113
|
try {
|
|
2835
|
-
const bytes = await
|
|
3114
|
+
const bytes = await readFile5(file);
|
|
2836
3115
|
return `data:image/png;base64,${bytes.toString("base64")}`;
|
|
2837
3116
|
} catch {
|
|
2838
3117
|
return void 0;
|
|
@@ -2893,14 +3172,14 @@ function seconds(ms) {
|
|
|
2893
3172
|
function renderSteps(steps) {
|
|
2894
3173
|
if (steps.length === 0) return "";
|
|
2895
3174
|
const items = steps.map(
|
|
2896
|
-
(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>`
|
|
2897
3176
|
).join("\n ");
|
|
2898
3177
|
return `<ol class="steps">
|
|
2899
3178
|
${items}
|
|
2900
3179
|
</ol>`;
|
|
2901
3180
|
}
|
|
2902
3181
|
function withheldScreenshot(file, reportDir) {
|
|
2903
|
-
const href =
|
|
3182
|
+
const href = path9.relative(reportDir, file).split(path9.sep).join("/");
|
|
2904
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>`;
|
|
2905
3184
|
}
|
|
2906
3185
|
async function renderTest(result, screenshots, cwd) {
|
|
@@ -2908,7 +3187,7 @@ async function renderTest(result, screenshots, cwd) {
|
|
|
2908
3187
|
const notRun = result.status === "not-run";
|
|
2909
3188
|
const tagClass = failed ? "fail" : notRun ? "skip" : "pass";
|
|
2910
3189
|
const label = failed ? "FAIL" : notRun ? "NOT RUN" : "PASS";
|
|
2911
|
-
const file = cwd ?
|
|
3190
|
+
const file = cwd ? path9.relative(cwd, result.file) : result.file;
|
|
2912
3191
|
const device = result.device ? ` \xB7 ${escapeHtml(result.device)}` : "";
|
|
2913
3192
|
const parts = [
|
|
2914
3193
|
` <details${failed || notRun ? " open" : ""}>`,
|
|
@@ -2956,14 +3235,14 @@ async function renderHtml(results, skipped, meta) {
|
|
|
2956
3235
|
<pre>${escapeHtml(w.lines.join("\n"))}</pre>` : "")
|
|
2957
3236
|
).join("\n") + "\n </section>\n\n";
|
|
2958
3237
|
const rows = results.map((r) => {
|
|
2959
|
-
const file = meta.cwd ?
|
|
3238
|
+
const file = meta.cwd ? path9.relative(meta.cwd, r.file) : r.file;
|
|
2960
3239
|
const tagClass = r.status === "failed" ? "fail" : r.status === "not-run" ? "skip" : "pass";
|
|
2961
3240
|
const label = r.status === "failed" ? "FAIL" : r.status === "not-run" ? "NOT RUN" : "PASS";
|
|
2962
3241
|
const time = r.status === "not-run" ? "\u2014" : seconds(r.durationMs);
|
|
2963
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>`;
|
|
2964
3243
|
}).join("\n");
|
|
2965
3244
|
const skippedRows = skipped.map((s) => {
|
|
2966
|
-
const file = meta.cwd ?
|
|
3245
|
+
const file = meta.cwd ? path9.relative(meta.cwd, s.path) : s.path;
|
|
2967
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>`;
|
|
2968
3247
|
}).join("\n");
|
|
2969
3248
|
return `<!doctype html>
|
|
@@ -3002,8 +3281,8 @@ ${detail}
|
|
|
3002
3281
|
}
|
|
3003
3282
|
async function writeHtml(file, html) {
|
|
3004
3283
|
try {
|
|
3005
|
-
await
|
|
3006
|
-
await
|
|
3284
|
+
await mkdir6(path9.dirname(file), { recursive: true });
|
|
3285
|
+
await writeFile5(file, html, "utf8");
|
|
3007
3286
|
return file;
|
|
3008
3287
|
} catch (error) {
|
|
3009
3288
|
throw new ReportError(
|
|
@@ -3013,8 +3292,8 @@ async function writeHtml(file, html) {
|
|
|
3013
3292
|
}
|
|
3014
3293
|
|
|
3015
3294
|
// src/report/junit.ts
|
|
3016
|
-
import { mkdir as
|
|
3017
|
-
import
|
|
3295
|
+
import { mkdir as mkdir7, writeFile as writeFile6 } from "fs/promises";
|
|
3296
|
+
import path10 from "path";
|
|
3018
3297
|
var ESCAPES2 = {
|
|
3019
3298
|
"&": "&",
|
|
3020
3299
|
"<": "<",
|
|
@@ -3028,8 +3307,19 @@ function escapeXml(text) {
|
|
|
3028
3307
|
function seconds2(ms) {
|
|
3029
3308
|
return (ms / 1e3).toFixed(3);
|
|
3030
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
|
+
}
|
|
3031
3321
|
function renderJUnit(results, skipped, meta) {
|
|
3032
|
-
const relative = (file) => meta.cwd ?
|
|
3322
|
+
const relative = (file) => meta.cwd ? path10.relative(meta.cwd, file) : file;
|
|
3033
3323
|
const warnings = meta.warnings ?? [];
|
|
3034
3324
|
const failures = results.filter((result) => result.status === "failed").length;
|
|
3035
3325
|
const notRun = results.filter((result) => result.status === "not-run");
|
|
@@ -3052,6 +3342,7 @@ function renderJUnit(results, skipped, meta) {
|
|
|
3052
3342
|
] : [],
|
|
3053
3343
|
// Emitted as 0 too (design D2): unlike a token count nobody reported, 0 is
|
|
3054
3344
|
// a true claim here, that the run printed no warning.
|
|
3345
|
+
...replayProperties(results),
|
|
3055
3346
|
` <property name="warnings" value="${warnings.length}"/>`,
|
|
3056
3347
|
" </properties>"
|
|
3057
3348
|
];
|
|
@@ -3091,8 +3382,8 @@ ${reason}` : reason;
|
|
|
3091
3382
|
}
|
|
3092
3383
|
async function writeJUnit(file, xml) {
|
|
3093
3384
|
try {
|
|
3094
|
-
await
|
|
3095
|
-
await
|
|
3385
|
+
await mkdir7(path10.dirname(file), { recursive: true });
|
|
3386
|
+
await writeFile6(file, xml, "utf8");
|
|
3096
3387
|
return file;
|
|
3097
3388
|
} catch (error) {
|
|
3098
3389
|
throw new ReportError(
|
|
@@ -3237,6 +3528,9 @@ function printEvent(event, write = console.log) {
|
|
|
3237
3528
|
write(` X step failed: ${event.reason ?? "unknown reason"}`);
|
|
3238
3529
|
}
|
|
3239
3530
|
break;
|
|
3531
|
+
case "replay-ended":
|
|
3532
|
+
write(` ~ replay ended: ${event.reason}; the model takes over`);
|
|
3533
|
+
break;
|
|
3240
3534
|
}
|
|
3241
3535
|
}
|
|
3242
3536
|
function statusLabel(status) {
|
|
@@ -3283,7 +3577,7 @@ function deviceTag(test, config) {
|
|
|
3283
3577
|
const device = test.device ?? config.browser.device;
|
|
3284
3578
|
return device ? ` [${device}]` : "";
|
|
3285
3579
|
}
|
|
3286
|
-
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) {
|
|
3287
3581
|
const brain = createBrain(createModel(config.llm).model, void 0, budget, firstJudge);
|
|
3288
3582
|
let resolved;
|
|
3289
3583
|
const mask = runMask;
|
|
@@ -3305,6 +3599,7 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3305
3599
|
throw error;
|
|
3306
3600
|
}
|
|
3307
3601
|
const device = test.device ?? config.browser.device;
|
|
3602
|
+
const saved = replayCwd === void 0 ? void 0 : await loadReplay(replayFile(replayCwd, test.path), device);
|
|
3308
3603
|
const context = await browser.newContext(contextOptions(test.auth ? session : void 0, device));
|
|
3309
3604
|
try {
|
|
3310
3605
|
await seedContext(context, test.auth ? session : void 0);
|
|
@@ -3321,8 +3616,14 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3321
3616
|
maxSnapshotLines: config.browser.max_snapshot_lines,
|
|
3322
3617
|
mask: (text) => mask.mask(text),
|
|
3323
3618
|
onEvent: (event) => printEvent(event, write),
|
|
3324
|
-
onHiddenFrame
|
|
3619
|
+
onHiddenFrame,
|
|
3620
|
+
...saved ? { replay: { saved } } : {}
|
|
3325
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
|
+
}
|
|
3326
3627
|
return device ? { ...result, device } : result;
|
|
3327
3628
|
} finally {
|
|
3328
3629
|
await context.close();
|
|
@@ -3363,7 +3664,7 @@ Changed files: ${changedCount}`);
|
|
|
3363
3664
|
console.log(`Tests: ${selection.selected.length} selected`);
|
|
3364
3665
|
if (unrouted.length > 0) {
|
|
3365
3666
|
console.log(` ${unrouted.length} ${unrouted.length === 1 ? "declares" : "declare"} no routes:, so --impacted cannot select ${unrouted.length === 1 ? "it" : "them"}:`);
|
|
3366
|
-
for (const test of unrouted) console.log(` ${test.summary} (${
|
|
3667
|
+
for (const test of unrouted) console.log(` ${test.summary} (${path11.relative(cwd, test.path)})`);
|
|
3367
3668
|
}
|
|
3368
3669
|
console.log("---------------------------------------------------------------");
|
|
3369
3670
|
}
|
|
@@ -3384,12 +3685,14 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3384
3685
|
reportNearMissedSecrets(nearMissedSecrets, warnings);
|
|
3385
3686
|
if (spend) console.log(formatSpendLine(spend));
|
|
3386
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));
|
|
3387
3690
|
const score = scoreOf(results, incomplete !== void 0);
|
|
3388
3691
|
console.log(
|
|
3389
3692
|
incomplete ? formatIncompleteLine(score, incomplete.message) : formatScoreLine(computeScore(results), results, options.minScore)
|
|
3390
3693
|
);
|
|
3391
3694
|
if (options.junit) {
|
|
3392
|
-
const target = typeof options.junit === "string" ?
|
|
3695
|
+
const target = typeof options.junit === "string" ? path11.resolve(options.cwd, options.junit) : path11.join(sessionDir, "junit.xml");
|
|
3393
3696
|
const xml = renderJUnit(results, skipped, {
|
|
3394
3697
|
score,
|
|
3395
3698
|
durationMs,
|
|
@@ -3399,10 +3702,10 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3399
3702
|
warnings
|
|
3400
3703
|
});
|
|
3401
3704
|
await writeJUnit(target, xml);
|
|
3402
|
-
console.log(`JUnit report: ${
|
|
3705
|
+
console.log(`JUnit report: ${path11.relative(options.cwd, target)}`);
|
|
3403
3706
|
}
|
|
3404
3707
|
if (options.html) {
|
|
3405
|
-
const target = typeof options.html === "string" ?
|
|
3708
|
+
const target = typeof options.html === "string" ? path11.resolve(options.cwd, options.html) : path11.join(sessionDir, "report.html");
|
|
3406
3709
|
const html = await renderHtml(results, skipped, {
|
|
3407
3710
|
score,
|
|
3408
3711
|
durationMs,
|
|
@@ -3416,10 +3719,10 @@ async function finalize(results, skipped, options, sessionDir, secretsHeld, near
|
|
|
3416
3719
|
// withhold-a-screenshot-that-saw-a-secret, D1): the run's mask, not the
|
|
3417
3720
|
// failed test's own placeholders, because a login credential is echoed by
|
|
3418
3721
|
// the pages of every test that comes after it.
|
|
3419
|
-
screenshots: secretsHeld ? { withheldRelativeTo:
|
|
3722
|
+
screenshots: secretsHeld ? { withheldRelativeTo: path11.dirname(target) } : "embed"
|
|
3420
3723
|
});
|
|
3421
3724
|
await writeHtml(target, html);
|
|
3422
|
-
console.log(`HTML report: ${
|
|
3725
|
+
console.log(`HTML report: ${path11.relative(options.cwd, target)}`);
|
|
3423
3726
|
}
|
|
3424
3727
|
if (incomplete) return EXIT_FAILED;
|
|
3425
3728
|
if (reportUnclassified(options, impact)) return EXIT_FAILED;
|
|
@@ -3450,7 +3753,7 @@ function routeDriftWarning(drift, cwd) {
|
|
|
3450
3753
|
kind: "route-drift",
|
|
3451
3754
|
title: "Route drift (test routes declared by no routes: mapping \u2014 contribute nothing to --impacted selection):",
|
|
3452
3755
|
lines: [
|
|
3453
|
-
...drift.drifted.map(({ test, routes }) => ` ${test.summary} (${
|
|
3756
|
+
...drift.drifted.map(({ test, routes }) => ` ${test.summary} (${path11.relative(cwd, test.path)}): ${routes.join(", ")}`),
|
|
3454
3757
|
"Fix the route typo, or add the route to a routes: mapping in .blastproof/config.yaml."
|
|
3455
3758
|
]
|
|
3456
3759
|
};
|
|
@@ -3464,7 +3767,7 @@ function authoringWarning(result, cwd) {
|
|
|
3464
3767
|
...result.findings.flatMap(({ test, origin, index, step }) => {
|
|
3465
3768
|
const where = origin === "setup" ? `setup step ${index}` : `step ${index}`;
|
|
3466
3769
|
return [
|
|
3467
|
-
` ${test.summary} (${
|
|
3770
|
+
` ${test.summary} (${path11.relative(cwd, test.path)}) ${where}:`,
|
|
3468
3771
|
` ${step}`,
|
|
3469
3772
|
` \u2192 ${suggestValueClause(step)}`
|
|
3470
3773
|
];
|
|
@@ -3479,7 +3782,7 @@ function printDryRun(selected, config, cwd) {
|
|
|
3479
3782
|
console.log(`
|
|
3480
3783
|
Dry run: ${selected.length} test(s) selected, base_url=${config.base_url}`);
|
|
3481
3784
|
for (const test of selected) {
|
|
3482
|
-
console.log(` ${test.summary} [${test.priority}]${deviceTag(test, config)} (${
|
|
3785
|
+
console.log(` ${test.summary} [${test.priority}]${deviceTag(test, config)} (${path11.relative(cwd, test.path)})`);
|
|
3483
3786
|
}
|
|
3484
3787
|
const needsLogin = selected.some((test) => test.auth);
|
|
3485
3788
|
const authSteps = needsLogin ? config.auth?.steps ?? [] : [];
|
|
@@ -3537,7 +3840,7 @@ async function runCommand(options) {
|
|
|
3537
3840
|
changedCount = changedFiles.length;
|
|
3538
3841
|
printUncommitted(await getUncommittedFiles(options.cwd), changedFiles, config, base, warnings);
|
|
3539
3842
|
}
|
|
3540
|
-
const testsDir =
|
|
3843
|
+
const testsDir = path11.join(options.cwd, TESTS_RELATIVE_DIR);
|
|
3541
3844
|
let files;
|
|
3542
3845
|
try {
|
|
3543
3846
|
files = await discoverTestFiles(testsDir);
|
|
@@ -3553,8 +3856,8 @@ async function runCommand(options) {
|
|
|
3553
3856
|
} catch (error) {
|
|
3554
3857
|
if (error instanceof TestFileError) {
|
|
3555
3858
|
results.push({
|
|
3556
|
-
file:
|
|
3557
|
-
summary:
|
|
3859
|
+
file: path11.relative(options.cwd, file),
|
|
3860
|
+
summary: path11.basename(file),
|
|
3558
3861
|
priority: "P1",
|
|
3559
3862
|
tags: [],
|
|
3560
3863
|
status: "failed",
|
|
@@ -3596,7 +3899,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3596
3899
|
}
|
|
3597
3900
|
return reportUnclassified(options, impact) ? EXIT_FAILED : EXIT_OK;
|
|
3598
3901
|
}
|
|
3599
|
-
const sessionDir =
|
|
3902
|
+
const sessionDir = path11.join(options.cwd, ".blastproof", "reports", sessionId());
|
|
3600
3903
|
const startedAt = Date.now();
|
|
3601
3904
|
if (selected.length === 0) {
|
|
3602
3905
|
console.log(
|
|
@@ -3628,7 +3931,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3628
3931
|
} : void 0;
|
|
3629
3932
|
if (firstJudgeLog) {
|
|
3630
3933
|
console.log(
|
|
3631
|
-
`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))}`
|
|
3632
3935
|
);
|
|
3633
3936
|
}
|
|
3634
3937
|
const runMask = buildRunMask(config, parsed);
|
|
@@ -3682,7 +3985,7 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3682
3985
|
if (stoppedBy) return { index, stopped: stoppedBy };
|
|
3683
3986
|
const lines = [];
|
|
3684
3987
|
const header = `
|
|
3685
|
-
> ${test.summary} [${test.priority}]${deviceTag(test, config)} (${
|
|
3988
|
+
> ${test.summary} [${test.priority}]${deviceTag(test, config)} (${path11.relative(options.cwd, test.path)})`;
|
|
3686
3989
|
const write = streaming ? console.log : (line) => lines.push(line);
|
|
3687
3990
|
if (streaming) console.log(header);
|
|
3688
3991
|
else lines.push(header);
|
|
@@ -3698,7 +4001,8 @@ ${results.length} test file(s) could not be parsed:`);
|
|
|
3698
4001
|
budget,
|
|
3699
4002
|
write,
|
|
3700
4003
|
onHiddenFrame,
|
|
3701
|
-
firstJudgeFor(
|
|
4004
|
+
firstJudgeFor(path11.relative(options.cwd, test.path)),
|
|
4005
|
+
options.replay ?? config.replay ? options.cwd : void 0
|
|
3702
4006
|
);
|
|
3703
4007
|
if (!streaming) for (const line of lines) console.log(line);
|
|
3704
4008
|
return { index, result };
|
|
@@ -3751,12 +4055,12 @@ function printAuthEvent(event) {
|
|
|
3751
4055
|
console.log(` step ${event.index + 1}/${event.total}: ${event.step}`);
|
|
3752
4056
|
} else if (event.type === "action") {
|
|
3753
4057
|
console.log(` -> ${event.action.action} :: ${event.result}`);
|
|
3754
|
-
} else if (event.status === "failed") {
|
|
4058
|
+
} else if (event.type === "step-end" && event.status === "failed") {
|
|
3755
4059
|
console.log(` X step failed: ${event.reason ?? "unknown reason"}`);
|
|
3756
4060
|
}
|
|
3757
4061
|
}
|
|
3758
4062
|
async function loadSuite(cwd) {
|
|
3759
|
-
const testsDir =
|
|
4063
|
+
const testsDir = path12.join(cwd, TESTS_RELATIVE_DIR);
|
|
3760
4064
|
let files;
|
|
3761
4065
|
try {
|
|
3762
4066
|
files = await discoverTestFiles(testsDir);
|
|
@@ -3946,8 +4250,8 @@ async function planCommand(options) {
|
|
|
3946
4250
|
if (options.write) {
|
|
3947
4251
|
try {
|
|
3948
4252
|
const file = await writeDraft(options.cwd, draft, { route, base });
|
|
3949
|
-
written.push(
|
|
3950
|
-
console.log(` wrote ${
|
|
4253
|
+
written.push(path12.relative(options.cwd, file));
|
|
4254
|
+
console.log(` wrote ${path12.relative(options.cwd, file)}`);
|
|
3951
4255
|
} catch (error) {
|
|
3952
4256
|
generated.pop();
|
|
3953
4257
|
const reason = error instanceof Error ? error.message : String(error);
|
|
@@ -4019,6 +4323,7 @@ async function testCommand(options) {
|
|
|
4019
4323
|
html: options.html,
|
|
4020
4324
|
failOnUnmapped: options.failOnUnmapped,
|
|
4021
4325
|
failOnAuthoring: options.failOnAuthoring,
|
|
4326
|
+
replay: options.replay,
|
|
4022
4327
|
budget
|
|
4023
4328
|
});
|
|
4024
4329
|
if (runCode === EXIT_USAGE) return EXIT_USAGE;
|
|
@@ -4075,7 +4380,7 @@ function parsePositiveNumber(flag) {
|
|
|
4075
4380
|
};
|
|
4076
4381
|
}
|
|
4077
4382
|
var program = new Command();
|
|
4078
|
-
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");
|
|
4079
4384
|
program.command("init").description("Scaffold .blastproof/ (config, tests, sample tests) in the current directory").action(async () => {
|
|
4080
4385
|
try {
|
|
4081
4386
|
const result = await initProject(process.cwd());
|
|
@@ -4090,7 +4395,7 @@ program.command("run").description("Discover and run all tests under .blastproof
|
|
|
4090
4395
|
"--min-score <n>",
|
|
4091
4396
|
"require a weighted score of at least n (0-100); replaces the all-must-pass rule",
|
|
4092
4397
|
parseMinScore
|
|
4093
|
-
).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(
|
|
4094
4399
|
"--concurrency <n>",
|
|
4095
4400
|
"run this many tests at once (overrides config; default 1 \u2014 see the README on when this is safe)",
|
|
4096
4401
|
parsePositiveInt("--concurrency")
|
|
@@ -4124,6 +4429,7 @@ program.command("run").description("Discover and run all tests under .blastproof
|
|
|
4124
4429
|
failOnUnmapped: options.failOnUnmapped,
|
|
4125
4430
|
failOnAuthoring: options.failOnAuthoring,
|
|
4126
4431
|
concurrency: options.concurrency,
|
|
4432
|
+
replay: options.replay,
|
|
4127
4433
|
maxLlmCalls: options.maxLlmCalls,
|
|
4128
4434
|
maxTokens: options.maxTokens,
|
|
4129
4435
|
maxDuration: options.maxDuration
|
|
@@ -4181,7 +4487,7 @@ program.command("test").description("Full PR pipeline: run the tests covering th
|
|
|
4181
4487
|
"--max-tokens <n>",
|
|
4182
4488
|
"stop the pipeline after this many tokens, shared by both phases (overrides config)",
|
|
4183
4489
|
parsePositiveInt("--max-tokens")
|
|
4184
|
-
).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(
|
|
4185
4491
|
"--max-duration <seconds>",
|
|
4186
4492
|
"stop the pipeline after this many seconds of wall-clock time (overrides config)",
|
|
4187
4493
|
parsePositiveNumber("--max-duration")
|
|
@@ -4198,6 +4504,7 @@ program.command("test").description("Full PR pipeline: run the tests covering th
|
|
|
4198
4504
|
write: options.write,
|
|
4199
4505
|
failOnUnmapped: options.failOnUnmapped,
|
|
4200
4506
|
failOnAuthoring: options.failOnAuthoring,
|
|
4507
|
+
replay: options.replay,
|
|
4201
4508
|
maxLlmCalls: options.maxLlmCalls,
|
|
4202
4509
|
maxTokens: options.maxTokens,
|
|
4203
4510
|
maxDuration: options.maxDuration
|