@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fliwright contributors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fliwright/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Fliwright's command interface for developers, coding agents and CI. Node.js 22.12+ (22.x), 24.x, or 26+ is required.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npx fliwright init
|
|
7
|
+
npx fliwright schema --json
|
|
8
|
+
npx fliwright schema app.interact --json
|
|
9
|
+
npx fliwright doctor --strict --json
|
|
10
|
+
npx fliwright run --test .fliwright/tests/cart.test.ts --scenario cart-ready --json --junit-output artifacts/junit.xml
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Every leaf command accepts `--cwd`, `--json`, `--input <file|->`, `--deadline <milliseconds>` and `--session`.
|
|
14
|
+
Use `schema` to discover commands and `schema <command.path>` to inspect input, the JSON output envelope, result type, exit codes, effects and connection requirements. The envelope schema leaves command-specific `data` open; use generated feature references for its API details. Structured input rejects unknown fields and duplicate fields supplied both as flags and JSON. Booleans accept `--flag`, `--flag true`, or `--flag false`. Arrays accept repeated flags or a JSON array.
|
|
15
|
+
|
|
16
|
+
`--json` prints exactly one versioned envelope on stdout: `schemaVersion`, `command`, `requestId`, `ok`, and `data` or `error`. Progress uses stderr. Session operations include `operationId`; inspect a lost response with `session status --operation-id` before retrying a mutation. Exit codes: 0 success; 1 test/review failure; 2 invalid input; 3 environment/execution unavailable; 4 workflow conflict; 5 deadline; 130 cancellation. Deadlines request cancellation and wait for owned work to settle.
|
|
17
|
+
|
|
18
|
+
- `run` and `script <file>` execute finite Vitest runs. Attach with `--vm-url` or launch with `--device-id`; managed apps stop afterward unless `--keep-app-alive`. `--junit-output` is independent of JSON output. Test-attempt fixtures own endpoint leases and named scenario preparation, including retries.
|
|
19
|
+
- `record --duration <seconds>` captures bounded recordings. Test readiness still requires deterministic scenario/assertion/replay evidence.
|
|
20
|
+
- `app` provides status, snapshot, find, observe, interact, screenshot, source-map, diagnostics, reload and debug-snapshot. Screenshots are files. Snapshot refs are opaque handles tied to the running app/isolate; reacquire them after restart.
|
|
21
|
+
- `scenario` lists, resolves, applies or resets named project scenarios. Business authentication uses app-owned auth seeding.
|
|
22
|
+
- `mock` lists the file catalog, reads Flutter routes/calls, applies one named rule, clears calls or resets routes/history/passthrough.
|
|
23
|
+
- `artifacts` reads reports, failures and timelines offline, diagnoses agent-visible failures and exports portable evidence. Select testId/attemptId when a run has multiple timelines.
|
|
24
|
+
- `flow` provides recording-derived flows, test generation, runtime/Figma capture and review reports. Figma's external MCP remains a valid design input.
|
|
25
|
+
- `generate-test` and `tdd validate-spec` work offline. `tdd cycle --file ...` runs one finite CI cycle.
|
|
26
|
+
|
|
27
|
+
For repeated exploration and persistent TDD:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
fliwright session open --json
|
|
31
|
+
# Read data.sessionId from the result.
|
|
32
|
+
fliwright app snapshot --session <id> --json
|
|
33
|
+
fliwright tdd start --session <id> --scenario cart-ready --json
|
|
34
|
+
fliwright tdd focus --session <id> --file .fliwright/tests/cart.test.ts --json
|
|
35
|
+
fliwright tdd cycle --session <id> --json
|
|
36
|
+
fliwright session close --session <id> --json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`FLIWRIGHT_SESSION` selects a project session for app and persistent workflow commands. Offline artifact/schema queries and finite run/script/record commands remain independent. Connection workers serialize commands, retain TDD ownership until real execution settles, and release endpoint control before Vitest forks acquire it. Worker startup is bounded at 30 seconds for attach and 180 seconds for a managed launch; an explicit command deadline can shorten it. Workers expire after 30 minutes of inactivity. Runtime control and operation journals live in ignored `.fliwright/sessions/` files.
|
|
40
|
+
|
|
41
|
+
Fliwright's MCP server and `fliwright mcp` have been removed. Use the bundled Skills with this CLI. Install the CLI in each target project and retain CI artifacts even when the command fails.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Command documentation for Skills
|
|
45
|
+
|
|
46
|
+
Read the [task and command index](https://github.com/0x01lab/fliwright/blob/main/.agents/skills/fliwright-cli-workflows/references/commands/index.md)
|
|
47
|
+
for one page per CLI command: purpose, prerequisites, parameter meanings,
|
|
48
|
+
examples, result fields, side effects and failure recovery. The CLI workflow
|
|
49
|
+
Skill bundles these references, so an installed Skill can read them without
|
|
50
|
+
cloning this repository. Use `fliwright schema <command.path> --json` to confirm
|
|
51
|
+
the installed version’s contract.
|
|
52
|
+
|
|
53
|
+
Maintainers: edit semantic guidance in `docs/command-guide.mjs` and parameter
|
|
54
|
+
explanations in `docs/parameter-guide.mjs`; the registry remains the source of
|
|
55
|
+
truth for command inventory, types, flags and defaults. After building the CLI,
|
|
56
|
+
run `pnpm docs:cli`, `pnpm plugin:sync`, and `pnpm docs:cli:check` from the repository
|
|
57
|
+
root. The check rejects undocumented/stale commands, missing parameter guidance,
|
|
58
|
+
broken links, unparseable examples and source/plugin drift. CI runs this check
|
|
59
|
+
after the build. Regenerate `docs/features/` with
|
|
60
|
+
`node scripts/generate-feature-docs.mjs` to reuse the same command pages there.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface ArtifactReference {
|
|
2
|
+
path: string;
|
|
3
|
+
set(path: string): void;
|
|
4
|
+
}
|
|
5
|
+
/** Enumerate schema-owned artifact paths, excluding source-code locations and arbitrary metadata. */
|
|
6
|
+
export declare function artifactReferences(document: unknown, kind: 'report' | 'result' | 'timeline' | 'trace' | 'failures'): ArtifactReference[];
|
|
7
|
+
export declare function relativeArtifactPath(root: string, target: string): string | undefined;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
2
|
+
function record(value) {
|
|
3
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
4
|
+
}
|
|
5
|
+
function list(value) {
|
|
6
|
+
return Array.isArray(value) ? value : [];
|
|
7
|
+
}
|
|
8
|
+
/** Enumerate schema-owned artifact paths, excluding source-code locations and arbitrary metadata. */
|
|
9
|
+
export function artifactReferences(document, kind) {
|
|
10
|
+
const refs = [];
|
|
11
|
+
const field = (value, key) => {
|
|
12
|
+
const object = record(value);
|
|
13
|
+
if (object && typeof object[key] === 'string' && object[key]) {
|
|
14
|
+
refs.push({ path: object[key], set: (path) => { object[key] = path; } });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const paths = (value, key) => {
|
|
18
|
+
const array = record(value)?.[key];
|
|
19
|
+
if (!Array.isArray(array))
|
|
20
|
+
return;
|
|
21
|
+
for (let index = 0; index < array.length; index++)
|
|
22
|
+
if (typeof array[index] === 'string') {
|
|
23
|
+
refs.push({ path: array[index], set: (path) => { array[index] = path; } });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const appState = (value) => {
|
|
27
|
+
const state = record(value)?.appState;
|
|
28
|
+
for (const key of ['screenshotPath', 'snapshotPath', 'diagnosticsPath'])
|
|
29
|
+
field(state, key);
|
|
30
|
+
};
|
|
31
|
+
const failure = (value) => {
|
|
32
|
+
field(record(value)?.screenshot, 'path');
|
|
33
|
+
appState(value);
|
|
34
|
+
};
|
|
35
|
+
const object = record(document);
|
|
36
|
+
if (kind === 'report') {
|
|
37
|
+
const artifacts = record(object?.artifacts);
|
|
38
|
+
field(artifacts, 'manifestPath');
|
|
39
|
+
field(artifacts, 'reportPath');
|
|
40
|
+
paths(artifacts, 'screenshots');
|
|
41
|
+
paths(artifacts, 'timelines');
|
|
42
|
+
for (const timeline of list(object?.timelines)) {
|
|
43
|
+
field(timeline, 'path');
|
|
44
|
+
appState(record(timeline)?.firstFailure);
|
|
45
|
+
}
|
|
46
|
+
for (const entry of list(object?.failures))
|
|
47
|
+
failure(entry);
|
|
48
|
+
for (const entry of list(object?.agentVisibleFailures))
|
|
49
|
+
appState(entry);
|
|
50
|
+
}
|
|
51
|
+
else if (kind === 'result') {
|
|
52
|
+
field(object, 'failureContextPath');
|
|
53
|
+
field(object, 'eventsPath');
|
|
54
|
+
for (const evidence of list(object?.evidence))
|
|
55
|
+
paths(record(evidence)?.result, 'artifactPaths');
|
|
56
|
+
}
|
|
57
|
+
else if (kind === 'timeline') {
|
|
58
|
+
for (const node of list(object?.nodes)) {
|
|
59
|
+
for (const artifact of list(record(node)?.artifacts))
|
|
60
|
+
field(artifact, 'path');
|
|
61
|
+
appState(record(node)?.error);
|
|
62
|
+
}
|
|
63
|
+
for (const entry of list(object?.agentVisibleFailures))
|
|
64
|
+
appState(entry);
|
|
65
|
+
}
|
|
66
|
+
else if (kind === 'trace') {
|
|
67
|
+
for (const step of list(object?.steps)) {
|
|
68
|
+
field(step, 'screenshotFile');
|
|
69
|
+
field(step, 'snapshotFile');
|
|
70
|
+
field(step, 'diagnosticsFile');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
for (const entry of list(document))
|
|
75
|
+
failure(entry);
|
|
76
|
+
return refs;
|
|
77
|
+
}
|
|
78
|
+
export function relativeArtifactPath(root, target) {
|
|
79
|
+
const rel = relative(resolve(root), resolve(target));
|
|
80
|
+
return rel === '..' || rel.startsWith('../') || rel.startsWith('..\\') || isAbsolute(rel)
|
|
81
|
+
? undefined : rel.split('\\').join('/');
|
|
82
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare class CliError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly exitCode: number;
|
|
6
|
+
readonly data?: unknown | undefined;
|
|
7
|
+
constructor(code: string, message: string, exitCode?: number, data?: unknown | undefined);
|
|
8
|
+
}
|
|
9
|
+
export interface CommandContext {
|
|
10
|
+
cwd: string;
|
|
11
|
+
signal: AbortSignal;
|
|
12
|
+
requestId: string;
|
|
13
|
+
session?: string;
|
|
14
|
+
waitForInterrupt?: (signal: AbortSignal) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface CommandDefinition {
|
|
17
|
+
path: string;
|
|
18
|
+
description: string;
|
|
19
|
+
input: z.AnyZodObject;
|
|
20
|
+
effects: string[];
|
|
21
|
+
needsApp?: boolean;
|
|
22
|
+
needsSession?: boolean;
|
|
23
|
+
output?: string;
|
|
24
|
+
positional?: string[];
|
|
25
|
+
aliases?: Record<string, string>;
|
|
26
|
+
execute(input: any, context: CommandContext): Promise<unknown> | unknown;
|
|
27
|
+
}
|
|
28
|
+
export interface CliExecution {
|
|
29
|
+
stdout: string;
|
|
30
|
+
stderr: string;
|
|
31
|
+
exitCode: number;
|
|
32
|
+
}
|
|
33
|
+
export declare class CommandRegistry {
|
|
34
|
+
readonly definitions: Map<string, CommandDefinition>;
|
|
35
|
+
add(definition: CommandDefinition): void;
|
|
36
|
+
schema(path?: string): unknown;
|
|
37
|
+
program(onExecute: (definition: CommandDefinition, input: any, options: Record<string, unknown>) => Promise<void>): Command;
|
|
38
|
+
}
|
|
39
|
+
export declare function classifyError(error: unknown): CliError;
|
|
40
|
+
export declare function requestId(): string;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Command, CommanderError } from 'commander';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
7
|
+
export class CliError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
exitCode;
|
|
10
|
+
data;
|
|
11
|
+
constructor(code, message, exitCode = 3, data) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.exitCode = exitCode;
|
|
15
|
+
this.data = data;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class CommandRegistry {
|
|
19
|
+
definitions = new Map();
|
|
20
|
+
add(definition) {
|
|
21
|
+
if (this.definitions.has(definition.path))
|
|
22
|
+
throw new Error(`Duplicate command ${definition.path}`);
|
|
23
|
+
this.definitions.set(definition.path, definition);
|
|
24
|
+
}
|
|
25
|
+
schema(path) {
|
|
26
|
+
if (!path)
|
|
27
|
+
return { commands: [...this.definitions.values()].map(({ path, description, effects, needsApp, needsSession }) => ({ path, description, effects, needsApp: Boolean(needsApp), needsSession: Boolean(needsSession) })) };
|
|
28
|
+
const definition = this.definitions.get(path.replace(/ /g, '.'));
|
|
29
|
+
if (!definition)
|
|
30
|
+
throw new CliError('INVALID_INPUT', `Unknown command: ${path}`, 2);
|
|
31
|
+
return { command: definition.path, description: definition.description,
|
|
32
|
+
input: zodToJsonSchema(definition.input.strict(), { $refStrategy: 'none' }),
|
|
33
|
+
outputType: definition.output ?? 'CommandResult.data',
|
|
34
|
+
output: { $schema: 'http://json-schema.org/draft-07/schema#', type: 'object', additionalProperties: false,
|
|
35
|
+
required: ['schemaVersion', 'command', 'requestId', 'ok'], properties: {
|
|
36
|
+
schemaVersion: { const: 1 }, command: { const: definition.path }, requestId: { type: 'string' },
|
|
37
|
+
operationId: { type: 'string' }, ok: { type: 'boolean' }, data: { description: definition.output ?? 'Command-specific result or partial failure evidence' },
|
|
38
|
+
error: { type: 'object', required: ['code', 'message', 'retryable'], additionalProperties: false,
|
|
39
|
+
properties: { code: { type: 'string' }, message: { type: 'string' }, retryable: { const: false } } },
|
|
40
|
+
}, allOf: [{ if: { properties: { ok: { const: false } } }, then: { required: ['error'] } }],
|
|
41
|
+
},
|
|
42
|
+
exitCodes: { 0: 'SUCCESS', 1: 'TEST_OR_REVIEW_FAILED', 2: 'INVALID_INPUT', 3: 'EXECUTION_UNAVAILABLE', 4: 'WORKFLOW_CONFLICT', 5: 'DEADLINE_EXCEEDED', 130: 'CANCELLED' },
|
|
43
|
+
cancellation: { deadlineUnit: 'milliseconds', signals: ['SIGINT', 'SIGTERM'], session: 'Query operation status before retrying uncertain mutations.' }, effects: definition.effects,
|
|
44
|
+
needsApp: Boolean(definition.needsApp), needsSession: Boolean(definition.needsSession),
|
|
45
|
+
common: { cwd: 'Project root', json: 'One versioned result on stdout', input: 'JSON file or stdin; duplicate fields are rejected', deadline: 'Milliseconds; cancellation waits for owned work to settle', session: 'Explicit CLI connection session' } };
|
|
46
|
+
}
|
|
47
|
+
program(onExecute) {
|
|
48
|
+
const root = new Command().name('fliwright').description('Flutter automation for terminals, coding agents and CI').version('0.1.0');
|
|
49
|
+
const groups = new Map([['', root]]);
|
|
50
|
+
for (const definition of this.definitions.values()) {
|
|
51
|
+
const parts = definition.path.split('.');
|
|
52
|
+
let parent = root;
|
|
53
|
+
let groupPath = '';
|
|
54
|
+
for (const part of parts.slice(0, -1)) {
|
|
55
|
+
groupPath = groupPath ? `${groupPath}.${part}` : part;
|
|
56
|
+
let group = groups.get(groupPath);
|
|
57
|
+
if (!group) {
|
|
58
|
+
group = parent.command(part);
|
|
59
|
+
groups.set(groupPath, group);
|
|
60
|
+
}
|
|
61
|
+
parent = group;
|
|
62
|
+
}
|
|
63
|
+
const command = parent.command(parts.at(-1)).description(definition.description);
|
|
64
|
+
command.exitOverride();
|
|
65
|
+
for (const field of definition.positional ?? [])
|
|
66
|
+
command.argument(`[${field}]`);
|
|
67
|
+
for (const [key, field] of Object.entries(definition.input.shape)) {
|
|
68
|
+
if (definition.positional?.includes(key))
|
|
69
|
+
continue;
|
|
70
|
+
const shape = unwrap(field);
|
|
71
|
+
const flag = definition.aliases?.[key] ?? key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
72
|
+
const description = field.description ?? key;
|
|
73
|
+
if (shape instanceof z.ZodBoolean)
|
|
74
|
+
command.option(`--${flag} [boolean]`, description, parseBoolean);
|
|
75
|
+
else if (shape instanceof z.ZodArray)
|
|
76
|
+
command.option(`--${flag} <value>`, description, (value, previous = []) => {
|
|
77
|
+
if (value.trim().startsWith('[')) {
|
|
78
|
+
try {
|
|
79
|
+
const values = JSON.parse(value);
|
|
80
|
+
if (Array.isArray(values))
|
|
81
|
+
return [...previous, ...values];
|
|
82
|
+
}
|
|
83
|
+
catch { }
|
|
84
|
+
throw new CliError('INVALID_INPUT', 'Expected JSON array.', 2);
|
|
85
|
+
}
|
|
86
|
+
return [...previous, parseValue(value, shape.element)];
|
|
87
|
+
});
|
|
88
|
+
else
|
|
89
|
+
command.option(`--${flag} <value>`, description, (value) => parseValue(value, shape));
|
|
90
|
+
}
|
|
91
|
+
command.option('--cwd <directory>', 'Project root').option('--json', 'Print one versioned JSON result')
|
|
92
|
+
.option('--input <file>', 'Structured JSON input; - reads stdin')
|
|
93
|
+
.option('--deadline <ms>', 'Command deadline in milliseconds')
|
|
94
|
+
.option('--session <id>', 'Explicit connection session');
|
|
95
|
+
command.action(async (...args) => {
|
|
96
|
+
const options = args.at(-2);
|
|
97
|
+
const input = {};
|
|
98
|
+
for (const key of Object.keys(definition.input.shape))
|
|
99
|
+
if (options[key] !== undefined)
|
|
100
|
+
input[key] = options[key];
|
|
101
|
+
for (const [i, key] of (definition.positional ?? []).entries())
|
|
102
|
+
if (args[i] !== undefined)
|
|
103
|
+
input[key] = args[i];
|
|
104
|
+
if (options.input) {
|
|
105
|
+
const body = options.input === '-' ? await readStdin() : await readFile(resolve(String(options.cwd ?? process.cwd()), String(options.input)), 'utf8');
|
|
106
|
+
let parsed;
|
|
107
|
+
try {
|
|
108
|
+
parsed = JSON.parse(body);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
throw new CliError('INVALID_INPUT', 'Input must be valid JSON.', 2);
|
|
112
|
+
}
|
|
113
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
114
|
+
throw new CliError('INVALID_INPUT', 'Input must be a JSON object.', 2);
|
|
115
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
116
|
+
if (key in input)
|
|
117
|
+
throw new CliError('INVALID_INPUT', `Duplicate input field: ${key}`, 2);
|
|
118
|
+
input[key] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
await onExecute(definition, definition.input.strict().parse(input), options);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
root.exitOverride();
|
|
125
|
+
return root;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function unwrap(field) {
|
|
129
|
+
if (field instanceof z.ZodOptional || field instanceof z.ZodNullable)
|
|
130
|
+
return unwrap(field.unwrap());
|
|
131
|
+
if (field instanceof z.ZodDefault)
|
|
132
|
+
return unwrap(field.removeDefault());
|
|
133
|
+
if (field instanceof z.ZodEffects)
|
|
134
|
+
return unwrap(field.innerType());
|
|
135
|
+
return field;
|
|
136
|
+
}
|
|
137
|
+
function parseBoolean(value) {
|
|
138
|
+
if (value === undefined || value === 'true')
|
|
139
|
+
return true;
|
|
140
|
+
if (value === 'false')
|
|
141
|
+
return false;
|
|
142
|
+
throw new CliError('INVALID_INPUT', 'Expected true or false.', 2);
|
|
143
|
+
}
|
|
144
|
+
function parseValue(value, field) {
|
|
145
|
+
if (field instanceof z.ZodNumber)
|
|
146
|
+
return Number(value);
|
|
147
|
+
if (field instanceof z.ZodObject || field instanceof z.ZodRecord) {
|
|
148
|
+
try {
|
|
149
|
+
return JSON.parse(value);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
throw new CliError('INVALID_INPUT', 'Expected JSON value.', 2);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
async function readStdin() {
|
|
158
|
+
let body = '';
|
|
159
|
+
for await (const chunk of process.stdin)
|
|
160
|
+
body += String(chunk);
|
|
161
|
+
return body;
|
|
162
|
+
}
|
|
163
|
+
export function classifyError(error) {
|
|
164
|
+
if (error instanceof CliError)
|
|
165
|
+
return error;
|
|
166
|
+
if (error instanceof Error && error.name === 'RunFinalizationError' && 'runnerResult' in error && 'runId' in error && 'outputDir' in error) {
|
|
167
|
+
return new CliError('ARTIFACT_FINALIZATION_FAILED', error.message, 3, { runnerResult: error.runnerResult, runId: error.runId, outputDir: error.outputDir });
|
|
168
|
+
}
|
|
169
|
+
if (error instanceof z.ZodError || error instanceof CommanderError)
|
|
170
|
+
return new CliError('INVALID_INPUT', error.message, 2);
|
|
171
|
+
if (error instanceof Error && error.name === 'TimeoutError')
|
|
172
|
+
return new CliError('DEADLINE_EXCEEDED', error.message, 5);
|
|
173
|
+
if (error instanceof Error && error.name === 'AbortError')
|
|
174
|
+
return new CliError('CANCELLED', error.message, 130);
|
|
175
|
+
return new CliError('EXECUTION_UNAVAILABLE', error instanceof Error ? error.message : String(error), 3);
|
|
176
|
+
}
|
|
177
|
+
export function requestId() { return randomUUID(); }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { resolveProjectConfig } from './config.js';
|
|
4
|
+
/** Resolve explicit files or a unique temporary capture under the project's cache. */
|
|
5
|
+
export async function inspectionOutput(options, name) {
|
|
6
|
+
const cwd = options.cwd ?? process.cwd();
|
|
7
|
+
if (options.output)
|
|
8
|
+
return resolve(cwd, options.output);
|
|
9
|
+
const config = await resolveProjectConfig(cwd);
|
|
10
|
+
return join(config.cacheRoot, 'inspect', randomUUID(), `${name}.png`);
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RecordingCaptureResult } from '@fliwright/core';
|
|
2
|
+
export interface RecordingReplayOptions {
|
|
3
|
+
code: string;
|
|
4
|
+
mode?: 'script' | 'test';
|
|
5
|
+
scenario: string;
|
|
6
|
+
scenarioFingerprint?: string;
|
|
7
|
+
cwd: string;
|
|
8
|
+
vmUrl: string;
|
|
9
|
+
directory?: string;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
capture?: RecordingCaptureResult;
|
|
12
|
+
}
|
|
13
|
+
export interface RecordingReplayResult {
|
|
14
|
+
passed: boolean;
|
|
15
|
+
verifiedRunId?: string;
|
|
16
|
+
replayRunId?: string;
|
|
17
|
+
replayPath?: string;
|
|
18
|
+
manifestPath?: string;
|
|
19
|
+
contentFingerprint?: string;
|
|
20
|
+
scenarioFingerprint?: string;
|
|
21
|
+
issues: string[];
|
|
22
|
+
}
|
|
23
|
+
/** Replay the unchanged candidate once, preserving source and failed run evidence. */
|
|
24
|
+
export declare function verifyRecordingReplay(input: RecordingReplayOptions): Promise<RecordingReplayResult>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { copyRecordingArtifacts, fingerprintScenario, parseTimelineData, ScenarioResolver } from '@fliwright/core';
|
|
5
|
+
import { resolveProjectConfig } from './config.js';
|
|
6
|
+
import { runCommand } from './commands/run.js';
|
|
7
|
+
/** Replay the unchanged candidate once, preserving source and failed run evidence. */
|
|
8
|
+
export async function verifyRecordingReplay(input) {
|
|
9
|
+
const config = await resolveProjectConfig(input.cwd);
|
|
10
|
+
const directory = input.directory ?? resolve(input.cwd, config.paths.recordings, `replay-${randomUUID()}`);
|
|
11
|
+
await mkdir(directory, { recursive: true });
|
|
12
|
+
const replayPath = resolve(directory, 'replay.test.ts');
|
|
13
|
+
await writeFile(replayPath, input.code, 'utf8');
|
|
14
|
+
if (input.capture) {
|
|
15
|
+
const { artifactDirectory, ...capture } = input.capture;
|
|
16
|
+
await copyRecordingArtifacts(capture.recording, artifactDirectory, directory);
|
|
17
|
+
await writeFile(join(directory, 'capture.json'), `${JSON.stringify({
|
|
18
|
+
...capture, selectors: [...capture.selectors],
|
|
19
|
+
}, null, 2)}\n`, 'utf8');
|
|
20
|
+
}
|
|
21
|
+
let replayRunId;
|
|
22
|
+
let manifestPath;
|
|
23
|
+
const issues = [];
|
|
24
|
+
try {
|
|
25
|
+
const expectedScenario = fingerprintScenario(new ScenarioResolver(config.scenarios ?? {}).resolve(input.scenario));
|
|
26
|
+
if (!input.scenarioFingerprint || input.scenarioFingerprint !== expectedScenario) {
|
|
27
|
+
throw new Error('Recording scenario changed before replay.');
|
|
28
|
+
}
|
|
29
|
+
const run = await runCommand({ cwd: input.cwd, vmUrl: input.vmUrl,
|
|
30
|
+
testPattern: replayPath, print: false, signal: input.signal,
|
|
31
|
+
recordingReplay: true,
|
|
32
|
+
}, { resolveVmUrl: async () => input.vmUrl });
|
|
33
|
+
replayRunId = run.artifacts?.runId;
|
|
34
|
+
manifestPath = run.artifacts?.manifestPath;
|
|
35
|
+
if (!run.passed || run.totalTests !== 1 || run.passedTests !== 1 || !run.artifacts?.manifestPath) {
|
|
36
|
+
throw new Error(`Recording replay failed (${run.status ?? 'failed'}); expected one passing test.`);
|
|
37
|
+
}
|
|
38
|
+
manifestPath = run.artifacts.manifestPath;
|
|
39
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
40
|
+
if (manifest.tests.length !== 1 || manifest.status !== 'passed')
|
|
41
|
+
throw new Error('Recording replay has no single passing attempt.');
|
|
42
|
+
const test = manifest.tests[0];
|
|
43
|
+
if (test.attempts.length !== 1)
|
|
44
|
+
throw new Error('Recording replay requires a passing first attempt without retries.');
|
|
45
|
+
const resultPath = join(dirname(manifestPath), test.attempts[0].resultPath);
|
|
46
|
+
const result = JSON.parse(await readFile(resultPath, 'utf8'));
|
|
47
|
+
if (result.runId !== replayRunId || result.testId !== test.testId || result.attemptId !== test.attempts[0].attemptId
|
|
48
|
+
|| result.attemptOutcome !== 'passed' || result.testOutcome !== 'passed' || result.expectedFailure) {
|
|
49
|
+
throw new Error('Recording replay attempt identity or outcome does not match.');
|
|
50
|
+
}
|
|
51
|
+
const timeline = parseTimelineData(await readFile(join(dirname(resultPath), 'timeline.json'), 'utf8'));
|
|
52
|
+
if ((input.mode ?? 'test') === 'test' && !timeline?.nodes.some((node) => node.kind === 'assertion' && node.status === 'passed')) {
|
|
53
|
+
throw new Error('Recording replay executed no confirmed assertions.');
|
|
54
|
+
}
|
|
55
|
+
if (!timeline?.nodes.some((node) => node.status === 'passed'
|
|
56
|
+
&& node.metadata?.scenarioName === input.scenario
|
|
57
|
+
&& node.metadata?.scenarioFingerprint === expectedScenario)) {
|
|
58
|
+
throw new Error('Recording replay did not apply the bound scenario.');
|
|
59
|
+
}
|
|
60
|
+
const after = await resolveProjectConfig(input.cwd);
|
|
61
|
+
if (fingerprintScenario(new ScenarioResolver(after.scenarios ?? {}).resolve(input.scenario)) !== expectedScenario
|
|
62
|
+
|| digest(await readFile(replayPath, 'utf8')) !== digest(input.code)) {
|
|
63
|
+
throw new Error('Recording content or scenario changed during replay.');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
issues.push(error instanceof Error ? error.message : String(error));
|
|
68
|
+
}
|
|
69
|
+
const result = { passed: issues.length === 0 && !!replayRunId,
|
|
70
|
+
replayRunId, replayPath, manifestPath, issues,
|
|
71
|
+
contentFingerprint: digest(input.code), scenarioFingerprint: input.scenarioFingerprint,
|
|
72
|
+
...(issues.length === 0 && replayRunId ? { verifiedRunId: replayRunId } : {}),
|
|
73
|
+
};
|
|
74
|
+
await writeFile(join(directory, 'verification.json'), `${JSON.stringify(result, null, 2)}\n`, 'utf8');
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
function digest(code) {
|
|
78
|
+
return createHash('sha256').update(code).digest('hex');
|
|
79
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Durable generation metadata; active driver/executor objects never belong here. */
|
|
2
|
+
export interface TddWorkflowContext {
|
|
3
|
+
testName?: string;
|
|
4
|
+
flowId?: string;
|
|
5
|
+
testFile?: string;
|
|
6
|
+
selectorDiagnostics?: unknown[];
|
|
7
|
+
tests?: unknown[];
|
|
8
|
+
coverage?: unknown;
|
|
9
|
+
workflow?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface GenerateTestResult {
|
|
12
|
+
testCode: string;
|
|
13
|
+
testName: string;
|
|
14
|
+
testFile?: string;
|
|
15
|
+
warnings?: string[];
|
|
16
|
+
selectorDiagnostics?: unknown[];
|
|
17
|
+
workflow?: unknown;
|
|
18
|
+
tests?: unknown[];
|
|
19
|
+
coverage?: unknown;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FormAnalyzeResult, FormFillResult, FormHelperOptions } from '@fliwright/core';
|
|
2
|
+
export interface FormCapabilityDriver {
|
|
3
|
+
page: {
|
|
4
|
+
formHelper: {
|
|
5
|
+
analyze(options?: FormHelperOptions): Promise<FormAnalyzeResult>;
|
|
6
|
+
fill(options?: FormHelperOptions): Promise<FormFillResult>;
|
|
7
|
+
fillFields(fieldHints: string[], options?: FormHelperOptions): Promise<FormFillResult>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function analyzeFormCapability(driver: FormCapabilityDriver, options?: FormHelperOptions): Promise<FormAnalyzeResult>;
|
|
12
|
+
export declare function fillFormCapability(driver: FormCapabilityDriver, options?: FormHelperOptions): Promise<FormFillResult>;
|
|
13
|
+
export declare function fillFormFieldsCapability(driver: FormCapabilityDriver, fieldHints: string[], options?: FormHelperOptions): Promise<FormFillResult>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function analyzeFormCapability(driver, options) {
|
|
2
|
+
return driver.page.formHelper.analyze(options);
|
|
3
|
+
}
|
|
4
|
+
export function fillFormCapability(driver, options) {
|
|
5
|
+
return driver.page.formHelper.fill(options);
|
|
6
|
+
}
|
|
7
|
+
export function fillFormFieldsCapability(driver, fieldHints, options) {
|
|
8
|
+
return driver.page.formHelper.fillFields(fieldHints, options);
|
|
9
|
+
}
|