sedum-cli 0.1.0-alpha.7 → 0.1.0-alpha.9
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-OHKZUPYG.js → affected-selection-ENIH4AGP.js} +24 -14
- package/dist/{chunk-BEY4UNIW.js → chunk-37KG5X5K.js} +0 -166
- package/dist/{chunk-FKAOS73X.js → chunk-6JUQUT2O.js} +31 -22
- package/dist/{chunk-DRCPO7W3.js → chunk-7M7YUTRH.js} +1 -1
- package/dist/{chunk-NMAMFLDA.js → chunk-H4QXVVQI.js} +28 -13
- package/dist/chunk-NOGCXR4U.js +208 -0
- package/dist/{chunk-GYFQYSYT.js → chunk-VNGIF7AY.js} +70 -8
- package/dist/cli.js +4 -3
- package/dist/{doctor-command-5HKQX3DN.js → doctor-command-XRE6PEGU.js} +2 -2
- package/dist/index.d.ts +7 -3
- package/dist/index.js +4 -3
- package/dist/{init-command-CTZAAPJ5.js → init-command-SXAVPVX6.js} +12 -5
- package/dist/{run-command-GQN53UWF.js → run-command-D5KF6PB3.js} +19 -23
- package/package.json +5 -4
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
discoverRunTests
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7M7YUTRH.js";
|
|
4
|
+
import {
|
|
5
|
+
createCliProvider,
|
|
6
|
+
providerDiagnostic
|
|
7
|
+
} from "./chunk-NOGCXR4U.js";
|
|
4
8
|
import {
|
|
5
9
|
loadProjectConfig
|
|
6
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-VNGIF7AY.js";
|
|
7
11
|
|
|
8
12
|
// src/affected-selection.ts
|
|
9
13
|
import { execFile } from "child_process";
|
|
@@ -13,11 +17,9 @@ import { promisify } from "util";
|
|
|
13
17
|
import {
|
|
14
18
|
isScriptTestFile,
|
|
15
19
|
loadFlowFile,
|
|
20
|
+
ProviderError,
|
|
16
21
|
resolveFlowModules
|
|
17
22
|
} from "@sedum-dev/core";
|
|
18
|
-
import {
|
|
19
|
-
TypeSafeAdapter
|
|
20
|
-
} from "@sedum-dev/provider-typesafe";
|
|
21
23
|
var exec = promisify(execFile);
|
|
22
24
|
var AffectedSelectionError = class extends Error {
|
|
23
25
|
};
|
|
@@ -167,15 +169,23 @@ async function selectAffectedTests(options) {
|
|
|
167
169
|
});
|
|
168
170
|
}
|
|
169
171
|
options.signal?.throwIfAborted();
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
tests,
|
|
177
|
-
|
|
178
|
-
|
|
172
|
+
let scores;
|
|
173
|
+
try {
|
|
174
|
+
scores = branch.diff ? await (options.createProvider ? await options.createProvider(config) : await createCliProvider(config)).scoreRelevance(
|
|
175
|
+
branch.diff,
|
|
176
|
+
tests,
|
|
177
|
+
options.signal ? { signal: options.signal } : void 0
|
|
178
|
+
) : { probabilities: tests.map(() => 0), calls: [] };
|
|
179
|
+
} catch (error) {
|
|
180
|
+
if (error instanceof ProviderError && (error.code === "authentication" || error.code === "configuration")) {
|
|
181
|
+
const diagnostic = providerDiagnostic(config.providerName, error.code);
|
|
182
|
+
throw new AffectedSelectionError(
|
|
183
|
+
`${diagnostic.message}
|
|
184
|
+
Fix: ${diagnostic.fix}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
179
189
|
return {
|
|
180
190
|
base: branch.base,
|
|
181
191
|
mergeBase: branch.mergeBase,
|
|
@@ -1,163 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ProjectConfigError
|
|
3
|
-
} from "./chunk-GYFQYSYT.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 model provider is not configured.",
|
|
13
|
-
fix: "Set TYPESAFE_API_KEY for the configured endpoint, then 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 === "navigation_failed")
|
|
107
|
-
return {
|
|
108
|
-
code: result.code,
|
|
109
|
-
message: bounded(result.message),
|
|
110
|
-
fix: bounded(
|
|
111
|
-
result.fix ?? "Check the test's url (or baseUrl), your network or VPN, and that the site is up."
|
|
112
|
-
)
|
|
113
|
-
};
|
|
114
|
-
if (result.code === "provider_rate_limited")
|
|
115
|
-
return {
|
|
116
|
-
code: result.code,
|
|
117
|
-
message: "The model provider kept rate limiting requests for five minutes.",
|
|
118
|
-
fix: "Lower --parallel or --provider-concurrency, or retry later."
|
|
119
|
-
};
|
|
120
|
-
if (result.code === "provider_authentication")
|
|
121
|
-
return {
|
|
122
|
-
code: result.code,
|
|
123
|
-
message: "The model provider rejected the API key.",
|
|
124
|
-
fix: "Set TYPESAFE_API_KEY to a valid key, check it with `sedum doctor`, then rerun."
|
|
125
|
-
};
|
|
126
|
-
if (result.code === "provider_configuration")
|
|
127
|
-
return {
|
|
128
|
-
code: result.code,
|
|
129
|
-
message: "The model provider is not configured correctly.",
|
|
130
|
-
fix: "Check TYPESAFE_API_KEY, TYPESAFE_BASE_URL and the model with `sedum doctor`, then rerun."
|
|
131
|
-
};
|
|
132
|
-
if (result.code.startsWith("provider_"))
|
|
133
|
-
return {
|
|
134
|
-
code: result.code,
|
|
135
|
-
message: "The model provider could not complete the run safely.",
|
|
136
|
-
fix: "Check provider availability and the test input, then rerun the test."
|
|
137
|
-
};
|
|
138
|
-
return {
|
|
139
|
-
code: "execution_error",
|
|
140
|
-
message: "The browser run could not be completed safely.",
|
|
141
|
-
fix: "Check the browser, provider, and test input, then rerun the test."
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
var RUN_STOPPING_CODES = /* @__PURE__ */ new Set([
|
|
145
|
-
"browser-missing",
|
|
146
|
-
"browser-launch-failed",
|
|
147
|
-
"script-missing",
|
|
148
|
-
"provider_configuration",
|
|
149
|
-
"provider_authentication",
|
|
150
|
-
"provider_rate_limited"
|
|
151
|
-
]);
|
|
152
|
-
function stopsRun(code) {
|
|
153
|
-
return RUN_STOPPING_CODES.has(code);
|
|
154
|
-
}
|
|
155
|
-
function renderDiagnostic(diagnostic) {
|
|
156
|
-
return `${diagnostic.message}
|
|
157
|
-
Fix: ${diagnostic.fix}
|
|
158
|
-
`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
1
|
// src/run-pool.ts
|
|
162
2
|
var MAX_PARALLEL = 64;
|
|
163
3
|
function planLanes(requested, availableParallelism, selectedTests) {
|
|
@@ -461,12 +301,6 @@ async function clearLocatorCache(root) {
|
|
|
461
301
|
}
|
|
462
302
|
|
|
463
303
|
export {
|
|
464
|
-
setupDiagnostic,
|
|
465
|
-
outputDiagnostic,
|
|
466
|
-
canonicalDiagnosticError,
|
|
467
|
-
flowDiagnostic,
|
|
468
|
-
stopsRun,
|
|
469
|
-
renderDiagnostic,
|
|
470
304
|
MAX_PARALLEL,
|
|
471
305
|
planLanes,
|
|
472
306
|
parseParallel,
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MAX_PARALLEL,
|
|
3
3
|
clearLocatorCache,
|
|
4
|
-
parseParallel
|
|
4
|
+
parseParallel
|
|
5
|
+
} from "./chunk-37KG5X5K.js";
|
|
6
|
+
import {
|
|
7
|
+
configDiagnostic,
|
|
8
|
+
createCliProvider,
|
|
5
9
|
renderDiagnostic
|
|
6
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-NOGCXR4U.js";
|
|
7
11
|
import {
|
|
8
12
|
ProjectConfigError,
|
|
9
13
|
discoverConfiguredTests,
|
|
10
14
|
loadProjectConfig
|
|
11
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-VNGIF7AY.js";
|
|
12
16
|
|
|
13
17
|
// src/invocation.ts
|
|
14
18
|
function sedumCommand(env = process.env, script = process.argv[1] ?? "") {
|
|
@@ -351,14 +355,6 @@ import {
|
|
|
351
355
|
validateProject
|
|
352
356
|
} from "@sedum-dev/core";
|
|
353
357
|
import path2 from "path";
|
|
354
|
-
var createTypeSafeClassifier = async ({
|
|
355
|
-
apiKey,
|
|
356
|
-
baseURL,
|
|
357
|
-
model
|
|
358
|
-
}) => {
|
|
359
|
-
const { TypeSafeAdapter } = await import("@sedum-dev/provider-typesafe");
|
|
360
|
-
return new TypeSafeAdapter({ ...apiKey ? { apiKey } : {}, baseURL, model });
|
|
361
|
-
};
|
|
362
358
|
function emptyProjectProblem(paths, testDirectory) {
|
|
363
359
|
const shown = paths.length ? paths.join(", ") : testDirectory || ".";
|
|
364
360
|
return {
|
|
@@ -371,7 +367,7 @@ function emptyProjectProblem(paths, testDirectory) {
|
|
|
371
367
|
var missingKey = {
|
|
372
368
|
code: "missing_key",
|
|
373
369
|
message: "`sedum validate --online` needs a configured model provider.",
|
|
374
|
-
fix: "Set TYPESAFE_API_KEY
|
|
370
|
+
fix: "Set the selected provider's credentials (TYPESAFE_API_KEY, or CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN/CLOUDFLARE_API_TOKEN) and rerun; otherwise omit --online."
|
|
375
371
|
};
|
|
376
372
|
async function onlineProvider(options) {
|
|
377
373
|
try {
|
|
@@ -380,11 +376,16 @@ async function onlineProvider(options) {
|
|
|
380
376
|
provider: await options.createProvider({
|
|
381
377
|
...config.apiKey ? { apiKey: config.apiKey } : {},
|
|
382
378
|
baseURL: config.providerBaseUrl,
|
|
383
|
-
model: config.providerModel
|
|
379
|
+
model: config.providerModel,
|
|
380
|
+
...config.providerName === "clef" ? {
|
|
381
|
+
providerName: config.providerName,
|
|
382
|
+
...config.cloudflareAccountId ? { accountId: config.cloudflareAccountId } : {}
|
|
383
|
+
} : {}
|
|
384
384
|
}),
|
|
385
385
|
model: config.providerModel
|
|
386
386
|
};
|
|
387
387
|
} catch (error) {
|
|
388
|
+
if (error instanceof ProjectConfigError) return configDiagnostic(error);
|
|
388
389
|
if (error instanceof ProviderError && error.code === "configuration")
|
|
389
390
|
return missingKey;
|
|
390
391
|
return {
|
|
@@ -394,6 +395,13 @@ async function onlineProvider(options) {
|
|
|
394
395
|
};
|
|
395
396
|
}
|
|
396
397
|
}
|
|
398
|
+
var createSelectedClassifier = (options) => createCliProvider({
|
|
399
|
+
providerName: options.providerName ?? "typesafe",
|
|
400
|
+
apiKey: options.apiKey,
|
|
401
|
+
cloudflareAccountId: options.accountId,
|
|
402
|
+
providerModel: options.model,
|
|
403
|
+
providerBaseUrl: options.baseURL
|
|
404
|
+
});
|
|
397
405
|
async function executeValidateCommand(options) {
|
|
398
406
|
const context = await loadProjectContext(options.paths, options.cwd);
|
|
399
407
|
if (!context.config)
|
|
@@ -434,7 +442,8 @@ async function executeValidateCommand(options) {
|
|
|
434
442
|
}
|
|
435
443
|
const cache = await FileClassificationCache.load(
|
|
436
444
|
path2.join(discovery.root, ".sedum", "classifications.json"),
|
|
437
|
-
classificationModel
|
|
445
|
+
classificationModel,
|
|
446
|
+
config.providerName
|
|
438
447
|
);
|
|
439
448
|
const result = await validateProject(discovery, {
|
|
440
449
|
repoRoot: discovery.root,
|
|
@@ -664,7 +673,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
664
673
|
const writeOut = (value) => rawOut(withCommand(value, command));
|
|
665
674
|
const writeErr = (value) => rawErr(withCommand(value, command));
|
|
666
675
|
const capabilities = runtime.capabilities ?? plainOutput;
|
|
667
|
-
const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-
|
|
676
|
+
const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-D5KF6PB3.js")).executeRunCommand(options));
|
|
668
677
|
const cwd = runtime.cwd ?? process.cwd();
|
|
669
678
|
let exitCode = 3;
|
|
670
679
|
const program = new Command().name("sedum").description(
|
|
@@ -682,7 +691,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
682
691
|
"after",
|
|
683
692
|
"\nCreates a config, a SauceDemo example, .env.example, and ignore rules.\nExisting files are never replaced.\n"
|
|
684
693
|
).action(async () => {
|
|
685
|
-
const { executeInitCommand } = await import("./init-command-
|
|
694
|
+
const { executeInitCommand } = await import("./init-command-SXAVPVX6.js");
|
|
686
695
|
const interactive = capabilities.stdoutIsTTY && (process.stdin.isTTY === true || runtime.confirmInit !== void 0);
|
|
687
696
|
const confirm = runtime.confirmInit ?? (interactive ? async (question) => {
|
|
688
697
|
const { createInterface } = await import("readline/promises");
|
|
@@ -713,7 +722,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
713
722
|
"test files or directories relative to the project root"
|
|
714
723
|
).option(
|
|
715
724
|
"--affected",
|
|
716
|
-
"experimental: send Git diff and test sources to
|
|
725
|
+
"experimental: send Git diff and test sources to the text provider; run relevant tests",
|
|
717
726
|
false
|
|
718
727
|
).option("--base <ref>", "base ref for --affected (default main or master)").option(
|
|
719
728
|
"--threshold <probability>",
|
|
@@ -721,7 +730,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
721
730
|
relevanceThreshold
|
|
722
731
|
).option(
|
|
723
732
|
"--selection-only",
|
|
724
|
-
"with --affected, print selection JSON without running tests (calls
|
|
733
|
+
"with --affected, print selection JSON without running tests (calls the text provider)",
|
|
725
734
|
false
|
|
726
735
|
).option(
|
|
727
736
|
"--include <glob>",
|
|
@@ -829,10 +838,10 @@ async function runCli(args, version, runtime = {}) {
|
|
|
829
838
|
return;
|
|
830
839
|
}
|
|
831
840
|
if (options.affected) {
|
|
832
|
-
const { selectAffectedTests, AffectedSelectionError } = await import("./affected-selection-
|
|
841
|
+
const { selectAffectedTests, AffectedSelectionError } = await import("./affected-selection-ENIH4AGP.js");
|
|
833
842
|
const { ProviderError: ProviderError2 } = await import("@sedum-dev/core");
|
|
834
843
|
writeErr(
|
|
835
|
-
"Experimental selection sends the tracked Git diff and test/module sources to the configured
|
|
844
|
+
"Experimental selection sends the tracked Git diff and test/module sources to the configured provider. Full CI is still recommended.\n"
|
|
836
845
|
);
|
|
837
846
|
try {
|
|
838
847
|
const selection = await selectAffectedTests({
|
|
@@ -1021,7 +1030,7 @@ No tests were run. Fix the selection error or run without --affected.
|
|
|
1021
1030
|
"after",
|
|
1022
1031
|
"\nThe authenticated API check makes one small, potentially billable request.\n\nExit codes:\n 0 all checks passed\n 3 one or more prerequisites failed\n"
|
|
1023
1032
|
).action(async (options) => {
|
|
1024
|
-
const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-
|
|
1033
|
+
const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-XRE6PEGU.js");
|
|
1025
1034
|
const result = await executeDoctorCommand(cwd, runtime.doctorProbes, {
|
|
1026
1035
|
vision: options.vision
|
|
1027
1036
|
});
|
|
@@ -1048,7 +1057,7 @@ No tests were run. Fix the selection error or run without --affected.
|
|
|
1048
1057
|
paths,
|
|
1049
1058
|
online: options.online,
|
|
1050
1059
|
cwd,
|
|
1051
|
-
createProvider: runtime.createClassificationProvider ??
|
|
1060
|
+
createProvider: runtime.createClassificationProvider ?? createSelectedClassifier,
|
|
1052
1061
|
...runtime.signal ? { signal: runtime.signal } : {}
|
|
1053
1062
|
});
|
|
1054
1063
|
const problems = execution.discovery?.problems ?? [];
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
DEFAULT_PROVIDER_BASE_URL,
|
|
3
3
|
DEFAULT_PROVIDER_MODEL,
|
|
4
4
|
loadProjectConfig
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-VNGIF7AY.js";
|
|
6
6
|
|
|
7
7
|
// src/doctor-command.ts
|
|
8
8
|
import { lstat, mkdir, mkdtemp, rm, rmdir, writeFile } from "fs/promises";
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
probeTypeSafeApiKey
|
|
16
16
|
} from "@sedum-dev/provider-typesafe";
|
|
17
|
+
var CLOUDFLARE_API = "https://api.cloudflare.com";
|
|
17
18
|
var pass = (id, message) => ({
|
|
18
19
|
id,
|
|
19
20
|
status: "pass",
|
|
@@ -34,7 +35,9 @@ function browserAvailable(kind) {
|
|
|
34
35
|
return findBrowserExecutable(kind) !== null;
|
|
35
36
|
}
|
|
36
37
|
function keyPresent(config) {
|
|
37
|
-
return Boolean(
|
|
38
|
+
return Boolean(
|
|
39
|
+
config.apiKey?.trim() && (config.providerName !== "clef" || config.cloudflareAccountId?.trim())
|
|
40
|
+
);
|
|
38
41
|
}
|
|
39
42
|
async function networkReachable(baseURL) {
|
|
40
43
|
try {
|
|
@@ -133,7 +136,7 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
133
136
|
)
|
|
134
137
|
);
|
|
135
138
|
}
|
|
136
|
-
const providerBaseUrl = config?.providerBaseUrl ?? DEFAULT_PROVIDER_BASE_URL;
|
|
139
|
+
const providerBaseUrl = config?.providerName === "clef" ? CLOUDFLARE_API : config?.providerBaseUrl ?? DEFAULT_PROVIDER_BASE_URL;
|
|
137
140
|
const providerModel = config?.providerModel ?? DEFAULT_PROVIDER_MODEL;
|
|
138
141
|
let network = false;
|
|
139
142
|
try {
|
|
@@ -157,7 +160,7 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
157
160
|
) : key ? pass("api_key", "Provider API key is present.") : fail(
|
|
158
161
|
"api_key",
|
|
159
162
|
"Provider API key is missing.",
|
|
160
|
-
"Set TYPESAFE_API_KEY for the configured endpoint."
|
|
163
|
+
config.providerName === "clef" ? "Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN)." : "Set TYPESAFE_API_KEY for the configured endpoint."
|
|
161
164
|
)
|
|
162
165
|
);
|
|
163
166
|
if (!config)
|
|
@@ -173,7 +176,7 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
173
176
|
fail(
|
|
174
177
|
"api_auth",
|
|
175
178
|
"API authentication could not be checked without a key.",
|
|
176
|
-
"Set
|
|
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."
|
|
177
180
|
)
|
|
178
181
|
);
|
|
179
182
|
else if (!network)
|
|
@@ -187,18 +190,30 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
187
190
|
else {
|
|
188
191
|
let result;
|
|
189
192
|
try {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
+
});
|
|
194
206
|
} catch {
|
|
195
207
|
result = "unavailable";
|
|
196
208
|
}
|
|
197
209
|
checks.push(
|
|
198
|
-
result === "accepted" ? pass(
|
|
210
|
+
result === "accepted" ? pass(
|
|
211
|
+
"api_auth",
|
|
212
|
+
config.providerName === "clef" ? "Cloudflare completed the explicitly billable inference probe." : "Model provider API accepted the key."
|
|
213
|
+
) : result === "rejected" ? fail(
|
|
199
214
|
"api_auth",
|
|
200
|
-
"Model provider API rejected the key.",
|
|
201
|
-
"
|
|
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."
|
|
202
217
|
) : result === "unreachable" ? fail(
|
|
203
218
|
"api_auth",
|
|
204
219
|
"Authenticated provider request could not reach the API.",
|
|
@@ -206,7 +221,7 @@ async function executeDoctorCommand(cwd, probes = {}, options = {}) {
|
|
|
206
221
|
) : fail(
|
|
207
222
|
"api_auth",
|
|
208
223
|
"The model provider could not complete the authentication probe.",
|
|
209
|
-
"Check API availability and account access, then retry."
|
|
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."
|
|
210
225
|
)
|
|
211
226
|
);
|
|
212
227
|
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProjectConfigError
|
|
3
|
+
} from "./chunk-VNGIF7AY.js";
|
|
4
|
+
|
|
5
|
+
// src/diagnostics.ts
|
|
6
|
+
import { BrowserDriverError, ProviderError } from "@sedum-dev/core";
|
|
7
|
+
function providerDiagnostic(providerName, code) {
|
|
8
|
+
if (providerName === "clef")
|
|
9
|
+
return code === "authentication" ? {
|
|
10
|
+
code: "provider_authentication",
|
|
11
|
+
message: "Cloudflare rejected the configured API token.",
|
|
12
|
+
fix: "Check CLOUDFLARE_ACCOUNT_ID, replace 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."
|
|
13
|
+
} : {
|
|
14
|
+
code: "provider_configuration",
|
|
15
|
+
message: "The Cloudflare Clef provider is not configured correctly.",
|
|
16
|
+
fix: "Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN), then check the account, Workers AI access, and model with `sedum doctor`."
|
|
17
|
+
};
|
|
18
|
+
return code === "authentication" ? {
|
|
19
|
+
code: "provider_authentication",
|
|
20
|
+
message: "The model provider rejected the API key.",
|
|
21
|
+
fix: "Set TYPESAFE_API_KEY to a valid key, check it with `sedum doctor`, then rerun."
|
|
22
|
+
} : {
|
|
23
|
+
code: "provider_configuration",
|
|
24
|
+
message: "The model provider is not configured correctly.",
|
|
25
|
+
fix: "Check TYPESAFE_API_KEY, TYPESAFE_BASE_URL and the model with `sedum doctor`, then rerun."
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function setupDiagnostic(error, providerName = "typesafe") {
|
|
29
|
+
if (error instanceof ProjectConfigError) return configDiagnostic(error);
|
|
30
|
+
if (error instanceof ProviderError && error.code === "configuration")
|
|
31
|
+
return providerName === "clef" ? providerDiagnostic(providerName, "configuration") : {
|
|
32
|
+
code: "missing_key",
|
|
33
|
+
message: "The model provider is not configured.",
|
|
34
|
+
fix: "Set TYPESAFE_API_KEY for the configured endpoint, then rerun the command."
|
|
35
|
+
};
|
|
36
|
+
if (error instanceof BrowserDriverError && error.code === "browser-missing")
|
|
37
|
+
return {
|
|
38
|
+
code: "browser_missing",
|
|
39
|
+
message: "No supported browser binary was found.",
|
|
40
|
+
fix: "Run `sedum browsers install chromium`, then rerun the test."
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
code: "setup_or_output_error",
|
|
44
|
+
message: "The run could not be prepared safely.",
|
|
45
|
+
fix: "Check the test path, provider key, browser installation, and write access, then rerun."
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function configDiagnostic(error) {
|
|
49
|
+
const first = error.diagnostics[0];
|
|
50
|
+
if (!first)
|
|
51
|
+
return {
|
|
52
|
+
code: "invalid_config",
|
|
53
|
+
message: "The Sedum configuration is invalid.",
|
|
54
|
+
fix: "Correct sedum.config.yaml and rerun the command."
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
code: first.code,
|
|
58
|
+
message: bounded(
|
|
59
|
+
`${first.file}:${first.line}:${first.col}: ${first.message} (key: ${first.key})`
|
|
60
|
+
),
|
|
61
|
+
fix: bounded(first.fix)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function outputDiagnostic(path) {
|
|
65
|
+
return {
|
|
66
|
+
code: "output_error",
|
|
67
|
+
message: `The run result could not be written to ${path}.`,
|
|
68
|
+
fix: "Make the configured output directory writable and rerun the command."
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function bounded(value, maximum = 512) {
|
|
72
|
+
return [...value].slice(0, maximum).join("");
|
|
73
|
+
}
|
|
74
|
+
function canonicalDiagnosticError(diagnostic) {
|
|
75
|
+
return {
|
|
76
|
+
code: diagnostic.code,
|
|
77
|
+
message: diagnostic.code === "output_error" ? "The run result could not be written." : bounded(diagnostic.message)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function flowDiagnostic(result, providerName = "typesafe") {
|
|
81
|
+
if (result.code === "invalid_test" || result.code === "unsupported_test" || result.code === "invalid_data") {
|
|
82
|
+
const source = result.source ? `${result.source.file}:${result.source.line}:${result.source.col}: ` : "";
|
|
83
|
+
return {
|
|
84
|
+
code: result.code,
|
|
85
|
+
message: bounded(`${source}${result.message}`),
|
|
86
|
+
fix: bounded(
|
|
87
|
+
result.fix ?? "Fix the reported test input and rerun the command."
|
|
88
|
+
)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const known = {
|
|
92
|
+
"browser-missing": {
|
|
93
|
+
message: "No supported browser binary was found.",
|
|
94
|
+
fix: "Run `sedum browsers install chromium`, then rerun the test."
|
|
95
|
+
},
|
|
96
|
+
"browser-launch-failed": {
|
|
97
|
+
message: "The browser could not be started safely.",
|
|
98
|
+
fix: "Check the browser installation and permissions, then rerun the test."
|
|
99
|
+
},
|
|
100
|
+
"browser-disconnected": {
|
|
101
|
+
message: "The browser disconnected during the run.",
|
|
102
|
+
fix: "Restart the browser run and check browser stability if it repeats."
|
|
103
|
+
},
|
|
104
|
+
"context-closed": {
|
|
105
|
+
message: "The browser context closed during the run.",
|
|
106
|
+
fix: "Rerun the test and check browser stability if it repeats."
|
|
107
|
+
},
|
|
108
|
+
"page-closed": {
|
|
109
|
+
message: "The browser page closed during the run.",
|
|
110
|
+
fix: "Rerun the test and check whether the tested page closes itself."
|
|
111
|
+
},
|
|
112
|
+
"page-crashed": {
|
|
113
|
+
message: "The browser page crashed during the run.",
|
|
114
|
+
fix: "Rerun the test and check browser resource usage if it repeats."
|
|
115
|
+
},
|
|
116
|
+
"operation-failed": {
|
|
117
|
+
message: "A browser operation could not be completed safely.",
|
|
118
|
+
fix: "Check the named test step and rerun the test."
|
|
119
|
+
},
|
|
120
|
+
"script-missing": {
|
|
121
|
+
message: "The Sedum browser script was unavailable.",
|
|
122
|
+
fix: "Rebuild or reinstall Sedum, then rerun the test."
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const diagnostic = known[result.code];
|
|
126
|
+
if (diagnostic) return { code: result.code, ...diagnostic };
|
|
127
|
+
if (result.code === "navigation_failed")
|
|
128
|
+
return {
|
|
129
|
+
code: result.code,
|
|
130
|
+
message: bounded(result.message),
|
|
131
|
+
fix: bounded(
|
|
132
|
+
result.fix ?? "Check the test's url (or baseUrl), your network or VPN, and that the site is up."
|
|
133
|
+
)
|
|
134
|
+
};
|
|
135
|
+
if (result.code === "provider_rate_limited")
|
|
136
|
+
return {
|
|
137
|
+
code: result.code,
|
|
138
|
+
message: "The model provider kept rate limiting requests for five minutes.",
|
|
139
|
+
fix: "Lower --parallel or --provider-concurrency, or retry later."
|
|
140
|
+
};
|
|
141
|
+
if (result.code === "provider_authentication")
|
|
142
|
+
return providerDiagnostic(providerName, "authentication");
|
|
143
|
+
if (result.code === "provider_configuration")
|
|
144
|
+
return providerDiagnostic(providerName, "configuration");
|
|
145
|
+
if (result.code.startsWith("provider_"))
|
|
146
|
+
return {
|
|
147
|
+
code: result.code,
|
|
148
|
+
message: "The model provider could not complete the run safely.",
|
|
149
|
+
fix: "Check provider availability and the test input, then rerun the test."
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
code: "execution_error",
|
|
153
|
+
message: "The browser run could not be completed safely.",
|
|
154
|
+
fix: "Check the browser, provider, and test input, then rerun the test."
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
var RUN_STOPPING_CODES = /* @__PURE__ */ new Set([
|
|
158
|
+
"browser-missing",
|
|
159
|
+
"browser-launch-failed",
|
|
160
|
+
"script-missing",
|
|
161
|
+
"provider_configuration",
|
|
162
|
+
"provider_authentication",
|
|
163
|
+
"provider_rate_limited"
|
|
164
|
+
]);
|
|
165
|
+
function stopsRun(code) {
|
|
166
|
+
return RUN_STOPPING_CODES.has(code);
|
|
167
|
+
}
|
|
168
|
+
function renderDiagnostic(diagnostic) {
|
|
169
|
+
return `${diagnostic.message}
|
|
170
|
+
Fix: ${diagnostic.fix}
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/provider-factory.ts
|
|
175
|
+
import { ProviderGate } from "@sedum-dev/core";
|
|
176
|
+
async function createCliProvider(config, options = {}) {
|
|
177
|
+
const gate = options.gate ?? new ProviderGate(
|
|
178
|
+
options.concurrency === void 0 ? {} : { concurrency: options.concurrency }
|
|
179
|
+
);
|
|
180
|
+
if (config.providerName === "clef") {
|
|
181
|
+
const { ClefAdapter } = await import("@sedum-dev/provider-clef");
|
|
182
|
+
return new ClefAdapter({
|
|
183
|
+
accountId: config.cloudflareAccountId ?? "",
|
|
184
|
+
apiKey: config.apiKey ?? "",
|
|
185
|
+
model: config.providerModel,
|
|
186
|
+
gate
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const { TypeSafeAdapter } = await import("@sedum-dev/provider-typesafe");
|
|
190
|
+
return new TypeSafeAdapter({
|
|
191
|
+
...config.apiKey ? { apiKey: config.apiKey } : {},
|
|
192
|
+
baseURL: config.providerBaseUrl,
|
|
193
|
+
model: config.providerModel,
|
|
194
|
+
gate
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export {
|
|
199
|
+
providerDiagnostic,
|
|
200
|
+
setupDiagnostic,
|
|
201
|
+
configDiagnostic,
|
|
202
|
+
outputDiagnostic,
|
|
203
|
+
canonicalDiagnosticError,
|
|
204
|
+
flowDiagnostic,
|
|
205
|
+
stopsRun,
|
|
206
|
+
renderDiagnostic,
|
|
207
|
+
createCliProvider
|
|
208
|
+
};
|
|
@@ -46,13 +46,15 @@ var allowed = {
|
|
|
46
46
|
"environment",
|
|
47
47
|
"variables",
|
|
48
48
|
"environments",
|
|
49
|
-
"vision"
|
|
49
|
+
"vision",
|
|
50
|
+
"provider"
|
|
50
51
|
]),
|
|
51
52
|
tests: /* @__PURE__ */ new Set(["directory", "include", "exclude"]),
|
|
52
53
|
viewport: /* @__PURE__ */ new Set(["width", "height"]),
|
|
53
54
|
thresholds: /* @__PURE__ */ new Set(["verify", "lowConfidenceBand", "contradiction"]),
|
|
54
55
|
environment: /* @__PURE__ */ new Set(["baseUrl", "variables"]),
|
|
55
|
-
vision: /* @__PURE__ */ new Set(["enabled", "model", "timeoutMs"])
|
|
56
|
+
vision: /* @__PURE__ */ new Set(["enabled", "model", "timeoutMs"]),
|
|
57
|
+
provider: /* @__PURE__ */ new Set(["name", "model"])
|
|
56
58
|
};
|
|
57
59
|
function source(file, counter, node) {
|
|
58
60
|
const position = counter.linePos(node?.range?.[0] ?? 0);
|
|
@@ -125,7 +127,7 @@ function scalarVariables(value, key, diagnostics, file, counter, node) {
|
|
|
125
127
|
}
|
|
126
128
|
const result = {};
|
|
127
129
|
for (const [name, item] of Object.entries(value)) {
|
|
128
|
-
if (name === "TYPESAFE_API_KEY" || name === "OPEN_ROUTER_API_KEY") {
|
|
130
|
+
if (name === "TYPESAFE_API_KEY" || name === "OPEN_ROUTER_API_KEY" || name === "CLOUDFLARE_ACCOUNT_ID" || name === "CLOUDFLARE_AUTH_TOKEN" || name === "CLOUDFLARE_API_TOKEN") {
|
|
129
131
|
diagnostic(
|
|
130
132
|
diagnostics,
|
|
131
133
|
file,
|
|
@@ -403,7 +405,8 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
403
405
|
["tests", allowed.tests],
|
|
404
406
|
["viewport", allowed.viewport],
|
|
405
407
|
["thresholds", allowed.thresholds],
|
|
406
|
-
["vision", allowed.vision]
|
|
408
|
+
["vision", allowed.vision],
|
|
409
|
+
["provider", allowed.provider]
|
|
407
410
|
];
|
|
408
411
|
for (const [key, names] of maps)
|
|
409
412
|
mapUnknownKeys(
|
|
@@ -443,7 +446,8 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
443
446
|
["viewport", raw.viewport],
|
|
444
447
|
["thresholds", raw.thresholds],
|
|
445
448
|
["environments", raw.environments],
|
|
446
|
-
["vision", raw.vision]
|
|
449
|
+
["vision", raw.vision],
|
|
450
|
+
["provider", raw.provider]
|
|
447
451
|
])
|
|
448
452
|
if (value !== void 0 && !object(value))
|
|
449
453
|
diagnostic(
|
|
@@ -460,6 +464,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
460
464
|
const thresholds = object(raw.thresholds) ? raw.thresholds : {};
|
|
461
465
|
const environments = object(raw.environments) ? raw.environments : {};
|
|
462
466
|
const vision = object(raw.vision) ? raw.vision : {};
|
|
467
|
+
const provider = object(raw.provider) ? raw.provider : {};
|
|
463
468
|
for (const [name, value] of Object.entries(environments)) {
|
|
464
469
|
if (!object(value)) {
|
|
465
470
|
diagnostic(
|
|
@@ -640,12 +645,53 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
640
645
|
...hostEnvironment
|
|
641
646
|
};
|
|
642
647
|
const providerValue = (name) => hostEnvironment[name]?.trim() || fileEnvironment[name]?.trim() || void 0;
|
|
648
|
+
const cloudflareTokenFrom = (environment2) => {
|
|
649
|
+
const authToken = environment2.CLOUDFLARE_AUTH_TOKEN?.trim();
|
|
650
|
+
const apiToken = environment2.CLOUDFLARE_API_TOKEN?.trim();
|
|
651
|
+
if (authToken && apiToken && authToken !== apiToken)
|
|
652
|
+
diagnostics.push({
|
|
653
|
+
code: "conflicting_cloudflare_api_tokens",
|
|
654
|
+
file: environmentFile,
|
|
655
|
+
line: 1,
|
|
656
|
+
col: 1,
|
|
657
|
+
key: "CLOUDFLARE_AUTH_TOKEN",
|
|
658
|
+
message: "CLOUDFLARE_AUTH_TOKEN and CLOUDFLARE_API_TOKEN contain different values at the same precedence level.",
|
|
659
|
+
fix: "Keep one token variable, or set both names to the same Workers AI API token."
|
|
660
|
+
});
|
|
661
|
+
return authToken || apiToken || void 0;
|
|
662
|
+
};
|
|
663
|
+
const providerNameValue = provider.name ?? "typesafe";
|
|
664
|
+
const providerName = providerNameValue === "typesafe" || providerNameValue === "clef" ? providerNameValue : "typesafe";
|
|
665
|
+
if (providerNameValue !== "typesafe" && providerNameValue !== "clef")
|
|
666
|
+
diagnostic(
|
|
667
|
+
diagnostics,
|
|
668
|
+
file,
|
|
669
|
+
counter,
|
|
670
|
+
node("provider.name"),
|
|
671
|
+
"provider.name",
|
|
672
|
+
"invalid_config_provider",
|
|
673
|
+
"Configuration key `provider.name` must be `typesafe` or `clef`.",
|
|
674
|
+
"Choose one of the supported provider names."
|
|
675
|
+
);
|
|
676
|
+
const configuredModel = provider.model;
|
|
677
|
+
const validClefModel = configuredModel === "clef" || configuredModel === "clef-flash";
|
|
678
|
+
if (configuredModel !== void 0 && (typeof configuredModel !== "string" || !configuredModel.trim() || providerName === "clef" && !validClefModel))
|
|
679
|
+
diagnostic(
|
|
680
|
+
diagnostics,
|
|
681
|
+
file,
|
|
682
|
+
counter,
|
|
683
|
+
node("provider.model"),
|
|
684
|
+
"provider.model",
|
|
685
|
+
"invalid_config_provider_model",
|
|
686
|
+
providerName === "clef" ? "Clef provider model must be `clef` or `clef-flash`." : "Provider model must be nonempty text.",
|
|
687
|
+
providerName === "clef" ? "Use `provider.model: clef`." : "Use a nonempty model name."
|
|
688
|
+
);
|
|
643
689
|
const customProvider = {
|
|
644
690
|
baseUrl: providerValue("TYPESAFE_BASE_URL"),
|
|
645
691
|
model: providerValue("TYPESAFE_DEFAULT_MODEL")
|
|
646
692
|
};
|
|
647
693
|
let providerBaseUrl = DEFAULT_PROVIDER_BASE_URL;
|
|
648
|
-
if (customProvider.baseUrl) {
|
|
694
|
+
if (providerName === "typesafe" && customProvider.baseUrl) {
|
|
649
695
|
try {
|
|
650
696
|
const parsed = new URL(customProvider.baseUrl);
|
|
651
697
|
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.search || parsed.hash)
|
|
@@ -663,10 +709,24 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
663
709
|
});
|
|
664
710
|
}
|
|
665
711
|
}
|
|
666
|
-
const providerModel = customProvider.model ?? DEFAULT_PROVIDER_MODEL;
|
|
667
|
-
const apiKey = providerValue("TYPESAFE_API_KEY");
|
|
712
|
+
const providerModel = providerName === "clef" ? typeof configuredModel === "string" && validClefModel ? configuredModel : "clef" : typeof configuredModel === "string" && configuredModel.trim() ? configuredModel.trim() : customProvider.model ?? DEFAULT_PROVIDER_MODEL;
|
|
713
|
+
const apiKey = providerName === "clef" ? cloudflareTokenFrom(hostEnvironment) ?? cloudflareTokenFrom(fileEnvironment) : providerValue("TYPESAFE_API_KEY");
|
|
714
|
+
const cloudflareAccountId = providerName === "clef" ? providerValue("CLOUDFLARE_ACCOUNT_ID") : void 0;
|
|
715
|
+
if (providerName === "clef" && cloudflareAccountId !== void 0 && !/^[a-f\d]{32}$/iu.test(cloudflareAccountId))
|
|
716
|
+
diagnostics.push({
|
|
717
|
+
code: "invalid_cloudflare_account_id",
|
|
718
|
+
file: environmentFile,
|
|
719
|
+
line: 1,
|
|
720
|
+
col: 1,
|
|
721
|
+
key: "CLOUDFLARE_ACCOUNT_ID",
|
|
722
|
+
message: "CLOUDFLARE_ACCOUNT_ID must be exactly 32 hexadecimal characters.",
|
|
723
|
+
fix: "Copy the account ID from the Cloudflare dashboard."
|
|
724
|
+
});
|
|
668
725
|
const visionApiKey = providerValue("OPEN_ROUTER_API_KEY");
|
|
669
726
|
variables.OPEN_ROUTER_API_KEY = void 0;
|
|
727
|
+
variables.CLOUDFLARE_ACCOUNT_ID = void 0;
|
|
728
|
+
variables.CLOUDFLARE_AUTH_TOKEN = void 0;
|
|
729
|
+
variables.CLOUDFLARE_API_TOKEN = void 0;
|
|
670
730
|
const visionEnabledValue = overrides.vision?.enabled ?? vision.enabled;
|
|
671
731
|
const visionEnabled = visionEnabledValue ?? DEFAULTS.vision.enabled;
|
|
672
732
|
if (typeof visionEnabled !== "boolean")
|
|
@@ -768,7 +828,9 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
768
828
|
reporterDir,
|
|
769
829
|
baseUrl,
|
|
770
830
|
variables,
|
|
831
|
+
providerName,
|
|
771
832
|
apiKey,
|
|
833
|
+
cloudflareAccountId,
|
|
772
834
|
providerBaseUrl,
|
|
773
835
|
providerModel,
|
|
774
836
|
vision: {
|
package/dist/cli.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
runCli,
|
|
4
4
|
sedumCommand
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-6JUQUT2O.js";
|
|
6
|
+
import "./chunk-37KG5X5K.js";
|
|
7
|
+
import "./chunk-NOGCXR4U.js";
|
|
8
|
+
import "./chunk-VNGIF7AY.js";
|
|
8
9
|
|
|
9
10
|
// src/cli.ts
|
|
10
11
|
import { createRequire } from "module";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RunResult, BrowserKind, VerifyPolicy, VisionKeyProbe, ClassificationProvider, BrowserInstallResult } from '@sedum-dev/core';
|
|
2
|
-
import {
|
|
1
|
+
import { RunResult, BrowserKind, VerifyPolicy, VisionKeyProbe, RelevanceProvider, ClassificationProvider, BrowserInstallResult } from '@sedum-dev/core';
|
|
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
|
|
|
5
5
|
interface OutputCapabilities {
|
|
@@ -65,7 +65,9 @@ interface ResolvedProjectConfig {
|
|
|
65
65
|
readonly reporterDir: string;
|
|
66
66
|
readonly baseUrl: string | null;
|
|
67
67
|
readonly variables: Readonly<Record<string, string | undefined>>;
|
|
68
|
+
readonly providerName: "typesafe" | "clef";
|
|
68
69
|
readonly apiKey: string | undefined;
|
|
70
|
+
readonly cloudflareAccountId: string | undefined;
|
|
69
71
|
readonly providerBaseUrl: string;
|
|
70
72
|
readonly providerModel: string;
|
|
71
73
|
readonly vision: {
|
|
@@ -161,7 +163,7 @@ interface RunCommandExecution {
|
|
|
161
163
|
readonly onReporterFailure?: () => Promise<RunCommandExecution>;
|
|
162
164
|
}
|
|
163
165
|
|
|
164
|
-
type RelevanceProviderFactory = (config: ResolvedProjectConfig) =>
|
|
166
|
+
type RelevanceProviderFactory = (config: ResolvedProjectConfig) => RelevanceProvider | Promise<RelevanceProvider>;
|
|
165
167
|
|
|
166
168
|
interface DoctorProbes {
|
|
167
169
|
readonly nodeVersion?: string;
|
|
@@ -180,6 +182,8 @@ type ClassificationProviderFactory = (options: {
|
|
|
180
182
|
readonly apiKey?: string;
|
|
181
183
|
readonly baseURL: string;
|
|
182
184
|
readonly model: string;
|
|
185
|
+
readonly providerName?: "typesafe" | "clef";
|
|
186
|
+
readonly accountId?: string;
|
|
183
187
|
}) => ClassificationProvider | Promise<ClassificationProvider>;
|
|
184
188
|
|
|
185
189
|
interface CliOutput {
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,14 @@ import {
|
|
|
2
2
|
renderRunSummary,
|
|
3
3
|
runCli,
|
|
4
4
|
runExitCode
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-6JUQUT2O.js";
|
|
6
|
+
import "./chunk-37KG5X5K.js";
|
|
7
|
+
import "./chunk-NOGCXR4U.js";
|
|
7
8
|
import {
|
|
8
9
|
ProjectConfigError,
|
|
9
10
|
discoverConfiguredTests,
|
|
10
11
|
loadProjectConfig
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-VNGIF7AY.js";
|
|
12
13
|
|
|
13
14
|
// src/index.ts
|
|
14
15
|
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-
|
|
5
|
+
} from "./chunk-H4QXVVQI.js";
|
|
6
6
|
import {
|
|
7
7
|
ProjectConfigError,
|
|
8
8
|
loadProjectConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VNGIF7AY.js";
|
|
10
10
|
|
|
11
11
|
// src/init-command.ts
|
|
12
12
|
import { constants } from "fs";
|
|
@@ -37,6 +37,9 @@ 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 clef, use these instead (never commit .env).
|
|
41
|
+
# CLOUDFLARE_ACCOUNT_ID=
|
|
42
|
+
# CLOUDFLARE_AUTH_TOKEN=
|
|
40
43
|
# Public SauceDemo sample account; no Sauce Labs account is required.
|
|
41
44
|
SAUCE_PASSWORD=secret_sauce
|
|
42
45
|
`;
|
|
@@ -200,10 +203,14 @@ ${++step}. ${title}
|
|
|
200
203
|
const hasEnv = await pathExists(path.join(root, ".env"));
|
|
201
204
|
if (!keyPresent(config))
|
|
202
205
|
next("Add a provider API key", [
|
|
203
|
-
"Get a key at https://typesafe.ai/.",
|
|
206
|
+
...config.providerName === "clef" ? ["Create a scoped Workers AI token in the Cloudflare dashboard."] : ["Get a key at https://typesafe.ai/."],
|
|
204
207
|
...hasEnv ? [] : ["cp .env.example .env"],
|
|
205
|
-
|
|
206
|
-
|
|
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
|
+
]
|
|
207
214
|
]);
|
|
208
215
|
if (!hasBrowser)
|
|
209
216
|
next(
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openLocatorCache,
|
|
3
|
+
planLanes,
|
|
4
|
+
runPool
|
|
5
|
+
} from "./chunk-37KG5X5K.js";
|
|
6
|
+
import {
|
|
7
|
+
discoverRunTests
|
|
8
|
+
} from "./chunk-7M7YUTRH.js";
|
|
1
9
|
import {
|
|
2
10
|
canonicalDiagnosticError,
|
|
11
|
+
createCliProvider,
|
|
3
12
|
flowDiagnostic,
|
|
4
|
-
openLocatorCache,
|
|
5
13
|
outputDiagnostic,
|
|
6
|
-
planLanes,
|
|
7
|
-
runPool,
|
|
8
14
|
setupDiagnostic,
|
|
9
15
|
stopsRun
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import {
|
|
12
|
-
discoverRunTests
|
|
13
|
-
} from "./chunk-DRCPO7W3.js";
|
|
16
|
+
} from "./chunk-NOGCXR4U.js";
|
|
14
17
|
import {
|
|
15
18
|
ProjectConfigError,
|
|
16
19
|
loadProjectConfig
|
|
17
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-VNGIF7AY.js";
|
|
18
21
|
|
|
19
22
|
// src/run-command.ts
|
|
20
23
|
import {
|
|
@@ -29,13 +32,10 @@ import {
|
|
|
29
32
|
runScriptTest,
|
|
30
33
|
safeText,
|
|
31
34
|
validateRunResult as validateRunResult2,
|
|
32
|
-
RejectionRouter
|
|
33
|
-
} from "@sedum-dev/core";
|
|
34
|
-
import {
|
|
35
|
+
RejectionRouter,
|
|
35
36
|
DEFAULT_PROVIDER_CONCURRENCY,
|
|
36
|
-
ProviderGate
|
|
37
|
-
|
|
38
|
-
} from "@sedum-dev/provider-typesafe";
|
|
37
|
+
ProviderGate
|
|
38
|
+
} from "@sedum-dev/core";
|
|
39
39
|
import path3 from "path";
|
|
40
40
|
import { availableParallelism } from "os";
|
|
41
41
|
import { randomBytes, randomUUID } from "crypto";
|
|
@@ -1060,15 +1060,11 @@ async function executeRunCommand(options) {
|
|
|
1060
1060
|
await recorder.addDiscoveryProblems(discoveryProblems);
|
|
1061
1061
|
if (signal.aborted) throw new Error("canceled");
|
|
1062
1062
|
const gate = new ProviderGate({ concurrency: providerConcurrency });
|
|
1063
|
-
const provider =
|
|
1064
|
-
...config.apiKey ? { apiKey: config.apiKey } : {},
|
|
1065
|
-
baseURL: config.providerBaseUrl,
|
|
1066
|
-
model: config.providerModel,
|
|
1067
|
-
gate
|
|
1068
|
-
});
|
|
1063
|
+
const provider = await createCliProvider(config, { gate });
|
|
1069
1064
|
const cache = await FileClassificationCache.load(
|
|
1070
1065
|
path3.join(config.projectRoot, ".sedum", "classifications.json"),
|
|
1071
|
-
config.providerModel
|
|
1066
|
+
config.providerModel,
|
|
1067
|
+
config.providerName
|
|
1072
1068
|
);
|
|
1073
1069
|
const locatorCache = await openLocatorCache(config.projectRoot, {
|
|
1074
1070
|
disabled: options.locatorCacheDisabled ?? false,
|
|
@@ -1142,7 +1138,7 @@ async function executeRunCommand(options) {
|
|
|
1142
1138
|
if (signal.aborted) return "stop";
|
|
1143
1139
|
if (result.status === "could_not_run") {
|
|
1144
1140
|
await browser.recycle();
|
|
1145
|
-
const diagnostic = flowDiagnostic(result);
|
|
1141
|
+
const diagnostic = flowDiagnostic(result, config.providerName);
|
|
1146
1142
|
operational ??= diagnostic;
|
|
1147
1143
|
if (stopsRun(result.code)) return "stop";
|
|
1148
1144
|
erroredTests += 1;
|
|
@@ -1228,7 +1224,7 @@ async function executeRunCommand(options) {
|
|
|
1228
1224
|
code: "canceled",
|
|
1229
1225
|
message: "The run was interrupted.",
|
|
1230
1226
|
fix: "Rerun the command when you are ready to continue."
|
|
1231
|
-
} : setupDiagnostic(error);
|
|
1227
|
+
} : setupDiagnostic(error, config.providerName);
|
|
1232
1228
|
commit();
|
|
1233
1229
|
try {
|
|
1234
1230
|
if (recorder.snapshot.state === "running")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sedum-cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.9",
|
|
4
4
|
"repository": "https://github.com/sedum-dev/sedum",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,9 +25,10 @@
|
|
|
25
25
|
"commander": "14.0.2",
|
|
26
26
|
"minimatch": "10.2.6",
|
|
27
27
|
"yaml": "2.9.1",
|
|
28
|
-
"@sedum-dev/
|
|
29
|
-
"@sedum-dev/provider-typesafe": "0.1.0-alpha.
|
|
30
|
-
"@sedum-dev/reporters": "0.1.0-alpha.
|
|
28
|
+
"@sedum-dev/provider-clef": "0.1.0-alpha.9",
|
|
29
|
+
"@sedum-dev/provider-typesafe": "0.1.0-alpha.9",
|
|
30
|
+
"@sedum-dev/reporters": "0.1.0-alpha.9",
|
|
31
|
+
"@sedum-dev/core": "0.1.0-alpha.9"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "tsup src/index.ts src/cli.ts --format esm --dts --clean --out-dir dist",
|