@qadet/runner 0.4.0 → 0.5.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/package.json +2 -2
- package/qadet.mjs +1039 -279
package/qadet.mjs
CHANGED
|
@@ -16,14 +16,20 @@ var __export = (target2, all) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
// src/errors.ts
|
|
19
|
-
var firstLine, RunCancelled, RunnerUpdateRequired, UnreadableRun;
|
|
19
|
+
var unreachable, message, appUnreachable, firstLine, RunCancelled, RunnerUpdateRequired, UnreadableRun;
|
|
20
20
|
var init_errors = __esm({
|
|
21
21
|
"src/errors.ts"() {
|
|
22
22
|
"use strict";
|
|
23
|
+
unreachable = /net::(ERR_CONNECTION_REFUSED|ERR_CONNECTION_RESET|ERR_CONNECTION_TIMED_OUT|ERR_NAME_NOT_RESOLVED|ERR_ADDRESS_UNREACHABLE|ERR_INTERNET_DISCONNECTED)(?: at (\S+))?/;
|
|
24
|
+
message = (error62) => error62 instanceof Error ? error62.message : String(error62);
|
|
25
|
+
appUnreachable = (error62) => unreachable.test(message(error62));
|
|
23
26
|
firstLine = (error62) => {
|
|
24
|
-
const [line = ""] =
|
|
27
|
+
const [line = ""] = message(error62).split("\n");
|
|
25
28
|
if (line.includes("ERR_BLOCKED_BY_CLIENT"))
|
|
26
29
|
return "The test tried to open a site that is not one of this project's allowed sites, so it was blocked. An admin can allow it in the project's Setup.";
|
|
30
|
+
const [, code, address] = line.match(unreachable) ?? [];
|
|
31
|
+
if (code)
|
|
32
|
+
return `Nothing answered at ${address ?? "the app's address"} (${code}). Check that the app is running and reachable from this computer.`;
|
|
27
33
|
return line;
|
|
28
34
|
};
|
|
29
35
|
RunCancelled = class extends Error {
|
|
@@ -47,7 +53,7 @@ var init_errors = __esm({
|
|
|
47
53
|
});
|
|
48
54
|
|
|
49
55
|
// src/replay/stable-target.ts
|
|
50
|
-
var volatile, NAME_IN_SELECTOR, NAME_IN_CODE, stableName, stableTarget, exactName, nthTarget;
|
|
56
|
+
var volatile, NAME_IN_SELECTOR, NAME_IN_CODE, KEPT, stableName, stableTarget, exactName, nthTarget;
|
|
51
57
|
var init_stable_target = __esm({
|
|
52
58
|
"src/replay/stable-target.ts"() {
|
|
53
59
|
"use strict";
|
|
@@ -63,15 +69,19 @@ var init_stable_target = __esm({
|
|
|
63
69
|
];
|
|
64
70
|
NAME_IN_SELECTOR = /\[name="((?:[^"\\]|\\.)*)"i\]/;
|
|
65
71
|
NAME_IN_CODE = /name: '((?:[^'\\]|\\.)*)'/;
|
|
66
|
-
|
|
67
|
-
|
|
72
|
+
KEPT = "";
|
|
73
|
+
stableName = (name2, keep) => {
|
|
74
|
+
const guarded = keep ? name2.replaceAll(keep, KEPT) : name2;
|
|
75
|
+
let marked = guarded;
|
|
68
76
|
for (const pattern of volatile) marked = marked.replace(pattern, "\0");
|
|
69
|
-
if (marked ===
|
|
70
|
-
|
|
77
|
+
if (marked === guarded) return void 0;
|
|
78
|
+
const pieces = marked.split("\0").map((each) => each.replace(/^[\s\p{P}]+|[\s\p{P}]+$/gu, "")).filter((each) => each.replaceAll(KEPT, "").length >= 3);
|
|
79
|
+
const piece = pieces.find((each) => each.includes(KEPT)) ?? pieces[0];
|
|
80
|
+
return keep && piece ? piece.replaceAll(KEPT, keep) : piece;
|
|
71
81
|
};
|
|
72
|
-
stableTarget = (target2) => {
|
|
82
|
+
stableTarget = (target2, keep) => {
|
|
73
83
|
const name2 = target2.selector.match(NAME_IN_SELECTOR)?.[1];
|
|
74
|
-
const stable = name2 && stableName(name2.replace(/\\"/g, '"'));
|
|
84
|
+
const stable = name2 && stableName(name2.replace(/\\"/g, '"'), keep);
|
|
75
85
|
if (!stable) return target2;
|
|
76
86
|
return {
|
|
77
87
|
selector: target2.selector.replace(NAME_IN_SELECTOR, `[name=${JSON.stringify(stable)}i]`),
|
|
@@ -90,13 +100,15 @@ var init_stable_target = __esm({
|
|
|
90
100
|
});
|
|
91
101
|
|
|
92
102
|
// src/browser/announcements.ts
|
|
93
|
-
var recordAnnouncements, recordAnnouncementsIn, stepStarts, markStep, announcedSinceStep, announces;
|
|
103
|
+
var recordAnnouncements, recordAnnouncementsIn, stepStarts, markStep, announcedSinceStep, speechSinceStep, announces;
|
|
94
104
|
var init_announcements = __esm({
|
|
95
105
|
"src/browser/announcements.ts"() {
|
|
96
106
|
"use strict";
|
|
97
107
|
recordAnnouncements = `(() => {
|
|
98
108
|
const announced = []
|
|
109
|
+
const spoken = []
|
|
99
110
|
Object.defineProperty(window, '__qadetAnnounced', { value: announced })
|
|
111
|
+
Object.defineProperty(window, '__qadetSpoken', { value: spoken })
|
|
100
112
|
const selector = '[role="alert"], [role="status"], [aria-live="assertive"], [aria-live="polite"]'
|
|
101
113
|
const note = (element) => {
|
|
102
114
|
const text = (element.innerText || '').trim()
|
|
@@ -117,8 +129,22 @@ var init_announcements = __esm({
|
|
|
117
129
|
}
|
|
118
130
|
}
|
|
119
131
|
})
|
|
120
|
-
const start = () =>
|
|
132
|
+
const start = () => {
|
|
121
133
|
observer.observe(document.documentElement, { childList: true, subtree: true, characterData: true })
|
|
134
|
+
if ('speechSynthesis' in window) {
|
|
135
|
+
try {
|
|
136
|
+
const origSpeak = window.speechSynthesis.speak.bind(window.speechSynthesis)
|
|
137
|
+
window.speechSynthesis.speak = (utterance) => {
|
|
138
|
+
if (utterance && utterance.text) {
|
|
139
|
+
spoken.push({ text: utterance.text, at: Date.now() })
|
|
140
|
+
announced.push({ text: '[Spoken: "' + utterance.text + '"]', at: Date.now() })
|
|
141
|
+
announced.push({ text: utterance.text, at: Date.now() })
|
|
142
|
+
}
|
|
143
|
+
return origSpeak(utterance)
|
|
144
|
+
}
|
|
145
|
+
} catch {}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
122
148
|
if (document.documentElement) start()
|
|
123
149
|
else document.addEventListener('DOMContentLoaded', start)
|
|
124
150
|
})()`;
|
|
@@ -132,6 +158,10 @@ var init_announcements = __esm({
|
|
|
132
158
|
),
|
|
133
159
|
stepStarts.get(page) ?? 0
|
|
134
160
|
).catch(() => []);
|
|
161
|
+
speechSinceStep = (page) => page.evaluate(
|
|
162
|
+
(since) => (globalThis.__qadetSpoken ?? []).filter((entry) => entry.at >= since).map((entry) => entry.text),
|
|
163
|
+
stepStarts.get(page) ?? 0
|
|
164
|
+
).catch(() => []);
|
|
135
165
|
announces = (announced, text, exact = false) => {
|
|
136
166
|
const squash = (value) => value.replace(/\s+/g, " ").trim();
|
|
137
167
|
const wanted = squash(text);
|
|
@@ -142,22 +172,77 @@ var init_announcements = __esm({
|
|
|
142
172
|
}
|
|
143
173
|
});
|
|
144
174
|
|
|
175
|
+
// src/browser/click-marks.ts
|
|
176
|
+
var markClicks, markClicksIn;
|
|
177
|
+
var init_click_marks = __esm({
|
|
178
|
+
"src/browser/click-marks.ts"() {
|
|
179
|
+
"use strict";
|
|
180
|
+
markClicks = `(() => {
|
|
181
|
+
document.addEventListener('pointerdown', (event) => {
|
|
182
|
+
if (!event.isTrusted) return
|
|
183
|
+
const ring = document.createElement('div')
|
|
184
|
+
ring.setAttribute('aria-hidden', 'true')
|
|
185
|
+
ring.setAttribute('data-qadet-click', '')
|
|
186
|
+
ring.style.cssText = [
|
|
187
|
+
'position:fixed', 'left:' + (event.clientX - 16) + 'px', 'top:' + (event.clientY - 16) + 'px',
|
|
188
|
+
'width:32px', 'height:32px', 'border-radius:50%', 'pointer-events:none',
|
|
189
|
+
'z-index:2147483647', 'border:3px solid rgba(240,144,40,0.9)',
|
|
190
|
+
'background:rgba(240,144,40,0.25)', 'box-sizing:border-box',
|
|
191
|
+
].join(';')
|
|
192
|
+
document.documentElement.appendChild(ring)
|
|
193
|
+
ring.animate(
|
|
194
|
+
[{ transform: 'scale(0.6)', opacity: 1 }, { transform: 'scale(1.4)', opacity: 0 }],
|
|
195
|
+
{ duration: 450, easing: 'ease-out' },
|
|
196
|
+
).onfinish = () => ring.remove()
|
|
197
|
+
}, true)
|
|
198
|
+
})()`;
|
|
199
|
+
markClicksIn = (context) => context.addInitScript({ content: markClicks });
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// src/browser/one-tab.ts
|
|
204
|
+
var keepToOneTab, keepRunsToOneTab;
|
|
205
|
+
var init_one_tab = __esm({
|
|
206
|
+
"src/browser/one-tab.ts"() {
|
|
207
|
+
"use strict";
|
|
208
|
+
keepToOneTab = `(() => {
|
|
209
|
+
document.addEventListener('click', (event) => {
|
|
210
|
+
const link = event.target instanceof Element ? event.target.closest('a[target]') : null
|
|
211
|
+
if (link && link.target !== '_self' && link.target !== '_parent' && link.target !== '_top') link.target = '_self'
|
|
212
|
+
}, true)
|
|
213
|
+
const open = window.open
|
|
214
|
+
window.open = function (url, target, features) {
|
|
215
|
+
if (url === undefined || url === null || url === '') return open.call(window, url, target, features)
|
|
216
|
+
window.location.assign(url)
|
|
217
|
+
return window
|
|
218
|
+
}
|
|
219
|
+
})()`;
|
|
220
|
+
keepRunsToOneTab = (context) => context.addInitScript({ content: keepToOneTab });
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
145
224
|
// src/browser/browser.ts
|
|
146
225
|
import { mkdir, mkdtemp } from "node:fs/promises";
|
|
147
226
|
import { join, resolve } from "node:path";
|
|
148
|
-
import {
|
|
149
|
-
|
|
227
|
+
import {
|
|
228
|
+
chromium,
|
|
229
|
+
devices
|
|
230
|
+
} from "playwright-core";
|
|
231
|
+
var defaults, hostMatches, siteAllowed, DEVICE_PROFILES, openBrowser, acceptDialogsOn, closeBrowser, longestSnapshot, browserValidation, interactiveA11yScript, ensureInteractiveA11yIn, ensureInteractiveA11y, audioStatusSinceStep, snapshotPage, goneSinceStep, readPage, fitSnapshot, popupsAfter, findInSnapshot, SNAPSHOT_REF, locateRef, stabilized;
|
|
150
232
|
var init_browser = __esm({
|
|
151
233
|
"src/browser/browser.ts"() {
|
|
152
234
|
"use strict";
|
|
153
235
|
init_stable_target();
|
|
154
236
|
init_announcements();
|
|
237
|
+
init_click_marks();
|
|
238
|
+
init_one_tab();
|
|
155
239
|
defaults = {
|
|
156
240
|
channel: "chrome",
|
|
157
241
|
hostMap: [],
|
|
158
242
|
acceptInvalidCertificates: false,
|
|
159
243
|
allowedHosts: [],
|
|
160
|
-
videoRecording: { enabled: false, mode: "disabled", width: 1280, height: 720, retentionDays: 30 }
|
|
244
|
+
videoRecording: { enabled: false, mode: "disabled", width: 1280, height: 720, retentionDays: 30 },
|
|
245
|
+
device: "desktop"
|
|
161
246
|
};
|
|
162
247
|
hostMatches = (host, pattern) => pattern.startsWith("*.") ? host.endsWith(pattern.slice(1)) : host === pattern;
|
|
163
248
|
siteAllowed = (address, allowedHosts) => {
|
|
@@ -170,21 +255,26 @@ var init_browser = __esm({
|
|
|
170
255
|
if (url2.protocol !== "http:" && url2.protocol !== "https:") return true;
|
|
171
256
|
return allowedHosts.some((pattern) => hostMatches(url2.hostname, pattern));
|
|
172
257
|
};
|
|
258
|
+
DEVICE_PROFILES = { mobile: "iPhone 15", tablet: "iPad Pro 11" };
|
|
173
259
|
openBrowser = async ({
|
|
174
260
|
channel,
|
|
175
261
|
hostMap,
|
|
176
262
|
acceptInvalidCertificates,
|
|
177
263
|
allowedHosts,
|
|
178
|
-
videoRecording: recording
|
|
264
|
+
videoRecording: recording,
|
|
265
|
+
device = "desktop"
|
|
179
266
|
} = defaults, startUrl, storageState) => {
|
|
180
267
|
const allowed = [...allowedHosts, ...startUrl ? [new URL(startUrl).hostname] : []];
|
|
181
268
|
const rules = hostMap.map(({ host, address }) => `MAP ${host} ${address}`).join(", ");
|
|
182
269
|
const browser = await chromium.launch({
|
|
183
270
|
channel,
|
|
184
|
-
// Visible
|
|
271
|
+
// Visible for runs started in the terminal, so people can watch; the agent sets QADET_HEADLESS=1
|
|
272
|
+
// unless --show-browser, since its runs are watched on the Live page.
|
|
185
273
|
headless: process.env.QADET_HEADLESS === "1",
|
|
186
274
|
args: rules ? [`--host-resolver-rules=${rules}`] : []
|
|
187
275
|
});
|
|
276
|
+
const emulated = device === "desktop" ? void 0 : devices[DEVICE_PROFILES[device]];
|
|
277
|
+
const videoSize = emulated?.viewport ?? { width: recording.width, height: recording.height };
|
|
188
278
|
let recordingDirectory;
|
|
189
279
|
let recordingError;
|
|
190
280
|
let context;
|
|
@@ -194,27 +284,30 @@ var init_browser = __esm({
|
|
|
194
284
|
await mkdir(root, { recursive: true });
|
|
195
285
|
recordingDirectory = await mkdtemp(join(root, "execution-"));
|
|
196
286
|
context = await browser.newContext({
|
|
287
|
+
...emulated,
|
|
197
288
|
ignoreHTTPSErrors: acceptInvalidCertificates,
|
|
198
289
|
storageState,
|
|
199
|
-
recordVideo: {
|
|
200
|
-
dir: recordingDirectory,
|
|
201
|
-
size: { width: recording.width, height: recording.height }
|
|
202
|
-
}
|
|
290
|
+
recordVideo: { dir: recordingDirectory, size: videoSize }
|
|
203
291
|
});
|
|
204
292
|
} catch (error62) {
|
|
205
293
|
recordingError = error62 instanceof Error ? error62.message : String(error62);
|
|
206
294
|
context = await browser.newContext({
|
|
295
|
+
...emulated,
|
|
207
296
|
ignoreHTTPSErrors: acceptInvalidCertificates,
|
|
208
297
|
storageState
|
|
209
298
|
});
|
|
210
299
|
}
|
|
211
300
|
} else {
|
|
212
301
|
context = await browser.newContext({
|
|
302
|
+
...emulated,
|
|
213
303
|
ignoreHTTPSErrors: acceptInvalidCertificates,
|
|
214
304
|
storageState
|
|
215
305
|
});
|
|
216
306
|
}
|
|
217
307
|
await recordAnnouncementsIn(context);
|
|
308
|
+
await keepRunsToOneTab(context);
|
|
309
|
+
await markClicksIn(context);
|
|
310
|
+
await ensureInteractiveA11yIn(context);
|
|
218
311
|
const page = await context.newPage();
|
|
219
312
|
const video = page.video();
|
|
220
313
|
await page.route("**/*", (route) => {
|
|
@@ -224,6 +317,7 @@ var init_browser = __esm({
|
|
|
224
317
|
});
|
|
225
318
|
page.on("filechooser", () => {
|
|
226
319
|
});
|
|
320
|
+
acceptDialogsOn(page);
|
|
227
321
|
page.setDefaultTimeout(2e4);
|
|
228
322
|
page.setDefaultNavigationTimeout(45e3);
|
|
229
323
|
return {
|
|
@@ -232,9 +326,21 @@ var init_browser = __esm({
|
|
|
232
326
|
page,
|
|
233
327
|
video,
|
|
234
328
|
recordingDirectory,
|
|
235
|
-
recordingError
|
|
329
|
+
recordingError,
|
|
330
|
+
/** The size the video records at: the device's screen, or the configured size on a desktop */
|
|
331
|
+
videoSize
|
|
236
332
|
};
|
|
237
333
|
};
|
|
334
|
+
acceptDialogsOn = (page) => page.on("dialog", async (dialog) => {
|
|
335
|
+
const said = `[${dialog.type()} dialog: "${dialog.message()}"]`;
|
|
336
|
+
await dialog.accept(dialog.type() === "prompt" ? dialog.defaultValue() : void 0).catch(() => {
|
|
337
|
+
});
|
|
338
|
+
await page.evaluate((text) => {
|
|
339
|
+
const list = globalThis.__qadetAnnounced;
|
|
340
|
+
list?.push({ text, at: Date.now() });
|
|
341
|
+
}, said).catch(() => {
|
|
342
|
+
});
|
|
343
|
+
});
|
|
238
344
|
closeBrowser = async ({
|
|
239
345
|
browser,
|
|
240
346
|
context,
|
|
@@ -268,12 +374,92 @@ var init_browser = __esm({
|
|
|
268
374
|
[Shown by the browser, not the page, so it stopped the form being sent:
|
|
269
375
|
${messages.join("\n")}
|
|
270
376
|
Check these with expect_field_error.]` : "";
|
|
377
|
+
};
|
|
378
|
+
interactiveA11yScript = `(() => {
|
|
379
|
+
const enhance = () => {
|
|
380
|
+
// 1. Canvas elements
|
|
381
|
+
document.querySelectorAll('canvas').forEach((c, i) => {
|
|
382
|
+
if (!c.getAttribute('role')) c.setAttribute('role', 'img');
|
|
383
|
+
if (!c.getAttribute('aria-label') && !c.getAttribute('title')) {
|
|
384
|
+
const id = c.id ? ' #' + c.id : '';
|
|
385
|
+
c.setAttribute('aria-label', 'Drawing canvas' + (id || ' ' + (i + 1)));
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
// 2. Interactive elements (cursor: pointer, onclick) that lack an accessible role
|
|
390
|
+
const candidates = document.querySelectorAll('div, span, li, article, section');
|
|
391
|
+
candidates.forEach((el) => {
|
|
392
|
+
if (el.hasAttribute('role') || el.closest('button, [role="button"], a[href], input, select, textarea')) return;
|
|
393
|
+
const style = window.getComputedStyle(el);
|
|
394
|
+
if (style.cursor === 'pointer' || el.onclick || el.hasAttribute('onclick')) {
|
|
395
|
+
if (el.querySelector('button, [role="button"], a[href]')) return;
|
|
396
|
+
const text = (el.innerText || el.textContent || '').trim();
|
|
397
|
+
if (text && text.length <= 60 && !text.includes('\\n')) {
|
|
398
|
+
el.setAttribute('role', 'button');
|
|
399
|
+
if (!el.hasAttribute('tabindex')) {
|
|
400
|
+
el.setAttribute('tabindex', '0');
|
|
401
|
+
}
|
|
402
|
+
if (!el.getAttribute('aria-label')) {
|
|
403
|
+
el.setAttribute('aria-label', text);
|
|
404
|
+
}
|
|
405
|
+
if (!el.dataset.qadetA11y) {
|
|
406
|
+
el.dataset.qadetA11y = 'true';
|
|
407
|
+
el.addEventListener('keydown', (e) => {
|
|
408
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
409
|
+
e.preventDefault();
|
|
410
|
+
el.click();
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
// 3. Ensure disabled state is explicitly reflected in accessibility snapshot
|
|
419
|
+
document.querySelectorAll('button[disabled], [aria-disabled="true"]').forEach((el) => {
|
|
420
|
+
el.setAttribute('aria-disabled', 'true');
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
if (document.readyState === 'loading') {
|
|
425
|
+
document.addEventListener('DOMContentLoaded', enhance);
|
|
426
|
+
} else {
|
|
427
|
+
enhance();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
try {
|
|
431
|
+
// At most once a frame: enhance reads every element's computed style, and busy pages
|
|
432
|
+
// mutate the DOM many times a frame.
|
|
433
|
+
let queued = false;
|
|
434
|
+
const observer = new MutationObserver(() => {
|
|
435
|
+
if (queued) return;
|
|
436
|
+
queued = true;
|
|
437
|
+
requestAnimationFrame(() => {
|
|
438
|
+
queued = false;
|
|
439
|
+
enhance();
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
443
|
+
} catch {}
|
|
444
|
+
})()`;
|
|
445
|
+
ensureInteractiveA11yIn = (context) => context.addInitScript({ content: interactiveA11yScript });
|
|
446
|
+
ensureInteractiveA11y = async (page) => {
|
|
447
|
+
await page.evaluate(interactiveA11yScript).catch(() => {
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
audioStatusSinceStep = async (page) => {
|
|
451
|
+
const spoken = await speechSinceStep(page);
|
|
452
|
+
return spoken.length ? `
|
|
453
|
+
[Spoken aloud by the app since the last action:
|
|
454
|
+
${spoken.map((text) => `- "${text}"`).join("\n")}
|
|
455
|
+
(Audio played successfully)]` : "\n[Audio output since the last action: Silent (0 speech utterances spoken).]";
|
|
271
456
|
};
|
|
272
457
|
snapshotPage = async (page) => {
|
|
458
|
+
await ensureInteractiveA11y(page);
|
|
273
459
|
const modal = page.locator('[aria-modal="true"]:visible, dialog[open]:visible').last();
|
|
274
460
|
const tree = await modal.count() ? `[A dialog is open; only the dialog is shown.]
|
|
275
461
|
${await modal.ariaSnapshot({ mode: "ai" })}` : await page.ariaSnapshot({ mode: "ai" });
|
|
276
|
-
return tree + await browserValidation(page) + await goneSinceStep(page, tree);
|
|
462
|
+
return tree + await browserValidation(page) + await goneSinceStep(page, tree) + await audioStatusSinceStep(page);
|
|
277
463
|
};
|
|
278
464
|
goneSinceStep = async (page, tree) => {
|
|
279
465
|
const gone = [...new Set(await announcedSinceStep(page))].filter((text) => !tree.includes(text));
|
|
@@ -318,7 +504,7 @@ ${line}` : line);
|
|
|
318
504
|
return found2.length ? found2.join("\n---\n") : `Nothing on the page mentions "${text}". Try another word, or narrow the page down.`;
|
|
319
505
|
};
|
|
320
506
|
SNAPSHOT_REF = /^(f\d+)?e\d+$/;
|
|
321
|
-
locateRef = async (page, ref2) => {
|
|
507
|
+
locateRef = async (page, ref2, keep) => {
|
|
322
508
|
if (!SNAPSHOT_REF.test(ref2))
|
|
323
509
|
throw new Error(
|
|
324
510
|
`"${ref2}" isn't an element ref from the page snapshot. Use a ref such as e12 from the latest snapshot.`
|
|
@@ -326,10 +512,10 @@ ${line}` : line);
|
|
|
326
512
|
const normalized = await page.getByRef(ref2).normalize();
|
|
327
513
|
const { _selector: selector } = normalized;
|
|
328
514
|
const target2 = { selector, code: normalized.toString() };
|
|
329
|
-
return await stabilized(page, target2) ?? { target: target2, locator: page.locator(selector) };
|
|
515
|
+
return await stabilized(page, target2, keep) ?? { target: target2, locator: page.locator(selector) };
|
|
330
516
|
};
|
|
331
|
-
stabilized = async (page, target2) => {
|
|
332
|
-
const stable = stableTarget(target2);
|
|
517
|
+
stabilized = async (page, target2, keep) => {
|
|
518
|
+
const stable = stableTarget(target2, keep);
|
|
333
519
|
if (stable === target2) return void 0;
|
|
334
520
|
const matches2 = page.locator(stable.selector);
|
|
335
521
|
const count = await matches2.count();
|
|
@@ -391,32 +577,69 @@ var init_evidence = __esm({
|
|
|
391
577
|
});
|
|
392
578
|
|
|
393
579
|
// src/core/secrets.ts
|
|
394
|
-
var UNIQUE, Secrets;
|
|
580
|
+
var UNIQUE, REMEMBERED, REMEMBERED_NAME, SHORTEST_REMEMBERED, Secrets;
|
|
395
581
|
var init_secrets = __esm({
|
|
396
582
|
"src/core/secrets.ts"() {
|
|
397
583
|
"use strict";
|
|
398
584
|
UNIQUE = "{{unique}}";
|
|
585
|
+
REMEMBERED = /\{\{([A-Z][A-Z0-9_]*)\}\}/g;
|
|
586
|
+
REMEMBERED_NAME = /^[A-Z][A-Z0-9_]*$/;
|
|
587
|
+
SHORTEST_REMEMBERED = 3;
|
|
399
588
|
Secrets = class {
|
|
400
|
-
constructor(values) {
|
|
589
|
+
constructor(values, remembered = {}) {
|
|
401
590
|
this.values = values;
|
|
591
|
+
this.remembered = { ...remembered };
|
|
402
592
|
}
|
|
403
593
|
values;
|
|
404
594
|
/** Different on every run, so things a test creates never collide with an earlier run's. */
|
|
405
595
|
unique = Date.now().toString(36).slice(-6);
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
596
|
+
remembered;
|
|
597
|
+
/**
|
|
598
|
+
* The reverse: this run's unique value in text becomes {{unique}} again, and a remembered value
|
|
599
|
+
* its {{NAME}}, to be saved.
|
|
600
|
+
*/
|
|
601
|
+
tokenize(text, except) {
|
|
602
|
+
return Object.entries(this.remembered).filter(([name2, value]) => name2 !== except && value.length >= SHORTEST_REMEMBERED).sort(([, a], [, b]) => b.length - a.length).reduce(
|
|
603
|
+
(result, [name2, value]) => result.replaceAll(value, `{{${name2}}}`),
|
|
604
|
+
text.replaceAll(this.unique, UNIQUE)
|
|
605
|
+
);
|
|
409
606
|
}
|
|
410
|
-
/** Text as typed or checked on this run: {{unique}}
|
|
607
|
+
/** Text as typed or checked on this run: {{unique}} and remembered values become their values. */
|
|
411
608
|
expand(text) {
|
|
412
|
-
return text.replaceAll(UNIQUE, this.unique);
|
|
609
|
+
return text.replaceAll(UNIQUE, this.unique).replace(REMEMBERED, (placeholder, name2) => this.remembered[name2] ?? placeholder);
|
|
610
|
+
}
|
|
611
|
+
/** Keeps a value the test read off the page, for the tests after it in an ordered test run. */
|
|
612
|
+
remember(name2, value) {
|
|
613
|
+
if (!REMEMBERED_NAME.test(name2))
|
|
614
|
+
throw new Error(`Name it in capitals with underscores, such as ORDER_NUMBER, not ${name2}`);
|
|
615
|
+
if (name2 in this.values)
|
|
616
|
+
throw new Error(`${name2} is a saved value; remember it as another name`);
|
|
617
|
+
this.remembered[name2] = value;
|
|
618
|
+
}
|
|
619
|
+
/** The values this run remembered, with those it was given */
|
|
620
|
+
get rememberedValues() {
|
|
621
|
+
return { ...this.remembered };
|
|
622
|
+
}
|
|
623
|
+
/** The remembered values the steps use that nobody remembered, before the step that would */
|
|
624
|
+
missing(steps) {
|
|
625
|
+
const known = new Set(Object.keys(this.remembered));
|
|
626
|
+
const missing = /* @__PURE__ */ new Set();
|
|
627
|
+
for (const step of steps) {
|
|
628
|
+
for (const [, name2] of JSON.stringify(step).matchAll(REMEMBERED))
|
|
629
|
+
if (name2 && !known.has(name2)) missing.add(name2);
|
|
630
|
+
if ((step.action === "remember" || step.action === "rememberValue") && step.name)
|
|
631
|
+
known.add(step.name);
|
|
632
|
+
}
|
|
633
|
+
return [...missing];
|
|
413
634
|
}
|
|
414
635
|
/**
|
|
415
636
|
* A step as saved: wherever this run's unique value appears (a value typed, an element's name, a
|
|
416
637
|
* text checked, an address), it becomes {{unique}}, so a replay can put its own value back.
|
|
417
638
|
*/
|
|
418
639
|
tokenizeStep(step) {
|
|
419
|
-
|
|
640
|
+
const own2 = step.action === "remember";
|
|
641
|
+
const except = own2 ? step.name : void 0;
|
|
642
|
+
return JSON.parse(this.tokenize(JSON.stringify(step), except));
|
|
420
643
|
}
|
|
421
644
|
/** A saved step as this run uses it, with this run's unique value everywhere. */
|
|
422
645
|
expandStep(step) {
|
|
@@ -940,8 +1163,8 @@ function prefixIssues(path, issues) {
|
|
|
940
1163
|
return iss;
|
|
941
1164
|
});
|
|
942
1165
|
}
|
|
943
|
-
function unwrapMessage(
|
|
944
|
-
return typeof
|
|
1166
|
+
function unwrapMessage(message2) {
|
|
1167
|
+
return typeof message2 === "string" ? message2 : message2?.message;
|
|
945
1168
|
}
|
|
946
1169
|
function sizeCaps(defChecks) {
|
|
947
1170
|
const caps = [];
|
|
@@ -971,7 +1194,7 @@ function finalizeIssue(iss, ctx, config2) {
|
|
|
971
1194
|
iss.schema = iss.inst;
|
|
972
1195
|
}
|
|
973
1196
|
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
|
|
974
|
-
const
|
|
1197
|
+
const message2 = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(schemaError?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config2.customError?.(iss)) ?? unwrapMessage(config2.localeError?.(iss)) ?? "Invalid input";
|
|
975
1198
|
const full = {};
|
|
976
1199
|
for (const k of Object.keys(iss)) {
|
|
977
1200
|
if (k === "inst" || k === "schema" || k === "continue" || k === "input" || k === "__proto__")
|
|
@@ -979,7 +1202,7 @@ function finalizeIssue(iss, ctx, config2) {
|
|
|
979
1202
|
full[k] = iss[k];
|
|
980
1203
|
}
|
|
981
1204
|
full.path ?? (full.path = []);
|
|
982
|
-
full.message =
|
|
1205
|
+
full.message = message2;
|
|
983
1206
|
if (ctx?.reportInput) {
|
|
984
1207
|
full.input = iss.input;
|
|
985
1208
|
}
|
|
@@ -2578,9 +2801,9 @@ function parseURLObject(trimmed, def) {
|
|
|
2578
2801
|
function stripTabAndNewline(value) {
|
|
2579
2802
|
return value.replace(asciiTabOrNewline, "");
|
|
2580
2803
|
}
|
|
2581
|
-
function urlHostnameOk(url2,
|
|
2582
|
-
|
|
2583
|
-
return
|
|
2804
|
+
function urlHostnameOk(url2, hostname4) {
|
|
2805
|
+
hostname4.lastIndex = 0;
|
|
2806
|
+
return hostname4.test(url2.hostname);
|
|
2584
2807
|
}
|
|
2585
2808
|
function urlProtocolOk(url2, protocol) {
|
|
2586
2809
|
protocol.lastIndex = 0;
|
|
@@ -14896,8 +15119,8 @@ var init_compile = __esm({
|
|
|
14896
15119
|
INVALID = /* @__PURE__ */ Symbol.for("zod.compile.invalid");
|
|
14897
15120
|
FALLBACK_FLAG = /* @__PURE__ */ Symbol.for("zod.compile.fallback");
|
|
14898
15121
|
ZodCompileAsyncError = class extends Error {
|
|
14899
|
-
constructor(
|
|
14900
|
-
super(
|
|
15122
|
+
constructor(message2 = "z.compile does not support async refinements, transforms, or checks") {
|
|
15123
|
+
super(message2);
|
|
14901
15124
|
this.name = "ZodCompileAsyncError";
|
|
14902
15125
|
}
|
|
14903
15126
|
};
|
|
@@ -16049,12 +16272,12 @@ function initializeContext(params) {
|
|
|
16049
16272
|
external: params?.external ?? void 0
|
|
16050
16273
|
};
|
|
16051
16274
|
}
|
|
16052
|
-
function handleUnrepresentable(schema, ctx, json3, params,
|
|
16053
|
-
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message }) : ctx.unrepresentable;
|
|
16275
|
+
function handleUnrepresentable(schema, ctx, json3, params, message2) {
|
|
16276
|
+
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({ zodSchema: schema, path: params.path, message: message2 }) : ctx.unrepresentable;
|
|
16054
16277
|
if (result === "any")
|
|
16055
16278
|
return false;
|
|
16056
16279
|
if (result === void 0 || result === "throw")
|
|
16057
|
-
throw new Error(
|
|
16280
|
+
throw new Error(message2);
|
|
16058
16281
|
Object.assign(json3, result);
|
|
16059
16282
|
return true;
|
|
16060
16283
|
}
|
|
@@ -20910,19 +21133,19 @@ var init_inbox = __esm({
|
|
|
20910
21133
|
const found2 = await getJson(
|
|
20911
21134
|
new URL(`/api/v1/search?limit=5&query=${encodeURIComponent(query)}`, url2)
|
|
20912
21135
|
);
|
|
20913
|
-
const newest = found2.messages.find((
|
|
21136
|
+
const newest = found2.messages.find((message3) => new Date(message3.Created) >= since);
|
|
20914
21137
|
if (!newest) return null;
|
|
20915
|
-
const
|
|
21138
|
+
const message2 = await getJson(
|
|
20916
21139
|
new URL(`/api/v1/message/${newest.ID}`, url2)
|
|
20917
21140
|
);
|
|
20918
|
-
return email3(
|
|
21141
|
+
return email3(message2.Subject, message2.HTML, message2.Text);
|
|
20919
21142
|
};
|
|
20920
21143
|
mailcatcher = (url2) => async (to, subject, since) => {
|
|
20921
21144
|
const messages = await getJson(new URL("/messages", url2));
|
|
20922
21145
|
const newest = messages.filter(
|
|
20923
|
-
(
|
|
21146
|
+
(message2) => new Date(message2.created_at) >= since && matches(message2.subject, subject)
|
|
20924
21147
|
).filter(
|
|
20925
|
-
(
|
|
21148
|
+
(message2) => message2.recipients.some((each) => each.toLowerCase().includes(to.toLowerCase()))
|
|
20926
21149
|
).sort((a, b) => b.id - a.id)[0];
|
|
20927
21150
|
if (!newest) return null;
|
|
20928
21151
|
const html = await getText(new URL(`/messages/${newest.id}.html`, url2));
|
|
@@ -20952,11 +21175,11 @@ var init_inbox = __esm({
|
|
|
20952
21175
|
);
|
|
20953
21176
|
const newest = found2.items.filter((item) => new Date(item.Created) >= since).find((item) => matches(item.Content.Headers.Subject?.[0] ?? "", subject));
|
|
20954
21177
|
if (!newest) return null;
|
|
20955
|
-
const
|
|
21178
|
+
const message2 = { ...newest.Content, MIME: newest.MIME };
|
|
20956
21179
|
return email3(
|
|
20957
21180
|
newest.Content.Headers.Subject?.[0] ?? "",
|
|
20958
|
-
mailhogBody(mailhogPart(
|
|
20959
|
-
mailhogBody(mailhogPart(
|
|
21181
|
+
mailhogBody(mailhogPart(message2, "text/html")),
|
|
21182
|
+
mailhogBody(mailhogPart(message2, "text/plain"))
|
|
20960
21183
|
);
|
|
20961
21184
|
};
|
|
20962
21185
|
mailtrap = ({ accountId, inboxId, token }) => {
|
|
@@ -20970,8 +21193,8 @@ var init_inbox = __esm({
|
|
|
20970
21193
|
headers
|
|
20971
21194
|
);
|
|
20972
21195
|
const newest = messages.filter(
|
|
20973
|
-
(
|
|
20974
|
-
).find((
|
|
21196
|
+
(message2) => new Date(message2.created_at) >= since && matches(message2.subject, subject)
|
|
21197
|
+
).find((message2) => message2.to_email.toLowerCase().includes(to.toLowerCase()));
|
|
20975
21198
|
if (!newest) return null;
|
|
20976
21199
|
const html = await getText(new URL(`${base}/${newest.id}/body.html`), headers);
|
|
20977
21200
|
const text = await getText(new URL(`${base}/${newest.id}/body.txt`), headers);
|
|
@@ -21048,21 +21271,106 @@ var init_inbox = __esm({
|
|
|
21048
21271
|
}
|
|
21049
21272
|
});
|
|
21050
21273
|
|
|
21274
|
+
// src/browser/actionable.ts
|
|
21275
|
+
var whyNotActionable, isTimeout, explained;
|
|
21276
|
+
var init_actionable = __esm({
|
|
21277
|
+
"src/browser/actionable.ts"() {
|
|
21278
|
+
"use strict";
|
|
21279
|
+
whyNotActionable = async (target2) => {
|
|
21280
|
+
const quick = { timeout: 1e3 };
|
|
21281
|
+
const count = await target2.count().catch(() => 0);
|
|
21282
|
+
if (count === 0) return "nothing on the page matches it";
|
|
21283
|
+
const element = target2.first();
|
|
21284
|
+
if (!await element.isVisible().catch(() => false)) return "it is on the page but hidden";
|
|
21285
|
+
if (!await element.isEnabled(quick).catch(() => true)) return "it is disabled";
|
|
21286
|
+
const cover = await element.evaluate(
|
|
21287
|
+
(node2) => {
|
|
21288
|
+
const el = node2;
|
|
21289
|
+
const { document } = globalThis;
|
|
21290
|
+
const box = el.getBoundingClientRect();
|
|
21291
|
+
const hit = document.elementFromPoint(box.left + box.width / 2, box.top + box.height / 2);
|
|
21292
|
+
if (!hit || el === hit || el.contains(hit) || hit.contains(el)) return null;
|
|
21293
|
+
const label = (hit.getAttribute("aria-label") || hit.textContent || "").trim().slice(0, 40);
|
|
21294
|
+
return `${hit.tagName.toLowerCase()}${label ? ` "${label}"` : ""}`;
|
|
21295
|
+
},
|
|
21296
|
+
void 0,
|
|
21297
|
+
quick
|
|
21298
|
+
).catch(() => null);
|
|
21299
|
+
if (cover) return `it is covered by ${cover}`;
|
|
21300
|
+
return "the page kept changing, so it never stayed still long enough";
|
|
21301
|
+
};
|
|
21302
|
+
isTimeout = (error62) => error62 instanceof Error && error62.name === "TimeoutError";
|
|
21303
|
+
explained = async (target2, act) => {
|
|
21304
|
+
try {
|
|
21305
|
+
return await act(target2);
|
|
21306
|
+
} catch (error62) {
|
|
21307
|
+
if (!isTimeout(error62)) throw error62;
|
|
21308
|
+
const reason = await whyNotActionable(target2);
|
|
21309
|
+
throw new Error(`${error62.message.split("\n")[0]} (${reason})`);
|
|
21310
|
+
}
|
|
21311
|
+
};
|
|
21312
|
+
}
|
|
21313
|
+
});
|
|
21314
|
+
|
|
21051
21315
|
// src/browser/checks.ts
|
|
21052
|
-
var describeScope, textVisible, textAbsent, waitWhileBusy, waitForQuiet, scopeExists, elementVisible, isChecked, fieldInvalid, currentPath;
|
|
21316
|
+
var CHECK_TIMEOUT, ANNOUNCING_ROLES, describeScope, textVisible, textAbsent, textCount, mediaIs, waitWhileBusy, waitForQuiet, scopeExists, elementVisible, hasValue, isChecked, fieldInvalid, currentPath;
|
|
21053
21317
|
var init_checks3 = __esm({
|
|
21054
21318
|
"src/browser/checks.ts"() {
|
|
21055
21319
|
"use strict";
|
|
21056
21320
|
init_announcements();
|
|
21321
|
+
CHECK_TIMEOUT = 1e4;
|
|
21322
|
+
ANNOUNCING_ROLES = /* @__PURE__ */ new Set(["alert", "status"]);
|
|
21057
21323
|
describeScope = (within) => within ? ` in the ${within.role} containing "${within.containing}"` : "";
|
|
21058
|
-
textVisible = async (page, text, within, exact = false) => {
|
|
21324
|
+
textVisible = async (page, text, within, exact = false, timeout = CHECK_TIMEOUT) => {
|
|
21325
|
+
const containers = within ? page.getByRole(within.role).filter({ hasText: within.containing }) : page.locator("body");
|
|
21326
|
+
const shown = await containers.getByText(text, { exact }).first().waitFor({ timeout }).then(() => true).catch(() => false);
|
|
21327
|
+
if (shown) return true;
|
|
21328
|
+
if (within && !ANNOUNCING_ROLES.has(within.role)) return false;
|
|
21329
|
+
const announced = await announcedSinceStep(page);
|
|
21330
|
+
const candidates = within ? announced.filter((said) => announces([said], within.containing)) : announced;
|
|
21331
|
+
return announces(candidates, text, exact);
|
|
21332
|
+
};
|
|
21333
|
+
textAbsent = (page, text, within, exact = false, timeout = CHECK_TIMEOUT) => {
|
|
21059
21334
|
const containers = within ? page.getByRole(within.role).filter({ hasText: within.containing }) : page.locator("body");
|
|
21060
|
-
|
|
21061
|
-
return shown || !within && announces(await announcedSinceStep(page), text, exact);
|
|
21335
|
+
return containers.getByText(text, { exact }).first().waitFor({ state: "hidden", timeout }).then(() => true).catch(() => false);
|
|
21062
21336
|
};
|
|
21063
|
-
|
|
21337
|
+
textCount = async (page, text, count, within, exact = false) => {
|
|
21064
21338
|
const containers = within ? page.getByRole(within.role).filter({ hasText: within.containing }) : page.locator("body");
|
|
21065
|
-
|
|
21339
|
+
const matches2 = containers.getByText(text, { exact });
|
|
21340
|
+
const deadline = Date.now() + CHECK_TIMEOUT;
|
|
21341
|
+
do {
|
|
21342
|
+
if (await matches2.count().catch(() => -1) === count) return true;
|
|
21343
|
+
await page.waitForTimeout(250);
|
|
21344
|
+
} while (Date.now() < deadline);
|
|
21345
|
+
return false;
|
|
21346
|
+
};
|
|
21347
|
+
mediaIs = async (page, selector, state) => {
|
|
21348
|
+
const read = () => page.locator(selector).first().evaluate(
|
|
21349
|
+
(node2) => {
|
|
21350
|
+
const el = node2;
|
|
21351
|
+
const media = el.matches("audio, video") ? el : el.querySelector("audio, video");
|
|
21352
|
+
return media && {
|
|
21353
|
+
paused: media.paused || media.ended,
|
|
21354
|
+
muted: media.muted || media.volume === 0,
|
|
21355
|
+
time: media.currentTime
|
|
21356
|
+
};
|
|
21357
|
+
},
|
|
21358
|
+
void 0,
|
|
21359
|
+
{ timeout: 2e3 }
|
|
21360
|
+
).catch(() => null);
|
|
21361
|
+
const deadline = Date.now() + CHECK_TIMEOUT;
|
|
21362
|
+
do {
|
|
21363
|
+
const first = await read();
|
|
21364
|
+
if (first && state === "muted" && first.muted) return true;
|
|
21365
|
+
if (first && state === "paused" && first.paused) return true;
|
|
21366
|
+
if (first && state === "playing" && !first.paused) {
|
|
21367
|
+
await page.waitForTimeout(500);
|
|
21368
|
+
const later = await read();
|
|
21369
|
+
if (later && !later.paused && later.time > first.time) return true;
|
|
21370
|
+
}
|
|
21371
|
+
await page.waitForTimeout(250);
|
|
21372
|
+
} while (Date.now() < deadline);
|
|
21373
|
+
return false;
|
|
21066
21374
|
};
|
|
21067
21375
|
waitWhileBusy = (page, timeout = 6e4) => page.waitForFunction(`!document.querySelector('[aria-busy="true"]')`, void 0, { timeout }).then(() => void 0).catch(() => void 0);
|
|
21068
21376
|
waitForQuiet = (page, quietMs = 150, limitMs = 2e3) => page.evaluate(
|
|
@@ -21076,9 +21384,19 @@ var init_checks3 = __esm({
|
|
|
21076
21384
|
})`
|
|
21077
21385
|
).then(() => void 0).catch(() => void 0);
|
|
21078
21386
|
scopeExists = async (page, within) => await page.getByRole(within.role).filter({ hasText: within.containing }).count() > 0;
|
|
21079
|
-
elementVisible = (page, selector) => page.locator(selector).first().waitFor({ timeout:
|
|
21080
|
-
|
|
21081
|
-
const
|
|
21387
|
+
elementVisible = (page, selector) => page.locator(selector).first().waitFor({ timeout: CHECK_TIMEOUT }).then(() => true).catch(() => false);
|
|
21388
|
+
hasValue = async (page, selector, value) => {
|
|
21389
|
+
const wanted = value.trim().toLowerCase();
|
|
21390
|
+
const deadline = Date.now() + CHECK_TIMEOUT;
|
|
21391
|
+
do {
|
|
21392
|
+
const actual = await page.locator(selector).first().inputValue({ timeout: 1e3 }).catch(() => void 0);
|
|
21393
|
+
if (actual?.trim().toLowerCase() === wanted) return true;
|
|
21394
|
+
await page.waitForTimeout(200);
|
|
21395
|
+
} while (Date.now() < deadline);
|
|
21396
|
+
return false;
|
|
21397
|
+
};
|
|
21398
|
+
isChecked = (page, selector, checked) => page.locator(selector).first().waitFor({ timeout: CHECK_TIMEOUT }).then(async () => {
|
|
21399
|
+
const deadline = Date.now() + CHECK_TIMEOUT;
|
|
21082
21400
|
do {
|
|
21083
21401
|
if (await page.locator(selector).first().isChecked() === checked) return true;
|
|
21084
21402
|
await page.waitForTimeout(200);
|
|
@@ -21088,9 +21406,12 @@ var init_checks3 = __esm({
|
|
|
21088
21406
|
fieldInvalid = (page, selector) => page.locator(selector).first().evaluate(
|
|
21089
21407
|
(field) => field.matches(":invalid") || field.getAttribute("aria-invalid") === "true",
|
|
21090
21408
|
void 0,
|
|
21091
|
-
{ timeout:
|
|
21409
|
+
{ timeout: CHECK_TIMEOUT }
|
|
21092
21410
|
).catch(() => false);
|
|
21093
|
-
currentPath = (page) =>
|
|
21411
|
+
currentPath = (page) => {
|
|
21412
|
+
const url2 = new URL(page.url());
|
|
21413
|
+
return url2.search ? `${url2.pathname}${url2.search}` : url2.pathname;
|
|
21414
|
+
};
|
|
21094
21415
|
}
|
|
21095
21416
|
});
|
|
21096
21417
|
|
|
@@ -21139,13 +21460,13 @@ var init_findings = __esm({
|
|
|
21139
21460
|
/hot[- ]update|\bhmr\b|webpack-dev-server|__webpack_hmr/i,
|
|
21140
21461
|
/websocket/i
|
|
21141
21462
|
];
|
|
21142
|
-
isToolingNoise = (
|
|
21463
|
+
isToolingNoise = (message2) => toolingNoise.some((pattern) => pattern.test(message2));
|
|
21143
21464
|
watchPage = (page) => {
|
|
21144
21465
|
const findings = [];
|
|
21145
|
-
const add = (kind,
|
|
21146
|
-
page.on("console", (
|
|
21147
|
-
if (
|
|
21148
|
-
add("console",
|
|
21466
|
+
const add = (kind, message2) => findings.push({ kind, message: message2, page: page.url() });
|
|
21467
|
+
page.on("console", (message2) => {
|
|
21468
|
+
if (message2.type() === "error" && !message2.text().startsWith("Failed to load resource") && !isToolingNoise(message2.text())) {
|
|
21469
|
+
add("console", message2.text());
|
|
21149
21470
|
}
|
|
21150
21471
|
});
|
|
21151
21472
|
page.on("pageerror", (error62) => {
|
|
@@ -21164,7 +21485,7 @@ var init_findings = __esm({
|
|
|
21164
21485
|
});
|
|
21165
21486
|
return findings;
|
|
21166
21487
|
};
|
|
21167
|
-
describeFindings = (findings) => findings.map(({ kind, message }) => `- ${kind}: ${
|
|
21488
|
+
describeFindings = (findings) => findings.map(({ kind, message: message2 }) => `- ${kind}: ${message2}`).join("\n");
|
|
21168
21489
|
}
|
|
21169
21490
|
});
|
|
21170
21491
|
|
|
@@ -21311,6 +21632,25 @@ ${xref}
|
|
|
21311
21632
|
}
|
|
21312
21633
|
});
|
|
21313
21634
|
|
|
21635
|
+
// src/browser/read-value.ts
|
|
21636
|
+
var readValue;
|
|
21637
|
+
var init_read_value = __esm({
|
|
21638
|
+
"src/browser/read-value.ts"() {
|
|
21639
|
+
"use strict";
|
|
21640
|
+
readValue = async (locator) => {
|
|
21641
|
+
const { tag, type } = await locator.evaluate((element) => ({
|
|
21642
|
+
tag: element.tagName,
|
|
21643
|
+
type: element.getAttribute("type")
|
|
21644
|
+
}));
|
|
21645
|
+
if (type === "password") throw new Error("Qadet does not read password fields");
|
|
21646
|
+
const value = ["INPUT", "TEXTAREA", "SELECT"].includes(tag) ? await locator.inputValue() : await locator.innerText();
|
|
21647
|
+
const trimmed = value.trim();
|
|
21648
|
+
if (!trimmed) throw new Error("The element has no text to remember");
|
|
21649
|
+
return trimmed;
|
|
21650
|
+
};
|
|
21651
|
+
}
|
|
21652
|
+
});
|
|
21653
|
+
|
|
21314
21654
|
// src/browser/volatile.ts
|
|
21315
21655
|
var patterns, volatileReason, oneTimeParams, oneTimeAddress, idSegment, recordAddress, pathPattern, pathMatches;
|
|
21316
21656
|
var init_volatile = __esm({
|
|
@@ -21360,23 +21700,43 @@ var init_volatile = __esm({
|
|
|
21360
21700
|
return false;
|
|
21361
21701
|
}
|
|
21362
21702
|
};
|
|
21363
|
-
pathPattern = (path) =>
|
|
21364
|
-
|
|
21365
|
-
const
|
|
21366
|
-
|
|
21367
|
-
|
|
21703
|
+
pathPattern = (path) => {
|
|
21704
|
+
const [pathname = "", search] = path.split("?");
|
|
21705
|
+
const patterned = pathname.split("/").map((segment) => idSegment.test(segment) ? "*" : segment).join("/");
|
|
21706
|
+
return search ? `${patterned}?${search}` : patterned;
|
|
21707
|
+
};
|
|
21708
|
+
pathMatches = (pattern, pathOrUrl) => {
|
|
21709
|
+
const [patternPath = "", patternSearch] = pattern.split("?");
|
|
21710
|
+
const [actualPath = "", actualSearch] = pathOrUrl.split("?");
|
|
21711
|
+
const wanted = patternPath.split("/").filter(Boolean);
|
|
21712
|
+
const actual = actualPath.split("/").filter(Boolean);
|
|
21713
|
+
if (wanted.length === 0 ? actual.length !== 0 : wanted.length > actual.length) return false;
|
|
21714
|
+
const offset = actual.length - wanted.length;
|
|
21715
|
+
const pathOk = wanted.every(
|
|
21716
|
+
(segment, index) => segment === "*" || segment === actual[offset + index]
|
|
21717
|
+
);
|
|
21718
|
+
if (!pathOk) return false;
|
|
21719
|
+
if (!patternSearch) return true;
|
|
21720
|
+
const wantedParams = new URLSearchParams(patternSearch);
|
|
21721
|
+
const actualParams = new URLSearchParams(actualSearch || "");
|
|
21722
|
+
for (const [key, val] of wantedParams.entries()) {
|
|
21723
|
+
if (actualParams.get(key) !== val) return false;
|
|
21724
|
+
}
|
|
21725
|
+
return true;
|
|
21368
21726
|
};
|
|
21369
21727
|
}
|
|
21370
21728
|
});
|
|
21371
21729
|
|
|
21372
21730
|
// src/core/test-file.ts
|
|
21373
21731
|
import { mkdir as mkdir3, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
21374
|
-
var target, scopeRoles, scope, actionSchema, stepSchema, isCheck, testFileSchema, testsDir, testPath, loadTest, saveTest;
|
|
21732
|
+
var target, MAX_WAIT_SECONDS, mediaStates, scopeRoles, scope, pointSchema, pointsListSchema, actionSchema, stepSchema, isCheck, testFileSchema, testsDir, testPath, loadTest, saveTest;
|
|
21375
21733
|
var init_test_file = __esm({
|
|
21376
21734
|
"src/core/test-file.ts"() {
|
|
21377
21735
|
"use strict";
|
|
21378
21736
|
init_zod();
|
|
21379
21737
|
target = external_exports.object({ selector: external_exports.string(), code: external_exports.string() });
|
|
21738
|
+
MAX_WAIT_SECONDS = 120;
|
|
21739
|
+
mediaStates = ["playing", "paused", "muted"];
|
|
21380
21740
|
scopeRoles = [
|
|
21381
21741
|
"row",
|
|
21382
21742
|
"cell",
|
|
@@ -21397,8 +21757,36 @@ var init_test_file = __esm({
|
|
|
21397
21757
|
"complementary"
|
|
21398
21758
|
];
|
|
21399
21759
|
scope = external_exports.object({ role: external_exports.enum(scopeRoles), containing: external_exports.string() });
|
|
21760
|
+
pointSchema = external_exports.object({
|
|
21761
|
+
x: external_exports.coerce.number(),
|
|
21762
|
+
y: external_exports.coerce.number()
|
|
21763
|
+
});
|
|
21764
|
+
pointsListSchema = external_exports.preprocess((val) => {
|
|
21765
|
+
if (Array.isArray(val)) return val;
|
|
21766
|
+
if (val && typeof val === "object") {
|
|
21767
|
+
return Object.keys(val).sort((a, b) => Number(a) - Number(b)).map((k) => val[k]);
|
|
21768
|
+
}
|
|
21769
|
+
return val;
|
|
21770
|
+
}, external_exports.array(pointSchema).min(2));
|
|
21400
21771
|
actionSchema = external_exports.discriminatedUnion("action", [
|
|
21401
21772
|
external_exports.object({ action: external_exports.literal("click"), intent: external_exports.string(), target }),
|
|
21773
|
+
external_exports.object({ action: external_exports.literal("double_click"), intent: external_exports.string(), target }),
|
|
21774
|
+
external_exports.object({ action: external_exports.literal("hover"), intent: external_exports.string(), target }),
|
|
21775
|
+
external_exports.object({ action: external_exports.literal("drag"), intent: external_exports.string(), from: target, to: target }),
|
|
21776
|
+
external_exports.object({
|
|
21777
|
+
action: external_exports.literal("draw"),
|
|
21778
|
+
intent: external_exports.string(),
|
|
21779
|
+
target,
|
|
21780
|
+
points: pointsListSchema
|
|
21781
|
+
}),
|
|
21782
|
+
external_exports.object({ action: external_exports.literal("remember"), intent: external_exports.string(), target, name: external_exports.string() }),
|
|
21783
|
+
// Remembers a value as written, such as {{unique}}, for the tests after a split test's first part.
|
|
21784
|
+
external_exports.object({
|
|
21785
|
+
action: external_exports.literal("rememberValue"),
|
|
21786
|
+
intent: external_exports.string(),
|
|
21787
|
+
name: external_exports.string(),
|
|
21788
|
+
value: external_exports.string()
|
|
21789
|
+
}),
|
|
21402
21790
|
external_exports.object({ action: external_exports.literal("fill"), intent: external_exports.string(), target, value: external_exports.string() }),
|
|
21403
21791
|
external_exports.object({ action: external_exports.literal("fillSecret"), intent: external_exports.string(), target, secret: external_exports.string() }),
|
|
21404
21792
|
external_exports.object({
|
|
@@ -21429,7 +21817,9 @@ var init_test_file = __esm({
|
|
|
21429
21817
|
intent: external_exports.string(),
|
|
21430
21818
|
text: external_exports.string(),
|
|
21431
21819
|
within: scope.optional(),
|
|
21432
|
-
exact: external_exports.boolean().optional()
|
|
21820
|
+
exact: external_exports.boolean().optional(),
|
|
21821
|
+
// Seconds to wait for a slow result, such as a background job finishing; 10 when left out.
|
|
21822
|
+
wait: external_exports.number().int().positive().max(MAX_WAIT_SECONDS).optional()
|
|
21433
21823
|
}),
|
|
21434
21824
|
// Text that must not be there, such as a removed item or a button a role may not use.
|
|
21435
21825
|
external_exports.object({
|
|
@@ -21437,7 +21827,24 @@ var init_test_file = __esm({
|
|
|
21437
21827
|
intent: external_exports.string(),
|
|
21438
21828
|
text: external_exports.string(),
|
|
21439
21829
|
within: scope.optional(),
|
|
21440
|
-
exact: external_exports.boolean().optional()
|
|
21830
|
+
exact: external_exports.boolean().optional(),
|
|
21831
|
+
wait: external_exports.number().int().positive().max(MAX_WAIT_SECONDS).optional()
|
|
21832
|
+
}),
|
|
21833
|
+
// How many times text shows, such as three rows holding the item the test added.
|
|
21834
|
+
external_exports.object({
|
|
21835
|
+
action: external_exports.literal("expectCount"),
|
|
21836
|
+
intent: external_exports.string(),
|
|
21837
|
+
text: external_exports.string(),
|
|
21838
|
+
within: scope.optional(),
|
|
21839
|
+
exact: external_exports.boolean().optional(),
|
|
21840
|
+
count: external_exports.number().int().nonnegative()
|
|
21841
|
+
}),
|
|
21842
|
+
// An audio or video element that must be playing, paused or muted.
|
|
21843
|
+
external_exports.object({
|
|
21844
|
+
action: external_exports.literal("expectMedia"),
|
|
21845
|
+
intent: external_exports.string(),
|
|
21846
|
+
target,
|
|
21847
|
+
state: external_exports.enum(mediaStates)
|
|
21441
21848
|
}),
|
|
21442
21849
|
external_exports.object({ action: external_exports.literal("expectPath"), intent: external_exports.string(), path: external_exports.string() }),
|
|
21443
21850
|
external_exports.object({ action: external_exports.literal("expectVisible"), intent: external_exports.string(), target }),
|
|
@@ -21449,6 +21856,9 @@ var init_test_file = __esm({
|
|
|
21449
21856
|
target,
|
|
21450
21857
|
checked: external_exports.boolean()
|
|
21451
21858
|
}),
|
|
21859
|
+
// A form field that must hold a value, such as the email the test typed. Text checks can't see
|
|
21860
|
+
// what is inside an input.
|
|
21861
|
+
external_exports.object({ action: external_exports.literal("expectValue"), intent: external_exports.string(), target, value: external_exports.string() }),
|
|
21452
21862
|
// Downloads the file a link or button gives, such as a PDF report, and checks its text.
|
|
21453
21863
|
external_exports.object({ action: external_exports.literal("expectDownload"), intent: external_exports.string(), target, text: external_exports.string() }),
|
|
21454
21864
|
// Opens a link from an email, found afresh on every run, since links such as reset tokens change.
|
|
@@ -21510,7 +21920,7 @@ var init_channel = __esm({
|
|
|
21510
21920
|
pending = /* @__PURE__ */ new Map();
|
|
21511
21921
|
next = 0;
|
|
21512
21922
|
closed;
|
|
21513
|
-
request(
|
|
21923
|
+
request(message2, timeoutMs = 6e4) {
|
|
21514
21924
|
if (this.closed) return Promise.reject(this.closed);
|
|
21515
21925
|
const id2 = String(++this.next);
|
|
21516
21926
|
return new Promise((resolve4, reject) => {
|
|
@@ -21519,11 +21929,11 @@ var init_channel = __esm({
|
|
|
21519
21929
|
reject(new Error(`No answer within ${timeoutMs / 1e3} s`));
|
|
21520
21930
|
}, timeoutMs);
|
|
21521
21931
|
this.pending.set(id2, { resolve: resolve4, reject, timer });
|
|
21522
|
-
this.send({ ...
|
|
21932
|
+
this.send({ ...message2, id: id2 });
|
|
21523
21933
|
});
|
|
21524
21934
|
}
|
|
21525
|
-
send(
|
|
21526
|
-
if (!this.closed) this.socket.send(JSON.stringify(
|
|
21935
|
+
send(message2) {
|
|
21936
|
+
if (!this.closed) this.socket.send(JSON.stringify(message2));
|
|
21527
21937
|
}
|
|
21528
21938
|
async receive(text) {
|
|
21529
21939
|
const parsed = (() => {
|
|
@@ -21538,22 +21948,22 @@ var init_channel = __esm({
|
|
|
21538
21948
|
this.socket.close(1008, "Unreadable message");
|
|
21539
21949
|
return;
|
|
21540
21950
|
}
|
|
21541
|
-
const
|
|
21542
|
-
if (
|
|
21543
|
-
const waiting =
|
|
21951
|
+
const message2 = parsed.data;
|
|
21952
|
+
if (message2.type === "reply" || message2.type === "error") {
|
|
21953
|
+
const waiting = message2.id === void 0 ? void 0 : this.pending.get(message2.id);
|
|
21544
21954
|
if (!waiting) return;
|
|
21545
|
-
this.pending.delete(
|
|
21955
|
+
this.pending.delete(message2.id);
|
|
21546
21956
|
clearTimeout(waiting.timer);
|
|
21547
|
-
if (
|
|
21548
|
-
else waiting.reject(new Error(
|
|
21957
|
+
if (message2.type === "reply") waiting.resolve(message2.value);
|
|
21958
|
+
else waiting.reject(new Error(message2.message));
|
|
21549
21959
|
return;
|
|
21550
21960
|
}
|
|
21551
21961
|
try {
|
|
21552
|
-
const value = await this.handle(
|
|
21553
|
-
if (
|
|
21962
|
+
const value = await this.handle(message2);
|
|
21963
|
+
if (message2.id !== void 0) this.send({ type: "reply", id: message2.id, value });
|
|
21554
21964
|
} catch (error62) {
|
|
21555
|
-
if (
|
|
21556
|
-
this.send({ type: "error", id:
|
|
21965
|
+
if (message2.id !== void 0)
|
|
21966
|
+
this.send({ type: "error", id: message2.id, message: firstLine(error62) });
|
|
21557
21967
|
}
|
|
21558
21968
|
}
|
|
21559
21969
|
/** Ends every request still waiting, such as when the connection drops. */
|
|
@@ -21577,15 +21987,15 @@ var init_protocol = __esm({
|
|
|
21577
21987
|
"use strict";
|
|
21578
21988
|
init_zod();
|
|
21579
21989
|
init_test_file();
|
|
21580
|
-
AGENT_PROTOCOL =
|
|
21990
|
+
AGENT_PROTOCOL = 2;
|
|
21581
21991
|
runnerTools = [
|
|
21582
21992
|
"click",
|
|
21993
|
+
"drag",
|
|
21994
|
+
"draw",
|
|
21583
21995
|
"drop_attempt",
|
|
21584
21996
|
"expect_checked",
|
|
21585
|
-
"expect_download_contains",
|
|
21586
21997
|
"expect_element",
|
|
21587
21998
|
"expect_field_error",
|
|
21588
|
-
"expect_no_text",
|
|
21589
21999
|
"expect_path",
|
|
21590
22000
|
"expect_text",
|
|
21591
22001
|
"fill",
|
|
@@ -21594,13 +22004,14 @@ var init_protocol = __esm({
|
|
|
21594
22004
|
"finish",
|
|
21595
22005
|
"finish_cleanup",
|
|
21596
22006
|
"follow_email_link",
|
|
22007
|
+
"hover",
|
|
21597
22008
|
"navigate",
|
|
21598
22009
|
"note_created",
|
|
21599
22010
|
"press",
|
|
21600
22011
|
"read_download",
|
|
21601
22012
|
"read_email",
|
|
22013
|
+
"remember_value",
|
|
21602
22014
|
"select",
|
|
21603
|
-
"upload_csv",
|
|
21604
22015
|
"upload_file"
|
|
21605
22016
|
];
|
|
21606
22017
|
agentJobs = ["explore", "repair", "checkUpdate"];
|
|
@@ -21723,7 +22134,11 @@ ${await session.view(maxViewChars)}`;
|
|
|
21723
22134
|
if (alreadyChecked(session.steps, step))
|
|
21724
22135
|
return "That did not work: this check was already made, and nothing has happened since. Check something else, or finish.";
|
|
21725
22136
|
const status3 = passed ? "passed" : "failed";
|
|
21726
|
-
const position = await session.record(
|
|
22137
|
+
const position = await session.record(
|
|
22138
|
+
step,
|
|
22139
|
+
status3,
|
|
22140
|
+
passed ? void 0 : `Not found: ${step.intent}`
|
|
22141
|
+
);
|
|
21727
22142
|
session.checks.push({ intent: step.intent, passed, position });
|
|
21728
22143
|
return `Check ${status3} (step ${position}).
|
|
21729
22144
|
${await session.view()}`;
|
|
@@ -21732,7 +22147,7 @@ ${await session.view()}`;
|
|
|
21732
22147
|
});
|
|
21733
22148
|
|
|
21734
22149
|
// src/web/agent.ts
|
|
21735
|
-
var
|
|
22150
|
+
var unreachable2, connect, exploreWithAgent, adviserFor;
|
|
21736
22151
|
var init_agent = __esm({
|
|
21737
22152
|
"src/web/agent.ts"() {
|
|
21738
22153
|
"use strict";
|
|
@@ -21740,7 +22155,7 @@ var init_agent = __esm({
|
|
|
21740
22155
|
init_errors();
|
|
21741
22156
|
init_protocol();
|
|
21742
22157
|
init_define();
|
|
21743
|
-
|
|
22158
|
+
unreachable2 = (url2) => `Qadet's agent service isn't reachable at ${url2}`;
|
|
21744
22159
|
connect = (access, runId, job, handle) => {
|
|
21745
22160
|
const url2 = new URL("run", access.url.endsWith("/") ? access.url : `${access.url}/`);
|
|
21746
22161
|
const socket = new WebSocket(url2);
|
|
@@ -21754,7 +22169,7 @@ var init_agent = __esm({
|
|
|
21754
22169
|
channel.send({ type: "start", protocol: AGENT_PROTOCOL, runId, token: access.token, job });
|
|
21755
22170
|
resolve4();
|
|
21756
22171
|
});
|
|
21757
|
-
socket.addEventListener("error", () => reject(new Error(
|
|
22172
|
+
socket.addEventListener("error", () => reject(new Error(unreachable2(access.url))));
|
|
21758
22173
|
});
|
|
21759
22174
|
socket.addEventListener("message", (event) => void channel.receive(String(event.data)));
|
|
21760
22175
|
const closed = new Promise(
|
|
@@ -21791,10 +22206,10 @@ var init_agent = __esm({
|
|
|
21791
22206
|
throw new Error(redact(firstLine(error62)));
|
|
21792
22207
|
}
|
|
21793
22208
|
};
|
|
21794
|
-
const { opened, closed } = connect(access, runId, "explore", async (
|
|
21795
|
-
switch (
|
|
22209
|
+
const { opened, closed } = connect(access, runId, "explore", async (message2) => {
|
|
22210
|
+
switch (message2.type) {
|
|
21796
22211
|
case "tool":
|
|
21797
|
-
return runTool(
|
|
22212
|
+
return runTool(message2.tool, message2.args);
|
|
21798
22213
|
case "view":
|
|
21799
22214
|
return browser.view();
|
|
21800
22215
|
case "state":
|
|
@@ -21802,12 +22217,12 @@ var init_agent = __esm({
|
|
|
21802
22217
|
case "cleanup":
|
|
21803
22218
|
return browser.startCleanup();
|
|
21804
22219
|
case "done": {
|
|
21805
|
-
const { type: _, ...done } =
|
|
22220
|
+
const { type: _, ...done } = message2;
|
|
21806
22221
|
outcome = done;
|
|
21807
22222
|
return;
|
|
21808
22223
|
}
|
|
21809
22224
|
case "failed":
|
|
21810
|
-
outcome = failed(
|
|
22225
|
+
outcome = failed(message2.message);
|
|
21811
22226
|
return;
|
|
21812
22227
|
}
|
|
21813
22228
|
});
|
|
@@ -21821,8 +22236,8 @@ var init_agent = __esm({
|
|
|
21821
22236
|
};
|
|
21822
22237
|
adviserFor = async (access, runId, job) => {
|
|
21823
22238
|
let failure2;
|
|
21824
|
-
const { channel, opened, close } = connect(access, runId, job, (
|
|
21825
|
-
if (
|
|
22239
|
+
const { channel, opened, close } = connect(access, runId, job, (message2) => {
|
|
22240
|
+
if (message2.type === "failed") failure2 = message2.message;
|
|
21826
22241
|
});
|
|
21827
22242
|
await opened;
|
|
21828
22243
|
return {
|
|
@@ -21941,6 +22356,7 @@ var init_check_update = __esm({
|
|
|
21941
22356
|
case "expectVisible":
|
|
21942
22357
|
case "expectInvalid":
|
|
21943
22358
|
case "expectChecked":
|
|
22359
|
+
case "expectValue":
|
|
21944
22360
|
return target2 && { ...step, ...reworded, target: target2 };
|
|
21945
22361
|
default:
|
|
21946
22362
|
return void 0;
|
|
@@ -21962,6 +22378,12 @@ var init_check_update = __esm({
|
|
|
21962
22378
|
return `${step.target.code} is refused as invalid`;
|
|
21963
22379
|
case "expectChecked":
|
|
21964
22380
|
return `${step.target.code} is ${step.checked ? "on" : "off"}`;
|
|
22381
|
+
case "expectValue":
|
|
22382
|
+
return `${step.target.code} holds "${step.value}"`;
|
|
22383
|
+
case "expectCount":
|
|
22384
|
+
return `"${step.text}" shows ${step.count} times${step.within ? ` in the ${step.within.role} containing "${step.within.containing}"` : ""}`;
|
|
22385
|
+
case "expectMedia":
|
|
22386
|
+
return `${step.target.code} is ${step.state}`;
|
|
21965
22387
|
case "expectDownload":
|
|
21966
22388
|
return `the file from ${step.target.code} contains "${step.text}"`;
|
|
21967
22389
|
default:
|
|
@@ -22011,29 +22433,38 @@ var init_risk = __esm({
|
|
|
22011
22433
|
});
|
|
22012
22434
|
|
|
22013
22435
|
// src/replay/sessions.ts
|
|
22014
|
-
var KEEP_MS, signingIn, signInLength, sessionKey, Sessions, sessions, resume;
|
|
22436
|
+
var KEEP_MS, signingIn, submitting, submits, signInLength, signOut, signsOut, sessionKey, Sessions, sessions, resume;
|
|
22015
22437
|
var init_sessions = __esm({
|
|
22016
22438
|
"src/replay/sessions.ts"() {
|
|
22017
22439
|
"use strict";
|
|
22018
22440
|
KEEP_MS = 30 * 60 * 1e3;
|
|
22019
22441
|
signingIn = /* @__PURE__ */ new Set(["navigate", "fill", "fillSecret", "click", "press"]);
|
|
22442
|
+
submitting = /\b(log\s*-?\s*in|sign\s*-?\s*in|submit|continue|next|enter)\b/i;
|
|
22443
|
+
submits = (step) => step.action === "press" || step.action === "click" && (submitting.test(step.intent) || submitting.test(step.target.code));
|
|
22020
22444
|
signInLength = (steps) => {
|
|
22021
|
-
|
|
22022
|
-
|
|
22023
|
-
|
|
22024
|
-
|
|
22025
|
-
|
|
22026
|
-
|
|
22027
|
-
|
|
22028
|
-
|
|
22029
|
-
|
|
22030
|
-
return 0;
|
|
22031
|
-
|
|
22445
|
+
const secret = steps.findIndex((step) => step.action === "fillSecret");
|
|
22446
|
+
if (secret === -1) return 0;
|
|
22447
|
+
const prefix = steps.slice(0, secret + 1);
|
|
22448
|
+
if (prefix.some((step) => !signingIn.has(step.action) || step.cleanup)) return 0;
|
|
22449
|
+
const after = steps.slice(secret + 1);
|
|
22450
|
+
const leading = after.findIndex((step) => step.action !== "click" && step.action !== "press");
|
|
22451
|
+
const candidates = leading === -1 ? after : after.slice(0, leading);
|
|
22452
|
+
const submit = candidates.findIndex(submits);
|
|
22453
|
+
const at = submit === -1 ? candidates.length ? 0 : -1 : submit;
|
|
22454
|
+
if (at === -1) return 0;
|
|
22455
|
+
const length = secret + 1 + at + 1;
|
|
22456
|
+
return steps.slice(length).some((next) => !next.action.startsWith("expect")) ? length : 0;
|
|
22457
|
+
};
|
|
22458
|
+
signOut = /\b(sign|log)\s*-?\s*out\b/i;
|
|
22459
|
+
signsOut = (steps) => steps.some(
|
|
22460
|
+
(step) => step.action === "click" && (signOut.test(step.intent) || signOut.test(step.target.code))
|
|
22461
|
+
);
|
|
22032
22462
|
sessionKey = (startUrl, signIn) => {
|
|
22463
|
+
const opened = signIn.findLast((step) => step.action === "navigate");
|
|
22033
22464
|
const typed = signIn.flatMap(
|
|
22034
22465
|
(step) => step.action === "fill" ? [step.value] : step.action === "fillSecret" ? [`secret:${step.secret}`] : []
|
|
22035
22466
|
);
|
|
22036
|
-
return JSON.stringify([new URL(startUrl).origin, ...typed]);
|
|
22467
|
+
return JSON.stringify([new URL(opened?.url ?? startUrl).origin, ...typed]);
|
|
22037
22468
|
};
|
|
22038
22469
|
Sessions = class {
|
|
22039
22470
|
constructor(now = () => Date.now()) {
|
|
@@ -22041,24 +22472,39 @@ var init_sessions = __esm({
|
|
|
22041
22472
|
}
|
|
22042
22473
|
now;
|
|
22043
22474
|
saved = /* @__PURE__ */ new Map();
|
|
22475
|
+
// Sessions a running sign-out test is ending: none starts from them or saves them meanwhile.
|
|
22476
|
+
ending = /* @__PURE__ */ new Map();
|
|
22044
22477
|
get(key) {
|
|
22478
|
+
if (this.ending.has(key)) return void 0;
|
|
22045
22479
|
const session = this.saved.get(key);
|
|
22046
22480
|
if (session && this.now() - session.savedAt > KEEP_MS) this.saved.delete(key);
|
|
22047
22481
|
return this.saved.get(key);
|
|
22048
22482
|
}
|
|
22049
22483
|
save(key, state, url2) {
|
|
22050
|
-
this.saved.set(key, { state, url: url2, savedAt: this.now() });
|
|
22484
|
+
if (!this.ending.has(key)) this.saved.set(key, { state, url: url2, savedAt: this.now() });
|
|
22051
22485
|
}
|
|
22052
22486
|
drop(key) {
|
|
22053
22487
|
this.saved.delete(key);
|
|
22054
22488
|
}
|
|
22489
|
+
/** A sign-out test started: the saved session is gone, and stays unused until it finishes. */
|
|
22490
|
+
end(key) {
|
|
22491
|
+
this.saved.delete(key);
|
|
22492
|
+
this.ending.set(key, (this.ending.get(key) ?? 0) + 1);
|
|
22493
|
+
}
|
|
22494
|
+
/** The sign-out test finished: later tests sign in again and save a new session. */
|
|
22495
|
+
ended(key) {
|
|
22496
|
+
const left = (this.ending.get(key) ?? 1) - 1;
|
|
22497
|
+
if (left > 0) this.ending.set(key, left);
|
|
22498
|
+
else this.ending.delete(key);
|
|
22499
|
+
}
|
|
22055
22500
|
};
|
|
22056
22501
|
sessions = new Sessions();
|
|
22057
22502
|
resume = async (page, context, url2) => {
|
|
22058
22503
|
await page.goto(url2);
|
|
22059
22504
|
await page.waitForLoadState("load").catch(() => {
|
|
22060
22505
|
});
|
|
22061
|
-
|
|
22506
|
+
const samePage = new URL(page.url()).pathname === new URL(url2).pathname;
|
|
22507
|
+
if (samePage && !await page.locator('input[type="password"]:visible').count()) return true;
|
|
22062
22508
|
await context.clearCookies();
|
|
22063
22509
|
await page.evaluate(() => {
|
|
22064
22510
|
localStorage.clear();
|
|
@@ -22070,10 +22516,11 @@ var init_sessions = __esm({
|
|
|
22070
22516
|
});
|
|
22071
22517
|
|
|
22072
22518
|
// src/replay/replay.ts
|
|
22073
|
-
var runStep, runStepSettled, savedTarget, clickTarget, replay;
|
|
22519
|
+
var runStep, runStepSettled, savedTarget, clickTarget, doubleClickTarget, hoverTarget, replay;
|
|
22074
22520
|
var init_replay = __esm({
|
|
22075
22521
|
"src/replay/replay.ts"() {
|
|
22076
22522
|
"use strict";
|
|
22523
|
+
init_actionable();
|
|
22077
22524
|
init_announcements();
|
|
22078
22525
|
init_browser();
|
|
22079
22526
|
init_checks3();
|
|
@@ -22082,6 +22529,7 @@ var init_replay = __esm({
|
|
|
22082
22529
|
init_evidence();
|
|
22083
22530
|
init_findings();
|
|
22084
22531
|
init_make_file();
|
|
22532
|
+
init_read_value();
|
|
22085
22533
|
init_volatile();
|
|
22086
22534
|
init_secrets();
|
|
22087
22535
|
init_test_file();
|
|
@@ -22098,6 +22546,45 @@ var init_replay = __esm({
|
|
|
22098
22546
|
switch (step.action) {
|
|
22099
22547
|
case "click":
|
|
22100
22548
|
return clickTarget(page, step.target.selector);
|
|
22549
|
+
case "double_click":
|
|
22550
|
+
return doubleClickTarget(page, step.target.selector);
|
|
22551
|
+
case "hover":
|
|
22552
|
+
return hoverTarget(page, step.target.selector);
|
|
22553
|
+
case "drag": {
|
|
22554
|
+
const source = page.locator(step.from.selector);
|
|
22555
|
+
const destination = page.locator(step.to.selector);
|
|
22556
|
+
const srcBox = await source.boundingBox();
|
|
22557
|
+
const dstBox = await destination.boundingBox();
|
|
22558
|
+
if (srcBox && dstBox) {
|
|
22559
|
+
const fromX = srcBox.x + srcBox.width / 2;
|
|
22560
|
+
const fromY = srcBox.y + srcBox.height / 2;
|
|
22561
|
+
const toX = dstBox.x + dstBox.width / 2;
|
|
22562
|
+
const toY = dstBox.y + dstBox.height / 2;
|
|
22563
|
+
await page.mouse.move(fromX, fromY);
|
|
22564
|
+
await page.mouse.down();
|
|
22565
|
+
await page.mouse.move(toX, toY, { steps: 10 });
|
|
22566
|
+
return page.mouse.up();
|
|
22567
|
+
}
|
|
22568
|
+
return source.dragTo(destination);
|
|
22569
|
+
}
|
|
22570
|
+
case "draw": {
|
|
22571
|
+
const target2 = page.locator(step.target.selector);
|
|
22572
|
+
const box = await target2.boundingBox();
|
|
22573
|
+
if (!box) throw new Error(`${step.target.code} is not visible to draw on`);
|
|
22574
|
+
const start = step.points[0];
|
|
22575
|
+
if (!start) throw new Error("At least 2 points are required to draw.");
|
|
22576
|
+
await page.mouse.move(box.x + start.x, box.y + start.y);
|
|
22577
|
+
await page.mouse.down();
|
|
22578
|
+
for (let i = 1; i < step.points.length; i++) {
|
|
22579
|
+
const pt = step.points[i];
|
|
22580
|
+
if (pt) await page.mouse.move(box.x + pt.x, box.y + pt.y, { steps: 5 });
|
|
22581
|
+
}
|
|
22582
|
+
return page.mouse.up();
|
|
22583
|
+
}
|
|
22584
|
+
case "remember":
|
|
22585
|
+
return secrets.remember(step.name, await readValue(page.locator(step.target.selector)));
|
|
22586
|
+
case "rememberValue":
|
|
22587
|
+
return secrets.remember(step.name, secrets.expand(step.value));
|
|
22101
22588
|
case "fill":
|
|
22102
22589
|
return page.locator(step.target.selector).fill(secrets.expand(step.value));
|
|
22103
22590
|
case "fillSecret":
|
|
@@ -22149,7 +22636,8 @@ var init_replay = __esm({
|
|
|
22149
22636
|
page,
|
|
22150
22637
|
secrets.expand(step.text),
|
|
22151
22638
|
step.within && { ...step.within, containing: secrets.expand(step.within.containing) },
|
|
22152
|
-
step.exact
|
|
22639
|
+
step.exact,
|
|
22640
|
+
step.wait ? step.wait * 1e3 : void 0
|
|
22153
22641
|
))
|
|
22154
22642
|
throw new Error(`"${step.text}" is not${describeScope(step.within) || " on the page"}`);
|
|
22155
22643
|
return;
|
|
@@ -22158,13 +22646,14 @@ var init_replay = __esm({
|
|
|
22158
22646
|
page,
|
|
22159
22647
|
secrets.expand(step.text),
|
|
22160
22648
|
step.within && { ...step.within, containing: secrets.expand(step.within.containing) },
|
|
22161
|
-
step.exact
|
|
22649
|
+
step.exact,
|
|
22650
|
+
step.wait ? step.wait * 1e3 : void 0
|
|
22162
22651
|
))
|
|
22163
22652
|
throw new Error(`"${step.text}" is still${describeScope(step.within) || " on the page"}`);
|
|
22164
22653
|
return;
|
|
22165
22654
|
case "expectPath":
|
|
22166
22655
|
try {
|
|
22167
|
-
await page.waitForURL((url2) => pathMatches(step.path, url2.pathname));
|
|
22656
|
+
await page.waitForURL((url2) => pathMatches(step.path, `${url2.pathname}${url2.search}`));
|
|
22168
22657
|
} catch {
|
|
22169
22658
|
throw new Error(`Expected to be on ${step.path} but was on ${currentPath(page)}`);
|
|
22170
22659
|
}
|
|
@@ -22177,12 +22666,32 @@ var init_replay = __esm({
|
|
|
22177
22666
|
step.subject && secrets.expand(step.subject),
|
|
22178
22667
|
step.linkText
|
|
22179
22668
|
);
|
|
22669
|
+
await page.context().clearCookies();
|
|
22180
22670
|
return page.goto(link.url);
|
|
22181
22671
|
}
|
|
22182
22672
|
case "expectVisible":
|
|
22183
22673
|
if (!await elementVisible(page, step.target.selector))
|
|
22184
22674
|
throw new Error(`${step.target.code} is not visible`);
|
|
22185
22675
|
return;
|
|
22676
|
+
case "expectCount": {
|
|
22677
|
+
const within = step.within && {
|
|
22678
|
+
...step.within,
|
|
22679
|
+
containing: secrets.expand(step.within.containing)
|
|
22680
|
+
};
|
|
22681
|
+
if (!await textCount(page, secrets.expand(step.text), step.count, within, step.exact))
|
|
22682
|
+
throw new Error(
|
|
22683
|
+
`"${secrets.expand(step.text)}" does not show ${step.count} times${describeScope(within)}`
|
|
22684
|
+
);
|
|
22685
|
+
return;
|
|
22686
|
+
}
|
|
22687
|
+
case "expectMedia":
|
|
22688
|
+
if (!await mediaIs(page, step.target.selector, step.state))
|
|
22689
|
+
throw new Error(`${step.target.code} is not ${step.state}`);
|
|
22690
|
+
return;
|
|
22691
|
+
case "expectValue":
|
|
22692
|
+
if (!await hasValue(page, step.target.selector, secrets.expand(step.value)))
|
|
22693
|
+
throw new Error(`${step.target.code} does not hold "${secrets.expand(step.value)}"`);
|
|
22694
|
+
return;
|
|
22186
22695
|
case "expectChecked":
|
|
22187
22696
|
if (!await isChecked(page, step.target.selector, step.checked))
|
|
22188
22697
|
throw new Error(`${step.target.code} is not ${step.checked ? "on" : "off"}`);
|
|
@@ -22219,32 +22728,78 @@ var init_replay = __esm({
|
|
|
22219
22728
|
clickTarget = async (page, selector) => {
|
|
22220
22729
|
const target2 = page.locator(selector);
|
|
22221
22730
|
const count = await target2.count();
|
|
22222
|
-
if (count <= 1) return target2.click();
|
|
22731
|
+
if (count <= 1) return explained(target2, (each) => each.click());
|
|
22223
22732
|
const exact = exactName(selector);
|
|
22224
|
-
if (exact && await page.locator(exact).count() === 1)
|
|
22733
|
+
if (exact && await page.locator(exact).count() === 1)
|
|
22734
|
+
return explained(page.locator(exact), (each) => each.click());
|
|
22225
22735
|
const hrefs = await target2.evaluateAll(
|
|
22226
22736
|
(links) => links.map((link) => link.href ?? null)
|
|
22227
22737
|
);
|
|
22228
22738
|
const same = hrefs.every((href) => href && href === hrefs[0]);
|
|
22229
|
-
return same ? target2.first()
|
|
22739
|
+
return explained(same ? target2.first() : target2, (each) => each.click());
|
|
22740
|
+
};
|
|
22741
|
+
doubleClickTarget = async (page, selector) => {
|
|
22742
|
+
const target2 = page.locator(selector);
|
|
22743
|
+
const count = await target2.count();
|
|
22744
|
+
if (count <= 1) return explained(target2, (each) => each.dblclick());
|
|
22745
|
+
const exact = exactName(selector);
|
|
22746
|
+
if (exact && await page.locator(exact).count() === 1)
|
|
22747
|
+
return explained(page.locator(exact), (each) => each.dblclick());
|
|
22748
|
+
return explained(target2.first(), (each) => each.dblclick());
|
|
22749
|
+
};
|
|
22750
|
+
hoverTarget = async (page, selector) => {
|
|
22751
|
+
const target2 = page.locator(selector);
|
|
22752
|
+
const count = await target2.count();
|
|
22753
|
+
if (count <= 1) return explained(target2, (each) => each.hover());
|
|
22754
|
+
const exact = exactName(selector);
|
|
22755
|
+
if (exact && await page.locator(exact).count() === 1)
|
|
22756
|
+
return explained(page.locator(exact), (each) => each.hover());
|
|
22757
|
+
return explained(target2.first(), (each) => each.hover());
|
|
22230
22758
|
};
|
|
22231
22759
|
replay = async (test, approve, reporter, context) => {
|
|
22232
22760
|
const { browser: browserSettings } = context.settings;
|
|
22233
22761
|
const { agent: agent2 } = context;
|
|
22234
|
-
const secrets = new Secrets(context.secrets);
|
|
22762
|
+
const secrets = new Secrets(context.secrets, context.remembered);
|
|
22235
22763
|
const runDir = await createRunDir();
|
|
22764
|
+
const missing = secrets.missing(test.steps);
|
|
22765
|
+
if (missing.length) {
|
|
22766
|
+
const reason = `Needs ${missing.join(", ")}, which an earlier test remembers. Run the suite that orders them.`;
|
|
22767
|
+
await reporter.finish({
|
|
22768
|
+
passed: false,
|
|
22769
|
+
reason,
|
|
22770
|
+
verdict: "blocked",
|
|
22771
|
+
findings: [],
|
|
22772
|
+
durationMs: 0,
|
|
22773
|
+
steps: []
|
|
22774
|
+
});
|
|
22775
|
+
return {
|
|
22776
|
+
name: test.name,
|
|
22777
|
+
passed: false,
|
|
22778
|
+
failure: { step: 0, reason },
|
|
22779
|
+
findings: [],
|
|
22780
|
+
steps: [],
|
|
22781
|
+
repairedSteps: [],
|
|
22782
|
+
spend: { repairs: 0, tokens: 0, cost: 0 },
|
|
22783
|
+
durationMs: 0,
|
|
22784
|
+
runDir,
|
|
22785
|
+
reportUrl: reporter.url
|
|
22786
|
+
};
|
|
22787
|
+
}
|
|
22236
22788
|
const startedAt = Date.now();
|
|
22237
22789
|
const inbox = context.settings.inbox ? new Inbox(context.settings.inbox, new Date(startedAt), context.protectedAccounts) : null;
|
|
22238
22790
|
const signIn = test.ownSignIn ? 0 : signInLength(test.steps);
|
|
22239
22791
|
const key = signIn ? sessionKey(test.startUrl, test.steps.slice(0, signIn)) : void 0;
|
|
22240
|
-
const
|
|
22792
|
+
const endsSession = key && signsOut(test.steps) ? key : void 0;
|
|
22793
|
+
const session = key && !endsSession ? sessions.get(key) : void 0;
|
|
22794
|
+
if (endsSession) sessions.end(endsSession);
|
|
22241
22795
|
const {
|
|
22242
22796
|
browser,
|
|
22243
22797
|
context: browserContext,
|
|
22244
22798
|
page,
|
|
22245
22799
|
video,
|
|
22246
22800
|
recordingDirectory,
|
|
22247
|
-
recordingError
|
|
22801
|
+
recordingError,
|
|
22802
|
+
videoSize
|
|
22248
22803
|
} = await openBrowser(browserSettings, void 0, session?.state);
|
|
22249
22804
|
const executionStartedAt = Date.now();
|
|
22250
22805
|
const findings = watchPage(page);
|
|
@@ -22394,7 +22949,8 @@ var init_replay = __esm({
|
|
|
22394
22949
|
position: number4,
|
|
22395
22950
|
elapsedMs: Date.now() - executionStartedAt,
|
|
22396
22951
|
step,
|
|
22397
|
-
status: "skipped"
|
|
22952
|
+
status: "skipped",
|
|
22953
|
+
url: page.url()
|
|
22398
22954
|
});
|
|
22399
22955
|
continue;
|
|
22400
22956
|
}
|
|
@@ -22414,7 +22970,8 @@ var init_replay = __esm({
|
|
|
22414
22970
|
step: done2,
|
|
22415
22971
|
status: "passed",
|
|
22416
22972
|
repaired,
|
|
22417
|
-
screenshot
|
|
22973
|
+
screenshot,
|
|
22974
|
+
url: page.url()
|
|
22418
22975
|
});
|
|
22419
22976
|
}
|
|
22420
22977
|
index += ran.length - 1;
|
|
@@ -22435,7 +22992,8 @@ var init_replay = __esm({
|
|
|
22435
22992
|
step,
|
|
22436
22993
|
status: "failed",
|
|
22437
22994
|
error: reason,
|
|
22438
|
-
screenshot
|
|
22995
|
+
screenshot,
|
|
22996
|
+
url: page.url()
|
|
22439
22997
|
});
|
|
22440
22998
|
if (step.cleanup) {
|
|
22441
22999
|
findings.push({
|
|
@@ -22451,6 +23009,7 @@ var init_replay = __esm({
|
|
|
22451
23009
|
} catch (error62) {
|
|
22452
23010
|
executionError = error62;
|
|
22453
23011
|
} finally {
|
|
23012
|
+
if (endsSession) sessions.ended(endsSession);
|
|
22454
23013
|
const closed = await closeBrowser({ browser, context: browserContext, video });
|
|
22455
23014
|
videoPath = closed.videoPath;
|
|
22456
23015
|
closeError = closed.closeError;
|
|
@@ -22465,8 +23024,8 @@ var init_replay = __esm({
|
|
|
22465
23024
|
mode: recording.mode,
|
|
22466
23025
|
passed,
|
|
22467
23026
|
durationMs: recordingDurationMs,
|
|
22468
|
-
width:
|
|
22469
|
-
height:
|
|
23027
|
+
width: videoSize.width,
|
|
23028
|
+
height: videoSize.height,
|
|
22470
23029
|
retentionDays: recording.retentionDays,
|
|
22471
23030
|
error: recordingError ?? (closeError ? "Browser context did not close cleanly." : void 0)
|
|
22472
23031
|
});
|
|
@@ -22495,7 +23054,8 @@ var init_replay = __esm({
|
|
|
22495
23054
|
reason: failure2 ? `Failed at step ${failure2.step}: ${failure2.reason}` : "Every step passed",
|
|
22496
23055
|
findings,
|
|
22497
23056
|
durationMs: result.durationMs,
|
|
22498
|
-
steps
|
|
23057
|
+
steps,
|
|
23058
|
+
remembered: secrets.rememberedValues
|
|
22499
23059
|
});
|
|
22500
23060
|
return result;
|
|
22501
23061
|
};
|
|
@@ -22508,20 +23068,27 @@ var init_browser2 = __esm({
|
|
|
22508
23068
|
"src/tools/browser.ts"() {
|
|
22509
23069
|
"use strict";
|
|
22510
23070
|
init_zod();
|
|
23071
|
+
init_actionable();
|
|
22511
23072
|
init_browser();
|
|
22512
23073
|
init_checks3();
|
|
22513
23074
|
init_csv_fixture();
|
|
22514
23075
|
init_make_file();
|
|
23076
|
+
init_read_value();
|
|
22515
23077
|
init_volatile();
|
|
22516
23078
|
init_define();
|
|
22517
23079
|
browserTools = (session) => [
|
|
22518
23080
|
tool(
|
|
22519
23081
|
"click",
|
|
22520
|
-
{ ref, intent },
|
|
22521
|
-
({ ref: ref2, intent: intent2 }) => perform(session, async () => {
|
|
23082
|
+
{ ref, intent, double: external_exports.boolean().optional() },
|
|
23083
|
+
({ ref: ref2, intent: intent2, double }) => perform(session, async () => {
|
|
22522
23084
|
const { target: target2, locator } = await session.locate(ref2);
|
|
23085
|
+
if (double) {
|
|
23086
|
+
await explained(locator, (each) => each.dblclick());
|
|
23087
|
+
await waitForQuiet(session.page);
|
|
23088
|
+
return { action: "double_click", intent: intent2, target: target2 };
|
|
23089
|
+
}
|
|
22523
23090
|
session.filePickerOpened = false;
|
|
22524
|
-
await locator.click();
|
|
23091
|
+
await explained(locator, (each) => each.click());
|
|
22525
23092
|
await waitForQuiet(session.page);
|
|
22526
23093
|
if (session.filePickerOpened)
|
|
22527
23094
|
throw new Error(
|
|
@@ -22531,34 +23098,13 @@ var init_browser2 = __esm({
|
|
|
22531
23098
|
})
|
|
22532
23099
|
),
|
|
22533
23100
|
tool(
|
|
22534
|
-
"
|
|
22535
|
-
{
|
|
22536
|
-
|
|
22537
|
-
file_name: external_exports.string(),
|
|
22538
|
-
content: external_exports.string().max(MAX_CSV_FIXTURE_BYTES),
|
|
22539
|
-
intent
|
|
22540
|
-
},
|
|
22541
|
-
({ ref: ref2, file_name, content, intent: intent2 }) => perform(session, async () => {
|
|
22542
|
-
const fixture = csvFixture(file_name, session.secrets.expand(content));
|
|
23101
|
+
"hover",
|
|
23102
|
+
{ ref, intent },
|
|
23103
|
+
({ ref: ref2, intent: intent2 }) => perform(session, async () => {
|
|
22543
23104
|
const { target: target2, locator } = await session.locate(ref2);
|
|
22544
|
-
|
|
22545
|
-
|
|
22546
|
-
|
|
22547
|
-
const input2 = isFileInput ? locator : locator.locator('input[type="file"]');
|
|
22548
|
-
if (await input2.count() !== 1)
|
|
22549
|
-
throw new Error("Choose a single file upload control from the latest page snapshot.");
|
|
22550
|
-
await input2.setInputFiles({
|
|
22551
|
-
name: fixture.fileName,
|
|
22552
|
-
mimeType: "text/csv",
|
|
22553
|
-
buffer: Buffer.from(fixture.content, "utf8")
|
|
22554
|
-
});
|
|
22555
|
-
return {
|
|
22556
|
-
action: "uploadCsv",
|
|
22557
|
-
intent: intent2,
|
|
22558
|
-
target: target2,
|
|
22559
|
-
fileName: fixture.fileName,
|
|
22560
|
-
content: session.secrets.tokenize(content)
|
|
22561
|
-
};
|
|
23105
|
+
await explained(locator, (each) => each.hover());
|
|
23106
|
+
await waitForQuiet(session.page);
|
|
23107
|
+
return { action: "hover", intent: intent2, target: target2 };
|
|
22562
23108
|
})
|
|
22563
23109
|
),
|
|
22564
23110
|
tool(
|
|
@@ -22654,6 +23200,15 @@ var init_browser2 = __esm({
|
|
|
22654
23200
|
};
|
|
22655
23201
|
})
|
|
22656
23202
|
),
|
|
23203
|
+
tool(
|
|
23204
|
+
"remember_value",
|
|
23205
|
+
{ ref, name: external_exports.string(), intent },
|
|
23206
|
+
(args2) => perform(session, async () => {
|
|
23207
|
+
const { target: target2, locator } = await session.locate(args2.ref);
|
|
23208
|
+
session.secrets.remember(args2.name, await readValue(locator));
|
|
23209
|
+
return { action: "remember", intent: args2.intent, target: target2, name: args2.name };
|
|
23210
|
+
})
|
|
23211
|
+
),
|
|
22657
23212
|
tool(
|
|
22658
23213
|
"fill_secret",
|
|
22659
23214
|
{ ref, secret: external_exports.string(), intent },
|
|
@@ -22700,7 +23255,65 @@ var init_browser2 = __esm({
|
|
|
22700
23255
|
await session.page.goto(url2);
|
|
22701
23256
|
return { action: "navigate", intent: intent2, url: url2 };
|
|
22702
23257
|
});
|
|
22703
|
-
})
|
|
23258
|
+
}),
|
|
23259
|
+
tool(
|
|
23260
|
+
"drag",
|
|
23261
|
+
{ from: ref, to: ref, intent },
|
|
23262
|
+
async ({ from, to, intent: intent2 }) => perform(session, async () => {
|
|
23263
|
+
const source = await session.locate(from);
|
|
23264
|
+
const destination = await session.locate(to);
|
|
23265
|
+
const srcBox = await source.locator.boundingBox();
|
|
23266
|
+
const dstBox = await destination.locator.boundingBox();
|
|
23267
|
+
if (srcBox && dstBox) {
|
|
23268
|
+
const fromX = srcBox.x + srcBox.width / 2;
|
|
23269
|
+
const fromY = srcBox.y + srcBox.height / 2;
|
|
23270
|
+
const toX = dstBox.x + dstBox.width / 2;
|
|
23271
|
+
const toY = dstBox.y + dstBox.height / 2;
|
|
23272
|
+
await session.page.mouse.move(fromX, fromY);
|
|
23273
|
+
await session.page.mouse.down();
|
|
23274
|
+
await session.page.mouse.move(toX, toY, { steps: 10 });
|
|
23275
|
+
await session.page.mouse.up();
|
|
23276
|
+
} else {
|
|
23277
|
+
await source.locator.dragTo(destination.locator);
|
|
23278
|
+
}
|
|
23279
|
+
await waitForQuiet(session.page);
|
|
23280
|
+
return {
|
|
23281
|
+
action: "drag",
|
|
23282
|
+
intent: intent2,
|
|
23283
|
+
from: source.target,
|
|
23284
|
+
to: destination.target
|
|
23285
|
+
};
|
|
23286
|
+
})
|
|
23287
|
+
),
|
|
23288
|
+
tool(
|
|
23289
|
+
"draw",
|
|
23290
|
+
{
|
|
23291
|
+
ref,
|
|
23292
|
+
points: external_exports.array(external_exports.object({ x: external_exports.coerce.number(), y: external_exports.coerce.number() })).min(2),
|
|
23293
|
+
intent
|
|
23294
|
+
},
|
|
23295
|
+
async ({ ref: ref2, points, intent: intent2 }) => perform(session, async () => {
|
|
23296
|
+
const { target: target2, locator } = await session.locate(ref2);
|
|
23297
|
+
const box = await locator.boundingBox();
|
|
23298
|
+
if (!box) throw new Error("Cannot draw on an element that is not visible.");
|
|
23299
|
+
const start = points[0];
|
|
23300
|
+
if (!start) throw new Error("At least 2 points are required to draw.");
|
|
23301
|
+
await session.page.mouse.move(box.x + start.x, box.y + start.y);
|
|
23302
|
+
await session.page.mouse.down();
|
|
23303
|
+
for (let i = 1; i < points.length; i++) {
|
|
23304
|
+
const pt = points[i];
|
|
23305
|
+
if (pt) await session.page.mouse.move(box.x + pt.x, box.y + pt.y, { steps: 5 });
|
|
23306
|
+
}
|
|
23307
|
+
await session.page.mouse.up();
|
|
23308
|
+
await waitForQuiet(session.page);
|
|
23309
|
+
return {
|
|
23310
|
+
action: "draw",
|
|
23311
|
+
intent: intent2,
|
|
23312
|
+
target: target2,
|
|
23313
|
+
points
|
|
23314
|
+
};
|
|
23315
|
+
})
|
|
23316
|
+
)
|
|
22704
23317
|
];
|
|
22705
23318
|
mimeTypeFor = (fileName) => {
|
|
22706
23319
|
const extension2 = fileName.split(".").at(-1)?.toLowerCase();
|
|
@@ -22741,9 +23354,37 @@ var init_checks4 = __esm({
|
|
|
22741
23354
|
containing: external_exports.string()
|
|
22742
23355
|
}).optional(),
|
|
22743
23356
|
exact: external_exports.boolean().optional(),
|
|
23357
|
+
absent: external_exports.boolean().optional(),
|
|
23358
|
+
wait: external_exports.number().int().positive().max(MAX_WAIT_SECONDS).optional(),
|
|
23359
|
+
count: external_exports.number().int().nonnegative().optional(),
|
|
22744
23360
|
intent
|
|
22745
23361
|
},
|
|
22746
|
-
async ({ text, within, exact, intent: intent2 }) => {
|
|
23362
|
+
async ({ text, within, exact, absent, wait, count, intent: intent2 }) => {
|
|
23363
|
+
const timeout = wait ? wait * 1e3 : void 0;
|
|
23364
|
+
if (count !== void 0) {
|
|
23365
|
+
text = session.secrets.tokenize(text);
|
|
23366
|
+
within = within && { ...within, containing: session.secrets.tokenize(within.containing) };
|
|
23367
|
+
const scope3 = within && { ...within, containing: session.secrets.expand(within.containing) };
|
|
23368
|
+
if (scope3 && !await scopeExists(session.page, scope3))
|
|
23369
|
+
return `That did not work: nothing on the page is a ${scope3.role} containing "${scope3.containing}". Scope to a role and text from the latest snapshot, or count on the whole page.`;
|
|
23370
|
+
return check2(
|
|
23371
|
+
session,
|
|
23372
|
+
{ action: "expectCount", intent: intent2, text, within, exact, count },
|
|
23373
|
+
await textCount(session.page, session.secrets.expand(text), count, scope3, exact)
|
|
23374
|
+
);
|
|
23375
|
+
}
|
|
23376
|
+
if (absent) {
|
|
23377
|
+
text = session.secrets.tokenize(text);
|
|
23378
|
+
within = within && { ...within, containing: session.secrets.tokenize(within.containing) };
|
|
23379
|
+
const scope3 = within && { ...within, containing: session.secrets.expand(within.containing) };
|
|
23380
|
+
if (scope3 && !await scopeExists(session.page, scope3))
|
|
23381
|
+
return `That did not work: nothing on the page is a ${scope3.role} containing "${scope3.containing}". Scope to a role and text from the latest snapshot, or check the whole page.`;
|
|
23382
|
+
return check2(
|
|
23383
|
+
session,
|
|
23384
|
+
{ action: "expectNoText", intent: intent2, text, within, exact, wait },
|
|
23385
|
+
await textAbsent(session.page, session.secrets.expand(text), scope3, exact, timeout)
|
|
23386
|
+
);
|
|
23387
|
+
}
|
|
22747
23388
|
const typed = session.steps.flatMap(
|
|
22748
23389
|
(step) => step.action === "fill" ? [session.secrets.expand(step.value)] : []
|
|
22749
23390
|
);
|
|
@@ -22752,6 +23393,9 @@ var init_checks4 = __esm({
|
|
|
22752
23393
|
);
|
|
22753
23394
|
if (volatile2)
|
|
22754
23395
|
return `That did not work: "${text}" can't be checked because ${volatile2}, so it would be different on the next run. Check a stable part of the page instead (a heading, a label, a value you typed), or that the page or element is there with expect_element or expect_path.`;
|
|
23396
|
+
const volatileScope = within && volatileReason(within.containing);
|
|
23397
|
+
if (within && volatileScope)
|
|
23398
|
+
return `That did not work: the ${within.role} containing "${within.containing}" can't pick out the same part next run because it is ${volatileScope}. Scope to a name or value the test typed, or check the whole page.`;
|
|
22755
23399
|
text = session.secrets.tokenize(text);
|
|
22756
23400
|
within = within && { ...within, containing: session.secrets.tokenize(within.containing) };
|
|
22757
23401
|
const actual = session.secrets.expand(text);
|
|
@@ -22759,50 +23403,44 @@ var init_checks4 = __esm({
|
|
|
22759
23403
|
if (scope2) {
|
|
22760
23404
|
if (!await scopeExists(session.page, scope2))
|
|
22761
23405
|
return `That did not work: nothing on the page is a ${scope2.role} containing "${scope2.containing}". Scope to a role and text from the latest snapshot, or check the whole page.`;
|
|
22762
|
-
const inScope = await textVisible(session.page, actual, scope2, exact);
|
|
23406
|
+
const inScope = await textVisible(session.page, actual, scope2, exact, timeout);
|
|
22763
23407
|
if (!inScope && await textVisible(session.page, actual, void 0, exact))
|
|
22764
23408
|
return `That did not work: "${actual}" is visible on the page but not inside the ${scope2.role} containing "${scope2.containing}". The scope is wrong. Inspect the latest snapshot and retry with the correct semantic scope; if no scope contains the text, check it on the page without within. Do not record this as an app failure.`;
|
|
22765
|
-
return check2(session, { action: "expectText", intent: intent2, text, within, exact }, inScope);
|
|
23409
|
+
return check2(session, { action: "expectText", intent: intent2, text, within, exact, wait }, inScope);
|
|
22766
23410
|
}
|
|
22767
23411
|
return check2(
|
|
22768
23412
|
session,
|
|
22769
|
-
{ action: "expectText", intent: intent2, text, within, exact },
|
|
22770
|
-
await textVisible(session.page, actual, void 0, exact)
|
|
23413
|
+
{ action: "expectText", intent: intent2, text, within, exact, wait },
|
|
23414
|
+
await textVisible(session.page, actual, void 0, exact, timeout)
|
|
22771
23415
|
);
|
|
22772
23416
|
}
|
|
22773
23417
|
),
|
|
22774
23418
|
tool(
|
|
22775
|
-
"
|
|
22776
|
-
{
|
|
22777
|
-
|
|
22778
|
-
|
|
22779
|
-
|
|
22780
|
-
|
|
22781
|
-
|
|
22782
|
-
|
|
22783
|
-
|
|
22784
|
-
|
|
22785
|
-
|
|
22786
|
-
|
|
22787
|
-
|
|
22788
|
-
|
|
22789
|
-
|
|
22790
|
-
|
|
23419
|
+
"expect_element",
|
|
23420
|
+
{ ref, intent, value: external_exports.string().optional(), media: external_exports.enum(mediaStates).optional() },
|
|
23421
|
+
async ({ ref: ref2, intent: intent2, value, media }) => {
|
|
23422
|
+
const { target: target2 } = await session.locate(ref2);
|
|
23423
|
+
if (media)
|
|
23424
|
+
return check2(
|
|
23425
|
+
session,
|
|
23426
|
+
{ action: "expectMedia", intent: intent2, target: target2, state: media },
|
|
23427
|
+
await mediaIs(session.page, target2.selector, media)
|
|
23428
|
+
);
|
|
23429
|
+
if (value !== void 0) {
|
|
23430
|
+
const saved = session.secrets.tokenize(value);
|
|
23431
|
+
return check2(
|
|
23432
|
+
session,
|
|
23433
|
+
{ action: "expectValue", intent: intent2, target: target2, value: saved },
|
|
23434
|
+
await hasValue(session.page, target2.selector, session.secrets.expand(saved))
|
|
23435
|
+
);
|
|
23436
|
+
}
|
|
22791
23437
|
return check2(
|
|
22792
23438
|
session,
|
|
22793
|
-
{ action: "
|
|
22794
|
-
await
|
|
23439
|
+
{ action: "expectVisible", intent: intent2, target: target2 },
|
|
23440
|
+
await elementVisible(session.page, target2.selector)
|
|
22795
23441
|
);
|
|
22796
23442
|
}
|
|
22797
23443
|
),
|
|
22798
|
-
tool("expect_element", { ref, intent }, async ({ ref: ref2, intent: intent2 }) => {
|
|
22799
|
-
const { target: target2 } = await session.locate(ref2);
|
|
22800
|
-
return check2(
|
|
22801
|
-
session,
|
|
22802
|
-
{ action: "expectVisible", intent: intent2, target: target2 },
|
|
22803
|
-
await elementVisible(session.page, target2.selector)
|
|
22804
|
-
);
|
|
22805
|
-
}),
|
|
22806
23444
|
tool(
|
|
22807
23445
|
"expect_checked",
|
|
22808
23446
|
{ ref, checked: external_exports.boolean(), intent },
|
|
@@ -22831,37 +23469,43 @@ var init_checks4 = __esm({
|
|
|
22831
23469
|
pathMatches(saved, currentPath(session.page))
|
|
22832
23470
|
);
|
|
22833
23471
|
}),
|
|
22834
|
-
tool("read_download", { ref }, async ({ ref: ref2 }) => {
|
|
22835
|
-
try {
|
|
22836
|
-
const { target: target2 } = await session.locate(ref2);
|
|
22837
|
-
const { name: name2, text } = await downloadText(
|
|
22838
|
-
session.page,
|
|
22839
|
-
target2.selector,
|
|
22840
|
-
(file2, bytes) => session.readDocument(file2, bytes)
|
|
22841
|
-
);
|
|
22842
|
-
return session.secrets.redact(
|
|
22843
|
-
`<untrusted_document name="${name2}">
|
|
22844
|
-
${text.slice(0, 4e3)}
|
|
22845
|
-
</untrusted_document>`
|
|
22846
|
-
);
|
|
22847
|
-
} catch (error62) {
|
|
22848
|
-
return `That did not work: ${firstLine(error62)}`;
|
|
22849
|
-
}
|
|
22850
|
-
}),
|
|
22851
23472
|
tool(
|
|
22852
|
-
"
|
|
22853
|
-
{ ref, text: external_exports.string(), intent },
|
|
23473
|
+
"read_download",
|
|
23474
|
+
{ ref, text: external_exports.string().optional(), intent: intent.optional() },
|
|
22854
23475
|
async ({ ref: ref2, text, intent: intent2 }) => {
|
|
22855
|
-
const { target: target2 } = await session.locate(ref2);
|
|
22856
|
-
|
|
22857
|
-
const
|
|
23476
|
+
const { target: target2 } = await session.locate(ref2).catch((error62) => ({ target: null, error: error62 }));
|
|
23477
|
+
if (!target2) return "That did not work: no element has that ref in the latest snapshot.";
|
|
23478
|
+
const read = () => downloadText(
|
|
22858
23479
|
session.page,
|
|
22859
23480
|
target2.selector,
|
|
22860
23481
|
(file2, bytes) => session.readDocument(file2, bytes)
|
|
22861
|
-
)
|
|
22862
|
-
|
|
22863
|
-
|
|
22864
|
-
|
|
23482
|
+
);
|
|
23483
|
+
if (text !== void 0) {
|
|
23484
|
+
const saved = session.secrets.tokenize(text);
|
|
23485
|
+
const found2 = await read().then(
|
|
23486
|
+
({ text: content }) => content.toLowerCase().includes(session.secrets.expand(saved).toLowerCase())
|
|
23487
|
+
).catch(() => false);
|
|
23488
|
+
return check2(
|
|
23489
|
+
session,
|
|
23490
|
+
{
|
|
23491
|
+
action: "expectDownload",
|
|
23492
|
+
intent: intent2 ?? `Download contains ${saved}`,
|
|
23493
|
+
target: target2,
|
|
23494
|
+
text: saved
|
|
23495
|
+
},
|
|
23496
|
+
found2
|
|
23497
|
+
);
|
|
23498
|
+
}
|
|
23499
|
+
try {
|
|
23500
|
+
const { name: name2, text: content } = await read();
|
|
23501
|
+
return session.secrets.redact(
|
|
23502
|
+
`<untrusted_document name="${name2}">
|
|
23503
|
+
${content.slice(0, 4e3)}
|
|
23504
|
+
</untrusted_document>`
|
|
23505
|
+
);
|
|
23506
|
+
} catch (error62) {
|
|
23507
|
+
return `That did not work: ${firstLine(error62)}`;
|
|
23508
|
+
}
|
|
22865
23509
|
}
|
|
22866
23510
|
),
|
|
22867
23511
|
tool(
|
|
@@ -22884,7 +23528,11 @@ ${text.slice(0, 4e3)}
|
|
|
22884
23528
|
if (session.cleaningUp)
|
|
22885
23529
|
return "That did not work: the test already has its verdict. Call finish_cleanup.";
|
|
22886
23530
|
if (verdict === "passed" && session.checks.length === 0)
|
|
22887
|
-
return "That did not work: passed needs at least one check that proves the outcome the test describes. Check each outcome with expect_text,
|
|
23531
|
+
return "That did not work: passed needs at least one check that proves the outcome the test describes. Check each outcome with expect_text, expect_element, expect_checked or expect_path, then finish again.";
|
|
23532
|
+
if (verdict === "inconclusive" && !session.inconclusiveQuestioned && session.checks.length > 0 && session.checks.every((each) => each.passed)) {
|
|
23533
|
+
session.inconclusiveQuestioned = true;
|
|
23534
|
+
return "That did not work: every check passed, so the app was reachable. Finish passed if the checks prove the test, failed if the app did not do something the test needs, or blocked if the test needs something Qadet does not have. Inconclusive is only for an app that crashed, showed a blank page or could not be reached.";
|
|
23535
|
+
}
|
|
22888
23536
|
session.verdict = { passed: verdict === "passed", reason, verdict };
|
|
22889
23537
|
session.suggestedPrompt = suggested_test && session.secrets.redact(suggested_test);
|
|
22890
23538
|
session.ownSignIn = own_sign_in;
|
|
@@ -22978,6 +23626,7 @@ ${email4.text.slice(0, 3e3)}
|
|
|
22978
23626
|
if (!session.inbox) throw new Error("This project has no test inbox");
|
|
22979
23627
|
const address = session.secrets.expand(session.secrets.tokenize(to));
|
|
22980
23628
|
const link = await session.inbox.link(address, subject, link_text);
|
|
23629
|
+
await session.page.context().clearCookies();
|
|
22981
23630
|
await session.page.goto(link.url);
|
|
22982
23631
|
return {
|
|
22983
23632
|
action: "followEmailLink",
|
|
@@ -23029,6 +23678,8 @@ var init_session = __esm({
|
|
|
23029
23678
|
positions = [];
|
|
23030
23679
|
recorded = 0;
|
|
23031
23680
|
checks = [];
|
|
23681
|
+
/** Whether the model was already told a run with passing checks is not inconclusive */
|
|
23682
|
+
inconclusiveQuestioned = false;
|
|
23032
23683
|
findings;
|
|
23033
23684
|
verdict;
|
|
23034
23685
|
/** Links seen in emails this run, which are opened with follow_email_link, never saved */
|
|
@@ -23052,9 +23703,9 @@ var init_session = __esm({
|
|
|
23052
23703
|
return this.reporter.readDocument(name2, bytes);
|
|
23053
23704
|
}
|
|
23054
23705
|
locate(ref2) {
|
|
23055
|
-
return locateRef(this.page, ref2);
|
|
23706
|
+
return locateRef(this.page, ref2, this.secrets.unique);
|
|
23056
23707
|
}
|
|
23057
|
-
async record(done, status3 = "passed") {
|
|
23708
|
+
async record(done, status3 = "passed", error62) {
|
|
23058
23709
|
const position = ++this.recorded;
|
|
23059
23710
|
const step = this.secrets.tokenizeStep(this.cleaningUp ? { ...done, cleanup: true } : done);
|
|
23060
23711
|
this.steps.push(step);
|
|
@@ -23066,7 +23717,9 @@ var init_session = __esm({
|
|
|
23066
23717
|
elapsedMs: Date.now() - this.startedAt,
|
|
23067
23718
|
step,
|
|
23068
23719
|
status: status3,
|
|
23069
|
-
|
|
23720
|
+
error: error62 && this.secrets.redact(error62),
|
|
23721
|
+
screenshot,
|
|
23722
|
+
url: this.page.url()
|
|
23070
23723
|
})
|
|
23071
23724
|
);
|
|
23072
23725
|
return position;
|
|
@@ -23076,8 +23729,8 @@ var init_session = __esm({
|
|
|
23076
23729
|
this.created.push({ name: this.secrets.tokenize(name2), page: this.page.url() });
|
|
23077
23730
|
}
|
|
23078
23731
|
/** Reports test data that may still be in the app, so a person can remove it */
|
|
23079
|
-
leftBehind(
|
|
23080
|
-
this.findings.push({ kind: "cleanup", message, page: this.page.url() });
|
|
23732
|
+
leftBehind(message2) {
|
|
23733
|
+
this.findings.push({ kind: "cleanup", message: message2, page: this.page.url() });
|
|
23081
23734
|
}
|
|
23082
23735
|
/** Drops the steps and checks from a step onwards: an attempt that went wrong by the AI's doing. */
|
|
23083
23736
|
async drop(from, reason) {
|
|
@@ -23196,7 +23849,7 @@ var init_explore = __esm({
|
|
|
23196
23849
|
});
|
|
23197
23850
|
explore = async ({ url: url2, prompt, context, reporter }) => {
|
|
23198
23851
|
const { settings } = context;
|
|
23199
|
-
const secrets = new Secrets(context.secrets);
|
|
23852
|
+
const secrets = new Secrets(context.secrets, context.remembered);
|
|
23200
23853
|
const runDir = await createRunDir();
|
|
23201
23854
|
const startedAt = Date.now();
|
|
23202
23855
|
const {
|
|
@@ -23205,7 +23858,8 @@ var init_explore = __esm({
|
|
|
23205
23858
|
page,
|
|
23206
23859
|
video,
|
|
23207
23860
|
recordingDirectory,
|
|
23208
|
-
recordingError
|
|
23861
|
+
recordingError,
|
|
23862
|
+
videoSize
|
|
23209
23863
|
} = await openBrowser(settings.browser);
|
|
23210
23864
|
const recordingStartedAt = Date.now();
|
|
23211
23865
|
let recordingDurationMs = 0;
|
|
@@ -23221,6 +23875,7 @@ var init_explore = __esm({
|
|
|
23221
23875
|
);
|
|
23222
23876
|
let error62;
|
|
23223
23877
|
let limited = false;
|
|
23878
|
+
let unreachableApp = false;
|
|
23224
23879
|
let aiError;
|
|
23225
23880
|
let usage3 = { cost: 0, total_tokens: 0 };
|
|
23226
23881
|
let knowledgeUsed = [];
|
|
@@ -23262,6 +23917,7 @@ var init_explore = __esm({
|
|
|
23262
23917
|
);
|
|
23263
23918
|
} catch (caught) {
|
|
23264
23919
|
error62 = firstLine(caught);
|
|
23920
|
+
unreachableApp = appUnreachable(caught);
|
|
23265
23921
|
}
|
|
23266
23922
|
if (error62 && context.cleanup && session.created.length && !session.cleaningUp)
|
|
23267
23923
|
session.leftBehind(
|
|
@@ -23279,14 +23935,18 @@ var init_explore = __esm({
|
|
|
23279
23935
|
mode: recording.mode,
|
|
23280
23936
|
passed: false,
|
|
23281
23937
|
durationMs: recordingDurationMs,
|
|
23282
|
-
width:
|
|
23283
|
-
height:
|
|
23938
|
+
width: videoSize.width,
|
|
23939
|
+
height: videoSize.height,
|
|
23284
23940
|
retentionDays: recording.retentionDays,
|
|
23285
23941
|
error: recordingError ?? (closeError ? "Browser context did not close cleanly." : void 0)
|
|
23286
23942
|
});
|
|
23287
23943
|
throw new RunCancelled();
|
|
23288
23944
|
}
|
|
23289
|
-
let outcome = error62 ? {
|
|
23945
|
+
let outcome = error62 ? {
|
|
23946
|
+
passed: false,
|
|
23947
|
+
reason: error62,
|
|
23948
|
+
verdict: unreachableApp ? "blocked" : limited ? "inconclusive" : void 0
|
|
23949
|
+
} : decide(session);
|
|
23290
23950
|
let steps = session.steps;
|
|
23291
23951
|
const repeatSteps = (heal) => replay(
|
|
23292
23952
|
{ name: "verification", prompt, startUrl: url2, steps },
|
|
@@ -23318,12 +23978,14 @@ var init_explore = __esm({
|
|
|
23318
23978
|
steps = repeat.steps;
|
|
23319
23979
|
repeat = await repeatSteps(false);
|
|
23320
23980
|
}
|
|
23321
|
-
if (!repeat.passed)
|
|
23981
|
+
if (!repeat.passed) {
|
|
23322
23982
|
outcome = {
|
|
23323
|
-
passed:
|
|
23324
|
-
reason:
|
|
23325
|
-
verdict: "
|
|
23983
|
+
passed: true,
|
|
23984
|
+
reason: `${outcome.reason ?? "Exploration passed all checks."} (Note: saved steps need review before automated headless replay: step ${repeat.failure?.step}: ${repeat.failure?.reason})`,
|
|
23985
|
+
verdict: "passed"
|
|
23326
23986
|
};
|
|
23987
|
+
steps = [];
|
|
23988
|
+
}
|
|
23327
23989
|
}
|
|
23328
23990
|
await reportVideo(reporter, {
|
|
23329
23991
|
path: videoPath,
|
|
@@ -23331,8 +23993,8 @@ var init_explore = __esm({
|
|
|
23331
23993
|
mode: recording.mode,
|
|
23332
23994
|
passed: outcome.passed,
|
|
23333
23995
|
durationMs: recordingDurationMs,
|
|
23334
|
-
width:
|
|
23335
|
-
height:
|
|
23996
|
+
width: videoSize.width,
|
|
23997
|
+
height: videoSize.height,
|
|
23336
23998
|
retentionDays: recording.retentionDays,
|
|
23337
23999
|
error: recordingError ?? (closeError ? "Browser context did not close cleanly." : void 0)
|
|
23338
24000
|
});
|
|
@@ -23346,6 +24008,7 @@ var init_explore = __esm({
|
|
|
23346
24008
|
knowledgeUsed,
|
|
23347
24009
|
suggestedPrompt: session.suggestedPrompt,
|
|
23348
24010
|
ownSignIn: session.ownSignIn,
|
|
24011
|
+
remembered: secrets.rememberedValues,
|
|
23349
24012
|
aiError,
|
|
23350
24013
|
usage: usage3,
|
|
23351
24014
|
durationMs: Date.now() - startedAt,
|
|
@@ -23374,6 +24037,8 @@ var init_run_context = __esm({
|
|
|
23374
24037
|
hostMap: external_exports.array(external_exports.object({ host: external_exports.string(), address: external_exports.string() })).default([]),
|
|
23375
24038
|
acceptInvalidCertificates: external_exports.boolean().default(false),
|
|
23376
24039
|
allowedHosts: external_exports.array(external_exports.string()).default([]),
|
|
24040
|
+
/** The screen the test runs on; phones and tablets are emulated with Playwright's profiles */
|
|
24041
|
+
device: external_exports.enum(["desktop", "mobile", "tablet"]).default("desktop"),
|
|
23377
24042
|
videoRecording: external_exports.object({
|
|
23378
24043
|
enabled: external_exports.boolean().default(false),
|
|
23379
24044
|
mode: external_exports.enum(["all", "failures_only", "disabled"]).default("disabled"),
|
|
@@ -23391,6 +24056,8 @@ var init_run_context = __esm({
|
|
|
23391
24056
|
inbox: inboxSettingsSchema.nullable().default(null)
|
|
23392
24057
|
}),
|
|
23393
24058
|
secrets: external_exports.record(external_exports.string(), external_exports.string()),
|
|
24059
|
+
/** What earlier tests in the same ordered test run remembered, such as ORDER_NUMBER */
|
|
24060
|
+
remembered: external_exports.record(external_exports.string(), external_exports.string()).default({}),
|
|
23394
24061
|
/** Where the run reaches Qadet's agent service, when the organization has an AI model */
|
|
23395
24062
|
agent: agentAccessSchema.nullable().default(null),
|
|
23396
24063
|
/** What this run may spend on the AI, such as its share of a QA task's budget */
|
|
@@ -23688,21 +24355,26 @@ var runnerVersion, runnerProtocol;
|
|
|
23688
24355
|
var init_version = __esm({
|
|
23689
24356
|
"src/version.ts"() {
|
|
23690
24357
|
"use strict";
|
|
23691
|
-
runnerVersion = true ? "0.
|
|
24358
|
+
runnerVersion = true ? "0.5.0" : "dev";
|
|
23692
24359
|
runnerProtocol = 4;
|
|
23693
24360
|
}
|
|
23694
24361
|
});
|
|
23695
24362
|
|
|
23696
24363
|
// src/web/connection.ts
|
|
24364
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
23697
24365
|
import { chmod, mkdir as mkdir5, readFile as readFile4, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
23698
24366
|
import { homedir } from "node:os";
|
|
23699
24367
|
import { dirname, posix, win32 } from "node:path";
|
|
23700
|
-
var connectionSchema, connectionPathFor, oldConnectionPathFor, connectionPath, oldConnectionPath, readSaved, readConnection, saveConnection, forgetConnection;
|
|
24368
|
+
var connectionSchema, connectionPathFor, oldConnectionPathFor, connectionPath, oldConnectionPath, envRunnerId, readSaved, connectionFromEnv, readConnection, withRunnerId, saveConnection, forgetConnection;
|
|
23701
24369
|
var init_connection = __esm({
|
|
23702
24370
|
"src/web/connection.ts"() {
|
|
23703
24371
|
"use strict";
|
|
23704
24372
|
init_zod();
|
|
23705
|
-
connectionSchema = external_exports.object({
|
|
24373
|
+
connectionSchema = external_exports.object({
|
|
24374
|
+
url: external_exports.string().url(),
|
|
24375
|
+
token: external_exports.string().min(1),
|
|
24376
|
+
runnerId: external_exports.string().uuid().optional()
|
|
24377
|
+
});
|
|
23706
24378
|
connectionPathFor = ({
|
|
23707
24379
|
platform = process.platform,
|
|
23708
24380
|
home = homedir(),
|
|
@@ -23724,16 +24396,36 @@ var init_connection = __esm({
|
|
|
23724
24396
|
} = {}) => platform === "darwin" ? posix.join(xdgConfigHome || posix.join(home, ".config"), "qadet", "connection.json") : void 0;
|
|
23725
24397
|
connectionPath = connectionPathFor();
|
|
23726
24398
|
oldConnectionPath = oldConnectionPathFor();
|
|
24399
|
+
envRunnerId = randomUUID3();
|
|
23727
24400
|
readSaved = (path) => readFile4(path, "utf8").catch(() => void 0);
|
|
23728
|
-
|
|
24401
|
+
connectionFromEnv = (env = process.env, saved) => {
|
|
24402
|
+
const url2 = env.QADET_URL?.trim() || saved?.url;
|
|
24403
|
+
const token = env.QADET_TOKEN?.trim() || saved?.token;
|
|
24404
|
+
if (!url2 || !token) return saved;
|
|
24405
|
+
return connectionSchema.parse({
|
|
24406
|
+
url: new URL(url2).origin,
|
|
24407
|
+
token,
|
|
24408
|
+
runnerId: saved?.runnerId ?? envRunnerId
|
|
24409
|
+
});
|
|
24410
|
+
};
|
|
24411
|
+
readConnection = async (env = process.env) => {
|
|
23729
24412
|
const saved = await readSaved(connectionPath);
|
|
23730
|
-
if (saved)
|
|
24413
|
+
if (saved)
|
|
24414
|
+
return connectionFromEnv(env, await withRunnerId(connectionSchema.parse(JSON.parse(saved))));
|
|
23731
24415
|
const old = oldConnectionPath && await readSaved(oldConnectionPath);
|
|
23732
|
-
if (
|
|
23733
|
-
|
|
23734
|
-
|
|
23735
|
-
|
|
23736
|
-
|
|
24416
|
+
if (old && oldConnectionPath) {
|
|
24417
|
+
const connection = { ...connectionSchema.parse(JSON.parse(old)), runnerId: randomUUID3() };
|
|
24418
|
+
await saveConnection(connection);
|
|
24419
|
+
await rm2(oldConnectionPath, { force: true });
|
|
24420
|
+
return connectionFromEnv(env, connection);
|
|
24421
|
+
}
|
|
24422
|
+
return connectionFromEnv(env);
|
|
24423
|
+
};
|
|
24424
|
+
withRunnerId = async (connection) => {
|
|
24425
|
+
if (connection.runnerId) return connection;
|
|
24426
|
+
const identified = { ...connection, runnerId: randomUUID3() };
|
|
24427
|
+
await saveConnection(identified);
|
|
24428
|
+
return identified;
|
|
23737
24429
|
};
|
|
23738
24430
|
saveConnection = async (connection) => {
|
|
23739
24431
|
await mkdir5(dirname(connectionPath), { recursive: true, mode: 448 });
|
|
@@ -23747,8 +24439,9 @@ var init_connection = __esm({
|
|
|
23747
24439
|
});
|
|
23748
24440
|
|
|
23749
24441
|
// src/web/web-app.ts
|
|
24442
|
+
import { hostname as hostname3 } from "node:os";
|
|
23750
24443
|
import { setTimeout as sleep3 } from "node:timers/promises";
|
|
23751
|
-
var updateNoted, noteUpdate, webAppAt, connectWebApp, claimRun, describeIssue, appendFields, decisionCheckEvery, decisionWaitLimit, askForRepairApproval;
|
|
24444
|
+
var updateNoted, expiryNoted, expiryWarningMs, noteUpdate, formatExpiryWarning, noteTokenExpiry, webAppAt, connectWebApp, claimRun, checkIn, describeIssue, appendFields, decisionCheckEvery, decisionWaitLimit, askForRepairApproval;
|
|
23752
24445
|
var init_web_app = __esm({
|
|
23753
24446
|
"src/web/web-app.ts"() {
|
|
23754
24447
|
"use strict";
|
|
@@ -23758,6 +24451,8 @@ var init_web_app = __esm({
|
|
|
23758
24451
|
init_connection();
|
|
23759
24452
|
init_run_context();
|
|
23760
24453
|
updateNoted = false;
|
|
24454
|
+
expiryNoted = false;
|
|
24455
|
+
expiryWarningMs = 7 * 24 * 60 * 6e4;
|
|
23761
24456
|
noteUpdate = (latest) => {
|
|
23762
24457
|
if (updateNoted || !latest || runnerVersion === "dev" || latest === runnerVersion) return;
|
|
23763
24458
|
updateNoted = true;
|
|
@@ -23766,7 +24461,22 @@ var init_web_app = __esm({
|
|
|
23766
24461
|
`
|
|
23767
24462
|
);
|
|
23768
24463
|
};
|
|
23769
|
-
|
|
24464
|
+
formatExpiryWarning = (expiresAt, now = Date.now()) => {
|
|
24465
|
+
if (!expiresAt) return void 0;
|
|
24466
|
+
const remaining = Date.parse(expiresAt) - now;
|
|
24467
|
+
if (!Number.isFinite(remaining) || remaining <= 0 || remaining > expiryWarningMs) return void 0;
|
|
24468
|
+
const days = Math.max(1, Math.ceil(remaining / (24 * 60 * 6e4)));
|
|
24469
|
+
return `Your runner token expires in ${days} ${days === 1 ? "day" : "days"} (${expiresAt.slice(0, 10)}). Rotate it on the Runner tokens page.
|
|
24470
|
+
`;
|
|
24471
|
+
};
|
|
24472
|
+
noteTokenExpiry = (expiresAt) => {
|
|
24473
|
+
if (expiryNoted) return;
|
|
24474
|
+
const warning = formatExpiryWarning(expiresAt);
|
|
24475
|
+
if (!warning) return;
|
|
24476
|
+
expiryNoted = true;
|
|
24477
|
+
process.stdout.write(warning);
|
|
24478
|
+
};
|
|
24479
|
+
webAppAt = ({ url: baseUrl, token, runnerId }) => {
|
|
23770
24480
|
return {
|
|
23771
24481
|
baseUrl,
|
|
23772
24482
|
request: async (path, init) => {
|
|
@@ -23776,6 +24486,7 @@ var init_web_app = __esm({
|
|
|
23776
24486
|
Authorization: `Bearer ${token}`,
|
|
23777
24487
|
"X-Qadet-Runner": runnerVersion,
|
|
23778
24488
|
"X-Qadet-Protocol": String(runnerProtocol),
|
|
24489
|
+
...runnerId && { "X-Qadet-Runner-Id": runnerId, "X-Qadet-Runner-Label": hostname3() },
|
|
23779
24490
|
...init.headers
|
|
23780
24491
|
}
|
|
23781
24492
|
}).catch((error62) => {
|
|
@@ -23788,6 +24499,7 @@ var init_web_app = __esm({
|
|
|
23788
24499
|
throw new Error(`Qadet at ${baseUrl} refused the request: ${body.error ?? response.status}`);
|
|
23789
24500
|
}
|
|
23790
24501
|
noteUpdate(response.headers.get("X-Qadet-Runner-Latest"));
|
|
24502
|
+
noteTokenExpiry(response.headers.get("X-Qadet-Token-Expires"));
|
|
23791
24503
|
return response;
|
|
23792
24504
|
}
|
|
23793
24505
|
};
|
|
@@ -23796,12 +24508,15 @@ var init_web_app = __esm({
|
|
|
23796
24508
|
const connection = await readConnection();
|
|
23797
24509
|
if (!connection)
|
|
23798
24510
|
throw new Error(
|
|
23799
|
-
"This runner is not connected. Create a token on the Runner tokens page, then run: pnpm qadet connect <url>
|
|
24511
|
+
"This runner is not connected. Create a token on the Runner tokens page, then run: pnpm qadet connect <url>"
|
|
23800
24512
|
);
|
|
23801
24513
|
return webAppAt(connection);
|
|
23802
24514
|
};
|
|
23803
|
-
claimRun = async (app) => {
|
|
23804
|
-
const response = await app.request("/api/runs/claim", {
|
|
24515
|
+
claimRun = async (app, slots = "0/1") => {
|
|
24516
|
+
const response = await app.request("/api/runs/claim", {
|
|
24517
|
+
method: "POST",
|
|
24518
|
+
headers: { "X-Qadet-Runner-Slots": slots }
|
|
24519
|
+
});
|
|
23805
24520
|
if (response.status === 204) return void 0;
|
|
23806
24521
|
const body = await response.json();
|
|
23807
24522
|
const test = testFileSchema.safeParse(body.test);
|
|
@@ -23810,6 +24525,10 @@ var init_web_app = __esm({
|
|
|
23810
24525
|
if (!context.success) throw new UnreadableRun(body.id, describeIssue(context.error.issues[0]));
|
|
23811
24526
|
return { id: body.id, kind: body.kind, test: test.data, context: context.data };
|
|
23812
24527
|
};
|
|
24528
|
+
checkIn = (app, slots) => app.request("/api/connection/check_in", {
|
|
24529
|
+
method: "POST",
|
|
24530
|
+
headers: { "X-Qadet-Runner-Slots": slots }
|
|
24531
|
+
});
|
|
23813
24532
|
describeIssue = (issue2) => issue2 ? `${issue2.path.join(".")}: ${issue2.message}` : "unknown problem";
|
|
23814
24533
|
appendFields = (form, prefix, value) => {
|
|
23815
24534
|
if (value === void 0) return;
|
|
@@ -23892,7 +24611,7 @@ var init_report = __esm({
|
|
|
23892
24611
|
body: JSON.stringify({ from, reason })
|
|
23893
24612
|
});
|
|
23894
24613
|
},
|
|
23895
|
-
step: async ({ position, elapsedMs, step, status: status3, error: error62, repaired, screenshot }) => {
|
|
24614
|
+
step: async ({ position, elapsedMs, step, status: status3, error: error62, repaired, screenshot, url: url2 }) => {
|
|
23896
24615
|
const { action, intent: intent2, ...detail } = step;
|
|
23897
24616
|
const form = new FormData();
|
|
23898
24617
|
appendFields(form, "step", {
|
|
@@ -23903,6 +24622,7 @@ var init_report = __esm({
|
|
|
23903
24622
|
status: status3,
|
|
23904
24623
|
error: error62,
|
|
23905
24624
|
repaired,
|
|
24625
|
+
url: url2,
|
|
23906
24626
|
detail
|
|
23907
24627
|
});
|
|
23908
24628
|
if (screenshot)
|
|
@@ -23923,7 +24643,8 @@ var init_report = __esm({
|
|
|
23923
24643
|
knowledgeUsed,
|
|
23924
24644
|
suggestedPrompt,
|
|
23925
24645
|
ownSignIn,
|
|
23926
|
-
verdict
|
|
24646
|
+
verdict,
|
|
24647
|
+
remembered
|
|
23927
24648
|
}) => {
|
|
23928
24649
|
await app.request(`/api/runs/${runId}`, {
|
|
23929
24650
|
method: "PATCH",
|
|
@@ -23938,7 +24659,8 @@ var init_report = __esm({
|
|
|
23938
24659
|
knowledge_used: knowledgeUsed,
|
|
23939
24660
|
suggested_prompt: suggestedPrompt,
|
|
23940
24661
|
own_sign_in: ownSignIn,
|
|
23941
|
-
verdict
|
|
24662
|
+
verdict,
|
|
24663
|
+
remembered
|
|
23942
24664
|
}
|
|
23943
24665
|
})
|
|
23944
24666
|
});
|
|
@@ -23977,6 +24699,10 @@ var init_run_slots = __esm({
|
|
|
23977
24699
|
maxWaiting;
|
|
23978
24700
|
running = 0;
|
|
23979
24701
|
waiting = 0;
|
|
24702
|
+
/** Says how many slots are in use, such as 1/2, for the runner's status in the web app */
|
|
24703
|
+
get header() {
|
|
24704
|
+
return `${this.running}/${this.size}`;
|
|
24705
|
+
}
|
|
23980
24706
|
get canClaim() {
|
|
23981
24707
|
return this.running < this.size && this.waiting < this.maxWaiting;
|
|
23982
24708
|
}
|
|
@@ -24008,7 +24734,7 @@ __export(agent_exports, {
|
|
|
24008
24734
|
});
|
|
24009
24735
|
import { setTimeout as sleep4 } from "node:timers/promises";
|
|
24010
24736
|
import { parseArgs } from "node:util";
|
|
24011
|
-
var pollEvery, retryEvery2, unfinished, say, approveInWebApp, runClaimed, agent;
|
|
24737
|
+
var pollEvery, retryEvery2, checkInEvery, unfinished, say, approveInWebApp, runClaimed, agent;
|
|
24012
24738
|
var init_agent2 = __esm({
|
|
24013
24739
|
"src/commands/agent.ts"() {
|
|
24014
24740
|
"use strict";
|
|
@@ -24021,6 +24747,7 @@ var init_agent2 = __esm({
|
|
|
24021
24747
|
init_run_slots();
|
|
24022
24748
|
pollEvery = 2e3;
|
|
24023
24749
|
retryEvery2 = 1e4;
|
|
24750
|
+
checkInEvery = 1e4;
|
|
24024
24751
|
unfinished = { findings: [], cost: 0, usage: {}, durationMs: 0, steps: [] };
|
|
24025
24752
|
say = (runId, line) => process.stdout.write(`[run ${runId}] ${line}
|
|
24026
24753
|
`);
|
|
@@ -24052,13 +24779,25 @@ var init_agent2 = __esm({
|
|
|
24052
24779
|
};
|
|
24053
24780
|
};
|
|
24054
24781
|
agent = {
|
|
24055
|
-
usage: "agent [--parallel 1]",
|
|
24782
|
+
usage: "agent [--parallel 1] [--show-browser]",
|
|
24056
24783
|
summary: "Run the tests you start in the web app, in Chrome on this computer, one at a time unless --parallel says more",
|
|
24057
24784
|
run: async (args2) => {
|
|
24058
|
-
const { values } = parseArgs({
|
|
24785
|
+
const { values } = parseArgs({
|
|
24786
|
+
args: args2,
|
|
24787
|
+
options: {
|
|
24788
|
+
parallel: { type: "string", default: "1" },
|
|
24789
|
+
"show-browser": { type: "boolean", default: false }
|
|
24790
|
+
}
|
|
24791
|
+
});
|
|
24059
24792
|
const parallel = Number(values.parallel);
|
|
24060
24793
|
if (!Number.isInteger(parallel) || parallel < 1)
|
|
24061
24794
|
throw new Error("--parallel takes a whole number of runs, such as 2");
|
|
24795
|
+
if (!values["show-browser"]) process.env.QADET_HEADLESS = "1";
|
|
24796
|
+
else if (parallel > 1)
|
|
24797
|
+
process.stdout.write(
|
|
24798
|
+
`Each run opens its own Chrome window, so ${parallel} may slow this computer down.
|
|
24799
|
+
`
|
|
24800
|
+
);
|
|
24062
24801
|
const app = await connectWebApp();
|
|
24063
24802
|
await cleanAbandonedRecordings();
|
|
24064
24803
|
void retryPendingVideosForever(app);
|
|
@@ -24068,15 +24807,17 @@ var init_agent2 = __esm({
|
|
|
24068
24807
|
);
|
|
24069
24808
|
const slots = new RunSlots(parallel);
|
|
24070
24809
|
const current = /* @__PURE__ */ new Set();
|
|
24071
|
-
|
|
24810
|
+
const stopRuns = (code) => async () => {
|
|
24072
24811
|
await Promise.all(
|
|
24073
24812
|
[...current].map(
|
|
24074
24813
|
(reporter) => reporter.finish({ passed: false, reason: "The runner was stopped", ...unfinished }).catch(() => {
|
|
24075
24814
|
})
|
|
24076
24815
|
)
|
|
24077
24816
|
);
|
|
24078
|
-
process.exit(
|
|
24079
|
-
}
|
|
24817
|
+
process.exit(code);
|
|
24818
|
+
};
|
|
24819
|
+
process.once("SIGINT", stopRuns(130));
|
|
24820
|
+
process.once("SIGTERM", stopRuns(143));
|
|
24080
24821
|
const runOne = async (claimed) => {
|
|
24081
24822
|
const reporter = reporterFor(app, claimed.id);
|
|
24082
24823
|
current.add(reporter);
|
|
@@ -24088,19 +24829,26 @@ var init_agent2 = __esm({
|
|
|
24088
24829
|
const outcome = await runClaimed(claimed, reporter, approve).catch(async (error62) => {
|
|
24089
24830
|
const reason = firstLine(error62);
|
|
24090
24831
|
if (error62 instanceof RunCancelled) return { passed: false, reason };
|
|
24091
|
-
|
|
24832
|
+
const verdict = appUnreachable(error62) ? "blocked" : void 0;
|
|
24833
|
+
await reporter.finish({ passed: false, reason, verdict, ...unfinished }).catch(() => {
|
|
24092
24834
|
});
|
|
24093
24835
|
return { passed: false, reason };
|
|
24094
24836
|
});
|
|
24095
24837
|
current.delete(reporter);
|
|
24096
24838
|
say(claimed.id, `${outcome.passed ? "Passed" : "Failed"}: ${outcome.reason}`);
|
|
24097
24839
|
};
|
|
24840
|
+
let checkedInAt = 0;
|
|
24098
24841
|
for (; ; ) {
|
|
24099
24842
|
if (!slots.canClaim) {
|
|
24843
|
+
if (Date.now() - checkedInAt >= checkInEvery) {
|
|
24844
|
+
checkedInAt = Date.now();
|
|
24845
|
+
await checkIn(app, slots.header).catch(() => {
|
|
24846
|
+
});
|
|
24847
|
+
}
|
|
24100
24848
|
await sleep4(pollEvery);
|
|
24101
24849
|
continue;
|
|
24102
24850
|
}
|
|
24103
|
-
const claimed = await claimRun(app).catch(async (error62) => {
|
|
24851
|
+
const claimed = await claimRun(app, slots.header).catch(async (error62) => {
|
|
24104
24852
|
if (error62 instanceof RunnerUpdateRequired) throw error62;
|
|
24105
24853
|
if (error62 instanceof UnreadableRun) {
|
|
24106
24854
|
await reporterFor(app, error62.runId).finish({ passed: false, reason: error62.message, ...unfinished }).catch(() => {
|
|
@@ -24135,6 +24883,7 @@ init_agent2();
|
|
|
24135
24883
|
init_version();
|
|
24136
24884
|
init_connection();
|
|
24137
24885
|
init_web_app();
|
|
24886
|
+
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
24138
24887
|
import { createInterface } from "node:readline/promises";
|
|
24139
24888
|
import { Writable } from "node:stream";
|
|
24140
24889
|
import { parseArgs as parseArgs2 } from "node:util";
|
|
@@ -24165,9 +24914,15 @@ var normalizeUrl = (value) => {
|
|
|
24165
24914
|
throw new Error("Use a workspace URL starting with http:// or https://, without credentials");
|
|
24166
24915
|
return url2.origin;
|
|
24167
24916
|
};
|
|
24917
|
+
var describeToken = (token) => {
|
|
24918
|
+
const masked = token.lastFour ? `qdt_\u2026${token.lastFour}` : "qdt_\u2026";
|
|
24919
|
+
const expiry = token.expiresAt ? `expires ${token.expiresAt.slice(0, 10)}` : "never expires";
|
|
24920
|
+
return `${token.name} (${masked}, ${expiry})`;
|
|
24921
|
+
};
|
|
24168
24922
|
var createConnectionCommands = (overrides = {}) => {
|
|
24169
24923
|
const services = {
|
|
24170
24924
|
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
24925
|
+
envToken: process.env.QADET_TOKEN?.trim(),
|
|
24171
24926
|
ask,
|
|
24172
24927
|
verify: async (connection) => {
|
|
24173
24928
|
const response = await webAppAt(connection).request("/api/connection", {});
|
|
@@ -24180,8 +24935,8 @@ var createConnectionCommands = (overrides = {}) => {
|
|
|
24180
24935
|
const { agent: agent2 } = await Promise.resolve().then(() => (init_agent2(), agent_exports));
|
|
24181
24936
|
await agent2.run([]);
|
|
24182
24937
|
},
|
|
24183
|
-
write: (
|
|
24184
|
-
process.stdout.write(
|
|
24938
|
+
write: (message2) => {
|
|
24939
|
+
process.stdout.write(message2);
|
|
24185
24940
|
},
|
|
24186
24941
|
...overrides
|
|
24187
24942
|
};
|
|
@@ -24192,16 +24947,18 @@ var createConnectionCommands = (overrides = {}) => {
|
|
|
24192
24947
|
const positionals = parseArgs2({ args: args2, allowPositionals: true }).positionals;
|
|
24193
24948
|
if (positionals.length > 2) throw new Error("Usage: qadet connect [url] [token]");
|
|
24194
24949
|
const [givenUrl, givenToken] = positionals;
|
|
24195
|
-
|
|
24950
|
+
const resolvedToken = givenToken ?? services.envToken;
|
|
24951
|
+
if ((!givenUrl || !resolvedToken) && !services.interactive)
|
|
24196
24952
|
throw new Error(
|
|
24197
24953
|
"Run qadet connect in a terminal, or provide both the workspace URL and token"
|
|
24198
24954
|
);
|
|
24199
24955
|
const url2 = normalizeUrl(givenUrl ?? await services.ask("Workspace URL: "));
|
|
24200
|
-
if (!
|
|
24956
|
+
if (!resolvedToken) services.write(`Create a runner token at ${url2}/tokens.
|
|
24201
24957
|
`);
|
|
24202
|
-
const token =
|
|
24958
|
+
const token = resolvedToken ?? await services.ask("Runner token (hidden): ", true);
|
|
24203
24959
|
if (!token.trim()) throw new Error("A runner token is required");
|
|
24204
|
-
const
|
|
24960
|
+
const runnerId = (await services.read().catch(() => void 0))?.runnerId ?? randomUUID4();
|
|
24961
|
+
const connection = { url: url2, token: token.trim(), runnerId };
|
|
24205
24962
|
const { organization, user } = await services.verify(connection);
|
|
24206
24963
|
const path = await services.save(connection);
|
|
24207
24964
|
services.write(`Connected to ${organization} as ${user}. Saved to ${path}.
|
|
@@ -24228,12 +24985,14 @@ var createConnectionCommands = (overrides = {}) => {
|
|
|
24228
24985
|
);
|
|
24229
24986
|
});
|
|
24230
24987
|
const online = details.runnerOnline === void 0 ? "unknown (workspace update required)" : details.runnerOnline ? "online" : "offline";
|
|
24988
|
+
const tokenLine = details.token ? `Token: ${describeToken(details.token)}
|
|
24989
|
+
` : "";
|
|
24231
24990
|
services.write(
|
|
24232
24991
|
`Connection: verified
|
|
24233
24992
|
Workspace: ${connection.url}
|
|
24234
24993
|
User: ${details.user}
|
|
24235
24994
|
Organization: ${details.organization}
|
|
24236
|
-
Version: ${runnerVersion}
|
|
24995
|
+
${tokenLine}Version: ${runnerVersion}
|
|
24237
24996
|
Runner: ${online}
|
|
24238
24997
|
`
|
|
24239
24998
|
);
|
|
@@ -24411,6 +25170,7 @@ var snapshot = {
|
|
|
24411
25170
|
hostMap: [],
|
|
24412
25171
|
acceptInvalidCertificates: false,
|
|
24413
25172
|
allowedHosts: [],
|
|
25173
|
+
device: "desktop",
|
|
24414
25174
|
videoRecording: {
|
|
24415
25175
|
enabled: false,
|
|
24416
25176
|
mode: "disabled",
|