sedum-cli 0.1.0-alpha.0 → 0.1.0-alpha.11
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/README.md +64 -0
- package/dist/affected-selection-WV5WY5NQ.js +392 -0
- package/dist/chunk-AWBC7NOM.js +132 -0
- package/dist/{chunk-BEV24G7S.js → chunk-EFRMSNBD.js} +37 -171
- package/dist/{chunk-TZGSCV23.js → chunk-FAGJCNV7.js} +253 -16
- package/dist/{chunk-TU5MIKGA.js → chunk-HT6BIET2.js} +515 -188
- package/dist/{chunk-OB6ZUJ6X.js → chunk-HXQDSNLL.js} +83 -22
- package/dist/chunk-S7OB3JEF.js +208 -0
- package/dist/cli.js +31 -5
- package/dist/{doctor-command-2PMOA32Y.js → doctor-command-F4Y5KW36.js} +2 -2
- package/dist/index.d.ts +57 -11
- package/dist/index.js +11 -4
- package/dist/{init-command-54R2FQ2U.js → init-command-62IUO5LA.js} +38 -20
- package/dist/run-command-ZEIANJWZ.js +1605 -0
- package/package.json +23 -4
- package/dist/run-command-VAVFPCWG.js +0 -1269
|
@@ -1,166 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ProjectConfigError
|
|
3
|
-
} from "./chunk-TZGSCV23.js";
|
|
4
|
-
|
|
5
|
-
// src/diagnostics.ts
|
|
6
|
-
import { BrowserDriverError, ProviderError } from "@sedum-dev/core";
|
|
7
|
-
function setupDiagnostic(error) {
|
|
8
|
-
if (error instanceof ProjectConfigError) return configDiagnostic(error);
|
|
9
|
-
if (error instanceof ProviderError && error.code === "configuration")
|
|
10
|
-
return {
|
|
11
|
-
code: "missing_key",
|
|
12
|
-
message: "The TypeSafe provider is not configured.",
|
|
13
|
-
fix: "Set TYPESAFE_API_KEY and rerun the command."
|
|
14
|
-
};
|
|
15
|
-
if (error instanceof BrowserDriverError && error.code === "browser-missing")
|
|
16
|
-
return {
|
|
17
|
-
code: "browser_missing",
|
|
18
|
-
message: "No supported browser binary was found.",
|
|
19
|
-
fix: "Run `sedum browsers install chromium`, then rerun the test."
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
code: "setup_or_output_error",
|
|
23
|
-
message: "The run could not be prepared safely.",
|
|
24
|
-
fix: "Check the test path, provider key, browser installation, and write access, then rerun."
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function configDiagnostic(error) {
|
|
28
|
-
const first = error.diagnostics[0];
|
|
29
|
-
if (!first)
|
|
30
|
-
return {
|
|
31
|
-
code: "invalid_config",
|
|
32
|
-
message: "The Sedum configuration is invalid.",
|
|
33
|
-
fix: "Correct sedum.config.yaml and rerun the command."
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
code: first.code,
|
|
37
|
-
message: bounded(
|
|
38
|
-
`${first.file}:${first.line}:${first.col}: ${first.message} (key: ${first.key})`
|
|
39
|
-
),
|
|
40
|
-
fix: bounded(first.fix)
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function outputDiagnostic(path2) {
|
|
44
|
-
return {
|
|
45
|
-
code: "output_error",
|
|
46
|
-
message: `The run result could not be written to ${path2}.`,
|
|
47
|
-
fix: "Make the configured output directory writable and rerun the command."
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function bounded(value, maximum = 512) {
|
|
51
|
-
return [...value].slice(0, maximum).join("");
|
|
52
|
-
}
|
|
53
|
-
function canonicalDiagnosticError(diagnostic) {
|
|
54
|
-
return {
|
|
55
|
-
code: diagnostic.code,
|
|
56
|
-
message: diagnostic.code === "output_error" ? "The run result could not be written." : bounded(diagnostic.message)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
function flowDiagnostic(result) {
|
|
60
|
-
if (result.code === "invalid_test" || result.code === "unsupported_test" || result.code === "invalid_data") {
|
|
61
|
-
const source = result.source ? `${result.source.file}:${result.source.line}:${result.source.col}: ` : "";
|
|
62
|
-
return {
|
|
63
|
-
code: result.code,
|
|
64
|
-
message: bounded(`${source}${result.message}`),
|
|
65
|
-
fix: bounded(
|
|
66
|
-
result.fix ?? "Fix the reported test input and rerun the command."
|
|
67
|
-
)
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
const known = {
|
|
71
|
-
"browser-missing": {
|
|
72
|
-
message: "No supported browser binary was found.",
|
|
73
|
-
fix: "Run `sedum browsers install chromium`, then rerun the test."
|
|
74
|
-
},
|
|
75
|
-
"browser-launch-failed": {
|
|
76
|
-
message: "The browser could not be started safely.",
|
|
77
|
-
fix: "Check the browser installation and permissions, then rerun the test."
|
|
78
|
-
},
|
|
79
|
-
"browser-disconnected": {
|
|
80
|
-
message: "The browser disconnected during the run.",
|
|
81
|
-
fix: "Restart the browser run and check browser stability if it repeats."
|
|
82
|
-
},
|
|
83
|
-
"context-closed": {
|
|
84
|
-
message: "The browser context closed during the run.",
|
|
85
|
-
fix: "Rerun the test and check browser stability if it repeats."
|
|
86
|
-
},
|
|
87
|
-
"page-closed": {
|
|
88
|
-
message: "The browser page closed during the run.",
|
|
89
|
-
fix: "Rerun the test and check whether the tested page closes itself."
|
|
90
|
-
},
|
|
91
|
-
"page-crashed": {
|
|
92
|
-
message: "The browser page crashed during the run.",
|
|
93
|
-
fix: "Rerun the test and check browser resource usage if it repeats."
|
|
94
|
-
},
|
|
95
|
-
"operation-failed": {
|
|
96
|
-
message: "A browser operation could not be completed safely.",
|
|
97
|
-
fix: "Check the named test step and rerun the test."
|
|
98
|
-
},
|
|
99
|
-
"script-missing": {
|
|
100
|
-
message: "The Sedum browser script was unavailable.",
|
|
101
|
-
fix: "Rebuild or reinstall Sedum, then rerun the test."
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
const diagnostic = known[result.code];
|
|
105
|
-
if (diagnostic) return { code: result.code, ...diagnostic };
|
|
106
|
-
if (result.code === "provider_rate_limited")
|
|
107
|
-
return {
|
|
108
|
-
code: result.code,
|
|
109
|
-
message: "The model provider kept rate limiting requests for five minutes.",
|
|
110
|
-
fix: "Lower --parallel or --provider-concurrency, or retry later."
|
|
111
|
-
};
|
|
112
|
-
if (result.code.startsWith("provider_"))
|
|
113
|
-
return {
|
|
114
|
-
code: result.code,
|
|
115
|
-
message: "The model provider could not complete the run safely.",
|
|
116
|
-
fix: result.code === "provider_configuration" || result.code === "provider_authentication" ? "Check TYPESAFE_API_KEY and provider access, then rerun the test." : "Check provider availability and the test input, then rerun the test."
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
code: "execution_error",
|
|
120
|
-
message: "The browser run could not be completed safely.",
|
|
121
|
-
fix: "Check the browser, provider, and test input, then rerun the test."
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function renderDiagnostic(diagnostic) {
|
|
125
|
-
return `${diagnostic.message}
|
|
126
|
-
Fix: ${diagnostic.fix}
|
|
127
|
-
`;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/run-pool.ts
|
|
131
|
-
var MAX_PARALLEL = 64;
|
|
132
|
-
function planLanes(requested, availableParallelism, selectedTests) {
|
|
133
|
-
const wanted = requested === "auto" ? Math.max(1, Math.floor(availableParallelism / 2)) : requested;
|
|
134
|
-
return Math.max(1, Math.min(wanted, MAX_PARALLEL, selectedTests));
|
|
135
|
-
}
|
|
136
|
-
function parseParallel(value) {
|
|
137
|
-
if (value === "auto") return "auto";
|
|
138
|
-
if (!/^[1-9]\d*$/u.test(value)) return null;
|
|
139
|
-
const parsed = Number(value);
|
|
140
|
-
return parsed <= MAX_PARALLEL ? parsed : null;
|
|
141
|
-
}
|
|
142
|
-
async function runPool(options) {
|
|
143
|
-
let cursor = 0;
|
|
144
|
-
let stopped = false;
|
|
145
|
-
let failure = null;
|
|
146
|
-
const lane = async (index) => {
|
|
147
|
-
while (!stopped && !options.signal?.aborted) {
|
|
148
|
-
const ordinal = cursor++;
|
|
149
|
-
if (ordinal >= options.items.length) return;
|
|
150
|
-
try {
|
|
151
|
-
if (await options.run(options.items[ordinal], index, ordinal) === "stop")
|
|
152
|
-
stopped = true;
|
|
153
|
-
} catch (error) {
|
|
154
|
-
stopped = true;
|
|
155
|
-
failure ??= { error };
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
const count = Math.max(1, Math.min(options.lanes, options.items.length));
|
|
160
|
-
await Promise.all(Array.from({ length: count }, (_, index) => lane(index)));
|
|
161
|
-
if (failure) throw failure.error;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
1
|
// src/locator-cache-store.ts
|
|
165
2
|
import { randomBytes, randomUUID } from "crypto";
|
|
166
3
|
import { execFile } from "child_process";
|
|
@@ -429,16 +266,45 @@ async function clearLocatorCache(root) {
|
|
|
429
266
|
return true;
|
|
430
267
|
}
|
|
431
268
|
|
|
269
|
+
// src/run-pool.ts
|
|
270
|
+
var MAX_PARALLEL = 64;
|
|
271
|
+
function planLanes(requested, availableParallelism, selectedTests) {
|
|
272
|
+
const wanted = requested === "auto" ? Math.max(1, Math.floor(availableParallelism / 2)) : requested;
|
|
273
|
+
return Math.max(1, Math.min(wanted, MAX_PARALLEL, selectedTests));
|
|
274
|
+
}
|
|
275
|
+
function parseParallel(value) {
|
|
276
|
+
if (value === "auto") return "auto";
|
|
277
|
+
if (!/^[1-9]\d*$/u.test(value)) return null;
|
|
278
|
+
const parsed = Number(value);
|
|
279
|
+
return parsed <= MAX_PARALLEL ? parsed : null;
|
|
280
|
+
}
|
|
281
|
+
async function runPool(options) {
|
|
282
|
+
let cursor = 0;
|
|
283
|
+
let stopped = false;
|
|
284
|
+
let failure = null;
|
|
285
|
+
const lane = async (index) => {
|
|
286
|
+
while (!stopped && !options.signal?.aborted) {
|
|
287
|
+
const ordinal = cursor++;
|
|
288
|
+
if (ordinal >= options.items.length) return;
|
|
289
|
+
try {
|
|
290
|
+
if (await options.run(options.items[ordinal], index, ordinal) === "stop")
|
|
291
|
+
stopped = true;
|
|
292
|
+
} catch (error) {
|
|
293
|
+
stopped = true;
|
|
294
|
+
failure ??= { error };
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const count = Math.max(1, Math.min(options.lanes, options.items.length));
|
|
299
|
+
await Promise.all(Array.from({ length: count }, (_, index) => lane(index)));
|
|
300
|
+
if (failure) throw failure.error;
|
|
301
|
+
}
|
|
302
|
+
|
|
432
303
|
export {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
canonicalDiagnosticError,
|
|
436
|
-
flowDiagnostic,
|
|
437
|
-
renderDiagnostic,
|
|
304
|
+
openLocatorCache,
|
|
305
|
+
clearLocatorCache,
|
|
438
306
|
MAX_PARALLEL,
|
|
439
307
|
planLanes,
|
|
440
308
|
parseParallel,
|
|
441
|
-
runPool
|
|
442
|
-
openLocatorCache,
|
|
443
|
-
clearLocatorCache
|
|
309
|
+
runPool
|
|
444
310
|
};
|
|
@@ -2,8 +2,44 @@
|
|
|
2
2
|
import { readFile, readdir } from "fs/promises";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { parseEnv } from "util";
|
|
5
|
-
import { minimatch } from "minimatch";
|
|
5
|
+
import { minimatch as minimatch2 } from "minimatch";
|
|
6
6
|
import { isMap, LineCounter, parseDocument, visit } from "yaml";
|
|
7
|
+
|
|
8
|
+
// src/affected-paths.ts
|
|
9
|
+
import { minimatch } from "minimatch";
|
|
10
|
+
function validAffectedGlob(pattern) {
|
|
11
|
+
if (!pattern.trim()) return false;
|
|
12
|
+
if (/^[/!]|^[A-Za-z]:|\\/u.test(pattern)) return false;
|
|
13
|
+
if (pattern.split("/").includes("..")) return false;
|
|
14
|
+
return balancedGlobDelimiters(pattern);
|
|
15
|
+
}
|
|
16
|
+
function balancedGlobDelimiters(pattern) {
|
|
17
|
+
const stack = [];
|
|
18
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
19
|
+
const character = pattern[index];
|
|
20
|
+
if (character === "[") {
|
|
21
|
+
const closing = pattern.indexOf("]", index + 1);
|
|
22
|
+
if (closing < 0) return false;
|
|
23
|
+
index = closing;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if ("{(".includes(character)) stack.push(character);
|
|
27
|
+
const opening = { ")": "(", "}": "{" }[character];
|
|
28
|
+
if (opening && stack.pop() !== opening) return false;
|
|
29
|
+
}
|
|
30
|
+
return stack.length === 0;
|
|
31
|
+
}
|
|
32
|
+
function affectedPathIgnored(file, patterns) {
|
|
33
|
+
return patterns.some(
|
|
34
|
+
(pattern) => minimatch(file, pattern.endsWith("/") ? `${pattern}**` : pattern, {
|
|
35
|
+
dot: true,
|
|
36
|
+
nonegate: true,
|
|
37
|
+
nocomment: true
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/config.ts
|
|
7
43
|
var CONFIG_FILE = "sedum.config.yaml";
|
|
8
44
|
var ProjectConfigError = class extends Error {
|
|
9
45
|
constructor(diagnostics) {
|
|
@@ -15,7 +51,7 @@ var ProjectConfigError = class extends Error {
|
|
|
15
51
|
};
|
|
16
52
|
var DEFAULTS = {
|
|
17
53
|
testDirectory: "tests",
|
|
18
|
-
include: ["**/*.test.yaml"],
|
|
54
|
+
include: ["**/*.test.ts", "**/*.test.yaml"],
|
|
19
55
|
exclude: [],
|
|
20
56
|
browser: "chrome",
|
|
21
57
|
viewport: { width: 1280, height: 900 },
|
|
@@ -25,11 +61,19 @@ var DEFAULTS = {
|
|
|
25
61
|
contradictionCutoff: 0.5
|
|
26
62
|
},
|
|
27
63
|
outputDir: ".sedum/runs",
|
|
28
|
-
reporterDir: ".sedum/reports"
|
|
64
|
+
reporterDir: ".sedum/reports",
|
|
65
|
+
vision: {
|
|
66
|
+
enabled: false,
|
|
67
|
+
model: "google/gemini-3.8-flash",
|
|
68
|
+
timeoutMs: 1e4
|
|
69
|
+
}
|
|
29
70
|
};
|
|
71
|
+
var DEFAULT_PROVIDER_BASE_URL = "https://api.typesafe.ai";
|
|
72
|
+
var DEFAULT_PROVIDER_MODEL = "jev-latest";
|
|
30
73
|
var allowed = {
|
|
31
74
|
root: /* @__PURE__ */ new Set([
|
|
32
75
|
"tests",
|
|
76
|
+
"affected",
|
|
33
77
|
"browser",
|
|
34
78
|
"viewport",
|
|
35
79
|
"thresholds",
|
|
@@ -38,12 +82,17 @@ var allowed = {
|
|
|
38
82
|
"baseUrl",
|
|
39
83
|
"environment",
|
|
40
84
|
"variables",
|
|
41
|
-
"environments"
|
|
85
|
+
"environments",
|
|
86
|
+
"vision",
|
|
87
|
+
"provider"
|
|
42
88
|
]),
|
|
43
89
|
tests: /* @__PURE__ */ new Set(["directory", "include", "exclude"]),
|
|
90
|
+
affected: /* @__PURE__ */ new Set(["ignore"]),
|
|
44
91
|
viewport: /* @__PURE__ */ new Set(["width", "height"]),
|
|
45
92
|
thresholds: /* @__PURE__ */ new Set(["verify", "lowConfidenceBand", "contradiction"]),
|
|
46
|
-
environment: /* @__PURE__ */ new Set(["baseUrl", "variables"])
|
|
93
|
+
environment: /* @__PURE__ */ new Set(["baseUrl", "variables"]),
|
|
94
|
+
vision: /* @__PURE__ */ new Set(["enabled", "model", "timeoutMs"]),
|
|
95
|
+
provider: /* @__PURE__ */ new Set(["name", "model"])
|
|
47
96
|
};
|
|
48
97
|
function source(file, counter, node) {
|
|
49
98
|
const position = counter.linePos(node?.range?.[0] ?? 0);
|
|
@@ -71,10 +120,31 @@ function mapUnknownKeys(value, names, prefix, file, counter, diagnostics) {
|
|
|
71
120
|
prefix ? `${prefix}.${key}` : key,
|
|
72
121
|
"unknown_config_key",
|
|
73
122
|
`Unknown configuration key \`${prefix ? `${prefix}.` : ""}${key}\`.`,
|
|
74
|
-
|
|
123
|
+
keyFix(key, names)
|
|
75
124
|
);
|
|
76
125
|
}
|
|
77
126
|
}
|
|
127
|
+
function distance(left, right) {
|
|
128
|
+
const row = Array.from({ length: right.length + 1 }, (_, i) => i);
|
|
129
|
+
for (let i = 1; i <= left.length; i++) {
|
|
130
|
+
let previous = row[0];
|
|
131
|
+
row[0] = i;
|
|
132
|
+
for (let j = 1; j <= right.length; j++) {
|
|
133
|
+
const saved = row[j];
|
|
134
|
+
row[j] = Math.min(
|
|
135
|
+
row[j] + 1,
|
|
136
|
+
row[j - 1] + 1,
|
|
137
|
+
previous + (left[i - 1] === right[j - 1] ? 0 : 1)
|
|
138
|
+
);
|
|
139
|
+
previous = saved;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return row[right.length];
|
|
143
|
+
}
|
|
144
|
+
function keyFix(key, names) {
|
|
145
|
+
const [closest] = [...names].map((known) => ({ known, score: distance(key, known) })).sort((a, b) => a.score - b.score || a.known.localeCompare(b.known));
|
|
146
|
+
return closest && closest.score <= 2 ? `Did you mean \`${closest.known}\`?` : "Remove the key or use one documented in docs/configuration.md.";
|
|
147
|
+
}
|
|
78
148
|
function object(value) {
|
|
79
149
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
80
150
|
}
|
|
@@ -95,7 +165,7 @@ function scalarVariables(value, key, diagnostics, file, counter, node) {
|
|
|
95
165
|
}
|
|
96
166
|
const result = {};
|
|
97
167
|
for (const [name, item] of Object.entries(value)) {
|
|
98
|
-
if (name === "TYPESAFE_API_KEY") {
|
|
168
|
+
if (name === "TYPESAFE_API_KEY" || name === "OPEN_ROUTER_API_KEY" || name === "CLOUDFLARE_ACCOUNT_ID" || name === "CLOUDFLARE_AUTH_TOKEN" || name === "CLOUDFLARE_API_TOKEN") {
|
|
99
169
|
diagnostic(
|
|
100
170
|
diagnostics,
|
|
101
171
|
file,
|
|
@@ -103,8 +173,8 @@ function scalarVariables(value, key, diagnostics, file, counter, node) {
|
|
|
103
173
|
node,
|
|
104
174
|
`${key}.${name}`,
|
|
105
175
|
"api_key_in_config",
|
|
106
|
-
|
|
107
|
-
|
|
176
|
+
`${name} must not be stored in sedum.config.yaml.`,
|
|
177
|
+
`Put ${name} in the project-root .env or invoking process environment.`
|
|
108
178
|
);
|
|
109
179
|
continue;
|
|
110
180
|
}
|
|
@@ -201,7 +271,7 @@ function stringList(value, fallback, key, diagnostics, file, counter, node) {
|
|
|
201
271
|
key,
|
|
202
272
|
"invalid_config_globs",
|
|
203
273
|
`Configuration key \`${key}\` must be a list of nonempty glob strings.`,
|
|
204
|
-
`Write \`${key}: ["**/*.test.yaml"]\`.`
|
|
274
|
+
`Write \`${key}: ["**/*.test.ts", "**/*.test.yaml"]\`.`
|
|
205
275
|
);
|
|
206
276
|
return [...fallback];
|
|
207
277
|
}
|
|
@@ -271,8 +341,11 @@ async function findConfig(start) {
|
|
|
271
341
|
function freeze(config) {
|
|
272
342
|
Object.freeze(config.include);
|
|
273
343
|
Object.freeze(config.exclude);
|
|
344
|
+
Object.freeze(config.affected.ignore);
|
|
345
|
+
Object.freeze(config.affected);
|
|
274
346
|
Object.freeze(config.viewport);
|
|
275
347
|
Object.freeze(config.thresholds);
|
|
348
|
+
Object.freeze(config.vision);
|
|
276
349
|
Object.freeze(config.variables);
|
|
277
350
|
return Object.freeze(config);
|
|
278
351
|
}
|
|
@@ -370,8 +443,11 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
370
443
|
);
|
|
371
444
|
const maps = [
|
|
372
445
|
["tests", allowed.tests],
|
|
446
|
+
["affected", allowed.affected],
|
|
373
447
|
["viewport", allowed.viewport],
|
|
374
|
-
["thresholds", allowed.thresholds]
|
|
448
|
+
["thresholds", allowed.thresholds],
|
|
449
|
+
["vision", allowed.vision],
|
|
450
|
+
["provider", allowed.provider]
|
|
375
451
|
];
|
|
376
452
|
for (const [key, names] of maps)
|
|
377
453
|
mapUnknownKeys(
|
|
@@ -408,9 +484,12 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
408
484
|
"Use `tests: { directory: tests }`."
|
|
409
485
|
);
|
|
410
486
|
for (const [key, value] of [
|
|
487
|
+
["affected", raw.affected],
|
|
411
488
|
["viewport", raw.viewport],
|
|
412
489
|
["thresholds", raw.thresholds],
|
|
413
|
-
["environments", raw.environments]
|
|
490
|
+
["environments", raw.environments],
|
|
491
|
+
["vision", raw.vision],
|
|
492
|
+
["provider", raw.provider]
|
|
414
493
|
])
|
|
415
494
|
if (value !== void 0 && !object(value))
|
|
416
495
|
diagnostic(
|
|
@@ -424,8 +503,31 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
424
503
|
`Write \`${key}: {}\` and add its documented child keys.`
|
|
425
504
|
);
|
|
426
505
|
const viewport = object(raw.viewport) ? raw.viewport : {};
|
|
506
|
+
const affected = object(raw.affected) ? raw.affected : {};
|
|
507
|
+
const affectedIgnore = stringList(
|
|
508
|
+
affected.ignore,
|
|
509
|
+
[],
|
|
510
|
+
"affected.ignore",
|
|
511
|
+
diagnostics,
|
|
512
|
+
file,
|
|
513
|
+
counter,
|
|
514
|
+
node("affected.ignore")
|
|
515
|
+
);
|
|
516
|
+
if (affectedIgnore.some((glob) => !validAffectedGlob(glob)))
|
|
517
|
+
diagnostic(
|
|
518
|
+
diagnostics,
|
|
519
|
+
file,
|
|
520
|
+
counter,
|
|
521
|
+
node("affected.ignore"),
|
|
522
|
+
"affected.ignore",
|
|
523
|
+
"invalid_affected_glob",
|
|
524
|
+
"Affected ignores must be valid repository-relative POSIX globs.",
|
|
525
|
+
"Use patterns such as `docs/` or `**/*.lock`."
|
|
526
|
+
);
|
|
427
527
|
const thresholds = object(raw.thresholds) ? raw.thresholds : {};
|
|
428
528
|
const environments = object(raw.environments) ? raw.environments : {};
|
|
529
|
+
const vision = object(raw.vision) ? raw.vision : {};
|
|
530
|
+
const provider = object(raw.provider) ? raw.provider : {};
|
|
429
531
|
for (const [name, value] of Object.entries(environments)) {
|
|
430
532
|
if (!object(value)) {
|
|
431
533
|
diagnostic(
|
|
@@ -597,7 +699,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
597
699
|
"tests.include",
|
|
598
700
|
"empty_config_globs",
|
|
599
701
|
"Configuration key `tests.include` must select at least one pattern.",
|
|
600
|
-
"Add `**/*.test.
|
|
702
|
+
"Add `**/*.test.ts` or another test glob."
|
|
601
703
|
);
|
|
602
704
|
const variables = {
|
|
603
705
|
...rootVariables,
|
|
@@ -605,7 +707,127 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
605
707
|
...fileEnvironment,
|
|
606
708
|
...hostEnvironment
|
|
607
709
|
};
|
|
608
|
-
const
|
|
710
|
+
const providerValue = (name) => hostEnvironment[name]?.trim() || fileEnvironment[name]?.trim() || void 0;
|
|
711
|
+
const cloudflareTokenFrom = (environment2) => {
|
|
712
|
+
const authToken = environment2.CLOUDFLARE_AUTH_TOKEN?.trim();
|
|
713
|
+
const apiToken = environment2.CLOUDFLARE_API_TOKEN?.trim();
|
|
714
|
+
if (authToken && apiToken && authToken !== apiToken)
|
|
715
|
+
diagnostics.push({
|
|
716
|
+
code: "conflicting_cloudflare_api_tokens",
|
|
717
|
+
file: environmentFile,
|
|
718
|
+
line: 1,
|
|
719
|
+
col: 1,
|
|
720
|
+
key: "CLOUDFLARE_AUTH_TOKEN",
|
|
721
|
+
message: "CLOUDFLARE_AUTH_TOKEN and CLOUDFLARE_API_TOKEN contain different values at the same precedence level.",
|
|
722
|
+
fix: "Keep one token variable, or set both names to the same Workers AI API token."
|
|
723
|
+
});
|
|
724
|
+
return authToken || apiToken || void 0;
|
|
725
|
+
};
|
|
726
|
+
const providerNameValue = provider.name ?? "typesafe";
|
|
727
|
+
const providerName = providerNameValue === "typesafe" || providerNameValue === "clef" ? providerNameValue : "typesafe";
|
|
728
|
+
if (providerNameValue !== "typesafe" && providerNameValue !== "clef")
|
|
729
|
+
diagnostic(
|
|
730
|
+
diagnostics,
|
|
731
|
+
file,
|
|
732
|
+
counter,
|
|
733
|
+
node("provider.name"),
|
|
734
|
+
"provider.name",
|
|
735
|
+
"invalid_config_provider",
|
|
736
|
+
"Configuration key `provider.name` must be `typesafe` or `clef`.",
|
|
737
|
+
"Choose one of the supported provider names."
|
|
738
|
+
);
|
|
739
|
+
const configuredModel = provider.model;
|
|
740
|
+
const validClefModel = configuredModel === "clef" || configuredModel === "clef-flash";
|
|
741
|
+
if (configuredModel !== void 0 && (typeof configuredModel !== "string" || !configuredModel.trim() || providerName === "clef" && !validClefModel))
|
|
742
|
+
diagnostic(
|
|
743
|
+
diagnostics,
|
|
744
|
+
file,
|
|
745
|
+
counter,
|
|
746
|
+
node("provider.model"),
|
|
747
|
+
"provider.model",
|
|
748
|
+
"invalid_config_provider_model",
|
|
749
|
+
providerName === "clef" ? "Clef provider model must be `clef` or `clef-flash`." : "Provider model must be nonempty text.",
|
|
750
|
+
providerName === "clef" ? "Use `provider.model: clef`." : "Use a nonempty model name."
|
|
751
|
+
);
|
|
752
|
+
const customProvider = {
|
|
753
|
+
baseUrl: providerValue("TYPESAFE_BASE_URL"),
|
|
754
|
+
model: providerValue("TYPESAFE_DEFAULT_MODEL")
|
|
755
|
+
};
|
|
756
|
+
let providerBaseUrl = DEFAULT_PROVIDER_BASE_URL;
|
|
757
|
+
if (providerName === "typesafe" && customProvider.baseUrl) {
|
|
758
|
+
try {
|
|
759
|
+
const parsed = new URL(customProvider.baseUrl);
|
|
760
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.search || parsed.hash)
|
|
761
|
+
throw new Error("unsafe provider URL");
|
|
762
|
+
providerBaseUrl = parsed.href.replace(/\/$/u, "");
|
|
763
|
+
} catch {
|
|
764
|
+
diagnostics.push({
|
|
765
|
+
code: "invalid_provider_url",
|
|
766
|
+
file: environmentFile,
|
|
767
|
+
line: 1,
|
|
768
|
+
col: 1,
|
|
769
|
+
key: "TYPESAFE_BASE_URL",
|
|
770
|
+
message: "TYPESAFE_BASE_URL must be an absolute HTTPS URL without credentials, query, or fragment.",
|
|
771
|
+
fix: "Use a base URL such as https://api.typesafe.ai."
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
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 apiKey = providerName === "clef" ? cloudflareTokenFrom(hostEnvironment) ?? cloudflareTokenFrom(fileEnvironment) : providerValue("TYPESAFE_API_KEY");
|
|
777
|
+
const cloudflareAccountId = providerName === "clef" ? providerValue("CLOUDFLARE_ACCOUNT_ID") : void 0;
|
|
778
|
+
if (providerName === "clef" && cloudflareAccountId !== void 0 && !/^[a-f\d]{32}$/iu.test(cloudflareAccountId))
|
|
779
|
+
diagnostics.push({
|
|
780
|
+
code: "invalid_cloudflare_account_id",
|
|
781
|
+
file: environmentFile,
|
|
782
|
+
line: 1,
|
|
783
|
+
col: 1,
|
|
784
|
+
key: "CLOUDFLARE_ACCOUNT_ID",
|
|
785
|
+
message: "CLOUDFLARE_ACCOUNT_ID must be exactly 32 hexadecimal characters.",
|
|
786
|
+
fix: "Copy the account ID from the Cloudflare dashboard."
|
|
787
|
+
});
|
|
788
|
+
const visionApiKey = providerValue("OPEN_ROUTER_API_KEY");
|
|
789
|
+
variables.OPEN_ROUTER_API_KEY = void 0;
|
|
790
|
+
variables.CLOUDFLARE_ACCOUNT_ID = void 0;
|
|
791
|
+
variables.CLOUDFLARE_AUTH_TOKEN = void 0;
|
|
792
|
+
variables.CLOUDFLARE_API_TOKEN = void 0;
|
|
793
|
+
const visionEnabledValue = overrides.vision?.enabled ?? vision.enabled;
|
|
794
|
+
const visionEnabled = visionEnabledValue ?? DEFAULTS.vision.enabled;
|
|
795
|
+
if (typeof visionEnabled !== "boolean")
|
|
796
|
+
diagnostic(
|
|
797
|
+
diagnostics,
|
|
798
|
+
file,
|
|
799
|
+
counter,
|
|
800
|
+
node("vision.enabled"),
|
|
801
|
+
"vision.enabled",
|
|
802
|
+
"invalid_config_type",
|
|
803
|
+
"Configuration key `vision.enabled` must be a boolean.",
|
|
804
|
+
"Use `vision.enabled: true` or `vision.enabled: false`."
|
|
805
|
+
);
|
|
806
|
+
const visionModelValue = overrides.vision?.model ?? vision.model;
|
|
807
|
+
const visionModel = visionModelValue ?? DEFAULTS.vision.model;
|
|
808
|
+
if (typeof visionModel !== "string" || !visionModel.trim())
|
|
809
|
+
diagnostic(
|
|
810
|
+
diagnostics,
|
|
811
|
+
file,
|
|
812
|
+
counter,
|
|
813
|
+
node("vision.model"),
|
|
814
|
+
"vision.model",
|
|
815
|
+
"invalid_config_type",
|
|
816
|
+
"Configuration key `vision.model` must be nonempty text.",
|
|
817
|
+
`Use a model such as \`${DEFAULTS.vision.model}\`.`
|
|
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`."
|
|
830
|
+
);
|
|
609
831
|
const testDirectory = relativePath(
|
|
610
832
|
found.root,
|
|
611
833
|
tests.directory,
|
|
@@ -662,6 +884,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
662
884
|
testDirectory,
|
|
663
885
|
include,
|
|
664
886
|
exclude,
|
|
887
|
+
affected: { ignore: affectedIgnore },
|
|
665
888
|
browser,
|
|
666
889
|
viewport: { width, height },
|
|
667
890
|
thresholds: { minP: verify, band, contradictionCutoff },
|
|
@@ -669,7 +892,17 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
669
892
|
reporterDir,
|
|
670
893
|
baseUrl,
|
|
671
894
|
variables,
|
|
672
|
-
|
|
895
|
+
providerName,
|
|
896
|
+
apiKey,
|
|
897
|
+
cloudflareAccountId,
|
|
898
|
+
providerBaseUrl,
|
|
899
|
+
providerModel,
|
|
900
|
+
vision: {
|
|
901
|
+
enabled: visionEnabled === true,
|
|
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
|
|
673
906
|
});
|
|
674
907
|
}
|
|
675
908
|
async function discoverConfiguredTests(config) {
|
|
@@ -688,7 +921,7 @@ async function discoverConfiguredTests(config) {
|
|
|
688
921
|
if (entry.isDirectory()) await visit2(absolute);
|
|
689
922
|
else if (entry.isFile()) {
|
|
690
923
|
const relative = path.relative(config.testDirectory, absolute).split(path.sep).join("/");
|
|
691
|
-
if (relative.endsWith(".test.yaml") && config.include.some((pattern) =>
|
|
924
|
+
if ((relative.endsWith(".test.ts") || relative.endsWith(".test.yaml")) && config.include.some((pattern) => minimatch2(relative, pattern)) && !config.exclude.some((pattern) => minimatch2(relative, pattern)))
|
|
692
925
|
files.push(absolute);
|
|
693
926
|
}
|
|
694
927
|
}
|
|
@@ -698,7 +931,11 @@ async function discoverConfiguredTests(config) {
|
|
|
698
931
|
}
|
|
699
932
|
|
|
700
933
|
export {
|
|
934
|
+
validAffectedGlob,
|
|
935
|
+
affectedPathIgnored,
|
|
701
936
|
ProjectConfigError,
|
|
937
|
+
DEFAULT_PROVIDER_BASE_URL,
|
|
938
|
+
DEFAULT_PROVIDER_MODEL,
|
|
702
939
|
loadProjectConfig,
|
|
703
940
|
discoverConfiguredTests
|
|
704
941
|
};
|