@fliwright/tdd 0.0.0-stage → 0.1.1
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 +29 -2
- package/dist/baseline/AppCapabilityResetAdapter.d.ts +6 -0
- package/dist/baseline/AppCapabilityResetAdapter.js +41 -0
- package/dist/baseline/BaselineManager.d.ts +67 -0
- package/dist/baseline/BaselineManager.js +145 -0
- package/dist/baseline/StorageResetAdapter.d.ts +19 -0
- package/dist/baseline/StorageResetAdapter.js +43 -0
- package/dist/daemon/DaemonTransport.d.ts +37 -0
- package/dist/daemon/DaemonTransport.js +1 -0
- package/dist/daemon/FlutterDaemonController.d.ts +20 -0
- package/dist/daemon/FlutterDaemonController.js +120 -0
- package/dist/daemon/FlutterDaemonEndpointSource.d.ts +23 -0
- package/dist/daemon/FlutterDaemonEndpointSource.js +37 -0
- package/dist/daemon/ReloadStrategy.d.ts +28 -0
- package/dist/daemon/ReloadStrategy.js +72 -0
- package/dist/daemon/SubprocessDaemonTransport.d.ts +32 -0
- package/dist/daemon/SubprocessDaemonTransport.js +171 -0
- package/dist/diagnostics/TddFailureContext.d.ts +56 -0
- package/dist/diagnostics/TddFailureContext.js +220 -0
- package/dist/executor/FocusedRerunRecipe.d.ts +7 -0
- package/dist/executor/FocusedRerunRecipe.js +64 -0
- package/dist/executor/PersistentTestExecutor.d.ts +56 -0
- package/dist/executor/PersistentTestExecutor.js +235 -0
- package/dist/executor/TestRunResults.d.ts +13 -0
- package/dist/executor/TestRunResults.js +19 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +13 -0
- package/dist/runtime/TddRuntime.d.ts +73 -0
- package/dist/runtime/TddRuntime.js +552 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.js +2 -0
- package/package.json +42 -3
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File-path suffixes that are generated and therefore always structural: a change here can never
|
|
3
|
+
* be hot-reloaded and must trigger a restart.
|
|
4
|
+
*/
|
|
5
|
+
const GENERATED_SUFFIXES = [
|
|
6
|
+
'.g.dart',
|
|
7
|
+
'.freezed.dart',
|
|
8
|
+
'.gr.dart', // go_router codegen
|
|
9
|
+
'.mocks.dart', // mockito codegen
|
|
10
|
+
'.gen.dart',
|
|
11
|
+
];
|
|
12
|
+
/** Basenames / path segments that imply structural app changes. */
|
|
13
|
+
const STRUCTURAL_BASENAMES = new Set([
|
|
14
|
+
'pubspec.yaml',
|
|
15
|
+
'pubspec.lock',
|
|
16
|
+
]);
|
|
17
|
+
/** Path segments that imply resource directories the VM cannot reload. */
|
|
18
|
+
const STRUCTURAL_SEGMENTS = new Set(['assets', 'l10n']);
|
|
19
|
+
/** Path fragments that imply resource changes the VM cannot reload. */
|
|
20
|
+
const STRUCTURAL_FRAGMENTS = ['i18n'];
|
|
21
|
+
/**
|
|
22
|
+
* Decide the sync level for a set of changed file paths since the last sync.
|
|
23
|
+
*
|
|
24
|
+
* - no changes → `none`
|
|
25
|
+
* - any generated / pubspec / assets / l10n path → `restart`
|
|
26
|
+
* - otherwise (plain `.dart` bodies, literals, UI) → `reload`
|
|
27
|
+
*/
|
|
28
|
+
export function decideSync(changes = []) {
|
|
29
|
+
if (changes.length === 0)
|
|
30
|
+
return 'none';
|
|
31
|
+
for (const change of changes) {
|
|
32
|
+
if (isStructuralFileChange(change))
|
|
33
|
+
return 'restart';
|
|
34
|
+
}
|
|
35
|
+
return 'reload';
|
|
36
|
+
}
|
|
37
|
+
/** True when a single changed path is provably structural by inspection alone. */
|
|
38
|
+
export function isStructuralFileChange(changePath) {
|
|
39
|
+
const lower = changePath.toLowerCase();
|
|
40
|
+
if (GENERATED_SUFFIXES.some((suffix) => lower.endsWith(suffix)))
|
|
41
|
+
return true;
|
|
42
|
+
const segments = lower.split('/');
|
|
43
|
+
const base = segments.pop() ?? lower;
|
|
44
|
+
if (STRUCTURAL_BASENAMES.has(base))
|
|
45
|
+
return true;
|
|
46
|
+
if (segments.some((segment) => STRUCTURAL_SEGMENTS.has(segment)))
|
|
47
|
+
return true;
|
|
48
|
+
return STRUCTURAL_FRAGMENTS.some((fragment) => lower.includes(fragment));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Failure kinds whose presence after a `reload` strongly suggests the reload did not reflect a
|
|
52
|
+
* structural edit (a provider/route/declaration that only a restart can pick up). Used by the loop's
|
|
53
|
+
* reload→restart auto-escalation.
|
|
54
|
+
*/
|
|
55
|
+
const STRUCTURAL_FAILURE_KINDS = new Set([
|
|
56
|
+
'missing-element',
|
|
57
|
+
'ambiguous-element',
|
|
58
|
+
'state-mismatch',
|
|
59
|
+
'navigation-failed',
|
|
60
|
+
]);
|
|
61
|
+
/**
|
|
62
|
+
* True when a red cycle result looks like a reload that failed to reflect a structural change and
|
|
63
|
+
* is therefore worth retrying with a restart.
|
|
64
|
+
*/
|
|
65
|
+
export function looksStructuralAfterReload(result) {
|
|
66
|
+
if (result.status !== 'red')
|
|
67
|
+
return false;
|
|
68
|
+
if (result.lastSync !== 'reload')
|
|
69
|
+
return false;
|
|
70
|
+
const kind = result.failureContext?.kind;
|
|
71
|
+
return kind !== undefined && STRUCTURAL_FAILURE_KINDS.has(kind);
|
|
72
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DaemonMessage, DaemonTransport } from './DaemonTransport.js';
|
|
2
|
+
export declare function parseDaemonLines(line: string): DaemonMessage[];
|
|
3
|
+
export interface SubprocessDaemonTransportOptions {
|
|
4
|
+
flutterBin?: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
extraArgs?: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare class SubprocessDaemonTransport implements DaemonTransport {
|
|
9
|
+
private readonly opts;
|
|
10
|
+
private child?;
|
|
11
|
+
private buffer;
|
|
12
|
+
private seq;
|
|
13
|
+
private readonly pending;
|
|
14
|
+
private readonly listeners;
|
|
15
|
+
constructor(opts?: SubprocessDaemonTransportOptions);
|
|
16
|
+
private connected;
|
|
17
|
+
private starting?;
|
|
18
|
+
private stderr;
|
|
19
|
+
private startingApp?;
|
|
20
|
+
private closing?;
|
|
21
|
+
private exited?;
|
|
22
|
+
connect(): Promise<void>;
|
|
23
|
+
private launch;
|
|
24
|
+
request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
25
|
+
onEvent(handler: (message: DaemonMessage) => void): () => void;
|
|
26
|
+
dispose(options?: {
|
|
27
|
+
keepAppAlive?: boolean;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
private close;
|
|
30
|
+
private dispatch;
|
|
31
|
+
private rejectAll;
|
|
32
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
export function parseDaemonLines(line) {
|
|
3
|
+
const trimmed = line.trim();
|
|
4
|
+
if (!trimmed)
|
|
5
|
+
return [];
|
|
6
|
+
try {
|
|
7
|
+
const parsed = JSON.parse(trimmed);
|
|
8
|
+
return Array.isArray(parsed) ? parsed : [parsed];
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class SubprocessDaemonTransport {
|
|
15
|
+
opts;
|
|
16
|
+
child;
|
|
17
|
+
buffer = '';
|
|
18
|
+
seq = 0;
|
|
19
|
+
pending = new Map();
|
|
20
|
+
listeners = new Set();
|
|
21
|
+
constructor(opts = {}) {
|
|
22
|
+
this.opts = opts;
|
|
23
|
+
}
|
|
24
|
+
connected = false;
|
|
25
|
+
starting;
|
|
26
|
+
stderr = '';
|
|
27
|
+
startingApp;
|
|
28
|
+
closing;
|
|
29
|
+
exited;
|
|
30
|
+
async connect() { this.connected = true; }
|
|
31
|
+
launch(params) {
|
|
32
|
+
if (this.child)
|
|
33
|
+
throw new Error('A managed Flutter app is already running.');
|
|
34
|
+
if (params.mode === 'drive')
|
|
35
|
+
throw new Error('Managed VM Service launch uses flutter run; drive mode is not supported.');
|
|
36
|
+
const bin = this.opts.flutterBin ?? 'flutter';
|
|
37
|
+
const args = ['run', '--machine', '-d', String(params.deviceId), '-t', String(params.target ?? 'lib/main.dart'),
|
|
38
|
+
...(Array.isArray(params.flutterArgs) ? params.flutterArgs.map(String) : []), ...(this.opts.extraArgs ?? [])];
|
|
39
|
+
this.stderr = '';
|
|
40
|
+
this.buffer = '';
|
|
41
|
+
this.startingApp = undefined;
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
this.starting = { resolve, reject };
|
|
44
|
+
const child = spawn(bin, args, { cwd: typeof params.projectId === 'string' ? params.projectId : this.opts.cwd,
|
|
45
|
+
stdio: ['pipe', 'pipe', 'pipe'], detached: process.platform !== 'win32' });
|
|
46
|
+
this.child = child;
|
|
47
|
+
this.exited = new Promise(resolve => { child.once('exit', () => resolve()); });
|
|
48
|
+
child.stdout.setEncoding('utf8');
|
|
49
|
+
child.stdout.on('data', (chunk) => {
|
|
50
|
+
this.buffer += chunk;
|
|
51
|
+
let nl;
|
|
52
|
+
while ((nl = this.buffer.indexOf('\n')) >= 0) {
|
|
53
|
+
const line = this.buffer.slice(0, nl);
|
|
54
|
+
this.buffer = this.buffer.slice(nl + 1);
|
|
55
|
+
for (const message of parseDaemonLines(line))
|
|
56
|
+
this.dispatch(message);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
child.stderr.on('data', (chunk) => { this.stderr = (this.stderr + String(chunk)).slice(-8192); });
|
|
60
|
+
child.on('error', (error) => this.rejectAll(new Error(`Failed to start ${bin} run --machine: ${error.message}`)));
|
|
61
|
+
child.on('exit', (code, signal) => {
|
|
62
|
+
if (this.child === child) {
|
|
63
|
+
this.child = undefined;
|
|
64
|
+
this.rejectAll(new Error(`flutter run --machine exited with code ${code ?? 'null'} signal ${signal ?? 'null'}${this.stderr ? `: ${this.stderr}` : ''}`));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
request(method, params = {}) {
|
|
70
|
+
if (!this.connected)
|
|
71
|
+
throw new Error('SubprocessDaemonTransport is not connected');
|
|
72
|
+
// app.start is the controller's launch abstraction. Flutter itself launches
|
|
73
|
+
// through run --machine and emits app.start; it has no app.start RPC.
|
|
74
|
+
if (method === 'app.start')
|
|
75
|
+
return this.launch(params);
|
|
76
|
+
if (!this.child)
|
|
77
|
+
throw new Error('No managed Flutter app is running');
|
|
78
|
+
const id = this.seq++;
|
|
79
|
+
const line = `${JSON.stringify([{ id, method, params }])}\n`;
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
this.pending.set(id, { resolve: resolve, reject });
|
|
82
|
+
this.child?.stdin.write(line, (error) => {
|
|
83
|
+
if (!error)
|
|
84
|
+
return;
|
|
85
|
+
this.pending.delete(id);
|
|
86
|
+
reject(error);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
onEvent(handler) {
|
|
91
|
+
this.listeners.add(handler);
|
|
92
|
+
return () => {
|
|
93
|
+
this.listeners.delete(handler);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
dispose(options = {}) {
|
|
97
|
+
return this.closing ??= this.close(options);
|
|
98
|
+
}
|
|
99
|
+
async close(options) {
|
|
100
|
+
const child = this.child;
|
|
101
|
+
this.child = undefined;
|
|
102
|
+
this.buffer = '';
|
|
103
|
+
this.rejectAll(new Error('SubprocessDaemonTransport disposed'));
|
|
104
|
+
this.connected = false;
|
|
105
|
+
if (child?.pid && child.exitCode === null && child.signalCode === null) {
|
|
106
|
+
const wait = async () => {
|
|
107
|
+
let timer;
|
|
108
|
+
try {
|
|
109
|
+
return await Promise.race([this.exited.then(() => true), new Promise(resolve => {
|
|
110
|
+
timer = setTimeout(() => resolve(false), 2000);
|
|
111
|
+
})]);
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
if (options.keepAppAlive) {
|
|
118
|
+
child.stdin.end();
|
|
119
|
+
if (await wait())
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
123
|
+
const terminate = (signal) => { try {
|
|
124
|
+
process.kill(process.platform === 'win32' ? child.pid : -child.pid, signal);
|
|
125
|
+
}
|
|
126
|
+
catch { } };
|
|
127
|
+
terminate('SIGTERM');
|
|
128
|
+
if (!await wait()) {
|
|
129
|
+
terminate('SIGKILL');
|
|
130
|
+
if (!await wait())
|
|
131
|
+
throw new Error('Owned Flutter process termination could not be confirmed.');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
dispatch(message) {
|
|
137
|
+
if (message.id !== undefined && (message.result !== undefined || message.error !== undefined)) {
|
|
138
|
+
const id = Number(message.id);
|
|
139
|
+
const pending = this.pending.get(id);
|
|
140
|
+
if (!pending)
|
|
141
|
+
return;
|
|
142
|
+
this.pending.delete(id);
|
|
143
|
+
if (message.error)
|
|
144
|
+
pending.reject(new Error(typeof message.error === 'string' ? message.error : message.error.message));
|
|
145
|
+
else
|
|
146
|
+
pending.resolve(message.result);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (message.event === 'app.start' && this.starting)
|
|
150
|
+
this.startingApp = message.params;
|
|
151
|
+
if (message.event === 'app.started' && this.starting && message.params?.appId === this.startingApp?.appId) {
|
|
152
|
+
this.starting.resolve(this.startingApp);
|
|
153
|
+
this.starting = undefined;
|
|
154
|
+
}
|
|
155
|
+
if (message.event === 'app.stop' && this.starting)
|
|
156
|
+
this.rejectAll(new Error(`Flutter app stopped during startup: ${JSON.stringify(message.params)}${this.stderr}`));
|
|
157
|
+
if (message.event === 'app.log' && message.params?.error)
|
|
158
|
+
this.stderr = (this.stderr + String(message.params.log ?? '')).slice(-8192);
|
|
159
|
+
if (message.event) {
|
|
160
|
+
for (const listener of this.listeners)
|
|
161
|
+
listener(message);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
rejectAll(error) {
|
|
165
|
+
this.starting?.reject(error);
|
|
166
|
+
this.starting = undefined;
|
|
167
|
+
for (const pending of this.pending.values())
|
|
168
|
+
pending.reject(error);
|
|
169
|
+
this.pending.clear();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ResetCategory, TddCycleResult } from '../types.js';
|
|
2
|
+
export type TddFailureKind = 'missing-element' | 'ambiguous-element' | 'wrong-text' | 'navigation-failed' | 'mock-not-called' | 'state-mismatch' | 'timeout' | 'disconnected' | 'test-error';
|
|
3
|
+
export interface TddFailureContext {
|
|
4
|
+
kind: TddFailureKind;
|
|
5
|
+
message: string;
|
|
6
|
+
testFile: string;
|
|
7
|
+
testName?: string;
|
|
8
|
+
lastSync?: TddCycleResult['lastSync'];
|
|
9
|
+
baselineVersion?: number;
|
|
10
|
+
unsupportedState?: ResetCategory[];
|
|
11
|
+
source?: TddFailureSource;
|
|
12
|
+
assertion?: TddFailureAssertion;
|
|
13
|
+
artifacts?: TddFailureArtifacts;
|
|
14
|
+
recoveryHints?: TddRecoveryHint[];
|
|
15
|
+
}
|
|
16
|
+
export type TddRecoveryHintKind = 'inspect-source' | 'inspect-snapshot' | 'refine-selector' | 'disambiguate-selector' | 'check-navigation' | 'configure-mock' | 'seed-state' | 'sync-app' | 'increase-timeout' | 'reconnect' | 'configure-reset-adapter';
|
|
17
|
+
export interface TddRecoveryHint {
|
|
18
|
+
kind: TddRecoveryHintKind;
|
|
19
|
+
priority: 'high' | 'medium' | 'low';
|
|
20
|
+
message: string;
|
|
21
|
+
actions: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface BuildTddFailureContextInput {
|
|
24
|
+
file: string;
|
|
25
|
+
testName?: string;
|
|
26
|
+
message?: string;
|
|
27
|
+
/** Override the heuristic classification (e.g. an explicit cycle timeout / disconnect). */
|
|
28
|
+
kind?: TddFailureKind;
|
|
29
|
+
lastSync?: TddCycleResult['lastSync'];
|
|
30
|
+
baselineVersion?: number;
|
|
31
|
+
unsupportedState?: ResetCategory[];
|
|
32
|
+
source?: TddFailureSource;
|
|
33
|
+
assertion?: TddFailureAssertion;
|
|
34
|
+
artifacts?: TddFailureArtifacts;
|
|
35
|
+
}
|
|
36
|
+
export interface TddFailureSource {
|
|
37
|
+
file: string;
|
|
38
|
+
line: number;
|
|
39
|
+
snippet: string;
|
|
40
|
+
}
|
|
41
|
+
export interface TddFailureAssertion {
|
|
42
|
+
matcher: string;
|
|
43
|
+
expected: string;
|
|
44
|
+
actual: string;
|
|
45
|
+
timeout: number;
|
|
46
|
+
}
|
|
47
|
+
export interface TddFailureArtifacts {
|
|
48
|
+
failureContextPath?: string;
|
|
49
|
+
screenshotPath?: string;
|
|
50
|
+
screenshotBase64?: string;
|
|
51
|
+
widgetTree?: unknown;
|
|
52
|
+
timelinePath?: string;
|
|
53
|
+
timelineNodeId?: string;
|
|
54
|
+
}
|
|
55
|
+
export declare function buildTddFailureContext(input: BuildTddFailureContextInput): TddFailureContext;
|
|
56
|
+
export declare function classifyFailure(message: string): TddFailureKind;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
export function buildTddFailureContext(input) {
|
|
2
|
+
const message = input.message?.trim() || 'Focused TDD test failed without a structured failure message.';
|
|
3
|
+
const kind = input.kind ?? classifyFailure(message);
|
|
4
|
+
const context = {
|
|
5
|
+
kind,
|
|
6
|
+
message,
|
|
7
|
+
testFile: input.file,
|
|
8
|
+
testName: input.testName,
|
|
9
|
+
lastSync: input.lastSync,
|
|
10
|
+
baselineVersion: input.baselineVersion,
|
|
11
|
+
unsupportedState: input.unsupportedState?.length ? input.unsupportedState : undefined,
|
|
12
|
+
source: input.source,
|
|
13
|
+
assertion: input.assertion,
|
|
14
|
+
artifacts: input.artifacts,
|
|
15
|
+
};
|
|
16
|
+
const recoveryHints = buildRecoveryHints(context);
|
|
17
|
+
return {
|
|
18
|
+
...context,
|
|
19
|
+
recoveryHints: recoveryHints.length > 0 ? recoveryHints : undefined,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function classifyFailure(message) {
|
|
23
|
+
const normalized = message.toLowerCase();
|
|
24
|
+
if (normalized.includes('strict mode violation')
|
|
25
|
+
|| normalized.includes('multiple widgets')
|
|
26
|
+
|| normalized.includes('ambiguous')) {
|
|
27
|
+
return 'ambiguous-element';
|
|
28
|
+
}
|
|
29
|
+
if (normalized.includes('no widget found')
|
|
30
|
+
|| normalized.includes('could not find')
|
|
31
|
+
|| normalized.includes('not found')
|
|
32
|
+
|| normalized.includes('tobevisible')
|
|
33
|
+
|| normalized.includes('to be visible')) {
|
|
34
|
+
return 'missing-element';
|
|
35
|
+
}
|
|
36
|
+
if (normalized.includes('currentroute')
|
|
37
|
+
|| normalized.includes('reset route')
|
|
38
|
+
|| normalized.includes('route')
|
|
39
|
+
|| normalized.includes('navigation')) {
|
|
40
|
+
return 'navigation-failed';
|
|
41
|
+
}
|
|
42
|
+
if (normalized.includes('tohavetext')
|
|
43
|
+
|| normalized.includes('tocontaintext')
|
|
44
|
+
|| (normalized.includes('expected') && normalized.includes('received'))) {
|
|
45
|
+
return 'wrong-text';
|
|
46
|
+
}
|
|
47
|
+
if (normalized.includes('waitforcall')
|
|
48
|
+
|| normalized.includes('recorded calls')
|
|
49
|
+
|| normalized.includes('mock')
|
|
50
|
+
|| normalized.includes('called at least')) {
|
|
51
|
+
return 'mock-not-called';
|
|
52
|
+
}
|
|
53
|
+
if (normalized.includes('state') || normalized.includes('provider')) {
|
|
54
|
+
return 'state-mismatch';
|
|
55
|
+
}
|
|
56
|
+
return 'test-error';
|
|
57
|
+
}
|
|
58
|
+
function buildRecoveryHints(context) {
|
|
59
|
+
const hints = [];
|
|
60
|
+
if (context.unsupportedState?.length) {
|
|
61
|
+
hints.push({
|
|
62
|
+
kind: 'configure-reset-adapter',
|
|
63
|
+
priority: 'high',
|
|
64
|
+
message: `Baseline reset could not fully control: ${context.unsupportedState.join(', ')}.`,
|
|
65
|
+
actions: [
|
|
66
|
+
'Add the missing host app reset handler/capability, or remove the unsupported category from the scenario while iterating.',
|
|
67
|
+
'If the category is required for determinism, configure it before trusting a green result.',
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (context.source) {
|
|
72
|
+
hints.push({
|
|
73
|
+
kind: 'inspect-source',
|
|
74
|
+
priority: 'medium',
|
|
75
|
+
message: `Inspect the failing test source at ${context.source.file}:${context.source.line}.`,
|
|
76
|
+
actions: [
|
|
77
|
+
'Open the reported source line and compare the assertion or locator with the current app snapshot.',
|
|
78
|
+
'Prefer fixing stale generated test code before changing app behavior.',
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (context.artifacts?.screenshotPath || context.artifacts?.widgetTree || context.artifacts?.timelinePath) {
|
|
83
|
+
hints.push({
|
|
84
|
+
kind: 'inspect-snapshot',
|
|
85
|
+
priority: 'medium',
|
|
86
|
+
message: 'Use the captured artifacts to compare expected UI with the actual rendered app state.',
|
|
87
|
+
actions: [
|
|
88
|
+
'Inspect screenshot, widget tree, or timeline artifacts before editing code.',
|
|
89
|
+
'If the UI is correct but the locator is stale, update the generated test selector.',
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
switch (context.kind) {
|
|
94
|
+
case 'missing-element':
|
|
95
|
+
hints.push({
|
|
96
|
+
kind: 'refine-selector',
|
|
97
|
+
priority: 'high',
|
|
98
|
+
message: 'The generated test is looking for a widget that is not currently discoverable.',
|
|
99
|
+
actions: [
|
|
100
|
+
'Capture a fresh fliwright app snapshot and replace brittle text/type selectors with key or semantics selectors when available.',
|
|
101
|
+
'If the widget should exist but does not render, fix the app state/setup before changing the assertion.',
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
maybeSuggestSync(hints, context);
|
|
105
|
+
break;
|
|
106
|
+
case 'ambiguous-element':
|
|
107
|
+
hints.push({
|
|
108
|
+
kind: 'disambiguate-selector',
|
|
109
|
+
priority: 'high',
|
|
110
|
+
message: 'The locator matches multiple widgets.',
|
|
111
|
+
actions: [
|
|
112
|
+
'Narrow the selector using a stable key, semantics label, ancestor scope, or visible text unique to the intended widget.',
|
|
113
|
+
'Avoid broad text/type locators in generated tests when several widgets share the same label.',
|
|
114
|
+
],
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
case 'wrong-text':
|
|
118
|
+
hints.push({
|
|
119
|
+
kind: 'inspect-source',
|
|
120
|
+
priority: 'high',
|
|
121
|
+
message: 'The assertion expected different text or value than the app produced.',
|
|
122
|
+
actions: [
|
|
123
|
+
'Decide whether the generated expectation is stale or the product behavior is wrong.',
|
|
124
|
+
'Update the test only when the current app output is the intended behavior.',
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
break;
|
|
128
|
+
case 'navigation-failed':
|
|
129
|
+
hints.push({
|
|
130
|
+
kind: 'check-navigation',
|
|
131
|
+
priority: 'high',
|
|
132
|
+
message: 'The app is not on the expected route or reset route.',
|
|
133
|
+
actions: [
|
|
134
|
+
'Check scenario.homeRoute and any navigation preconditions in the generated test.',
|
|
135
|
+
'If routing code changed, rerun with sync:auto or restart before editing assertions.',
|
|
136
|
+
],
|
|
137
|
+
});
|
|
138
|
+
break;
|
|
139
|
+
case 'mock-not-called':
|
|
140
|
+
hints.push({
|
|
141
|
+
kind: 'configure-mock',
|
|
142
|
+
priority: 'high',
|
|
143
|
+
message: 'The expected mocked endpoint was not called or did not match the active mock profile.',
|
|
144
|
+
actions: [
|
|
145
|
+
'Verify the mock endpoint, HTTP method, active rule, and mockProfile used by the scenario.',
|
|
146
|
+
'Check whether the app reached the action that should trigger the request.',
|
|
147
|
+
],
|
|
148
|
+
});
|
|
149
|
+
break;
|
|
150
|
+
case 'state-mismatch':
|
|
151
|
+
hints.push({
|
|
152
|
+
kind: 'seed-state',
|
|
153
|
+
priority: 'high',
|
|
154
|
+
message: 'The app state does not match the test precondition.',
|
|
155
|
+
actions: [
|
|
156
|
+
'Seed required storage/Riverpod/app state through the scenario before the cycle.',
|
|
157
|
+
'If reset categories are unsupported, configure the host app reset contract first.',
|
|
158
|
+
],
|
|
159
|
+
});
|
|
160
|
+
break;
|
|
161
|
+
case 'timeout':
|
|
162
|
+
hints.push({
|
|
163
|
+
kind: 'increase-timeout',
|
|
164
|
+
priority: 'medium',
|
|
165
|
+
message: 'The cycle exceeded its wall-clock budget.',
|
|
166
|
+
actions: [
|
|
167
|
+
'Inspect whether the app is stuck, a locator wait is too broad, or the timeoutMs budget is too small.',
|
|
168
|
+
'Keep the next cycle serialized; do not start a second runtime while the previous body is finishing.',
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
break;
|
|
172
|
+
case 'disconnected':
|
|
173
|
+
hints.push({
|
|
174
|
+
kind: 'reconnect',
|
|
175
|
+
priority: 'high',
|
|
176
|
+
message: 'The Flutter VM service connection appears disconnected.',
|
|
177
|
+
actions: [
|
|
178
|
+
'Call fliwright tdd reconnect, then rerun the focused cycle.',
|
|
179
|
+
'If reconnect fails, restart the app/runtime and preserve the generated test file.',
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
break;
|
|
183
|
+
case 'test-error':
|
|
184
|
+
hints.push({
|
|
185
|
+
kind: 'inspect-source',
|
|
186
|
+
priority: 'high',
|
|
187
|
+
message: 'The failure is not recognized as a selector, mock, navigation, state, or timeout issue.',
|
|
188
|
+
actions: [
|
|
189
|
+
'Read the raw error and failing source line before editing.',
|
|
190
|
+
'If this is a compile/runtime error, fix the test or app code and rerun the same focused cycle.',
|
|
191
|
+
],
|
|
192
|
+
});
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
return dedupeHints(hints);
|
|
198
|
+
}
|
|
199
|
+
function maybeSuggestSync(hints, context) {
|
|
200
|
+
if (context.lastSync === 'restart')
|
|
201
|
+
return;
|
|
202
|
+
hints.push({
|
|
203
|
+
kind: 'sync-app',
|
|
204
|
+
priority: 'low',
|
|
205
|
+
message: 'A missing widget can be caused by stale hot-reload state after structural app changes.',
|
|
206
|
+
actions: [
|
|
207
|
+
'If app structure, generated code, assets, or providers changed, rerun with sync:auto or sync:restart.',
|
|
208
|
+
],
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function dedupeHints(hints) {
|
|
212
|
+
const seen = new Set();
|
|
213
|
+
return hints.filter((hint) => {
|
|
214
|
+
const key = `${hint.kind}:${hint.message}`;
|
|
215
|
+
if (seen.has(key))
|
|
216
|
+
return false;
|
|
217
|
+
seen.add(key);
|
|
218
|
+
return true;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Vitest } from 'vitest/node';
|
|
2
|
+
/**
|
|
3
|
+
* Encodes the Vitest 5 focused rerun recipe for the persistent TDD executor.
|
|
4
|
+
* Vitest 5 replaces changeNamePattern/changeFilenamePattern with specification-scoped
|
|
5
|
+
* filters plus rerunTestSpecifications.
|
|
6
|
+
*/
|
|
7
|
+
export declare function focusAndRerun(vitest: Vitest, file: string, testName?: string): ReturnType<Vitest['rerunTestSpecifications']>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { stat } from 'node:fs/promises';
|
|
2
|
+
import { relative, resolve, sep } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Encodes the Vitest 5 focused rerun recipe for the persistent TDD executor.
|
|
5
|
+
* Vitest 5 replaces changeNamePattern/changeFilenamePattern with specification-scoped
|
|
6
|
+
* filters plus rerunTestSpecifications.
|
|
7
|
+
*/
|
|
8
|
+
export async function focusAndRerun(vitest, file, testName) {
|
|
9
|
+
const specifications = await resolveSpecifications(vitest, file);
|
|
10
|
+
if (specifications.length === 0) {
|
|
11
|
+
throw new Error(`No Vitest specifications found for ${file}`);
|
|
12
|
+
}
|
|
13
|
+
const savedPatterns = specifications.map((spec) => spec.testNamePattern);
|
|
14
|
+
try {
|
|
15
|
+
if (testName) {
|
|
16
|
+
// Names are literal, including punctuation. A leaf name may occur in
|
|
17
|
+
// several suites; the executor aggregates all matching results.
|
|
18
|
+
const escaped = testName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
19
|
+
const pattern = new RegExp(`(?:^| > )${escaped}$`);
|
|
20
|
+
for (const spec of specifications)
|
|
21
|
+
spec.testNamePattern = pattern;
|
|
22
|
+
}
|
|
23
|
+
const run = await vitest.rerunTestSpecifications(specifications);
|
|
24
|
+
// Vitest returns its accumulated module state, including previously run
|
|
25
|
+
// files. Only this request's files belong to the focused result.
|
|
26
|
+
const moduleIds = new Set(specifications.map((spec) => spec.moduleId));
|
|
27
|
+
return { ...run, testModules: run.testModules.filter((module) => moduleIds.has(module.moduleId)) };
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
specifications.forEach((spec, index) => {
|
|
31
|
+
spec.testNamePattern = savedPatterns[index];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function resolveSpecifications(vitest, file) {
|
|
36
|
+
let specifications = vitest.getModuleSpecifications(file);
|
|
37
|
+
if (specifications.length > 0)
|
|
38
|
+
return specifications;
|
|
39
|
+
specifications = (await vitest.globTestSpecifications([file])).filter((spec) => spec.moduleId === file);
|
|
40
|
+
if (specifications.length > 0)
|
|
41
|
+
return specifications;
|
|
42
|
+
const candidate = resolve(file);
|
|
43
|
+
if (!(await isFile(candidate)))
|
|
44
|
+
return [];
|
|
45
|
+
// When a persistent watcher has cleared its module cache between reruns,
|
|
46
|
+
// create a specification directly for the exact file. Generated candidates
|
|
47
|
+
// are deliberately excluded from normal project discovery, and ordinary
|
|
48
|
+
// files use this only as a race-safe fallback.
|
|
49
|
+
return vitest.projects
|
|
50
|
+
.filter((project) => isWithinProject(project.config.root, candidate))
|
|
51
|
+
.map((project) => project.createSpecification(candidate));
|
|
52
|
+
}
|
|
53
|
+
function isWithinProject(root, file) {
|
|
54
|
+
const path = relative(root, file);
|
|
55
|
+
return path !== '' && !path.startsWith(`..${sep}`) && path !== '..' && !path.startsWith(sep);
|
|
56
|
+
}
|
|
57
|
+
async function isFile(path) {
|
|
58
|
+
try {
|
|
59
|
+
return (await stat(path)).isFile();
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { TddFailureArtifacts, TddFailureAssertion, TddFailureSource } from '../diagnostics/TddFailureContext.js';
|
|
2
|
+
export interface TestRunOutcome {
|
|
3
|
+
status: 'red' | 'green';
|
|
4
|
+
testName?: string;
|
|
5
|
+
failure?: {
|
|
6
|
+
message?: string;
|
|
7
|
+
};
|
|
8
|
+
failureDetails?: TddFailureDetails;
|
|
9
|
+
timelinePath?: string;
|
|
10
|
+
timelineNodeId?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface BootOptions {
|
|
13
|
+
configRoot: string;
|
|
14
|
+
vmServiceUrl?: string;
|
|
15
|
+
runsRoot?: string;
|
|
16
|
+
sharedConfig?: Partial<import('@fliwright/core').FliwrightProjectConfig>;
|
|
17
|
+
defaultScenario?: string;
|
|
18
|
+
scenarioMode?: 'managed-start' | 'attach';
|
|
19
|
+
}
|
|
20
|
+
export declare class PersistentTestExecutor {
|
|
21
|
+
private vitest?;
|
|
22
|
+
private previousDefaultScenario?;
|
|
23
|
+
private previousScenarioMode?;
|
|
24
|
+
private previousVmServiceUrl?;
|
|
25
|
+
private previousVmUrl?;
|
|
26
|
+
private previousTddMode?;
|
|
27
|
+
private previousScreenshotMode?;
|
|
28
|
+
private previousFailureTimeoutMs?;
|
|
29
|
+
private previousRunsRoot?;
|
|
30
|
+
private previousRunId?;
|
|
31
|
+
private previousSharedConfig?;
|
|
32
|
+
private previousProjectRoot?;
|
|
33
|
+
private runsRoot?;
|
|
34
|
+
private envApplied;
|
|
35
|
+
boot(opts: BootOptions): Promise<void>;
|
|
36
|
+
rerun(file: string, testName?: string): Promise<TestRunOutcome>;
|
|
37
|
+
dispose(): Promise<void>;
|
|
38
|
+
private restoreRuntimeEnv;
|
|
39
|
+
private applyRuntimeEnv;
|
|
40
|
+
private snapshotPreviousEnv;
|
|
41
|
+
private attemptDirectory;
|
|
42
|
+
private readFailureDetails;
|
|
43
|
+
private readTimelineArtifacts;
|
|
44
|
+
}
|
|
45
|
+
export declare function defaultArtifactsRoot(configRoot: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Default RuntimeSnapshot status-file path a read-only monitor (e.g. the VS Code TDD Loop panel)
|
|
48
|
+
* polls: `~/.fliwright/<project-path>/runtime/tdd-status.json`. The project root is derived from the same
|
|
49
|
+
* configRoot convention as {@link defaultArtifactsRoot}.
|
|
50
|
+
*/
|
|
51
|
+
export declare function defaultStatusFilePath(configRoot: string): string;
|
|
52
|
+
export interface TddFailureDetails {
|
|
53
|
+
assertion?: TddFailureAssertion;
|
|
54
|
+
source?: TddFailureSource;
|
|
55
|
+
artifacts?: TddFailureArtifacts;
|
|
56
|
+
}
|