sedum-cli 0.1.0-alpha.0 → 0.1.0-alpha.10

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,132 @@
1
+ import {
2
+ discoverConfiguredTests
3
+ } from "./chunk-VNGIF7AY.js";
4
+
5
+ // src/run-selection.ts
6
+ import { lstat, realpath } from "fs/promises";
7
+ import path from "path";
8
+ import { minimatch } from "minimatch";
9
+ import {
10
+ listTests,
11
+ loadListingEntries,
12
+ TEST_SUFFIXES,
13
+ walkSuiteFiles
14
+ } from "@sedum-dev/core";
15
+ function contained(root, target) {
16
+ const relative = path.relative(root, target);
17
+ return relative === "" || relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
18
+ }
19
+ function selectRunTests(tests, filters) {
20
+ const includes = filters.include ?? [];
21
+ const excludes = filters.exclude ?? [];
22
+ const labels = filters.labels ?? [];
23
+ const names = filters.names ?? [];
24
+ const ids = filters.ids ?? [];
25
+ return tests.filter(
26
+ (test) => (includes.length === 0 || includes.some((glob) => minimatch(test.file, glob))) && !excludes.some((glob) => minimatch(test.file, glob)) && labels.every((label) => test.tags.includes(label)) && (ids.length === 0 || ids.includes(test.id)) && (names.length === 0 || names.some(
27
+ (name) => `${test.id}
28
+ ${test.description ?? ""}`.toLowerCase().includes(name.toLowerCase())
29
+ ))
30
+ );
31
+ }
32
+ async function discoverRunTests(config, paths, filters = {}) {
33
+ const problems = [];
34
+ const files = /* @__PURE__ */ new Set();
35
+ const root = await realpath(config.projectRoot);
36
+ if (paths.length === 0) {
37
+ for (const file of await discoverConfiguredTests(config)) {
38
+ const target = await realpath(file);
39
+ if (contained(root, target)) files.add(target);
40
+ else
41
+ problems.push({
42
+ file: "<outside-project>",
43
+ code: "outside_root",
44
+ message: "A configured test is outside the project root.",
45
+ fix: "Keep the test directory inside the project."
46
+ });
47
+ }
48
+ } else {
49
+ for (const requested of paths) {
50
+ const candidate = path.resolve(config.projectRoot, requested);
51
+ const namedInside = contained(config.projectRoot, candidate);
52
+ const file = namedInside ? path.relative(config.projectRoot, candidate).split(path.sep).join("/") : "<outside-project>";
53
+ if (!namedInside) {
54
+ problems.push({
55
+ file,
56
+ code: "outside_root",
57
+ message: "Path is outside the project root.",
58
+ fix: "Choose a path inside the project."
59
+ });
60
+ continue;
61
+ }
62
+ let info;
63
+ try {
64
+ info = await lstat(candidate);
65
+ } catch {
66
+ problems.push({
67
+ file,
68
+ code: "missing_path",
69
+ message: "Path does not exist.",
70
+ fix: "Check the path and rerun."
71
+ });
72
+ continue;
73
+ }
74
+ if (info.isSymbolicLink()) {
75
+ problems.push({
76
+ file,
77
+ code: "symlinked_path",
78
+ message: "Symlinked test paths are not supported.",
79
+ fix: "Name the regular file."
80
+ });
81
+ continue;
82
+ }
83
+ const target = await realpath(candidate).catch(() => candidate);
84
+ if (!contained(root, target)) {
85
+ problems.push({
86
+ file,
87
+ code: "outside_root",
88
+ message: "Path is outside the project root.",
89
+ fix: "Choose a path inside the project."
90
+ });
91
+ continue;
92
+ }
93
+ if (info.isDirectory()) {
94
+ for (const file2 of await walkSuiteFiles(
95
+ target,
96
+ TEST_SUFFIXES,
97
+ (folder) => {
98
+ problems.push({
99
+ file: path.relative(root, folder),
100
+ code: "unreadable_directory",
101
+ message: "Directory could not be read.",
102
+ fix: "Check permissions."
103
+ });
104
+ }
105
+ ))
106
+ files.add(file2);
107
+ } else if (info.isFile() && TEST_SUFFIXES.some((suffix) => candidate.endsWith(suffix)))
108
+ files.add(target);
109
+ else
110
+ problems.push({
111
+ file,
112
+ code: "unsupported_file",
113
+ message: "Expected a *.test.ts or *.test.yaml file, or a directory.",
114
+ fix: "Choose a test path."
115
+ });
116
+ }
117
+ }
118
+ const parsed = await loadListingEntries([...files].sort(), {
119
+ repoRoot: root,
120
+ rejectSymlinks: true
121
+ });
122
+ const listing = listTests(parsed, { repoRoot: root });
123
+ return {
124
+ tests: selectRunTests(listing.tests, filters),
125
+ invalid: listing.invalid,
126
+ problems
127
+ };
128
+ }
129
+
130
+ export {
131
+ discoverRunTests
132
+ };
@@ -1,166 +1,3 @@
1
- import {
2
- ProjectConfigError
3
- } from "./chunk-TZGSCV23.js";
4
-
5
- // src/diagnostics.ts
6
- import { BrowserDriverError, ProviderError } from "@sedum-dev/core";
7
- function setupDiagnostic(error) {
8
- if (error instanceof ProjectConfigError) return configDiagnostic(error);
9
- if (error instanceof ProviderError && error.code === "configuration")
10
- return {
11
- code: "missing_key",
12
- message: "The TypeSafe provider is not configured.",
13
- fix: "Set TYPESAFE_API_KEY and rerun the command."
14
- };
15
- if (error instanceof BrowserDriverError && error.code === "browser-missing")
16
- return {
17
- code: "browser_missing",
18
- message: "No supported browser binary was found.",
19
- fix: "Run `sedum browsers install chromium`, then rerun the test."
20
- };
21
- return {
22
- code: "setup_or_output_error",
23
- message: "The run could not be prepared safely.",
24
- fix: "Check the test path, provider key, browser installation, and write access, then rerun."
25
- };
26
- }
27
- function configDiagnostic(error) {
28
- const first = error.diagnostics[0];
29
- if (!first)
30
- return {
31
- code: "invalid_config",
32
- message: "The Sedum configuration is invalid.",
33
- fix: "Correct sedum.config.yaml and rerun the command."
34
- };
35
- return {
36
- code: first.code,
37
- message: bounded(
38
- `${first.file}:${first.line}:${first.col}: ${first.message} (key: ${first.key})`
39
- ),
40
- fix: bounded(first.fix)
41
- };
42
- }
43
- function outputDiagnostic(path2) {
44
- return {
45
- code: "output_error",
46
- message: `The run result could not be written to ${path2}.`,
47
- fix: "Make the configured output directory writable and rerun the command."
48
- };
49
- }
50
- function bounded(value, maximum = 512) {
51
- return [...value].slice(0, maximum).join("");
52
- }
53
- function canonicalDiagnosticError(diagnostic) {
54
- return {
55
- code: diagnostic.code,
56
- message: diagnostic.code === "output_error" ? "The run result could not be written." : bounded(diagnostic.message)
57
- };
58
- }
59
- function flowDiagnostic(result) {
60
- if (result.code === "invalid_test" || result.code === "unsupported_test" || result.code === "invalid_data") {
61
- const source = result.source ? `${result.source.file}:${result.source.line}:${result.source.col}: ` : "";
62
- return {
63
- code: result.code,
64
- message: bounded(`${source}${result.message}`),
65
- fix: bounded(
66
- result.fix ?? "Fix the reported test input and rerun the command."
67
- )
68
- };
69
- }
70
- const known = {
71
- "browser-missing": {
72
- message: "No supported browser binary was found.",
73
- fix: "Run `sedum browsers install chromium`, then rerun the test."
74
- },
75
- "browser-launch-failed": {
76
- message: "The browser could not be started safely.",
77
- fix: "Check the browser installation and permissions, then rerun the test."
78
- },
79
- "browser-disconnected": {
80
- message: "The browser disconnected during the run.",
81
- fix: "Restart the browser run and check browser stability if it repeats."
82
- },
83
- "context-closed": {
84
- message: "The browser context closed during the run.",
85
- fix: "Rerun the test and check browser stability if it repeats."
86
- },
87
- "page-closed": {
88
- message: "The browser page closed during the run.",
89
- fix: "Rerun the test and check whether the tested page closes itself."
90
- },
91
- "page-crashed": {
92
- message: "The browser page crashed during the run.",
93
- fix: "Rerun the test and check browser resource usage if it repeats."
94
- },
95
- "operation-failed": {
96
- message: "A browser operation could not be completed safely.",
97
- fix: "Check the named test step and rerun the test."
98
- },
99
- "script-missing": {
100
- message: "The Sedum browser script was unavailable.",
101
- fix: "Rebuild or reinstall Sedum, then rerun the test."
102
- }
103
- };
104
- const diagnostic = known[result.code];
105
- if (diagnostic) return { code: result.code, ...diagnostic };
106
- if (result.code === "provider_rate_limited")
107
- return {
108
- code: result.code,
109
- message: "The model provider kept rate limiting requests for five minutes.",
110
- fix: "Lower --parallel or --provider-concurrency, or retry later."
111
- };
112
- if (result.code.startsWith("provider_"))
113
- return {
114
- code: result.code,
115
- message: "The model provider could not complete the run safely.",
116
- fix: result.code === "provider_configuration" || result.code === "provider_authentication" ? "Check TYPESAFE_API_KEY and provider access, then rerun the test." : "Check provider availability and the test input, then rerun the test."
117
- };
118
- return {
119
- code: "execution_error",
120
- message: "The browser run could not be completed safely.",
121
- fix: "Check the browser, provider, and test input, then rerun the test."
122
- };
123
- }
124
- function renderDiagnostic(diagnostic) {
125
- return `${diagnostic.message}
126
- Fix: ${diagnostic.fix}
127
- `;
128
- }
129
-
130
- // src/run-pool.ts
131
- var MAX_PARALLEL = 64;
132
- function planLanes(requested, availableParallelism, selectedTests) {
133
- const wanted = requested === "auto" ? Math.max(1, Math.floor(availableParallelism / 2)) : requested;
134
- return Math.max(1, Math.min(wanted, MAX_PARALLEL, selectedTests));
135
- }
136
- function parseParallel(value) {
137
- if (value === "auto") return "auto";
138
- if (!/^[1-9]\d*$/u.test(value)) return null;
139
- const parsed = Number(value);
140
- return parsed <= MAX_PARALLEL ? parsed : null;
141
- }
142
- async function runPool(options) {
143
- let cursor = 0;
144
- let stopped = false;
145
- let failure = null;
146
- const lane = async (index) => {
147
- while (!stopped && !options.signal?.aborted) {
148
- const ordinal = cursor++;
149
- if (ordinal >= options.items.length) return;
150
- try {
151
- if (await options.run(options.items[ordinal], index, ordinal) === "stop")
152
- stopped = true;
153
- } catch (error) {
154
- stopped = true;
155
- failure ??= { error };
156
- }
157
- }
158
- };
159
- const count = Math.max(1, Math.min(options.lanes, options.items.length));
160
- await Promise.all(Array.from({ length: count }, (_, index) => lane(index)));
161
- if (failure) throw failure.error;
162
- }
163
-
164
1
  // src/locator-cache-store.ts
