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

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.
@@ -0,0 +1,208 @@
1
+ import {
2
+ ProjectConfigError
3
+ } from "./chunk-J7CLCLHW.js";
4
+
5
+ // src/diagnostics.ts
6
+ import { BrowserDriverError, ProviderError } from "@sedum-dev/core";
7
+ function providerDiagnostic(provider, code, apiKeyEnv) {
8
+ const providerName = typeof provider === "string" ? provider : provider.providerName;
9
+ if (typeof provider !== "string") apiKeyEnv = provider.apiKeyEnv;
10
+ if (providerName === "openrouter")
11
+ return {
12
+ code: `provider_${code}`,
13
+ message: code === "authentication" ? "OpenRouter rejected the configured API key." : "The OpenRouter decision provider is not configured correctly.",
14
+ fix: `Set ${apiKeyEnv ?? "OPENROUTER_API_KEY (or OPEN_ROUTER_API_KEY)"} to a valid OpenRouter key, check account credits and provider.model with \`sedum doctor\`, then rerun.`
15
+ };
16
+ if (providerName === "clef")
17
+ return code === "authentication" ? {
18
+ code: "provider_authentication",
19
+ message: "Cloudflare rejected the configured API token.",
20
+ fix: `Check CLOUDFLARE_ACCOUNT_ID, replace ${apiKeyEnv ?? "CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN)"} with a token for that account that has Workers AI Read and Edit permissions, run \`sedum doctor\`, then rerun.`
21
+ } : {
22
+ code: "provider_configuration",
23
+ message: "The Cloudflare Clef provider is not configured correctly.",
24
+ fix: `Set CLOUDFLARE_ACCOUNT_ID and ${apiKeyEnv ?? "CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN)"}, then check the account, Workers AI access, and model with \`sedum doctor\`.`
25
+ };
26
+ return code === "authentication" ? {
27
+ code: "provider_authentication",
28
+ message: "The model provider rejected the API key.",
29
+ fix: `Set ${apiKeyEnv ?? "TYPESAFE_API_KEY"} to a valid key, check it with \`sedum doctor\`, then rerun.`
30
+ } : {
31
+ code: "provider_configuration",
32
+ message: "The model provider is not configured correctly.",
33
+ fix: `Check ${apiKeyEnv ?? "TYPESAFE_API_KEY"}, TYPESAFE_BASE_URL and the model with \`sedum doctor\`, then rerun.`
34
+ };
35
+ }
36
+ var DetectorUnsupportedError = class extends Error {
37
+ constructor(providerName) {
38
+ super(
39
+ `--detect semantic is not supported by the ${providerName} provider.`
40
+ );
41
+ this.providerName = providerName;
42
+ this.name = "DetectorUnsupportedError";
43
+ }
44
+ providerName;
45
+ };
46
+ function setupDiagnostic(error, providerName = "typesafe", apiKeyEnv) {
47
+ if (error instanceof ProjectConfigError) return configDiagnostic(error);
48
+ if (error instanceof DetectorUnsupportedError)
49
+ return {
50
+ code: "detect_unsupported",
51
+ message: `--detect semantic needs a System One provider; ${error.providerName} cannot answer its page questions.`,
52
+ fix: "Use --detect browser with this provider, or select the TypeSafe or OpenRouter provider."
53
+ };
54
+ if (error instanceof ProviderError && error.code === "configuration")
55
+ return providerName !== "typesafe" ? providerDiagnostic(providerName, "configuration", apiKeyEnv) : {
56
+ code: "missing_key",
57
+ message: "The model provider is not configured.",
58
+ fix: `Set ${apiKeyEnv ?? "TYPESAFE_API_KEY"} for the configured endpoint, then rerun the command.`
59
+ };
60
+ if (error instanceof BrowserDriverError && error.code === "browser-missing")
61
+ return {
62
+ code: "browser_missing",
63
+ message: "No supported browser binary was found.",
64
+ fix: "Run `sedum browsers install chromium`, then rerun the test."
65
+ };
66
+ return {
67
+ code: "setup_or_output_error",
68
+ message: "The run could not be prepared safely.",
69
+ fix: "Check the test path, provider key, browser installation, and write access, then rerun."
70
+ };
71
+ }
72
+ function configDiagnostic(error) {
73
+ const first = error.diagnostics[0];
74
+ if (!first)
75
+ return {
76
+ code: "invalid_config",
77
+ message: "The Sedum configuration is invalid.",
78
+ fix: "Correct sedum.config.yaml and rerun the command."
79
+ };
80
+ return {
81
+ code: first.code,
82
+ message: bounded(
83
+ `${first.file}:${first.line}:${first.col}: ${first.message} (key: ${first.key})`
84
+ ),
85
+ fix: bounded(first.fix)
86
+ };
87
+ }
88
+ function outputDiagnostic(path) {
89
+ return {
90
+ code: "output_error",
91
+ message: `The run result could not be written to ${path}.`,
92
+ fix: "Make the configured output directory writable and rerun the command."
93
+ };
94
+ }
95
+ function bounded(value, maximum = 512) {
96
+ return [...value].slice(0, maximum).join("");
97
+ }
98
+ function canonicalDiagnosticError(diagnostic) {
99
+ return {
100
+ code: diagnostic.code,
101
+ message: diagnostic.code === "output_error" ? "The run result could not be written." : bounded(diagnostic.message)
102
+ };
103
+ }
104
+ function flowDiagnostic(result, providerName = "typesafe", apiKeyEnv) {
105
+ if (result.code === "invalid_test" || result.code === "unsupported_test" || result.code === "invalid_data") {
106
+ const source = result.source ? `${result.source.file}:${result.source.line}:${result.source.col}: ` : "";
107
+ return {
108
+ code: result.code,
109
+ message: bounded(`${source}${result.message}`),
110
+ fix: bounded(
111
+ result.fix ?? "Fix the reported test input and rerun the command."
112
+ )
113
+ };
114
+ }
115
+ const known = {
116
+ "browser-missing": {
117
+ message: "No supported browser binary was found.",
118
+ fix: "Run `sedum browsers install chromium`, then rerun the test."
119
+ },
120
+ "browser-launch-failed": {
121
+ message: "The browser could not be started safely.",
122
+ fix: "Check the browser installation and permissions, then rerun the test."
123
+ },
124
+ "browser-disconnected": {
125
+ message: "The browser disconnected during the run.",
126
+ fix: "Restart the browser run and check browser stability if it repeats."
127
+ },
128
+ "context-closed": {
129
+ message: "The browser context closed during the run.",
130
+ fix: "Rerun the test and check browser stability if it repeats."
131
+ },
132
+ "page-closed": {
133
+ message: "The browser page closed during the run.",
134
+ fix: "Rerun the test and check whether the tested page closes itself."
135
+ },
136
+ "page-crashed": {
137
+ message: "The browser page crashed during the run.",
138
+ fix: "Rerun the test and check browser resource usage if it repeats."
139
+ },
140
+ "operation-failed": {
141
+ message: "A browser operation could not be completed safely.",
142
+ fix: "Check the named test step and rerun the test."
143
+ },
144
+ "script-missing": {
145
+ message: "The Sedum browser script was unavailable.",
146
+ fix: "Rebuild or reinstall Sedum, then rerun the test."
147
+ }
148
+ };
149
+ const diagnostic = known[result.code];
150
+ if (diagnostic) return { code: result.code, ...diagnostic };
151
+ if (result.code === "navigation_failed")
152
+ return {
153
+ code: result.code,
154
+ message: bounded(result.message),
155
+ fix: bounded(
156
+ result.fix ?? "Check the test's url (or baseUrl), your network or VPN, and that the site is up."
157
+ )
158
+ };
159
+ if (result.code === "provider_rate_limited")
160
+ return {
161
+ code: result.code,
162
+ message: "The model provider kept rate limiting requests for five minutes.",
163
+ fix: "Lower --parallel or --provider-concurrency, or retry later."
164
+ };
165
+ if (result.code === "provider_authentication")
166
+ return providerDiagnostic(providerName, "authentication", apiKeyEnv);
167
+ if (result.code === "provider_configuration")
168
+ return providerDiagnostic(providerName, "configuration", apiKeyEnv);
169
+ if (result.code.startsWith("provider_"))
170
+ return {
171
+ code: result.code,
172
+ message: "The model provider could not complete the run safely.",
173
+ fix: "Check provider availability and the test input, then rerun the test."
174
+ };
175
+ return {
176
+ code: "execution_error",
177
+ message: "The browser run could not be completed safely.",
178
+ fix: "Check the browser, provider, and test input, then rerun the test."
179
+ };
180
+ }
181
+ var RUN_STOPPING_CODES = /* @__PURE__ */ new Set([
182
+ "browser-missing",
183
+ "browser-launch-failed",
184
+ "script-missing",
185
+ "provider_configuration",
186
+ "provider_authentication",
187
+ "provider_rate_limited"
188
+ ]);
189
+ function stopsRun(code) {
190
+ return RUN_STOPPING_CODES.has(code);
191
+ }
192
+ function renderDiagnostic(diagnostic) {
193
+ return `${diagnostic.message}
194
+ Fix: ${diagnostic.fix}
195
+ `;
196
+ }
197
+
198
+ export {
199
+ providerDiagnostic,
200
+ DetectorUnsupportedError,
201
+ setupDiagnostic,
202
+ configDiagnostic,
203
+ outputDiagnostic,
204
+ canonicalDiagnosticError,
205
+ flowDiagnostic,
206
+ stopsRun,
207
+ renderDiagnostic
208
+ };
@@ -1,9 +1,12 @@
1
+ import {
2
+ providerDiagnostic
3
+ } from "./chunk-CGDXQY2Y.js";
1
4
  import {
2
5
  DEFAULT_PROVIDER_BASE_URL,
3
6
  DEFAULT_PROVIDER_MODEL,
4
- loadProjectConfig,
5
- providerDiagnostic
6
- } from "./chunk-KZF4NZ6M.js";
7
+ ProjectConfigError,
8
+ loadProjectConfig
9
+ } from "./chunk-J7CLCLHW.js";
7
10
 
