@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,216 @@
|
|
|
1
|
+
import { resolveVmUrl } from '../vm-discovery.js';
|
|
2
|
+
import { resolveProjectConfig } from '../config.js';
|
|
3
|
+
import { verifyRecordingReplay } from '../RecordingReplay.js';
|
|
4
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { randomUUID } from 'node:crypto';
|
|
6
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
7
|
+
import { copyRecordingArtifacts, applyDartVerification, parseDartVerificationEvidence, fingerprintScenario, generateRecordingAutomation, buildFlowFromRecording, captureRecording, openRecordingCapture, ScenarioResolver, EndpointLeaseManager } from '@fliwright/core';
|
|
8
|
+
export async function recordCommand(options, deps = {}) {
|
|
9
|
+
const cwd = options.cwd ?? process.cwd();
|
|
10
|
+
const dartVerification = options.dartVerificationFile
|
|
11
|
+
? parseDartVerificationEvidence(JSON.parse(await readFile(resolve(cwd, options.dartVerificationFile), 'utf8')))
|
|
12
|
+
: options.dartVerification;
|
|
13
|
+
const config = await resolveProjectConfig(cwd);
|
|
14
|
+
const resolver = deps.resolveVmUrl ?? resolveVmUrl;
|
|
15
|
+
const vmUrl = await resolver({ cliFlag: options.vmUrl, configUrl: config.vmServiceUrl, cwd, verify: true });
|
|
16
|
+
if (!vmUrl) {
|
|
17
|
+
throw new Error('Could not find a running Flutter VM Service.\n\n' +
|
|
18
|
+
' Start your Flutter app first: flutter run\n' +
|
|
19
|
+
' Then re-run: fliwright record\n' +
|
|
20
|
+
' Or specify: fliwright record --vm-url ws://127.0.0.1:8181/ws');
|
|
21
|
+
}
|
|
22
|
+
const lang = options.lang ?? 'ts';
|
|
23
|
+
const testName = options.testName ?? 'recorded test';
|
|
24
|
+
const mode = options.mode ?? 'script';
|
|
25
|
+
let scenarioFingerprint;
|
|
26
|
+
let scenarioIssue;
|
|
27
|
+
if (options.scenario) {
|
|
28
|
+
try {
|
|
29
|
+
scenarioFingerprint = fingerprintScenario(new ScenarioResolver(config.scenarios ?? {}).resolve(options.scenario));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
scenarioIssue = `unknown deterministic scenario '${options.scenario}'`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const generatedTarget = options.output ? resolve(cwd, options.output)
|
|
36
|
+
: defaultGeneratedTarget(cwd, mode, testName, lang, config.paths);
|
|
37
|
+
const log = options.print === false ? () => { } : console.error;
|
|
38
|
+
log('Recording... Press Ctrl+C to stop.');
|
|
39
|
+
const checkpointInput = options.assertions
|
|
40
|
+
? await readCheckpointFile(resolve(cwd, options.assertions))
|
|
41
|
+
: undefined;
|
|
42
|
+
const codegenOptions = {
|
|
43
|
+
lang, testName, mode,
|
|
44
|
+
dartAppEntrypoint: options.dartAppEntrypoint,
|
|
45
|
+
resetToHomeBeforeEach: options.resetToHomeBeforeEach ?? lang === 'ts',
|
|
46
|
+
homeRoute: options.homeRoute,
|
|
47
|
+
};
|
|
48
|
+
const lease = await recordingLeases.acquire(vmUrl, { signal: options.signal });
|
|
49
|
+
const captured = await lease.run(() => captureRecording({
|
|
50
|
+
open: () => (deps.openCapture ?? openRecordingCapture)(vmUrl),
|
|
51
|
+
signal: options.signal,
|
|
52
|
+
durationMs: options.durationMs,
|
|
53
|
+
waitForStop: deps.waitForStop ?? waitForSigint,
|
|
54
|
+
start: {
|
|
55
|
+
captureScreenshots: true,
|
|
56
|
+
filterNoise: true,
|
|
57
|
+
onOperation: (op, index) => {
|
|
58
|
+
// Input contents may be sensitive. Progress only needs the action kind.
|
|
59
|
+
log(` ${index + 1}. ${op.kind}`);
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
generate: codegenOptions,
|
|
63
|
+
})).finally(() => lease.release());
|
|
64
|
+
const generated = generateRecordingAutomation(captured, {
|
|
65
|
+
...codegenOptions, checkpoints: checkpointInput, scenarioName: options.scenario, scenarioFingerprint,
|
|
66
|
+
});
|
|
67
|
+
const recordingResult = generated.recording;
|
|
68
|
+
const { code: finalCode, operations, frames } = recordingResult;
|
|
69
|
+
const flow = buildFlowFromRecording({
|
|
70
|
+
frames,
|
|
71
|
+
operations,
|
|
72
|
+
testName,
|
|
73
|
+
targetFile: generatedTarget,
|
|
74
|
+
});
|
|
75
|
+
const readiness = generated.readiness;
|
|
76
|
+
let verifiedRunId;
|
|
77
|
+
let replayRunId;
|
|
78
|
+
const blockers = [
|
|
79
|
+
...readiness.issues,
|
|
80
|
+
...((mode === 'test' || options.verify) && scenarioIssue ? [scenarioIssue] : []),
|
|
81
|
+
];
|
|
82
|
+
// Preserve the capture before any subprocess or verifier can fail.
|
|
83
|
+
const persisted = { mode, testName, readiness, operations, frames,
|
|
84
|
+
code: finalCode, flow, result: recordingResult, checkpoints: generated.checkpoints,
|
|
85
|
+
artifactDirectory: captured.artifactDirectory, createdAt: new Date().toISOString(), recordedSelectors: [...captured.selectors],
|
|
86
|
+
generationOptions: { ...codegenOptions, checkpoints: generated.checkpoints, scenarioName: options.scenario, scenarioFingerprint } };
|
|
87
|
+
const recordingPath = await persistRecording(options, persisted, resolve(cwd, config.paths.recordings));
|
|
88
|
+
if (options.verify) {
|
|
89
|
+
if (!options.scenario) {
|
|
90
|
+
blockers.push('verification requires a deterministic scenario');
|
|
91
|
+
}
|
|
92
|
+
else if (lang === 'dart' && !dartVerification) {
|
|
93
|
+
blockers.push('Dart verification requires its own compilation and Flutter run; provide dartVerification evidence before publishing');
|
|
94
|
+
}
|
|
95
|
+
else if (lang === 'dart') {
|
|
96
|
+
// Dart evidence comes from its own compiler and Flutter run; never use the TS replay verifier.
|
|
97
|
+
}
|
|
98
|
+
else if (blockers.length === 0) {
|
|
99
|
+
const verify = deps.verifyRecording ?? ((input) => verifyRecordingReplay({ ...input,
|
|
100
|
+
cwd, vmUrl, mode, directory: recordingPath, signal: options.signal,
|
|
101
|
+
capture: { ...captured, recording: recordingResult },
|
|
102
|
+
}));
|
|
103
|
+
const verification = await verify({
|
|
104
|
+
code: finalCode,
|
|
105
|
+
scenario: options.scenario,
|
|
106
|
+
scenarioFingerprint,
|
|
107
|
+
operations,
|
|
108
|
+
});
|
|
109
|
+
replayRunId = 'replayRunId' in verification ? verification.replayRunId : verification.verifiedRunId;
|
|
110
|
+
if (verification.passed) {
|
|
111
|
+
if (verification.verifiedRunId)
|
|
112
|
+
verifiedRunId = verification.verifiedRunId;
|
|
113
|
+
else
|
|
114
|
+
blockers.push('verification did not return a run identity');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
blockers.push(...(verification.issues ?? ['recording replay verification failed']));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
let finalReadiness = {
|
|
122
|
+
...readiness,
|
|
123
|
+
readiness: blockers.length > 0 ? 'draft' : verifiedRunId ? 'verified' : readiness.readiness,
|
|
124
|
+
...(verifiedRunId ? { verifiedRunId } : {}),
|
|
125
|
+
...(replayRunId ? { replayRunId } : {}),
|
|
126
|
+
issues: blockers,
|
|
127
|
+
};
|
|
128
|
+
if (lang === 'dart' && dartVerification) {
|
|
129
|
+
finalReadiness = applyDartVerification(finalReadiness, dartVerification);
|
|
130
|
+
}
|
|
131
|
+
const finalBlockers = finalReadiness.issues;
|
|
132
|
+
await persistRecording(options, { ...persisted, readiness: finalReadiness }, resolve(cwd, config.paths.recordings), recordingPath);
|
|
133
|
+
const canWriteAutomation = finalReadiness.readiness !== 'draft';
|
|
134
|
+
if (generatedTarget && canWriteAutomation) {
|
|
135
|
+
await mkdir(dirname(generatedTarget), { recursive: true });
|
|
136
|
+
await writeFile(generatedTarget, finalCode, 'utf8');
|
|
137
|
+
log(`\n✅ Automation written to ${generatedTarget}`);
|
|
138
|
+
}
|
|
139
|
+
else if (generatedTarget && !canWriteAutomation) {
|
|
140
|
+
log(`\n⚠️ Recording was kept as a draft because recording is not ready: ${finalBlockers.join('; ')}`);
|
|
141
|
+
}
|
|
142
|
+
if (options.flowOutput) {
|
|
143
|
+
const flowPath = resolve(cwd, options.flowOutput);
|
|
144
|
+
await mkdir(dirname(flowPath), { recursive: true });
|
|
145
|
+
await writeFile(flowPath, `${JSON.stringify(flow, null, 2)}\n`, 'utf8');
|
|
146
|
+
log(`\n✅ Flow written to ${options.flowOutput}`);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
code: finalCode,
|
|
150
|
+
operations,
|
|
151
|
+
flow,
|
|
152
|
+
readiness: finalReadiness,
|
|
153
|
+
...(recordingPath ? { recordingPath } : {}),
|
|
154
|
+
blockers: finalBlockers,
|
|
155
|
+
recording: recordingResult,
|
|
156
|
+
checkpoints: generated.checkpoints,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function defaultGeneratedTarget(root, mode, testName, lang, paths) {
|
|
160
|
+
const directory = mode === 'test' ? paths.tests : paths.scripts;
|
|
161
|
+
const suffix = lang === 'dart' ? '.dart' : mode === 'test' ? '.test.ts' : '.script.ts';
|
|
162
|
+
return resolve(root, directory, `${safeName(testName)}${suffix}`);
|
|
163
|
+
}
|
|
164
|
+
async function readCheckpointFile(path) {
|
|
165
|
+
const parsed = JSON.parse(await readFile(path, 'utf8'));
|
|
166
|
+
if (typeof parsed === 'object' && parsed !== null && 'assertions' in parsed)
|
|
167
|
+
return parsed.assertions;
|
|
168
|
+
return parsed;
|
|
169
|
+
}
|
|
170
|
+
async function persistRecording(options, input, recordingsRoot, existingDirectory) {
|
|
171
|
+
const recordingId = `${safeName(input.testName)}-${randomUUID()}`;
|
|
172
|
+
const dir = existingDirectory ?? join(recordingsRoot, recordingId);
|
|
173
|
+
await mkdir(dir, { recursive: true });
|
|
174
|
+
await copyRecordingArtifacts(input.result, input.artifactDirectory, dir);
|
|
175
|
+
await writeFile(`${dir}/recording.json`, JSON.stringify({
|
|
176
|
+
schemaVersion: 2,
|
|
177
|
+
id: basename(dir),
|
|
178
|
+
createdAt: input.createdAt, updatedAt: new Date().toISOString(),
|
|
179
|
+
rawEventCount: input.result.eventCache?.eventCount ?? input.result.receivedSequences.length,
|
|
180
|
+
operationCount: input.operations.length,
|
|
181
|
+
mode: input.mode,
|
|
182
|
+
testName: input.testName,
|
|
183
|
+
readiness: input.readiness,
|
|
184
|
+
frames: input.frames,
|
|
185
|
+
flow: input.flow,
|
|
186
|
+
recording: input.result,
|
|
187
|
+
generatedCode: input.code,
|
|
188
|
+
recordedSelectors: input.recordedSelectors,
|
|
189
|
+
generationOptions: input.generationOptions,
|
|
190
|
+
checkpoints: input.checkpoints,
|
|
191
|
+
}, null, 2) + '\n', 'utf8');
|
|
192
|
+
await writeFile(`${dir}/blockers.json`, JSON.stringify(input.readiness.issues, null, 2) + '\n', 'utf8');
|
|
193
|
+
await writeFile(`${dir}/draft.${options.lang === 'dart' ? 'dart' : input.mode === 'test' ? 'test.ts' : 'script.ts'}`, input.code, 'utf8');
|
|
194
|
+
return dir;
|
|
195
|
+
}
|
|
196
|
+
function safeName(value) {
|
|
197
|
+
return value.toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 48) || 'recording';
|
|
198
|
+
}
|
|
199
|
+
function waitForSigint(signal) {
|
|
200
|
+
return new Promise((resolve) => {
|
|
201
|
+
const cleanup = () => {
|
|
202
|
+
process.removeListener('SIGINT', stop);
|
|
203
|
+
signal.removeEventListener('abort', cleanup);
|
|
204
|
+
};
|
|
205
|
+
const stop = () => {
|
|
206
|
+
cleanup();
|
|
207
|
+
console.error('Stopping recording...');
|
|
208
|
+
resolve();
|
|
209
|
+
};
|
|
210
|
+
if (signal.aborted)
|
|
211
|
+
return resolve();
|
|
212
|
+
process.once('SIGINT', stop);
|
|
213
|
+
signal.addEventListener('abort', cleanup, { once: true });
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const recordingLeases = new EndpointLeaseManager();
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { RunError, ResolvedFliwrightConfig } from '@fliwright/core';
|
|
2
|
+
import type { ScenarioExecutionMode, TestScenario } from '@fliwright/core';
|
|
3
|
+
import { type CliRunResult } from '../reporter.js';
|
|
4
|
+
export interface RunOptions {
|
|
5
|
+
testPattern?: string;
|
|
6
|
+
caseSelection?: import('../catalog.js').CatalogSelection;
|
|
7
|
+
testName?: string;
|
|
8
|
+
vmUrl?: string;
|
|
9
|
+
reporter?: 'pretty' | 'json' | 'junit';
|
|
10
|
+
timeout?: number;
|
|
11
|
+
screenshot?: 'file' | 'base64' | 'off';
|
|
12
|
+
recordingMode?: 'standard' | 'full' | 'off';
|
|
13
|
+
output?: string;
|
|
14
|
+
junitOutput?: string;
|
|
15
|
+
scenario?: string;
|
|
16
|
+
/** Set by the CLI only when it owns a managed app launch. */
|
|
17
|
+
scenarioMode?: ScenarioExecutionMode;
|
|
18
|
+
cwd?: string;
|
|
19
|
+
print?: boolean;
|
|
20
|
+
runsRoot?: string;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
/** Inherit only when an external supervisor owns and terminates the whole process group. */
|
|
23
|
+
processGroup?: 'isolated' | 'inherit';
|
|
24
|
+
/** Strict unchanged-candidate verification: assertions must not heal targets. */
|
|
25
|
+
recordingReplay?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface RunDeps {
|
|
28
|
+
resolveVmUrl?: (options: {
|
|
29
|
+
cliFlag?: string;
|
|
30
|
+
configUrl?: string;
|
|
31
|
+
cwd?: string;
|
|
32
|
+
verify?: boolean;
|
|
33
|
+
}) => Promise<string | null>;
|
|
34
|
+
onVmResolved?: (url: string) => void;
|
|
35
|
+
}
|
|
36
|
+
/** Artifact persistence failed after the runner produced its business outcome. */
|
|
37
|
+
export declare class RunFinalizationError extends Error {
|
|
38
|
+
readonly runId: string;
|
|
39
|
+
readonly outputDir: string;
|
|
40
|
+
readonly runnerResult: CliRunResult;
|
|
41
|
+
constructor(result: CliRunResult, options: {
|
|
42
|
+
runId: string;
|
|
43
|
+
outputDir: string;
|
|
44
|
+
}, cause: unknown);
|
|
45
|
+
}
|
|
46
|
+
export declare function runCommand(options: RunOptions, deps?: RunDeps): Promise<CliRunResult>;
|
|
47
|
+
interface RunVitestOptions {
|
|
48
|
+
processGroup?: 'isolated' | 'inherit';
|
|
49
|
+
recordingReplay?: boolean;
|
|
50
|
+
sharedConfig?: ResolvedFliwrightConfig;
|
|
51
|
+
testPattern: string;
|
|
52
|
+
caseSelection?: import('../catalog.js').CatalogSelection;
|
|
53
|
+
testName?: string;
|
|
54
|
+
vmUrl: string;
|
|
55
|
+
cwd: string;
|
|
56
|
+
timeout: number;
|
|
57
|
+
screenshot: 'file' | 'base64' | 'off';
|
|
58
|
+
recordingMode?: 'standard' | 'full' | 'off';
|
|
59
|
+
runId?: string;
|
|
60
|
+
runsRoot?: string;
|
|
61
|
+
sessionResultsPath?: string;
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
scenarios?: Record<string, TestScenario>;
|
|
64
|
+
scenarioMode?: ScenarioExecutionMode;
|
|
65
|
+
}
|
|
66
|
+
export declare function runVitest(options: RunVitestOptions): Promise<CliRunResult>;
|
|
67
|
+
export declare function parseVitestOutput(raw: string): CliRunResult;
|
|
68
|
+
/** Finalize an externally executed runner using the canonical CLI artifact pipeline. */
|
|
69
|
+
export declare function finalizeRunArtifacts(result: CliRunResult, options: {
|
|
70
|
+
cwd: string;
|
|
71
|
+
outputDir: string;
|
|
72
|
+
reportPath: string;
|
|
73
|
+
runId: string;
|
|
74
|
+
runsRoot: string;
|
|
75
|
+
screenshot: 'file' | 'base64' | 'off';
|
|
76
|
+
testPattern: string;
|
|
77
|
+
recordingMode?: 'standard' | 'full' | 'off';
|
|
78
|
+
caseSelection?: import('../catalog.js').CatalogSelection;
|
|
79
|
+
testName?: string;
|
|
80
|
+
}): Promise<CliRunResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Merge worker-written attempt results into the one authoritative run index.
|
|
83
|
+
* Workers only create files below tests/<testId>/attempts/<attemptId>; the
|
|
84
|
+
* parent process is the sole writer of run.json after Vitest exits.
|
|
85
|
+
*/
|
|
86
|
+
export declare function writeRunManifest(options: {
|
|
87
|
+
runsRoot: string;
|
|
88
|
+
runId: string;
|
|
89
|
+
runDir: string;
|
|
90
|
+
runStatus?: CliRunResult['status'];
|
|
91
|
+
runnerErrors?: RunError[];
|
|
92
|
+
}): Promise<string>;
|
|
93
|
+
export {};
|