blastproof 0.29.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cli.js +272 -31
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ That test failed 3 runs of 3 written as one step, and passed 3 of 3 written this
|
|
|
104
104
|
Not supported yet:
|
|
105
105
|
|
|
106
106
|
- **`iframe` content** — a hosted payment widget is invisible, so an embedded checkout cannot be driven end to end
|
|
107
|
-
- **
|
|
107
|
+
- **scroll-to, drag and drop, file upload**
|
|
108
108
|
- **multiple tabs**, and native `alert` / `confirm` dialogs
|
|
109
109
|
|
|
110
110
|
**Windows is untested.** Development and CI run on Linux and macOS. Nothing is known to be broken and reports are welcome ([#8](https://github.com/hamc/blastproof/issues/8)).
|
package/dist/cli.js
CHANGED
|
@@ -574,13 +574,13 @@ async function resolveTarget(page, target, resolveTimeoutMs = 2e3) {
|
|
|
574
574
|
if (!target.ref) throw new ActionError(`Element not found: ${describeTarget(target)} has no ref`);
|
|
575
575
|
const ref = bareRef(target.ref);
|
|
576
576
|
const locator = page.locator(`aria-ref=${ref}`);
|
|
577
|
-
let
|
|
577
|
+
let count2;
|
|
578
578
|
try {
|
|
579
|
-
|
|
579
|
+
count2 = await locator.count();
|
|
580
580
|
} catch {
|
|
581
|
-
|
|
581
|
+
count2 = 0;
|
|
582
582
|
}
|
|
583
|
-
if (
|
|
583
|
+
if (count2 === 0) {
|
|
584
584
|
throw new ActionError(
|
|
585
585
|
`Element not found: ${describeTarget(target)} (ref ${ref}) is no longer on the page; it changed since the snapshot. Choose the element again from the fresh snapshot.`
|
|
586
586
|
);
|
|
@@ -646,6 +646,12 @@ async function performResolvedAction(page, action, ctx) {
|
|
|
646
646
|
await locator.click();
|
|
647
647
|
return `ok: clicked ${describeTarget(target)}`;
|
|
648
648
|
}
|
|
649
|
+
case "hover": {
|
|
650
|
+
const target = requireTarget(action);
|
|
651
|
+
const locator = await resolveTarget(page, target, ctx.resolveTimeoutMs);
|
|
652
|
+
await locator.hover();
|
|
653
|
+
return `ok: hovered ${describeTarget(target)}`;
|
|
654
|
+
}
|
|
649
655
|
case "fill": {
|
|
650
656
|
const target = requireTarget(action);
|
|
651
657
|
const value = resolve(requireValue(action), ctx);
|
|
@@ -987,6 +993,19 @@ async function pageChangedWithin(page, takeSnapshot, view, seen, withinMs) {
|
|
|
987
993
|
}
|
|
988
994
|
return void 0;
|
|
989
995
|
}
|
|
996
|
+
var NOTE_MAX_LINES = 4;
|
|
997
|
+
function pageChangeNote(before, after) {
|
|
998
|
+
const beforeLines = before.split("\n");
|
|
999
|
+
const afterLines = after.split("\n");
|
|
1000
|
+
const kept = { before: new Set(beforeLines), after: new Set(afterLines) };
|
|
1001
|
+
const removed = beforeLines.filter((line) => !kept.after.has(line));
|
|
1002
|
+
const added = afterLines.filter((line) => !kept.before.has(line));
|
|
1003
|
+
const changed = removed.length + added.length;
|
|
1004
|
+
if (changed === 0) return " (after it, the page did not change at all)";
|
|
1005
|
+
if (changed > NOTE_MAX_LINES) return void 0;
|
|
1006
|
+
const lines = [...removed.map((line) => `- ${line.trim()}`), ...added.map((line) => `+ ${line.trim()}`)];
|
|
1007
|
+
return ` (after it, the only change on the page: ${lines.join("; ")})`;
|
|
1008
|
+
}
|
|
990
1009
|
async function executeTest(page, test, options) {
|
|
991
1010
|
const {
|
|
992
1011
|
brain,
|
|
@@ -1035,6 +1054,8 @@ async function executeTest(page, test, options) {
|
|
|
1035
1054
|
let lastSnapshot;
|
|
1036
1055
|
let lookedAgain = false;
|
|
1037
1056
|
const recovery = new StepRecovery(step);
|
|
1057
|
+
const agentRecord = [];
|
|
1058
|
+
let pageActedOn;
|
|
1038
1059
|
try {
|
|
1039
1060
|
while (true) {
|
|
1040
1061
|
if (iterations >= maxIterationsPerStep) {
|
|
@@ -1052,6 +1073,15 @@ async function executeTest(page, test, options) {
|
|
|
1052
1073
|
const refs = indexRefs(maskedSnap);
|
|
1053
1074
|
const pageSnap = withoutRefs(maskedSnap);
|
|
1054
1075
|
recovery.observe(pageSnap);
|
|
1076
|
+
if (pageActedOn !== void 0) {
|
|
1077
|
+
const note = pageChangeNote(pageActedOn, pageSnap);
|
|
1078
|
+
const acted = agentRecord[agentRecord.length - 1];
|
|
1079
|
+
if (note !== void 0 && acted !== void 0 && lastResult !== void 0) {
|
|
1080
|
+
acted.result += note;
|
|
1081
|
+
lastResult += note;
|
|
1082
|
+
}
|
|
1083
|
+
pageActedOn = void 0;
|
|
1084
|
+
}
|
|
1055
1085
|
let action;
|
|
1056
1086
|
try {
|
|
1057
1087
|
action = await brain.nextAction({
|
|
@@ -1061,7 +1091,7 @@ async function executeTest(page, test, options) {
|
|
|
1061
1091
|
lastResult: lastResult === void 0 ? void 0 : mask(lastResult),
|
|
1062
1092
|
// Already masked when recorded, on the same boundary as everything
|
|
1063
1093
|
// else crossing into a prompt (design contained-recovery, D2).
|
|
1064
|
-
stepHistory:
|
|
1094
|
+
stepHistory: agentRecord.map((entry) => ({ ...entry })),
|
|
1065
1095
|
retriesLeft: maxRetries - failedAttempts,
|
|
1066
1096
|
iterationsLeft: maxIterationsPerStep - iterations
|
|
1067
1097
|
});
|
|
@@ -1145,6 +1175,9 @@ async function executeTest(page, test, options) {
|
|
|
1145
1175
|
continue;
|
|
1146
1176
|
}
|
|
1147
1177
|
const result = judgment.pass ? `ok: assertion passed: ${judgment.reason}` : `assertion failed: ${judgment.reason}`;
|
|
1178
|
+
if (!judgment.pass) {
|
|
1179
|
+
agentRecord.push({ action: `assert "${mask(expectation)}"`, result: mask(result) });
|
|
1180
|
+
}
|
|
1148
1181
|
emitAction(index, shown(), result);
|
|
1149
1182
|
if (judgment.pass) {
|
|
1150
1183
|
lastResult = result;
|
|
@@ -1187,6 +1220,8 @@ async function executeTest(page, test, options) {
|
|
|
1187
1220
|
});
|
|
1188
1221
|
lastResult = result;
|
|
1189
1222
|
recovery.record(action, mask(describeAction(action)), mask(result));
|
|
1223
|
+
agentRecord.push({ action: mask(describeAction(action)), result: mask(result) });
|
|
1224
|
+
pageActedOn = pageSnap;
|
|
1190
1225
|
emitAction(index, action, result);
|
|
1191
1226
|
} catch (error) {
|
|
1192
1227
|
failedAttempts++;
|
|
@@ -1269,6 +1304,141 @@ function deviceOptions(name) {
|
|
|
1269
1304
|
return options;
|
|
1270
1305
|
}
|
|
1271
1306
|
|
|
1307
|
+
// src/session-capture.ts
|
|
1308
|
+
var SESSION_SEEDED_MARKER = "blastproof:session-seeded";
|
|
1309
|
+
async function readFalsyRecords() {
|
|
1310
|
+
const g = globalThis;
|
|
1311
|
+
const done = (request) => new Promise((resolve2, reject) => {
|
|
1312
|
+
request.onsuccess = () => resolve2(request.result);
|
|
1313
|
+
request.onerror = () => reject(request.error);
|
|
1314
|
+
});
|
|
1315
|
+
const encode = (value) => {
|
|
1316
|
+
if (value === null) return { v: "null" };
|
|
1317
|
+
if (typeof value === "number" && Number.isNaN(value)) return { v: "NaN" };
|
|
1318
|
+
if (Object.is(value, -0)) return { v: "-0" };
|
|
1319
|
+
if (value === 0 || value === "" || value === false) return { plain: value };
|
|
1320
|
+
return void 0;
|
|
1321
|
+
};
|
|
1322
|
+
const databases = [];
|
|
1323
|
+
for (const info of await g.indexedDB.databases()) {
|
|
1324
|
+
if (!info.name) continue;
|
|
1325
|
+
const db = await done(g.indexedDB.open(info.name));
|
|
1326
|
+
try {
|
|
1327
|
+
if (db.objectStoreNames.length === 0) {
|
|
1328
|
+
databases.push({ name: info.name, stores: [] });
|
|
1329
|
+
continue;
|
|
1330
|
+
}
|
|
1331
|
+
const transaction = db.transaction(db.objectStoreNames, "readonly");
|
|
1332
|
+
const reads = [...db.objectStoreNames].map((name) => {
|
|
1333
|
+
const store = transaction.objectStore(name);
|
|
1334
|
+
return Promise.all([done(store.getAllKeys()), done(store.getAll())]).then(([keys, values]) => ({
|
|
1335
|
+
name,
|
|
1336
|
+
count: keys.length,
|
|
1337
|
+
keys: keys.flatMap((key, i) => key === 0 || key === "" ? [[i, key]] : []),
|
|
1338
|
+
values: values.flatMap((value, i) => {
|
|
1339
|
+
const encoded = encode(value);
|
|
1340
|
+
return encoded ? [[i, encoded]] : [];
|
|
1341
|
+
})
|
|
1342
|
+
}));
|
|
1343
|
+
});
|
|
1344
|
+
databases.push({ name: info.name, stores: await Promise.all(reads) });
|
|
1345
|
+
} finally {
|
|
1346
|
+
db.close();
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
return { origin: g.location.origin, databases };
|
|
1350
|
+
}
|
|
1351
|
+
function readSessionStorage() {
|
|
1352
|
+
const g = globalThis;
|
|
1353
|
+
const items = [];
|
|
1354
|
+
for (let i = 0; i < g.sessionStorage.length; i++) {
|
|
1355
|
+
const name = g.sessionStorage.key(i);
|
|
1356
|
+
if (name !== null) items.push({ name, value: g.sessionStorage.getItem(name) ?? "" });
|
|
1357
|
+
}
|
|
1358
|
+
return { origin: g.location.origin, items };
|
|
1359
|
+
}
|
|
1360
|
+
function seedSessionStorage(seed) {
|
|
1361
|
+
const g = globalThis;
|
|
1362
|
+
if (g.location.origin !== seed.origin) return;
|
|
1363
|
+
try {
|
|
1364
|
+
if (g.sessionStorage.getItem(seed.marker) !== null) return;
|
|
1365
|
+
for (const { name, value } of seed.items) g.sessionStorage.setItem(name, value);
|
|
1366
|
+
g.sessionStorage.setItem(seed.marker, "1");
|
|
1367
|
+
} catch {
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
var isMissing = (record, field) => !(field in record) && !(`${field}Encoded` in record);
|
|
1371
|
+
var isOutOfLine = (store) => store.keyPath === void 0 && store.keyPathArray === void 0;
|
|
1372
|
+
function repairIndexedDB(state, found) {
|
|
1373
|
+
const origins = structuredClone(state.origins);
|
|
1374
|
+
for (const origin of origins) {
|
|
1375
|
+
const databases = origin.indexedDB ?? [];
|
|
1376
|
+
if (origin.origin !== found.origin) {
|
|
1377
|
+
const broken = databases.some(
|
|
1378
|
+
(db) => db.stores.some(
|
|
1379
|
+
(store) => store.records.some((r) => isOutOfLine(store) && isMissing(r, "key") || isMissing(r, "value"))
|
|
1380
|
+
)
|
|
1381
|
+
);
|
|
1382
|
+
if (broken) delete origin.indexedDB;
|
|
1383
|
+
continue;
|
|
1384
|
+
}
|
|
1385
|
+
for (const db of databases) {
|
|
1386
|
+
for (const store of db.stores) {
|
|
1387
|
+
const read = found.databases.find((d) => d.name === db.name)?.stores.find((s) => s.name === store.name);
|
|
1388
|
+
if (!read || read.count !== store.records.length) return void 0;
|
|
1389
|
+
const keys = new Map(read.keys);
|
|
1390
|
+
const values = new Map(read.values);
|
|
1391
|
+
for (const [i, record] of store.records.entries()) {
|
|
1392
|
+
if (isOutOfLine(store)) {
|
|
1393
|
+
const key = keys.get(i);
|
|
1394
|
+
if (isMissing(record, "key")) {
|
|
1395
|
+
if (key === void 0) return void 0;
|
|
1396
|
+
record.key = key;
|
|
1397
|
+
} else if (key !== void 0 && record.key !== key) {
|
|
1398
|
+
return void 0;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
const value = values.get(i);
|
|
1402
|
+
if (isMissing(record, "value")) {
|
|
1403
|
+
if (value === void 0) return void 0;
|
|
1404
|
+
if ("plain" in value) record.value = value.plain;
|
|
1405
|
+
else record.valueEncoded = value;
|
|
1406
|
+
} else if (value !== void 0 && "value" in record && record.value) {
|
|
1407
|
+
return void 0;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
return { ...state, origins };
|
|
1414
|
+
}
|
|
1415
|
+
var CAPTURE_ATTEMPTS = 3;
|
|
1416
|
+
async function captureSession(context, page) {
|
|
1417
|
+
for (let attempt = 1; ; attempt++) {
|
|
1418
|
+
const state = await context.storageState({ indexedDB: true });
|
|
1419
|
+
const found = await page.evaluate(readFalsyRecords);
|
|
1420
|
+
const repaired = repairIndexedDB(state, found);
|
|
1421
|
+
if (repaired) {
|
|
1422
|
+
const sessionStorage = await page.evaluate(readSessionStorage);
|
|
1423
|
+
return {
|
|
1424
|
+
storageState: repaired,
|
|
1425
|
+
...sessionStorage.items.length > 0 && sessionStorage.origin !== "null" ? { sessionStorage } : {}
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
if (attempt === CAPTURE_ATTEMPTS) {
|
|
1429
|
+
throw new Error(`the app kept writing to its IndexedDB while the session was read (${CAPTURE_ATTEMPTS} attempts)`);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
async function seedSessionStorageInto(context, seed) {
|
|
1434
|
+
await context.addInitScript(seedSessionStorage, { ...seed, marker: SESSION_SEEDED_MARKER });
|
|
1435
|
+
}
|
|
1436
|
+
function isSessionStorageSeed(value) {
|
|
1437
|
+
return typeof value === "object" && value !== null && typeof value.origin === "string" && Array.isArray(value.items) && value.items.every(
|
|
1438
|
+
(item) => typeof item?.name === "string" && typeof item?.value === "string"
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1272
1442
|
// src/auth.ts
|
|
1273
1443
|
var AUTH_STATE_RELATIVE_PATH = path3.join(".blastproof", ".auth-state.json");
|
|
1274
1444
|
var AuthError = class extends Error {
|
|
@@ -1300,7 +1470,8 @@ async function fromStorageState(file) {
|
|
|
1300
1470
|
`Invalid storage state at ${file}: expected an object with "cookies" and "origins" arrays.`
|
|
1301
1471
|
);
|
|
1302
1472
|
}
|
|
1303
|
-
|
|
1473
|
+
const { sessionStorage, ...storageState } = parsed;
|
|
1474
|
+
return { storageState, ...isSessionStorageSeed(sessionStorage) ? { sessionStorage } : {} };
|
|
1304
1475
|
}
|
|
1305
1476
|
function fromStatic(auth, mask) {
|
|
1306
1477
|
const session = {};
|
|
@@ -1392,7 +1563,55 @@ async function fromSteps(options) {
|
|
|
1392
1563
|
throw new AuthError(`Authentication could not be verified: ${mask.mask(judgment.reason)}`);
|
|
1393
1564
|
}
|
|
1394
1565
|
}
|
|
1395
|
-
|
|
1566
|
+
let session;
|
|
1567
|
+
try {
|
|
1568
|
+
session = await captureSession(context, page);
|
|
1569
|
+
} catch (error) {
|
|
1570
|
+
throw new AuthError(
|
|
1571
|
+
`Signed in, but the session could not be captured: ${error instanceof Error ? error.message : String(error)}`
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
await checkWhereUsed(options, session, page, takeSnapshot);
|
|
1575
|
+
return session;
|
|
1576
|
+
} finally {
|
|
1577
|
+
await context.close();
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
async function checkWhereUsed(options, session, loginPage, takeSnapshot) {
|
|
1581
|
+
const { browser, brain, mask, maxRetries, timeoutMs } = options;
|
|
1582
|
+
const verify = options.auth.verify;
|
|
1583
|
+
if (!verify) return;
|
|
1584
|
+
let context;
|
|
1585
|
+
try {
|
|
1586
|
+
context = await browser.newContext(contextOptions(session, options.device));
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
throw new AuthError(
|
|
1589
|
+
"Signed in, but the captured session cannot be restored into a new browser context: " + (error instanceof Error ? error.message : String(error))
|
|
1590
|
+
);
|
|
1591
|
+
}
|
|
1592
|
+
try {
|
|
1593
|
+
await seedContext(context, session);
|
|
1594
|
+
const page = await context.newPage();
|
|
1595
|
+
try {
|
|
1596
|
+
await page.goto(loginPage.url(), { timeout: timeoutMs });
|
|
1597
|
+
} catch (error) {
|
|
1598
|
+
throw new AuthError(
|
|
1599
|
+
"Signed in, but the page the login ended on did not open in a new browser context seeded with the session: " + (error instanceof Error ? error.message : String(error))
|
|
1600
|
+
);
|
|
1601
|
+
}
|
|
1602
|
+
await waitForSettled(page);
|
|
1603
|
+
const judgment = await verifyJudgment(
|
|
1604
|
+
brain,
|
|
1605
|
+
verify,
|
|
1606
|
+
async () => withoutRefs(mask.mask(await takeSnapshot(page))),
|
|
1607
|
+
(text) => mask.mask(text),
|
|
1608
|
+
maxRetries
|
|
1609
|
+
);
|
|
1610
|
+
if (!judgment.pass) {
|
|
1611
|
+
throw new AuthError(
|
|
1612
|
+
`Signed in, but the captured session does not keep the sign-in: a new browser context seeded with it is not signed in (${mask.mask(judgment.reason)}). The app may keep its session where a storage state cannot hold it, such as memory or a service worker. Tests would start signed out, so none were run.`
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1396
1615
|
} finally {
|
|
1397
1616
|
await context.close();
|
|
1398
1617
|
}
|
|
@@ -1408,7 +1627,8 @@ async function writeCached(cwd, session) {
|
|
|
1408
1627
|
if (!session.storageState) return;
|
|
1409
1628
|
const file = path3.join(cwd, AUTH_STATE_RELATIVE_PATH);
|
|
1410
1629
|
await mkdir3(path3.dirname(file), { recursive: true });
|
|
1411
|
-
|
|
1630
|
+
const cached = session.sessionStorage ? { ...session.storageState, sessionStorage: session.sessionStorage } : session.storageState;
|
|
1631
|
+
await writeFile2(file, JSON.stringify(cached), "utf8");
|
|
1412
1632
|
}
|
|
1413
1633
|
async function authenticate(options) {
|
|
1414
1634
|
const { auth, cwd } = options;
|
|
@@ -1434,6 +1654,9 @@ function contextOptions(session, device) {
|
|
|
1434
1654
|
...session.extraHTTPHeaders ? { extraHTTPHeaders: session.extraHTTPHeaders } : {}
|
|
1435
1655
|
};
|
|
1436
1656
|
}
|
|
1657
|
+
async function seedContext(context, session) {
|
|
1658
|
+
if (session?.sessionStorage) await seedSessionStorageInto(context, session.sessionStorage);
|
|
1659
|
+
}
|
|
1437
1660
|
|
|
1438
1661
|
// src/config.ts
|
|
1439
1662
|
import { readFile as readFile2 } from "fs/promises";
|
|
@@ -1831,7 +2054,7 @@ Rules:
|
|
|
1831
2054
|
- Return exactly ONE action per response. Never batch actions.
|
|
1832
2055
|
- Placeholders like {{env.SOME_NAME}} are secrets that are filled in after you answer. Pass them through in your action exactly as written, never expanded, never guessed at.
|
|
1833
2056
|
- Pick target elements exclusively from the current snapshot. Every element there carries a ref, like \`[ref=f1e25]\`: name your target by that ref, and give its role and name exactly as that same line shows them (the text after the colon when it has no quoted name). The ref decides which element is acted on, so copy it from the line of the element you mean; a role or name that does not match that line is refused. Refs change when the page changes, so always take them from the current snapshot. Never invent CSS selectors or guess elements not in the snapshot.
|
|
1834
|
-
- Use "navigate" only with a URL or path as value. Use "fill" to type into textboxes/inputs. Use "press" for keyboard keys (value e.g. "Enter"). Use "select" for dropdowns (value = option label).
|
|
2057
|
+
- Use "navigate" only with a URL or path as value. Use "fill" to type into textboxes/inputs. Use "press" for keyboard keys (value e.g. "Enter"). Use "select" for dropdowns (value = option label). Use "hover" to point at an element without clicking it, when a menu, tooltip or control appears only on hover.
|
|
1835
2058
|
- Use "assert" with an expectation to verify page state (visible text, counts, URLs). Assertions never modify the page.
|
|
1836
2059
|
- A step that begins with "verify", "check", "confirm", "ensure", "assert", "expect", "validate", "make sure" or "see that" only looks. Never click or press in it: making the page show what the step checks would hide the very thing it checks. Assert what the page shows, navigate if what it names is on another page, or fail. It closes on a passing assertion, never on "done". This is enforced: a click, a press or "done" in such a step is refused.
|
|
1837
2060
|
- Return "done" when the current step's outcome holds \u2014 including when it already held before you acted, or was achieved by your previous action. "Already true" is done, never failure. Do not return "done" for work belonging to later steps.
|
|
@@ -2165,7 +2388,7 @@ import { z as z2 } from "zod";
|
|
|
2165
2388
|
function absentAsNull(schema) {
|
|
2166
2389
|
return schema.nullable().transform((value) => value ?? void 0);
|
|
2167
2390
|
}
|
|
2168
|
-
var ACTION_NAMES = ["navigate", "click", "fill", "press", "select", "assert", "done", "fail"];
|
|
2391
|
+
var ACTION_NAMES = ["navigate", "click", "fill", "press", "select", "hover", "assert", "done", "fail"];
|
|
2169
2392
|
var agentActionSchema = z2.object({
|
|
2170
2393
|
action: z2.enum(ACTION_NAMES).describe("The next browser action to perform for the current step."),
|
|
2171
2394
|
target: absentAsNull(
|
|
@@ -3206,6 +3429,7 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3206
3429
|
const device = test.device ?? config.browser.device;
|
|
3207
3430
|
const context = await browser.newContext(contextOptions(test.auth ? session : void 0, device));
|
|
3208
3431
|
try {
|
|
3432
|
+
await seedContext(context, test.auth ? session : void 0);
|
|
3209
3433
|
const page = await context.newPage();
|
|
3210
3434
|
page.setDefaultTimeout(config.browser.timeout_ms);
|
|
3211
3435
|
const result = await executeTest(page, resolved, {
|
|
@@ -3225,28 +3449,42 @@ async function runOne(browser, test, config, sessionDir, session, runMask, budge
|
|
|
3225
3449
|
await context.close();
|
|
3226
3450
|
}
|
|
3227
3451
|
}
|
|
3228
|
-
function
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3452
|
+
function count(n, singular, plural) {
|
|
3453
|
+
return `${n} ${n === 1 ? singular : plural}`;
|
|
3454
|
+
}
|
|
3455
|
+
var IGNORED_NAMED = 3;
|
|
3456
|
+
function printImpactReport(impact, selection, changedCount, base, cwd) {
|
|
3457
|
+
const uncovered = new Set(selection.uncoveredRoutes);
|
|
3458
|
+
const unrouted = selection.unroutedSkipped;
|
|
3459
|
+
const gaps = [
|
|
3460
|
+
impact.unmappedFiles.length > 0 && count(impact.unmappedFiles.length, "unclassified file", "unclassified files"),
|
|
3461
|
+
uncovered.size > 0 && count(uncovered.size, "route no selected test covers", "routes no selected test covers"),
|
|
3462
|
+
unrouted.length > 0 && count(unrouted.length, "test with no routes:", "tests with no routes:")
|
|
3463
|
+
].filter((gap) => gap !== false);
|
|
3464
|
+
console.log(`
|
|
3465
|
+
${`--- Impact against ${base} `.padEnd(64, "-")}`);
|
|
3466
|
+
console.log(`Not covered: ${gaps.length > 0 ? gaps.join(" \xB7 ") : "nothing"}`);
|
|
3467
|
+
console.log(`
|
|
3468
|
+
Changed files: ${changedCount}`);
|
|
3469
|
+
const reaching = changedCount - impact.ignoredFiles.length - impact.unmappedFiles.length;
|
|
3470
|
+
if (reaching > 0) console.log(` ${reaching} reach a route`);
|
|
3238
3471
|
if (impact.ignoredFiles.length > 0) {
|
|
3239
|
-
|
|
3472
|
+
const named = impact.ignoredFiles.slice(0, IGNORED_NAMED).join(", ");
|
|
3473
|
+
const more = impact.ignoredFiles.length - IGNORED_NAMED;
|
|
3474
|
+
console.log(` ${impact.ignoredFiles.length} ignored by an ignore: glob: ${named}${more > 0 ? ` and ${more} more` : ""}`);
|
|
3240
3475
|
}
|
|
3241
|
-
if (
|
|
3242
|
-
console.log(
|
|
3243
|
-
for (const
|
|
3244
|
-
|
|
3245
|
-
|
|
3476
|
+
if (impact.unmappedFiles.length > 0) {
|
|
3477
|
+
console.log(` ${impact.unmappedFiles.length} unclassified, matched by no routes: or ignore: glob:`);
|
|
3478
|
+
for (const file of impact.unmappedFiles) console.log(` ${file}`);
|
|
3479
|
+
}
|
|
3480
|
+
console.log(`Routes the diff reaches: ${impact.affectedRoutes.length > 0 ? impact.affectedRoutes.length : "none"}`);
|
|
3481
|
+
for (const route of impact.affectedRoutes) {
|
|
3482
|
+
console.log(` ${route}${uncovered.has(route) ? " (no selected test covers it)" : ""}`);
|
|
3246
3483
|
}
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3484
|
+
console.log(`Tests: ${selection.selected.length} selected`);
|
|
3485
|
+
if (unrouted.length > 0) {
|
|
3486
|
+
console.log(` ${unrouted.length} ${unrouted.length === 1 ? "declares" : "declare"} no routes:, so --impacted cannot select ${unrouted.length === 1 ? "it" : "them"}:`);
|
|
3487
|
+
for (const test of unrouted) console.log(` ${test.summary} (${path10.relative(cwd, test.path)})`);
|
|
3250
3488
|
}
|
|
3251
3489
|
console.log("---------------------------------------------------------------");
|
|
3252
3490
|
}
|
|
@@ -3402,6 +3640,7 @@ async function runCommand(options) {
|
|
|
3402
3640
|
return EXIT_USAGE;
|
|
3403
3641
|
}
|
|
3404
3642
|
let impact;
|
|
3643
|
+
let changedCount = 0;
|
|
3405
3644
|
if (impacted) {
|
|
3406
3645
|
let changedFiles;
|
|
3407
3646
|
try {
|
|
@@ -3414,6 +3653,7 @@ async function runCommand(options) {
|
|
|
3414
3653
|
throw error;
|
|
3415
3654
|
}
|
|
3416
3655
|
impact = mapImpact(changedFiles, config.routes ?? {}, config.ignore ?? []);
|
|
3656
|
+
changedCount = changedFiles.length;
|
|
3417
3657
|
printUncommitted(await getUncommittedFiles(options.cwd), changedFiles, config, base, warnings);
|
|
3418
3658
|
}
|
|
3419
3659
|
const testsDir = path10.join(options.cwd, TESTS_RELATIVE_DIR);
|
|
@@ -3463,7 +3703,7 @@ async function runCommand(options) {
|
|
|
3463
3703
|
};
|
|
3464
3704
|
const selected = selection.selected;
|
|
3465
3705
|
if (impact) {
|
|
3466
|
-
printImpactReport(impact, selection, options.cwd);
|
|
3706
|
+
printImpactReport(impact, selection, changedCount, base, options.cwd);
|
|
3467
3707
|
}
|
|
3468
3708
|
if (options.dryRun) {
|
|
3469
3709
|
printDryRun(selected, config, options.cwd);
|
|
@@ -3782,6 +4022,7 @@ async function planCommand(options) {
|
|
|
3782
4022
|
let draft;
|
|
3783
4023
|
const context = await browser.newContext(contextOptions(session, config.browser.device));
|
|
3784
4024
|
try {
|
|
4025
|
+
await seedContext(context, session);
|
|
3785
4026
|
const page = await context.newPage();
|
|
3786
4027
|
page.setDefaultTimeout(config.browser.timeout_ms);
|
|
3787
4028
|
draft = await generateForRoute(page, {
|
|
@@ -3942,7 +4183,7 @@ function parsePositiveNumber(flag) {
|
|
|
3942
4183
|
};
|
|
3943
4184
|
}
|
|
3944
4185
|
var program = new Command();
|
|
3945
|
-
program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.
|
|
4186
|
+
program.name("blastproof").description("Open-source AI testing agent: plain-English YAML tests executed agentically on a real browser.").version("0.31.0");
|
|
3946
4187
|
program.command("init").description("Scaffold .blastproof/ (config, tests, sample tests) in the current directory").action(async () => {
|
|
3947
4188
|
try {
|
|
3948
4189
|
const result = await initProject(process.cwd());
|