sedum-cli 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/chunk-BEV24G7S.js +444 -0
- package/dist/chunk-OB6ZUJ6X.js +242 -0
- package/dist/chunk-TU5MIKGA.js +963 -0
- package/dist/chunk-TZGSCV23.js +704 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +66 -0
- package/dist/doctor-command-2PMOA32Y.js +17 -0
- package/dist/index.d.ts +179 -0
- package/dist/index.js +19 -0
- package/dist/init-command-54R2FQ2U.js +237 -0
- package/dist/run-command-VAVFPCWG.js +1269 -0
- package/package.json +36 -0
|
@@ -0,0 +1,963 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_PARALLEL,
|
|
3
|
+
clearLocatorCache,
|
|
4
|
+
parseParallel,
|
|
5
|
+
renderDiagnostic
|
|
6
|
+
} from "./chunk-BEV24G7S.js";
|
|
7
|
+
import {
|
|
8
|
+
ProjectConfigError,
|
|
9
|
+
discoverConfiguredTests,
|
|
10
|
+
loadProjectConfig
|
|
11
|
+
} from "./chunk-TZGSCV23.js";
|
|
12
|
+
|
|
13
|
+
// src/exit-policy.ts
|
|
14
|
+
import {
|
|
15
|
+
validateRunResult
|
|
16
|
+
} from "@sedum-dev/core";
|
|
17
|
+
import { runIsTrustworthy } from "@sedum-dev/reporters";
|
|
18
|
+
function runExitCode(result, strict) {
|
|
19
|
+
const value = validateRunResult(result);
|
|
20
|
+
if (!runIsTrustworthy(value)) return 3;
|
|
21
|
+
if (value.verdict === "failed") return 1;
|
|
22
|
+
return strict && value.flags.length > 0 ? 2 : 0;
|
|
23
|
+
}
|
|
24
|
+
function validateExitCode(result, failedBeforeChecks) {
|
|
25
|
+
if (failedBeforeChecks || !result || result.counts.operational > 0) return 3;
|
|
26
|
+
if (!result.fullyValidated) return 1;
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
function listExitCode(listing, failedBeforeListing) {
|
|
30
|
+
if (failedBeforeListing || !listing) return 3;
|
|
31
|
+
return listing.invalid.length ? 1 : 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/output.ts
|
|
35
|
+
import { validateRunResult as validateRunResult2 } from "@sedum-dev/core";
|
|
36
|
+
var ansi = {
|
|
37
|
+
green: "\x1B[32m",
|
|
38
|
+
red: "\x1B[31m",
|
|
39
|
+
yellow: "\x1B[33m",
|
|
40
|
+
cyan: "\x1B[36m",
|
|
41
|
+
reset: "\x1B[0m"
|
|
42
|
+
};
|
|
43
|
+
function paint(value, color, enabled) {
|
|
44
|
+
return enabled ? `${ansi[color]}${value}${ansi.reset}` : value;
|
|
45
|
+
}
|
|
46
|
+
function stateLabel(state, verdict) {
|
|
47
|
+
if (verdict === "passed") return { text: "PASSED", color: "green" };
|
|
48
|
+
if (verdict === "failed") return { text: "FAILED", color: "red" };
|
|
49
|
+
if (state === "interrupted") return { text: "INTERRUPTED", color: "yellow" };
|
|
50
|
+
if (state === "running") return { text: "INCOMPLETE", color: "yellow" };
|
|
51
|
+
return { text: "ERROR", color: "red" };
|
|
52
|
+
}
|
|
53
|
+
function executionLines(value) {
|
|
54
|
+
const lines = [];
|
|
55
|
+
const execution = value.execution;
|
|
56
|
+
if (execution && (execution.parallel.lanes > 1 || execution.shard)) {
|
|
57
|
+
const shard = execution.shard ? `, shard ${execution.shard.index}/${execution.shard.count} of ${execution.shard.globalSelectedTests} selected` : "";
|
|
58
|
+
lines.push(
|
|
59
|
+
`lanes ${execution.parallel.lanes}, provider concurrency ${execution.providerConcurrency}${shard}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const calls = [
|
|
63
|
+
...value.setupCalls,
|
|
64
|
+
...value.tests.flatMap(
|
|
65
|
+
(test) => test.attempts.flatMap((attempt) => [
|
|
66
|
+
...attempt.calls ?? [],
|
|
67
|
+
...attempt.steps.flatMap((step) => step.calls)
|
|
68
|
+
])
|
|
69
|
+
)
|
|
70
|
+
];
|
|
71
|
+
const limited = calls.filter((call) => call.rateLimited).length;
|
|
72
|
+
const waitMs = calls.reduce(
|
|
73
|
+
(sum, call) => sum + (call.rateLimitWaitMs ?? 0),
|
|
74
|
+
0
|
|
75
|
+
);
|
|
76
|
+
if (limited > 0)
|
|
77
|
+
lines.push(
|
|
78
|
+
`provider rate limited ${limited} call(s), waited ${(waitMs / 1e3).toFixed(1)}s in shared cooldowns`
|
|
79
|
+
);
|
|
80
|
+
const conflicts = value.tests.flatMap((test) => test.attempts).flatMap((attempt) => attempt.steps).filter((step) => step.locator?.cache?.reason === "conflict").length;
|
|
81
|
+
if (conflicts > 0)
|
|
82
|
+
lines.push(
|
|
83
|
+
`cache ${conflicts} locator cache write conflict(s); the model result was used`
|
|
84
|
+
);
|
|
85
|
+
return lines;
|
|
86
|
+
}
|
|
87
|
+
function renderRunSummary(result, capabilities, artifacts, showCosts) {
|
|
88
|
+
const value = validateRunResult2(result);
|
|
89
|
+
const color = capabilities.stdoutIsTTY && capabilities.color;
|
|
90
|
+
const lines = [];
|
|
91
|
+
const flagCounts = { low_confidence: 0, contradiction: 0 };
|
|
92
|
+
for (const test of value.tests) {
|
|
93
|
+
const label = stateLabel(test.state, test.verdict);
|
|
94
|
+
const flags = test.flags.length ? ` [${test.flags.join(", ")}]` : "";
|
|
95
|
+
lines.push(
|
|
96
|
+
`test ${paint(label.text, label.color, color)} ${test.file}${flags}`
|
|
97
|
+
);
|
|
98
|
+
if (test.attempts.length > 1)
|
|
99
|
+
lines.push(
|
|
100
|
+
` attempts ${test.attempts.length} (${test.attempts.map((attempt) => attempt.verdict ?? attempt.state).join(" -> ")})`
|
|
101
|
+
);
|
|
102
|
+
const selected = test.attempts.find(
|
|
103
|
+
(attempt) => attempt.id === test.selectedAttemptId
|
|
104
|
+
);
|
|
105
|
+
for (const step of selected?.steps ?? []) {
|
|
106
|
+
for (const flag of step.flags) flagCounts[flag] += 1;
|
|
107
|
+
const cache = step.locator?.cache;
|
|
108
|
+
if (cache) {
|
|
109
|
+
const reason = cache.reason ? ` (${cache.reason})` : "";
|
|
110
|
+
const fallback = cache.fallbackCalledModel ? ", model fallback" : "";
|
|
111
|
+
const changed = cache.targetChanged ? ", target changed" : "";
|
|
112
|
+
lines.push(
|
|
113
|
+
` step ${step.index}: cache ${cache.outcome}${reason}${fallback}${changed}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const runLabel = stateLabel(value.state, value.verdict);
|
|
119
|
+
lines.push(`run ${paint(runLabel.text, runLabel.color, color)}`);
|
|
120
|
+
for (const problem of value.discoveryProblems ?? [])
|
|
121
|
+
lines.push(
|
|
122
|
+
`discovery ${problem.file}${problem.line === void 0 ? "" : `:${problem.line}:${problem.col ?? 1}`}: ${problem.message} Fix: ${problem.fix}`
|
|
123
|
+
);
|
|
124
|
+
lines.push(
|
|
125
|
+
`tests ${value.totals.selectedTests} selected, ${value.totals.executedTests} executed, ${value.totals.passedTests} passed, ${value.totals.failedTests} failed`
|
|
126
|
+
);
|
|
127
|
+
lines.push(
|
|
128
|
+
`flags ${value.totals.flaggedSteps} flagged step(s), low_confidence ${flagCounts.low_confidence}, contradiction ${flagCounts.contradiction}`
|
|
129
|
+
);
|
|
130
|
+
lines.push(...executionLines(value));
|
|
131
|
+
if (artifacts.authoritative) {
|
|
132
|
+
lines.push(`progress ${artifacts.progressPath}`);
|
|
133
|
+
lines.push(`result ${artifacts.resultPath}`);
|
|
134
|
+
if (artifacts.htmlPath) lines.push(`html ${artifacts.htmlPath}`);
|
|
135
|
+
if (artifacts.markdownPath)
|
|
136
|
+
lines.push(`markdown ${artifacts.markdownPath}`);
|
|
137
|
+
if (artifacts.junitPath) lines.push(`junit ${artifacts.junitPath}`);
|
|
138
|
+
if (artifacts.reporterPath)
|
|
139
|
+
lines.push(`reporter ${artifacts.reporterPath}`);
|
|
140
|
+
} else {
|
|
141
|
+
lines.push(`result unavailable (intended ${artifacts.resultPath})`);
|
|
142
|
+
}
|
|
143
|
+
if (capabilities.stdoutIsTTY || showCosts) {
|
|
144
|
+
lines.push(
|
|
145
|
+
`model ${value.totals.modelCalls} call(s), ${value.totals.inputTokens} input tokens, ${value.totals.outputTokens} output tokens`
|
|
146
|
+
);
|
|
147
|
+
lines.push(
|
|
148
|
+
value.totals.costComplete && value.totals.costUsd !== null ? `cost $${value.totals.costUsd.toFixed(6)}` : "cost unknown or incomplete"
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return `${lines.join("\n")}
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/run-cli.ts
|
|
156
|
+
import { Command, CommanderError, InvalidArgumentError } from "commander";
|
|
157
|
+
import {
|
|
158
|
+
createTerminalReporter,
|
|
159
|
+
ReporterLifecycle
|
|
160
|
+
} from "@sedum-dev/reporters";
|
|
161
|
+
|
|
162
|
+
// src/list-command.ts
|
|
163
|
+
import {
|
|
164
|
+
listTests,
|
|
165
|
+
loadFlowFile
|
|
166
|
+
} from "@sedum-dev/core";
|
|
167
|
+
|
|
168
|
+
// src/project-context.ts
|
|
169
|
+
import { realpath, stat } from "fs/promises";
|
|
170
|
+
import path from "path";
|
|
171
|
+
import {
|
|
172
|
+
discoverProjectFiles,
|
|
173
|
+
walkSuiteFiles
|
|
174
|
+
} from "@sedum-dev/core";
|
|
175
|
+
async function loadProjectContext(paths, cwd) {
|
|
176
|
+
let config;
|
|
177
|
+
try {
|
|
178
|
+
config = await loadProjectConfig(
|
|
179
|
+
cwd,
|
|
180
|
+
{},
|
|
181
|
+
{},
|
|
182
|
+
{ readEnvironmentFile: false }
|
|
183
|
+
);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
return {
|
|
186
|
+
config: null,
|
|
187
|
+
discovery: null,
|
|
188
|
+
configErrors: error instanceof ProjectConfigError ? error.diagnostics : [
|
|
189
|
+
{
|
|
190
|
+
code: "config_error",
|
|
191
|
+
file: path.join(cwd, "sedum.config.yaml"),
|
|
192
|
+
line: 1,
|
|
193
|
+
col: 1,
|
|
194
|
+
key: "<file>",
|
|
195
|
+
message: "The Sedum configuration could not be loaded.",
|
|
196
|
+
fix: "Check sedum.config.yaml and its permissions, then rerun."
|
|
197
|
+
}
|
|
198
|
+
]
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
if (paths.length)
|
|
202
|
+
return {
|
|
203
|
+
config,
|
|
204
|
+
discovery: await discoverProjectFiles(paths, {
|
|
205
|
+
repoRoot: config.projectRoot
|
|
206
|
+
}),
|
|
207
|
+
configErrors: []
|
|
208
|
+
};
|
|
209
|
+
const root = await realpath(config.projectRoot).catch(
|
|
210
|
+
() => config.projectRoot
|
|
211
|
+
);
|
|
212
|
+
const under = (file) => path.join(root, path.relative(config.projectRoot, file));
|
|
213
|
+
const testDirectory = path.relative(config.projectRoot, config.testDirectory);
|
|
214
|
+
let tests;
|
|
215
|
+
let unreadable = false;
|
|
216
|
+
try {
|
|
217
|
+
tests = await discoverConfiguredTests(config);
|
|
218
|
+
} catch {
|
|
219
|
+
tests = [];
|
|
220
|
+
unreadable = true;
|
|
221
|
+
}
|
|
222
|
+
const exists = await stat(config.testDirectory).then(
|
|
223
|
+
() => true,
|
|
224
|
+
() => false
|
|
225
|
+
);
|
|
226
|
+
const modules = exists ? await walkSuiteFiles(config.testDirectory, [".module.yaml"], () => {
|
|
227
|
+
unreadable = true;
|
|
228
|
+
}) : [];
|
|
229
|
+
return {
|
|
230
|
+
config,
|
|
231
|
+
discovery: {
|
|
232
|
+
root,
|
|
233
|
+
tests: tests.map(under),
|
|
234
|
+
modules: modules.map(under),
|
|
235
|
+
problems: unreadable ? [
|
|
236
|
+
{
|
|
237
|
+
code: "unreadable_directory",
|
|
238
|
+
path: testDirectory || ".",
|
|
239
|
+
message: `Could not read the configured test directory ${testDirectory || "."}.`,
|
|
240
|
+
fix: "Check tests.directory in sedum.config.yaml and the directory permissions."
|
|
241
|
+
}
|
|
242
|
+
] : []
|
|
243
|
+
},
|
|
244
|
+
configErrors: []
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function renderConfigErrors(errors, cwd) {
|
|
248
|
+
return errors.map((item) => {
|
|
249
|
+
const file = path.relative(cwd, item.file).split(path.sep).join("/");
|
|
250
|
+
return `${file}:${item.line}:${item.col}: error ${item.code}: ${item.message}
|
|
251
|
+
Fix: ${item.fix}
|
|
252
|
+
`;
|
|
253
|
+
}).join("");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/list-command.ts
|
|
257
|
+
async function executeListCommand(options) {
|
|
258
|
+
const context = await loadProjectContext(options.paths, options.cwd);
|
|
259
|
+
if (!context.config)
|
|
260
|
+
return {
|
|
261
|
+
discovery: null,
|
|
262
|
+
configErrors: context.configErrors,
|
|
263
|
+
listing: null
|
|
264
|
+
};
|
|
265
|
+
const { discovery } = context;
|
|
266
|
+
if (discovery.problems.length)
|
|
267
|
+
return { discovery, configErrors: [], listing: null };
|
|
268
|
+
const parsed = [];
|
|
269
|
+
for (const file of discovery.tests)
|
|
270
|
+
parsed.push({
|
|
271
|
+
file,
|
|
272
|
+
result: await loadFlowFile(file, { repoRoot: discovery.root })
|
|
273
|
+
});
|
|
274
|
+
return {
|
|
275
|
+
discovery,
|
|
276
|
+
configErrors: [],
|
|
277
|
+
listing: listTests(parsed, { repoRoot: discovery.root })
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/validate-command.ts
|
|
282
|
+
import {
|
|
283
|
+
FileClassificationCache,
|
|
284
|
+
ProviderError,
|
|
285
|
+
validateProject
|
|
286
|
+
} from "@sedum-dev/core";
|
|
287
|
+
import path2 from "path";
|
|
288
|
+
var CLASSIFICATION_MODEL = "jev-latest";
|
|
289
|
+
var createTypeSafeClassifier = async ({
|
|
290
|
+
apiKey
|
|
291
|
+
}) => {
|
|
292
|
+
const { TypeSafeAdapter } = await import("@sedum-dev/provider-typesafe");
|
|
293
|
+
return new TypeSafeAdapter(apiKey ? { apiKey } : {});
|
|
294
|
+
};
|
|
295
|
+
function emptyProjectProblem(paths, testDirectory) {
|
|
296
|
+
const shown = paths.length ? paths.join(", ") : testDirectory || ".";
|
|
297
|
+
return {
|
|
298
|
+
code: "missing_path",
|
|
299
|
+
path: shown,
|
|
300
|
+
message: `No *.test.yaml or *.module.yaml files were found under ${shown}.`,
|
|
301
|
+
fix: paths.length ? "Pass paths relative to the project root that contain tests or modules." : "Add tests under tests.directory, or correct tests.directory/include/exclude in sedum.config.yaml."
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
var missingKey = {
|
|
305
|
+
code: "missing_key",
|
|
306
|
+
message: "`sedum validate --online` needs a configured TypeSafe provider.",
|
|
307
|
+
fix: "Set TYPESAFE_API_KEY in the environment or the project-root .env and rerun, or omit --online to validate offline."
|
|
308
|
+
};
|
|
309
|
+
async function onlineProvider(options) {
|
|
310
|
+
try {
|
|
311
|
+
const { apiKey } = await loadProjectConfig(options.cwd);
|
|
312
|
+
return await options.createProvider(apiKey ? { apiKey } : {});
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (error instanceof ProviderError && error.code === "configuration")
|
|
315
|
+
return missingKey;
|
|
316
|
+
return {
|
|
317
|
+
code: "setup_error",
|
|
318
|
+
message: "The classification provider could not be prepared.",
|
|
319
|
+
fix: "Check the provider installation, sedum.config.yaml, and the project-root .env, then rerun."
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async function executeValidateCommand(options) {
|
|
324
|
+
const context = await loadProjectContext(options.paths, options.cwd);
|
|
325
|
+
if (!context.config)
|
|
326
|
+
return {
|
|
327
|
+
discovery: null,
|
|
328
|
+
configErrors: context.configErrors,
|
|
329
|
+
result: null,
|
|
330
|
+
setup: null
|
|
331
|
+
};
|
|
332
|
+
const { config, discovery } = context;
|
|
333
|
+
const stop = (files, setup) => ({
|
|
334
|
+
discovery: files,
|
|
335
|
+
configErrors: [],
|
|
336
|
+
result: null,
|
|
337
|
+
setup
|
|
338
|
+
});
|
|
339
|
+
if (discovery.problems.length) return stop(discovery, null);
|
|
340
|
+
if (!discovery.tests.length && !discovery.modules.length)
|
|
341
|
+
return stop(
|
|
342
|
+
{
|
|
343
|
+
...discovery,
|
|
344
|
+
problems: [
|
|
345
|
+
emptyProjectProblem(
|
|
346
|
+
options.paths,
|
|
347
|
+
path2.relative(config.projectRoot, config.testDirectory)
|
|
348
|
+
)
|
|
349
|
+
]
|
|
350
|
+
},
|
|
351
|
+
null
|
|
352
|
+
);
|
|
353
|
+
let provider;
|
|
354
|
+
if (options.online) {
|
|
355
|
+
const prepared = await onlineProvider(options);
|
|
356
|
+
if ("code" in prepared) return stop(discovery, prepared);
|
|
357
|
+
provider = prepared;
|
|
358
|
+
}
|
|
359
|
+
const cache = await FileClassificationCache.load(
|
|
360
|
+
path2.join(discovery.root, ".sedum", "classifications.json"),
|
|
361
|
+
CLASSIFICATION_MODEL
|
|
362
|
+
);
|
|
363
|
+
const result = await validateProject(discovery, {
|
|
364
|
+
repoRoot: discovery.root,
|
|
365
|
+
baseUrl: config.baseUrl,
|
|
366
|
+
mode: options.online ? "allow-model" : "offline",
|
|
367
|
+
cache,
|
|
368
|
+
...provider ? { provider } : {},
|
|
369
|
+
...options.signal ? { signal: options.signal } : {}
|
|
370
|
+
});
|
|
371
|
+
return { discovery, configErrors: [], result, setup: null };
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// src/validate-output.ts
|
|
375
|
+
import {
|
|
376
|
+
displayPath,
|
|
377
|
+
NOT_CHECKED_OFFLINE_CODE
|
|
378
|
+
} from "@sedum-dev/core";
|
|
379
|
+
var ansi2 = {
|
|
380
|
+
red: "\x1B[31m",
|
|
381
|
+
yellow: "\x1B[33m",
|
|
382
|
+
green: "\x1B[32m",
|
|
383
|
+
reset: "\x1B[0m"
|
|
384
|
+
};
|
|
385
|
+
function paint2(value, color, capabilities) {
|
|
386
|
+
return capabilities.color ? `${ansi2[color]}${value}${ansi2.reset}` : value;
|
|
387
|
+
}
|
|
388
|
+
function plural(count, noun) {
|
|
389
|
+
return `${count} ${noun}${count === 1 ? "" : "s"}`;
|
|
390
|
+
}
|
|
391
|
+
function renderValidation(result, root, capabilities) {
|
|
392
|
+
const lines = [];
|
|
393
|
+
for (const item of result.diagnostics) {
|
|
394
|
+
const where = `${displayPath(root, item.source.file)}:${item.source.line}:${item.source.col}`;
|
|
395
|
+
const label = item.severity === "warning" ? paint2(`warning ${item.code}`, "yellow", capabilities) : item.code === NOT_CHECKED_OFFLINE_CODE ? paint2("not checked offline", "yellow", capabilities) : paint2(`error ${item.code}`, "red", capabilities);
|
|
396
|
+
const fix = item.code === NOT_CHECKED_OFFLINE_CODE ? "Rephrase with a supported verb, or run `sedum validate --online` with TYPESAFE_API_KEY set and commit .sedum/classifications.json." : item.fix;
|
|
397
|
+
lines.push(`${where}: ${label}: ${item.message}`, ` Fix: ${fix}`);
|
|
398
|
+
}
|
|
399
|
+
const { counts } = result;
|
|
400
|
+
const checked = `Checked ${plural(counts.tests, "test")} and ${plural(counts.modules, "module")}`;
|
|
401
|
+
const parts = [
|
|
402
|
+
counts.errors ? plural(counts.errors, "error") : "",
|
|
403
|
+
counts.warnings ? plural(counts.warnings, "warning") : "",
|
|
404
|
+
counts.notCheckedOffline ? `${plural(counts.notCheckedOffline, "sentence")} not checked offline` : ""
|
|
405
|
+
].filter(Boolean);
|
|
406
|
+
lines.push(
|
|
407
|
+
parts.length ? `${checked}: ${parts.join(", ")}.` : `${checked}: ${paint2("all valid", "green", capabilities)}.`
|
|
408
|
+
);
|
|
409
|
+
if (counts.unreferencedModules)
|
|
410
|
+
lines.push(
|
|
411
|
+
`${plural(counts.unreferencedModules, "module")} not used by any test ${counts.unreferencedModules === 1 ? "was" : "were"} checked for format and ${counts.unreferencedModules === 1 ? "its" : "their"} own sentences only; module calls are checked through tests.`
|
|
412
|
+
);
|
|
413
|
+
return `${lines.join("\n")}
|
|
414
|
+
`;
|
|
415
|
+
}
|
|
416
|
+
function renderProblems(problems) {
|
|
417
|
+
return problems.map((problem) => `${problem.message}
|
|
418
|
+
Fix: ${problem.fix}
|
|
419
|
+
`).join("");
|
|
420
|
+
}
|
|
421
|
+
function renderListTable(listing) {
|
|
422
|
+
if (!listing.tests.length) return "No tests found.\n";
|
|
423
|
+
const rows = [
|
|
424
|
+
["ID", "TAGS", "PATH"],
|
|
425
|
+
...listing.tests.map((test) => [
|
|
426
|
+
test.id,
|
|
427
|
+
test.tags.length ? test.tags.join(",") : "-",
|
|
428
|
+
test.file
|
|
429
|
+
])
|
|
430
|
+
];
|
|
431
|
+
const widths = [0, 1].map(
|
|
432
|
+
(column) => Math.max(...rows.map((row) => row[column].length))
|
|
433
|
+
);
|
|
434
|
+
const body = rows.map(
|
|
435
|
+
(row) => [row[0].padEnd(widths[0]), row[1].padEnd(widths[1]), row[2]].join(
|
|
436
|
+
" "
|
|
437
|
+
)
|
|
438
|
+
);
|
|
439
|
+
return `${body.join("\n")}
|
|
440
|
+
${plural(listing.tests.length, "test")}
|
|
441
|
+
`;
|
|
442
|
+
}
|
|
443
|
+
function renderListInvalid(listing) {
|
|
444
|
+
return listing.invalid.map((entry) => {
|
|
445
|
+
const first = entry.diagnostics[0];
|
|
446
|
+
const detail = first ? `${entry.file}:${first.line}:${first.col}: ${first.severity} ${first.code}: ${first.message}` : `${entry.file}: could not be listed.`;
|
|
447
|
+
return `${detail}
|
|
448
|
+
Run \`sedum validate ${entry.file}\` for all problems.
|
|
449
|
+
`;
|
|
450
|
+
}).join("");
|
|
451
|
+
}
|
|
452
|
+
function renderListJson(listing) {
|
|
453
|
+
return `${JSON.stringify(
|
|
454
|
+
{
|
|
455
|
+
schemaVersion: 1,
|
|
456
|
+
tests: listing.tests.map((test) => ({
|
|
457
|
+
id: test.id,
|
|
458
|
+
idSource: test.idSource,
|
|
459
|
+
file: test.file,
|
|
460
|
+
description: test.description,
|
|
461
|
+
tags: test.tags
|
|
462
|
+
})),
|
|
463
|
+
invalid: listing.invalid.map((entry) => ({
|
|
464
|
+
file: entry.file,
|
|
465
|
+
diagnostics: entry.diagnostics.map((item) => ({
|
|
466
|
+
severity: item.severity,
|
|
467
|
+
code: item.code,
|
|
468
|
+
line: item.line,
|
|
469
|
+
col: item.col,
|
|
470
|
+
message: item.message,
|
|
471
|
+
fix: item.fix
|
|
472
|
+
}))
|
|
473
|
+
}))
|
|
474
|
+
},
|
|
475
|
+
null,
|
|
476
|
+
2
|
|
477
|
+
)}
|
|
478
|
+
`;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// src/run-cli.ts
|
|
482
|
+
var plainOutput = {
|
|
483
|
+
stdoutIsTTY: false,
|
|
484
|
+
stderrIsTTY: false,
|
|
485
|
+
color: false
|
|
486
|
+
};
|
|
487
|
+
function collectOrigin(value, previous) {
|
|
488
|
+
try {
|
|
489
|
+
return [...previous, new URL(value).origin];
|
|
490
|
+
} catch {
|
|
491
|
+
throw new InvalidArgumentError(
|
|
492
|
+
`Invalid origin ${JSON.stringify(value)}. Use an absolute URL such as https://example.com.`
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function collectValue(value, previous) {
|
|
497
|
+
if (!value.trim()) throw new InvalidArgumentError("Value must not be blank.");
|
|
498
|
+
return [...previous, value];
|
|
499
|
+
}
|
|
500
|
+
var REPORTERS = ["list", "steps", "terminal", "json", "markdown", "junit"];
|
|
501
|
+
function collectReporter(value, previous) {
|
|
502
|
+
const selected = [...previous];
|
|
503
|
+
for (const item of value.split(",").map((name) => name.trim())) {
|
|
504
|
+
if (!REPORTERS.includes(item))
|
|
505
|
+
throw new InvalidArgumentError(
|
|
506
|
+
`Unknown reporter ${JSON.stringify(item)}. Use list or steps for terminal output, or terminal, json, markdown, or junit.`
|
|
507
|
+
);
|
|
508
|
+
if (!selected.includes(item)) selected.push(item);
|
|
509
|
+
}
|
|
510
|
+
return selected;
|
|
511
|
+
}
|
|
512
|
+
function collectGlob(value, previous) {
|
|
513
|
+
if (!value.trim() || value.startsWith("/") || /^[A-Za-z]:[/\\]/u.test(value) || value.split(/[/\\]/u).includes(".."))
|
|
514
|
+
throw new InvalidArgumentError(
|
|
515
|
+
"Glob must be a nonempty project-relative path without '..'."
|
|
516
|
+
);
|
|
517
|
+
return [...previous, value];
|
|
518
|
+
}
|
|
519
|
+
function collectLabels(value, previous) {
|
|
520
|
+
const labels = value.split(",").map((item) => item.trim());
|
|
521
|
+
if (labels.some((item) => !item))
|
|
522
|
+
throw new InvalidArgumentError(
|
|
523
|
+
"Labels must be nonempty comma-separated tags."
|
|
524
|
+
);
|
|
525
|
+
return [...previous, ...labels];
|
|
526
|
+
}
|
|
527
|
+
function nonnegativeInteger(value) {
|
|
528
|
+
const number = Number(value);
|
|
529
|
+
if (!Number.isSafeInteger(number) || number < 0 || number > 20)
|
|
530
|
+
throw new InvalidArgumentError("Expected an integer from 0 to 20.");
|
|
531
|
+
return number;
|
|
532
|
+
}
|
|
533
|
+
function nonnegativeSlow(value) {
|
|
534
|
+
const number = Number(value);
|
|
535
|
+
if (!Number.isSafeInteger(number) || number < 0 || number > 3e4)
|
|
536
|
+
throw new InvalidArgumentError("Expected milliseconds from 0 to 30000.");
|
|
537
|
+
return number;
|
|
538
|
+
}
|
|
539
|
+
function parallelValue(value) {
|
|
540
|
+
const parsed = parseParallel(value);
|
|
541
|
+
if (parsed === null)
|
|
542
|
+
throw new InvalidArgumentError(
|
|
543
|
+
`Expected auto or an integer from 1 to ${MAX_PARALLEL}.`
|
|
544
|
+
);
|
|
545
|
+
return parsed;
|
|
546
|
+
}
|
|
547
|
+
function positiveCount(maximum) {
|
|
548
|
+
return (value) => {
|
|
549
|
+
const number = Number(value);
|
|
550
|
+
if (!/^[1-9]\d*$/u.test(value) || !Number.isSafeInteger(number) || number > maximum)
|
|
551
|
+
throw new InvalidArgumentError(
|
|
552
|
+
`Expected an integer from 1 to ${maximum}.`
|
|
553
|
+
);
|
|
554
|
+
return number;
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
function positiveMinutes(value) {
|
|
558
|
+
const number = Number(value);
|
|
559
|
+
if (!Number.isFinite(number) || number <= 0 || number > 1440)
|
|
560
|
+
throw new InvalidArgumentError(
|
|
561
|
+
"Expected minutes greater than 0 and at most 1440."
|
|
562
|
+
);
|
|
563
|
+
return number;
|
|
564
|
+
}
|
|
565
|
+
function commandHelp(command, writeErr) {
|
|
566
|
+
command.outputHelp({ error: true });
|
|
567
|
+
const commandPath = [];
|
|
568
|
+
for (let current = command; current; current = current.parent) {
|
|
569
|
+
commandPath.unshift(current.name());
|
|
570
|
+
}
|
|
571
|
+
writeErr(
|
|
572
|
+
`Fix: run \`${commandPath.join(" ")} --help\` and provide a command.
|
|
573
|
+
`
|
|
574
|
+
);
|
|
575
|
+
}
|
|
576
|
+
async function runCli(args, version, runtime = {}) {
|
|
577
|
+
const stdout = [];
|
|
578
|
+
const stderr = [];
|
|
579
|
+
const writeOut = runtime.stdout ?? ((value) => stdout.push(value));
|
|
580
|
+
const writeErr = runtime.stderr ?? ((value) => stderr.push(value));
|
|
581
|
+
const capabilities = runtime.capabilities ?? plainOutput;
|
|
582
|
+
const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-VAVFPCWG.js")).executeRunCommand(options));
|
|
583
|
+
const cwd = runtime.cwd ?? process.cwd();
|
|
584
|
+
let exitCode = 3;
|
|
585
|
+
const program = new Command().name("sedum").description(
|
|
586
|
+
"Run plain-English browser tests with deterministic automation."
|
|
587
|
+
).version(version, "-v, --version", "print the installed Sedum version").helpOption("-h, --help", "show command help").showSuggestionAfterError().showHelpAfterError("Run `sedum --help` to see available commands.").exitOverride().configureOutput({
|
|
588
|
+
writeOut,
|
|
589
|
+
writeErr,
|
|
590
|
+
outputError: (value, write) => write(value)
|
|
591
|
+
}).addHelpText(
|
|
592
|
+
"after",
|
|
593
|
+
"\nExamples:\n sedum init\n sedum run tests/login.test.yaml\n sedum validate\n sedum list --json\n sedum doctor --json\n sedum browsers install chromium\n\nExit codes:\n 0 passed\n 1 failed test (validate and list: invalid test files)\n 2 flagged pass with --strict\n 3 command or operational error\n"
|
|
594
|
+
);
|
|
595
|
+
program.action(() => commandHelp(program, writeErr));
|
|
596
|
+
program.command("init").description("scaffold a runnable Sedum project in the current directory").addHelpText(
|
|
597
|
+
"after",
|
|
598
|
+
"\nCreates a config, a SauceDemo example, .env.example, and ignore rules.\nExisting files are never replaced.\n"
|
|
599
|
+
).action(async () => {
|
|
600
|
+
const { executeInitCommand } = await import("./init-command-54R2FQ2U.js");
|
|
601
|
+
const interactive = capabilities.stdoutIsTTY && (process.stdin.isTTY === true || runtime.confirmInit !== void 0);
|
|
602
|
+
const confirm = runtime.confirmInit ?? (interactive ? async (question) => {
|
|
603
|
+
const { createInterface } = await import("readline/promises");
|
|
604
|
+
const prompt = createInterface({
|
|
605
|
+
input: process.stdin,
|
|
606
|
+
output: process.stdout
|
|
607
|
+
});
|
|
608
|
+
try {
|
|
609
|
+
const answer = await prompt.question(`${question} [y/N] `);
|
|
610
|
+
return /^(?:y|yes)$/iu.test(answer.trim());
|
|
611
|
+
} finally {
|
|
612
|
+
prompt.close();
|
|
613
|
+
}
|
|
614
|
+
} : void 0);
|
|
615
|
+
const result = await executeInitCommand({
|
|
616
|
+
cwd,
|
|
617
|
+
interactive,
|
|
618
|
+
color: capabilities.color,
|
|
619
|
+
...capabilities.columns ? { columns: capabilities.columns } : {},
|
|
620
|
+
...confirm ? { confirm } : {},
|
|
621
|
+
onOutput: writeOut
|
|
622
|
+
});
|
|
623
|
+
writeErr(result.stderr);
|
|
624
|
+
exitCode = result.exitCode;
|
|
625
|
+
});
|
|
626
|
+
program.command("run").description("run configured tests, files, or directories").argument(
|
|
627
|
+
"[paths...]",
|
|
628
|
+
"test files or directories relative to the project root"
|
|
629
|
+
).option(
|
|
630
|
+
"--include <glob>",
|
|
631
|
+
"include matching project-relative paths (repeatable)",
|
|
632
|
+
collectGlob,
|
|
633
|
+
[]
|
|
634
|
+
).option(
|
|
635
|
+
"--exclude <glob>",
|
|
636
|
+
"exclude matching project-relative paths (repeatable)",
|
|
637
|
+
collectGlob,
|
|
638
|
+
[]
|
|
639
|
+
).option(
|
|
640
|
+
"--labels <tags>",
|
|
641
|
+
"require all comma-separated test tags (repeatable)",
|
|
642
|
+
collectLabels,
|
|
643
|
+
[]
|
|
644
|
+
).option(
|
|
645
|
+
"--name <text>",
|
|
646
|
+
"match id or description substring (repeatable)",
|
|
647
|
+
collectValue,
|
|
648
|
+
[]
|
|
649
|
+
).option("--env <name>", "select a named environment").option("--browser <kind>", "chrome or chromium").option(
|
|
650
|
+
"--url-override <url>",
|
|
651
|
+
"replace entry URL origin for preview deployments"
|
|
652
|
+
).option("--output-dir <path>", "run output directory").option("--reporter-dir <path>", "reporter artifact directory").option("--headed", "show the browser", false).option(
|
|
653
|
+
"--slow <ms>",
|
|
654
|
+
"slow browser actions by milliseconds",
|
|
655
|
+
nonnegativeSlow
|
|
656
|
+
).option(
|
|
657
|
+
"--retries <count>",
|
|
658
|
+
"additional whole-test attempts",
|
|
659
|
+
nonnegativeInteger,
|
|
660
|
+
0
|
|
661
|
+
).option(
|
|
662
|
+
"--timeout-minutes <minutes>",
|
|
663
|
+
"whole-run deadline",
|
|
664
|
+
positiveMinutes
|
|
665
|
+
).option(
|
|
666
|
+
"--parallel <n|auto>",
|
|
667
|
+
"run tests in parallel lanes; auto uses half the CPU cores (default 1)",
|
|
668
|
+
parallelValue
|
|
669
|
+
).option(
|
|
670
|
+
"--shard-index <index>",
|
|
671
|
+
"run only this 1-based shard of the selection (with --shard-count)",
|
|
672
|
+
positiveCount(1e4)
|
|
673
|
+
).option(
|
|
674
|
+
"--shard-count <count>",
|
|
675
|
+
"split the selection into this many deterministic shards",
|
|
676
|
+
positiveCount(1e4)
|
|
677
|
+
).option(
|
|
678
|
+
"--provider-concurrency <n>",
|
|
679
|
+
"cap concurrent model-provider requests (default min(4, 2 x lanes))",
|
|
680
|
+
positiveCount(32)
|
|
681
|
+
).option("--replay", "capture replay frames for executed steps", false).option("--no-evidence", "disable non-passing evidence frames").option("--no-locator-cache", "disable the local locator cache").option("--locator-cache-ci", "enable the local locator cache in CI", false).option(
|
|
682
|
+
"--sensitive-origin <url>",
|
|
683
|
+
"omit sensitive page details and frames (repeatable)",
|
|
684
|
+
collectOrigin,
|
|
685
|
+
[]
|
|
686
|
+
).option("--strict", "exit 2 when a passed run has uncertainty flags", false).option(
|
|
687
|
+
"--reporter <name>",
|
|
688
|
+
"reporter: list, steps, terminal, json, markdown, or junit (repeatable or comma-separated; default list)",
|
|
689
|
+
collectReporter,
|
|
690
|
+
[]
|
|
691
|
+
).option(
|
|
692
|
+
"--costs",
|
|
693
|
+
"show model tokens and cost even when stdout is redirected",
|
|
694
|
+
false
|
|
695
|
+
).addHelpText(
|
|
696
|
+
"after",
|
|
697
|
+
"\nPrerequisites:\n Install Chromium with `sedum browsers install chromium` and set TYPESAFE_API_KEY.\n\nExamples:\n sedum run tests/login.test.yaml\n sedum run tests/login.test.yaml --strict --costs\n"
|
|
698
|
+
).action(
|
|
699
|
+
async (paths, options) => {
|
|
700
|
+
if (options.shardIndex === void 0 !== (options.shardCount === void 0) || options.shardIndex !== void 0 && options.shardIndex > options.shardCount) {
|
|
701
|
+
writeErr(
|
|
702
|
+
renderDiagnostic({
|
|
703
|
+
code: "invalid_shard",
|
|
704
|
+
message: "--shard-index and --shard-count must be given together, with the index from 1 to the count.",
|
|
705
|
+
fix: "Use --shard-index 1 --shard-count 4 through --shard-index 4 --shard-count 4."
|
|
706
|
+
})
|
|
707
|
+
);
|
|
708
|
+
exitCode = 3;
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const lifecycle = new ReporterLifecycle();
|
|
712
|
+
const terminalNames = options.reporter.length ? options.reporter.filter(
|
|
713
|
+
(name) => name !== "json" && name !== "markdown" && name !== "junit"
|
|
714
|
+
).map((name) => name === "terminal" ? "list" : name) : ["list"];
|
|
715
|
+
const reporters = [...new Set(terminalNames)].map(
|
|
716
|
+
(name) => createTerminalReporter(name)
|
|
717
|
+
);
|
|
718
|
+
const context = (artifacts) => ({
|
|
719
|
+
stdoutIsTTY: capabilities.stdoutIsTTY,
|
|
720
|
+
color: capabilities.color,
|
|
721
|
+
showCosts: options.costs,
|
|
722
|
+
...paths.length === 1 ? { rerunFile: paths[0] } : {},
|
|
723
|
+
...artifacts,
|
|
724
|
+
includeSharedSummary: true
|
|
725
|
+
});
|
|
726
|
+
const emit = (snapshot, artifacts) => {
|
|
727
|
+
const events = lifecycle.feed(snapshot);
|
|
728
|
+
const lanes = snapshot.execution?.parallel.lanes ?? 1;
|
|
729
|
+
const parallel = lanes > 1 ? {
|
|
730
|
+
parallel: {
|
|
731
|
+
lanes,
|
|
732
|
+
total: snapshot.selectedTestCount ?? snapshot.tests.length,
|
|
733
|
+
retries: options.retries
|
|
734
|
+
}
|
|
735
|
+
} : {};
|
|
736
|
+
for (const event of events)
|
|
737
|
+
for (const [index, reporter] of reporters.entries()) {
|
|
738
|
+
if (event.type === "runStarted" && index > 0) continue;
|
|
739
|
+
const output = reporter.onEvent(event, {
|
|
740
|
+
...context(artifacts),
|
|
741
|
+
...parallel
|
|
742
|
+
});
|
|
743
|
+
if (output) writeOut(output);
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
const execution = await executeRun({
|
|
747
|
+
paths,
|
|
748
|
+
filters: {
|
|
749
|
+
include: options.include,
|
|
750
|
+
exclude: options.exclude,
|
|
751
|
+
labels: options.labels,
|
|
752
|
+
names: options.name
|
|
753
|
+
},
|
|
754
|
+
...options.env ? { environment: options.env } : {},
|
|
755
|
+
...options.browser ? { browser: options.browser } : {},
|
|
756
|
+
...options.urlOverride ? { urlOverride: options.urlOverride } : {},
|
|
757
|
+
...options.outputDir ? { outputDir: options.outputDir } : {},
|
|
758
|
+
...options.reporterDir ? { reporterDir: options.reporterDir } : {},
|
|
759
|
+
reporters: options.reporter,
|
|
760
|
+
strict: options.strict,
|
|
761
|
+
headed: options.headed,
|
|
762
|
+
...options.slow !== void 0 ? { slowMoMs: options.slow } : {},
|
|
763
|
+
retries: options.retries,
|
|
764
|
+
...options.parallel !== void 0 ? { parallel: options.parallel } : {},
|
|
765
|
+
...options.shardIndex !== void 0 && options.shardCount !== void 0 ? {
|
|
766
|
+
shard: {
|
|
767
|
+
index: options.shardIndex,
|
|
768
|
+
count: options.shardCount
|
|
769
|
+
}
|
|
770
|
+
} : {},
|
|
771
|
+
...options.providerConcurrency !== void 0 ? { providerConcurrency: options.providerConcurrency } : {},
|
|
772
|
+
...options.timeoutMinutes !== void 0 ? { timeoutMinutes: options.timeoutMinutes } : {},
|
|
773
|
+
replay: options.replay,
|
|
774
|
+
evidence: options.evidence,
|
|
775
|
+
sensitiveOrigins: options.sensitiveOrigin,
|
|
776
|
+
locatorCacheDisabled: !options.locatorCache,
|
|
777
|
+
locatorCacheCi: options.locatorCacheCi,
|
|
778
|
+
...runtime.signal ? { signal: runtime.signal } : {},
|
|
779
|
+
...runtime.onRunCommitted ? { onCommitted: runtime.onRunCommitted } : {},
|
|
780
|
+
...runtime.onRunDeadline ? { onDeadline: runtime.onRunDeadline } : {},
|
|
781
|
+
onSnapshot: emit
|
|
782
|
+
});
|
|
783
|
+
if (!execution.reporterFailed && reporters.length) {
|
|
784
|
+
try {
|
|
785
|
+
emit(execution.result, execution.artifacts);
|
|
786
|
+
writeOut(
|
|
787
|
+
renderRunSummary(
|
|
788
|
+
execution.result,
|
|
789
|
+
capabilities,
|
|
790
|
+
execution.artifacts,
|
|
791
|
+
options.costs
|
|
792
|
+
)
|
|
793
|
+
);
|
|
794
|
+
for (const [index, reporter] of reporters.entries()) {
|
|
795
|
+
const output = reporter.onResult(execution.result, {
|
|
796
|
+
...context(execution.artifacts),
|
|
797
|
+
includeSharedSummary: index === 0
|
|
798
|
+
});
|
|
799
|
+
if (output) writeOut(output);
|
|
800
|
+
}
|
|
801
|
+
} catch {
|
|
802
|
+
const failure = await execution.onReporterFailure?.();
|
|
803
|
+
writeErr(
|
|
804
|
+
renderDiagnostic(
|
|
805
|
+
failure?.diagnostic ?? {
|
|
806
|
+
code: "reporter_output_error",
|
|
807
|
+
message: "The selected reporter could not write output.",
|
|
808
|
+
fix: "Check terminal output access and rerun the command."
|
|
809
|
+
}
|
|
810
|
+
)
|
|
811
|
+
);
|
|
812
|
+
exitCode = 3;
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (!reporters.length && execution.artifacts.authoritative && execution.artifacts.markdownPath) {
|
|
817
|
+
writeOut(`markdown ${execution.artifacts.markdownPath}
|
|
818
|
+
`);
|
|
819
|
+
if (execution.artifacts.junitPath)
|
|
820
|
+
writeOut(`junit ${execution.artifacts.junitPath}
|
|
821
|
+
`);
|
|
822
|
+
}
|
|
823
|
+
if (execution.diagnostic)
|
|
824
|
+
writeErr(renderDiagnostic(execution.diagnostic));
|
|
825
|
+
exitCode = runExitCode(execution.result, options.strict);
|
|
826
|
+
}
|
|
827
|
+
);
|
|
828
|
+
const cache = program.command("cache").description("manage the local locator cache");
|
|
829
|
+
cache.action(() => commandHelp(cache, writeErr));
|
|
830
|
+
cache.command("clear").description("remove the current worktree's locator cache and digest key").action(async () => {
|
|
831
|
+
const cleared = await clearLocatorCache(process.cwd());
|
|
832
|
+
writeOut(
|
|
833
|
+
cleared ? "Local locator cache cleared.\n" : "No Git checkout locator cache was found.\n"
|
|
834
|
+
);
|
|
835
|
+
exitCode = 0;
|
|
836
|
+
});
|
|
837
|
+
program.command("doctor").description("check whether this environment can run Sedum").option("--json", "print versioned JSON checks on stdout", false).addHelpText(
|
|
838
|
+
"after",
|
|
839
|
+
"\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"
|
|
840
|
+
).action(async (options) => {
|
|
841
|
+
const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-2PMOA32Y.js");
|
|
842
|
+
const result = await executeDoctorCommand(cwd, runtime.doctorProbes);
|
|
843
|
+
writeOut(
|
|
844
|
+
options.json ? `${JSON.stringify(result)}
|
|
845
|
+
` : renderDoctorText(result)
|
|
846
|
+
);
|
|
847
|
+
exitCode = result.checks.every((check) => check.status === "pass") ? 0 : 3;
|
|
848
|
+
});
|
|
849
|
+
program.command("validate").description(
|
|
850
|
+
"check tests and modules without a browser or model key (offline by default)"
|
|
851
|
+
).argument(
|
|
852
|
+
"[paths...]",
|
|
853
|
+
"test files, module files, or directories relative to the project root (default: configured tests)"
|
|
854
|
+
).option(
|
|
855
|
+
"--online",
|
|
856
|
+
"classify sentences the offline cache cannot, using TYPESAFE_API_KEY, and update .sedum/classifications.json",
|
|
857
|
+
false
|
|
858
|
+
).addHelpText(
|
|
859
|
+
"after",
|
|
860
|
+
"\nOffline validation reads only your files and the committed .sedum/classifications.json.\nA sentence it cannot classify is reported as `not checked offline`, never as valid.\n\nExamples:\n sedum validate\n sedum validate tests/login.test.yaml\n sedum validate --online\n\nExit codes:\n 0 every test and module is valid\n 1 invalid content or sentences not checked offline\n 3 invalid config, bad paths, no files found, or the check could not run\n"
|
|
861
|
+
).action(async (paths, options) => {
|
|
862
|
+
const execution = await executeValidateCommand({
|
|
863
|
+
paths,
|
|
864
|
+
online: options.online,
|
|
865
|
+
cwd,
|
|
866
|
+
createProvider: runtime.createClassificationProvider ?? createTypeSafeClassifier,
|
|
867
|
+
...runtime.signal ? { signal: runtime.signal } : {}
|
|
868
|
+
});
|
|
869
|
+
const problems = execution.discovery?.problems ?? [];
|
|
870
|
+
writeErr(renderConfigErrors(execution.configErrors, cwd));
|
|
871
|
+
writeErr(renderProblems(problems));
|
|
872
|
+
if (execution.setup) writeErr(renderDiagnostic(execution.setup));
|
|
873
|
+
if (execution.result && execution.discovery)
|
|
874
|
+
writeOut(
|
|
875
|
+
renderValidation(
|
|
876
|
+
execution.result,
|
|
877
|
+
execution.discovery.root,
|
|
878
|
+
capabilities
|
|
879
|
+
)
|
|
880
|
+
);
|
|
881
|
+
exitCode = validateExitCode(
|
|
882
|
+
execution.result,
|
|
883
|
+
execution.configErrors.length > 0 || problems.length > 0 || execution.setup !== null
|
|
884
|
+
);
|
|
885
|
+
});
|
|
886
|
+
program.command("list").description("list discovered tests with their ids, tags, and paths").argument(
|
|
887
|
+
"[paths...]",
|
|
888
|
+
"test files or directories relative to the project root (default: configured tests)"
|
|
889
|
+
).option("--json", "print a versioned JSON listing on stdout", false).addHelpText(
|
|
890
|
+
"after",
|
|
891
|
+
"\nExamples:\n sedum list\n sedum list tests --json\n\nExit codes:\n 0 listed (including when no tests are found)\n 1 some files could not be listed; run `sedum validate` for details\n 3 invalid config or bad paths\n"
|
|
892
|
+
).action(async (paths, options) => {
|
|
893
|
+
const execution = await executeListCommand({ paths, cwd });
|
|
894
|
+
const problems = execution.discovery?.problems ?? [];
|
|
895
|
+
writeErr(renderConfigErrors(execution.configErrors, cwd));
|
|
896
|
+
writeErr(renderProblems(problems));
|
|
897
|
+
if (execution.listing) {
|
|
898
|
+
if (options.json) writeOut(renderListJson(execution.listing));
|
|
899
|
+
else {
|
|
900
|
+
writeOut(renderListTable(execution.listing));
|
|
901
|
+
writeErr(renderListInvalid(execution.listing));
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
exitCode = listExitCode(
|
|
905
|
+
execution.listing,
|
|
906
|
+
execution.configErrors.length > 0 || problems.length > 0
|
|
907
|
+
);
|
|
908
|
+
});
|
|
909
|
+
const browsers = program.command("browsers").description("manage browser binaries required by Sedum");
|
|
910
|
+
browsers.action(() => commandHelp(browsers, writeErr));
|
|
911
|
+
browsers.command("install").description("install a browser binary").argument("<browser>", "browser to install (currently: chromium)").option(
|
|
912
|
+
"--with-deps",
|
|
913
|
+
"also install supported Linux system dependencies",
|
|
914
|
+
false
|
|
915
|
+
).addHelpText(
|
|
916
|
+
"after",
|
|
917
|
+
"\nExample:\n sedum browsers install chromium --with-deps\n"
|
|
918
|
+
).action(async (browser, options) => {
|
|
919
|
+
if (browser !== "chromium") {
|
|
920
|
+
writeErr(
|
|
921
|
+
`Unsupported browser ${JSON.stringify(browser)}.
|
|
922
|
+
Fix: use \`sedum browsers install chromium\`.
|
|
923
|
+
`
|
|
924
|
+
);
|
|
925
|
+
exitCode = 3;
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
const install = runtime.installChromium ?? (await import("@sedum-dev/core")).installChromium;
|
|
929
|
+
const result = install(options.withDeps);
|
|
930
|
+
if (result.stdout) writeOut(result.stdout);
|
|
931
|
+
if (result.stderr) writeErr(result.stderr);
|
|
932
|
+
if (result.exitCode === 0) exitCode = 0;
|
|
933
|
+
else {
|
|
934
|
+
writeErr(
|
|
935
|
+
"Fix: resolve the installer error above, then rerun `sedum browsers install chromium`.\n"
|
|
936
|
+
);
|
|
937
|
+
exitCode = 3;
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
try {
|
|
941
|
+
await program.parseAsync(["node", "sedum", ...args]);
|
|
942
|
+
} catch (error) {
|
|
943
|
+
if (error instanceof CommanderError) {
|
|
944
|
+
exitCode = error.exitCode === 0 ? 0 : 3;
|
|
945
|
+
if (error.exitCode !== 0)
|
|
946
|
+
writeErr(
|
|
947
|
+
"Fix: correct the command shown above and rerun it, or use `sedum --help`.\n"
|
|
948
|
+
);
|
|
949
|
+
} else {
|
|
950
|
+
writeErr(
|
|
951
|
+
"The command could not be parsed safely.\nFix: run `sedum --help` and correct the command.\n"
|
|
952
|
+
);
|
|
953
|
+
exitCode = 3;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
return { stdout: stdout.join(""), stderr: stderr.join(""), exitCode };
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
export {
|
|
960
|
+
runExitCode,
|
|
961
|
+
renderRunSummary,
|
|
962
|
+
runCli
|
|
963
|
+
};
|