sedum-cli 0.1.0-alpha.11 → 0.1.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{affected-selection-WV5WY5NQ.js → affected-selection-KRK5HRF4.js} +7 -5
- package/dist/{chunk-HT6BIET2.js → chunk-A7HBQLEM.js} +188 -36
- package/dist/chunk-ACDJLEMS.js +508 -0
- package/dist/{chunk-HXQDSNLL.js → chunk-F4RD4S4P.js} +27 -46
- package/dist/{chunk-S7OB3JEF.js → chunk-GJ5QI7JQ.js} +38 -38
- package/dist/chunk-N5CTUO2A.js +27 -0
- package/dist/{chunk-FAGJCNV7.js → chunk-OKZ6VJKA.js} +145 -48
- package/dist/{chunk-AWBC7NOM.js → chunk-ZAACPFCW.js} +50 -2
- package/dist/cli.js +5 -3
- package/dist/{doctor-command-F4Y5KW36.js → doctor-command-KIGPIDQA.js} +3 -2
- package/dist/explore-command-NRRJADY4.js +25 -0
- package/dist/index.d.ts +21 -11
- package/dist/index.js +5 -3
- package/dist/{init-command-62IUO5LA.js → init-command-DEEVMROG.js} +81 -38
- package/dist/{run-command-ZEIANJWZ.js → run-command-EVUWZI4F.js} +75 -47
- package/package.json +5 -5
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readProjectEnvironment
|
|
3
|
+
} from "./chunk-OKZ6VJKA.js";
|
|
4
|
+
|
|
5
|
+
// src/explore-command.ts
|
|
6
|
+
import { randomInt } from "crypto";
|
|
7
|
+
import { mkdir as mkdir2, readFile, writeFile as writeFile3 } from "fs/promises";
|
|
8
|
+
import path3 from "path";
|
|
9
|
+
import { InvalidArgumentError } from "commander";
|
|
10
|
+
|
|
11
|
+
// src/explore-frames.ts
|
|
12
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
13
|
+
import path from "path";
|
|
14
|
+
var FrameRecorder = class _FrameRecorder {
|
|
15
|
+
constructor(directory, page, sensitive) {
|
|
16
|
+
this.directory = directory;
|
|
17
|
+
this.page = page;
|
|
18
|
+
this.sensitive = sensitive;
|
|
19
|
+
}
|
|
20
|
+
directory;
|
|
21
|
+
page;
|
|
22
|
+
sensitive;
|
|
23
|
+
#steps = /* @__PURE__ */ new Map();
|
|
24
|
+
/** Frame bytes by their path in the run directory, for the HTML report. */
|
|
25
|
+
bytes = /* @__PURE__ */ new Map();
|
|
26
|
+
static async create(directory, page, sensitiveOrigins) {
|
|
27
|
+
await mkdir(path.join(directory, "frames"), { recursive: true });
|
|
28
|
+
return new _FrameRecorder(directory, page, new Set(sensitiveOrigins));
|
|
29
|
+
}
|
|
30
|
+
get frames() {
|
|
31
|
+
return this.#steps;
|
|
32
|
+
}
|
|
33
|
+
async before(step, box) {
|
|
34
|
+
const file = await this.#capture(`frames/step-${step}-before.jpg`);
|
|
35
|
+
if (!file) return;
|
|
36
|
+
this.#frames(step).before = file;
|
|
37
|
+
if (box) this.#frames(step).box = box;
|
|
38
|
+
}
|
|
39
|
+
async after(step) {
|
|
40
|
+
const file = await this.#capture(`frames/step-${step}.jpg`);
|
|
41
|
+
if (file) this.#frames(step).after = file;
|
|
42
|
+
}
|
|
43
|
+
#frames(step) {
|
|
44
|
+
let frames = this.#steps.get(step);
|
|
45
|
+
if (!frames) this.#steps.set(step, frames = {});
|
|
46
|
+
return frames;
|
|
47
|
+
}
|
|
48
|
+
/** The frame's path in the run directory, or null when none was taken. */
|
|
49
|
+
async #capture(file) {
|
|
50
|
+
if (!this.page.captureFrame || this.#isSensitive()) return null;
|
|
51
|
+
const bytes = await this.page.captureFrame().catch(() => null);
|
|
52
|
+
if (!bytes) return null;
|
|
53
|
+
await writeFile(path.join(this.directory, file), bytes);
|
|
54
|
+
this.bytes.set(file, bytes);
|
|
55
|
+
return file;
|
|
56
|
+
}
|
|
57
|
+
#isSensitive() {
|
|
58
|
+
try {
|
|
59
|
+
return this.sensitive.has(new URL(this.page.url).origin);
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/explore-output.ts
|
|
67
|
+
import { writeFile as writeFile2 } from "fs/promises";
|
|
68
|
+
import path2 from "path";
|
|
69
|
+
async function writeExploreReports(directory, result, meta, frames) {
|
|
70
|
+
const { buildExploreRunResult } = await import("@sedum-dev/core");
|
|
71
|
+
const { renderExploreHtml, renderExploreMarkdown } = await import("@sedum-dev/reporters");
|
|
72
|
+
const run2 = buildExploreRunResult(result, meta);
|
|
73
|
+
const files = {
|
|
74
|
+
result: path2.join(directory, "result.json"),
|
|
75
|
+
markdown: path2.join(directory, "report.md"),
|
|
76
|
+
html: path2.join(directory, "report.html")
|
|
77
|
+
};
|
|
78
|
+
await writeFile2(files.result, `${JSON.stringify(run2, null, 2)}
|
|
79
|
+
`);
|
|
80
|
+
await writeFile2(files.markdown, renderExploreMarkdown(run2));
|
|
81
|
+
await writeFile2(files.html, renderExploreHtml(run2, { frames }));
|
|
82
|
+
return { run: run2, files };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/explore-command.ts
|
|
86
|
+
var EXPLORE_MODES = [
|
|
87
|
+
"guided",
|
|
88
|
+
"heuristic",
|
|
89
|
+
"random"
|
|
90
|
+
];
|
|
91
|
+
function exploreMode(value) {
|
|
92
|
+
if (!EXPLORE_MODES.includes(value))
|
|
93
|
+
throw new InvalidArgumentError(
|
|
94
|
+
`Expected one of ${EXPLORE_MODES.join(", ")}.`
|
|
95
|
+
);
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
function seedValue(value) {
|
|
99
|
+
const seed = /^\d{1,10}$/u.test(value) ? Number(value) : NaN;
|
|
100
|
+
if (!(seed <= 2147483647))
|
|
101
|
+
throw new InvalidArgumentError("Expected an integer from 0 to 2147483647.");
|
|
102
|
+
return seed;
|
|
103
|
+
}
|
|
104
|
+
function watched(options) {
|
|
105
|
+
const origins = options.watchOrigins ?? [];
|
|
106
|
+
const ignore = options.ignoreConsole ?? [];
|
|
107
|
+
const allow = options.detectAllow ?? [];
|
|
108
|
+
const oracles = {
|
|
109
|
+
...origins.length ? { watchOrigins: origins } : {},
|
|
110
|
+
...options.rejectedSubmits ? { rejectedSubmits: true } : {},
|
|
111
|
+
...ignore.length ? { ignoreConsole: ignore } : {},
|
|
112
|
+
...allow.length ? { allow } : {}
|
|
113
|
+
};
|
|
114
|
+
return Object.keys(oracles).length ? { oracles } : {};
|
|
115
|
+
}
|
|
116
|
+
function tuning(options) {
|
|
117
|
+
return { tuning: { safety: options.safety } };
|
|
118
|
+
}
|
|
119
|
+
function restoreLocalStorage(origin, items) {
|
|
120
|
+
return `(() => {
|
|
121
|
+
if (location.origin !== ${JSON.stringify(origin)}) return;
|
|
122
|
+
for (const { name, value } of ${JSON.stringify(items)})
|
|
123
|
+
if (localStorage.getItem(name) === null) localStorage.setItem(name, value);
|
|
124
|
+
})()`;
|
|
125
|
+
}
|
|
126
|
+
async function openPage(browser, cookies) {
|
|
127
|
+
const context = await browser.newContext({
|
|
128
|
+
viewport: { width: 1280, height: 720 }
|
|
129
|
+
});
|
|
130
|
+
const page = await context.newPage();
|
|
131
|
+
if (cookies) {
|
|
132
|
+
const state = JSON.parse(await readFile(cookies, "utf8"));
|
|
133
|
+
const native = page.playwright?.();
|
|
134
|
+
if (!native) throw new Error("Cookies need a Playwright browser.");
|
|
135
|
+
await native.context.addCookies(state.cookies ?? []);
|
|
136
|
+
for (const { origin, localStorage } of state.origins ?? [])
|
|
137
|
+
await native.context.addInitScript(
|
|
138
|
+
restoreLocalStorage(origin, localStorage)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
return { page, close: () => context.close() };
|
|
142
|
+
}
|
|
143
|
+
function collectText(value, previous = []) {
|
|
144
|
+
return [...previous, value];
|
|
145
|
+
}
|
|
146
|
+
function watchOrigin(value, previous = []) {
|
|
147
|
+
return [...previous, new URL(startUrl(value)).origin];
|
|
148
|
+
}
|
|
149
|
+
function startUrl(value) {
|
|
150
|
+
try {
|
|
151
|
+
const url = new URL(value);
|
|
152
|
+
if (url.protocol === "http:" || url.protocol === "https:") return url.href;
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
throw new InvalidArgumentError("Expected an absolute http or https URL.");
|
|
156
|
+
}
|
|
157
|
+
function describe(action) {
|
|
158
|
+
if (action.kind === "click")
|
|
159
|
+
return `click ${action.target.role} "${action.target.name}"`;
|
|
160
|
+
if (action.kind === "type")
|
|
161
|
+
return `type ${action.source.kind === "faker" ? action.source.generator : action.source.kind} into "${action.target.name}"`;
|
|
162
|
+
return action.kind;
|
|
163
|
+
}
|
|
164
|
+
function progressLine(entry) {
|
|
165
|
+
const kind = entry.pageKind ? ` [${entry.pageKind}]` : "";
|
|
166
|
+
const events = entry.events.length ? ` ! ${entry.events.map((e) => e.signature).join("; ")}` : "";
|
|
167
|
+
const outcome = entry.outcome === "acted" ? "" : ` (${entry.outcome})`;
|
|
168
|
+
return `${String(entry.step).padStart(4)} ${entry.route}${kind} ${describe(entry.action)}${outcome}${events}
|
|
169
|
+
`;
|
|
170
|
+
}
|
|
171
|
+
function cost(calls) {
|
|
172
|
+
const tokens = calls.reduce((sum, call) => sum + call.usage.inputTokens, 0);
|
|
173
|
+
const usd = calls.reduce((sum, call) => sum + (call.totalCostUsd ?? 0), 0);
|
|
174
|
+
return `${calls.length} calls, ${tokens} input tokens, $${usd.toFixed(5)}`;
|
|
175
|
+
}
|
|
176
|
+
async function launch(headed) {
|
|
177
|
+
const { PlaywrightBrowserDriver } = await import("@sedum-dev/core");
|
|
178
|
+
return new PlaywrightBrowserDriver().launch({
|
|
179
|
+
browser: "chromium",
|
|
180
|
+
headless: !headed
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async function advisor(mode, needed, provider = {}) {
|
|
184
|
+
if (mode !== "guided" && !needed) return void 0;
|
|
185
|
+
const { TypeSafeAdapter } = await import("@sedum-dev/provider-typesafe");
|
|
186
|
+
return new TypeSafeAdapter(provider);
|
|
187
|
+
}
|
|
188
|
+
async function exploreProvider(cwd, environment = process.env) {
|
|
189
|
+
const file = await readProjectEnvironment(cwd);
|
|
190
|
+
const value = (name) => environment[name]?.trim() || file[name]?.trim() || void 0;
|
|
191
|
+
const apiKey = value("TYPESAFE_API_KEY");
|
|
192
|
+
const baseURL = value("TYPESAFE_BASE_URL");
|
|
193
|
+
const model = value("TYPESAFE_DEFAULT_MODEL");
|
|
194
|
+
return {
|
|
195
|
+
...apiKey ? { apiKey } : {},
|
|
196
|
+
...baseURL ? { baseURL } : {},
|
|
197
|
+
...model ? { model } : {}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function traceEnd(result, step) {
|
|
201
|
+
let end = 0;
|
|
202
|
+
result.trace.forEach((entry, index) => {
|
|
203
|
+
if (entry.step <= step) end = index + 1;
|
|
204
|
+
});
|
|
205
|
+
return end;
|
|
206
|
+
}
|
|
207
|
+
async function shrinkFailures(browser, result, options, directory) {
|
|
208
|
+
const context = {
|
|
209
|
+
result,
|
|
210
|
+
options,
|
|
211
|
+
directory,
|
|
212
|
+
resolver: await advisor("guided", true, options.provider),
|
|
213
|
+
freshPage: () => openPage(browser, options.cookies),
|
|
214
|
+
calls: []
|
|
215
|
+
};
|
|
216
|
+
const tests = /* @__PURE__ */ new Map();
|
|
217
|
+
await mkdir2(path3.join(directory, "tests"), { recursive: true });
|
|
218
|
+
for (const [index, failure] of result.failures.entries())
|
|
219
|
+
tests.set(failure.signature, await shrinkOne(failure, index, context));
|
|
220
|
+
return { calls: context.calls, tests };
|
|
221
|
+
}
|
|
222
|
+
async function shrinkOne(failure, index, context) {
|
|
223
|
+
const { result, options } = context;
|
|
224
|
+
if (failure.kind === "semantic") {
|
|
225
|
+
options.write(` ${failure.signature}: page check, not shrunk
|
|
226
|
+
`);
|
|
227
|
+
return { notShrunk: "a page check needs Jev on every replay" };
|
|
228
|
+
}
|
|
229
|
+
const { shrink } = await import("@sedum-dev/core");
|
|
230
|
+
const actions = result.trace.map((entry) => entry.action);
|
|
231
|
+
const prefix = actions.slice(0, traceEnd(result, failure.step));
|
|
232
|
+
const shrunk = await shrink({
|
|
233
|
+
startUrl: result.startUrl,
|
|
234
|
+
actions: prefix,
|
|
235
|
+
signature: failure.signature,
|
|
236
|
+
freshPage: context.freshPage,
|
|
237
|
+
...watched(options)
|
|
238
|
+
});
|
|
239
|
+
if (!shrunk.reproduced) {
|
|
240
|
+
options.write(` ${failure.signature}: did not reproduce on replay
|
|
241
|
+
`);
|
|
242
|
+
return { notShrunk: "did not reproduce on replay" };
|
|
243
|
+
}
|
|
244
|
+
const test = await emitOne(
|
|
245
|
+
{ failure, index, actions: shrunk.actions, originalLength: prefix.length },
|
|
246
|
+
context
|
|
247
|
+
);
|
|
248
|
+
options.write(
|
|
249
|
+
` ${failure.signature}
|
|
250
|
+
${prefix.length} -> ${shrunk.actions.length} actions in ${shrunk.replays} replays; ${test.sentences.matched}/${test.sentences.located} sentences round-tripped; ${test.reproduced ? "reproduced" : "NOT reproduced"} by sentences
|
|
251
|
+
${path3.join(context.directory, test.path)}
|
|
252
|
+
`
|
|
253
|
+
);
|
|
254
|
+
return test;
|
|
255
|
+
}
|
|
256
|
+
async function emitOne(shrunk, context) {
|
|
257
|
+
const { failure, index, actions, originalLength } = shrunk;
|
|
258
|
+
const { emitTest } = await import("@sedum-dev/core");
|
|
259
|
+
const fresh = await context.freshPage();
|
|
260
|
+
try {
|
|
261
|
+
const emitted = await emitTest(fresh.page, context.resolver, {
|
|
262
|
+
startUrl: context.result.startUrl,
|
|
263
|
+
actions,
|
|
264
|
+
failure,
|
|
265
|
+
originalLength,
|
|
266
|
+
...watched(context.options)
|
|
267
|
+
});
|
|
268
|
+
context.calls.push(...emitted.calls);
|
|
269
|
+
const relative = `tests/finding-F${index + 1}.test.yaml`;
|
|
270
|
+
await writeFile3(path3.join(context.directory, relative), emitted.yaml);
|
|
271
|
+
const located = emitted.steps.filter((s) => s.roundTrip !== "n/a");
|
|
272
|
+
return {
|
|
273
|
+
path: relative,
|
|
274
|
+
yaml: emitted.yaml,
|
|
275
|
+
actionsBefore: originalLength,
|
|
276
|
+
actionsAfter: actions.length,
|
|
277
|
+
reproduced: emitted.reproduced,
|
|
278
|
+
sentences: {
|
|
279
|
+
matched: located.filter((s) => s.roundTrip === "matched").length,
|
|
280
|
+
located: located.length
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
} finally {
|
|
284
|
+
await fresh.close();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function summary(result) {
|
|
288
|
+
const kinds = Object.entries(result.kinds).map(([kind, n]) => `${kind} ${n}`).join(", ");
|
|
289
|
+
const lines = [
|
|
290
|
+
`
|
|
291
|
+
Explored ${result.trace.length} actions in ${(result.elapsedMs / 1e3).toFixed(1)}s (seed ${result.seed}, ${result.mode}).`,
|
|
292
|
+
`States: ${result.states} distinct, ${result.routes.length} routes.${kinds ? ` Page kinds: ${kinds}.` : ""}`,
|
|
293
|
+
result.skippedDestructive.length ? `Not clicked (destructive or session-ending): ${result.skippedDestructive.join(", ")}.` : "",
|
|
294
|
+
result.calls.length ? `Jev: ${cost(result.calls)}.` : "",
|
|
295
|
+
Object.keys(result.writes).length ? `Writes (successful non-GET requests): ${Object.entries(result.writes).map(([key, n]) => `${key} \xD7${n}`).join(", ")}.` : "No writes observed.",
|
|
296
|
+
result.stopReason ? `Stopped early: ${result.stopReason}` : "",
|
|
297
|
+
result.failures.length ? `Failures (${result.failures.length}):
|
|
298
|
+
${result.failures.map((f) => ` step ${f.step}: ${f.signature}`).join("\n")}` : "No failures observed."
|
|
299
|
+
];
|
|
300
|
+
return `${lines.filter(Boolean).join("\n")}
|
|
301
|
+
`;
|
|
302
|
+
}
|
|
303
|
+
var SAFETY_OFF = "Safety is off: the walk may delete, send or pay, but never logs itself out.\nUse --safe on shared or production-like data.\n";
|
|
304
|
+
function shownPath(file) {
|
|
305
|
+
const relative = path3.relative(process.cwd(), file);
|
|
306
|
+
return !relative || relative.startsWith("..") ? file : relative;
|
|
307
|
+
}
|
|
308
|
+
function runId(seed) {
|
|
309
|
+
return `${(/* @__PURE__ */ new Date()).toISOString().replaceAll(":", "-")}-seed-${seed}`;
|
|
310
|
+
}
|
|
311
|
+
async function openRun(options) {
|
|
312
|
+
const seed = options.seed ?? randomInt(2147483647);
|
|
313
|
+
const id = runId(seed);
|
|
314
|
+
const directory = path3.resolve(options.out, id);
|
|
315
|
+
await mkdir2(directory, { recursive: true });
|
|
316
|
+
const trace = path3.join(directory, "trace.jsonl");
|
|
317
|
+
const header = {
|
|
318
|
+
sedumExplore: 1,
|
|
319
|
+
startUrl: options.url,
|
|
320
|
+
seed,
|
|
321
|
+
mode: options.mode,
|
|
322
|
+
steps: options.steps
|
|
323
|
+
};
|
|
324
|
+
await writeFile3(trace, `${JSON.stringify(header)}
|
|
325
|
+
`);
|
|
326
|
+
options.write(
|
|
327
|
+
`Exploring ${options.url} (seed ${seed}, ${options.mode}). Trace: ${trace}
|
|
328
|
+
`
|
|
329
|
+
);
|
|
330
|
+
if (options.safety === "off") options.write(SAFETY_OFF);
|
|
331
|
+
return { seed, id, directory, trace, startedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
332
|
+
}
|
|
333
|
+
async function walk(page, place, frames, options) {
|
|
334
|
+
const { explore } = await import("@sedum-dev/core");
|
|
335
|
+
const guide = await advisor(options.mode, false, options.provider);
|
|
336
|
+
return explore(page, {
|
|
337
|
+
startUrl: options.url,
|
|
338
|
+
steps: options.steps,
|
|
339
|
+
seed: place.seed,
|
|
340
|
+
mode: options.mode,
|
|
341
|
+
...guide ? { advisor: guide } : {},
|
|
342
|
+
...tuning(options),
|
|
343
|
+
...watched(options),
|
|
344
|
+
...options.detect ? { detect: options.detect } : {},
|
|
345
|
+
...options.signal ? { signal: options.signal } : {},
|
|
346
|
+
...frames ? {
|
|
347
|
+
beforeAction: (step, _action, box) => frames.before(step, box ?? null)
|
|
348
|
+
} : {},
|
|
349
|
+
onStep: async (entry) => {
|
|
350
|
+
await frames?.after(entry.step);
|
|
351
|
+
options.write(progressLine(entry));
|
|
352
|
+
await writeFile3(place.trace, `${JSON.stringify(entry)}
|
|
353
|
+
`, { flag: "a" });
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
async function report(run2, options) {
|
|
358
|
+
const { browser, result, place, frames } = run2;
|
|
359
|
+
const shrunk = options.shrink && result.failures.length ? await shrinkReport(browser, result, options, place.directory) : null;
|
|
360
|
+
const { files } = await writeExploreReports(
|
|
361
|
+
place.directory,
|
|
362
|
+
result,
|
|
363
|
+
{
|
|
364
|
+
runId: place.id,
|
|
365
|
+
startedAt: place.startedAt,
|
|
366
|
+
requestedSteps: options.steps,
|
|
367
|
+
safety: options.safety,
|
|
368
|
+
detect: options.detect ?? "browser",
|
|
369
|
+
trace: "trace.jsonl",
|
|
370
|
+
directory: shownPath(place.directory),
|
|
371
|
+
...frames ? { frames: frames.frames } : {},
|
|
372
|
+
...shrunk ? { tests: shrunk.tests, extraCalls: shrunk.calls } : {}
|
|
373
|
+
},
|
|
374
|
+
frames?.bytes ?? /* @__PURE__ */ new Map()
|
|
375
|
+
);
|
|
376
|
+
options.write(
|
|
377
|
+
`result ${files.result}
|
|
378
|
+
markdown ${files.markdown}
|
|
379
|
+
report ${files.html}
|
|
380
|
+
`
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
async function executeExploreCommand(options) {
|
|
384
|
+
const place = await openRun(options);
|
|
385
|
+
const browser = await launch(options.headed);
|
|
386
|
+
try {
|
|
387
|
+
const { page, close } = await openPage(browser, options.cookies);
|
|
388
|
+
const frames = options.replay ? await FrameRecorder.create(
|
|
389
|
+
place.directory,
|
|
390
|
+
page,
|
|
391
|
+
options.sensitiveOrigins ?? []
|
|
392
|
+
) : null;
|
|
393
|
+
const result = await walk(page, place, frames, options);
|
|
394
|
+
await close();
|
|
395
|
+
options.write(summary(result));
|
|
396
|
+
await report({ browser, result, place, frames }, options);
|
|
397
|
+
return result.failures.length ? 1 : 0;
|
|
398
|
+
} finally {
|
|
399
|
+
await browser.close();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
async function shrinkReport(browser, result, options, directory) {
|
|
403
|
+
options.write("Shrinking failures:\n");
|
|
404
|
+
const shrunk = await shrinkFailures(browser, result, options, directory);
|
|
405
|
+
if (shrunk.calls.length)
|
|
406
|
+
options.write(`Locator round-trips: ${cost(shrunk.calls)}.
|
|
407
|
+
`);
|
|
408
|
+
return shrunk;
|
|
409
|
+
}
|
|
410
|
+
async function executeRerunCommand(options) {
|
|
411
|
+
const { replay } = await import("@sedum-dev/core");
|
|
412
|
+
const [first, ...rest] = (await readFile(options.trace, "utf8")).split("\n").filter(Boolean);
|
|
413
|
+
const header = JSON.parse(first ?? "{}");
|
|
414
|
+
if (!header.startUrl)
|
|
415
|
+
throw new InvalidArgumentError("Not an exploration trace.");
|
|
416
|
+
const actions = rest.map((line) => JSON.parse(line).action);
|
|
417
|
+
const browser = await launch(options.headed);
|
|
418
|
+
try {
|
|
419
|
+
const context = await browser.newContext({
|
|
420
|
+
viewport: { width: 1280, height: 720 }
|
|
421
|
+
});
|
|
422
|
+
const result = await replay(
|
|
423
|
+
await context.newPage(),
|
|
424
|
+
header.startUrl,
|
|
425
|
+
actions
|
|
426
|
+
);
|
|
427
|
+
const signatures = [...new Set(result.events.map((e) => e.signature))];
|
|
428
|
+
options.write(
|
|
429
|
+
`Reran ${result.divergedAt ?? actions.length} of ${actions.length} actions${result.divergedAt === void 0 ? "" : ` (diverged at action ${result.divergedAt})`}.
|
|
430
|
+
${signatures.length ? signatures.map((s) => ` ${s}`).join("\n") : "No failures observed."}
|
|
431
|
+
`
|
|
432
|
+
);
|
|
433
|
+
return signatures.length ? 1 : 0;
|
|
434
|
+
} finally {
|
|
435
|
+
await browser.close();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function safetyOf(safe) {
|
|
439
|
+
if (safe === void 0) return "off";
|
|
440
|
+
return safe === true ? "on" : safe;
|
|
441
|
+
}
|
|
442
|
+
async function run(url, flags, io) {
|
|
443
|
+
return executeExploreCommand({
|
|
444
|
+
url,
|
|
445
|
+
steps: flags.steps,
|
|
446
|
+
...flags.seed === void 0 ? {} : { seed: flags.seed },
|
|
447
|
+
mode: flags.mode,
|
|
448
|
+
out: path3.resolve(io.cwd, flags.out),
|
|
449
|
+
shrink: flags.shrink,
|
|
450
|
+
headed: flags.headed,
|
|
451
|
+
safety: safetyOf(flags.safe),
|
|
452
|
+
replay: flags.replay,
|
|
453
|
+
sensitiveOrigins: flags.sensitiveOrigin,
|
|
454
|
+
watchOrigins: flags.watchOrigin,
|
|
455
|
+
rejectedSubmits: flags.rejectedSubmits,
|
|
456
|
+
ignoreConsole: flags.ignoreConsole,
|
|
457
|
+
detect: flags.detect,
|
|
458
|
+
detectAllow: flags.detectAllow,
|
|
459
|
+
...flags.cookies ? { cookies: path3.resolve(io.cwd, flags.cookies) } : {},
|
|
460
|
+
provider: await exploreProvider(io.cwd),
|
|
461
|
+
...io.signal ? { signal: io.signal } : {},
|
|
462
|
+
write: io.write
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
function usageProblem({
|
|
466
|
+
url,
|
|
467
|
+
flags
|
|
468
|
+
}) {
|
|
469
|
+
if (flags.detect === "semantic" && flags.mode !== "guided")
|
|
470
|
+
return "--detect semantic asks Jev in each new page's guided call.\nFix: use it with --mode guided.\n";
|
|
471
|
+
return url ? null : "Missing start URL.\nFix: use `sedum explore <url>`.\n";
|
|
472
|
+
}
|
|
473
|
+
async function exploreAction(url, flags, io) {
|
|
474
|
+
const { ProviderError } = await import("@sedum-dev/core");
|
|
475
|
+
try {
|
|
476
|
+
if (flags.rerun)
|
|
477
|
+
return await executeRerunCommand({
|
|
478
|
+
trace: path3.resolve(io.cwd, flags.rerun),
|
|
479
|
+
headed: flags.headed,
|
|
480
|
+
write: io.write
|
|
481
|
+
});
|
|
482
|
+
const problem = usageProblem({ url, flags });
|
|
483
|
+
if (!problem) return await run(url, flags, io);
|
|
484
|
+
io.writeErr(problem);
|
|
485
|
+
} catch (error) {
|
|
486
|
+
if (!(error instanceof ProviderError && error.code === "configuration"))
|
|
487
|
+
throw error;
|
|
488
|
+
io.writeErr(
|
|
489
|
+
`${error.message}
|
|
490
|
+
Fix: set TYPESAFE_API_KEY in the project-root .env or your shell, or use --mode random or --mode heuristic without --shrink.
|
|
491
|
+
`
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
return 3;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export {
|
|
498
|
+
EXPLORE_MODES,
|
|
499
|
+
exploreMode,
|
|
500
|
+
seedValue,
|
|
501
|
+
collectText,
|
|
502
|
+
watchOrigin,
|
|
503
|
+
startUrl,
|
|
504
|
+
exploreProvider,
|
|
505
|
+
executeExploreCommand,
|
|
506
|
+
executeRerunCommand,
|
|
507
|
+
exploreAction
|
|
508
|
+
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
providerDiagnostic
|
|
3
|
+
} from "./chunk-GJ5QI7JQ.js";
|
|
1
4
|
import {
|
|
2
5
|
DEFAULT_PROVIDER_BASE_URL,
|
|
3
6
|
DEFAULT_PROVIDER_MODEL,
|
|
4
7
|
loadProjectConfig
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OKZ6VJKA.js";
|
|
6
9
|
|
|
7
10
|
// src/doctor-command.ts
|
|
8
11
|
import { lstat, mkdir, mkdtemp, rm, rmdir, writeFile } from "fs/promises";
|
|
9
12
|
import path from "path";
|
|
10
|
-
import {
|
|
11
|
-
findBrowserExecutable,
|
|
12
|
-
probeOpenRouterKey
|
|
13
|
-
} from "@sedum-dev/core";
|
|
13
|
+
import { findBrowserExecutable } from "@sedum-dev/core";
|
|
14
14
|
import {
|
|
15
15
|
probeTypeSafeApiKey
|
|
16
16
|
} from "@sedum-dev/provider-typesafe";
|
|
@@ -85,6 +85,17 @@ async function checkOutputWritable(config) {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
var VISION_CHECKS = {
|
|
89
|
+
ready: pass(
|
|
90
|
+
"vision",
|
|
91
|
+
"Vision fallback will send screenshots to the provider's image model."
|
|
92
|
+
),
|
|
93
|
+
blocked: fail(
|
|
94
|
+
"vision",
|
|
95
|
+
"Vision fallback is enabled but screenshots are off, so it cannot run.",
|
|
96
|
+
"Use the TypeSafe API with screenshots on (the default there), or set vision.enabled: false."
|
|
97
|
+
)
|
|
98
|
+
};
|
|
88
99
|
async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
89
100
|
const checks = [];
|
|
90
101
|
const version = probes.nodeVersion ?? process.versions.node;
|
|
@@ -97,7 +108,11 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
97
108
|
);
|
|
98
109
|
let config = null;
|
|
99
110
|
try {
|
|
100
|
-
config = await
|
|
111
|
+
config = probes.loadConfig ? await probes.loadConfig(cwd) : await loadProjectConfig(
|
|
112
|
+
cwd,
|
|
113
|
+
process.env,
|
|
114
|
+
options.environment ? { environment: options.environment } : {}
|
|
115
|
+
);
|
|
101
116
|
checks.push(pass("config", "Project configuration is valid."));
|
|
102
117
|
} catch {
|
|
103
118
|
checks.push(
|
|
@@ -160,7 +175,7 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
160
175
|
) : key ? pass("api_key", "Provider API key is present.") : fail(
|
|
161
176
|
"api_key",
|
|
162
177
|
"Provider API key is missing.",
|
|
163
|
-
config
|
|
178
|
+
providerDiagnostic(config, "configuration").fix
|
|
164
179
|
)
|
|
165
180
|
);
|
|
166
181
|
if (!config)
|
|
@@ -176,7 +191,7 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
176
191
|
fail(
|
|
177
192
|
"api_auth",
|
|
178
193
|
"API authentication could not be checked without a key.",
|
|
179
|
-
config
|
|
194
|
+
providerDiagnostic(config, "configuration").fix
|
|
180
195
|
)
|
|
181
196
|
);
|
|
182
197
|
else if (!network)
|
|
@@ -212,8 +227,8 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
212
227
|
config.providerName === "clef" ? "Cloudflare completed the explicitly billable inference probe." : "Model provider API accepted the key."
|
|
213
228
|
) : result === "rejected" ? fail(
|
|
214
229
|
"api_auth",
|
|
215
|
-
config
|
|
216
|
-
config
|
|
230
|
+
providerDiagnostic(config, "authentication").message,
|
|
231
|
+
providerDiagnostic(config, "authentication").fix
|
|
217
232
|
) : result === "unreachable" ? fail(
|
|
218
233
|
"api_auth",
|
|
219
234
|
"Authenticated provider request could not reach the API.",
|
|
@@ -225,42 +240,8 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
225
240
|
)
|
|
226
241
|
);
|
|
227
242
|
}
|
|
228
|
-
if (config
|
|
229
|
-
|
|
230
|
-
checks.push(
|
|
231
|
-
visionKey ? pass(
|
|
232
|
-
"vision_key",
|
|
233
|
-
"OpenRouter API key for vision fallback is present."
|
|
234
|
-
) : fail(
|
|
235
|
-
"vision_key",
|
|
236
|
-
"Vision fallback is enabled but OPEN_ROUTER_API_KEY is missing.",
|
|
237
|
-
"Set OPEN_ROUTER_API_KEY in the environment or the project-root .env."
|
|
238
|
-
)
|
|
239
|
-
);
|
|
240
|
-
if (visionKey) {
|
|
241
|
-
const result = await (probes.visionAuth ?? probeOpenRouterKey)(
|
|
242
|
-
visionKey
|
|
243
|
-
).catch(() => "unreachable");
|
|
244
|
-
checks.push(
|
|
245
|
-
result === "accepted" ? pass("vision_auth", "OpenRouter accepted the vision key.") : result === "rejected" ? fail(
|
|
246
|
-
"vision_auth",
|
|
247
|
-
"OpenRouter rejected OPEN_ROUTER_API_KEY.",
|
|
248
|
-
"Replace OPEN_ROUTER_API_KEY with a valid OpenRouter key and rerun doctor."
|
|
249
|
-
) : fail(
|
|
250
|
-
"vision_auth",
|
|
251
|
-
"OpenRouter could not be reached to check the vision key.",
|
|
252
|
-
"Check access to https://openrouter.ai and retry."
|
|
253
|
-
)
|
|
254
|
-
);
|
|
255
|
-
} else
|
|
256
|
-
checks.push(
|
|
257
|
-
fail(
|
|
258
|
-
"vision_auth",
|
|
259
|
-
"The vision key could not be checked without a key.",
|
|
260
|
-
"Set OPEN_ROUTER_API_KEY, then rerun doctor."
|
|
261
|
-
)
|
|
262
|
-
);
|
|
263
|
-
}
|
|
243
|
+
if (config?.vision.enabled)
|
|
244
|
+
checks.push(VISION_CHECKS[config.screenshots ? "ready" : "blocked"]);
|
|
264
245
|
if (config) {
|
|
265
246
|
try {
|
|
266
247
|
await (probes.output ?? checkOutputWritable)(config);
|