sedum-cli 0.1.0-alpha.12 → 0.1.0-alpha.18

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.
@@ -1,16 +1,14 @@
1
1
  import {
2
2
  DEFAULT_PROVIDER_BASE_URL,
3
3
  DEFAULT_PROVIDER_MODEL,
4
- loadProjectConfig
5
- } from "./chunk-FAGJCNV7.js";
4
+ loadProjectConfig,
5
+ providerDiagnostic
6
+ } from "./chunk-KZF4NZ6M.js";
6
7
 
7
8
  // src/doctor-command.ts
8
9
  import { lstat, mkdir, mkdtemp, rm, rmdir, writeFile } from "fs/promises";
9
10
  import path from "path";
10
- import {
11
- findBrowserExecutable,
12
- probeOpenRouterKey
13
- } from "@sedum-dev/core";
11
+ import { findBrowserExecutable } from "@sedum-dev/core";
14
12
  import {
15
13
  probeTypeSafeApiKey
16
14
  } from "@sedum-dev/provider-typesafe";
@@ -85,6 +83,17 @@ async function checkOutputWritable(config) {
85
83
  }
86
84
  }
87
85
  }
86
+ var VISION_CHECKS = {
87
+ ready: pass(
88
+ "vision",
89
+ "Vision fallback will send screenshots to the provider's image model."
90
+ ),
91
+ blocked: fail(
92
+ "vision",
93
+ "Vision fallback is enabled but screenshots are off, so it cannot run.",
94
+ "Use the TypeSafe API with screenshots on (the default there), or set vision.enabled: false."
95
+ )
96
+ };
88
97
  async function executeDoctorCommand(cwd, probes = {}, options = {}) {
89
98
  const checks = [];
90
99
  const version = probes.nodeVersion ?? process.versions.node;
@@ -97,7 +106,11 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
97
106
  );
98
107
  let config = null;
99
108
  try {
100
- config = await (probes.loadConfig ?? loadProjectConfig)(cwd);
109
+ config = probes.loadConfig ? await probes.loadConfig(cwd) : await loadProjectConfig(
110
+ cwd,
111
+ process.env,
112
+ options.environment ? { environment: options.environment } : {}
113
+ );
101
114
  checks.push(pass("config", "Project configuration is valid."));
102
115
  } catch {
103
116
  checks.push(
@@ -160,7 +173,7 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
160
173
  ) : key ? pass("api_key", "Provider API key is present.") : fail(
161
174
  "api_key",
162
175
  "Provider API key is missing.",
163
- config.providerName === "clef" ? "Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN)." : "Set TYPESAFE_API_KEY for the configured endpoint."
176
+ providerDiagnostic(config, "configuration").fix
164
177
  )
165
178
  );
166
179
  if (!config)
@@ -176,7 +189,7 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
176
189
  fail(
177
190
  "api_auth",
178
191
  "API authentication could not be checked without a key.",
179
- config.providerName === "clef" ? "Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN), then rerun doctor." : "Set TYPESAFE_API_KEY, then rerun doctor."
192
+ providerDiagnostic(config, "configuration").fix
180
193
  )
181
194
  );
182
195
  else if (!network)
@@ -212,8 +225,8 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
212
225
  config.providerName === "clef" ? "Cloudflare completed the explicitly billable inference probe." : "Model provider API accepted the key."
213
226
  ) : result === "rejected" ? fail(
214
227
  "api_auth",
215
- config.providerName === "clef" ? "Cloudflare rejected the configured API token." : "Model provider API rejected the key.",
216
- config.providerName === "clef" ? "Check CLOUDFLARE_ACCOUNT_ID, then replace CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN) with a token for that account that has Workers AI Read and Edit permissions." : "Replace TYPESAFE_API_KEY with a valid key and rerun doctor."
228
+ providerDiagnostic(config, "authentication").message,
229
+ providerDiagnostic(config, "authentication").fix
217
230
  ) : result === "unreachable" ? fail(
218
231
  "api_auth",
219
232
  "Authenticated provider request could not reach the API.",
@@ -225,42 +238,8 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
225
238
  )
226
239
  );
227
240
  }