165
2
  import { randomBytes, randomUUID } from "crypto";
166
3
  import { execFile } from "child_process";
@@ -429,16 +266,45 @@ async function clearLocatorCache(root) {
429
266
  return true;
430
267
  }
431
268
 
269
+ // src/run-pool.ts
270
+ var MAX_PARALLEL = 64;
271
+ function planLanes(requested, availableParallelism, selectedTests) {
272
+ const wanted = requested === "auto" ? Math.max(1, Math.floor(availableParallelism / 2)) : requested;
273
+ return Math.max(1, Math.min(wanted, MAX_PARALLEL, selectedTests));
274
+ }
275
+ function parseParallel(value) {
276
+ if (value === "auto") return "auto";
277
+ if (!/^[1-9]\d*$/u.test(value)) return null;
278
+ const parsed = Number(value);
279
+ return parsed <= MAX_PARALLEL ? parsed : null;
280
+ }
281
+ async function runPool(options) {
282
+ let cursor = 0;
283
+ let stopped = false;
284
+ let failure = null;
285
+ const lane = async (index) => {
286
+ while (!stopped && !options.signal?.aborted) {
287
+ const ordinal = cursor++;
288
+ if (ordinal >= options.items.length) return;
289
+ try {
290
+ if (await options.run(options.items[ordinal], index, ordinal) === "stop")
291
+ stopped = true;
292
+ } catch (error) {
293
+ stopped = true;
294
+ failure ??= { error };
295
+ }
296
+ }
297
+ };
298
+ const count = Math.max(1, Math.min(options.lanes, options.items.length));
299
+ await Promise.all(Array.from({ length: count }, (_, index) => lane(index)));
300
+ if (failure) throw failure.error;
301
+ }
302
+
432
303
  export {
433
- setupDiagnostic,
434
- outputDiagnostic,
435
- canonicalDiagnosticError,
436
- flowDiagnostic,
437
- renderDiagnostic,
304
+ openLocatorCache,
305
+ clearLocatorCache,
438
306
  MAX_PARALLEL,
439
307
  planLanes,
440
308
  parseParallel,
441
- runPool,
442
- openLocatorCache,
443
- clearLocatorCache
309
+ runPool
444
310
  };