8
11
  // src/doctor-command.ts
9
12
  import { lstat, mkdir, mkdtemp, rm, rmdir, writeFile } from "fs/promises";
@@ -13,6 +16,12 @@ import {
13
16
  probeTypeSafeApiKey
14
17
  } from "@sedum-dev/provider-typesafe";
15
18
  var CLOUDFLARE_API = "https://api.cloudflare.com";
19
+ function doctorOptions(options) {
20
+ return {
21
+ ...options.env ? { environment: options.env } : {},
22
+ ...options.browser ? { browser: options.browser } : {}
23
+ };
24
+ }
16
25
  var pass = (id, message) => ({
17
26
  id,
18
27
  status: "pass",
@@ -94,6 +103,29 @@ var VISION_CHECKS = {
94
103
  "Use the TypeSafe API with screenshots on (the default there), or set vision.enabled: false."
95
104
  )
96
105
  };
106
+ function browserOrigin(config) {
107
+ return config.browserSource === "default" ? "the default" : `from ${config.browserSource}`;
108
+ }
109
+ function configOverrides(options) {
110
+ return {
111
+ ...options.environment ? { environment: options.environment } : {},
112
+ ...options.browser ? { browser: options.browser } : {}
113
+ };
114
+ }
115
+ function configFailure(error) {
116
+ const detail = error instanceof ProjectConfigError ? error.diagnostics[0] : void 0;
117
+ if (!detail)
118
+ return fail(
119
+ "config",
120
+ "Project configuration could not be loaded.",
121
+ "Correct sedum.config.yaml or the project-root .env and check file permissions."
122
+ );
123
+ return fail(
124
+ "config",
125
+ `Project configuration could not be loaded: ${detail.message}`,
126
+ detail.fix
127
+ );
128
+ }
97
129
  async function executeDoctorCommand(cwd, probes = {}, options = {}) {
98
130
  const checks = [];
99
131
  const version = probes.nodeVersion ?? process.versions.node;
@@ -106,28 +138,21 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
106
138
  );
107
139
  let config = null;
108
140
  try {
109
- config = probes.loadConfig ? await probes.loadConfig(cwd) : await loadProjectConfig(
110
- cwd,
111
- process.env,
112
- options.environment ? { environment: options.environment } : {}
113
- );
141
+ config = probes.loadConfig ? await probes.loadConfig(cwd) : await loadProjectConfig(cwd, process.env, configOverrides(options));
114
142
  checks.push(pass("config", "Project configuration is valid."));
115
- } catch {
116
- checks.push(
117
- fail(
118
- "config",
119
- "Project configuration could not be loaded.",
120
- "Correct sedum.config.yaml or the project-root .env and check file permissions."
121
- )
122
- );
143
+ } catch (error) {
144
+ checks.push(configFailure(error));
123
145
  }
124
146
  if (config) {
125
147
  try {
126
148
  const available = (probes.browser ?? browserAvailable)(config.browser);
127
149
  checks.push(
128
- available ? pass("browser", `${config.browser} is available.`) : fail(
150
+ available ? pass(
151
+ "browser",
152
+ `${config.browser} is available (${browserOrigin(config)}).`
153
+ ) : fail(
129
154
  "browser",
130
- `${config.browser} was not found.`,
155
+ `${config.browser} was not found (${browserOrigin(config)}).`,
131
156
  "Install Chrome or run `sedum browsers install chromium`; check the configured browser."
132
157
  )
133
158
  );
@@ -273,6 +298,7 @@ function renderDoctorText(result) {
273
298
  }
274
299
 
275
300
  export {
301
+ doctorOptions,
276
302
  supportedNode,
277
303
  browserAvailable,
278
304
  keyPresent,
@@ -1,9 +1,11 @@
1
+ import {
2
+ configDiagnostic
3
+ } from "./chunk-CGDXQY2Y.js";
1
4
  import {
2
5
  ProjectConfigError,
3
- configDiagnostic,
4
6
  loadProjectConfig,
5
7
  readProjectEnvironment
6
- } from "./chunk-KZF4NZ6M.js";
8
+ } from "./chunk-J7CLCLHW.js";
7
9
 
8
10
  // src/explore-command.ts
9
11
  import { randomInt } from "crypto";