228
- if (config && (options.vision || config.vision.enabled)) {
229
- const visionKey = config.visionApiKey?.trim();
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
- }
241
+ if (config?.vision.enabled)
242
+ checks.push(VISION_CHECKS[config.screenshots ? "ready" : "blocked"]);
264
243
  if (config) {
265
244
  try {
266
245
  await (probes.output ?? checkOutputWritable)(config);
package/dist/cli.js CHANGED
@@ -2,10 +2,11 @@
2
2
  import {
3
3
  runCli,
4
4
  sedumCommand
5
- } from "./chunk-HT6BIET2.js";
5
+ } from "./chunk-EPXLY5Q4.js";
6
+ import "./chunk-FG46OUHT.js";
6
7
  import "./chunk-EFRMSNBD.js";
7
- import "./chunk-S7OB3JEF.js";
8
- import "./chunk-FAGJCNV7.js";
8
+ import "./chunk-N5CTUO2A.js";
9
+ import "./chunk-KZF4NZ6M.js";
9
10
 
10
11
  // src/cli.ts
11
12
  import { createRequire } from "module";
@@ -5,8 +5,8 @@ import {
5
5
  keyPresent,
6
6
  renderDoctorText,
7
7
  supportedNode
8
- } from "./chunk-HXQDSNLL.js";
9
- import "./chunk-FAGJCNV7.js";
8
+ } from "./chunk-SI2F6MBN.js";
9
+ import "./chunk-KZF4NZ6M.js";
10
10
  export {
11
11
  browserAvailable,
12
12
  checkOutputWritable,
@@ -0,0 +1,25 @@
1
+ import {
2
+ EXPLORE_MODES,
3
+ collectText,
4
+ executeExploreCommand,
5
+ executeRerunCommand,
6
+ exploreAction,
7
+ exploreMode,
8
+ exploreProvider,
9
+ seedValue,
10
+ startUrl,
11
+ watchOrigin
12
+ } from "./chunk-FG46OUHT.js";
13
+ import "./chunk-KZF4NZ6M.js";
14
+ export {
15
+ EXPLORE_MODES,
16
+ collectText,
17
+ executeExploreCommand,
18
+ executeRerunCommand,
19
+ exploreAction,
20
+ exploreMode,
21
+ exploreProvider,
22
+ seedValue,
23
+ startUrl,
24
+ watchOrigin
25
+ };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RunResult, BrowserKind, VerifyPolicy, VisionKeyProbe, RelevanceProvider, ClassificationProvider, BrowserInstallResult } from '@sedum-dev/core';
1
+ import { RunResult, BrowserKind, VerifyPolicy, RelevanceProvider, ClassificationProvider, BrowserInstallResult } from '@sedum-dev/core';
2
2
  import { AuthProbeResult } from '@sedum-dev/provider-typesafe';
3
3
  export { Ai, AiValue, AiValues, BrowserContext, Locator, Page, Parser, SecretValue, TestBody, TestContext, TestInfo, TestOptions, expect, secret, test } from '@sedum-dev/core/script';
4
4
 
@@ -47,8 +47,8 @@ interface ProjectConfigOverrides {
47
47
  readonly baseUrl?: string;
48
48
  readonly vision?: {
49
49
  readonly enabled?: boolean;
50
- readonly model?: string;
51
50
  };
51
+ readonly screenshots?: boolean;
52
52
  }