@@ -1,14 +1,20 @@
1
1
  import {
2
+ DEFAULT_PROVIDER_BASE_URL,
3
+ DEFAULT_PROVIDER_MODEL,
2
4
  loadProjectConfig
3
- } from "./chunk-TZGSCV23.js";
5
+ } from "./chunk-VNGIF7AY.js";
4
6
 
5
7
  // src/doctor-command.ts
6
8
  import { lstat, mkdir, mkdtemp, rm, rmdir, writeFile } from "fs/promises";
7
9
  import path from "path";
8
- import { findBrowserExecutable } from "@sedum-dev/core";
10
+ import {
11
+ findBrowserExecutable,
12
+ probeOpenRouterKey
13
+ } from "@sedum-dev/core";
9
14
  import {
10
15
  probeTypeSafeApiKey
11
16
  } from "@sedum-dev/provider-typesafe";
17
+ var CLOUDFLARE_API = "https://api.cloudflare.com";
12
18
  var pass = (id, message) => ({
13
19
  id,
14
20
  status: "pass",
@@ -29,11 +35,13 @@ function browserAvailable(kind) {
29
35
  return findBrowserExecutable(kind) !== null;
30
36
  }
31
37
  function keyPresent(config) {
32
- return Boolean(config.apiKey?.trim());
38
+ return Boolean(
39
+ config.apiKey?.trim() && (config.providerName !== "clef" || config.cloudflareAccountId?.trim())
40
+ );
33
41
  }
34
- async function networkReachable() {
42
+ async function networkReachable(baseURL) {
35
43
  try {
36
- await fetch("https://api.typesafe.ai/", {
44
+ await fetch(baseURL, {
37
45
  method: "GET",
38
46
  redirect: "manual",
39
47
  signal: AbortSignal.timeout(5e3)
@@ -77,7 +85,7 @@ async function checkOutputWritable(config) {
77
85
  }
78
86
  }
79
87
  }
80
- async function executeDoctorCommand(cwd, probes = {}) {
88
+ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
81
89
  const checks = [];
82
90
  const version = probes.nodeVersion ?? process.versions.node;
83
91
  checks.push(
@@ -128,17 +136,19 @@ async function executeDoctorCommand(cwd, probes = {}) {
128
136
  )
129
137
  );
130
138
  }
139
+ const providerBaseUrl = config?.providerName === "clef" ? CLOUDFLARE_API : config?.providerBaseUrl ?? DEFAULT_PROVIDER_BASE_URL;
140
+ const providerModel = config?.providerModel ?? DEFAULT_PROVIDER_MODEL;
131
141
  let network = false;
132
142
  try {
133
- network = await (probes.network ?? networkReachable)();
143
+ network = await (probes.network ?? networkReachable)(providerBaseUrl);
134
144
  } catch {
135
145
  network = false;
136
146
  }
137
147
  checks.push(
138
- network ? pass("api_network", "TypeSafe API is reachable.") : fail(
148
+ network ? pass("api_network", "Model provider API is reachable.") : fail(
139
149
  "api_network",
140
- "TypeSafe API could not be reached.",
141
- "Check DNS, TLS, proxy, firewall, and access to https://api.typesafe.ai."
150
+ "Model provider API could not be reached.",
151
+ `Check DNS, TLS, proxy, firewall, and access to ${providerBaseUrl}.`
142
152
  )
143
153
  );
144
154
  const key = config && keyPresent(config) ? config.apiKey?.trim() : void 0;
@@ -147,10 +157,10 @@ async function executeDoctorCommand(cwd, probes = {}) {
147
157
  "api_key",
148
158
  "API key source could not be read.",
149
159
  "Fix project configuration, then rerun doctor."
150
- ) : key ? pass("api_key", "TYPESAFE_API_KEY is present.") : fail(
160
+ ) : key ? pass("api_key", "Provider API key is present.") : fail(
151
161
  "api_key",
152
- "TYPESAFE_API_KEY is missing.",
153
- "Set TYPESAFE_API_KEY in the process environment or project-root .env."
162
+ "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."
154
164
  )
155
165
  );
156
166
  if (!config)
@@ -166,7 +176,7 @@ async function executeDoctorCommand(cwd, probes = {}) {
166
176
  fail(
167
177
  "api_auth",
168
178
  "API authentication could not be checked without a key.",
169
- "Set TYPESAFE_API_KEY, then rerun doctor."
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."
170
180
  )
171
181
  );
172
182
  else if (!network)
@@ -174,31 +184,82 @@ async function executeDoctorCommand(cwd, probes = {}) {
174
184
  fail(
175
185
  "api_auth",
176
186
  "API authentication could not be checked without API access.",
177
- "Restore TypeSafe API network access, then rerun doctor."
187
+ "Restore model provider API network access, then rerun doctor."
178
188
  )
179
189
  );
180
190
  else {
181
191
  let result;
182
192
  try {
183
- result = await (probes.auth ?? probeTypeSafeApiKey)(key);
193
+ if (config.providerName === "clef") {
194
+ result = probes.auth ? await probes.auth(key, {
195
+ baseURL: providerBaseUrl,
196
+ model: providerModel
197
+ }) : await (await import("@sedum-dev/provider-clef")).probeClefApiKey(key, {
198
+ accountId: config.cloudflareAccountId,
199
+ model: providerModel
200
+ });
201
+ } else
202
+ result = await (probes.auth ?? probeTypeSafeApiKey)(key, {
203
+ baseURL: providerBaseUrl,
204
+ model: providerModel
205
+ });
184
206
  } catch {
185
207
  result = "unavailable";
186
208
  }
187
209
  checks.push(
188
- result === "accepted" ? pass("api_auth", "TypeSafe API accepted the key.") : result === "rejected" ? fail(
210
+ result === "accepted" ? pass(
189
211
  "api_auth",
190
- "TypeSafe API rejected the key.",
191
- "Replace TYPESAFE_API_KEY with a valid key and rerun doctor."
212
+ config.providerName === "clef" ? "Cloudflare completed the explicitly billable inference probe." : "Model provider API accepted the key."
213
+ ) : result === "rejected" ? fail(
214
+ "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."
192
217
  ) : result === "unreachable" ? fail(
193
218
  "api_auth",
194
- "Authenticated TypeSafe request could not reach the API.",
219
+ "Authenticated provider request could not reach the API.",
195
220
  "Check the API connection and retry."
196
221
  ) : fail(
197
222
  "api_auth",
198
- "TypeSafe could not complete the authentication probe.",
199
- "Check API availability and account access, then retry."
223
+ "The model provider could not complete the authentication probe.",
224
+ config.providerName === "clef" ? "Check Cloudflare API availability, CLOUDFLARE_ACCOUNT_ID, and Workers AI access, then retry." : "Check API availability and account access, then retry."
225
+ )
226
+ );
227
+ }
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."
200
238
  )
201
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
+ );
202
263
  }
203
264
  if (config) {
204
265
  try {