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,1269 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
canonicalDiagnosticError,
|
|
3
|
-
flowDiagnostic,
|
|
4
|
-
openLocatorCache,
|
|
5
|
-
outputDiagnostic,
|
|
6
|
-
planLanes,
|
|
7
|
-
runPool,
|
|
8
|
-
setupDiagnostic
|
|
9
|
-
} from "./chunk-BEV24G7S.js";
|
|
10
|
-
import {
|
|
11
|
-
ProjectConfigError,
|
|
12
|
-
discoverConfiguredTests,
|
|
13
|
-
loadProjectConfig
|
|
14
|
-
} from "./chunk-TZGSCV23.js";
|
|
15
|
-
|
|
16
|
-
// src/run-command.ts
|
|
17
|
-
import {
|
|
18
|
-
FileClassificationCache,
|
|
19
|
-
PlaywrightBrowserDriver,
|
|
20
|
-
ReusableBrowserDriver,
|
|
21
|
-
RunRecorder,
|
|
22
|
-
runFlow,
|
|
23
|
-
safeText,
|
|
24
|
-
validateRunResult as validateRunResult2
|
|
25
|
-
} from "@sedum-dev/core";
|
|
26
|
-
import {
|
|
27
|
-
DEFAULT_PROVIDER_CONCURRENCY,
|
|
28
|
-
ProviderGate,
|
|
29
|
-
TypeSafeAdapter
|
|
30
|
-
} from "@sedum-dev/provider-typesafe";
|
|
31
|
-
import path4 from "path";
|
|
32
|
-
import { availableParallelism } from "os";
|
|
33
|
-
import { randomBytes, randomUUID } from "crypto";
|
|
34
|
-
|
|
35
|
-
// src/progress-writer.ts
|
|
36
|
-
import { open, mkdir, rename, unlink, lstat, readFile } from "fs/promises";
|
|
37
|
-
import { createHash } from "crypto";
|
|
38
|
-
import path from "path";
|
|
39
|
-
import { validateRunResult } from "@sedum-dev/core";
|
|
40
|
-
import {
|
|
41
|
-
renderHtml,
|
|
42
|
-
renderJunit,
|
|
43
|
-
renderMarkdown
|
|
44
|
-
} from "@sedum-dev/reporters";
|
|
45
|
-
var ProgressWriterError = class extends Error {
|
|
46
|
-
constructor(path5, options) {
|
|
47
|
-
super(`Could not write run output at ${path5}.`, options);
|
|
48
|
-
this.path = path5;
|
|
49
|
-
this.name = "ProgressWriterError";
|
|
50
|
-
}
|
|
51
|
-
path;
|
|
52
|
-
};
|
|
53
|
-
var ProgressWriter = class _ProgressWriter {
|
|
54
|
-
constructor(directory, files) {
|
|
55
|
-
this.directory = directory;
|
|
56
|
-
this.files = files;
|
|
57
|
-
}
|
|
58
|
-
directory;
|
|
59
|
-
revision = 0;
|
|
60
|
-
pending = Promise.resolve();
|
|
61
|
-
queued = null;
|
|
62
|
-
draining = null;
|
|
63
|
-
attemptFolders = /* @__PURE__ */ new Map();
|
|
64
|
-
files;
|
|
65
|
-
static async create(root, runId, outputDirectory = path.join(root, ".sedum", "runs"), files = {}) {
|
|
66
|
-
if (!/^[a-zA-Z0-9-]+$/.test(runId)) throw new Error("Invalid run ID");
|
|
67
|
-
const resolvedRoot = path.resolve(root);
|
|
68
|
-
const base = path.resolve(outputDirectory);
|
|
69
|
-
const relation = path.relative(resolvedRoot, base);
|
|
70
|
-
if (relation === ".." || relation.startsWith(`..${path.sep}`))
|
|
71
|
-
throw new Error("Run output path escapes the project root");
|
|
72
|
-
let part = resolvedRoot;
|
|
73
|
-
for (const segment of relation.split(path.sep).filter(Boolean)) {
|
|
74
|
-
part = path.join(part, segment);
|
|
75
|
-
await mkdir(part, { mode: 448 }).catch((error) => {
|
|
76
|
-
if (error.code !== "EEXIST") throw error;
|
|
77
|
-
});
|
|
78
|
-
const info = await lstat(part);
|
|
79
|
-
if (!info.isDirectory() || info.isSymbolicLink())
|
|
80
|
-
throw new Error("Run output parent is not a directory");
|
|
81
|
-
}
|
|
82
|
-
const directory = path.join(base, runId);
|
|
83
|
-
await mkdir(directory, { mode: 448 });
|
|
84
|
-
return new _ProgressWriter(directory, {
|
|
85
|
-
json: true,
|
|
86
|
-
html: true,
|
|
87
|
-
markdown: false,
|
|
88
|
-
junit: null,
|
|
89
|
-
...files
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
get includeMarkdown() {
|
|
93
|
-
return this.files.markdown;
|
|
94
|
-
}
|
|
95
|
-
get includesJson() {
|
|
96
|
-
return this.files.json;
|
|
97
|
-
}
|
|
98
|
-
get includesJunit() {
|
|
99
|
-
return this.files.junit !== null;
|
|
100
|
-
}
|
|
101
|
-
/** Add `junit.xml`, once the evidence location is known. */
|
|
102
|
-
includeJunit(options) {
|
|
103
|
-
this.files = { ...this.files, junit: options };
|
|
104
|
-
}
|
|
105
|
-
get progressPath() {
|
|
106
|
-
return path.join(this.directory, "progress.json");
|
|
107
|
-
}
|
|
108
|
-
get resultPath() {
|
|
109
|
-
return path.join(this.directory, "result.json");
|
|
110
|
-
}
|
|
111
|
-
get htmlPath() {
|
|
112
|
-
return path.join(this.directory, "report.html");
|
|
113
|
-
}
|
|
114
|
-
get markdownPath() {
|
|
115
|
-
return path.join(this.directory, "report.md");
|
|
116
|
-
}
|
|
117
|
-
get junitPath() {
|
|
118
|
-
return path.join(this.directory, "junit.xml");
|
|
119
|
-
}
|
|
120
|
-
async atomicWrite(name, content) {
|
|
121
|
-
const target = path.join(this.directory, name);
|
|
122
|
-
const temporary = path.join(
|
|
123
|
-
this.directory,
|
|
124
|
-
`.${name}.${++this.revision}.tmp`
|
|
125
|
-
);
|
|
126
|
-
const handle = await open(temporary, "wx", 384);
|
|
127
|
-
try {
|
|
128
|
-
await handle.writeFile(content);
|
|
129
|
-
await handle.sync();
|
|
130
|
-
} catch (error) {
|
|
131
|
-
await handle.close().catch(() => void 0);
|
|
132
|
-
await unlink(temporary).catch(() => void 0);
|
|
133
|
-
throw error;
|
|
134
|
-
} finally {
|
|
135
|
-
await handle.close().catch(() => void 0);
|
|
136
|
-
}
|
|
137
|
-
try {
|
|
138
|
-
const existing = await lstat(target).catch(() => null);
|
|
139
|
-
if (existing?.isSymbolicLink())
|
|
140
|
-
throw new Error("Output path is a symlink");
|
|
141
|
-
await rename(temporary, target);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
await unlink(temporary).catch(() => void 0);
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Parallel lanes publish many snapshots at once. Writes stay serialized and
|
|
149
|
-
* monotonic, but snapshots that queue behind an in-flight write collapse to
|
|
150
|
-
* the newest one, so each step does not cost its own fsync. A failed write
|
|
151
|
-
* stays failed for every later write.
|
|
152
|
-
*/
|
|
153
|
-
write(result) {
|
|
154
|
-
const snapshot = validateRunResult(result);
|
|
155
|
-
this.queued = `${JSON.stringify(snapshot, null, 2)}
|
|
156
|
-
`;
|
|
157
|
-
this.draining ??= this.drain();
|
|
158
|
-
return this.draining.catch((cause) => {
|
|
159
|
-
throw cause instanceof ProgressWriterError ? cause : new ProgressWriterError(this.progressPath, { cause });
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
async drain() {
|
|
163
|
-
try {
|
|
164
|
-
await this.pending;
|
|
165
|
-
while (this.queued !== null) {
|
|
166
|
-
const content = this.queued;
|
|
167
|
-
this.queued = null;
|
|
168
|
-
this.pending = this.atomicWrite("progress.json", content);
|
|
169
|
-
await this.pending;
|
|
170
|
-
}
|
|
171
|
-
} finally {
|
|
172
|
-
this.draining = null;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Write this writer's files from one validated snapshot: JSON first, then
|
|
177
|
-
* the rendered reports. `reports: false` rewrites only the JSON, and
|
|
178
|
-
* `json: false` renders only the reports.
|
|
179
|
-
*/
|
|
180
|
-
async finish(result, only = {}) {
|
|
181
|
-
const json = this.files.json && only.json !== false;
|
|
182
|
-
const reports = only.reports !== false;
|
|
183
|
-
try {
|
|
184
|
-
const snapshot = validateRunResult(result);
|
|
185
|
-
if (json) {
|
|
186
|
-
await this.write(snapshot);
|
|
187
|
-
await this.atomicWrite(
|
|
188
|
-
"result.json",
|
|
189
|
-
`${JSON.stringify(snapshot, null, 2)}
|
|
190
|
-
`
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
if (!reports) return;
|
|
194
|
-
if (this.files.html) {
|
|
195
|
-
try {
|
|
196
|
-
const frames = await this.loadReplayFrames(snapshot);
|
|
197
|
-
await this.atomicWrite(
|
|
198
|
-
"report.html",
|
|
199
|
-
renderHtml(snapshot, frames ? { replayFrames: frames } : {})
|
|
200
|
-
);
|
|
201
|
-
} catch (cause) {
|
|
202
|
-
throw new ProgressWriterError(this.htmlPath, { cause });
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (this.files.markdown) {
|
|
206
|
-
try {
|
|
207
|
-
await this.atomicWrite("report.md", renderMarkdown(snapshot));
|
|
208
|
-
} catch (cause) {
|
|
209
|
-
throw new ProgressWriterError(this.markdownPath, { cause });
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
const junit = this.files.junit;
|
|
213
|
-
if (junit) {
|
|
214
|
-
try {
|
|
215
|
-
await this.atomicWrite("junit.xml", renderJunit(snapshot, junit));
|
|
216
|
-
} catch (cause) {
|
|
217
|
-
throw new ProgressWriterError(this.junitPath, { cause });
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
} catch (cause) {
|
|
221
|
-
throw cause instanceof ProgressWriterError ? cause : new ProgressWriterError(this.resultPath, { cause });
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/** Whether `path` is one of this writer's rendered reports. */
|
|
225
|
-
isReport(target) {
|
|
226
|
-
return [this.htmlPath, this.markdownPath, this.junitPath].includes(target);
|
|
227
|
-
}
|
|
228
|
-
/** Remove this writer's own rendered reports after one of them failed. */
|
|
229
|
-
async removeReports() {
|
|
230
|
-
for (const report of [this.htmlPath, this.markdownPath, this.junitPath])
|
|
231
|
-
await unlink(report).catch((error) => {
|
|
232
|
-
if (error.code !== "ENOENT") throw error;
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
/** Remove only this writer's non-authoritative result files after sink failure. */
|
|
236
|
-
async invalidate() {
|
|
237
|
-
await Promise.all([
|
|
238
|
-
unlink(this.progressPath).catch(() => void 0),
|
|
239
|
-
unlink(this.resultPath).catch(() => void 0),
|
|
240
|
-
unlink(this.htmlPath).catch(() => void 0),
|
|
241
|
-
unlink(this.markdownPath).catch(() => void 0),
|
|
242
|
-
unlink(this.junitPath).catch(() => void 0)
|
|
243
|
-
]);
|
|
244
|
-
}
|
|
245
|
-
async loadReplayFrames(result) {
|
|
246
|
-
const paths = result.tests.flatMap(
|
|
247
|
-
(test) => test.attempts.flatMap(
|
|
248
|
-
(attempt) => attempt.steps.flatMap(
|
|
249
|
-
(step) => step.replayFrame?.status === "captured" ? [step.replayFrame.path] : []
|
|
250
|
-
)
|
|
251
|
-
)
|
|
252
|
-
);
|
|
253
|
-
const hasReplay = result.tests.some(
|
|
254
|
-
(test) => test.attempts.some(
|
|
255
|
-
(attempt) => attempt.steps.some((step) => step.replayFrame !== null)
|
|
256
|
-
)
|
|
257
|
-
);
|
|
258
|
-
if (!hasReplay) return void 0;
|
|
259
|
-
const frames = /* @__PURE__ */ new Map();
|
|
260
|
-
for (const relative of new Set(paths)) {
|
|
261
|
-
try {
|
|
262
|
-
let current = this.directory;
|
|
263
|
-
const segments = relative.split("/");
|
|
264
|
-
for (const [index, segment] of segments.entries()) {
|
|
265
|
-
current = path.join(current, segment);
|
|
266
|
-
const info = await lstat(current);
|
|
267
|
-
if (info.isSymbolicLink() || (index < segments.length - 1 ? !info.isDirectory() : !info.isFile()))
|
|
268
|
-
throw new Error("Unsafe frame path");
|
|
269
|
-
if (index === segments.length - 1 && info.size > 5 * 1024 * 1024)
|
|
270
|
-
throw new Error("Frame exceeds capture limit");
|
|
271
|
-
}
|
|
272
|
-
const bytes = await readFile(current);
|
|
273
|
-
if (bytes.length > 5 * 1024 * 1024 || bytes.length < 4 || bytes[0] !== 255 || bytes[1] !== 216 || bytes[bytes.length - 2] !== 255 || bytes[bytes.length - 1] !== 217)
|
|
274
|
-
throw new Error("Invalid JPEG frame");
|
|
275
|
-
frames.set(relative, bytes.toString("base64"));
|
|
276
|
-
} catch {
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return frames;
|
|
280
|
-
}
|
|
281
|
-
/** Each attempt gets one new folder, so retries and parallel runs never share a frame file. */
|
|
282
|
-
attemptFolder(attempt) {
|
|
283
|
-
const existing = this.attemptFolders.get(attempt.id);
|
|
284
|
-
if (existing) return existing;
|
|
285
|
-
const created = (async () => {
|
|
286
|
-
const evidence = path.join(this.directory, "evidence");
|
|
287
|
-
await mkdir(evidence, { mode: 448 }).catch((error) => {
|
|
288
|
-
if (error.code !== "EEXIST") throw error;
|
|
289
|
-
});
|
|
290
|
-
const evidenceInfo = await lstat(evidence);
|
|
291
|
-
if (!evidenceInfo.isDirectory() || evidenceInfo.isSymbolicLink())
|
|
292
|
-
throw new Error("Evidence output path is not a directory");
|
|
293
|
-
const name = `a${attempt.ordinal}-${createHash("sha256").update(attempt.id).digest("hex").slice(0, 12)}`;
|
|
294
|
-
await mkdir(path.join(evidence, name), { mode: 448 });
|
|
295
|
-
return `evidence/${name}`;
|
|
296
|
-
})();
|
|
297
|
-
this.attemptFolders.set(attempt.id, created);
|
|
298
|
-
return created;
|
|
299
|
-
}
|
|
300
|
-
async saveFrame(attempt, frameId, bytes) {
|
|
301
|
-
if (bytes.byteLength === 0 || bytes.byteLength > 5 * 1024 * 1024)
|
|
302
|
-
return { status: "unavailable", reason: "frame_size" };
|
|
303
|
-
const folder = await this.attemptFolder(attempt);
|
|
304
|
-
const name = `${createHash("sha256").update(frameId).digest("hex").slice(0, 24)}.jpg`;
|
|
305
|
-
const relative = `${folder}/${name}`;
|
|
306
|
-
const target = path.join(this.directory, relative);
|
|
307
|
-
const handle = await open(target, "wx", 384);
|
|
308
|
-
try {
|
|
309
|
-
await handle.writeFile(bytes);
|
|
310
|
-
await handle.sync();
|
|
311
|
-
} catch (error) {
|
|
312
|
-
await handle.close().catch(() => void 0);
|
|
313
|
-
await unlink(target).catch(() => void 0);
|
|
314
|
-
throw error;
|
|
315
|
-
} finally {
|
|
316
|
-
await handle.close().catch(() => void 0);
|
|
317
|
-
}
|
|
318
|
-
return {
|
|
319
|
-
status: "captured",
|
|
320
|
-
path: relative,
|
|
321
|
-
mediaType: "image/jpeg"
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
// src/evidence-root.ts
|
|
327
|
-
import { realpath } from "fs/promises";
|
|
328
|
-
import path2 from "path";
|
|
329
|
-
import { isEvidenceDirectory } from "@sedum-dev/reporters";
|
|
330
|
-
var CI_ROOTS = [
|
|
331
|
-
{ root: "CI_PROJECT_DIR", running: (env) => env.GITLAB_CI === "true" },
|
|
332
|
-
{ root: "WORKSPACE", running: (env) => Boolean(env.JENKINS_URL) },
|
|
333
|
-
{
|
|
334
|
-
root: "GITHUB_WORKSPACE",
|
|
335
|
-
running: (env) => env.GITHUB_ACTIONS === "true"
|
|
336
|
-
}
|
|
337
|
-
];
|
|
338
|
-
async function relativeInside(base, target) {
|
|
339
|
-
let real;
|
|
340
|
-
try {
|
|
341
|
-
real = await realpath(base);
|
|
342
|
-
} catch {
|
|
343
|
-
return null;
|
|
344
|
-
}
|
|
345
|
-
const relative = path2.relative(real, target);
|
|
346
|
-
if (!relative || relative === ".." || relative.startsWith(`..${path2.sep}`) || path2.isAbsolute(relative))
|
|
347
|
-
return null;
|
|
348
|
-
return relative.split(path2.sep).join("/");
|
|
349
|
-
}
|
|
350
|
-
async function junitEvidenceDirectory(runDirectory, projectRoot, env) {
|
|
351
|
-
let run;
|
|
352
|
-
try {
|
|
353
|
-
run = await realpath(runDirectory);
|
|
354
|
-
} catch {
|
|
355
|
-
return null;
|
|
356
|
-
}
|
|
357
|
-
for (const { root, running } of CI_ROOTS) {
|
|
358
|
-
const value = env[root];
|
|
359
|
-
if (!value || !path2.isAbsolute(value) || !running(env)) continue;
|
|
360
|
-
const relative2 = await relativeInside(value, run);
|
|
361
|
-
if (relative2) return isEvidenceDirectory(relative2) ? relative2 : null;
|
|
362
|
-
}
|
|
363
|
-
const relative = await relativeInside(projectRoot, run);
|
|
364
|
-
return relative && isEvidenceDirectory(relative) ? relative : null;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// src/run-selection.ts
|
|
368
|
-
import { lstat as lstat2, realpath as realpath2 } from "fs/promises";
|
|
369
|
-
import path3 from "path";
|
|
370
|
-
import { minimatch } from "minimatch";
|
|
371
|
-
import {
|
|
372
|
-
listTests,
|
|
373
|
-
loadFlowFile,
|
|
374
|
-
walkSuiteFiles
|
|
375
|
-
} from "@sedum-dev/core";
|
|
376
|
-
function contained(root, target) {
|
|
377
|
-
const relative = path3.relative(root, target);
|
|
378
|
-
return relative === "" || relative !== ".." && !relative.startsWith(`..${path3.sep}`) && !path3.isAbsolute(relative);
|
|
379
|
-
}
|
|
380
|
-
function selectRunTests(tests, filters) {
|
|
381
|
-
const includes = filters.include ?? [];
|
|
382
|
-
const excludes = filters.exclude ?? [];
|
|
383
|
-
const labels = filters.labels ?? [];
|
|
384
|
-
const names = filters.names ?? [];
|
|
385
|
-
return tests.filter(
|
|
386
|
-
(test) => (includes.length === 0 || includes.some((glob) => minimatch(test.file, glob))) && !excludes.some((glob) => minimatch(test.file, glob)) && labels.every((label) => test.tags.includes(label)) && (names.length === 0 || names.some(
|
|
387
|
-
(name) => `${test.id}
|
|
388
|
-
${test.description ?? ""}`.toLowerCase().includes(name.toLowerCase())
|
|
389
|
-
))
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
async function discoverRunTests(config, paths, filters = {}) {
|
|
393
|
-
const problems = [];
|
|
394
|
-
const files = /* @__PURE__ */ new Set();
|
|
395
|
-
const root = await realpath2(config.projectRoot);
|
|
396
|
-
if (paths.length === 0) {
|
|
397
|
-
for (const file of await discoverConfiguredTests(config)) {
|
|
398
|
-
const target = await realpath2(file);
|
|
399
|
-
if (contained(root, target)) files.add(target);
|
|
400
|
-
else
|
|
401
|
-
problems.push({
|
|
402
|
-
file: "<outside-project>",
|
|
403
|
-
code: "outside_root",
|
|
404
|
-
message: "A configured test is outside the project root.",
|
|
405
|
-
fix: "Keep the test directory inside the project."
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
} else {
|
|
409
|
-
for (const requested of paths) {
|
|
410
|
-
const candidate = path3.resolve(config.projectRoot, requested);
|
|
411
|
-
const namedInside = contained(config.projectRoot, candidate);
|
|
412
|
-
const file = namedInside ? path3.relative(config.projectRoot, candidate).split(path3.sep).join("/") : "<outside-project>";
|
|
413
|
-
if (!namedInside) {
|
|
414
|
-
problems.push({
|
|
415
|
-
file,
|
|
416
|
-
code: "outside_root",
|
|
417
|
-
message: "Path is outside the project root.",
|
|
418
|
-
fix: "Choose a path inside the project."
|
|
419
|
-
});
|
|
420
|
-
continue;
|
|
421
|
-
}
|
|
422
|
-
let info;
|
|
423
|
-
try {
|
|
424
|
-
info = await lstat2(candidate);
|
|
425
|
-
} catch {
|
|
426
|
-
problems.push({
|
|
427
|
-
file,
|
|
428
|
-
code: "missing_path",
|
|
429
|
-
message: "Path does not exist.",
|
|
430
|
-
fix: "Check the path and rerun."
|
|
431
|
-
});
|
|
432
|
-
continue;
|
|
433
|
-
}
|
|
434
|
-
if (info.isSymbolicLink()) {
|
|
435
|
-
problems.push({
|
|
436
|
-
file,
|
|
437
|
-
code: "symlinked_path",
|
|
438
|
-
message: "Symlinked test paths are not supported.",
|
|
439
|
-
fix: "Name the regular file."
|
|
440
|
-
});
|
|
441
|
-
continue;
|
|
442
|
-
}
|
|
443
|
-
const target = await realpath2(candidate).catch(() => candidate);
|
|
444
|
-
if (!contained(root, target)) {
|
|
445
|
-
problems.push({
|
|
446
|
-
file,
|
|
447
|
-
code: "outside_root",
|
|
448
|
-
message: "Path is outside the project root.",
|
|
449
|
-
fix: "Choose a path inside the project."
|
|
450
|
-
});
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
if (info.isDirectory()) {
|
|
454
|
-
for (const file2 of await walkSuiteFiles(
|
|
455
|
-
target,
|
|
456
|
-
[".test.yaml"],
|
|
457
|
-
(folder) => {
|
|
458
|
-
problems.push({
|
|
459
|
-
file: path3.relative(root, folder),
|
|
460
|
-
code: "unreadable_directory",
|
|
461
|
-
message: "Directory could not be read.",
|
|
462
|
-
fix: "Check permissions."
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
))
|
|
466
|
-
files.add(file2);
|
|
467
|
-
} else if (info.isFile() && candidate.endsWith(".test.yaml"))
|
|
468
|
-
files.add(target);
|
|
469
|
-
else
|
|
470
|
-
problems.push({
|
|
471
|
-
file,
|
|
472
|
-
code: "unsupported_file",
|
|
473
|
-
message: "Expected a *.test.yaml file or directory.",
|
|
474
|
-
fix: "Choose a test path."
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
const parsed = [];
|
|
479
|
-
for (const file of [...files].sort()) {
|
|
480
|
-
parsed.push({
|
|
481
|
-
file,
|
|
482
|
-
result: await loadFlowFile(file, {
|
|
483
|
-
repoRoot: root,
|
|
484
|
-
rejectSymlinks: true
|
|
485
|
-
})
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
const listing = listTests(parsed, { repoRoot: root });
|
|
489
|
-
return {
|
|
490
|
-
tests: selectRunTests(listing.tests, filters),
|
|
491
|
-
invalid: listing.invalid,
|
|
492
|
-
problems
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// src/run-shard.ts
|
|
497
|
-
import { createHash as createHash2 } from "crypto";
|
|
498
|
-
function hashKey(key) {
|
|
499
|
-
return createHash2("sha1").update(key).digest("hex");
|
|
500
|
-
}
|
|
501
|
-
function shardItems(items, keyOf, shard) {
|
|
502
|
-
const { index, count } = shard;
|
|
503
|
-
if (!Number.isSafeInteger(count) || count < 1)
|
|
504
|
-
throw new RangeError("Shard count must be a positive integer");
|
|
505
|
-
if (!Number.isSafeInteger(index) || index < 1 || index > count)
|
|
506
|
-
throw new RangeError("Shard index must be between 1 and the shard count");
|
|
507
|
-
const ordered = items.map((item) => ({ item, key: keyOf(item) })).map((entry) => ({ ...entry, hash: hashKey(entry.key) })).sort(
|
|
508
|
-
(a, b) => a.hash < b.hash ? -1 : a.hash > b.hash ? 1 : a.key < b.key ? -1 : a.key > b.key ? 1 : 0
|
|
509
|
-
);
|
|
510
|
-
const start = Math.floor((index - 1) * ordered.length / count);
|
|
511
|
-
const end = Math.floor(index * ordered.length / count);
|
|
512
|
-
return ordered.slice(start, end).map((entry) => entry.item);
|
|
513
|
-
}
|
|
514
|
-
function shardTests(tests, shard) {
|
|
515
|
-
return shardItems(tests, (test) => test.id, shard);
|
|
516
|
-
}
|
|
517
|
-
function shardProblems(problems, shard) {
|
|
518
|
-
const files = [...new Set(problems.map((problem) => problem.file))];
|
|
519
|
-
const owned = new Set(shardItems(files, (file) => file, shard));
|
|
520
|
-
return problems.filter((problem) => owned.has(problem.file));
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// src/run-command.ts
|
|
524
|
-
var ReporterOutputError = class extends Error {
|
|
525
|
-
};
|
|
526
|
-
var SUPPORTED_REPORTERS = [
|
|
527
|
-
"terminal",
|
|
528
|
-
"json",
|
|
529
|
-
"list",
|
|
530
|
-
"steps",
|
|
531
|
-
"markdown",
|
|
532
|
-
"junit"
|
|
533
|
-
];
|
|
534
|
-
function safeDiscoveryText(value, config) {
|
|
535
|
-
const withoutUrls = value.replace(/https?:\/\/[^\s`"'<>]+/giu, "[URL]");
|
|
536
|
-
return safeText(
|
|
537
|
-
withoutUrls,
|
|
538
|
-
{
|
|
539
|
-
secretValues: Object.values(config.variables).filter(
|
|
540
|
-
(entry) => typeof entry === "string" && entry.length >= 4
|
|
541
|
-
)
|
|
542
|
-
},
|
|
543
|
-
512
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
function terminalOutputFailure(source, diagnostic, keepExisting = false) {
|
|
547
|
-
if (keepExisting && source.error !== null && source.state !== "running")
|
|
548
|
-
return source;
|
|
549
|
-
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
550
|
-
return validateRunResult2({
|
|
551
|
-
...source,
|
|
552
|
-
state: "error",
|
|
553
|
-
verdict: null,
|
|
554
|
-
error: canonicalDiagnosticError(diagnostic),
|
|
555
|
-
updatedAt: at,
|
|
556
|
-
finishedAt: at
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
function reportSelection(options) {
|
|
560
|
-
const reporters = options.reporters ?? [];
|
|
561
|
-
return {
|
|
562
|
-
json: Boolean(options.reporterDir) || reporters.includes("json"),
|
|
563
|
-
markdown: reporters.includes("markdown"),
|
|
564
|
-
junit: reporters.includes("junit")
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
async function openReportCopy(root, runId, canonical, outputDir, reporterDir, selection, strict) {
|
|
568
|
-
const junit = selection.junit ? {
|
|
569
|
-
strict,
|
|
570
|
-
evidenceDirectory: await junitEvidenceDirectory(
|
|
571
|
-
canonical.directory,
|
|
572
|
-
root,
|
|
573
|
-
process.env
|
|
574
|
-
)
|
|
575
|
-
} : null;
|
|
576
|
-
if (path4.resolve(reporterDir) === path4.resolve(outputDir)) {
|
|
577
|
-
if (junit) canonical.includeJunit(junit);
|
|
578
|
-
return void 0;
|
|
579
|
-
}
|
|
580
|
-
if (!selection.json && !junit) return void 0;
|
|
581
|
-
return ProgressWriter.create(root, runId, reporterDir, {
|
|
582
|
-
json: selection.json,
|
|
583
|
-
html: false,
|
|
584
|
-
junit
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
function reportFormat(target) {
|
|
588
|
-
const name = path4.basename(target);
|
|
589
|
-
return name === "report.html" ? "HTML" : name === "report.md" ? "Markdown" : "JUnit";
|
|
590
|
-
}
|
|
591
|
-
async function finishRun(canonical, copy, result, recordCopyFailure) {
|
|
592
|
-
let current = result;
|
|
593
|
-
let diagnostic = null;
|
|
594
|
-
let copyAvailable = copy !== void 0;
|
|
595
|
-
if (copy?.includesJson) {
|
|
596
|
-
try {
|
|
597
|
-
await copy.finish(current, { reports: false });
|
|
598
|
-
} catch {
|
|
599
|
-
diagnostic = outputDiagnostic(copy.resultPath);
|
|
600
|
-
copyAvailable = false;
|
|
601
|
-
await copy.invalidate().catch(() => void 0);
|
|
602
|
-
current = await recordCopyFailure(diagnostic);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
try {
|
|
606
|
-
await canonical.finish(current);
|
|
607
|
-
if (copy && copyAvailable && copy.includesJunit)
|
|
608
|
-
await copy.finish(current, { json: false });
|
|
609
|
-
return {
|
|
610
|
-
result: current,
|
|
611
|
-
diagnostic,
|
|
612
|
-
reportsAvailable: true,
|
|
613
|
-
copyAvailable
|
|
614
|
-
};
|
|
615
|
-
} catch (error) {
|
|
616
|
-
if (!(error instanceof ProgressWriterError) || !(canonical.isReport(error.path) || copy && copyAvailable && copy.isReport(error.path)))
|
|
617
|
-
throw error;
|
|
618
|
-
const failure = {
|
|
619
|
-
code: "reporter_output_error",
|
|
620
|
-
message: `The ${reportFormat(error.path)} report could not be written to ${error.path}.`,
|
|
621
|
-
fix: "Check the run output directory and rerun the command."
|
|
622
|
-
};
|
|
623
|
-
const failed = terminalOutputFailure(current, failure, true);
|
|
624
|
-
await canonical.removeReports();
|
|
625
|
-
if (copy && copyAvailable)
|
|
626
|
-
try {
|
|
627
|
-
await copy.removeReports();
|
|
628
|
-
if (copy.includesJson) await copy.finish(failed, { reports: false });
|
|
629
|
-
} catch {
|
|
630
|
-
copyAvailable = false;
|
|
631
|
-
await copy.invalidate().catch(() => void 0);
|
|
632
|
-
}
|
|
633
|
-
await canonical.finish(failed, { reports: false });
|
|
634
|
-
return {
|
|
635
|
-
result: failed,
|
|
636
|
-
diagnostic: failure,
|
|
637
|
-
reportsAvailable: false,
|
|
638
|
-
copyAvailable
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
function finishedArtifacts(canonical, copy, selection, finished) {
|
|
643
|
-
const junit = canonical.includesJunit ? canonical : copy?.includesJunit && finished.copyAvailable ? copy : void 0;
|
|
644
|
-
const json = copy?.includesJson ? finished.copyAvailable ? copy : void 0 : canonical;
|
|
645
|
-
return {
|
|
646
|
-
progressPath: canonical.progressPath,
|
|
647
|
-
resultPath: canonical.resultPath,
|
|
648
|
-
...finished.reportsAvailable ? {
|
|
649
|
-
htmlPath: canonical.htmlPath,
|
|
650
|
-
...canonical.includeMarkdown ? { markdownPath: canonical.markdownPath } : {},
|
|
651
|
-
...junit ? { junitPath: junit.junitPath } : {}
|
|
652
|
-
} : {},
|
|
653
|
-
...selection.json && json ? { reporterPath: json.resultPath } : {},
|
|
654
|
-
authoritative: true
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
async function resultWithoutSink(runId, diagnostic) {
|
|
658
|
-
const recorder = new RunRecorder(async () => void 0, runId);
|
|
659
|
-
await recorder.start();
|
|
660
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
661
|
-
return recorder.snapshot;
|
|
662
|
-
}
|
|
663
|
-
async function preExecutionFailure(root, runId, outputDir, reporterDir, selection, strict, diagnostic, commit) {
|
|
664
|
-
const base = outputDir ?? path4.join(root, ".sedum", "runs");
|
|
665
|
-
const intended = path4.join(base, runId);
|
|
666
|
-
let writer;
|
|
667
|
-
try {
|
|
668
|
-
writer = await ProgressWriter.create(root, runId, base, {
|
|
669
|
-
markdown: selection.markdown
|
|
670
|
-
});
|
|
671
|
-
} catch {
|
|
672
|
-
commit();
|
|
673
|
-
return {
|
|
674
|
-
result: await resultWithoutSink(runId, diagnostic),
|
|
675
|
-
artifacts: {
|
|
676
|
-
progressPath: path4.join(intended, "progress.json"),
|
|
677
|
-
resultPath: path4.join(intended, "result.json"),
|
|
678
|
-
authoritative: false
|
|
679
|
-
},
|
|
680
|
-
diagnostic
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
const copy = await openReportCopy(
|
|
684
|
-
root,
|
|
685
|
-
runId,
|
|
686
|
-
writer,
|
|
687
|
-
base,
|
|
688
|
-
reporterDir,
|
|
689
|
-
selection,
|
|
690
|
-
strict
|
|
691
|
-
).catch(() => void 0);
|
|
692
|
-
const recorder = new RunRecorder((snapshot) => writer.write(snapshot), runId);
|
|
693
|
-
try {
|
|
694
|
-
await recorder.start();
|
|
695
|
-
commit();
|
|
696
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
697
|
-
const finished = await finishRun(
|
|
698
|
-
writer,
|
|
699
|
-
copy,
|
|
700
|
-
recorder.snapshot,
|
|
701
|
-
async () => recorder.snapshot
|
|
702
|
-
);
|
|
703
|
-
return {
|
|
704
|
-
result: finished.result,
|
|
705
|
-
artifacts: finishedArtifacts(writer, copy, selection, finished),
|
|
706
|
-
diagnostic: finished.diagnostic ?? diagnostic
|
|
707
|
-
};
|
|
708
|
-
} catch {
|
|
709
|
-
commit();
|
|
710
|
-
await writer.invalidate();
|
|
711
|
-
await copy?.invalidate();
|
|
712
|
-
return {
|
|
713
|
-
result: await resultWithoutSink(runId, diagnostic),
|
|
714
|
-
artifacts: {
|
|
715
|
-
progressPath: writer.progressPath,
|
|
716
|
-
resultPath: writer.resultPath,
|
|
717
|
-
authoritative: false
|
|
718
|
-
},
|
|
719
|
-
diagnostic
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
async function executeRunCommand(options) {
|
|
724
|
-
const invocationRoot = process.cwd();
|
|
725
|
-
const reportFiles = reportSelection(options);
|
|
726
|
-
const runId = randomUUID();
|
|
727
|
-
let committed = false;
|
|
728
|
-
const commit = () => {
|
|
729
|
-
if (committed) return;
|
|
730
|
-
committed = true;
|
|
731
|
-
options.onCommitted?.();
|
|
732
|
-
};
|
|
733
|
-
let config;
|
|
734
|
-
try {
|
|
735
|
-
if (options.browser && options.browser !== "chrome" && options.browser !== "chromium")
|
|
736
|
-
throw new ProjectConfigError([
|
|
737
|
-
{
|
|
738
|
-
code: "invalid_browser",
|
|
739
|
-
file: path4.join(invocationRoot, "sedum.config.yaml"),
|
|
740
|
-
line: 1,
|
|
741
|
-
col: 1,
|
|
742
|
-
key: "browser",
|
|
743
|
-
message: "Browser must be chrome or chromium.",
|
|
744
|
-
fix: "Use --browser chrome or --browser chromium."
|
|
745
|
-
}
|
|
746
|
-
]);
|
|
747
|
-
if (options.urlOverride) {
|
|
748
|
-
let valid = false;
|
|
749
|
-
try {
|
|
750
|
-
const url = new URL(options.urlOverride);
|
|
751
|
-
valid = ["http:", "https:"].includes(url.protocol) && !url.username && !url.password;
|
|
752
|
-
} catch {
|
|
753
|
-
}
|
|
754
|
-
if (!valid)
|
|
755
|
-
throw new ProjectConfigError([
|
|
756
|
-
{
|
|
757
|
-
code: "invalid_url_override",
|
|
758
|
-
file: path4.join(invocationRoot, "sedum.config.yaml"),
|
|
759
|
-
line: 1,
|
|
760
|
-
col: 1,
|
|
761
|
-
key: "urlOverride",
|
|
762
|
-
message: "The URL override must be an absolute HTTP(S) URL without credentials.",
|
|
763
|
-
fix: "Use --url-override https://preview.example.com."
|
|
764
|
-
}
|
|
765
|
-
]);
|
|
766
|
-
}
|
|
767
|
-
config = await loadProjectConfig(invocationRoot, process.env, {
|
|
768
|
-
...options.environment ? { environment: options.environment } : {},
|
|
769
|
-
...options.browser ? { browser: options.browser } : {},
|
|
770
|
-
...options.outputDir ? { outputDir: options.outputDir } : {},
|
|
771
|
-
...options.reporterDir ? { reporterDir: options.reporterDir } : {}
|
|
772
|
-
});
|
|
773
|
-
} catch (error) {
|
|
774
|
-
const diagnostic = setupDiagnostic(error);
|
|
775
|
-
const fallbackRoot = error instanceof ProjectConfigError && error.diagnostics[0]?.file ? path4.dirname(error.diagnostics[0].file) : invocationRoot;
|
|
776
|
-
return preExecutionFailure(
|
|
777
|
-
fallbackRoot,
|
|
778
|
-
runId,
|
|
779
|
-
void 0,
|
|
780
|
-
options.reporterDir ? path4.resolve(fallbackRoot, options.reporterDir) : path4.join(fallbackRoot, ".sedum", "reports"),
|
|
781
|
-
reportFiles,
|
|
782
|
-
options.strict ?? false,
|
|
783
|
-
diagnostic,
|
|
784
|
-
commit
|
|
785
|
-
);
|
|
786
|
-
}
|
|
787
|
-
const unavailable = (options.reporters ?? []).find(
|
|
788
|
-
(reporter) => !SUPPORTED_REPORTERS.includes(reporter)
|
|
789
|
-
);
|
|
790
|
-
if (unavailable)
|
|
791
|
-
return preExecutionFailure(
|
|
792
|
-
config.projectRoot,
|
|
793
|
-
runId,
|
|
794
|
-
config.outputDir,
|
|
795
|
-
config.reporterDir,
|
|
796
|
-
reportFiles,
|
|
797
|
-
options.strict ?? false,
|
|
798
|
-
{
|
|
799
|
-
code: "unsupported_reporter",
|
|
800
|
-
message: `Reporter ${JSON.stringify(unavailable)} is not available in this build.`,
|
|
801
|
-
fix: "Use --reporter list, steps, terminal, json, markdown, or junit."
|
|
802
|
-
},
|
|
803
|
-
commit
|
|
804
|
-
);
|
|
805
|
-
const controller = new AbortController();
|
|
806
|
-
let timedOut = false;
|
|
807
|
-
const onExternalAbort = () => controller.abort(options.signal?.reason);
|
|
808
|
-
if (options.signal?.aborted) onExternalAbort();
|
|
809
|
-
else
|
|
810
|
-
options.signal?.addEventListener("abort", onExternalAbort, { once: true });
|
|
811
|
-
const timeout = options.timeoutMinutes === void 0 ? void 0 : setTimeout(() => {
|
|
812
|
-
if (controller.signal.aborted) return;
|
|
813
|
-
timedOut = true;
|
|
814
|
-
controller.abort(new Error("run_timeout"));
|
|
815
|
-
options.onDeadline?.();
|
|
816
|
-
}, options.timeoutMinutes * 6e4);
|
|
817
|
-
const signal = controller.signal;
|
|
818
|
-
try {
|
|
819
|
-
let writer;
|
|
820
|
-
try {
|
|
821
|
-
writer = await ProgressWriter.create(
|
|
822
|
-
config.projectRoot,
|
|
823
|
-
runId,
|
|
824
|
-
config.outputDir,
|
|
825
|
-
{ markdown: reportFiles.markdown }
|
|
826
|
-
);
|
|
827
|
-
} catch {
|
|
828
|
-
commit();
|
|
829
|
-
const intended = path4.join(config.outputDir, runId);
|
|
830
|
-
const diagnostic = outputDiagnostic(path4.join(intended, "result.json"));
|
|
831
|
-
return {
|
|
832
|
-
result: await resultWithoutSink(runId, diagnostic),
|
|
833
|
-
artifacts: {
|
|
834
|
-
progressPath: path4.join(intended, "progress.json"),
|
|
835
|
-
resultPath: path4.join(intended, "result.json"),
|
|
836
|
-
authoritative: false
|
|
837
|
-
},
|
|
838
|
-
diagnostic
|
|
839
|
-
};
|
|
840
|
-
}
|
|
841
|
-
let artifacts = {
|
|
842
|
-
progressPath: writer.progressPath,
|
|
843
|
-
resultPath: writer.resultPath,
|
|
844
|
-
htmlPath: writer.htmlPath,
|
|
845
|
-
...reportFiles.markdown ? { markdownPath: writer.markdownPath } : {},
|
|
846
|
-
authoritative: true
|
|
847
|
-
};
|
|
848
|
-
let reporterFailed = false;
|
|
849
|
-
let reportWriter;
|
|
850
|
-
const recorder = new RunRecorder(async (snapshot) => {
|
|
851
|
-
await writer.write(snapshot);
|
|
852
|
-
if (!reporterFailed) {
|
|
853
|
-
try {
|
|
854
|
-
options.onSnapshot?.(snapshot, artifacts);
|
|
855
|
-
} catch {
|
|
856
|
-
reporterFailed = true;
|
|
857
|
-
throw new ReporterOutputError(
|
|
858
|
-
"The selected reporter could not write output."
|
|
859
|
-
);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
}, runId);
|
|
863
|
-
const recordCopyFailure = async (diagnostic) => {
|
|
864
|
-
if (recorder.snapshot.error === null)
|
|
865
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
866
|
-
return recorder.snapshot;
|
|
867
|
-
};
|
|
868
|
-
const onReporterFailure = async () => {
|
|
869
|
-
const diagnostic = {
|
|
870
|
-
code: "reporter_output_error",
|
|
871
|
-
message: "The selected reporter could not write output.",
|
|
872
|
-
fix: "Check terminal output access and rerun the command."
|
|
873
|
-
};
|
|
874
|
-
const result = terminalOutputFailure(recorder.snapshot, diagnostic);
|
|
875
|
-
try {
|
|
876
|
-
const finished = await finishRun(
|
|
877
|
-
writer,
|
|
878
|
-
reportWriter,
|
|
879
|
-
result,
|
|
880
|
-
async () => result
|
|
881
|
-
);
|
|
882
|
-
return {
|
|
883
|
-
result: finished.result,
|
|
884
|
-
artifacts: finishedArtifacts(
|
|
885
|
-
writer,
|
|
886
|
-
reportWriter,
|
|
887
|
-
reportFiles,
|
|
888
|
-
finished
|
|
889
|
-
),
|
|
890
|
-
diagnostic: finished.diagnostic ?? diagnostic,
|
|
891
|
-
reporterFailed: true
|
|
892
|
-
};
|
|
893
|
-
} catch (error) {
|
|
894
|
-
await writer.invalidate();
|
|
895
|
-
await reportWriter?.invalidate();
|
|
896
|
-
const output = outputDiagnostic(
|
|
897
|
-
error instanceof ProgressWriterError ? error.path : writer.resultPath
|
|
898
|
-
);
|
|
899
|
-
return {
|
|
900
|
-
result: terminalOutputFailure(result, output),
|
|
901
|
-
artifacts: { ...artifacts, authoritative: false },
|
|
902
|
-
diagnostic: output,
|
|
903
|
-
reporterFailed: true
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
};
|
|
907
|
-
try {
|
|
908
|
-
await recorder.start();
|
|
909
|
-
} catch (error) {
|
|
910
|
-
if (error instanceof ReporterOutputError) return onReporterFailure();
|
|
911
|
-
commit();
|
|
912
|
-
const diagnostic = outputDiagnostic(writer.progressPath);
|
|
913
|
-
await writer.invalidate();
|
|
914
|
-
return {
|
|
915
|
-
result: await resultWithoutSink(runId, diagnostic),
|
|
916
|
-
artifacts: { ...artifacts, authoritative: false },
|
|
917
|
-
diagnostic
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
try {
|
|
921
|
-
reportWriter = await openReportCopy(
|
|
922
|
-
config.projectRoot,
|
|
923
|
-
runId,
|
|
924
|
-
writer,
|
|
925
|
-
config.outputDir,
|
|
926
|
-
config.reporterDir,
|
|
927
|
-
reportFiles,
|
|
928
|
-
options.strict ?? false
|
|
929
|
-
);
|
|
930
|
-
} catch {
|
|
931
|
-
const diagnostic = outputDiagnostic(
|
|
932
|
-
path4.join(config.reporterDir, runId, "result.json")
|
|
933
|
-
);
|
|
934
|
-
commit();
|
|
935
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
936
|
-
const finished = await finishRun(
|
|
937
|
-
writer,
|
|
938
|
-
void 0,
|
|
939
|
-
recorder.snapshot,
|
|
940
|
-
async () => recorder.snapshot
|
|
941
|
-
);
|
|
942
|
-
return {
|
|
943
|
-
result: finished.result,
|
|
944
|
-
artifacts: finishedArtifacts(writer, void 0, reportFiles, {
|
|
945
|
-
...finished,
|
|
946
|
-
copyAvailable: false
|
|
947
|
-
}),
|
|
948
|
-
diagnostic: finished.diagnostic ?? diagnostic
|
|
949
|
-
};
|
|
950
|
-
}
|
|
951
|
-
const junitWriter = writer.includesJunit ? writer : reportWriter?.includesJunit ? reportWriter : void 0;
|
|
952
|
-
if (junitWriter)
|
|
953
|
-
artifacts = { ...artifacts, junitPath: junitWriter.junitPath };
|
|
954
|
-
const terminalExecution = async (diagnostic) => {
|
|
955
|
-
try {
|
|
956
|
-
const finished = await finishRun(
|
|
957
|
-
writer,
|
|
958
|
-
reportWriter,
|
|
959
|
-
recorder.snapshot,
|
|
960
|
-
recordCopyFailure
|
|
961
|
-
);
|
|
962
|
-
return {
|
|
963
|
-
result: finished.result,
|
|
964
|
-
artifacts: finishedArtifacts(
|
|
965
|
-
writer,
|
|
966
|
-
reportWriter,
|
|
967
|
-
reportFiles,
|
|
968
|
-
finished
|
|
969
|
-
),
|
|
970
|
-
diagnostic: finished.diagnostic ?? diagnostic,
|
|
971
|
-
reporterFailed,
|
|
972
|
-
onReporterFailure
|
|
973
|
-
};
|
|
974
|
-
} catch (error) {
|
|
975
|
-
const output = outputDiagnostic(
|
|
976
|
-
error instanceof ProgressWriterError ? error.path : writer.resultPath
|
|
977
|
-
);
|
|
978
|
-
const result = terminalOutputFailure(recorder.snapshot, output);
|
|
979
|
-
await writer.invalidate();
|
|
980
|
-
await reportWriter?.invalidate();
|
|
981
|
-
return {
|
|
982
|
-
result,
|
|
983
|
-
artifacts: { ...artifacts, authoritative: false },
|
|
984
|
-
diagnostic: output
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
let files;
|
|
989
|
-
let globalSelectedTests = 0;
|
|
990
|
-
let discoveryProblems = [];
|
|
991
|
-
try {
|
|
992
|
-
const selection = await discoverRunTests(
|
|
993
|
-
config,
|
|
994
|
-
options.paths ?? (options.file ? [options.file] : []),
|
|
995
|
-
options.filters
|
|
996
|
-
);
|
|
997
|
-
globalSelectedTests = selection.tests.length;
|
|
998
|
-
const selected = options.shard ? shardTests(selection.tests, options.shard) : selection.tests;
|
|
999
|
-
files = selected.map((test) => path4.join(config.projectRoot, test.file));
|
|
1000
|
-
discoveryProblems = [
|
|
1001
|
-
...selection.problems,
|
|
1002
|
-
...selection.invalid.flatMap(
|
|
1003
|
-
(entry) => entry.diagnostics.map((item) => ({
|
|
1004
|
-
file: entry.file,
|
|
1005
|
-
line: item.line,
|
|
1006
|
-
col: item.col,
|
|
1007
|
-
code: item.code,
|
|
1008
|
-
message: safeDiscoveryText(item.message, config),
|
|
1009
|
-
fix: safeDiscoveryText(item.fix, config)
|
|
1010
|
-
}))
|
|
1011
|
-
)
|
|
1012
|
-
];
|
|
1013
|
-
if (options.shard)
|
|
1014
|
-
discoveryProblems = shardProblems(discoveryProblems, options.shard);
|
|
1015
|
-
} catch {
|
|
1016
|
-
const error = new ProjectConfigError([
|
|
1017
|
-
{
|
|
1018
|
-
code: "test_discovery_error",
|
|
1019
|
-
file: config.configPath ?? config.testDirectory,
|
|
1020
|
-
line: 1,
|
|
1021
|
-
col: 1,
|
|
1022
|
-
key: "tests.directory",
|
|
1023
|
-
message: "The configured test directory could not be read.",
|
|
1024
|
-
fix: "Check the test directory path and permissions, then try again."
|
|
1025
|
-
}
|
|
1026
|
-
]);
|
|
1027
|
-
const diagnostic = setupDiagnostic(error);
|
|
1028
|
-
commit();
|
|
1029
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
1030
|
-
return terminalExecution(diagnostic);
|
|
1031
|
-
}
|
|
1032
|
-
if (signal.aborted) {
|
|
1033
|
-
const diagnostic = timedOut ? {
|
|
1034
|
-
code: "run_timeout",
|
|
1035
|
-
message: "The run deadline expired.",
|
|
1036
|
-
fix: "Increase --timeout-minutes or reduce the selected suite."
|
|
1037
|
-
} : {
|
|
1038
|
-
code: "canceled",
|
|
1039
|
-
message: "The run was interrupted.",
|
|
1040
|
-
fix: "Rerun the command when you are ready to continue."
|
|
1041
|
-
};
|
|
1042
|
-
if (discoveryProblems.length)
|
|
1043
|
-
await recorder.addDiscoveryProblems(discoveryProblems);
|
|
1044
|
-
commit();
|
|
1045
|
-
await recorder.finish(
|
|
1046
|
-
canonicalDiagnosticError(diagnostic),
|
|
1047
|
-
timedOut ? "error" : "interrupted"
|
|
1048
|
-
);
|
|
1049
|
-
return terminalExecution(diagnostic);
|
|
1050
|
-
}
|
|
1051
|
-
if (files.length === 0 && options.shard && globalSelectedTests > 0) {
|
|
1052
|
-
const { index, count } = options.shard;
|
|
1053
|
-
const diagnostic = {
|
|
1054
|
-
code: "empty_shard",
|
|
1055
|
-
message: `Shard ${index}/${count} has no tests; the selection has ${globalSelectedTests} test${globalSelectedTests === 1 ? "" : "s"}.`,
|
|
1056
|
-
fix: `Use --shard-count ${globalSelectedTests} or fewer.`
|
|
1057
|
-
};
|
|
1058
|
-
if (discoveryProblems.length)
|
|
1059
|
-
await recorder.addDiscoveryProblems(discoveryProblems);
|
|
1060
|
-
commit();
|
|
1061
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
1062
|
-
return terminalExecution(diagnostic);
|
|
1063
|
-
}
|
|
1064
|
-
if (files.length === 0) {
|
|
1065
|
-
const error = new ProjectConfigError([
|
|
1066
|
-
{
|
|
1067
|
-
code: "no_tests",
|
|
1068
|
-
file: config.configPath ?? path4.join(config.projectRoot, "sedum.config.yaml"),
|
|
1069
|
-
line: 1,
|
|
1070
|
-
col: 1,
|
|
1071
|
-
key: "tests.include",
|
|
1072
|
-
message: "The selection matched no valid test files.",
|
|
1073
|
-
fix: "Add a matching *.test.yaml file or correct paths and filters."
|
|
1074
|
-
}
|
|
1075
|
-
]);
|
|
1076
|
-
const diagnostic = setupDiagnostic(error);
|
|
1077
|
-
if (discoveryProblems.length)
|
|
1078
|
-
await recorder.addDiscoveryProblems(discoveryProblems);
|
|
1079
|
-
commit();
|
|
1080
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
1081
|
-
return terminalExecution(diagnostic);
|
|
1082
|
-
}
|
|
1083
|
-
try {
|
|
1084
|
-
const lanes = planLanes(
|
|
1085
|
-
options.parallel ?? 1,
|
|
1086
|
-
options.availableParallelism ?? availableParallelism(),
|
|
1087
|
-
files.length
|
|
1088
|
-
);
|
|
1089
|
-
const providerConcurrency = options.providerConcurrency ?? Math.min(DEFAULT_PROVIDER_CONCURRENCY, lanes * 2);
|
|
1090
|
-
await recorder.selectTests(files.length, {
|
|
1091
|
-
parallel: { requested: options.parallel ?? 1, lanes },
|
|
1092
|
-
shard: options.shard ? { ...options.shard, globalSelectedTests } : null,
|
|
1093
|
-
providerConcurrency
|
|
1094
|
-
});
|
|
1095
|
-
if (discoveryProblems.length)
|
|
1096
|
-
await recorder.addDiscoveryProblems(discoveryProblems);
|
|
1097
|
-
if (signal.aborted) throw new Error("canceled");
|
|
1098
|
-
const gate = new ProviderGate({ concurrency: providerConcurrency });
|
|
1099
|
-
const provider = new TypeSafeAdapter({
|
|
1100
|
-
...config.apiKey ? { apiKey: config.apiKey } : {},
|
|
1101
|
-
gate
|
|
1102
|
-
});
|
|
1103
|
-
const cache = await FileClassificationCache.load(
|
|
1104
|
-
path4.join(config.projectRoot, ".sedum", "classifications.json"),
|
|
1105
|
-
"jev-latest"
|
|
1106
|
-
);
|
|
1107
|
-
const locatorCache = await openLocatorCache(config.projectRoot, {
|
|
1108
|
-
disabled: options.locatorCacheDisabled ?? false,
|
|
1109
|
-
ciOptIn: options.locatorCacheCi ?? false,
|
|
1110
|
-
env: process.env
|
|
1111
|
-
});
|
|
1112
|
-
let operational = null;
|
|
1113
|
-
const driver = new PlaywrightBrowserDriver();
|
|
1114
|
-
const browsers = Array.from(
|
|
1115
|
-
{ length: lanes },
|
|
1116
|
-
() => new ReusableBrowserDriver(driver)
|
|
1117
|
-
);
|
|
1118
|
-
try {
|
|
1119
|
-
await runPool({
|
|
1120
|
-
items: files,
|
|
1121
|
-
lanes,
|
|
1122
|
-
signal,
|
|
1123
|
-
run: async (file, lane, ordinal) => {
|
|
1124
|
-
const browser = browsers[lane];
|
|
1125
|
-
for (let attempt = 0; attempt <= (options.retries ?? 0); attempt++) {
|
|
1126
|
-
if (attempt > 0)
|
|
1127
|
-
await recorder.testAt(ordinal)?.startAttempt(lane);
|
|
1128
|
-
const result = await runFlow(file, {
|
|
1129
|
-
repoRoot: config.projectRoot,
|
|
1130
|
-
browser,
|
|
1131
|
-
provider,
|
|
1132
|
-
classificationCache: cache,
|
|
1133
|
-
locatorCache,
|
|
1134
|
-
// Per-attempt values let tests keep backend data apart, like
|
|
1135
|
-
// Playwright's TEST_PARALLEL_INDEX. They are env-derived, so
|
|
1136
|
-
// they stay opaque in model input and reports.
|
|
1137
|
-
env: {
|
|
1138
|
-
...config.variables,
|
|
1139
|
-
SEDUM_PARALLEL_INDEX: String(lane),
|
|
1140
|
-
SEDUM_SHARD_INDEX: String(options.shard?.index ?? 1),
|
|
1141
|
-
SEDUM_ATTEMPT_KEY: randomBytes(6).toString("hex")
|
|
1142
|
-
},
|
|
1143
|
-
browserKind: config.browser,
|
|
1144
|
-
viewport: config.viewport,
|
|
1145
|
-
verifyPolicy: config.thresholds,
|
|
1146
|
-
...config.baseUrl ? { baseUrl: config.baseUrl } : {},
|
|
1147
|
-
...options.urlOverride ? { urlOverride: options.urlOverride } : {},
|
|
1148
|
-
...options.headed ? { headless: false } : {},
|
|
1149
|
-
...options.headed ? { headedOverlay: true } : {},
|
|
1150
|
-
...options.slowMoMs !== void 0 ? { slowMoMs: options.slowMoMs } : {},
|
|
1151
|
-
signal,
|
|
1152
|
-
report: {
|
|
1153
|
-
recorder,
|
|
1154
|
-
slot: { ordinal, lane },
|
|
1155
|
-
privacy: {
|
|
1156
|
-
secretValues: [],
|
|
1157
|
-
sensitiveOrigins: options.sensitiveOrigins
|
|
1158
|
-
},
|
|
1159
|
-
evidenceEnabled: options.evidence,
|
|
1160
|
-
replay: options.replay,
|
|
1161
|
-
saveFrame: (attempt2, frameId, bytes) => writer.saveFrame(attempt2, frameId, bytes)
|
|
1162
|
-
}
|
|
1163
|
-
});
|
|
1164
|
-
if (reporterFailed) throw new ReporterOutputError();
|
|
1165
|
-
if (signal.aborted) return "stop";
|
|
1166
|
-
if (result.status === "could_not_run") {
|
|
1167
|
-
await browser.recycle();
|
|
1168
|
-
operational ??= flowDiagnostic(result);
|
|
1169
|
-
return "stop";
|
|
1170
|
-
}
|
|
1171
|
-
if (result.status === "passed") break;
|
|
1172
|
-
}
|
|
1173
|
-
return "continue";
|
|
1174
|
-
}
|
|
1175
|
-
});
|
|
1176
|
-
} finally {
|
|
1177
|
-
gate.close();
|
|
1178
|
-
await Promise.all(browsers.map((browser) => browser.recycle()));
|
|
1179
|
-
}
|
|
1180
|
-
if (signal.aborted) {
|
|
1181
|
-
const diagnostic = timedOut ? {
|
|
1182
|
-
code: "run_timeout",
|
|
1183
|
-
message: "The run deadline expired.",
|
|
1184
|
-
fix: "Increase --timeout-minutes or reduce the selected suite."
|
|
1185
|
-
} : {
|
|
1186
|
-
code: "canceled",
|
|
1187
|
-
message: "The run was interrupted.",
|
|
1188
|
-
fix: "Rerun the command when you are ready to continue."
|
|
1189
|
-
};
|
|
1190
|
-
commit();
|
|
1191
|
-
await recorder.finish(
|
|
1192
|
-
canonicalDiagnosticError(diagnostic),
|
|
1193
|
-
timedOut ? "error" : "interrupted"
|
|
1194
|
-
);
|
|
1195
|
-
return terminalExecution(diagnostic);
|
|
1196
|
-
}
|
|
1197
|
-
if (operational) {
|
|
1198
|
-
const diagnostic = operational;
|
|
1199
|
-
commit();
|
|
1200
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
1201
|
-
return terminalExecution(diagnostic);
|
|
1202
|
-
}
|
|
1203
|
-
if (discoveryProblems.length) {
|
|
1204
|
-
const diagnostic = {
|
|
1205
|
-
code: "discovery_error",
|
|
1206
|
-
message: `${discoveryProblems.length} test file or path problem(s) were found.`,
|
|
1207
|
-
fix: "Correct the files named in the run summary and rerun."
|
|
1208
|
-
};
|
|
1209
|
-
commit();
|
|
1210
|
-
await recorder.finish(canonicalDiagnosticError(diagnostic));
|
|
1211
|
-
return terminalExecution(diagnostic);
|
|
1212
|
-
}
|
|
1213
|
-
commit();
|
|
1214
|
-
await recorder.finish();
|
|
1215
|
-
return terminalExecution(null);
|
|
1216
|
-
} catch (error) {
|
|
1217
|
-
if (error instanceof ReporterOutputError) {
|
|
1218
|
-
commit();
|
|
1219
|
-
return onReporterFailure();
|
|
1220
|
-
}
|
|
1221
|
-
if (error instanceof ProgressWriterError) {
|
|
1222
|
-
commit();
|
|
1223
|
-
const diagnostic2 = outputDiagnostic(error.path);
|
|
1224
|
-
const result = terminalOutputFailure(recorder.snapshot, diagnostic2);
|
|
1225
|
-
await writer.invalidate();
|
|
1226
|
-
return {
|
|
1227
|
-
result,
|
|
1228
|
-
artifacts: { ...artifacts, authoritative: false },
|
|
1229
|
-
diagnostic: diagnostic2
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
const diagnostic = signal.aborted ? timedOut ? {
|
|
1233
|
-
code: "run_timeout",
|
|
1234
|
-
message: "The run deadline expired.",
|
|
1235
|
-
fix: "Increase --timeout-minutes or reduce the selected suite."
|
|
1236
|
-
} : {
|
|
1237
|
-
code: "canceled",
|
|
1238
|
-
message: "The run was interrupted.",
|
|
1239
|
-
fix: "Rerun the command when you are ready to continue."
|
|
1240
|
-
} : setupDiagnostic(error);
|
|
1241
|
-
commit();
|
|
1242
|
-
try {
|
|
1243
|
-
if (recorder.snapshot.state === "running")
|
|
1244
|
-
await recorder.finish(
|
|
1245
|
-
canonicalDiagnosticError(diagnostic),
|
|
1246
|
-
signal.aborted && !timedOut ? "interrupted" : "error"
|
|
1247
|
-
);
|
|
1248
|
-
return terminalExecution(diagnostic);
|
|
1249
|
-
} catch (writeError) {
|
|
1250
|
-
const output = outputDiagnostic(
|
|
1251
|
-
writeError instanceof ProgressWriterError ? writeError.path : writer.resultPath
|
|
1252
|
-
);
|
|
1253
|
-
const result = terminalOutputFailure(recorder.snapshot, output);
|
|
1254
|
-
await writer.invalidate();
|
|
1255
|
-
return {
|
|
1256
|
-
result,
|
|
1257
|
-
artifacts: { ...artifacts, authoritative: false },
|
|
1258
|
-
diagnostic: output
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
} finally {
|
|
1263
|
-
if (timeout) clearTimeout(timeout);
|
|
1264
|
-
options.signal?.removeEventListener("abort", onExternalAbort);
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
export {
|
|
1268
|
-
executeRunCommand
|
|
1269
|
-
};
|