@fliwright/cli 0.0.0-stage → 0.1.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/README.md +59 -2
- package/dist/ArtifactReferences.d.ts +7 -0
- package/dist/ArtifactReferences.js +82 -0
- package/dist/CommandRegistry.d.ts +40 -0
- package/dist/CommandRegistry.js +177 -0
- package/dist/InspectionOutput.d.ts +5 -0
- package/dist/InspectionOutput.js +11 -0
- package/dist/RecordingReplay.d.ts +24 -0
- package/dist/RecordingReplay.js +79 -0
- package/dist/WorkflowContext.d.ts +20 -0
- package/dist/WorkflowContext.js +1 -0
- package/dist/capabilities/form.d.ts +13 -0
- package/dist/capabilities/form.js +9 -0
- package/dist/capabilities/interaction.d.ts +226 -0
- package/dist/capabilities/interaction.js +447 -0
- package/dist/capabilities/session.d.ts +18 -0
- package/dist/capabilities/session.js +55 -0
- package/dist/catalog.d.ts +36 -0
- package/dist/catalog.js +69 -0
- package/dist/commands/app-inspect.d.ts +96 -0
- package/dist/commands/app-inspect.js +70 -0
- package/dist/commands/app.d.ts +53 -0
- package/dist/commands/app.js +104 -0
- package/dist/commands/artifact-query.d.ts +138 -0
- package/dist/commands/artifact-query.js +81 -0
- package/dist/commands/artifacts.d.ts +40 -0
- package/dist/commands/artifacts.js +311 -0
- package/dist/commands/doctor.d.ts +11 -0
- package/dist/commands/doctor.js +285 -0
- package/dist/commands/flow-runtime.d.ts +40 -0
- package/dist/commands/flow-runtime.js +37 -0
- package/dist/commands/flow.d.ts +122 -0
- package/dist/commands/flow.js +236 -0
- package/dist/commands/generate-test.d.ts +46 -0
- package/dist/commands/generate-test.js +233 -0
- package/dist/commands/init.d.ts +22 -0
- package/dist/commands/init.js +262 -0
- package/dist/commands/mock-management.d.ts +53 -0
- package/dist/commands/mock-management.js +65 -0
- package/dist/commands/mock.d.ts +8 -0
- package/dist/commands/mock.js +27 -0
- package/dist/commands/record.d.ts +55 -0
- package/dist/commands/record.js +216 -0
- package/dist/commands/run.d.ts +93 -0
- package/dist/commands/run.js +707 -0
- package/dist/commands/scenario.d.ts +26 -0
- package/dist/commands/scenario.js +39 -0
- package/dist/commands/tdd.d.ts +72 -0
- package/dist/commands/tdd.js +218 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.js +40 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +139 -0
- package/dist/registry/devices.d.ts +2 -0
- package/dist/registry/devices.js +12 -0
- package/dist/registry/finite.d.ts +38 -0
- package/dist/registry/finite.js +121 -0
- package/dist/registry/flow-schemas.d.ts +405 -0
- package/dist/registry/flow-schemas.js +98 -0
- package/dist/registry/flow.d.ts +3 -0
- package/dist/registry/flow.js +56 -0
- package/dist/registry/generation-schema.d.ts +112 -0
- package/dist/registry/generation-schema.js +36 -0
- package/dist/registry/session.d.ts +2 -0
- package/dist/registry/session.js +24 -0
- package/dist/registry/tdd.d.ts +3 -0
- package/dist/registry/tdd.js +118 -0
- package/dist/reporter.d.ts +95 -0
- package/dist/reporter.js +61 -0
- package/dist/run.d.ts +6 -0
- package/dist/run.js +5 -0
- package/dist/session/ConnectionHost.d.ts +43 -0
- package/dist/session/ConnectionHost.js +129 -0
- package/dist/session/client.d.ts +38 -0
- package/dist/session/client.js +120 -0
- package/dist/session/worker.d.ts +1 -0
- package/dist/session/worker.js +161 -0
- package/dist/vm-discovery.d.ts +14 -0
- package/dist/vm-discovery.js +85 -0
- package/package.json +78 -3
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import { ensureFliwrightRunsRoot, resolveFliwrightProjectRoot, FLIWRIGHT_RUNS_ROOT_ENV, TIMELINE_FILE_NAME, parseTimelineData, summarizeTimeline, RunArtifactStore, projectRunTrace, recoverRunProgress, restoreRunAttempts, mergeFliwrightConfig, } from '@fliwright/core';
|
|
2
|
+
import { resolveVmUrl } from '../vm-discovery.js';
|
|
3
|
+
import { resolveProjectConfig } from '../config.js';
|
|
4
|
+
import { artifactReferences } from '../ArtifactReferences.js';
|
|
5
|
+
import { formatPretty, formatJson, formatJunit } from '../reporter.js';
|
|
6
|
+
import { spawn } from 'node:child_process';
|
|
7
|
+
import { tmpdir } from 'node:os';
|
|
8
|
+
import { createJiti } from 'jiti';
|
|
9
|
+
import { mkdir, mkdtemp, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { dirname, join, relative, resolve, isAbsolute } from 'node:path';
|
|
12
|
+
/** Artifact persistence failed after the runner produced its business outcome. */
|
|
13
|
+
export class RunFinalizationError extends Error {
|
|
14
|
+
runId;
|
|
15
|
+
outputDir;
|
|
16
|
+
runnerResult;
|
|
17
|
+
constructor(result, options, cause) {
|
|
18
|
+
const failures = [
|
|
19
|
+
...result.results.flatMap((test) => test.error ? [test.error] : []),
|
|
20
|
+
...(result.runnerErrors ?? []).map((error) => error.message),
|
|
21
|
+
];
|
|
22
|
+
super(`Run artifacts could not be finalized: ${cause instanceof Error ? cause.message : String(cause)}` +
|
|
23
|
+
(failures.length ? `\nOriginal runner errors:\n${failures.join('\n')}` : ''), { cause });
|
|
24
|
+
this.name = 'RunFinalizationError';
|
|
25
|
+
this.runId = options.runId;
|
|
26
|
+
this.outputDir = options.outputDir;
|
|
27
|
+
this.runnerResult = result;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export async function runCommand(options, deps = {}) {
|
|
31
|
+
const cwd = resolveFliwrightProjectRoot(options.cwd);
|
|
32
|
+
const config = await resolveProjectConfig(cwd, {
|
|
33
|
+
...(options.recordingMode ? { recording: { mode: options.recordingMode } } : {}), runsRoot: options.runsRoot, defaultScenario: options.scenario, scenarioMode: options.scenarioMode,
|
|
34
|
+
});
|
|
35
|
+
const shared = mergeFliwrightConfig({ project: config });
|
|
36
|
+
const reporter = options.reporter ?? config.reporter;
|
|
37
|
+
const testPattern = options.testPattern ?? `${shared.paths.tests}/**/*.test.ts`;
|
|
38
|
+
const timeout = options.timeout ?? config.timeout ?? 30000;
|
|
39
|
+
const screenshot = options.screenshot ?? config.screenshot;
|
|
40
|
+
const recordingMode = shared.recording.mode;
|
|
41
|
+
const runId = createRunId();
|
|
42
|
+
const resolver = deps.resolveVmUrl ?? resolveVmUrl;
|
|
43
|
+
const vmUrl = await resolver({
|
|
44
|
+
cliFlag: options.vmUrl,
|
|
45
|
+
configUrl: config.vmServiceUrl,
|
|
46
|
+
cwd,
|
|
47
|
+
verify: true,
|
|
48
|
+
});
|
|
49
|
+
if (!vmUrl) {
|
|
50
|
+
throw new Error('Could not find a running Flutter VM Service.\n\n' +
|
|
51
|
+
' Start your Flutter app first: flutter run\n' +
|
|
52
|
+
' Then re-run: fliwright run\n' +
|
|
53
|
+
' Or specify: fliwright run --vm-url ws://127.0.0.1:8181/ws');
|
|
54
|
+
}
|
|
55
|
+
deps.onVmResolved?.(vmUrl);
|
|
56
|
+
const runsRoot = await ensureFliwrightRunsRoot({
|
|
57
|
+
projectRoot: cwd,
|
|
58
|
+
runsRoot: shared.runsRoot,
|
|
59
|
+
});
|
|
60
|
+
const outputDir = join(runsRoot, runId);
|
|
61
|
+
const reportPath = options.output ? resolve(cwd, options.output) : join(outputDir, 'report.json');
|
|
62
|
+
const vitestResult = await runVitest({
|
|
63
|
+
testPattern,
|
|
64
|
+
testName: options.testName,
|
|
65
|
+
caseSelection: options.caseSelection,
|
|
66
|
+
vmUrl,
|
|
67
|
+
cwd,
|
|
68
|
+
timeout,
|
|
69
|
+
screenshot,
|
|
70
|
+
recordingMode,
|
|
71
|
+
runId,
|
|
72
|
+
runsRoot,
|
|
73
|
+
sessionResultsPath: join(outputDir, 'sessions.jsonl'),
|
|
74
|
+
signal: options.signal,
|
|
75
|
+
recordingReplay: options.recordingReplay,
|
|
76
|
+
scenarios: shared.scenarios,
|
|
77
|
+
scenarioMode: shared.scenarioMode,
|
|
78
|
+
sharedConfig: shared,
|
|
79
|
+
processGroup: options.processGroup,
|
|
80
|
+
});
|
|
81
|
+
const withArtifacts = await finalizeRunArtifacts(vitestResult, {
|
|
82
|
+
cwd,
|
|
83
|
+
outputDir,
|
|
84
|
+
reportPath,
|
|
85
|
+
runId,
|
|
86
|
+
runsRoot,
|
|
87
|
+
screenshot,
|
|
88
|
+
recordingMode,
|
|
89
|
+
testPattern,
|
|
90
|
+
testName: options.testName,
|
|
91
|
+
});
|
|
92
|
+
if (options.junitOutput) {
|
|
93
|
+
const path = resolve(cwd, options.junitOutput);
|
|
94
|
+
await mkdir(dirname(path), { recursive: true });
|
|
95
|
+
await writeFile(path, formatJunit(withArtifacts), 'utf8');
|
|
96
|
+
}
|
|
97
|
+
const formatted = formatOutput(withArtifacts, reporter);
|
|
98
|
+
if (options.print !== false) {
|
|
99
|
+
console.log(formatted);
|
|
100
|
+
}
|
|
101
|
+
return withArtifacts;
|
|
102
|
+
}
|
|
103
|
+
export async function runVitest(options) {
|
|
104
|
+
// An editor can bundle this module outside the project's dependency tree.
|
|
105
|
+
// Prefer the project's runner and Vitest together; standalone CLI invocations
|
|
106
|
+
// without local packages can still use the CLI installation's dependencies.
|
|
107
|
+
const projectResolver = createJiti(join(options.cwd, 'package.json'));
|
|
108
|
+
const resolveRuntime = (specifier) => projectResolver.esmResolve(specifier, { try: true })
|
|
109
|
+
?? import.meta.resolve(specifier);
|
|
110
|
+
const runnerPath = fileURLToPath(resolveRuntime('@fliwright/vitest/runner'));
|
|
111
|
+
const vitestUrl = resolveRuntime('vitest/node');
|
|
112
|
+
// Use the public Node API and explicit file reports in an isolated child,
|
|
113
|
+
// preserving project configuration and custom runners.
|
|
114
|
+
const isGlob = ['*', '?', '{', '['].some((token) => options.testPattern.includes(token));
|
|
115
|
+
const isFile = !isGlob && await stat(resolve(options.cwd, options.testPattern)).then((entry) => entry.isFile(), () => false);
|
|
116
|
+
const filters = isGlob ? [] : [options.testPattern];
|
|
117
|
+
const reportDirectory = await mkdtemp(join(tmpdir(), 'fliwright-vitest-report-'));
|
|
118
|
+
const rawReportPath = join(reportDirectory, 'report.json');
|
|
119
|
+
const bootstrap = `
|
|
120
|
+
const { readFile, writeFile, realpath } = await import('node:fs/promises');
|
|
121
|
+
const { startVitest, createVitest, JsonReporter } = await import(${JSON.stringify(vitestUrl)});
|
|
122
|
+
class RunReporter extends JsonReporter {
|
|
123
|
+
runnerErrors = [];
|
|
124
|
+
recoveryAttempts = [];
|
|
125
|
+
collectionFailures = new Set();
|
|
126
|
+
onTestModuleCollected(module) {
|
|
127
|
+
if (module.errors().length) this.collectionFailures.add(module.moduleId);
|
|
128
|
+
}
|
|
129
|
+
async onTestRunEnd(modules, unhandledErrors = []) {
|
|
130
|
+
const normalize = (error, phase, file) => ({ phase, message: error.message ?? String(error),
|
|
131
|
+
...(error.stack ? { stack: error.stack } : {}), ...(file ? { file } : {}) });
|
|
132
|
+
this.runnerErrors = unhandledErrors.map(error => normalize(error, 'unhandled'));
|
|
133
|
+
for (const module of modules) {
|
|
134
|
+
for (const test of module.children.allTests()) this.recoveryAttempts.push(...(test.meta().fliwrightRecovery ?? []));
|
|
135
|
+
const phase = this.collectionFailures.has(module.moduleId) ? 'collection' : 'suite';
|
|
136
|
+
for (const error of module.errors()) this.runnerErrors.push(normalize(error, phase, module.relativeModuleId));
|
|
137
|
+
for (const suite of module.children.allSuites()) {
|
|
138
|
+
for (const error of suite.errors()) this.runnerErrors.push(normalize(error, 'suite', module.relativeModuleId));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
await super.onTestRunEnd(modules);
|
|
142
|
+
const report = JSON.parse(await readFile(${JSON.stringify(rawReportPath)}, 'utf8'));
|
|
143
|
+
await writeFile(${JSON.stringify(rawReportPath)}, JSON.stringify({ ...report,
|
|
144
|
+
runnerErrors: this.runnerErrors, recoveryAttempts: this.recoveryAttempts }));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const settings = {
|
|
149
|
+
${isGlob || isFile ? `include: ${JSON.stringify([options.testPattern])},` : ''}
|
|
150
|
+
run: true, reporters: [new RunReporter({ outputFile: ${JSON.stringify(rawReportPath)} })], testTimeout: ${JSON.stringify(options.timeout)},
|
|
151
|
+
${options.testName ? `testNamePattern: ${JSON.stringify(options.testName)},` : ''}
|
|
152
|
+
};
|
|
153
|
+
const viteOptions = { plugins: [{ name: 'fliwright-runner', config(config) {
|
|
154
|
+
return { test: { runner: config.test?.runner ?? ${JSON.stringify(runnerPath)} } };
|
|
155
|
+
} }] };
|
|
156
|
+
let context;
|
|
157
|
+
try {
|
|
158
|
+
${options.caseSelection ? `
|
|
159
|
+
const { collectedCases } = await import(${JSON.stringify(resolveRuntime('@fliwright/cli/run'))});
|
|
160
|
+
context = await createVitest(settings, viteOptions);
|
|
161
|
+
await context.standalone();
|
|
162
|
+
const result = await context.collect(${JSON.stringify(filters)}, { staticParse: false });
|
|
163
|
+
if (result.unhandledErrors.length) throw new Error('Case collection failed');
|
|
164
|
+
const selection = ${JSON.stringify(options.caseSelection)};
|
|
165
|
+
const selected = collectedCases(result.testModules, await realpath(${JSON.stringify(options.cwd)})).filter(item =>
|
|
166
|
+
item.caseId === selection.caseId && item.file === selection.file &&
|
|
167
|
+
item.duplicateIndex === selection.duplicateIndex && JSON.stringify(item.titlePath) === JSON.stringify(selection.titlePath));
|
|
168
|
+
if (selected.length !== 1) throw new Error('Frozen catalog case no longer matches collection');
|
|
169
|
+
await context.runTestSpecifications([selected[0].test.toTestSpecification()]);
|
|
170
|
+
` : `context = await startVitest('test', ${JSON.stringify(filters)}, settings, viteOptions);`}
|
|
171
|
+
} finally { await context?.close(); }
|
|
172
|
+
`;
|
|
173
|
+
const args = ['--input-type=module', '--eval', bootstrap];
|
|
174
|
+
const { stdout, stderr, interrupted, exitCode, exitSignal } = await execNode(args, {
|
|
175
|
+
...process.env,
|
|
176
|
+
FLIWRIGHT_PROJECT_ROOT: options.cwd,
|
|
177
|
+
...(options.sharedConfig ? { FLIWRIGHT_CONFIG: JSON.stringify(options.sharedConfig) } : {}),
|
|
178
|
+
FLIWRIGHT_VM_URL: options.vmUrl,
|
|
179
|
+
FLIWRIGHT_SCREENSHOT_MODE: options.screenshot,
|
|
180
|
+
FLIWRIGHT_RECORDING_MODE: options.recordingMode ?? 'standard',
|
|
181
|
+
FLIWRIGHT_FAILURE_TIMEOUT_MS: String(options.timeout),
|
|
182
|
+
FLIWRIGHT_SCENARIOS: JSON.stringify(options.scenarios ?? {}),
|
|
183
|
+
FLIWRIGHT_SCENARIO_MODE: options.scenarioMode ?? 'attach',
|
|
184
|
+
FLIWRIGHT_RECORDING_REPLAY: options.recordingReplay ? '1' : '',
|
|
185
|
+
...(options.runId ? { FLIWRIGHT_RUN_ID: options.runId } : {}),
|
|
186
|
+
...(options.runsRoot ? { [FLIWRIGHT_RUNS_ROOT_ENV]: options.runsRoot } : {}),
|
|
187
|
+
...(options.sessionResultsPath ? { FLIWRIGHT_SESSION_RESULTS_PATH: options.sessionResultsPath } : {}),
|
|
188
|
+
}, options.cwd, options.signal, options.processGroup);
|
|
189
|
+
const reportJson = await readFile(rawReportPath, 'utf8').catch(() => '');
|
|
190
|
+
await rm(reportDirectory, { recursive: true, force: true });
|
|
191
|
+
const result = parseVitestOutput(reportJson);
|
|
192
|
+
if (interrupted) {
|
|
193
|
+
result.runnerErrors = [...(result.runnerErrors ?? []), {
|
|
194
|
+
phase: 'process',
|
|
195
|
+
message: 'Vitest run interrupted by cancellation.',
|
|
196
|
+
}];
|
|
197
|
+
}
|
|
198
|
+
if (interrupted || exitCode !== 0 || exitSignal || result.runnerErrors?.length)
|
|
199
|
+
result.passed = false;
|
|
200
|
+
const expectedTestFailureExit = exitCode === 1 && result.failedTests > 0;
|
|
201
|
+
if (!interrupted && (exitSignal || (exitCode !== 0 && !expectedTestFailureExit)) && !result.runnerErrors?.some((error) => error.phase === 'process')) {
|
|
202
|
+
result.runnerErrors = [...(result.runnerErrors ?? []), { phase: 'process',
|
|
203
|
+
message: stderr.trim() || `Vitest did not finish successfully (exit ${exitCode ?? exitSignal ?? 'unknown'}).`,
|
|
204
|
+
}];
|
|
205
|
+
}
|
|
206
|
+
if (!interrupted && !result.passed && !result.runnerErrors?.length && result.failedTests === 0) {
|
|
207
|
+
result.runnerErrors = [{ phase: 'process',
|
|
208
|
+
message: stderr.trim() || `Vitest did not finish successfully (exit ${exitCode ?? exitSignal ?? 'unknown'}).`,
|
|
209
|
+
}];
|
|
210
|
+
}
|
|
211
|
+
result.status = interrupted ? 'interrupted' : result.passed ? 'passed' : 'failed';
|
|
212
|
+
if (options.runId && options.runsRoot) {
|
|
213
|
+
try {
|
|
214
|
+
await restoreRunAttempts(readVitestReport(reportJson)?.recoveryAttempts ?? [], options.runId, options.runsRoot);
|
|
215
|
+
}
|
|
216
|
+
catch (cause) {
|
|
217
|
+
throw new RunFinalizationError(result, {
|
|
218
|
+
runId: options.runId, outputDir: join(options.runsRoot, options.runId),
|
|
219
|
+
}, cause);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
function execNode(args, env, cwd, signal, processGroup = 'isolated') {
|
|
225
|
+
return new Promise((resolve, reject) => {
|
|
226
|
+
const ownsProcessGroup = process.platform !== 'win32' && processGroup === 'isolated';
|
|
227
|
+
const child = spawn(process.execPath, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: ownsProcessGroup });
|
|
228
|
+
let stdout = '';
|
|
229
|
+
let stderr = '';
|
|
230
|
+
let interrupted = false;
|
|
231
|
+
let killTimer;
|
|
232
|
+
const signalRun = (terminationSignal) => {
|
|
233
|
+
if (ownsProcessGroup && child.pid) {
|
|
234
|
+
try {
|
|
235
|
+
process.kill(-child.pid, terminationSignal);
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
if (error.code !== 'ESRCH')
|
|
239
|
+
child.kill(terminationSignal);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else
|
|
243
|
+
child.kill(terminationSignal);
|
|
244
|
+
};
|
|
245
|
+
const onSigint = () => {
|
|
246
|
+
if (interrupted)
|
|
247
|
+
return;
|
|
248
|
+
interrupted = true;
|
|
249
|
+
signalRun('SIGINT');
|
|
250
|
+
killTimer = setTimeout(() => signalRun('SIGKILL'), 5000);
|
|
251
|
+
};
|
|
252
|
+
const onAbort = () => onSigint();
|
|
253
|
+
process.once('SIGINT', onSigint);
|
|
254
|
+
process.once('SIGTERM', onSigint);
|
|
255
|
+
if (signal?.aborted)
|
|
256
|
+
onAbort();
|
|
257
|
+
else
|
|
258
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
259
|
+
child.stdout.setEncoding('utf8');
|
|
260
|
+
child.stderr.setEncoding('utf8');
|
|
261
|
+
child.stdout.on('data', (chunk) => { stdout += chunk; });
|
|
262
|
+
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
|
263
|
+
const cleanup = () => {
|
|
264
|
+
process.removeListener('SIGINT', onSigint);
|
|
265
|
+
process.removeListener('SIGTERM', onSigint);
|
|
266
|
+
signal?.removeEventListener('abort', onAbort);
|
|
267
|
+
if (killTimer)
|
|
268
|
+
clearTimeout(killTimer);
|
|
269
|
+
};
|
|
270
|
+
child.on('error', (error) => { cleanup(); reject(error); });
|
|
271
|
+
child.on('close', (exitCode, exitSignal) => {
|
|
272
|
+
// The runner can exit before its fork workers or owned subprocesses.
|
|
273
|
+
// Complete cancellation before returning the recovered run to callers.
|
|
274
|
+
if (interrupted && ownsProcessGroup)
|
|
275
|
+
signalRun('SIGKILL');
|
|
276
|
+
cleanup();
|
|
277
|
+
resolve({ stdout, stderr, interrupted, exitCode, exitSignal });
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
function readVitestReport(raw) {
|
|
282
|
+
const trimmed = raw.trim();
|
|
283
|
+
const start = trimmed.indexOf('{');
|
|
284
|
+
const end = trimmed.lastIndexOf('}');
|
|
285
|
+
if (start === -1 || end === -1 || end < start) {
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
return JSON.parse(trimmed.slice(start, end + 1));
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export function parseVitestOutput(raw) {
|
|
296
|
+
const report = readVitestReport(raw);
|
|
297
|
+
if (!report)
|
|
298
|
+
return { passed: false, totalTests: 0, passedTests: 0, failedTests: 0, duration: 0, results: [] };
|
|
299
|
+
const results = (report.testResults ?? []).flatMap((fileResult) => (fileResult.assertionResults ?? []).map((assertion) => {
|
|
300
|
+
const passed = assertion.status === 'passed';
|
|
301
|
+
return {
|
|
302
|
+
name: assertion.fullName ?? assertion.title ?? '<unknown>',
|
|
303
|
+
passed,
|
|
304
|
+
duration: assertion.duration ?? 0,
|
|
305
|
+
...(passed ? {} : { error: (assertion.failureMessages ?? []).join('\n') }),
|
|
306
|
+
};
|
|
307
|
+
}));
|
|
308
|
+
const duration = report.startTime ? Math.max(0, Date.now() - report.startTime) : 0;
|
|
309
|
+
return {
|
|
310
|
+
passed: report.success === true && !report.runnerErrors?.length,
|
|
311
|
+
totalTests: report.numTotalTests ?? results.length,
|
|
312
|
+
passedTests: report.numPassedTests ?? results.filter((r) => r.passed).length,
|
|
313
|
+
failedTests: report.numFailedTests ?? results.filter((r) => !r.passed).length,
|
|
314
|
+
duration,
|
|
315
|
+
results,
|
|
316
|
+
...(report.runnerErrors?.length ? { runnerErrors: report.runnerErrors } : {}),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
async function readFailureContexts(manifestPath, screenshotMode) {
|
|
320
|
+
const runDir = dirname(manifestPath);
|
|
321
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
322
|
+
const failures = [];
|
|
323
|
+
for (const test of manifest.tests) {
|
|
324
|
+
const latest = test.attempts.at(-1);
|
|
325
|
+
if (!latest)
|
|
326
|
+
continue;
|
|
327
|
+
const attemptDir = dirname(join(runDir, latest.resultPath));
|
|
328
|
+
const result = JSON.parse(await readFile(join(runDir, latest.resultPath), 'utf8'));
|
|
329
|
+
if (result.testOutcome !== 'failed' || !result.failureContextPath)
|
|
330
|
+
continue;
|
|
331
|
+
const entries = JSON.parse(await readFile(join(attemptDir, result.failureContextPath), 'utf8'));
|
|
332
|
+
for (const entry of entries) {
|
|
333
|
+
const screenshotPath = entry.screenshot?.path;
|
|
334
|
+
if (screenshotPath && !isAbsolute(screenshotPath)) {
|
|
335
|
+
const path = join(attemptDir, screenshotPath);
|
|
336
|
+
entry.screenshot = screenshotMode === 'base64'
|
|
337
|
+
? { mimeType: 'image/png', base64: (await readFile(path)).toString('base64') }
|
|
338
|
+
: { mimeType: 'image/png', path };
|
|
339
|
+
}
|
|
340
|
+
failures.push(entry);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return failures;
|
|
344
|
+
}
|
|
345
|
+
/** Finalize an externally executed runner using the canonical CLI artifact pipeline. */
|
|
346
|
+
export async function finalizeRunArtifacts(result, options) {
|
|
347
|
+
try {
|
|
348
|
+
return await persistRunArtifacts(result, options);
|
|
349
|
+
}
|
|
350
|
+
catch (cause) {
|
|
351
|
+
throw new RunFinalizationError(result, options, cause);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
async function persistRunArtifacts(result, options) {
|
|
355
|
+
await mkdir(options.outputDir, { recursive: true });
|
|
356
|
+
const manifestPath = await writeRunManifest({
|
|
357
|
+
runsRoot: options.runsRoot,
|
|
358
|
+
runId: options.runId,
|
|
359
|
+
runDir: options.outputDir,
|
|
360
|
+
runStatus: result.status,
|
|
361
|
+
runnerErrors: result.runnerErrors,
|
|
362
|
+
});
|
|
363
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
364
|
+
if (manifest.status === 'interrupted' && result.status !== 'interrupted') {
|
|
365
|
+
result = { ...result, status: 'interrupted', passed: false };
|
|
366
|
+
}
|
|
367
|
+
const screenshots = [];
|
|
368
|
+
const projectedFailures = await readFailureContexts(manifestPath, options.screenshot);
|
|
369
|
+
const failures = await persistScreenshots(projectedFailures, options.outputDir, options.screenshot, screenshots);
|
|
370
|
+
const { timelines, agentVisibleFailures } = await readTimelineSummaries(options.runsRoot, options.runId);
|
|
371
|
+
const report = {
|
|
372
|
+
...result,
|
|
373
|
+
...(failures.length > 0 ? { failures } : {}),
|
|
374
|
+
artifacts: {
|
|
375
|
+
runId: options.runId,
|
|
376
|
+
outputDir: options.outputDir,
|
|
377
|
+
reportPath: join(options.outputDir, 'report.json'),
|
|
378
|
+
manifestPath,
|
|
379
|
+
screenshots,
|
|
380
|
+
timelines: timelines.map((timeline) => timeline.path),
|
|
381
|
+
},
|
|
382
|
+
...(timelines.length ? { timelines, agentVisibleFailures } : {}),
|
|
383
|
+
reproduceCommand: buildReproduceCommand(options.testPattern, options.testName),
|
|
384
|
+
};
|
|
385
|
+
await mkdir(dirname(options.reportPath), { recursive: true });
|
|
386
|
+
const canonicalReportPath = join(options.outputDir, 'report.json');
|
|
387
|
+
await mkdir(dirname(canonicalReportPath), { recursive: true });
|
|
388
|
+
const serialized = JSON.stringify(report, null, 2);
|
|
389
|
+
await writeFile(canonicalReportPath, serialized, 'utf8');
|
|
390
|
+
if (resolve(options.reportPath) !== resolve(canonicalReportPath)) {
|
|
391
|
+
await writeFile(options.reportPath, serialized, 'utf8');
|
|
392
|
+
}
|
|
393
|
+
return report;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Merge worker-written attempt results into the one authoritative run index.
|
|
397
|
+
* Workers only create files below tests/<testId>/attempts/<attemptId>; the
|
|
398
|
+
* parent process is the sole writer of run.json after Vitest exits.
|
|
399
|
+
*/
|
|
400
|
+
export async function writeRunManifest(options) {
|
|
401
|
+
const testsRoot = join(options.runDir, 'tests');
|
|
402
|
+
// Repair any attempt that was left running or unreadable. This is safe on a
|
|
403
|
+
// normal run and also covers a worker crash whose parent exits cleanly.
|
|
404
|
+
await repairInterruptedAttempts(testsRoot, options.runId, options.runnerErrors);
|
|
405
|
+
const tests = new Map();
|
|
406
|
+
let testEntries = [];
|
|
407
|
+
try {
|
|
408
|
+
testEntries = await readdir(testsRoot, { withFileTypes: true });
|
|
409
|
+
}
|
|
410
|
+
catch {
|
|
411
|
+
testEntries = [];
|
|
412
|
+
}
|
|
413
|
+
for (const testEntry of testEntries) {
|
|
414
|
+
if (!testEntry.isDirectory())
|
|
415
|
+
continue;
|
|
416
|
+
const testDir = join(testsRoot, testEntry.name);
|
|
417
|
+
let attemptEntries = [];
|
|
418
|
+
try {
|
|
419
|
+
attemptEntries = await readdir(join(testDir, 'attempts'), { withFileTypes: true });
|
|
420
|
+
}
|
|
421
|
+
catch {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
for (const attemptEntry of attemptEntries) {
|
|
425
|
+
if (!attemptEntry.isDirectory())
|
|
426
|
+
continue;
|
|
427
|
+
const resultAbsolute = join(testDir, 'attempts', attemptEntry.name, 'result.json');
|
|
428
|
+
let result = {};
|
|
429
|
+
try {
|
|
430
|
+
result = JSON.parse(await readFile(resultAbsolute, 'utf8'));
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
// Keep the reference: artifact export will report it as missing or
|
|
434
|
+
// unreadable instead of claiming a complete run.
|
|
435
|
+
}
|
|
436
|
+
const testId = typeof result.testId === 'string' && result.testId.length > 0
|
|
437
|
+
? result.testId
|
|
438
|
+
: testEntry.name;
|
|
439
|
+
const attemptId = typeof result.attemptId === 'string' && result.attemptId.length > 0
|
|
440
|
+
? result.attemptId
|
|
441
|
+
: attemptEntry.name;
|
|
442
|
+
const list = tests.get(testId) ?? [];
|
|
443
|
+
list.push({
|
|
444
|
+
attemptId,
|
|
445
|
+
resultPath: relative(options.runDir, resultAbsolute).split('\\').join('/'),
|
|
446
|
+
...(typeof result.testOutcome === 'string' ? { status: result.testOutcome } : {}),
|
|
447
|
+
...(result.evidenceStatus === 'complete' || result.evidenceStatus === 'partial' || result.evidenceStatus === 'disabled'
|
|
448
|
+
? { evidenceStatus: result.evidenceStatus }
|
|
449
|
+
: {}),
|
|
450
|
+
});
|
|
451
|
+
tests.set(testId, list);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const attempts = [...tests.values()].flat();
|
|
455
|
+
const status = options.runStatus === 'interrupted' || attempts.some((attempt) => attempt.status === 'interrupted')
|
|
456
|
+
? 'interrupted'
|
|
457
|
+
: attempts.some((attempt) => attempt.status === 'failed') || options.runStatus === 'failed' || Boolean(options.runnerErrors?.length)
|
|
458
|
+
? 'failed'
|
|
459
|
+
: attempts.length > 0 && attempts.every((attempt) => attempt.status === 'skipped')
|
|
460
|
+
? 'skipped'
|
|
461
|
+
: 'passed';
|
|
462
|
+
const evidenceStatus = attempts.some((attempt) => attempt.evidenceStatus === 'partial')
|
|
463
|
+
? 'partial'
|
|
464
|
+
: attempts.length > 0 && attempts.every((attempt) => attempt.evidenceStatus === 'disabled')
|
|
465
|
+
? 'disabled'
|
|
466
|
+
: 'complete';
|
|
467
|
+
const manifest = {
|
|
468
|
+
schemaVersion: 1,
|
|
469
|
+
runId: options.runId,
|
|
470
|
+
status,
|
|
471
|
+
evidenceStatus,
|
|
472
|
+
...(options.runnerErrors?.length ? { runnerErrors: options.runnerErrors } : {}),
|
|
473
|
+
tests: [...tests.entries()].map(([testId, attemptList]) => ({
|
|
474
|
+
testId,
|
|
475
|
+
attempts: attemptList
|
|
476
|
+
.sort((a, b) => a.attemptId.localeCompare(b.attemptId, undefined, { numeric: true }))
|
|
477
|
+
.map(({ attemptId, resultPath }) => ({ attemptId, resultPath })),
|
|
478
|
+
})),
|
|
479
|
+
};
|
|
480
|
+
const store = new RunArtifactStore({ runsRoot: options.runsRoot, runId: options.runId });
|
|
481
|
+
return store.writeManifest(manifest);
|
|
482
|
+
}
|
|
483
|
+
async function repairInterruptedAttempts(testsRoot, runId, runErrors = []) {
|
|
484
|
+
const store = new RunArtifactStore({ runsRoot: dirname(dirname(testsRoot)), runId });
|
|
485
|
+
let tests;
|
|
486
|
+
try {
|
|
487
|
+
tests = await readdir(testsRoot, { withFileTypes: true });
|
|
488
|
+
}
|
|
489
|
+
catch {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
for (const testEntry of tests) {
|
|
493
|
+
if (!testEntry.isDirectory())
|
|
494
|
+
continue;
|
|
495
|
+
const attemptsDir = join(testsRoot, testEntry.name, 'attempts');
|
|
496
|
+
let attempts;
|
|
497
|
+
try {
|
|
498
|
+
attempts = await readdir(attemptsDir, { withFileTypes: true });
|
|
499
|
+
}
|
|
500
|
+
catch {
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
for (const attemptEntry of attempts) {
|
|
504
|
+
if (!attemptEntry.isDirectory())
|
|
505
|
+
continue;
|
|
506
|
+
const resultPath = join(attemptsDir, attemptEntry.name, 'result.json');
|
|
507
|
+
let current;
|
|
508
|
+
try {
|
|
509
|
+
const parsed = JSON.parse(await readFile(resultPath, 'utf8'));
|
|
510
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed))
|
|
511
|
+
current = parsed;
|
|
512
|
+
}
|
|
513
|
+
catch { /* incomplete attempt */ }
|
|
514
|
+
let recovered;
|
|
515
|
+
try {
|
|
516
|
+
const log = await store.readEvents(join(attemptsDir, attemptEntry.name, 'events.jsonl'));
|
|
517
|
+
// Filesystem directory names may encode characters in the original
|
|
518
|
+
// task id. Recover that id only from a journal identity mapping to this exact
|
|
519
|
+
// canonical directory, then enforce it for every subsequent event.
|
|
520
|
+
const candidate = log.events.find((value) => typeof value === 'object' && value !== null && 'testId' in value && typeof value.testId === 'string'
|
|
521
|
+
&& 'attemptId' in value && value.attemptId === attemptEntry.name && 'runId' in value && value.runId === runId
|
|
522
|
+
&& store.attemptDir(value.testId, value.attemptId) === join(attemptsDir, attemptEntry.name));
|
|
523
|
+
recovered = recoverRunProgress(log, { runId,
|
|
524
|
+
testId: typeof current?.testId === 'string' ? current.testId : candidate?.testId ?? testEntry.name,
|
|
525
|
+
attemptId: attemptEntry.name });
|
|
526
|
+
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
if (!(typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT')) {
|
|
529
|
+
recovered = { issues: ['Progress journal could not be read.'], finalized: false };
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
const snapshotFinalized = current?.finalized === true;
|
|
533
|
+
if (recovered?.result && !snapshotFinalized) {
|
|
534
|
+
current = { ...current, ...recovered.result,
|
|
535
|
+
operations: mergeFacts(current?.operations, recovered.result.operations, 'operationId'),
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
const terminalStatuses = new Set(['passed', 'failed', 'skipped', 'interrupted']);
|
|
539
|
+
const completed = current
|
|
540
|
+
&& terminalStatuses.has(String(current.status))
|
|
541
|
+
&& terminalStatuses.has(String(current.attemptOutcome))
|
|
542
|
+
&& terminalStatuses.has(String(current.testOutcome)) && (!recovered || recovered.finalized || snapshotFinalized);
|
|
543
|
+
if (completed && !recovered)
|
|
544
|
+
continue;
|
|
545
|
+
const interruptedAt = new Date().toISOString();
|
|
546
|
+
const runnerErrors = Array.isArray(current?.runnerErrors) ? [...current.runnerErrors] : [];
|
|
547
|
+
if (!completed || current?.testOutcome === 'interrupted') {
|
|
548
|
+
for (const { phase, message, stack } of runErrors) {
|
|
549
|
+
if (phase !== 'process' && phase !== 'unhandled')
|
|
550
|
+
continue;
|
|
551
|
+
if (!runnerErrors.some((error) => error?.phase === phase && error?.message === message)) {
|
|
552
|
+
runnerErrors.push({ phase, message, ...(stack ? { stack } : {}) });
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const result = {
|
|
557
|
+
...(current ?? {}),
|
|
558
|
+
runId: typeof current?.runId === 'string' ? current.runId : runId,
|
|
559
|
+
testId: typeof current?.testId === 'string' ? current.testId : testEntry.name,
|
|
560
|
+
testName: typeof current?.testName === 'string' ? current.testName : testEntry.name,
|
|
561
|
+
attemptId: typeof current?.attemptId === 'string' ? current.attemptId : attemptEntry.name,
|
|
562
|
+
status: completed ? current.status : 'interrupted',
|
|
563
|
+
attemptOutcome: completed ? current.attemptOutcome : 'interrupted',
|
|
564
|
+
testOutcome: completed ? current.testOutcome : 'interrupted',
|
|
565
|
+
expectedFailure: current?.expectedFailure === true,
|
|
566
|
+
flaky: current?.flaky === true,
|
|
567
|
+
...(runnerErrors.length ? { runnerErrors } : {}),
|
|
568
|
+
evidenceStatus: !completed || recovered?.issues.length ? 'partial' : current.evidenceStatus,
|
|
569
|
+
evidenceIssues: [...new Set([...(Array.isArray(current?.evidenceIssues) ? current.evidenceIssues : []),
|
|
570
|
+
...(recovered?.issues ?? []),
|
|
571
|
+
...(!completed ? ['Attempt interrupted before finalization; only flushed evidence is available.'] : [])])],
|
|
572
|
+
operations: Array.isArray(current?.operations) ? current.operations.map((operation) => {
|
|
573
|
+
if (!operation || typeof operation !== 'object' || !('outcome' in operation) || operation.outcome !== 'running')
|
|
574
|
+
return operation;
|
|
575
|
+
return { ...operation, outcome: 'interrupted', endedAt: interruptedAt };
|
|
576
|
+
}) : [],
|
|
577
|
+
evidence: Array.isArray(current?.evidence) ? current.evidence : [],
|
|
578
|
+
};
|
|
579
|
+
const temporary = `${resultPath}.${process.pid}.interrupted.tmp`;
|
|
580
|
+
await writeFile(temporary, `${JSON.stringify(result, null, 2)}\n`, 'utf8');
|
|
581
|
+
await rename(temporary, resultPath);
|
|
582
|
+
const timelinePath = join(attemptsDir, attemptEntry.name, TIMELINE_FILE_NAME);
|
|
583
|
+
const snapshot = parseTimelineData(await readFile(timelinePath, 'utf8').catch(() => ''));
|
|
584
|
+
const timeline = snapshotFinalized && snapshot ? snapshot : recovered?.timeline ? { ...recovered.timeline,
|
|
585
|
+
nodes: mergeFacts(snapshot?.nodes, recovered.timeline.nodes, 'id'),
|
|
586
|
+
} : snapshot;
|
|
587
|
+
if (timeline) {
|
|
588
|
+
if (!completed) {
|
|
589
|
+
timeline.status = 'interrupted';
|
|
590
|
+
timeline.endedAt = interruptedAt;
|
|
591
|
+
}
|
|
592
|
+
for (const node of timeline.nodes)
|
|
593
|
+
if (!completed && node.status === 'running') {
|
|
594
|
+
node.status = 'interrupted';
|
|
595
|
+
node.endedAt = interruptedAt;
|
|
596
|
+
}
|
|
597
|
+
const timelineTemp = `${timelinePath}.${process.pid}.interrupted.tmp`;
|
|
598
|
+
await writeFile(timelineTemp, `${JSON.stringify(timeline, null, 2)}\n`, 'utf8');
|
|
599
|
+
await rename(timelineTemp, timelinePath);
|
|
600
|
+
const traceDir = join(attemptsDir, attemptEntry.name, 'trace');
|
|
601
|
+
await mkdir(traceDir, { recursive: true });
|
|
602
|
+
const tracePath = join(traceDir, 'trace.json');
|
|
603
|
+
const traceTemp = `${tracePath}.${process.pid}.interrupted.tmp`;
|
|
604
|
+
await writeFile(traceTemp, JSON.stringify(projectRunTrace(result, timeline)), 'utf8');
|
|
605
|
+
await rename(traceTemp, tracePath);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
function mergeFacts(snapshot, journal, key) {
|
|
611
|
+
const facts = new Map();
|
|
612
|
+
for (const value of [...(Array.isArray(snapshot) ? snapshot : []), ...journal]) {
|
|
613
|
+
if (typeof value === 'object' && value !== null && key in value)
|
|
614
|
+
facts.set(value[key], value);
|
|
615
|
+
}
|
|
616
|
+
return [...facts.values()];
|
|
617
|
+
}
|
|
618
|
+
async function readTimelineSummaries(runsRoot, runId) {
|
|
619
|
+
const entries = await findTimelineFiles(runsRoot, runId);
|
|
620
|
+
const summaries = [];
|
|
621
|
+
const agentVisibleFailures = [];
|
|
622
|
+
for (const path of entries) {
|
|
623
|
+
const timeline = parseTimelineData(await readFile(path, 'utf8').catch(() => ''));
|
|
624
|
+
if (!timeline)
|
|
625
|
+
continue;
|
|
626
|
+
// Failure app-state paths belong to the attempt, while the report belongs
|
|
627
|
+
// to the run. Resolve their base before projecting them into the report.
|
|
628
|
+
for (const ref of artifactReferences({ agentVisibleFailures: timeline.agentVisibleFailures }, 'report')) {
|
|
629
|
+
ref.set(resolve(dirname(path), ref.path));
|
|
630
|
+
}
|
|
631
|
+
const summary = summarizeTimeline(timeline);
|
|
632
|
+
summaries.push({ path, ...summary });
|
|
633
|
+
agentVisibleFailures.push(...(timeline.agentVisibleFailures ?? []));
|
|
634
|
+
}
|
|
635
|
+
return { timelines: summaries, agentVisibleFailures };
|
|
636
|
+
}
|
|
637
|
+
async function findTimelineFiles(runsRoot, runId) {
|
|
638
|
+
const runDir = join(runsRoot, runId);
|
|
639
|
+
try {
|
|
640
|
+
const manifest = JSON.parse(await readFile(join(runDir, 'run.json'), 'utf8'));
|
|
641
|
+
return manifest.tests.flatMap((test) => test.attempts.map((attempt) => join(runDir, dirname(attempt.resultPath), TIMELINE_FILE_NAME)));
|
|
642
|
+
}
|
|
643
|
+
catch {
|
|
644
|
+
return [];
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
async function persistScreenshots(failures, outputDir, screenshotMode, screenshots) {
|
|
648
|
+
if (screenshotMode !== 'file')
|
|
649
|
+
return failures;
|
|
650
|
+
const screenshotDir = join(outputDir, 'screenshots');
|
|
651
|
+
await mkdir(screenshotDir, { recursive: true });
|
|
652
|
+
const persisted = [];
|
|
653
|
+
for (let index = 0; index < failures.length; index++) {
|
|
654
|
+
const failure = failures[index];
|
|
655
|
+
const existingPath = failure.screenshot?.path;
|
|
656
|
+
if (existingPath) {
|
|
657
|
+
screenshots.push(existingPath);
|
|
658
|
+
persisted.push(failure);
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
const base64 = failure.screenshot?.base64;
|
|
662
|
+
if (!base64) {
|
|
663
|
+
persisted.push(failure);
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
const filename = `${index + 1}-${safeFilename(failure.testName)}.png`;
|
|
667
|
+
const path = join(screenshotDir, filename);
|
|
668
|
+
await writeFile(path, Buffer.from(base64, 'base64'));
|
|
669
|
+
screenshots.push(path);
|
|
670
|
+
persisted.push({
|
|
671
|
+
...failure,
|
|
672
|
+
screenshot: {
|
|
673
|
+
mimeType: 'image/png',
|
|
674
|
+
path,
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
return persisted;
|
|
679
|
+
}
|
|
680
|
+
function createRunId() {
|
|
681
|
+
return `run-${new Date().toISOString().replace(/[:.]/g, '-')}`;
|
|
682
|
+
}
|
|
683
|
+
function safeFilename(value) {
|
|
684
|
+
return value.replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 80) || 'failure';
|
|
685
|
+
}
|
|
686
|
+
function buildReproduceCommand(testPattern, testName) {
|
|
687
|
+
const parts = ['fliwright run', '--test', shellQuote(testPattern)];
|
|
688
|
+
if (testName)
|
|
689
|
+
parts.push('--test-name', shellQuote(testName));
|
|
690
|
+
return parts.join(' ');
|
|
691
|
+
}
|
|
692
|
+
function shellQuote(value) {
|
|
693
|
+
if (/^[a-zA-Z0-9_./:@=-]+$/.test(value))
|
|
694
|
+
return value;
|
|
695
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
696
|
+
}
|
|
697
|
+
function formatOutput(result, reporter) {
|
|
698
|
+
switch (reporter) {
|
|
699
|
+
case 'json':
|
|
700
|
+
return formatJson(result);
|
|
701
|
+
case 'junit':
|
|
702
|
+
return formatJunit(result);
|
|
703
|
+
case 'pretty':
|
|
704
|
+
default:
|
|
705
|
+
return formatPretty(result);
|
|
706
|
+
}
|
|
707
|
+
}
|