sedum-cli 0.1.0-alpha.0
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/LICENSE +21 -0
- package/dist/chunk-BEV24G7S.js +444 -0
- package/dist/chunk-OB6ZUJ6X.js +242 -0
- package/dist/chunk-TU5MIKGA.js +963 -0
- package/dist/chunk-TZGSCV23.js +704 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +66 -0
- package/dist/doctor-command-2PMOA32Y.js +17 -0
- package/dist/index.d.ts +179 -0
- package/dist/index.js +19 -0
- package/dist/init-command-54R2FQ2U.js +237 -0
- package/dist/run-command-VAVFPCWG.js +1269 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sedum contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,444 @@
|
|
|
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
|
+
// src/locator-cache-store.ts
|
|
165
|
+
import { randomBytes, randomUUID } from "crypto";
|
|
166
|
+
import { execFile } from "child_process";
|
|
167
|
+
import { promisify } from "util";
|
|
168
|
+
import { promises as fs } from "fs";
|
|
169
|
+
import path from "path";
|
|
170
|
+
import {
|
|
171
|
+
LocatorCacheConflict,
|
|
172
|
+
NoopCacheStore
|
|
173
|
+
} from "@sedum-dev/core";
|
|
174
|
+
var run = promisify(execFile);
|
|
175
|
+
var HASH = /^[a-f0-9]{64}$/u;
|
|
176
|
+
var MAX_ENTRY_BYTES = 16 * 1024;
|
|
177
|
+
var KEY_FILE = "key";
|
|
178
|
+
var STALE_LOCK_MS = 1e4;
|
|
179
|
+
var ENTRY_DIR = "entries";
|
|
180
|
+
function isCi(env) {
|
|
181
|
+
return !!env.CI && env.CI !== "false" && env.CI !== "0";
|
|
182
|
+
}
|
|
183
|
+
async function gitCachePath(root) {
|
|
184
|
+
const env = { ...process.env };
|
|
185
|
+
delete env.GIT_DIR;
|
|
186
|
+
delete env.GIT_WORK_TREE;
|
|
187
|
+
delete env.GIT_COMMON_DIR;
|
|
188
|
+
try {
|
|
189
|
+
const inside = await run(
|
|
190
|
+
"git",
|
|
191
|
+
["-C", root, "rev-parse", "--is-inside-work-tree"],
|
|
192
|
+
{
|
|
193
|
+
env
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
if (inside.stdout.trim() !== "true") return null;
|
|
197
|
+
const metadata = await run(
|
|
198
|
+
"git",
|
|
199
|
+
[
|
|
200
|
+
"-C",
|
|
201
|
+
root,
|
|
202
|
+
"rev-parse",
|
|
203
|
+
"--path-format=absolute",
|
|
204
|
+
"--git-path",
|
|
205
|
+
"sedum/locator-cache"
|
|
206
|
+
],
|
|
207
|
+
{ env }
|
|
208
|
+
);
|
|
209
|
+
const resolved = metadata.stdout.trim();
|
|
210
|
+
return path.isAbsolute(resolved) ? resolved : null;
|
|
211
|
+
} catch {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function regularFile(filename) {
|
|
216
|
+
try {
|
|
217
|
+
return (await fs.lstat(filename)).isFile();
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (error.code === "ENOENT") return false;
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
async function atomicWrite(filename, content) {
|
|
224
|
+
const temp = `${filename}.${randomUUID()}.tmp`;
|
|
225
|
+
try {
|
|
226
|
+
await fs.writeFile(temp, content, {
|
|
227
|
+
encoding: "utf8",
|
|
228
|
+
flag: "wx",
|
|
229
|
+
mode: 384
|
|
230
|
+
});
|
|
231
|
+
await fs.rename(temp, filename);
|
|
232
|
+
} finally {
|
|
233
|
+
await fs.rm(temp, { force: true }).catch(() => void 0);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
var LocalLocatorCacheStore = class _LocalLocatorCacheStore {
|
|
237
|
+
constructor(directory, key) {
|
|
238
|
+
this.directory = directory;
|
|
239
|
+
this.key = key;
|
|
240
|
+
}
|
|
241
|
+
directory;
|
|
242
|
+
key;
|
|
243
|
+
static async open(directory) {
|
|
244
|
+
const parent = path.dirname(directory);
|
|
245
|
+
await fs.mkdir(parent, { recursive: true, mode: 448 });
|
|
246
|
+
if (!(await fs.lstat(parent)).isDirectory())
|
|
247
|
+
throw new Error("Invalid locator cache parent directory");
|
|
248
|
+
await fs.mkdir(directory, { mode: 448 }).catch((error) => {
|
|
249
|
+
if (error.code !== "EEXIST") throw error;
|
|
250
|
+
});
|
|
251
|
+
if (!(await fs.lstat(directory)).isDirectory())
|
|
252
|
+
throw new Error("Invalid locator cache directory");
|
|
253
|
+
await fs.chmod(directory, 448);
|
|
254
|
+
const entries = path.join(directory, ENTRY_DIR);
|
|
255
|
+
await fs.mkdir(entries, { mode: 448 }).catch((error) => {
|
|
256
|
+
if (error.code !== "EEXIST") throw error;
|
|
257
|
+
});
|
|
258
|
+
if (!(await fs.lstat(entries)).isDirectory())
|
|
259
|
+
throw new Error("Invalid locator entry directory");
|
|
260
|
+
await fs.chmod(entries, 448);
|
|
261
|
+
const keyPath = path.join(directory, KEY_FILE);
|
|
262
|
+
const lock = path.join(directory, ".init-lock");
|
|
263
|
+
let acquired = false;
|
|
264
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
265
|
+
try {
|
|
266
|
+
await fs.mkdir(lock, { mode: 448 });
|
|
267
|
+
acquired = true;
|
|
268
|
+
break;
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (error.code !== "EEXIST") throw error;
|
|
271
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (!acquired) throw new Error("Locator cache initialization timed out");
|
|
275
|
+
let key;
|
|
276
|
+
try {
|
|
277
|
+
if (await regularFile(keyPath)) {
|
|
278
|
+
key = new Uint8Array(await fs.readFile(keyPath));
|
|
279
|
+
if (key.byteLength !== 32) throw new Error("Invalid locator cache key");
|
|
280
|
+
await fs.chmod(keyPath, 384);
|
|
281
|
+
} else {
|
|
282
|
+
const generated = randomBytes(32);
|
|
283
|
+
await fs.writeFile(keyPath, generated, { flag: "wx", mode: 384 });
|
|
284
|
+
for (const name of await fs.readdir(entries))
|
|
285
|
+
await fs.rm(path.join(entries, name), { force: true });
|
|
286
|
+
key = generated;
|
|
287
|
+
}
|
|
288
|
+
} finally {
|
|
289
|
+
await fs.rmdir(lock);
|
|
290
|
+
}
|
|
291
|
+
return new _LocalLocatorCacheStore(directory, key);
|
|
292
|
+
}
|
|
293
|
+
filename(key) {
|
|
294
|
+
if (!HASH.test(key))
|
|
295
|
+
throw new RangeError("Invalid locator cache key digest");
|
|
296
|
+
return path.join(this.directory, ENTRY_DIR, `${key}.json`);
|
|
297
|
+
}
|
|
298
|
+
async currentKey() {
|
|
299
|
+
const filename = path.join(this.directory, KEY_FILE);
|
|
300
|
+
if (!await regularFile(filename)) return false;
|
|
301
|
+
const current = await fs.readFile(filename);
|
|
302
|
+
return current.byteLength === 32 && Buffer.from(this.key).equals(current);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Break a lock a crashed writer left behind, as `proper-lockfile` does: an
|
|
306
|
+
* mtime older than `STALE_LOCK_MS`. The atomic rename means only one waiter
|
|
307
|
+
* can break it.
|
|
308
|
+
*/
|
|
309
|
+
async breakStaleLock(lock) {
|
|
310
|
+
const stat = await fs.lstat(lock).catch(() => null);
|
|
311
|
+
if (!stat?.isDirectory() || Date.now() - stat.mtimeMs <= STALE_LOCK_MS)
|
|
312
|
+
return;
|
|
313
|
+
const stale = `${lock}.stale-${randomBytes(6).toString("hex")}`;
|
|
314
|
+
try {
|
|
315
|
+
await fs.rename(lock, stale);
|
|
316
|
+
} catch {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
await fs.rm(stale, { recursive: true, force: true });
|
|
320
|
+
}
|
|
321
|
+
async withEntryLock(key, operation) {
|
|
322
|
+
const lock = `${this.filename(key)}.lock`;
|
|
323
|
+
let acquired = false;
|
|
324
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
325
|
+
try {
|
|
326
|
+
await fs.mkdir(lock, { mode: 448 });
|
|
327
|
+
acquired = true;
|
|
328
|
+
break;
|
|
329
|
+
} catch (error) {
|
|
330
|
+
if (error.code !== "EEXIST") throw error;
|
|
331
|
+
await this.breakStaleLock(lock);
|
|
332
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (!acquired) throw new LocatorCacheConflict();
|
|
336
|
+
try {
|
|
337
|
+
return await operation();
|
|
338
|
+
} finally {
|
|
339
|
+
await fs.rmdir(lock);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
async lookup(key) {
|
|
343
|
+
try {
|
|
344
|
+
if (!await this.currentKey()) return { reason: "corrupt" };
|
|
345
|
+
const filename = this.filename(key);
|
|
346
|
+
if (!await regularFile(filename)) return { reason: "absent" };
|
|
347
|
+
const stat = await fs.stat(filename);
|
|
348
|
+
if (stat.size > MAX_ENTRY_BYTES) return { reason: "corrupt" };
|
|
349
|
+
const value = JSON.parse(await fs.readFile(filename, "utf8"));
|
|
350
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
351
|
+
return { reason: "corrupt" };
|
|
352
|
+
return { entry: value };
|
|
353
|
+
} catch (error) {
|
|
354
|
+
if (error.code === "ENOENT")
|
|
355
|
+
return { reason: "absent" };
|
|
356
|
+
if (error instanceof SyntaxError) return { reason: "corrupt" };
|
|
357
|
+
return { reason: "storage_error" };
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
async put(key, entry) {
|
|
361
|
+
await this.withEntryLock(key, async () => {
|
|
362
|
+
if (!await this.currentKey())
|
|
363
|
+
throw new Error("Locator cache key changed");
|
|
364
|
+
if (entry.pageKey !== key) throw new Error("Locator entry key mismatch");
|
|
365
|
+
const content = JSON.stringify(entry);
|
|
366
|
+
if (Buffer.byteLength(content) > MAX_ENTRY_BYTES)
|
|
367
|
+
throw new Error("Locator entry too large");
|
|
368
|
+
await atomicWrite(this.filename(key), content);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
async invalidate(key, observed) {
|
|
372
|
+
await this.withEntryLock(key, async () => {
|
|
373
|
+
if (!await this.currentKey()) return;
|
|
374
|
+
const filename = this.filename(key);
|
|
375
|
+
if (!await regularFile(filename)) return;
|
|
376
|
+
const stat = await fs.stat(filename);
|
|
377
|
+
if (stat.size > MAX_ENTRY_BYTES) {
|
|
378
|
+
if (!observed) await fs.rm(filename, { force: true });
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
let current;
|
|
382
|
+
try {
|
|
383
|
+
current = JSON.parse(await fs.readFile(filename, "utf8"));
|
|
384
|
+
} catch (error) {
|
|
385
|
+
if (error instanceof SyntaxError && !observed)
|
|
386
|
+
await fs.rm(filename, { force: true });
|
|
387
|
+
else if (!(error instanceof SyntaxError)) throw error;
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (observed) {
|
|
391
|
+
if (JSON.stringify(current) === JSON.stringify(observed))
|
|
392
|
+
await fs.rm(filename, { force: true });
|
|
393
|
+
} else if (!current || typeof current !== "object" || Array.isArray(current))
|
|
394
|
+
await fs.rm(filename, { force: true });
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
async clear() {
|
|
398
|
+
await fs.rm(this.directory, { recursive: true, force: true });
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
async function openLocatorCache(root, policy = {}) {
|
|
402
|
+
if (policy.disabled) return new NoopCacheStore("disabled");
|
|
403
|
+
const env = policy.env ?? process.env;
|
|
404
|
+
if (isCi(env) && !policy.ciOptIn && env.SEDUM_LOCATOR_CACHE_CI !== "1")
|
|
405
|
+
return new NoopCacheStore("ci_default");
|
|
406
|
+
const directory = await gitCachePath(root);
|
|
407
|
+
if (!directory) return new NoopCacheStore("outside_git");
|
|
408
|
+
try {
|
|
409
|
+
return await LocalLocatorCacheStore.open(directory);
|
|
410
|
+
} catch (error) {
|
|
411
|
+
return new NoopCacheStore(
|
|
412
|
+
error instanceof Error && error.message === "Invalid locator cache key" ? "corrupt" : "storage_error"
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
async function clearLocatorCache(root) {
|
|
417
|
+
const directory = await gitCachePath(root);
|
|
418
|
+
if (!directory) return false;
|
|
419
|
+
try {
|
|
420
|
+
if (!(await fs.lstat(path.dirname(directory))).isDirectory())
|
|
421
|
+
throw new Error("Invalid locator cache parent directory");
|
|
422
|
+
if (!(await fs.lstat(directory)).isDirectory())
|
|
423
|
+
throw new Error("Invalid locator cache directory");
|
|
424
|
+
} catch (error) {
|
|
425
|
+
if (error.code === "ENOENT") return false;
|
|
426
|
+
throw error;
|
|
427
|
+
}
|
|
428
|
+
await fs.rm(directory, { recursive: true, force: true });
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export {
|
|
433
|
+
setupDiagnostic,
|
|
434
|
+
outputDiagnostic,
|
|
435
|
+
canonicalDiagnosticError,
|
|
436
|
+
flowDiagnostic,
|
|
437
|
+
renderDiagnostic,
|
|
438
|
+
MAX_PARALLEL,
|
|
439
|
+
planLanes,
|
|
440
|
+
parseParallel,
|
|
441
|
+
runPool,
|
|
442
|
+
openLocatorCache,
|
|
443
|
+
clearLocatorCache
|
|
444
|
+
};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadProjectConfig
|
|
3
|
+
} from "./chunk-TZGSCV23.js";
|
|
4
|
+
|
|
5
|
+
// src/doctor-command.ts
|
|
6
|
+
import { lstat, mkdir, mkdtemp, rm, rmdir, writeFile } from "fs/promises";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import { findBrowserExecutable } from "@sedum-dev/core";
|
|
9
|
+
import {
|
|
10
|
+
probeTypeSafeApiKey
|
|
11
|
+
} from "@sedum-dev/provider-typesafe";
|
|
12
|
+
var pass = (id, message) => ({
|
|
13
|
+
id,
|
|
14
|
+
status: "pass",
|
|
15
|
+
message,
|
|
16
|
+
fix: null
|
|
17
|
+
});
|
|
18
|
+
var fail = (id, message, fix) => ({
|
|
19
|
+
id,
|
|
20
|
+
status: "fail",
|
|
21
|
+
message,
|
|
22
|
+
fix
|
|
23
|
+
});
|
|
24
|
+
function supportedNode(version) {
|
|
25
|
+
const parts = version.split(".").map(Number);
|
|
26
|
+
return parts.length >= 3 && parts.every(Number.isSafeInteger) && (parts[0] > 20 || parts[0] === 20 && (parts[1] > 19 || parts[1] === 19 && parts[2] >= 0));
|
|
27
|
+
}
|
|
28
|
+
function browserAvailable(kind) {
|
|
29
|
+
return findBrowserExecutable(kind) !== null;
|
|
30
|
+
}
|
|
31
|
+
function keyPresent(config) {
|
|
32
|
+
return Boolean(config.apiKey?.trim());
|
|
33
|
+
}
|
|
34
|
+
async function networkReachable() {
|
|
35
|
+
try {
|
|
36
|
+
await fetch("https://api.typesafe.ai/", {
|
|
37
|
+
method: "GET",
|
|
38
|
+
redirect: "manual",
|
|
39
|
+
signal: AbortSignal.timeout(5e3)
|
|
40
|
+
});
|
|
41
|
+
return true;
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function checkOutputWritable(config) {
|
|
47
|
+
const root = path.resolve(config.projectRoot);
|
|
48
|
+
const base = path.resolve(config.outputDir);
|
|
49
|
+
const relative = path.relative(root, base);
|
|
50
|
+
if (relative === ".." || relative.startsWith(`..${path.sep}`))
|
|
51
|
+
throw new Error("output path escapes project root");
|
|
52
|
+
const created = [];
|
|
53
|
+
let temporary;
|
|
54
|
+
try {
|
|
55
|
+
let current = root;
|
|
56
|
+
for (const segment of relative.split(path.sep).filter(Boolean)) {
|
|
57
|
+
current = path.join(current, segment);
|
|
58
|
+
try {
|
|
59
|
+
await mkdir(current, { mode: 448 });
|
|
60
|
+
created.push(current);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error.code !== "EEXIST") throw error;
|
|
63
|
+
}
|
|
64
|
+
const info = await lstat(current);
|
|
65
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
66
|
+
throw new Error("output path is not a regular directory");
|
|
67
|
+
}
|
|
68
|
+
temporary = await mkdtemp(path.join(base, ".doctor-"));
|
|
69
|
+
await writeFile(path.join(temporary, "write-probe"), "ok", {
|
|
70
|
+
flag: "wx",
|
|
71
|
+
mode: 384
|
|
72
|
+
});
|
|
73
|
+
} finally {
|
|
74
|
+
if (temporary) await rm(temporary, { recursive: true, force: true });
|
|
75
|
+
for (const directory of created.reverse()) {
|
|
76
|
+
await rmdir(directory).catch(() => void 0);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function executeDoctorCommand(cwd, probes = {}) {
|
|
81
|
+
const checks = [];
|
|
82
|
+
const version = probes.nodeVersion ?? process.versions.node;
|
|
83
|
+
checks.push(
|
|
84
|
+
supportedNode(version) ? pass("node", `Node ${version} meets the >=20.19.0 requirement.`) : fail(
|
|
85
|
+
"node",
|
|
86
|
+
`Node ${version} is too old or invalid.`,
|
|
87
|
+
"Install Node 20.19.0 or newer."
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
let config = null;
|
|
91
|
+
try {
|
|
92
|
+
config = await (probes.loadConfig ?? loadProjectConfig)(cwd);
|
|
93
|
+
checks.push(pass("config", "Project configuration is valid."));
|
|
94
|
+
} catch {
|
|
95
|
+
checks.push(
|
|
96
|
+
fail(
|
|
97
|
+
"config",
|
|
98
|
+
"Project configuration could not be loaded.",
|
|
99
|
+
"Correct sedum.config.yaml or the project-root .env and check file permissions."
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
if (config) {
|
|
104
|
+
try {
|
|
105
|
+
const available = (probes.browser ?? browserAvailable)(config.browser);
|
|
106
|
+
checks.push(
|
|
107
|
+
available ? pass("browser", `${config.browser} is available.`) : fail(
|
|
108
|
+
"browser",
|
|
109
|
+
`${config.browser} was not found.`,
|
|
110
|
+
"Install Chrome or run `sedum browsers install chromium`; check the configured browser."
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
} catch {
|
|
114
|
+
checks.push(
|
|
115
|
+
fail(
|
|
116
|
+
"browser",
|
|
117
|
+
"Browser availability could not be checked.",
|
|
118
|
+
"Check the browser installation and retry."
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
checks.push(
|
|
124
|
+
fail(
|
|
125
|
+
"browser",
|
|
126
|
+
"Configured browser is unknown.",
|
|
127
|
+
"Fix project configuration, then rerun doctor."
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
let network = false;
|
|
132
|
+
try {
|
|
133
|
+
network = await (probes.network ?? networkReachable)();
|
|
134
|
+
} catch {
|
|
135
|
+
network = false;
|
|
136
|
+
}
|
|
137
|
+
checks.push(
|
|
138
|
+
network ? pass("api_network", "TypeSafe API is reachable.") : fail(
|
|
139
|
+
"api_network",
|
|
140
|
+
"TypeSafe API could not be reached.",
|
|
141
|
+
"Check DNS, TLS, proxy, firewall, and access to https://api.typesafe.ai."
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
const key = config && keyPresent(config) ? config.apiKey?.trim() : void 0;
|
|
145
|
+
checks.push(
|
|
146
|
+
!config ? fail(
|
|
147
|
+
"api_key",
|
|
148
|
+
"API key source could not be read.",
|
|
149
|
+
"Fix project configuration, then rerun doctor."
|
|
150
|
+
) : key ? pass("api_key", "TYPESAFE_API_KEY is present.") : fail(
|
|
151
|
+
"api_key",
|
|
152
|
+
"TYPESAFE_API_KEY is missing.",
|
|
153
|
+
"Set TYPESAFE_API_KEY in the process environment or project-root .env."
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
if (!config)
|
|
157
|
+
checks.push(
|
|
158
|
+
fail(
|
|
159
|
+
"api_auth",
|
|
160
|
+
"API authentication could not be checked.",
|
|
161
|
+
"Fix project configuration, then rerun doctor."
|
|
162
|
+
)
|
|
163
|
+
);
|
|
164
|
+
else if (!key)
|
|
165
|
+
checks.push(
|
|
166
|
+
fail(
|
|
167
|
+
"api_auth",
|
|
168
|
+
"API authentication could not be checked without a key.",
|
|
169
|
+
"Set TYPESAFE_API_KEY, then rerun doctor."
|
|
170
|
+
)
|
|
171
|
+
);
|
|
172
|
+
else if (!network)
|
|
173
|
+
checks.push(
|
|
174
|
+
fail(
|
|
175
|
+
"api_auth",
|
|
176
|
+
"API authentication could not be checked without API access.",
|
|
177
|
+
"Restore TypeSafe API network access, then rerun doctor."
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
else {
|
|
181
|
+
let result;
|
|
182
|
+
try {
|
|
183
|
+
result = await (probes.auth ?? probeTypeSafeApiKey)(key);
|
|
184
|
+
} catch {
|
|
185
|
+
result = "unavailable";
|
|
186
|
+
}
|
|
187
|
+
checks.push(
|
|
188
|
+
result === "accepted" ? pass("api_auth", "TypeSafe API accepted the key.") : result === "rejected" ? fail(
|
|
189
|
+
"api_auth",
|
|
190
|
+
"TypeSafe API rejected the key.",
|
|
191
|
+
"Replace TYPESAFE_API_KEY with a valid key and rerun doctor."
|
|
192
|
+
) : result === "unreachable" ? fail(
|
|
193
|
+
"api_auth",
|
|
194
|
+
"Authenticated TypeSafe request could not reach the API.",
|
|
195
|
+
"Check the API connection and retry."
|
|
196
|
+
) : fail(
|
|
197
|
+
"api_auth",
|
|
198
|
+
"TypeSafe could not complete the authentication probe.",
|
|
199
|
+
"Check API availability and account access, then retry."
|
|
200
|
+
)
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
if (config) {
|
|
204
|
+
try {
|
|
205
|
+
await (probes.output ?? checkOutputWritable)(config);
|
|
206
|
+
checks.push(pass("output", "Output directory is writable."));
|
|
207
|
+
} catch {
|
|
208
|
+
checks.push(
|
|
209
|
+
fail(
|
|
210
|
+
"output",
|
|
211
|
+
"Output directory is not writable or safe.",
|
|
212
|
+
"Choose a writable, non-symlinked outputDir inside the project root and check permissions."
|
|
213
|
+
)
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
checks.push(
|
|
218
|
+
fail(
|
|
219
|
+
"output",
|
|
220
|
+
"Configured output directory is unknown.",
|
|
221
|
+
"Fix project configuration, then rerun doctor."
|
|
222
|
+
)
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
return { schemaVersion: 1, checks };
|
|
226
|
+
}
|
|
227
|
+
function renderDoctorText(result) {
|
|
228
|
+
return result.checks.map(
|
|
229
|
+
(check) => `${check.status === "pass" ? "PASS" : "FAIL"} ${check.id}: ${check.message}${check.fix ? `
|
|
230
|
+
Fix: ${check.fix}` : ""}
|
|
231
|
+
`
|
|
232
|
+
).join("");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export {
|
|
236
|
+
supportedNode,
|
|
237
|
+
browserAvailable,
|
|
238
|
+
keyPresent,
|
|
239
|
+
checkOutputWritable,
|
|
240
|
+
executeDoctorCommand,
|
|
241
|
+
renderDoctorText
|
|
242
|
+
};
|