@fliwright/tdd 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 +7 -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 +19 -0
- package/dist/daemon/FlutterDaemonController.js +109 -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 +29 -0
- package/dist/daemon/SubprocessDaemonTransport.js +155 -0
- package/dist/devassist/DevAssistCoordinator.d.ts +74 -0
- package/dist/devassist/DevAssistCoordinator.js +388 -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 +57 -0
- package/dist/executor/PersistentTestExecutor.d.ts +59 -0
- package/dist/executor/PersistentTestExecutor.js +242 -0
- package/dist/executor/ResultReporter.d.ts +23 -0
- package/dist/executor/ResultReporter.js +50 -0
- package/dist/generator/RedFirstTestGenerator.d.ts +32 -0
- package/dist/generator/RedFirstTestGenerator.js +189 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +20 -0
- package/dist/repair/TddRepairPlanner.d.ts +54 -0
- package/dist/repair/TddRepairPlanner.js +132 -0
- package/dist/runtime/TddRuntime.d.ts +87 -0
- package/dist/runtime/TddRuntime.js +589 -0
- package/dist/selectors/SelectorSynthesizer.d.ts +34 -0
- package/dist/selectors/SelectorSynthesizer.js +174 -0
- package/dist/spec/InteractionSpec.d.ts +94 -0
- package/dist/spec/InteractionSpec.js +236 -0
- package/dist/spec/InteractionSpecCoverage.d.ts +17 -0
- package/dist/spec/InteractionSpecCoverage.js +69 -0
- package/dist/types.d.ts +314 -0
- package/dist/types.js +2 -0
- package/dist/workflow/RedFirstWorkflow.d.ts +28 -0
- package/dist/workflow/RedFirstWorkflow.js +33 -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,29 @@
|
|
|
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
|
+
connect(): Promise<void>;
|
|
21
|
+
private launch;
|
|
22
|
+
request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
23
|
+
onEvent(handler: (message: DaemonMessage) => void): () => void;
|
|
24
|
+
dispose(options?: {
|
|
25
|
+
keepAppAlive?: boolean;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
private dispatch;
|
|
28
|
+
private rejectAll;
|
|
29
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
async connect() { this.connected = true; }
|
|
29
|
+
launch(params) {
|
|
30
|
+
if (this.child)
|
|
31
|
+
throw new Error('A managed Flutter app is already running.');
|
|
32
|
+
if (params.mode === 'drive')
|
|
33
|
+
throw new Error('Managed VM Service launch uses flutter run; drive mode is not supported.');
|
|
34
|
+
const bin = this.opts.flutterBin ?? 'flutter';
|
|
35
|
+
const args = ['run', '--machine', '-d', String(params.deviceId), '-t', String(params.target ?? 'lib/main.dart'),
|
|
36
|
+
...(Array.isArray(params.flutterArgs) ? params.flutterArgs.map(String) : []), ...(this.opts.extraArgs ?? [])];
|
|
37
|
+
this.stderr = '';
|
|
38
|
+
this.buffer = '';
|
|
39
|
+
this.startingApp = undefined;
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
this.starting = { resolve, reject };
|
|
42
|
+
const child = spawn(bin, args, { cwd: typeof params.projectId === 'string' ? params.projectId : this.opts.cwd,
|
|
43
|
+
stdio: ['pipe', 'pipe', 'pipe'], detached: process.platform !== 'win32' });
|
|
44
|
+
this.child = child;
|
|
45
|
+
child.stdout.setEncoding('utf8');
|
|
46
|
+
child.stdout.on('data', (chunk) => {
|
|
47
|
+
this.buffer += chunk;
|
|
48
|
+
let nl;
|
|
49
|
+
while ((nl = this.buffer.indexOf('\n')) >= 0) {
|
|
50
|
+
const line = this.buffer.slice(0, nl);
|
|
51
|
+
this.buffer = this.buffer.slice(nl + 1);
|
|
52
|
+
for (const message of parseDaemonLines(line))
|
|
53
|
+
this.dispatch(message);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
child.stderr.on('data', (chunk) => { this.stderr = (this.stderr + String(chunk)).slice(-8192); });
|
|
57
|
+
child.on('error', (error) => this.rejectAll(new Error(`Failed to start ${bin} run --machine: ${error.message}`)));
|
|
58
|
+
child.on('exit', (code, signal) => {
|
|
59
|
+
if (this.child === child) {
|
|
60
|
+
this.child = undefined;
|
|
61
|
+
this.rejectAll(new Error(`flutter run --machine exited with code ${code ?? 'null'} signal ${signal ?? 'null'}${this.stderr ? `: ${this.stderr}` : ''}`));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
request(method, params = {}) {
|
|
67
|
+
if (!this.connected)
|
|
68
|
+
throw new Error('SubprocessDaemonTransport is not connected');
|
|
69
|
+
// app.start is the controller's launch abstraction. Flutter itself launches
|
|
70
|
+
// through run --machine and emits app.start; it has no app.start RPC.
|
|
71
|
+
if (method === 'app.start')
|
|
72
|
+
return this.launch(params);
|
|
73
|
+
if (!this.child)
|
|
74
|
+
throw new Error('No managed Flutter app is running');
|
|
75
|
+
const id = this.seq++;
|
|
76
|
+
const line = `${JSON.stringify([{ id, method, params }])}\n`;
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
this.pending.set(id, { resolve: resolve, reject });
|
|
79
|
+
this.child?.stdin.write(line, (error) => {
|
|
80
|
+
if (!error)
|
|
81
|
+
return;
|
|
82
|
+
this.pending.delete(id);
|
|
83
|
+
reject(error);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
onEvent(handler) {
|
|
88
|
+
this.listeners.add(handler);
|
|
89
|
+
return () => {
|
|
90
|
+
this.listeners.delete(handler);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async dispose(options = {}) {
|
|
94
|
+
const child = this.child;
|
|
95
|
+
this.child = undefined;
|
|
96
|
+
this.buffer = '';
|
|
97
|
+
this.rejectAll(new Error('SubprocessDaemonTransport disposed'));
|
|
98
|
+
this.connected = false;
|
|
99
|
+
if (child?.pid && child.exitCode === null && child.signalCode === null) {
|
|
100
|
+
if (options.keepAppAlive) {
|
|
101
|
+
child.stdin.end();
|
|
102
|
+
await new Promise((resolve) => {
|
|
103
|
+
const timer = setTimeout(resolve, 2000);
|
|
104
|
+
child.once('exit', () => { clearTimeout(timer); resolve(); });
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
108
|
+
const terminate = (signal) => { try {
|
|
109
|
+
process.kill(process.platform === 'win32' ? child.pid : -child.pid, signal);
|
|
110
|
+
}
|
|
111
|
+
catch { } };
|
|
112
|
+
terminate('SIGTERM');
|
|
113
|
+
await new Promise((resolve) => {
|
|
114
|
+
const timer = setTimeout(() => { terminate('SIGKILL'); resolve(); }, 2000);
|
|
115
|
+
child.once('exit', () => { clearTimeout(timer); resolve(); });
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
dispatch(message) {
|
|
121
|
+
if (message.id !== undefined && (message.result !== undefined || message.error !== undefined)) {
|
|
122
|
+
const id = Number(message.id);
|
|
123
|
+
const pending = this.pending.get(id);
|
|
124
|
+
if (!pending)
|
|
125
|
+
return;
|
|
126
|
+
this.pending.delete(id);
|
|
127
|
+
if (message.error)
|
|
128
|
+
pending.reject(new Error(typeof message.error === 'string' ? message.error : message.error.message));
|
|
129
|
+
else
|
|
130
|
+
pending.resolve(message.result);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (message.event === 'app.start' && this.starting)
|
|
134
|
+
this.startingApp = message.params;
|
|
135
|
+
if (message.event === 'app.started' && this.starting && message.params?.appId === this.startingApp?.appId) {
|
|
136
|
+
this.starting.resolve(this.startingApp);
|
|
137
|
+
this.starting = undefined;
|
|
138
|
+
}
|
|
139
|
+
if (message.event === 'app.stop' && this.starting)
|
|
140
|
+
this.rejectAll(new Error(`Flutter app stopped during startup: ${JSON.stringify(message.params)}${this.stderr}`));
|
|
141
|
+
if (message.event === 'app.log' && message.params?.error)
|
|
142
|
+
this.stderr = (this.stderr + String(message.params.log ?? '')).slice(-8192);
|
|
143
|
+
if (message.event) {
|
|
144
|
+
for (const listener of this.listeners)
|
|
145
|
+
listener(message);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
rejectAll(error) {
|
|
149
|
+
this.starting?.reject(error);
|
|
150
|
+
this.starting = undefined;
|
|
151
|
+
for (const pending of this.pending.values())
|
|
152
|
+
pending.reject(error);
|
|
153
|
+
this.pending.clear();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { AiRuntime, DevAssistTraceStore, type AgentDiagnosis, type ChangeSetSnapshot, type TimelineArtifactRef } from '@fliwright/core';
|
|
2
|
+
import { type InteractionSpec } from '../spec/InteractionSpec.js';
|
|
3
|
+
import type { CycleOpts, TddCycleResult } from '../types.js';
|
|
4
|
+
export type DevAssistAction = 'start' | 'continue' | 'regenerate';
|
|
5
|
+
export type DevAssistStatus = 'green' | 'red' | 'needs_review' | 'needs_regeneration' | 'blocked';
|
|
6
|
+
export interface DevAssistCycleInput {
|
|
7
|
+
request?: string;
|
|
8
|
+
devAssistSessionId?: string;
|
|
9
|
+
action?: DevAssistAction;
|
|
10
|
+
files?: string[];
|
|
11
|
+
baseRevision?: string;
|
|
12
|
+
vmServiceUrl?: string;
|
|
13
|
+
deviceId?: string;
|
|
14
|
+
projectId?: string;
|
|
15
|
+
target?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DevAssistCycleResult {
|
|
18
|
+
status: DevAssistStatus;
|
|
19
|
+
devAssistSessionId?: string;
|
|
20
|
+
devAssistTracePath?: string;
|
|
21
|
+
timelinePath?: string;
|
|
22
|
+
timelineNodeId?: string;
|
|
23
|
+
artifacts?: TimelineArtifactRef[];
|
|
24
|
+
candidateTestPath?: string;
|
|
25
|
+
changeSet?: ChangeSetSnapshot;
|
|
26
|
+
sync?: {
|
|
27
|
+
decision: 'none' | 'reload' | 'restart';
|
|
28
|
+
escalation?: boolean;
|
|
29
|
+
};
|
|
30
|
+
diagnosis?: AgentDiagnosis;
|
|
31
|
+
nextCall?: DevAssistCycleInput;
|
|
32
|
+
reason?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface DevAssistInferenceResult {
|
|
35
|
+
testName: string;
|
|
36
|
+
provider?: string;
|
|
37
|
+
model?: string;
|
|
38
|
+
spec: InteractionSpec;
|
|
39
|
+
}
|
|
40
|
+
export interface DevAssistRuntime {
|
|
41
|
+
focus(file: string, testName?: string): Promise<unknown>;
|
|
42
|
+
cycle(testName?: string, opts?: CycleOpts): Promise<TddCycleResult>;
|
|
43
|
+
}
|
|
44
|
+
export interface DevAssistCoordinatorDeps {
|
|
45
|
+
cwd?: string;
|
|
46
|
+
runtime?: DevAssistRuntime;
|
|
47
|
+
aiRuntime?: AiRuntime;
|
|
48
|
+
traceStore?: DevAssistTraceStore;
|
|
49
|
+
changeSetProvider?: (input: DevAssistCycleInput) => Promise<ChangeSetSnapshot>;
|
|
50
|
+
infer?: (input: {
|
|
51
|
+
request?: string;
|
|
52
|
+
changeSet: ChangeSetSnapshot;
|
|
53
|
+
}) => Promise<DevAssistInferenceResult>;
|
|
54
|
+
diagnose?: (result: TddCycleResult) => Promise<AgentDiagnosis | undefined>;
|
|
55
|
+
createSessionId?: () => string;
|
|
56
|
+
now?: () => Date;
|
|
57
|
+
}
|
|
58
|
+
export declare class DevAssistCoordinator {
|
|
59
|
+
private readonly deps;
|
|
60
|
+
private readonly cwd;
|
|
61
|
+
private readonly traceStore;
|
|
62
|
+
private readonly now;
|
|
63
|
+
constructor(deps?: DevAssistCoordinatorDeps);
|
|
64
|
+
cycle(input?: DevAssistCycleInput): Promise<DevAssistCycleResult>;
|
|
65
|
+
private start;
|
|
66
|
+
private resume;
|
|
67
|
+
private generateAndRun;
|
|
68
|
+
private newTrace;
|
|
69
|
+
private runCandidate;
|
|
70
|
+
private persistNeedsRegeneration;
|
|
71
|
+
private infer;
|
|
72
|
+
private diagnose;
|
|
73
|
+
private captureChangeSet;
|
|
74
|
+
}
|