sedum-cli 0.1.0-alpha.12 → 0.1.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{affected-selection-WV5WY5NQ.js → affected-selection-DAQPGKOZ.js} +6 -6
- package/dist/{chunk-AWBC7NOM.js → chunk-6ILFLNDI.js} +50 -2
- package/dist/{chunk-HT6BIET2.js → chunk-EPXLY5Q4.js} +188 -38
- package/dist/chunk-FG46OUHT.js +538 -0
- package/dist/{chunk-FAGJCNV7.js → chunk-KZF4NZ6M.js} +348 -49
- package/dist/chunk-N5CTUO2A.js +27 -0
- package/dist/{chunk-HXQDSNLL.js → chunk-SI2F6MBN.js} +26 -47
- package/dist/cli.js +4 -3
- package/dist/{doctor-command-F4Y5KW36.js → doctor-command-7IBKI5YO.js} +2 -2
- package/dist/explore-command-QZCKFDYM.js +25 -0
- package/dist/index.d.ts +21 -11
- package/dist/index.js +4 -3
- package/dist/{init-command-62IUO5LA.js → init-command-MBTLGU5J.js} +80 -38
- package/dist/{run-command-ZEIANJWZ.js → run-command-P55TKTX3.js} +76 -50
- package/package.json +5 -5
- package/dist/chunk-S7OB3JEF.js +0 -208
|
@@ -62,11 +62,7 @@ var DEFAULTS = {
|
|
|
62
62
|
},
|
|
63
63
|
outputDir: ".sedum/runs",
|
|
64
64
|
reporterDir: ".sedum/reports",
|
|
65
|
-
vision: {
|
|
66
|
-
enabled: false,
|
|
67
|
-
model: "google/gemini-3.8-flash",
|
|
68
|
-
timeoutMs: 1e4
|
|
69
|
-
}
|
|
65
|
+
vision: { enabled: false }
|
|
70
66
|
};
|
|
71
67
|
var DEFAULT_PROVIDER_BASE_URL = "https://api.typesafe.ai";
|
|
72
68
|
var DEFAULT_PROVIDER_MODEL = "jev-latest";
|
|
@@ -84,15 +80,16 @@ var allowed = {
|
|
|
84
80
|
"variables",
|
|
85
81
|
"environments",
|
|
86
82
|
"vision",
|
|
87
|
-
"provider"
|
|
83
|
+
"provider",
|
|
84
|
+
"screenshots"
|
|
88
85
|
]),
|
|
89
86
|
tests: /* @__PURE__ */ new Set(["directory", "include", "exclude"]),
|
|
90
87
|
affected: /* @__PURE__ */ new Set(["ignore"]),
|
|
91
88
|
viewport: /* @__PURE__ */ new Set(["width", "height"]),
|
|
92
89
|
thresholds: /* @__PURE__ */ new Set(["verify", "lowConfidenceBand", "contradiction"]),
|
|
93
|
-
environment: /* @__PURE__ */ new Set(["baseUrl", "variables"]),
|
|
94
|
-
vision: /* @__PURE__ */ new Set(["enabled"
|
|
95
|
-
provider: /* @__PURE__ */ new Set(["name", "model"])
|
|
90
|
+
environment: /* @__PURE__ */ new Set(["baseUrl", "variables", "provider"]),
|
|
91
|
+
vision: /* @__PURE__ */ new Set(["enabled"]),
|
|
92
|
+
provider: /* @__PURE__ */ new Set(["name", "model", "apiKeyEnv"])
|
|
96
93
|
};
|
|
97
94
|
function source(file, counter, node) {
|
|
98
95
|
const position = counter.linePos(node?.range?.[0] ?? 0);
|
|
@@ -107,20 +104,40 @@ function diagnostic(diagnostics, file, counter, node, key, code, message, fix) {
|
|
|
107
104
|
fix
|
|
108
105
|
});
|
|
109
106
|
}
|
|
107
|
+
var REMOVED_KEYS = {
|
|
108
|
+
"vision.model": "Vision fallback now uses the TypeSafe provider's image model.",
|
|
109
|
+
"vision.timeoutMs": "Vision fallback now uses the TypeSafe provider's request deadline.",
|
|
110
|
+
"vision.apiKeyEnv": "Vision fallback now uses the TypeSafe provider's API key."
|
|
111
|
+
};
|
|
112
|
+
function keyProblem(path2, key, names) {
|
|
113
|
+
const removed = Object.hasOwn(REMOVED_KEYS, path2) ? REMOVED_KEYS[path2] : void 0;
|
|
114
|
+
if (removed)
|
|
115
|
+
return [
|
|
116
|
+
"removed_config_key",
|
|
117
|
+
`Configuration key \`${path2}\` was removed. ${removed}`,
|
|
118
|
+
`Delete \`${path2}\` from ${CONFIG_FILE}.`
|
|
119
|
+
];
|
|
120
|
+
if (names.has(key)) return null;
|
|
121
|
+
return [
|
|
122
|
+
"unknown_config_key",
|
|
123
|
+
`Unknown configuration key \`${path2}\`.`,
|
|
124
|
+
keyFix(key, names)
|
|
125
|
+
];
|
|
126
|
+
}
|
|
110
127
|
function mapUnknownKeys(value, names, prefix, file, counter, diagnostics) {
|
|
111
128
|
if (!isMap(value)) return;
|
|
112
129
|
for (const pair of value.items) {
|
|
113
130
|
const key = String(pair.key);
|
|
114
|
-
|
|
131
|
+
const path2 = prefix ? `${prefix}.${key}` : key;
|
|
132
|
+
const problem = keyProblem(path2, key, names);
|
|
133
|
+
if (problem)
|
|
115
134
|
diagnostic(
|
|
116
135
|
diagnostics,
|
|
117
136
|
file,
|
|
118
137
|
counter,
|
|
119
138
|
pair.key,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
`Unknown configuration key \`${prefix ? `${prefix}.` : ""}${key}\`.`,
|
|
123
|
-
keyFix(key, names)
|
|
139
|
+
path2,
|
|
140
|
+
...problem
|
|
124
141
|
);
|
|
125
142
|
}
|
|
126
143
|
}
|
|
@@ -165,7 +182,14 @@ function scalarVariables(value, key, diagnostics, file, counter, node) {
|
|
|
165
182
|
}
|
|
166
183
|
const result = {};
|
|
167
184
|
for (const [name, item] of Object.entries(value)) {
|
|
168
|
-
if (
|
|
185
|
+
if ([
|
|
186
|
+
"TYPESAFE_API_KEY",
|
|
187
|
+
"OPENROUTER_API_KEY",
|
|
188
|
+
"OPEN_ROUTER_API_KEY",
|
|
189
|
+
"CLOUDFLARE_ACCOUNT_ID",
|
|
190
|
+
"CLOUDFLARE_AUTH_TOKEN",
|
|
191
|
+
"CLOUDFLARE_API_TOKEN"
|
|
192
|
+
].includes(name)) {
|
|
169
193
|
diagnostic(
|
|
170
194
|
diagnostics,
|
|
171
195
|
file,
|
|
@@ -338,6 +362,15 @@ async function findConfig(start) {
|
|
|
338
362
|
current = parent;
|
|
339
363
|
}
|
|
340
364
|
}
|
|
365
|
+
async function readProjectEnvironment(start) {
|
|
366
|
+
const { root } = await findConfig(start);
|
|
367
|
+
try {
|
|
368
|
+
return parseEnv(await readFile(path.join(root, ".env"), "utf8"));
|
|
369
|
+
} catch (error) {
|
|
370
|
+
if (error.code === "ENOENT") return {};
|
|
371
|
+
throw error;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
341
374
|
function freeze(config) {
|
|
342
375
|
Object.freeze(config.include);
|
|
343
376
|
Object.freeze(config.exclude);
|
|
@@ -347,6 +380,7 @@ function freeze(config) {
|
|
|
347
380
|
Object.freeze(config.thresholds);
|
|
348
381
|
Object.freeze(config.vision);
|
|
349
382
|
Object.freeze(config.variables);
|
|
383
|
+
Object.freeze(config.credentialValues);
|
|
350
384
|
return Object.freeze(config);
|
|
351
385
|
}
|
|
352
386
|
async function loadProjectConfig(start = process.cwd(), hostEnvironment = process.env, overrides = {}, loadOptions = {}) {
|
|
@@ -528,6 +562,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
528
562
|
const environments = object(raw.environments) ? raw.environments : {};
|
|
529
563
|
const vision = object(raw.vision) ? raw.vision : {};
|
|
530
564
|
const provider = object(raw.provider) ? raw.provider : {};
|
|
565
|
+
const credentialSettings = [["provider", provider]];
|
|
531
566
|
for (const [name, value] of Object.entries(environments)) {
|
|
532
567
|
if (!object(value)) {
|
|
533
568
|
diagnostic(
|
|
@@ -542,6 +577,28 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
542
577
|
);
|
|
543
578
|
continue;
|
|
544
579
|
}
|
|
580
|
+
const key = `environments.${name}.provider`;
|
|
581
|
+
const settings = value.provider;
|
|
582
|
+
mapUnknownKeys(
|
|
583
|
+
node(key),
|
|
584
|
+
/* @__PURE__ */ new Set(["apiKeyEnv"]),
|
|
585
|
+
key,
|
|
586
|
+
file,
|
|
587
|
+
counter,
|
|
588
|
+
diagnostics
|
|
589
|
+
);
|
|
590
|
+
if (settings !== void 0 && !object(settings))
|
|
591
|
+
diagnostic(
|
|
592
|
+
diagnostics,
|
|
593
|
+
file,
|
|
594
|
+
counter,
|
|
595
|
+
node(key),
|
|
596
|
+
key,
|
|
597
|
+
"invalid_config_type",
|
|
598
|
+
`Configuration key \`${key}\` must be a mapping.`,
|
|
599
|
+
`Write \`${key}: { apiKeyEnv: MY_API_KEY }\`.`
|
|
600
|
+
);
|
|
601
|
+
if (object(settings)) credentialSettings.push([key, settings]);
|
|
545
602
|
scalarVariables(
|
|
546
603
|
value.variables,
|
|
547
604
|
`environments.${name}.variables`,
|
|
@@ -577,6 +634,22 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
577
634
|
`Add \`environments.${selected}\` or choose an existing environment.`
|
|
578
635
|
);
|
|
579
636
|
const environment = object(selectedRaw) ? selectedRaw : {};
|
|
637
|
+
for (const [prefix, settings] of credentialSettings) {
|
|
638
|
+
const value = settings.apiKeyEnv;
|
|
639
|
+
if (value !== void 0 && (typeof value !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/u.test(value)))
|
|
640
|
+
diagnostic(
|
|
641
|
+
diagnostics,
|
|
642
|
+
file,
|
|
643
|
+
counter,
|
|
644
|
+
node(`${prefix}.apiKeyEnv`),
|
|
645
|
+
`${prefix}.apiKeyEnv`,
|
|
646
|
+
"invalid_config_env_name",
|
|
647
|
+
`Configuration key \`${prefix}.apiKeyEnv\` must be a valid environment variable name.`,
|
|
648
|
+
"Use letters, digits, and underscores, starting with a letter or underscore."
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
const selectedProvider = object(environment.provider) ? environment.provider : {};
|
|
652
|
+
const apiKeyEnv = selectedProvider.apiKeyEnv ?? provider.apiKeyEnv;
|
|
580
653
|
const browserValue = overrides.browser ?? raw.browser ?? DEFAULTS.browser;
|
|
581
654
|
const browser = browserValue === "chrome" || browserValue === "chromium" ? browserValue : DEFAULTS.browser;
|
|
582
655
|
if (browserValue !== "chrome" && browserValue !== "chromium")
|
|
@@ -707,7 +780,11 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
707
780
|
...fileEnvironment,
|
|
708
781
|
...hostEnvironment
|
|
709
782
|
};
|
|
710
|
-
const
|
|
783
|
+
const providerEnvironment = new Map([
|
|
784
|
+
...Object.entries(fileEnvironment),
|
|
785
|
+
...Object.entries(hostEnvironment).filter(([, value]) => value?.trim())
|
|
786
|
+
]);
|
|
787
|
+
const providerValue = (name) => providerEnvironment.get(name)?.trim() || void 0;
|
|
711
788
|
const cloudflareTokenFrom = (environment2) => {
|
|
712
789
|
const authToken = environment2.CLOUDFLARE_AUTH_TOKEN?.trim();
|
|
713
790
|
const apiToken = environment2.CLOUDFLARE_API_TOKEN?.trim();
|
|
@@ -724,8 +801,8 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
724
801
|
return authToken || apiToken || void 0;
|
|
725
802
|
};
|
|
726
803
|
const providerNameValue = provider.name ?? "typesafe";
|
|
727
|
-
const providerName = providerNameValue === "typesafe" || providerNameValue === "clef" ? providerNameValue : "typesafe";
|
|
728
|
-
if (
|
|
804
|
+
const providerName = providerNameValue === "typesafe" || providerNameValue === "clef" || providerNameValue === "openrouter" ? providerNameValue : "typesafe";
|
|
805
|
+
if (providerName !== providerNameValue)
|
|
729
806
|
diagnostic(
|
|
730
807
|
diagnostics,
|
|
731
808
|
file,
|
|
@@ -733,7 +810,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
733
810
|
node("provider.name"),
|
|
734
811
|
"provider.name",
|
|
735
812
|
"invalid_config_provider",
|
|
736
|
-
"Configuration key `provider.name` must be `typesafe` or `
|
|
813
|
+
"Configuration key `provider.name` must be `typesafe`, `clef`, or `openrouter`.",
|
|
737
814
|
"Choose one of the supported provider names."
|
|
738
815
|
);
|
|
739
816
|
const configuredModel = provider.model;
|
|
@@ -753,7 +830,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
753
830
|
baseUrl: providerValue("TYPESAFE_BASE_URL"),
|
|
754
831
|
model: providerValue("TYPESAFE_DEFAULT_MODEL")
|
|
755
832
|
};
|
|
756
|
-
let providerBaseUrl = DEFAULT_PROVIDER_BASE_URL;
|
|
833
|
+
let providerBaseUrl = providerName === "openrouter" ? "https://openrouter.ai/api" : DEFAULT_PROVIDER_BASE_URL;
|
|
757
834
|
if (providerName === "typesafe" && customProvider.baseUrl) {
|
|
758
835
|
try {
|
|
759
836
|
const parsed = new URL(customProvider.baseUrl);
|
|
@@ -772,8 +849,10 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
772
849
|
});
|
|
773
850
|
}
|
|
774
851
|
}
|
|
775
|
-
const providerModel = providerName === "clef" ? typeof configuredModel === "string" && validClefModel ? configuredModel : "clef" : typeof configuredModel === "string" && configuredModel.trim() ? configuredModel.trim() : customProvider.model ?? DEFAULT_PROVIDER_MODEL;
|
|
776
|
-
const
|
|
852
|
+
const providerModel = providerName === "clef" ? typeof configuredModel === "string" && validClefModel ? configuredModel : "clef" : typeof configuredModel === "string" && configuredModel.trim() ? configuredModel.trim() : providerName === "openrouter" ? "typesafe/jev-1.13" : customProvider.model ?? DEFAULT_PROVIDER_MODEL;
|
|
853
|
+
const openRouterKeyFrom = (environment2) => environment2.OPENROUTER_API_KEY?.trim() || environment2.OPEN_ROUTER_API_KEY?.trim() || void 0;
|
|
854
|
+
const openRouterKey = openRouterKeyFrom(hostEnvironment) ?? openRouterKeyFrom(fileEnvironment);
|
|
855
|
+
const apiKey = typeof apiKeyEnv === "string" ? providerValue(apiKeyEnv) : providerName === "clef" ? cloudflareTokenFrom(hostEnvironment) ?? cloudflareTokenFrom(fileEnvironment) : providerName === "openrouter" ? openRouterKey : providerValue("TYPESAFE_API_KEY");
|
|
777
856
|
const cloudflareAccountId = providerName === "clef" ? providerValue("CLOUDFLARE_ACCOUNT_ID") : void 0;
|
|
778
857
|
if (providerName === "clef" && cloudflareAccountId !== void 0 && !/^[a-f\d]{32}$/iu.test(cloudflareAccountId))
|
|
779
858
|
diagnostics.push({
|
|
@@ -785,7 +864,38 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
785
864
|
message: "CLOUDFLARE_ACCOUNT_ID must be exactly 32 hexadecimal characters.",
|
|
786
865
|
fix: "Copy the account ID from the Cloudflare dashboard."
|
|
787
866
|
});
|
|
788
|
-
const
|
|
867
|
+
const credentialValues = [apiKey].filter((value) => value !== void 0);
|
|
868
|
+
for (const [, settings] of credentialSettings) {
|
|
869
|
+
if (typeof settings.apiKeyEnv !== "string") continue;
|
|
870
|
+
const name = settings.apiKeyEnv;
|
|
871
|
+
for (const source2 of [hostEnvironment, fileEnvironment]) {
|
|
872
|
+
const value = Object.hasOwn(source2, name) ? source2[name] : void 0;
|
|
873
|
+
if (value?.trim()) credentialValues.push(value, value.trim());
|
|
874
|
+
}
|
|
875
|
+
variables[name] = void 0;
|
|
876
|
+
for (const [prefix, values] of [
|
|
877
|
+
["variables", rootVariables],
|
|
878
|
+
...Object.entries(environments).filter(([, value]) => object(value)).map(
|
|
879
|
+
([key, value]) => [
|
|
880
|
+
`environments.${key}.variables`,
|
|
881
|
+
value.variables
|
|
882
|
+
]
|
|
883
|
+
)
|
|
884
|
+
]) {
|
|
885
|
+
if (object(values) && Object.hasOwn(values, name))
|
|
886
|
+
diagnostic(
|
|
887
|
+
diagnostics,
|
|
888
|
+
file,
|
|
889
|
+
counter,
|
|
890
|
+
node(prefix),
|
|
891
|
+
`${prefix}.${name}`,
|
|
892
|
+
"api_key_in_config",
|
|
893
|
+
`${name} must not be stored in sedum.config.yaml.`,
|
|
894
|
+
`Put ${name} in the project-root .env or invoking process environment.`
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
variables["OPENROUTER_API_KEY"] = void 0;
|
|
789
899
|
variables.OPEN_ROUTER_API_KEY = void 0;
|
|
790
900
|
variables.CLOUDFLARE_ACCOUNT_ID = void 0;
|
|
791
901
|
variables.CLOUDFLARE_AUTH_TOKEN = void 0;
|
|
@@ -803,31 +913,19 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
803
913
|
"Configuration key `vision.enabled` must be a boolean.",
|
|
804
914
|
"Use `vision.enabled: true` or `vision.enabled: false`."
|
|
805
915
|
);
|
|
806
|
-
const
|
|
807
|
-
|
|
808
|
-
if (typeof visionModel !== "string" || !visionModel.trim())
|
|
916
|
+
const screenshotsValue = overrides.screenshots ?? raw.screenshots;
|
|
917
|
+
if (screenshotsValue !== void 0 && typeof screenshotsValue !== "boolean")
|
|
809
918
|
diagnostic(
|
|
810
919
|
diagnostics,
|
|
811
920
|
file,
|
|
812
921
|
counter,
|
|
813
|
-
node("
|
|
814
|
-
"
|
|
922
|
+
node("screenshots"),
|
|
923
|
+
"screenshots",
|
|
815
924
|
"invalid_config_type",
|
|
816
|
-
"Configuration key `
|
|
817
|
-
|
|
818
|
-
);
|
|
819
|
-
const visionTimeoutValue = vision.timeoutMs ?? DEFAULTS.vision.timeoutMs;
|
|
820
|
-
if (!Number.isSafeInteger(visionTimeoutValue) || visionTimeoutValue < 1)
|
|
821
|
-
diagnostic(
|
|
822
|
-
diagnostics,
|
|
823
|
-
file,
|
|
824
|
-
counter,
|
|
825
|
-
node("vision.timeoutMs"),
|
|
826
|
-
"vision.timeoutMs",
|
|
827
|
-
"invalid_config_type",
|
|
828
|
-
"Configuration key `vision.timeoutMs` must be a positive integer.",
|
|
829
|
-
"Use a timeout such as `10000`."
|
|
925
|
+
"Configuration key `screenshots` must be a boolean.",
|
|
926
|
+
"Use `screenshots: true` or `screenshots: false`."
|
|
830
927
|
);
|
|
928
|
+
const screenshots = typeof screenshotsValue === "boolean" ? screenshotsValue : providerName === "typesafe" && providerBaseUrl === DEFAULT_PROVIDER_BASE_URL;
|
|
831
929
|
const testDirectory = relativePath(
|
|
832
930
|
found.root,
|
|
833
931
|
tests.directory,
|
|
@@ -894,15 +992,13 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
894
992
|
variables,
|
|
895
993
|
providerName,
|
|
896
994
|
apiKey,
|
|
995
|
+
credentialValues,
|
|
996
|
+
...typeof apiKeyEnv === "string" ? { apiKeyEnv } : {},
|
|
897
997
|
cloudflareAccountId,
|
|
898
998
|
providerBaseUrl,
|
|
899
999
|
providerModel,
|
|
900
|
-
vision: {
|
|
901
|
-
|
|
902
|
-
model: typeof visionModel === "string" && visionModel.trim() ? visionModel : DEFAULTS.vision.model,
|
|
903
|
-
timeoutMs: Number.isSafeInteger(visionTimeoutValue) && visionTimeoutValue > 0 ? visionTimeoutValue : DEFAULTS.vision.timeoutMs
|
|
904
|
-
},
|
|
905
|
-
visionApiKey
|
|
1000
|
+
vision: { enabled: visionEnabled === true },
|
|
1001
|
+
screenshots: screenshots && providerName !== "clef"
|
|
906
1002
|
});
|
|
907
1003
|
}
|
|
908
1004
|
async function discoverConfiguredTests(config) {
|
|
@@ -930,12 +1026,215 @@ async function discoverConfiguredTests(config) {
|
|
|
930
1026
|
return files.sort((left, right) => left.localeCompare(right));
|
|
931
1027
|
}
|
|
932
1028
|
|
|
1029
|
+
// src/diagnostics.ts
|
|
1030
|
+
import { BrowserDriverError, ProviderError } from "@sedum-dev/core";
|
|
1031
|
+
function providerDiagnostic(provider, code, apiKeyEnv) {
|
|
1032
|
+
const providerName = typeof provider === "string" ? provider : provider.providerName;
|
|
1033
|
+
if (typeof provider !== "string") apiKeyEnv = provider.apiKeyEnv;
|
|
1034
|
+
if (providerName === "openrouter")
|
|
1035
|
+
return {
|
|
1036
|
+
code: `provider_${code}`,
|
|
1037
|
+
message: code === "authentication" ? "OpenRouter rejected the configured API key." : "The OpenRouter decision provider is not configured correctly.",
|
|
1038
|
+
fix: `Set ${apiKeyEnv ?? "OPENROUTER_API_KEY (or OPEN_ROUTER_API_KEY)"} to a valid OpenRouter key, check account credits and provider.model with \`sedum doctor\`, then rerun.`
|
|
1039
|
+
};
|
|
1040
|
+
if (providerName === "clef")
|
|
1041
|
+
return code === "authentication" ? {
|
|
1042
|
+
code: "provider_authentication",
|
|
1043
|
+
message: "Cloudflare rejected the configured API token.",
|
|
1044
|
+
fix: `Check CLOUDFLARE_ACCOUNT_ID, replace ${apiKeyEnv ?? "CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN)"} with a token for that account that has Workers AI Read and Edit permissions, run \`sedum doctor\`, then rerun.`
|
|
1045
|
+
} : {
|
|
1046
|
+
code: "provider_configuration",
|
|
1047
|
+
message: "The Cloudflare Clef provider is not configured correctly.",
|
|
1048
|
+
fix: `Set CLOUDFLARE_ACCOUNT_ID and ${apiKeyEnv ?? "CLOUDFLARE_AUTH_TOKEN (or CLOUDFLARE_API_TOKEN)"}, then check the account, Workers AI access, and model with \`sedum doctor\`.`
|
|
1049
|
+
};
|
|
1050
|
+
return code === "authentication" ? {
|
|
1051
|
+
code: "provider_authentication",
|
|
1052
|
+
message: "The model provider rejected the API key.",
|
|
1053
|
+
fix: `Set ${apiKeyEnv ?? "TYPESAFE_API_KEY"} to a valid key, check it with \`sedum doctor\`, then rerun.`
|
|
1054
|
+
} : {
|
|
1055
|
+
code: "provider_configuration",
|
|
1056
|
+
message: "The model provider is not configured correctly.",
|
|
1057
|
+
fix: `Check ${apiKeyEnv ?? "TYPESAFE_API_KEY"}, TYPESAFE_BASE_URL and the model with \`sedum doctor\`, then rerun.`
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
var DetectorUnsupportedError = class extends Error {
|
|
1061
|
+
constructor(providerName) {
|
|
1062
|
+
super(
|
|
1063
|
+
`--detect semantic is not supported by the ${providerName} provider.`
|
|
1064
|
+
);
|
|
1065
|
+
this.providerName = providerName;
|
|
1066
|
+
this.name = "DetectorUnsupportedError";
|
|
1067
|
+
}
|
|
1068
|
+
providerName;
|
|
1069
|
+
};
|
|
1070
|
+
function setupDiagnostic(error, providerName = "typesafe", apiKeyEnv) {
|
|
1071
|
+
if (error instanceof ProjectConfigError) return configDiagnostic(error);
|
|
1072
|
+
if (error instanceof DetectorUnsupportedError)
|
|
1073
|
+
return {
|
|
1074
|
+
code: "detect_unsupported",
|
|
1075
|
+
message: `--detect semantic needs a System One provider; ${error.providerName} cannot answer its page questions.`,
|
|
1076
|
+
fix: "Use --detect browser with this provider, or select the TypeSafe or OpenRouter provider."
|
|
1077
|
+
};
|
|
1078
|
+
if (error instanceof ProviderError && error.code === "configuration")
|
|
1079
|
+
return providerName !== "typesafe" ? providerDiagnostic(providerName, "configuration", apiKeyEnv) : {
|
|
1080
|
+
code: "missing_key",
|
|
1081
|
+
message: "The model provider is not configured.",
|
|
1082
|
+
fix: `Set ${apiKeyEnv ?? "TYPESAFE_API_KEY"} for the configured endpoint, then rerun the command.`
|
|
1083
|
+
};
|
|
1084
|
+
if (error instanceof BrowserDriverError && error.code === "browser-missing")
|
|
1085
|
+
return {
|
|
1086
|
+
code: "browser_missing",
|
|
1087
|
+
message: "No supported browser binary was found.",
|
|
1088
|
+
fix: "Run `sedum browsers install chromium`, then rerun the test."
|
|
1089
|
+
};
|
|
1090
|
+
return {
|
|
1091
|
+
code: "setup_or_output_error",
|
|
1092
|
+
message: "The run could not be prepared safely.",
|
|
1093
|
+
fix: "Check the test path, provider key, browser installation, and write access, then rerun."
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
function configDiagnostic(error) {
|
|
1097
|
+
const first = error.diagnostics[0];
|
|
1098
|
+
if (!first)
|
|
1099
|
+
return {
|
|
1100
|
+
code: "invalid_config",
|
|
1101
|
+
message: "The Sedum configuration is invalid.",
|
|
1102
|
+
fix: "Correct sedum.config.yaml and rerun the command."
|
|
1103
|
+
};
|
|
1104
|
+
return {
|
|
1105
|
+
code: first.code,
|
|
1106
|
+
message: bounded(
|
|
1107
|
+
`${first.file}:${first.line}:${first.col}: ${first.message} (key: ${first.key})`
|
|
1108
|
+
),
|
|
1109
|
+
fix: bounded(first.fix)
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
function outputDiagnostic(path2) {
|
|
1113
|
+
return {
|
|
1114
|
+
code: "output_error",
|
|
1115
|
+
message: `The run result could not be written to ${path2}.`,
|
|
1116
|
+
fix: "Make the configured output directory writable and rerun the command."
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
function bounded(value, maximum = 512) {
|
|
1120
|
+
return [...value].slice(0, maximum).join("");
|
|
1121
|
+
}
|
|
1122
|
+
function canonicalDiagnosticError(diagnostic2) {
|
|
1123
|
+
return {
|
|
1124
|
+
code: diagnostic2.code,
|
|
1125
|
+
message: diagnostic2.code === "output_error" ? "The run result could not be written." : bounded(diagnostic2.message)
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
function flowDiagnostic(result, providerName = "typesafe", apiKeyEnv) {
|
|
1129
|
+
if (result.code === "invalid_test" || result.code === "unsupported_test" || result.code === "invalid_data") {
|
|
1130
|
+
const source2 = result.source ? `${result.source.file}:${result.source.line}:${result.source.col}: ` : "";
|
|
1131
|
+
return {
|
|
1132
|
+
code: result.code,
|
|
1133
|
+
message: bounded(`${source2}${result.message}`),
|
|
1134
|
+
fix: bounded(
|
|
1135
|
+
result.fix ?? "Fix the reported test input and rerun the command."
|
|
1136
|
+
)
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
const known = {
|
|
1140
|
+
"browser-missing": {
|
|
1141
|
+
message: "No supported browser binary was found.",
|
|
1142
|
+
fix: "Run `sedum browsers install chromium`, then rerun the test."
|
|
1143
|
+
},
|
|
1144
|
+
"browser-launch-failed": {
|
|
1145
|
+
message: "The browser could not be started safely.",
|
|
1146
|
+
fix: "Check the browser installation and permissions, then rerun the test."
|
|
1147
|
+
},
|
|
1148
|
+
"browser-disconnected": {
|
|
1149
|
+
message: "The browser disconnected during the run.",
|
|
1150
|
+
fix: "Restart the browser run and check browser stability if it repeats."
|
|
1151
|
+
},
|
|
1152
|
+
"context-closed": {
|
|
1153
|
+
message: "The browser context closed during the run.",
|
|
1154
|
+
fix: "Rerun the test and check browser stability if it repeats."
|
|
1155
|
+
},
|
|
1156
|
+
"page-closed": {
|
|
1157
|
+
message: "The browser page closed during the run.",
|
|
1158
|
+
fix: "Rerun the test and check whether the tested page closes itself."
|
|
1159
|
+
},
|
|
1160
|
+
"page-crashed": {
|
|
1161
|
+
message: "The browser page crashed during the run.",
|
|
1162
|
+
fix: "Rerun the test and check browser resource usage if it repeats."
|
|
1163
|
+
},
|
|
1164
|
+
"operation-failed": {
|
|
1165
|
+
message: "A browser operation could not be completed safely.",
|
|
1166
|
+
fix: "Check the named test step and rerun the test."
|
|
1167
|
+
},
|
|
1168
|
+
"script-missing": {
|
|
1169
|
+
message: "The Sedum browser script was unavailable.",
|
|
1170
|
+
fix: "Rebuild or reinstall Sedum, then rerun the test."
|
|
1171
|
+
}
|
|
1172
|
+
};
|
|
1173
|
+
const diagnostic2 = known[result.code];
|
|
1174
|
+
if (diagnostic2) return { code: result.code, ...diagnostic2 };
|
|
1175
|
+
if (result.code === "navigation_failed")
|
|
1176
|
+
return {
|
|
1177
|
+
code: result.code,
|
|
1178
|
+
message: bounded(result.message),
|
|
1179
|
+
fix: bounded(
|
|
1180
|
+
result.fix ?? "Check the test's url (or baseUrl), your network or VPN, and that the site is up."
|
|
1181
|
+
)
|
|
1182
|
+
};
|
|
1183
|
+
if (result.code === "provider_rate_limited")
|
|
1184
|
+
return {
|
|
1185
|
+
code: result.code,
|
|
1186
|
+
message: "The model provider kept rate limiting requests for five minutes.",
|
|
1187
|
+
fix: "Lower --parallel or --provider-concurrency, or retry later."
|
|
1188
|
+
};
|
|
1189
|
+
if (result.code === "provider_authentication")
|
|
1190
|
+
return providerDiagnostic(providerName, "authentication", apiKeyEnv);
|
|
1191
|
+
if (result.code === "provider_configuration")
|
|
1192
|
+
return providerDiagnostic(providerName, "configuration", apiKeyEnv);
|
|
1193
|
+
if (result.code.startsWith("provider_"))
|
|
1194
|
+
return {
|
|
1195
|
+
code: result.code,
|
|
1196
|
+
message: "The model provider could not complete the run safely.",
|
|
1197
|
+
fix: "Check provider availability and the test input, then rerun the test."
|
|
1198
|
+
};
|
|
1199
|
+
return {
|
|
1200
|
+
code: "execution_error",
|
|
1201
|
+
message: "The browser run could not be completed safely.",
|
|
1202
|
+
fix: "Check the browser, provider, and test input, then rerun the test."
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
var RUN_STOPPING_CODES = /* @__PURE__ */ new Set([
|
|
1206
|
+
"browser-missing",
|
|
1207
|
+
"browser-launch-failed",
|
|
1208
|
+
"script-missing",
|
|
1209
|
+
"provider_configuration",
|
|
1210
|
+
"provider_authentication",
|
|
1211
|
+
"provider_rate_limited"
|
|
1212
|
+
]);
|
|
1213
|
+
function stopsRun(code) {
|
|
1214
|
+
return RUN_STOPPING_CODES.has(code);
|
|
1215
|
+
}
|
|
1216
|
+
function renderDiagnostic(diagnostic2) {
|
|
1217
|
+
return `${diagnostic2.message}
|
|
1218
|
+
Fix: ${diagnostic2.fix}
|
|
1219
|
+
`;
|
|
1220
|
+
}
|
|
1221
|
+
|
|
933
1222
|
export {
|
|
934
1223
|
validAffectedGlob,
|
|
935
1224
|
affectedPathIgnored,
|
|
936
1225
|
ProjectConfigError,
|
|
937
1226
|
DEFAULT_PROVIDER_BASE_URL,
|
|
938
1227
|
DEFAULT_PROVIDER_MODEL,
|
|
1228
|
+
readProjectEnvironment,
|
|
939
1229
|
loadProjectConfig,
|
|
940
|
-
discoverConfiguredTests
|
|
1230
|
+
discoverConfiguredTests,
|
|
1231
|
+
providerDiagnostic,
|
|
1232
|
+
DetectorUnsupportedError,
|
|
1233
|
+
setupDiagnostic,
|
|
1234
|
+
configDiagnostic,
|
|
1235
|
+
outputDiagnostic,
|
|
1236
|
+
canonicalDiagnosticError,
|
|
1237
|
+
flowDiagnostic,
|
|
1238
|
+
stopsRun,
|
|
1239
|
+
renderDiagnostic
|
|
941
1240
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/provider-factory.ts
|
|
2
|
+
import { ProviderGate } from "@sedum-dev/core";
|
|
3
|
+
async function createCliProvider(config, options = {}) {
|
|
4
|
+
const gate = options.gate ?? new ProviderGate(
|
|
5
|
+
options.concurrency === void 0 ? {} : { concurrency: options.concurrency }
|
|
6
|
+
);
|
|
7
|
+
if (config.providerName === "clef") {
|
|
8
|
+
const { ClefAdapter } = await import("@sedum-dev/provider-clef");
|
|
9
|
+
return new ClefAdapter({
|
|
10
|
+
accountId: config.cloudflareAccountId ?? "",
|
|
11
|
+
apiKey: config.apiKey ?? "",
|
|
12
|
+
model: config.providerModel,
|
|
13
|
+
gate
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
const { TypeSafeAdapter } = await import("@sedum-dev/provider-typesafe");
|
|
17
|
+
return new TypeSafeAdapter({
|
|
18
|
+
apiKey: config.apiKey ?? "",
|
|
19
|
+
baseURL: config.providerBaseUrl,
|
|
20
|
+
model: config.providerModel,
|
|
21
|
+
gate
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
createCliProvider
|
|
27
|
+
};
|