53
53
  interface ResolvedProjectConfig {
54
54
  readonly projectRoot: string;
@@ -70,17 +70,24 @@ interface ResolvedProjectConfig {
70
70
  readonly reporterDir: string;
71
71
  readonly baseUrl: string | null;
72
72
  readonly variables: Readonly<Record<string, string | undefined>>;
73
- readonly providerName: "typesafe" | "clef";
73
+ readonly providerName: "typesafe" | "clef" | "openrouter";
74
74
  readonly apiKey: string | undefined;
75
+ readonly apiKeyEnv?: string;
76
+ /** Integration secrets retained for redaction, never injected into tests. */
77
+ readonly credentialValues?: readonly string[];
75
78
  readonly cloudflareAccountId: string | undefined;
76
79
  readonly providerBaseUrl: string;
77
80
  readonly providerModel: string;
81
+ /** Ask the provider's image model about ambiguous or unmatched clicks. */
78
82
  readonly vision: {
79
83
  readonly enabled: boolean;
80
- readonly model: string;
81
- readonly timeoutMs: number;
82
84
  };
83
- readonly visionApiKey: string | undefined;
85
+ /**
86
+ * Send viewport screenshots to the provider (TypeSafe images preview): a
87
+ * visual check of each model-resolved target, and the Judge's evidence.
88
+ * On by default for the direct TypeSafe endpoint only.
89
+ */
90
+ readonly screenshots: boolean;
84
91
  }
85
92
  interface ProjectConfigLoadOptions {
86
93
  /**
@@ -112,6 +119,7 @@ interface CliDiagnostic {
112
119
  readonly message: string;
113
120
  readonly fix: string;
114
121
  }
122
+ type ProviderName = ResolvedProjectConfig["providerName"];
115
123
 
116
124
  interface RunCommandOptions {
117
125
  /**
@@ -125,7 +133,8 @@ interface RunCommandOptions {
125
133
  readonly environment?: string;
126
134
  readonly browser?: string;
127
135
  readonly vision?: boolean;
128
- readonly visionModel?: string;
136
+ /** Overrides `screenshots` in sedum.config.yaml. */
137
+ readonly screenshots?: boolean;
129
138
  readonly urlOverride?: string;
130
139
  readonly outputDir?: string;
131
140
  readonly reporterDir?: string;
@@ -144,11 +153,13 @@ interface RunCommandOptions {
144
153
  readonly providerConcurrency?: number;
145
154
  /** Injected for tests; defaults to `os.availableParallelism()`. */
146
155
  readonly availableParallelism?: number;
147
- /** Injected for tests; defaults to OpenRouter's unbilled key endpoint. */
148
- readonly probeVisionKey?: (apiKey: string) => Promise<VisionKeyProbe>;
149
156
  readonly replay: boolean;
150
157
  readonly evidence: boolean;
151
158
  readonly sensitiveOrigins: readonly string[];
159
+ /** `--detect`: flag steps whose page reported errors or looks broken; findings never fail a step. */
160
+ readonly detect?: "off" | "browser" | "semantic";
161
+ /** `--detect-allow`: rules for known noise, added to the defaults. */
162
+ readonly detectAllow?: readonly string[];
152
163
  readonly locatorCacheDisabled?: boolean;
153
164
  readonly locatorCacheCi?: boolean;
154
165
  readonly signal?: AbortSignal;
@@ -178,14 +189,13 @@ interface DoctorProbes {
178
189
  readonly model: string;
179
190
  }) => Promise<AuthProbeResult>;
180
191
  readonly output?: (config: ResolvedProjectConfig) => Promise<void>;
181
- readonly visionAuth?: (apiKey: string) => Promise<VisionKeyProbe>;
182
192
  }
183
193
 
184
194
  type ClassificationProviderFactory = (options: {
185
195
  readonly apiKey?: string;
186
196
  readonly baseURL: string;
187
197
  readonly model: string;
188
- readonly providerName?: "typesafe" | "clef";
198
+ readonly providerName?: ProviderName;
189
199
  readonly accountId?: string;
190
200
  }) => ClassificationProvider | Promise<ClassificationProvider>;
191
201
 
package/dist/index.js CHANGED
@@ -2,14 +2,15 @@ import {
2
2
  renderRunSummary,
3
3
  runCli,
4
4
  runExitCode
5
- } from "./chunk-HT6BIET2.js";
5
+ } from "./chunk-EPXLY5Q4.js";
6
+ import "./chunk-FG46OUHT.js";
6
7
  import "./chunk-EFRMSNBD.js";
7
- import "./chunk-S7OB3JEF.js";
8
+ import "./chunk-N5CTUO2A.js";
8
9
  import {
9
10
  ProjectConfigError,
10
11
  discoverConfiguredTests,
11
12
  loadProjectConfig
12
- } from "./chunk-FAGJCNV7.js";
13
+ } from "./chunk-KZF4NZ6M.js";
13
14
 
14
15
  // src/index.ts
