@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,81 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { resolveProjectConfig } from '../config.js';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { isAbsolute, dirname, resolve, relative } from 'node:path';
|
|
6
|
+
import { AiRuntime, PassiveAgent, TimelineRecorder, buildFlowFromTimeline, resolveAiConfig } from '@fliwright/core';
|
|
7
|
+
import { artifactPathIssue, artifactsShowCommand } from './artifacts.js';
|
|
8
|
+
export async function artifactsFailuresCommand(options) {
|
|
9
|
+
const shown = await artifactsShowCommand(options);
|
|
10
|
+
const report = shown.report;
|
|
11
|
+
let entries = report?.failures ?? [];
|
|
12
|
+
if (!report && shown.runId && shown.manifest) {
|
|
13
|
+
const root = resolve(shown.runsRoot, shown.runId);
|
|
14
|
+
const manifest = shown.manifest;
|
|
15
|
+
entries = [];
|
|
16
|
+
for (const attempt of manifest.tests?.flatMap((test) => test.attempts) ?? []) {
|
|
17
|
+
const resultPath = resolve(root, attempt.resultPath);
|
|
18
|
+
if (await artifactPathIssue(root, resultPath))
|
|
19
|
+
continue;
|
|
20
|
+
const result = JSON.parse(await readFile(resultPath, 'utf8'));
|
|
21
|
+
if (!result.failureContextPath)
|
|
22
|
+
continue;
|
|
23
|
+
const path = resolve(dirname(resultPath), result.failureContextPath);
|
|
24
|
+
if (await artifactPathIssue(dirname(resultPath), path))
|
|
25
|
+
continue;
|
|
26
|
+
entries.push(...JSON.parse(await readFile(path, 'utf8')));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const failures = entries.filter((failure) => !options.testName || failure.testName === options.testName);
|
|
30
|
+
return { runId: shown.runId, failures, runnerErrors: report?.runnerErrors ?? [], evidenceStatus: shown.manifest?.evidenceStatus };
|
|
31
|
+
}
|
|
32
|
+
export async function artifactsTimelineCommand(options) {
|
|
33
|
+
let path;
|
|
34
|
+
if (options.path)
|
|
35
|
+
path = resolve(options.cwd ?? process.cwd(), options.path);
|
|
36
|
+
else {
|
|
37
|
+
const shown = await artifactsShowCommand(options);
|
|
38
|
+
if (!shown.runId)
|
|
39
|
+
throw new Error('No run is available. Specify runId or path.');
|
|
40
|
+
const root = resolve(shown.runsRoot, shown.runId);
|
|
41
|
+
const manifest = shown.manifest;
|
|
42
|
+
const candidates = manifest?.tests?.filter((test) => !options.testId || test.testId === options.testId)
|
|
43
|
+
.flatMap((test) => test.attempts.filter((attempt) => !options.attemptId || attempt.attemptId === options.attemptId)
|
|
44
|
+
.map((attempt) => resolve(root, dirname(attempt.resultPath), 'timeline.json'))) ?? [];
|
|
45
|
+
const fallback = shown.report?.artifacts?.timelines ?? [];
|
|
46
|
+
const paths = candidates.length ? candidates : fallback.map((entry) => isAbsolute(entry) ? entry : resolve(root, entry));
|
|
47
|
+
if (paths.length !== 1)
|
|
48
|
+
throw new Error(paths.length ? 'Multiple timelines exist; specify testId/attemptId or path.' : 'No timeline is available.');
|
|
49
|
+
path = paths[0];
|
|
50
|
+
const rel = relative(root, path);
|
|
51
|
+
if (rel.startsWith('..') || isAbsolute(rel) || await artifactPathIssue(root, path))
|
|
52
|
+
throw new Error('Timeline reference escapes the run directory.');
|
|
53
|
+
}
|
|
54
|
+
const timeline = JSON.parse(await readFile(path, 'utf8'));
|
|
55
|
+
if (!Array.isArray(timeline.nodes))
|
|
56
|
+
throw new Error('Invalid timeline document.');
|
|
57
|
+
const nodes = options.includeArtifacts ? timeline.nodes : timeline.nodes.map(({ artifacts: _artifacts, ...rest }) => rest);
|
|
58
|
+
const flow = options.includeFlow ? buildFlowFromTimeline({ timeline }) : undefined;
|
|
59
|
+
if (!options.nodeId)
|
|
60
|
+
return { path, timeline: { ...timeline, nodes }, flow };
|
|
61
|
+
const index = nodes.findIndex((node) => node.id === options.nodeId);
|
|
62
|
+
if (index < 0)
|
|
63
|
+
throw new Error(`Timeline node not found: ${options.nodeId}`);
|
|
64
|
+
const node = nodes[index];
|
|
65
|
+
return { path, node, parent: nodes.find((entry) => entry.id === node.parentId), children: nodes.filter((entry) => entry.parentId === node.id), previous: nodes[index - 1], next: nodes[index + 1], flow };
|
|
66
|
+
}
|
|
67
|
+
export async function artifactsDiagnoseCommand(options) {
|
|
68
|
+
const found = options.failure && !options.path && !options.runId ? undefined : await artifactsTimelineCommand({ ...options, includeArtifacts: true });
|
|
69
|
+
const timeline = found && 'timeline' in found ? found.timeline : undefined;
|
|
70
|
+
const failure = options.failure ? { ...options.failure, recoveryHints: [] } : timeline?.agentVisibleFailures?.[options.failureIndex ?? 0];
|
|
71
|
+
if (!failure)
|
|
72
|
+
throw new Error('No agent-visible failure is available.');
|
|
73
|
+
const recorder = new TimelineRecorder({ runId: timeline?.runId ?? 'cli-diagnosis', testName: timeline?.testName ?? 'CLI diagnosis' });
|
|
74
|
+
const config = await resolveProjectConfig(options.cwd ?? process.cwd());
|
|
75
|
+
const aiRuntime = new AiRuntime(resolveAiConfig({ artifactsDir: join(config.cacheRoot, 'inspect', randomUUID(), 'ai') }), { runId: recorder.runId, testName: recorder.testName });
|
|
76
|
+
const agent = new PassiveAgent({ aiRuntime, recorder, passive: true });
|
|
77
|
+
const currentNode = timeline?.nodes.find((node) => node.id === failure.timelineNodeId);
|
|
78
|
+
const diagnosis = await agent.diagnose(failure, { currentNode, recentNodes: timeline?.nodes.slice(-8), artifacts: currentNode?.artifacts,
|
|
79
|
+
allowedTools: ['fliwright artifacts timeline', 'fliwright app snapshot', 'fliwright app observe'] });
|
|
80
|
+
return { diagnosis, skipped: !diagnosis };
|
|
81
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface ArtifactOptions {
|
|
2
|
+
cwd?: string;
|
|
3
|
+
runsRoot?: string;
|
|
4
|
+
runId?: string;
|
|
5
|
+
allowPartial?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function artifactsShowCommand(options?: ArtifactOptions): Promise<{
|
|
8
|
+
runsRoot: string;
|
|
9
|
+
runs: {
|
|
10
|
+
runId: string;
|
|
11
|
+
modifiedAt: string;
|
|
12
|
+
}[];
|
|
13
|
+
report: null;
|
|
14
|
+
reportIssue: string | undefined;
|
|
15
|
+
runId?: undefined;
|
|
16
|
+
reportPath?: undefined;
|
|
17
|
+
manifest?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
runsRoot: string;
|
|
20
|
+
runId: string;
|
|
21
|
+
reportPath: string;
|
|
22
|
+
report: {} | null;
|
|
23
|
+
reportIssue: string | undefined;
|
|
24
|
+
manifest: {} | null;
|
|
25
|
+
runs: {
|
|
26
|
+
runId: string;
|
|
27
|
+
modifiedAt: string;
|
|
28
|
+
}[];
|
|
29
|
+
}>;
|
|
30
|
+
export declare function artifactsExportCommand(options: ArtifactOptions & {
|
|
31
|
+
output: string;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
runId: string;
|
|
34
|
+
source: string;
|
|
35
|
+
output: string;
|
|
36
|
+
partial: boolean;
|
|
37
|
+
missing: string[];
|
|
38
|
+
}>;
|
|
39
|
+
/** Resolve symlinks as well as lexical paths before reading or copying evidence. */
|
|
40
|
+
export declare function artifactPathIssue(boundary: string, target: string): Promise<'path escape' | 'missing' | 'not a file' | undefined>;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { cp, mkdir, readdir, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
3
|
+
import { ensureFliwrightRunsRoot, runManifestSchema, RunArtifactStore, recoverRunProgress } from '@fliwright/core';
|
|
4
|
+
import { resolveProjectConfig } from '../config.js';
|
|
5
|
+
import { artifactReferences, relativeArtifactPath } from '../ArtifactReferences.js';
|
|
6
|
+
export async function artifactsShowCommand(options = {}) {
|
|
7
|
+
const { runsRoot, runs } = await listRuns(options);
|
|
8
|
+
const runId = options.runId ?? runs[0]?.runId;
|
|
9
|
+
if (!runId)
|
|
10
|
+
return { runsRoot, runs, report: null, reportIssue: undefined };
|
|
11
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(runId))
|
|
12
|
+
throw new Error('Invalid runId.');
|
|
13
|
+
const runDir = join(runsRoot, runId);
|
|
14
|
+
const reportPath = join(runDir, 'report.json');
|
|
15
|
+
let report;
|
|
16
|
+
let reportIssue;
|
|
17
|
+
try {
|
|
18
|
+
report = await readJsonIfPresent(reportPath);
|
|
19
|
+
if (report !== undefined && !isRecord(report))
|
|
20
|
+
throw new Error('Canonical report must be an object.');
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
report = undefined;
|
|
24
|
+
reportIssue = 'report.json (unreadable)';
|
|
25
|
+
if (!options.allowPartial)
|
|
26
|
+
throw new Error(`Cannot read ${reportIssue}.`, { cause: error });
|
|
27
|
+
}
|
|
28
|
+
const manifest = await readJsonIfPresent(join(runDir, 'run.json'));
|
|
29
|
+
if (report === undefined && manifest === undefined) {
|
|
30
|
+
throw new Error(`Run '${runId}' has neither canonical report.json nor run.json manifest.`);
|
|
31
|
+
}
|
|
32
|
+
return { runsRoot, runId, reportPath, report: report ?? null, reportIssue, manifest: manifest ?? null, runs };
|
|
33
|
+
}
|
|
34
|
+
export async function artifactsExportCommand(options) {
|
|
35
|
+
const shown = await artifactsShowCommand(options);
|
|
36
|
+
if (!shown.runId)
|
|
37
|
+
throw new Error('No Fliwright run artifacts found to export.');
|
|
38
|
+
const source = join(shown.runsRoot, shown.runId);
|
|
39
|
+
const output = resolve(options.cwd ?? process.cwd(), options.output);
|
|
40
|
+
try {
|
|
41
|
+
await stat(output);
|
|
42
|
+
throw new Error(`Artifact export destination already exists: ${output}`);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (error instanceof Error && !('code' in error))
|
|
46
|
+
throw error;
|
|
47
|
+
if (typeof error === 'object' && error && 'code' in error && error.code !== 'ENOENT')
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
const manifest = runManifestSchema.safeParse(shown.manifest);
|
|
51
|
+
if (!manifest.success)
|
|
52
|
+
throw new Error('Cannot export without a valid run.json manifest.');
|
|
53
|
+
{
|
|
54
|
+
const missing = await validateManifestFiles(source, manifest.data);
|
|
55
|
+
if (shown.reportIssue)
|
|
56
|
+
missing.push(shown.reportIssue);
|
|
57
|
+
if (manifest.data.evidenceStatus === 'partial')
|
|
58
|
+
missing.push('run.json (evidence is partial)');
|
|
59
|
+
if (manifest.data.status === 'running' || manifest.data.status === 'interrupted')
|
|
60
|
+
missing.push(`run.json (run is ${manifest.data.status})`);
|
|
61
|
+
const documents = await readArtifactDocuments(source, manifest.data, shown.report);
|
|
62
|
+
const rewrites = new Map();
|
|
63
|
+
const referencedFiles = new Set();
|
|
64
|
+
for (const document of documents) {
|
|
65
|
+
if (document.data === undefined) {
|
|
66
|
+
missing.push(`${document.path} (unreadable)`);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const original = JSON.stringify(document.data);
|
|
70
|
+
const base = document.kind === 'report' ? source : dirname(resolve(source, document.path));
|
|
71
|
+
// Trace paths can use ../ to point back to the owning attempt.
|
|
72
|
+
const boundary = document.kind === 'report' ? source : document.attemptDir;
|
|
73
|
+
for (const ref of artifactReferences(document.data, document.kind)) {
|
|
74
|
+
const target = resolve(base, ref.path);
|
|
75
|
+
const portable = relativeArtifactPath(boundary, target);
|
|
76
|
+
const runRelative = relativeArtifactPath(source, target);
|
|
77
|
+
const issue = await artifactPathIssue(boundary, target);
|
|
78
|
+
if (portable === undefined || runRelative === undefined || issue === 'path escape') {
|
|
79
|
+
missing.push(`${document.path}:${ref.path} (path escape)`);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (issue)
|
|
83
|
+
missing.push(`${document.path}:${ref.path} (${issue})`);
|
|
84
|
+
else
|
|
85
|
+
referencedFiles.add(runRelative);
|
|
86
|
+
ref.set(document.kind === 'report' ? runRelative || '.' : relative(base, target).split('\\').join('/'));
|
|
87
|
+
}
|
|
88
|
+
if (document.kind === 'report' && isRecord(document.data) && isRecord(document.data.artifacts)) {
|
|
89
|
+
document.data.artifacts.outputDir = '.';
|
|
90
|
+
}
|
|
91
|
+
if (JSON.stringify(document.data) !== original)
|
|
92
|
+
rewrites.set(document.path, `${JSON.stringify(document.data, null, 2)}\n`);
|
|
93
|
+
}
|
|
94
|
+
const canonicalReportExists = await exists(join(source, 'report.json'));
|
|
95
|
+
if ((!canonicalReportExists || missing.length > 0) && !options.allowPartial) {
|
|
96
|
+
throw new Error(`Run export is incomplete. Missing: ${[
|
|
97
|
+
...(!canonicalReportExists ? ['report.json'] : []),
|
|
98
|
+
...missing,
|
|
99
|
+
].join(', ')}`);
|
|
100
|
+
}
|
|
101
|
+
const partial = !canonicalReportExists || missing.length > 0;
|
|
102
|
+
if (partial) {
|
|
103
|
+
rewrites.set('run.json', `${JSON.stringify({ ...manifest.data, evidenceStatus: 'partial' }, null, 2)}\n`);
|
|
104
|
+
rewrites.set('export.json', `${JSON.stringify({ schemaVersion: 1, runId: shown.runId, partial, missing }, null, 2)}\n`);
|
|
105
|
+
}
|
|
106
|
+
const files = new Set([
|
|
107
|
+
'run.json',
|
|
108
|
+
...(partial ? ['export.json'] : []),
|
|
109
|
+
...(canonicalReportExists ? ['report.json'] : []),
|
|
110
|
+
...(await manifestAttemptFiles(source, manifest.data)),
|
|
111
|
+
...referencedFiles,
|
|
112
|
+
]);
|
|
113
|
+
await publishFilesAtomically(source, output, files, rewrites);
|
|
114
|
+
return { runId: shown.runId, source, output, partial, missing };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function readArtifactDocuments(source, manifest, report) {
|
|
118
|
+
const documents = report ? [{ path: 'report.json', kind: 'report', data: report }] : [];
|
|
119
|
+
for (const attempt of manifest.tests.flatMap((test) => test.attempts.map((attempt) => ({ ...attempt, testId: test.testId })))) {
|
|
120
|
+
const resultPath = resolve(source, attempt.resultPath);
|
|
121
|
+
if (await artifactPathIssue(source, resultPath))
|
|
122
|
+
continue;
|
|
123
|
+
const attemptDir = dirname(resultPath);
|
|
124
|
+
let result;
|
|
125
|
+
try {
|
|
126
|
+
result = JSON.parse(await readFile(resultPath, 'utf8'));
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!isRecord(result))
|
|
132
|
+
continue;
|
|
133
|
+
documents.push({ path: attempt.resultPath, kind: 'result', data: result, attemptDir });
|
|
134
|
+
const context = isRecord(result) && typeof result.failureContextPath === 'string' ? result.failureContextPath : undefined;
|
|
135
|
+
const children = [
|
|
136
|
+
{ name: 'timeline.json', kind: 'timeline' },
|
|
137
|
+
{ name: 'trace/trace.json', kind: 'trace' },
|
|
138
|
+
...(context ? [{ name: context, kind: 'failures' }] : []),
|
|
139
|
+
];
|
|
140
|
+
for (const child of children) {
|
|
141
|
+
const target = resolve(attemptDir, child.name);
|
|
142
|
+
const issue = await artifactPathIssue(attemptDir, target);
|
|
143
|
+
if (issue)
|
|
144
|
+
continue;
|
|
145
|
+
try {
|
|
146
|
+
documents.push({ path: relative(source, target), kind: child.kind,
|
|
147
|
+
data: JSON.parse(await readFile(target, 'utf8')), attemptDir });
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
documents.push({ path: relative(source, target), kind: child.kind, data: undefined, attemptDir });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return documents;
|
|
155
|
+
}
|
|
156
|
+
function isRecord(value) {
|
|
157
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
158
|
+
}
|
|
159
|
+
async function readJsonIfPresent(path) {
|
|
160
|
+
try {
|
|
161
|
+
return JSON.parse(await readFile(path, 'utf8'));
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT')
|
|
165
|
+
return undefined;
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async function validateManifestFiles(source, manifest) {
|
|
170
|
+
const missing = [];
|
|
171
|
+
const store = new RunArtifactStore({ runsRoot: dirname(source), runId: manifest.runId });
|
|
172
|
+
for (const attempt of manifest.tests.flatMap((test) => test.attempts.map((attempt) => ({ ...attempt, testId: test.testId })))) {
|
|
173
|
+
const target = resolve(source, attempt.resultPath);
|
|
174
|
+
const issue = await artifactPathIssue(source, target);
|
|
175
|
+
if (issue) {
|
|
176
|
+
missing.push(issue === 'path escape' ? `${attempt.resultPath} (path escape)` : attempt.resultPath);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
const result = JSON.parse(await readFile(target, 'utf8'));
|
|
181
|
+
if (!isRecord(result))
|
|
182
|
+
throw new Error('Attempt result must be an object.');
|
|
183
|
+
if (typeof result.eventsPath === 'string') {
|
|
184
|
+
const eventsPath = resolve(dirname(target), result.eventsPath);
|
|
185
|
+
const journalIssue = await artifactPathIssue(dirname(target), eventsPath);
|
|
186
|
+
if (!journalIssue) {
|
|
187
|
+
try {
|
|
188
|
+
const recovered = recoverRunProgress(await store.readEvents(eventsPath), {
|
|
189
|
+
runId: manifest.runId, testId: attempt.testId, attemptId: attempt.attemptId,
|
|
190
|
+
});
|
|
191
|
+
for (const issue of recovered.issues)
|
|
192
|
+
missing.push(`${attempt.resultPath}:${result.eventsPath} (${issue})`);
|
|
193
|
+
if (!recovered.finalized)
|
|
194
|
+
missing.push(`${attempt.resultPath}:${result.eventsPath} (not finalized)`);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
missing.push(`${attempt.resultPath}:${result.eventsPath} (unreadable)`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (result.evidenceStatus === 'complete' || result.evidenceStatus === 'partial') {
|
|
202
|
+
for (const file of ['timeline.json', 'trace/trace.json']) {
|
|
203
|
+
const path = resolve(dirname(target), file);
|
|
204
|
+
const issue = await artifactPathIssue(dirname(target), path);
|
|
205
|
+
if (issue)
|
|
206
|
+
missing.push(`${join(dirname(attempt.resultPath), file)}${issue === 'path escape' ? ' (path escape)' : ''}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (typeof result.failureContextPath === 'string') {
|
|
210
|
+
const attemptDir = dirname(target);
|
|
211
|
+
const contextPath = resolve(attemptDir, result.failureContextPath);
|
|
212
|
+
const contextIssue = await artifactPathIssue(attemptDir, contextPath);
|
|
213
|
+
if (contextIssue === 'path escape') {
|
|
214
|
+
missing.push(`${attempt.resultPath}:${result.failureContextPath} (path escape)`);
|
|
215
|
+
}
|
|
216
|
+
else if (contextIssue) {
|
|
217
|
+
missing.push(join(dirname(attempt.resultPath), result.failureContextPath));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
missing.push(`${attempt.resultPath} (unreadable)`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return missing;
|
|
226
|
+
}
|
|
227
|
+
async function manifestAttemptFiles(source, manifest) {
|
|
228
|
+
const files = [];
|
|
229
|
+
for (const attempt of manifest.tests.flatMap((test) => test.attempts)) {
|
|
230
|
+
const resultPath = resolve(source, attempt.resultPath);
|
|
231
|
+
if (await artifactPathIssue(source, resultPath))
|
|
232
|
+
continue;
|
|
233
|
+
if (!(await exists(resultPath)))
|
|
234
|
+
continue;
|
|
235
|
+
for (const file of await walkFiles(dirname(resultPath))) {
|
|
236
|
+
const fileRelative = relative(source, file);
|
|
237
|
+
if (fileRelative.startsWith('..') || isAbsolute(fileRelative))
|
|
238
|
+
continue;
|
|
239
|
+
files.push(fileRelative.split('\\').join('/'));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return files;
|
|
243
|
+
}
|
|
244
|
+
async function walkFiles(directory) {
|
|
245
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
246
|
+
const files = [];
|
|
247
|
+
for (const entry of entries) {
|
|
248
|
+
const path = join(directory, entry.name);
|
|
249
|
+
if (entry.isDirectory())
|
|
250
|
+
files.push(...await walkFiles(path));
|
|
251
|
+
else if (entry.isFile())
|
|
252
|
+
files.push(path);
|
|
253
|
+
}
|
|
254
|
+
return files;
|
|
255
|
+
}
|
|
256
|
+
async function publishFilesAtomically(source, output, files, rewrites = new Map()) {
|
|
257
|
+
const temporary = `${output}.tmp-${process.pid}-${Date.now()}`;
|
|
258
|
+
try {
|
|
259
|
+
await mkdir(temporary, { recursive: true });
|
|
260
|
+
for (const file of files) {
|
|
261
|
+
const sourcePath = resolve(source, file);
|
|
262
|
+
const destinationPath = join(temporary, file);
|
|
263
|
+
await mkdir(dirname(destinationPath), { recursive: true });
|
|
264
|
+
const rewritten = rewrites.get(file);
|
|
265
|
+
if (rewritten !== undefined)
|
|
266
|
+
await writeFile(destinationPath, rewritten, 'utf8');
|
|
267
|
+
else if (await exists(sourcePath))
|
|
268
|
+
await cp(sourcePath, destinationPath, { dereference: true });
|
|
269
|
+
}
|
|
270
|
+
await rename(temporary, output);
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
await rm(temporary, { recursive: true, force: true });
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async function exists(path) {
|
|
278
|
+
try {
|
|
279
|
+
await stat(path);
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/** Resolve symlinks as well as lexical paths before reading or copying evidence. */
|
|
287
|
+
export async function artifactPathIssue(boundary, target) {
|
|
288
|
+
if (relativeArtifactPath(boundary, target) === undefined)
|
|
289
|
+
return 'path escape';
|
|
290
|
+
try {
|
|
291
|
+
const [actualBoundary, actualTarget] = await Promise.all([realpath(boundary), realpath(target)]);
|
|
292
|
+
if (relativeArtifactPath(actualBoundary, actualTarget) === undefined)
|
|
293
|
+
return 'path escape';
|
|
294
|
+
return (await stat(actualTarget)).isFile() ? undefined : 'not a file';
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
return 'missing';
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async function listRuns(options) {
|
|
301
|
+
const cwd = options.cwd ?? process.cwd();
|
|
302
|
+
const config = await resolveProjectConfig(cwd, { runsRoot: options.runsRoot });
|
|
303
|
+
const runsRoot = await ensureFliwrightRunsRoot({ runsRoot: config.runsRoot });
|
|
304
|
+
const entries = await readdir(runsRoot, { withFileTypes: true });
|
|
305
|
+
const runs = await Promise.all(entries.filter((entry) => entry.isDirectory()).map(async (entry) => ({
|
|
306
|
+
runId: basename(entry.name),
|
|
307
|
+
modifiedAt: (await stat(join(runsRoot, entry.name))).mtime.toISOString(),
|
|
308
|
+
})));
|
|
309
|
+
runs.sort((left, right) => right.modifiedAt.localeCompare(left.modifiedAt));
|
|
310
|
+
return { runsRoot, runs };
|
|
311
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface CheckResult {
|
|
2
|
+
name: string;
|
|
3
|
+
passed: boolean;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
export interface DoctorOptions {
|
|
7
|
+
vmServiceUrl?: string;
|
|
8
|
+
print?: boolean;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
export declare function doctorCommand(projectDir: string, options?: DoctorOptions): Promise<CheckResult[]>;
|