@monkeytestai/monkeytester 0.7.2-beta.2 → 0.7.2-beta.3
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/CHANGELOG.md +18 -0
- package/README.md +37 -15
- package/dist/audit/adjudication.d.ts +107 -0
- package/dist/audit/adjudication.d.ts.map +1 -0
- package/dist/audit/adjudication.js +164 -0
- package/dist/audit/adjudication.js.map +1 -0
- package/dist/auth/bind.d.ts +21 -0
- package/dist/auth/bind.d.ts.map +1 -0
- package/dist/auth/bind.js +152 -0
- package/dist/auth/bind.js.map +1 -0
- package/dist/auth/browser.d.ts +36 -0
- package/dist/auth/browser.d.ts.map +1 -0
- package/dist/auth/browser.js +64 -0
- package/dist/auth/browser.js.map +1 -0
- package/dist/auth/contract.d.ts +145 -0
- package/dist/auth/contract.d.ts.map +1 -0
- package/dist/auth/contract.js +50 -0
- package/dist/auth/contract.js.map +1 -0
- package/dist/auth/createProvider.d.ts +42 -0
- package/dist/auth/createProvider.d.ts.map +1 -0
- package/dist/auth/createProvider.js +152 -0
- package/dist/auth/createProvider.js.map +1 -0
- package/dist/auth/egress.d.ts +37 -0
- package/dist/auth/egress.d.ts.map +1 -0
- package/dist/auth/egress.js +117 -0
- package/dist/auth/egress.js.map +1 -0
- package/dist/auth/establish.d.ts +56 -0
- package/dist/auth/establish.d.ts.map +1 -0
- package/dist/auth/establish.js +346 -0
- package/dist/auth/establish.js.map +1 -0
- package/dist/auth/fence.d.ts +16 -0
- package/dist/auth/fence.d.ts.map +1 -0
- package/dist/auth/fence.js +215 -0
- package/dist/auth/fence.js.map +1 -0
- package/dist/auth/index.d.ts +16 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +11 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/origins.d.ts +64 -0
- package/dist/auth/origins.d.ts.map +1 -0
- package/dist/auth/origins.js +443 -0
- package/dist/auth/origins.js.map +1 -0
- package/dist/auth/proof.d.ts +31 -0
- package/dist/auth/proof.d.ts.map +1 -0
- package/dist/auth/proof.js +104 -0
- package/dist/auth/proof.js.map +1 -0
- package/dist/auth/provider.d.ts +19 -0
- package/dist/auth/provider.d.ts.map +1 -0
- package/dist/auth/provider.js +74 -0
- package/dist/auth/provider.js.map +1 -0
- package/dist/auth/redact.d.ts +37 -0
- package/dist/auth/redact.d.ts.map +1 -0
- package/dist/auth/redact.js +126 -0
- package/dist/auth/redact.js.map +1 -0
- package/dist/auth/report.d.ts +32 -0
- package/dist/auth/report.d.ts.map +1 -0
- package/dist/auth/report.js +110 -0
- package/dist/auth/report.js.map +1 -0
- package/dist/auth/resolve.d.ts +41 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +119 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/secretInput.d.ts +13 -0
- package/dist/auth/secretInput.d.ts.map +1 -0
- package/dist/auth/secretInput.js +39 -0
- package/dist/auth/secretInput.js.map +1 -0
- package/dist/auth/secrets.d.ts +33 -0
- package/dist/auth/secrets.d.ts.map +1 -0
- package/dist/auth/secrets.js +211 -0
- package/dist/auth/secrets.js.map +1 -0
- package/dist/auth/sessionFile.d.ts +47 -0
- package/dist/auth/sessionFile.d.ts.map +1 -0
- package/dist/auth/sessionFile.js +219 -0
- package/dist/auth/sessionFile.js.map +1 -0
- package/dist/checks/execute.d.ts +4 -0
- package/dist/checks/execute.d.ts.map +1 -1
- package/dist/checks/execute.js +55 -10
- package/dist/checks/execute.js.map +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +330 -6
- package/dist/cli.js.map +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +9 -1
- package/dist/events.js.map +1 -1
- package/dist/explorer/index.d.ts +13 -5
- package/dist/explorer/index.d.ts.map +1 -1
- package/dist/explorer/index.js +133 -35
- package/dist/explorer/index.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/monkey.d.ts +6 -0
- package/dist/monkey.d.ts.map +1 -1
- package/dist/monkey.js +160 -16
- package/dist/monkey.js.map +1 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +14 -0
- package/dist/outcome.js.map +1 -1
- package/dist/persistence/index.d.ts.map +1 -1
- package/dist/persistence/index.js +3 -2
- package/dist/persistence/index.js.map +1 -1
- package/dist/planner/index.d.ts +2 -0
- package/dist/planner/index.d.ts.map +1 -1
- package/dist/planner/index.js +3 -1
- package/dist/planner/index.js.map +1 -1
- package/dist/reportPaths.d.ts +19 -0
- package/dist/reportPaths.d.ts.map +1 -0
- package/dist/reportPaths.js +25 -0
- package/dist/reportPaths.js.map +1 -0
- package/dist/runner/actions.d.ts +1 -0
- package/dist/runner/actions.d.ts.map +1 -1
- package/dist/runner/actions.js +18 -2
- package/dist/runner/actions.js.map +1 -1
- package/dist/runner/authNegative.d.ts +1 -0
- package/dist/runner/authNegative.d.ts.map +1 -1
- package/dist/runner/authNegative.js +3 -0
- package/dist/runner/authNegative.js.map +1 -1
- package/dist/runner/evidence.d.ts.map +1 -1
- package/dist/runner/evidence.js +21 -8
- package/dist/runner/evidence.js.map +1 -1
- package/dist/runner/index.d.ts +17 -0
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +118 -7
- package/dist/runner/index.js.map +1 -1
- package/dist/runner/replay.d.ts +18 -1
- package/dist/runner/replay.d.ts.map +1 -1
- package/dist/runner/replay.js +105 -4
- package/dist/runner/replay.js.map +1 -1
- package/dist/runner/sensitive.d.ts +7 -1
- package/dist/runner/sensitive.d.ts.map +1 -1
- package/dist/runner/sensitive.js +58 -36
- package/dist/runner/sensitive.js.map +1 -1
- package/dist/starNudge.d.ts +74 -0
- package/dist/starNudge.d.ts.map +1 -0
- package/dist/starNudge.js +88 -0
- package/dist/starNudge.js.map +1 -0
- package/dist/types.d.ts +16 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/verify/index.d.ts +6 -0
- package/dist/verify/index.d.ts.map +1 -1
- package/dist/verify/index.js +62 -5
- package/dist/verify/index.js.map +1 -1
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* monkeytest diff <a> <b> Diff two stored runs by bug fingerprint.
|
|
16
16
|
* "<a>" / "<b>" are run ids or "latest"/"prev".
|
|
17
17
|
* monkeytest report [<runId>] Pretty-print a stored run (flows, bugs, paths).
|
|
18
|
+
* monkeytest open [<runId>] Print local paths for that run and its evidence.
|
|
18
19
|
*
|
|
19
20
|
* Common flags:
|
|
20
21
|
* --dir <path> Working directory (default ./.monkeytest)
|
|
@@ -52,8 +53,11 @@ import { replayTraces } from './runner/replay.js';
|
|
|
52
53
|
import { triage } from './triager/index.js';
|
|
53
54
|
import { verifyBugs } from './verify/index.js';
|
|
54
55
|
import { ENGINE_VERSION } from './version.js';
|
|
56
|
+
import { collectEvidencePaths } from './reportPaths.js';
|
|
57
|
+
import { starMarkerName, starNudgeLine } from './starNudge.js';
|
|
55
58
|
import { createHttpInbox } from './inbox/http.js';
|
|
56
59
|
import { loadInboxProvider } from './inbox/load.js';
|
|
60
|
+
import { authBlockedRun, authProcessExit, defaultSessionPath, deleteAuthSession, parseTtl, readSecretLine, rejectCredentialArg, resolveAuthInvocation, } from './auth/index.js';
|
|
57
61
|
/* ── Tiny ANSI helpers (no chalk dep) ─────────────────────────────────── */
|
|
58
62
|
const c = {
|
|
59
63
|
reset: '\x1b[0m',
|
|
@@ -83,6 +87,13 @@ function defaultCommonOpts() {
|
|
|
83
87
|
heal: false,
|
|
84
88
|
repeat: 1,
|
|
85
89
|
failOn5xx: true,
|
|
90
|
+
noStar: false,
|
|
91
|
+
authManual: false,
|
|
92
|
+
useSession: false,
|
|
93
|
+
saveSession: false,
|
|
94
|
+
deleteSession: false,
|
|
95
|
+
passwordStdin: false,
|
|
96
|
+
idpOrigins: [],
|
|
86
97
|
};
|
|
87
98
|
}
|
|
88
99
|
function parseArgs(argv) {
|
|
@@ -164,6 +175,9 @@ function parseArgs(argv) {
|
|
|
164
175
|
case '--json':
|
|
165
176
|
out.opts.json = true;
|
|
166
177
|
break;
|
|
178
|
+
case '--no-star':
|
|
179
|
+
out.opts.noStar = true;
|
|
180
|
+
break;
|
|
167
181
|
case '--fail-on-5xx':
|
|
168
182
|
out.opts.failOn5xx = true;
|
|
169
183
|
break;
|
|
@@ -184,6 +198,74 @@ function parseArgs(argv) {
|
|
|
184
198
|
out.opts.inboxHttp = url;
|
|
185
199
|
break;
|
|
186
200
|
}
|
|
201
|
+
case '--auth': {
|
|
202
|
+
const mode = next();
|
|
203
|
+
if (mode !== 'manual')
|
|
204
|
+
die(2, '--auth only supports manual. Form login uses --username-env and --password-env.');
|
|
205
|
+
out.opts.authManual = true;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case '--use-session':
|
|
209
|
+
out.opts.useSession = true;
|
|
210
|
+
break;
|
|
211
|
+
case '--save-session':
|
|
212
|
+
out.opts.saveSession = true;
|
|
213
|
+
break;
|
|
214
|
+
case '--delete':
|
|
215
|
+
out.opts.deleteSession = true;
|
|
216
|
+
break;
|
|
217
|
+
case '--session': {
|
|
218
|
+
const path = next();
|
|
219
|
+
if (!path)
|
|
220
|
+
die(2, '--session requires a path ending in auth/session.json');
|
|
221
|
+
out.opts.sessionPath = path;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case '--session-ttl': {
|
|
225
|
+
const ttl = next();
|
|
226
|
+
if (!ttl)
|
|
227
|
+
die(2, '--session-ttl requires a value such as 12h');
|
|
228
|
+
out.opts.sessionTtl = ttl;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
case '--username-env': {
|
|
232
|
+
const name = next();
|
|
233
|
+
if (!name)
|
|
234
|
+
die(2, '--username-env requires an uppercase variable name');
|
|
235
|
+
out.opts.usernameEnv = name;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
case '--password-env': {
|
|
239
|
+
const name = next();
|
|
240
|
+
if (!name)
|
|
241
|
+
die(2, '--password-env requires an uppercase variable name');
|
|
242
|
+
out.opts.passwordEnv = name;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case '--password-stdin':
|
|
246
|
+
out.opts.passwordStdin = true;
|
|
247
|
+
break;
|
|
248
|
+
case '--idp-origin': {
|
|
249
|
+
const origin = next();
|
|
250
|
+
if (!origin)
|
|
251
|
+
die(2, '--idp-origin requires an absolute origin');
|
|
252
|
+
out.opts.idpOrigins.push(origin);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case '--post-login-url': {
|
|
256
|
+
const value = next();
|
|
257
|
+
if (!value)
|
|
258
|
+
die(2, '--post-login-url requires a path or absolute URL on the target');
|
|
259
|
+
out.opts.postLoginUrl = value;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
case '--post-login-selector': {
|
|
263
|
+
const value = next();
|
|
264
|
+
if (!value)
|
|
265
|
+
die(2, '--post-login-selector requires a selector that is visible after sign-in');
|
|
266
|
+
out.opts.postLoginSelector = value;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
187
269
|
case '--heal':
|
|
188
270
|
out.opts.heal = true;
|
|
189
271
|
break;
|
|
@@ -201,11 +283,15 @@ function parseArgs(argv) {
|
|
|
201
283
|
out.opts.repeat = n;
|
|
202
284
|
break;
|
|
203
285
|
}
|
|
204
|
-
default:
|
|
286
|
+
default: {
|
|
287
|
+
const rejected = rejectCredentialArg(a);
|
|
288
|
+
if (rejected)
|
|
289
|
+
die(2, rejected);
|
|
205
290
|
if (a.startsWith('-')) {
|
|
206
291
|
die(2, `Unknown flag: ${a}`);
|
|
207
292
|
}
|
|
208
293
|
out.positional.push(a);
|
|
294
|
+
}
|
|
209
295
|
}
|
|
210
296
|
}
|
|
211
297
|
if (out.opts.depth) {
|
|
@@ -291,6 +377,9 @@ Commands:
|
|
|
291
377
|
${tty('verify', 'cyan')} [run] Replay each bug trace and print a verdict.
|
|
292
378
|
${tty('diff', 'cyan')} <runA> <runB> Diff two stored runs by bug fingerprint.
|
|
293
379
|
${tty('report', 'cyan')} [<runId>] Pretty-print a stored run.
|
|
380
|
+
${tty('open', 'cyan')} [<runId>] Print local evidence paths. Unreleased in this tree.
|
|
381
|
+
${tty('auth', 'cyan')} login <url> Headed local sign-in. Saves auth/session.json.
|
|
382
|
+
${tty('auth', 'cyan')} logout --delete Deletes that local file. Does not sign the site out.
|
|
294
383
|
${tty('help', 'cyan')} [<command>] Show help (this page or per-command).
|
|
295
384
|
${tty('version', 'cyan')} Print engine version and exit.
|
|
296
385
|
|
|
@@ -312,10 +401,25 @@ Common flags (apply to most commands):
|
|
|
312
401
|
--repeat <n> Replay each bug n times (verify, default 1)
|
|
313
402
|
--bug <fingerprint> Verify one bug
|
|
314
403
|
--json Machine-readable output
|
|
404
|
+
--no-star Do not print the one-time star link
|
|
315
405
|
--fail-on-5xx Fail steps that saw a same-origin HTTP ≥500 (default)
|
|
316
406
|
--no-fail-on-5xx Keep those 5xx responses as evidence only
|
|
317
407
|
--inbox <module> Module that exports your InboxProvider (no hosted inbox)
|
|
318
408
|
--inbox-http <url> Your HTTP inbox API (MONKEYTEST_INBOX_TOKEN). No default host.
|
|
409
|
+
--auth manual Headed sign-in for this run. No password flag.
|
|
410
|
+
--use-session Load the local session file for this command only.
|
|
411
|
+
--save-session Write auth/session.json after a successful sign-in.
|
|
412
|
+
--session <path> Session file. Must be named auth/session.json.
|
|
413
|
+
--session-ttl <dur> Opt-in expiry: 30m, 12h, or 7d. No default.
|
|
414
|
+
--username-env <NAME> Env var NAME for the account. Not the account itself.
|
|
415
|
+
--password-env <NAME> Env var NAME for the password. Not the password.
|
|
416
|
+
--post-login-url <path> URL path that exists only after sign-in
|
|
417
|
+
--post-login-selector <css> Selector that exists only after sign-in
|
|
418
|
+
--password-stdin Hidden prompt, or one stdin line when there is no TTY.
|
|
419
|
+
--idp-origin <origin> Extra origin allowed during sign-in. Repeatable.
|
|
420
|
+
|
|
421
|
+
Env vars named above are visible to the shell, CI logs, and process listings.
|
|
422
|
+
Do not pass the password as an argument. The hosted product does not take these credentials.
|
|
319
423
|
|
|
320
424
|
Exit codes: 0 ok · 1 bugs still firing · 2 bad args / setup · 3 engine error.
|
|
321
425
|
|
|
@@ -368,6 +472,28 @@ shortcuts. Prints new / fixed / persisting / regressed bugs.`,
|
|
|
368
472
|
report: `monkeytest report [<runId>] [--json]
|
|
369
473
|
Pretty-print a stored run (flows, bugs, evidence paths). Defaults to
|
|
370
474
|
"latest". Use --json for machine-readable output.`,
|
|
475
|
+
open: `monkeytest open [<runId>] [--json]
|
|
476
|
+
Unreleased: this command is in this source tree and is not in the published
|
|
477
|
+
npm dist-tags. Print the absolute path of a stored run and the screenshot
|
|
478
|
+
and WebM paths already recorded on it. Does not upload them, does not fetch
|
|
479
|
+
the site, and does not launch a browser. Defaults to "latest".`,
|
|
480
|
+
auth: `monkeytest auth login <url> [--idp-origin <origin>] [--session-ttl 12h]
|
|
481
|
+
Open a headed browser on that exact origin. You log in, including MFA or SSO.
|
|
482
|
+
Press Enter here to save .monkeytest/auth/session.json (file mode 600, directory mode 700).
|
|
483
|
+
The file is not uploaded. Deleting it later does not sign the website out.
|
|
484
|
+
|
|
485
|
+
monkeytest auth logout --delete
|
|
486
|
+
Remove the local file only.
|
|
487
|
+
|
|
488
|
+
Form login, instead of the headed browser:
|
|
489
|
+
monkeytest run <url> --username-env MONKEYTEST_USERNAME --password-env MONKEYTEST_PASSWORD
|
|
490
|
+
monkeytest run <url> --username-env MONKEYTEST_USERNAME --password-stdin
|
|
491
|
+
|
|
492
|
+
Those are variable names, not secret values. Form and manual sign-in also need
|
|
493
|
+
--post-login-url or --post-login-selector. Without that proof the run is
|
|
494
|
+
could_not_test, not a pass. A rerun does not reuse the session unless you pass
|
|
495
|
+
--use-session or a new password reference. An expired session is expired. It
|
|
496
|
+
is not a verified run.`,
|
|
371
497
|
};
|
|
372
498
|
console.log(text[cmd] || `No help for "${cmd}". Try \`monkeytest help\`.`);
|
|
373
499
|
}
|
|
@@ -394,22 +520,123 @@ async function cmdInit(opts) {
|
|
|
394
520
|
'# MonkeyTest local artefacts',
|
|
395
521
|
'shots/',
|
|
396
522
|
'runs/',
|
|
523
|
+
'auth/',
|
|
397
524
|
'*.tmp',
|
|
398
525
|
'',
|
|
399
526
|
'# Keep config + plan tracked',
|
|
400
527
|
'!config.json',
|
|
401
528
|
'!plan.json',
|
|
529
|
+
'.star-noted',
|
|
402
530
|
'',
|
|
403
531
|
].join('\n'));
|
|
404
532
|
}
|
|
405
533
|
console.log(`${tty('✓', 'green')} Initialised ${tty(relative(process.cwd(), dir) || '.', 'cyan')}/`);
|
|
406
534
|
console.log(` Tracked: config.json, plan.json (after first run)`);
|
|
407
|
-
console.log(` Ignored: shots/, runs/`);
|
|
535
|
+
console.log(` Ignored: shots/, runs/, auth/`);
|
|
408
536
|
console.log(`\nNext: ${tty('monkeytest run https://example.com', 'cyan')}`);
|
|
409
537
|
}
|
|
538
|
+
function authBind(prepared, opts) {
|
|
539
|
+
if (prepared.kind !== 'ready')
|
|
540
|
+
return undefined;
|
|
541
|
+
return {
|
|
542
|
+
targetOrigin: prepared.authOrigin.targetOrigin,
|
|
543
|
+
idpOrigins: prepared.authOrigin.idpOrigins,
|
|
544
|
+
storageState: prepared.storageState,
|
|
545
|
+
...(prepared.metadata.expiresAt ? { expiresAt: prepared.metadata.expiresAt } : {}),
|
|
546
|
+
...(opts.postLoginUrl ? { postLoginUrl: opts.postLoginUrl } : {}),
|
|
547
|
+
...(opts.postLoginSelector ? { postLoginSelector: opts.postLoginSelector } : {}),
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
async function prepareAuth(url, opts, extra = {}) {
|
|
551
|
+
const persist = Boolean(extra.persist || opts.saveSession);
|
|
552
|
+
const fresh = Boolean(opts.passwordEnv || opts.passwordStdin);
|
|
553
|
+
const wants = opts.authManual || opts.useSession || fresh || persist || extra.prior?.outcome === 'authenticated';
|
|
554
|
+
if (!wants)
|
|
555
|
+
return { kind: 'anonymous' };
|
|
556
|
+
if (opts.sessionTtl && !persist)
|
|
557
|
+
die(2, '--session-ttl applies when saving a session (--save-session or auth login).');
|
|
558
|
+
let sessionTtlMs;
|
|
559
|
+
try {
|
|
560
|
+
sessionTtlMs = parseTtl(opts.sessionTtl);
|
|
561
|
+
}
|
|
562
|
+
catch (err) {
|
|
563
|
+
die(2, err instanceof Error ? err.message : String(err));
|
|
564
|
+
}
|
|
565
|
+
if (opts.authManual && !process.stdin.isTTY) {
|
|
566
|
+
die(2, 'Manual login needs a terminal so you can finish SSO or a second factor. Nothing was opened.');
|
|
567
|
+
}
|
|
568
|
+
let passwordFromStdin;
|
|
569
|
+
if (opts.passwordStdin)
|
|
570
|
+
passwordFromStdin = await readSecretLine({ prompt: 'Password (input hidden): ' });
|
|
571
|
+
const sessionPath = (opts.useSession || persist) ? (opts.sessionPath || defaultSessionPath(opts.dir)) : undefined;
|
|
572
|
+
const resolution = await resolveAuthInvocation({
|
|
573
|
+
targetUrl: url,
|
|
574
|
+
idpOrigins: opts.idpOrigins,
|
|
575
|
+
usernameEnv: opts.usernameEnv,
|
|
576
|
+
passwordEnv: opts.passwordEnv,
|
|
577
|
+
passwordFromStdin,
|
|
578
|
+
useSession: opts.useSession,
|
|
579
|
+
saveSession: persist,
|
|
580
|
+
sessionPath,
|
|
581
|
+
sessionTtlMs,
|
|
582
|
+
manual: opts.authManual,
|
|
583
|
+
priorAuthenticated: extra.prior?.outcome === 'authenticated',
|
|
584
|
+
postLoginUrl: opts.postLoginUrl,
|
|
585
|
+
postLoginSelector: opts.postLoginSelector,
|
|
586
|
+
headless: opts.authManual ? false : opts.headless,
|
|
587
|
+
settle: opts.authManual
|
|
588
|
+
? async () => { await readSecretLine({ prompt: 'Log in in the browser, including any second factor, then press Enter. ' }); }
|
|
589
|
+
: undefined,
|
|
590
|
+
});
|
|
591
|
+
if (resolution.kind === 'anonymous')
|
|
592
|
+
return { kind: 'anonymous' };
|
|
593
|
+
if (resolution.kind === 'blocked') {
|
|
594
|
+
const run = triage(authBlockedRun(url, resolution.result.metadata));
|
|
595
|
+
return { kind: 'blocked', run, exitCode: authProcessExit(resolution.result.metadata.outcome, resolution.result.setup) };
|
|
596
|
+
}
|
|
597
|
+
return {
|
|
598
|
+
kind: 'ready',
|
|
599
|
+
storageState: resolution.result.storageState,
|
|
600
|
+
authOrigin: resolution.result.authOrigin,
|
|
601
|
+
metadata: resolution.result.metadata,
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
function finishBlockedAuth(run, exitCode, opts) {
|
|
605
|
+
const { path: runFile, id } = saveRun(run, { dir: opts.dir, engine: ENGINE_LABEL });
|
|
606
|
+
if (opts.json)
|
|
607
|
+
console.log(JSON.stringify({ run, runId: id, runFile }, null, 2));
|
|
608
|
+
else {
|
|
609
|
+
console.log(summariseRun(run));
|
|
610
|
+
console.log(` ${tty('run', 'dim')} → ${relative(process.cwd(), runFile)}`);
|
|
611
|
+
}
|
|
612
|
+
process.exit(exitCode);
|
|
613
|
+
}
|
|
614
|
+
async function cmdAuth(positional, opts) {
|
|
615
|
+
const sub = positional[0];
|
|
616
|
+
if (sub === 'logout') {
|
|
617
|
+
const result = deleteAuthSession(opts.sessionPath || defaultSessionPath(opts.dir), { confirm: opts.deleteSession });
|
|
618
|
+
console.log(result.detail);
|
|
619
|
+
if (!opts.deleteSession)
|
|
620
|
+
process.exit(2);
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (sub !== 'login')
|
|
624
|
+
die(2, 'Usage: monkeytest auth login <url> | monkeytest auth logout --delete');
|
|
625
|
+
const url = positional[1];
|
|
626
|
+
if (!url)
|
|
627
|
+
die(2, 'Usage: monkeytest auth login <url>');
|
|
628
|
+
opts.authManual = true;
|
|
629
|
+
const prepared = await prepareAuth(url, opts, { persist: true });
|
|
630
|
+
if (prepared.kind === 'blocked')
|
|
631
|
+
return finishBlockedAuth(prepared.run, prepared.exitCode, opts);
|
|
632
|
+
console.log('Saved the local session file. It was not uploaded. A later run needs --use-session. Deleting the file does not sign the website out.');
|
|
633
|
+
}
|
|
410
634
|
async function cmdExplore(url, opts) {
|
|
411
635
|
if (!url)
|
|
412
636
|
die(2, 'Usage: monkeytest explore <url>');
|
|
637
|
+
const prepared = await prepareAuth(url, opts);
|
|
638
|
+
if (prepared.kind === 'blocked')
|
|
639
|
+
return finishBlockedAuth(prepared.run, prepared.exitCode, opts);
|
|
413
640
|
ensureLLMReady(opts);
|
|
414
641
|
const monkey = new Monkey({ llm: buildLLMConfig(opts), plannerModel: opts.plannerModel, strictOracles: true, failOn5xx: opts.failOn5xx });
|
|
415
642
|
console.log(`\n→ Exploring ${tty(url, 'cyan')} (max ${opts.maxPages} pages, headless=${opts.headless})…\n`);
|
|
@@ -417,10 +644,11 @@ async function cmdExplore(url, opts) {
|
|
|
417
644
|
const screenshotsDir = resolve(opts.dir, 'shots');
|
|
418
645
|
mkdirSync(screenshotsDir, { recursive: true });
|
|
419
646
|
const { siteMap, plan } = await monkey.exploreAndPlan(url, {
|
|
647
|
+
...(authBind(prepared, opts) ? { auth: authBind(prepared, opts) } : {}),
|
|
420
648
|
explore: {
|
|
421
649
|
maxPages: opts.maxPages,
|
|
422
650
|
headless: opts.headless,
|
|
423
|
-
screenshotsDir,
|
|
651
|
+
screenshotsDir: prepared.kind === 'ready' ? undefined : screenshotsDir,
|
|
424
652
|
pageTimeoutMs: opts.pageTimeoutMs,
|
|
425
653
|
onPage: (p) => console.log(` · visited [${p.authGated ? 'auth' : 'open'}] ${p.url} — ${truncate(p.summary, 80)}`),
|
|
426
654
|
},
|
|
@@ -440,6 +668,9 @@ async function cmdExplore(url, opts) {
|
|
|
440
668
|
async function cmdRun(url, opts) {
|
|
441
669
|
if (!url)
|
|
442
670
|
die(2, 'Usage: monkeytest run <url>');
|
|
671
|
+
const prepared = await prepareAuth(url, opts);
|
|
672
|
+
if (prepared.kind === 'blocked')
|
|
673
|
+
return finishBlockedAuth(prepared.run, prepared.exitCode, opts);
|
|
443
674
|
ensureLLMReady(opts);
|
|
444
675
|
const screenshotsDir = resolve(opts.dir, 'shots');
|
|
445
676
|
mkdirSync(screenshotsDir, { recursive: true });
|
|
@@ -448,10 +679,11 @@ async function cmdRun(url, opts) {
|
|
|
448
679
|
console.log(`\n→ Running ${tty(url, 'cyan')} (max ${opts.maxPages} pages, ${opts.maxFlows} flows, headless=${opts.headless})…\n`);
|
|
449
680
|
const t0 = Date.now();
|
|
450
681
|
const { siteMap, plan, run } = await monkey.executeAndTriage(url, {
|
|
682
|
+
...(authBind(prepared, opts) ? { auth: authBind(prepared, opts) } : {}),
|
|
451
683
|
explore: {
|
|
452
684
|
maxPages: opts.maxPages,
|
|
453
685
|
headless: opts.headless,
|
|
454
|
-
screenshotsDir,
|
|
686
|
+
screenshotsDir: prepared.kind === 'ready' ? undefined : screenshotsDir,
|
|
455
687
|
pageTimeoutMs: opts.pageTimeoutMs,
|
|
456
688
|
onPage: (p) => console.log(` · visited ${p.url}`),
|
|
457
689
|
},
|
|
@@ -512,6 +744,9 @@ async function cmdRerun(runId, opts) {
|
|
|
512
744
|
return rerunStoredPlan(stored, opts);
|
|
513
745
|
}
|
|
514
746
|
async function replayStoredRun(stored, traces, opts) {
|
|
747
|
+
const prepared = await prepareAuth(stored.run.startUrl, opts, { prior: stored.run.auth });
|
|
748
|
+
if (prepared.kind === 'blocked')
|
|
749
|
+
return finishBlockedAuth(prepared.run, prepared.exitCode, opts);
|
|
515
750
|
if (opts.heal)
|
|
516
751
|
ensureLLMReady(opts);
|
|
517
752
|
const screenshotsDir = resolve(opts.dir, 'shots');
|
|
@@ -525,8 +760,18 @@ async function replayStoredRun(stored, traces, opts) {
|
|
|
525
760
|
llm: opts.heal ? runnerLLM(opts) : undefined,
|
|
526
761
|
strictOracles: true,
|
|
527
762
|
failOn5xx: opts.failOn5xx,
|
|
763
|
+
...(prepared.kind === 'ready' ? {
|
|
764
|
+
storageState: prepared.storageState,
|
|
765
|
+
authOrigin: prepared.authOrigin,
|
|
766
|
+
...(prepared.metadata.expiresAt ? { sessionExpiresAt: prepared.metadata.expiresAt } : {}),
|
|
767
|
+
...(opts.postLoginUrl ? { postLoginUrl: opts.postLoginUrl } : {}),
|
|
768
|
+
...(opts.postLoginSelector ? { postLoginSelector: opts.postLoginSelector } : {}),
|
|
769
|
+
} : {}),
|
|
528
770
|
});
|
|
529
|
-
const
|
|
771
|
+
const triaged = triage(raw, { failOn5xx: opts.failOn5xx });
|
|
772
|
+
const run = raw.auth && raw.auth.outcome !== 'authenticated'
|
|
773
|
+
? { ...triaged, auth: raw.auth }
|
|
774
|
+
: prepared.kind === 'ready' ? { ...triaged, auth: prepared.metadata } : triaged;
|
|
530
775
|
const dt = ((Date.now() - t0) / 1000).toFixed(1);
|
|
531
776
|
const { path: runFile, id: newRunId } = saveRun(run, {
|
|
532
777
|
dir: opts.dir,
|
|
@@ -548,7 +793,6 @@ async function replayStoredRun(stored, traces, opts) {
|
|
|
548
793
|
exitIfBlocking(run);
|
|
549
794
|
}
|
|
550
795
|
async function rerunStoredPlan(stored, opts) {
|
|
551
|
-
ensureLLMReady(opts);
|
|
552
796
|
// Resolve plan: an explicit run means "use the plan stored alongside that run",
|
|
553
797
|
// otherwise just load the canonical plan.json.
|
|
554
798
|
let storedPlan;
|
|
@@ -565,12 +809,17 @@ async function rerunStoredPlan(stored, opts) {
|
|
|
565
809
|
storedPlan = loadPlan(opts.dir);
|
|
566
810
|
planSource = resolve(opts.dir, 'plan.json');
|
|
567
811
|
}
|
|
812
|
+
const prepared = await prepareAuth(storedPlan.plan.startUrl, opts, { prior: stored?.run.auth ?? storedPlan.plan.auth });
|
|
813
|
+
if (prepared.kind === 'blocked')
|
|
814
|
+
return finishBlockedAuth(prepared.run, prepared.exitCode, opts);
|
|
815
|
+
ensureLLMReady(opts);
|
|
568
816
|
const screenshotsDir = resolve(opts.dir, 'shots');
|
|
569
817
|
mkdirSync(screenshotsDir, { recursive: true });
|
|
570
818
|
const monkey = new Monkey({ llm: buildLLMConfig(opts), plannerModel: opts.plannerModel, strictOracles: true, failOn5xx: opts.failOn5xx });
|
|
571
819
|
console.log(`\n↻ Re-running ${storedPlan.plan.flows.length} flow(s) from ${tty(relative(process.cwd(), planSource), 'cyan')}…\n`);
|
|
572
820
|
const t0 = Date.now();
|
|
573
821
|
const { run } = await monkey.runFromPlan(storedPlan.plan, {
|
|
822
|
+
...(authBind(prepared, opts) ? { auth: authBind(prepared, opts) } : {}),
|
|
574
823
|
run: {
|
|
575
824
|
screenshotsDir,
|
|
576
825
|
headless: opts.headless,
|
|
@@ -604,6 +853,9 @@ async function rerunStoredPlan(stored, opts) {
|
|
|
604
853
|
}
|
|
605
854
|
async function cmdVerify(positional, opts) {
|
|
606
855
|
const stored = resolveStoredRun(positional, opts);
|
|
856
|
+
const prepared = await prepareAuth(stored.run.startUrl, opts, { prior: stored.run.auth });
|
|
857
|
+
if (prepared.kind === 'blocked')
|
|
858
|
+
return finishBlockedAuth(prepared.run, prepared.exitCode, opts);
|
|
607
859
|
if (opts.bug && !stored.run.bugs.some(bug => bugMatchesFingerprint(bug, opts.bug))) {
|
|
608
860
|
const known = stored.run.bugs.map(bug => bug.fingerprint).slice(0, 8).join(', ');
|
|
609
861
|
die(2, `No bug with fingerprint ${opts.bug} on run ${stored.id}.${known ? ` Known: ${known}` : ''}`);
|
|
@@ -619,6 +871,13 @@ async function cmdVerify(positional, opts) {
|
|
|
619
871
|
const report = await verifyBugs(stored.run, {
|
|
620
872
|
screenshotsDir,
|
|
621
873
|
headless: opts.headless,
|
|
874
|
+
...(prepared.kind === 'ready' ? {
|
|
875
|
+
storageState: prepared.storageState,
|
|
876
|
+
authOrigin: prepared.authOrigin,
|
|
877
|
+
...(prepared.metadata.expiresAt ? { sessionExpiresAt: prepared.metadata.expiresAt } : {}),
|
|
878
|
+
...(opts.postLoginUrl ? { postLoginUrl: opts.postLoginUrl } : {}),
|
|
879
|
+
...(opts.postLoginSelector ? { postLoginSelector: opts.postLoginSelector } : {}),
|
|
880
|
+
} : {}),
|
|
622
881
|
heal: opts.heal,
|
|
623
882
|
llm: opts.heal ? runnerLLM(opts) : undefined,
|
|
624
883
|
repeat: opts.repeat,
|
|
@@ -671,6 +930,23 @@ function cmdDiff(a, b, opts) {
|
|
|
671
930
|
if (diff.newBugs.length > 0 || diff.regressedBugs.length > 0) {
|
|
672
931
|
process.exit(1);
|
|
673
932
|
}
|
|
933
|
+
noteStar(opts, runB.run, { kind: 'diff', stats: diff.stats });
|
|
934
|
+
}
|
|
935
|
+
function cmdOpen(runId, opts) {
|
|
936
|
+
const stored = resolveStoredRun(runId, opts);
|
|
937
|
+
const runFile = storedRunFile(runId, opts, stored);
|
|
938
|
+
const evidence = collectEvidencePaths(stored.run);
|
|
939
|
+
if (opts.json) {
|
|
940
|
+
console.log(JSON.stringify({ runFile, evidence }, null, 2));
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
console.log(`Run file: ${runFile}`);
|
|
944
|
+
console.log('Evidence (local files, not uploaded):');
|
|
945
|
+
if (evidence.length === 0)
|
|
946
|
+
console.log(' (none recorded)');
|
|
947
|
+
for (const file of evidence)
|
|
948
|
+
console.log(` ${file}`);
|
|
949
|
+
console.log('Open those paths on this machine. This command does not fetch the site and does not start a browser.');
|
|
674
950
|
}
|
|
675
951
|
function cmdReport(runId, opts) {
|
|
676
952
|
const id = runId || 'latest';
|
|
@@ -857,6 +1133,52 @@ async function inboxFromOpts(opts) {
|
|
|
857
1133
|
const token = process.env.MONKEYTEST_INBOX_TOKEN;
|
|
858
1134
|
return createHttpInbox({ baseUrl: opts.inboxHttp, ...(token ? { token } : {}) });
|
|
859
1135
|
}
|
|
1136
|
+
function storedRunFile(positional, opts, stored) {
|
|
1137
|
+
if (positional) {
|
|
1138
|
+
const abs = resolve(positional);
|
|
1139
|
+
if (existsSync(abs) && !statSync(abs).isDirectory())
|
|
1140
|
+
return abs;
|
|
1141
|
+
}
|
|
1142
|
+
return resolve(opts.dir, 'runs', `${stored.id}.json`);
|
|
1143
|
+
}
|
|
1144
|
+
function noteStar(opts, run, signal) {
|
|
1145
|
+
const marker = resolve(opts.dir, starMarkerName());
|
|
1146
|
+
const line = starNudgeLine({
|
|
1147
|
+
json: opts.json,
|
|
1148
|
+
tty: Boolean(process.stdout.isTTY),
|
|
1149
|
+
ci: Boolean(process.env.CI),
|
|
1150
|
+
optOut: opts.noStar || process.env.MONKEYTEST_NO_STAR === '1',
|
|
1151
|
+
alreadyNoted: existsSync(marker),
|
|
1152
|
+
startUrl: run.startUrl,
|
|
1153
|
+
finishedAt: run.finishedAt,
|
|
1154
|
+
outcome: run.outcome,
|
|
1155
|
+
currentBugCount: run.bugs.length,
|
|
1156
|
+
warnings: run.warnings,
|
|
1157
|
+
outcome_detail: run.outcome_detail,
|
|
1158
|
+
flows: run.flows.map(flow => ({
|
|
1159
|
+
outcome_detail: flow.outcome_detail,
|
|
1160
|
+
description: flow.description,
|
|
1161
|
+
failureReason: flow.failureReason,
|
|
1162
|
+
steps: flow.steps.map(step => ({ observation: step.observation, error: step.error })),
|
|
1163
|
+
})),
|
|
1164
|
+
bugs: run.bugs.map(bug => ({
|
|
1165
|
+
title: bug.title,
|
|
1166
|
+
observed: bug.observed,
|
|
1167
|
+
expected: bug.expected,
|
|
1168
|
+
triageNotes: bug.triageNotes,
|
|
1169
|
+
})),
|
|
1170
|
+
signal,
|
|
1171
|
+
});
|
|
1172
|
+
if (!line)
|
|
1173
|
+
return;
|
|
1174
|
+
try {
|
|
1175
|
+
writeFileSync(marker, 'noted\n', { flag: 'wx' });
|
|
1176
|
+
}
|
|
1177
|
+
catch {
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
console.log(`\n${line}\n`);
|
|
1181
|
+
}
|
|
860
1182
|
function die(code, msg) {
|
|
861
1183
|
console.error(tty(msg, 'red'));
|
|
862
1184
|
process.exit(code);
|
|
@@ -883,6 +1205,8 @@ async function main() {
|
|
|
883
1205
|
case 'verify': return cmdVerify(args.positional[0], args.opts);
|
|
884
1206
|
case 'diff': return cmdDiff(args.positional[0], args.positional[1], args.opts);
|
|
885
1207
|
case 'report': return cmdReport(args.positional[0], args.opts);
|
|
1208
|
+
case 'open': return cmdOpen(args.positional[0], args.opts);
|
|
1209
|
+
case 'auth': return cmdAuth(args.positional, args.opts);
|
|
886
1210
|
default:
|
|
887
1211
|
console.error(tty(`Unknown command: ${args.command}`, 'red'));
|
|
888
1212
|
printHelp();
|