15
16
  import { test, expect, secret } from "@sedum-dev/core/script";
@@ -2,11 +2,11 @@ import {
2
2
  browserAvailable,
3
3
  keyPresent,
4
4
  supportedNode
5
- } from "./chunk-HXQDSNLL.js";
5
+ } from "./chunk-SI2F6MBN.js";
6
6
  import {
7
7
  ProjectConfigError,
8
8
  loadProjectConfig
9
- } from "./chunk-FAGJCNV7.js";
9
+ } from "./chunk-KZF4NZ6M.js";
10
10
 
11
11
  // src/init-command.ts
12
12
  import { constants } from "fs";
@@ -37,17 +37,42 @@ test(
37
37
  var ENV_EXAMPLE = `# Get a TypeSafe key and put it in .env, or set it in your shell.
38
38
  # For a compatible provider, also set TYPESAFE_BASE_URL and optionally TYPESAFE_DEFAULT_MODEL.
39
39
  TYPESAFE_API_KEY=
40
+ # If provider.name is openrouter, use this instead (never commit .env).
41
+ # OPENROUTER_API_KEY=
40
42
  # If provider.name is clef, use these instead (never commit .env).
41
43
  # CLOUDFLARE_ACCOUNT_ID=
42
44
  # CLOUDFLARE_AUTH_TOKEN=
43
45
  # Public SauceDemo sample account; no Sauce Labs account is required.
44
46
  SAUCE_PASSWORD=secret_sauce
45
47
  `;
48
+ var PROVIDER_SETUP = {
49
+ typesafe: {
50
+ source: "Get a key at https://typesafe.ai/.",
51
+ instructions: [
52
+ "Open .env and set TYPESAFE_API_KEY to your key (or set it in your shell).",
53
+ "For a compatible provider, also set TYPESAFE_BASE_URL and use that provider's key as TYPESAFE_API_KEY."
54
+ ]
55
+ },
56
+ clef: {
57
+ source: "Create a scoped Workers AI token in the Cloudflare dashboard.",
58
+ instructions: [
59
+ "Open .env and set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN (or set them in your shell)."
60
+ ]
61
+ },
62
+ openrouter: {
63
+ source: "Get a key at https://openrouter.ai/settings/keys.",
64
+ instructions: [
65
+ "Open .env and set OPENROUTER_API_KEY to your key (or set it in your shell)."
66
+ ]
67
+ }
68
+ };
46
69
  var IGNORE = [
47
70
  "node_modules/",
48
71
  ".env",
49
72
  ".sedum/runs/",
50
- ".sedum/reports/"
73
+ ".sedum/reports/",
74
+ // `sedum explore` traces, reports and page frames.
75
+ ".sedum/explore/"
51
76
  ];
52
77
  var WORDMARK = [
53
78
  " \u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588 \u2588 \u2588 \u2588 \u2588 \u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588 \u2588 \u2588",
@@ -95,18 +120,6 @@ async function pathExists(file) {
95
120
  throw error;
96
121
  }
97
122
  }
98
- async function regularDirectory(directory) {
99
- try {
100
- await mkdir(directory);
101
- } catch (error) {
102
- if (code(error) !== "EEXIST") throw error;
103
- }
104
- const info = await lstat(directory);
105
- if (!info.isDirectory() || info.isSymbolicLink())
106
- throw new Error(
107
- `${path.basename(directory)} exists but is not a regular directory.`
108
- );
109
- }
110
123
  async function createOrKeep(file, contents) {
111
124
  try {
112
125
  await writeFile(file, contents, { flag: "wx", mode: 420 });
@@ -151,6 +164,55 @@ ${missing.map((line) => ` ${line}`).join("\n")}
151
164
  return `updated .gitignore (${missing.join(", ")})
152
165
  `;
153
166
  }
167
+ async function createStarterFiles(root, say) {
168
+ const directory = path.join(root, "tests");
169
+ try {
170
+ await mkdir(directory);
171
+ } catch (error) {
172
+ if (code(error) !== "EEXIST") throw error;
173
+ }
174
+ const info = await lstat(directory);
175
+ if (!info.isDirectory() || info.isSymbolicLink())
176
+ throw new Error(
177
+ `${path.basename(directory)} exists but is not a regular directory.`
178
+ );
179
+ say(
180
+ `${await createOrKeep(path.join(root, "sedum.config.yaml"), CONFIG)} sedum.config.yaml
181
+ `
182
+ );
183
+ const config = await loadProjectConfig(root);
184
+ const defaultKeyName = {
185
+ typesafe: "TYPESAFE_API_KEY",
186
+ openrouter: "OPENROUTER_API_KEY",
187
+ clef: "CLOUDFLARE_AUTH_TOKEN"
188
+ }[config.providerName];
189
+ const keyName = config.apiKeyEnv ?? defaultKeyName;
190
+ const setup = {
191
+ source: PROVIDER_SETUP[config.providerName].source,
192
+ instructions: PROVIDER_SETUP[config.providerName].instructions.map(
193
+ (line) => line.replaceAll(defaultKeyName, keyName)
194
+ )
195
+ };
196
+ const template = ENV_EXAMPLE.replaceAll(defaultKeyName, keyName);
197
+ const createdExample = await createOrKeep(
198
+ path.join(root, "tests/example.test.ts"),
199
+ EXAMPLE
200
+ );
201
+ say(`${createdExample} tests/example.test.ts
202
+ `);
203
+ const envExample = await createOrKeep(
204
+ path.join(root, ".env.example"),
205
+ template
206
+ );
207
+ say(`${envExample} .env.example
208
+ `);
209
+ return {
210
+ config,
211
+ setup,
212
+ createdExample: createdExample === "created",
213
+ keptEnvExample: envExample === "kept"
214
+ };
215
+ }
154
216
  async function executeInitCommand(options) {
155
217
  const root = path.resolve(options.cwd);
156
218
  const output = [];
@@ -159,22 +221,8 @@ async function executeInitCommand(options) {
159
221
  options.onOutput?.(value);
160
222
  };
161
223
  try {
162
- let keptEnvExample = false;
163
- let createdExample = false;
164
224
  if (options.interactive && options.color) say(initBanner(options.columns));
165
- await regularDirectory(path.join(root, "tests"));
166
- for (const [name, contents] of [
167
- ["sedum.config.yaml", CONFIG],
168
- ["tests/example.test.ts", EXAMPLE],
169
- [".env.example", ENV_EXAMPLE]
170
- ]) {
171
- const result = await createOrKeep(path.join(root, name), contents);
172
- if (name === ".env.example" && result === "kept") keptEnvExample = true;
173
- if (name === "tests/example.test.ts" && result === "created")
174
- createdExample = true;
175
- say(`${result} ${name}
176
- `);
177
- }
225
+ const { config, setup, createdExample, keptEnvExample } = await createStarterFiles(root, say);
178
226
  say(await updateIgnore(root, options));
179
227
  say("\nSedum runs plain-language tests in a browser.\n");
180
228
  if (createdExample) {
@@ -198,19 +246,13 @@ ${++step}. ${title}
198
246
  };
199
247
  if (!supportedNode(options.nodeVersion ?? process.versions.node))
200
248
  next("Update Node.js", ["Install Node 20.19.0 or newer."]);
201
- const config = await loadProjectConfig(root);
202
249
  const hasBrowser = (options.browser ?? browserAvailable)(config.browser);
203
250
  const hasEnv = await pathExists(path.join(root, ".env"));
204
251
  if (!keyPresent(config))
205
252
  next("Add a provider API key", [
206
- ...config.providerName === "clef" ? ["Create a scoped Workers AI token in the Cloudflare dashboard."] : ["Get a key at https://typesafe.ai/."],
253
+ setup.source,
207
254
  ...hasEnv ? [] : ["cp .env.example .env"],
208
- ...config.providerName === "clef" ? [
209
- "Open .env and set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN (or set them in your shell)."
210
- ] : [
211
- "Open .env and set TYPESAFE_API_KEY to your key (or set it in your shell).",
212
- "For a compatible provider, also set TYPESAFE_BASE_URL and use that provider's key as TYPESAFE_API_KEY."
213
- ]
255
+ ...setup.instructions
214
256
  ]);
215
257
  if (!hasBrowser)
216
258
  next(