@fliwright/tdd 0.1.0 → 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/README.md +25 -3
- package/dist/baseline/BaselineManager.d.ts +3 -3
- package/dist/daemon/FlutterDaemonController.d.ts +1 -0
- package/dist/daemon/FlutterDaemonController.js +13 -2
- package/dist/daemon/SubprocessDaemonTransport.d.ts +3 -0
- package/dist/daemon/SubprocessDaemonTransport.js +25 -9
- package/dist/executor/FocusedRerunRecipe.js +9 -2
- package/dist/executor/PersistentTestExecutor.d.ts +1 -4
- package/dist/executor/PersistentTestExecutor.js +31 -38
- package/dist/executor/TestRunResults.d.ts +13 -0
- package/dist/executor/TestRunResults.js +19 -0
- package/dist/index.d.ts +3 -17
- package/dist/index.js +1 -8
- package/dist/runtime/TddRuntime.d.ts +5 -19
- package/dist/runtime/TddRuntime.js +78 -115
- package/dist/types.d.ts +17 -192
- package/package.json +4 -4
- package/dist/devassist/DevAssistCoordinator.d.ts +0 -74
- package/dist/devassist/DevAssistCoordinator.js +0 -388
- package/dist/executor/ResultReporter.d.ts +0 -23
- package/dist/executor/ResultReporter.js +0 -50
- package/dist/generator/RedFirstTestGenerator.d.ts +0 -32
- package/dist/generator/RedFirstTestGenerator.js +0 -189
- package/dist/repair/TddRepairPlanner.d.ts +0 -54
- package/dist/repair/TddRepairPlanner.js +0 -132
- package/dist/selectors/SelectorSynthesizer.d.ts +0 -34
- package/dist/selectors/SelectorSynthesizer.js +0 -174
- package/dist/spec/InteractionSpec.d.ts +0 -94
- package/dist/spec/InteractionSpec.js +0 -236
- package/dist/spec/InteractionSpecCoverage.d.ts +0 -17
- package/dist/spec/InteractionSpecCoverage.js +0 -69
- package/dist/workflow/RedFirstWorkflow.d.ts +0 -28
- package/dist/workflow/RedFirstWorkflow.js +0 -33
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { readFile, mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { join, resolve } from 'node:path';
|
|
4
|
-
import { promisify } from 'node:util';
|
|
5
|
-
import { execFile } from 'node:child_process';
|
|
6
|
-
import { AiRuntime, DevAssistTraceStore, PassiveAgent, TimelineRecorder, buildChangeSetSnapshot, } from '@fliwright/core';
|
|
7
|
-
import { generateRedFirstTest } from '../generator/RedFirstTestGenerator.js';
|
|
8
|
-
import { validateInteractionSpec } from '../spec/InteractionSpec.js';
|
|
9
|
-
const execFileAsync = promisify(execFile);
|
|
10
|
-
export class DevAssistCoordinator {
|
|
11
|
-
deps;
|
|
12
|
-
cwd;
|
|
13
|
-
traceStore;
|
|
14
|
-
now;
|
|
15
|
-
constructor(deps = {}) {
|
|
16
|
-
this.deps = deps;
|
|
17
|
-
this.cwd = resolve(deps.cwd ?? process.cwd());
|
|
18
|
-
this.traceStore = deps.traceStore ?? new DevAssistTraceStore({ root: join(this.cwd, '.fliwright', 'devassist') });
|
|
19
|
-
this.now = deps.now ?? (() => new Date());
|
|
20
|
-
}
|
|
21
|
-
async cycle(input = {}) {
|
|
22
|
-
const action = input.action ?? (input.devAssistSessionId ? 'continue' : 'start');
|
|
23
|
-
if (action === 'start')
|
|
24
|
-
return await this.start(input);
|
|
25
|
-
if (!input.devAssistSessionId) {
|
|
26
|
-
return { status: 'blocked', reason: `DevAssist action '${action}' requires devAssistSessionId.` };
|
|
27
|
-
}
|
|
28
|
-
return await this.resume(input, action);
|
|
29
|
-
}
|
|
30
|
-
async start(input) {
|
|
31
|
-
if (!this.deps.runtime) {
|
|
32
|
-
return { status: 'blocked', reason: 'Start the persistent TDD runtime before running a DevAssist cycle.' };
|
|
33
|
-
}
|
|
34
|
-
const changeSet = await this.captureChangeSet(input);
|
|
35
|
-
const sessionId = this.deps.createSessionId?.() ?? randomUUID();
|
|
36
|
-
return await this.generateAndRun({ input, changeSet, sessionId });
|
|
37
|
-
}
|
|
38
|
-
async resume(input, action) {
|
|
39
|
-
if (!this.deps.runtime) {
|
|
40
|
-
return { status: 'blocked', reason: 'Start the persistent TDD runtime before running a DevAssist cycle.' };
|
|
41
|
-
}
|
|
42
|
-
let trace;
|
|
43
|
-
try {
|
|
44
|
-
trace = await this.traceStore.read(input.devAssistSessionId);
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return { status: 'blocked', reason: `DevAssist session '${input.devAssistSessionId}' was not found.` };
|
|
48
|
-
}
|
|
49
|
-
const changeSet = await this.captureChangeSet(input);
|
|
50
|
-
if (action === 'regenerate') {
|
|
51
|
-
if (trace.cycles.at(-1)?.status !== 'needs_regeneration') {
|
|
52
|
-
return {
|
|
53
|
-
status: 'needs_review',
|
|
54
|
-
devAssistSessionId: trace.devAssistSessionId,
|
|
55
|
-
candidateTestPath: trace.candidate.path,
|
|
56
|
-
changeSet,
|
|
57
|
-
reason: 'Regeneration is available only after the candidate becomes invalid.',
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
return await this.generateAndRun({
|
|
61
|
-
input: { ...input, request: trace.request },
|
|
62
|
-
changeSet,
|
|
63
|
-
sessionId: trace.devAssistSessionId,
|
|
64
|
-
previousTrace: trace,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
const candidatePath = trace.candidate.path;
|
|
68
|
-
const candidateSource = await readFile(candidatePath, 'utf8').catch(() => undefined);
|
|
69
|
-
if (!candidateSource || hash(candidateSource) !== trace.candidate.hash) {
|
|
70
|
-
return await this.persistNeedsRegeneration(trace, changeSet, 'The generated candidate changed or is missing. Regenerate explicitly to replace its test intent.');
|
|
71
|
-
}
|
|
72
|
-
return await this.runCandidate(trace, changeSet);
|
|
73
|
-
}
|
|
74
|
-
async generateAndRun(options) {
|
|
75
|
-
const inference = await this.infer({ request: options.input.request, changeSet: options.changeSet });
|
|
76
|
-
const validation = validateInteractionSpec(inference.spec);
|
|
77
|
-
const candidatePath = join(this.cwd, '.fliwright', 'generated', `${options.sessionId}.test.ts`);
|
|
78
|
-
const now = this.now().toISOString();
|
|
79
|
-
if (!validation.ok) {
|
|
80
|
-
const trace = this.newTrace(options, inference, {
|
|
81
|
-
path: candidatePath,
|
|
82
|
-
hash: '',
|
|
83
|
-
testName: inference.testName,
|
|
84
|
-
validation: { eligible: false, reason: validation.issues.map((issue) => `${issue.path} ${issue.message}`).join('; ') },
|
|
85
|
-
}, now);
|
|
86
|
-
const devAssistTracePath = await this.traceStore.write(trace);
|
|
87
|
-
return {
|
|
88
|
-
status: 'needs_review',
|
|
89
|
-
devAssistSessionId: options.sessionId,
|
|
90
|
-
devAssistTracePath,
|
|
91
|
-
candidateTestPath: candidatePath,
|
|
92
|
-
changeSet: options.changeSet,
|
|
93
|
-
reason: trace.candidate.validation.reason,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
if (!hasSupportedAssertion(validation.spec)) {
|
|
97
|
-
const trace = this.newTrace(options, inference, {
|
|
98
|
-
path: candidatePath,
|
|
99
|
-
hash: '',
|
|
100
|
-
testName: inference.testName,
|
|
101
|
-
validation: { eligible: false, reason: 'The inferred candidate has no supported assertion.' },
|
|
102
|
-
}, now);
|
|
103
|
-
const devAssistTracePath = await this.traceStore.write(trace);
|
|
104
|
-
return {
|
|
105
|
-
status: 'needs_review',
|
|
106
|
-
devAssistSessionId: options.sessionId,
|
|
107
|
-
devAssistTracePath,
|
|
108
|
-
candidateTestPath: candidatePath,
|
|
109
|
-
changeSet: options.changeSet,
|
|
110
|
-
reason: trace.candidate.validation.reason,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
const rendered = generateRedFirstTest(validation.spec, { testName: inference.testName });
|
|
114
|
-
if (rendered.warnings.length > 0) {
|
|
115
|
-
const trace = this.newTrace(options, inference, {
|
|
116
|
-
path: candidatePath,
|
|
117
|
-
hash: '',
|
|
118
|
-
testName: inference.testName,
|
|
119
|
-
validation: { eligible: false, reason: rendered.warnings.join(' ') },
|
|
120
|
-
}, now);
|
|
121
|
-
const devAssistTracePath = await this.traceStore.write(trace);
|
|
122
|
-
return {
|
|
123
|
-
status: 'needs_review',
|
|
124
|
-
devAssistSessionId: options.sessionId,
|
|
125
|
-
devAssistTracePath,
|
|
126
|
-
candidateTestPath: candidatePath,
|
|
127
|
-
changeSet: options.changeSet,
|
|
128
|
-
reason: trace.candidate.validation.reason,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
await mkdir(join(candidatePath, '..'), { recursive: true });
|
|
132
|
-
await writeFile(candidatePath, rendered.testCode, 'utf8');
|
|
133
|
-
const trace = this.newTrace(options, inference, {
|
|
134
|
-
path: candidatePath,
|
|
135
|
-
hash: hash(rendered.testCode),
|
|
136
|
-
testName: rendered.testName,
|
|
137
|
-
validation: { eligible: true },
|
|
138
|
-
}, now);
|
|
139
|
-
return await this.runCandidate(trace, options.changeSet);
|
|
140
|
-
}
|
|
141
|
-
newTrace(options, inference, candidate, now) {
|
|
142
|
-
return {
|
|
143
|
-
version: 1,
|
|
144
|
-
devAssistSessionId: options.sessionId,
|
|
145
|
-
...(options.input.request ? { request: options.input.request } : options.previousTrace?.request ? { request: options.previousTrace.request } : {}),
|
|
146
|
-
changeSets: [...(options.previousTrace?.changeSets ?? []), options.changeSet],
|
|
147
|
-
inference: {
|
|
148
|
-
promptTemplateVersion: 'devassist-v1',
|
|
149
|
-
provider: inference.provider ?? 'configured-ai',
|
|
150
|
-
...(inference.model ? { model: inference.model } : {}),
|
|
151
|
-
evidence: {
|
|
152
|
-
changeFiles: options.changeSet.files.map((file) => file.path),
|
|
153
|
-
validation: candidate.validation,
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
candidate,
|
|
157
|
-
cycles: [...(options.previousTrace?.cycles ?? [])],
|
|
158
|
-
createdAt: options.previousTrace?.createdAt ?? now,
|
|
159
|
-
updatedAt: now,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
async runCandidate(trace, changeSet) {
|
|
163
|
-
const runtime = this.deps.runtime;
|
|
164
|
-
await runtime.focus(trace.candidate.path, trace.candidate.testName);
|
|
165
|
-
const cycle = await runtime.cycle(trace.candidate.testName, {
|
|
166
|
-
sync: 'auto',
|
|
167
|
-
changes: changeSet.files.map((file) => file.path),
|
|
168
|
-
autoEscalate: true,
|
|
169
|
-
});
|
|
170
|
-
const diagnosis = cycle.status === 'red' ? await this.diagnose(cycle) : undefined;
|
|
171
|
-
const timelinePath = cycle.timelinePath ?? cycle.failureContext?.artifacts?.timelinePath;
|
|
172
|
-
const timelineNodeId = cycle.timelineNodeId ?? cycle.failureContext?.artifacts?.timelineNodeId;
|
|
173
|
-
const candidateInvalid = cycle.failureContext?.kind === 'test-error';
|
|
174
|
-
const status = candidateInvalid ? 'needs_regeneration' : cycle.status;
|
|
175
|
-
const artifacts = artifactReferences(cycle);
|
|
176
|
-
const nextTrace = {
|
|
177
|
-
...trace,
|
|
178
|
-
changeSets: trace.changeSets.at(-1)?.hash === changeSet.hash ? trace.changeSets : [...trace.changeSets, changeSet],
|
|
179
|
-
cycles: [...trace.cycles, {
|
|
180
|
-
changeSet,
|
|
181
|
-
status,
|
|
182
|
-
sync: { decision: cycle.lastSync, ...(cycle.syncEscalated ? { escalation: true } : {}) },
|
|
183
|
-
...(timelinePath ? { timelinePath } : {}),
|
|
184
|
-
...(timelineNodeId ? { timelineNodeId } : {}),
|
|
185
|
-
...(artifacts.length > 0 ? { artifacts } : {}),
|
|
186
|
-
...(diagnosis ? { diagnosis: diagnosisReference(diagnosis) } : {}),
|
|
187
|
-
...(cycle.failure?.message ? { reason: cycle.failure.message } : {}),
|
|
188
|
-
completedAt: this.now().toISOString(),
|
|
189
|
-
}],
|
|
190
|
-
updatedAt: this.now().toISOString(),
|
|
191
|
-
};
|
|
192
|
-
const devAssistTracePath = await this.traceStore.write(nextTrace);
|
|
193
|
-
return {
|
|
194
|
-
status,
|
|
195
|
-
devAssistSessionId: trace.devAssistSessionId,
|
|
196
|
-
devAssistTracePath,
|
|
197
|
-
candidateTestPath: trace.candidate.path,
|
|
198
|
-
changeSet,
|
|
199
|
-
sync: { decision: cycle.lastSync, ...(cycle.syncEscalated ? { escalation: true } : {}) },
|
|
200
|
-
...(timelinePath ? { timelinePath } : {}),
|
|
201
|
-
...(timelineNodeId ? { timelineNodeId } : {}),
|
|
202
|
-
...(artifacts.length > 0 ? { artifacts } : {}),
|
|
203
|
-
...(diagnosis ? { diagnosis } : {}),
|
|
204
|
-
nextCall: candidateInvalid
|
|
205
|
-
? { action: 'regenerate', devAssistSessionId: trace.devAssistSessionId }
|
|
206
|
-
: { action: 'continue', devAssistSessionId: trace.devAssistSessionId },
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
async persistNeedsRegeneration(trace, changeSet, reason) {
|
|
210
|
-
const updated = {
|
|
211
|
-
...trace,
|
|
212
|
-
changeSets: [...trace.changeSets, changeSet],
|
|
213
|
-
cycles: [...trace.cycles, {
|
|
214
|
-
changeSet,
|
|
215
|
-
status: 'needs_regeneration',
|
|
216
|
-
sync: { decision: 'none' },
|
|
217
|
-
reason,
|
|
218
|
-
completedAt: this.now().toISOString(),
|
|
219
|
-
}],
|
|
220
|
-
updatedAt: this.now().toISOString(),
|
|
221
|
-
};
|
|
222
|
-
const devAssistTracePath = await this.traceStore.write(updated);
|
|
223
|
-
return {
|
|
224
|
-
status: 'needs_regeneration',
|
|
225
|
-
devAssistSessionId: trace.devAssistSessionId,
|
|
226
|
-
devAssistTracePath,
|
|
227
|
-
candidateTestPath: trace.candidate.path,
|
|
228
|
-
changeSet,
|
|
229
|
-
sync: { decision: 'none' },
|
|
230
|
-
reason,
|
|
231
|
-
nextCall: { action: 'regenerate', devAssistSessionId: trace.devAssistSessionId },
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
async infer(input) {
|
|
235
|
-
if (this.deps.infer)
|
|
236
|
-
return await this.deps.infer(input);
|
|
237
|
-
const aiRuntime = this.deps.aiRuntime ?? new AiRuntime();
|
|
238
|
-
const result = await aiRuntime.generate({
|
|
239
|
-
prompt: [
|
|
240
|
-
'Produce one Fliwright DevAssist candidate as JSON.',
|
|
241
|
-
'Use only supported InteractionSpec actions and assertions. The candidate must contain an observable assertion and must not authorize side effects.',
|
|
242
|
-
`Developer request: ${input.request ?? 'Infer one focused behavior from the changed files.'}`,
|
|
243
|
-
`Change set: ${JSON.stringify({ baseRevision: input.changeSet.baseRevision, files: input.changeSet.files.map((file) => file.path) })}`,
|
|
244
|
-
].join('\n'),
|
|
245
|
-
schema: inferenceSchema,
|
|
246
|
-
});
|
|
247
|
-
return result;
|
|
248
|
-
}
|
|
249
|
-
async diagnose(cycle) {
|
|
250
|
-
if (this.deps.diagnose)
|
|
251
|
-
return await this.deps.diagnose(cycle);
|
|
252
|
-
const failure = toAgentVisibleFailure(cycle);
|
|
253
|
-
if (!failure)
|
|
254
|
-
return undefined;
|
|
255
|
-
try {
|
|
256
|
-
const passiveAgent = new PassiveAgent({
|
|
257
|
-
aiRuntime: this.deps.aiRuntime ?? new AiRuntime(),
|
|
258
|
-
recorder: new TimelineRecorder({ runId: `devassist-${Date.now()}`, testName: cycle.testName ?? 'DevAssist candidate' }),
|
|
259
|
-
passive: true,
|
|
260
|
-
});
|
|
261
|
-
return (await passiveAgent.diagnose(failure, {
|
|
262
|
-
allowedTools: ['fliwright artifacts timeline', 'fliwright app snapshot', 'fliwright app observe'],
|
|
263
|
-
screenshotPath: cycle.failureContext?.artifacts?.screenshotPath,
|
|
264
|
-
snapshotPath: cycle.failureContext?.artifacts?.timelinePath,
|
|
265
|
-
})) ?? undefined;
|
|
266
|
-
}
|
|
267
|
-
catch {
|
|
268
|
-
return undefined;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
async captureChangeSet(input) {
|
|
272
|
-
if (this.deps.changeSetProvider)
|
|
273
|
-
return await this.deps.changeSetProvider(input);
|
|
274
|
-
const files = input.files
|
|
275
|
-
? input.files.map((path) => ({ path, status: 'modified' }))
|
|
276
|
-
: await changedFiles(this.cwd);
|
|
277
|
-
const snapshots = await Promise.all(files.map(async (file) => {
|
|
278
|
-
const content = await readFile(resolve(this.cwd, file.path), 'utf8').catch(() => undefined);
|
|
279
|
-
return {
|
|
280
|
-
path: file.path,
|
|
281
|
-
status: content === undefined ? 'deleted' : file.status,
|
|
282
|
-
content,
|
|
283
|
-
};
|
|
284
|
-
}));
|
|
285
|
-
return buildChangeSetSnapshot({
|
|
286
|
-
baseRevision: input.baseRevision ?? await currentRevision(this.cwd),
|
|
287
|
-
files: snapshots,
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
const inferenceSchema = {
|
|
292
|
-
type: 'object',
|
|
293
|
-
properties: {
|
|
294
|
-
testName: { type: 'string' },
|
|
295
|
-
provider: { type: 'string' },
|
|
296
|
-
model: { type: 'string' },
|
|
297
|
-
spec: { type: 'object' },
|
|
298
|
-
},
|
|
299
|
-
required: ['testName', 'spec'],
|
|
300
|
-
};
|
|
301
|
-
async function changedFiles(cwd) {
|
|
302
|
-
try {
|
|
303
|
-
const { stdout } = await execFileAsync('git', ['status', '--porcelain=v1', '-z'], { cwd });
|
|
304
|
-
const records = stdout.split('\0').filter(Boolean);
|
|
305
|
-
const files = [];
|
|
306
|
-
for (let index = 0; index < records.length; index += 1) {
|
|
307
|
-
const record = records[index];
|
|
308
|
-
if (record.length <= 3)
|
|
309
|
-
continue;
|
|
310
|
-
const marker = record.slice(0, 2);
|
|
311
|
-
files.push({ path: record.slice(3), status: statusFromPorcelain(marker) });
|
|
312
|
-
if (marker.includes('R') || marker.includes('C'))
|
|
313
|
-
index += 1;
|
|
314
|
-
}
|
|
315
|
-
return files
|
|
316
|
-
.filter((file, index, candidates) => candidates.findIndex((candidate) => candidate.path === file.path) === index)
|
|
317
|
-
.sort((left, right) => left.path.localeCompare(right.path));
|
|
318
|
-
}
|
|
319
|
-
catch {
|
|
320
|
-
return [];
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
async function currentRevision(cwd) {
|
|
324
|
-
try {
|
|
325
|
-
const { stdout } = await execFileAsync('git', ['rev-parse', 'HEAD'], { cwd });
|
|
326
|
-
return stdout.trim() || undefined;
|
|
327
|
-
}
|
|
328
|
-
catch {
|
|
329
|
-
return undefined;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
function hash(value) {
|
|
333
|
-
return createHash('sha256').update(value).digest('hex');
|
|
334
|
-
}
|
|
335
|
-
function statusFromPorcelain(marker) {
|
|
336
|
-
if (marker === '??')
|
|
337
|
-
return 'untracked';
|
|
338
|
-
if (marker.includes('D'))
|
|
339
|
-
return 'deleted';
|
|
340
|
-
if (marker.includes('A') || marker.includes('C'))
|
|
341
|
-
return 'added';
|
|
342
|
-
return 'modified';
|
|
343
|
-
}
|
|
344
|
-
function hasSupportedAssertion(spec) {
|
|
345
|
-
return Boolean(spec.assertions?.length) || spec.flows.some((flow) => Boolean(flow.expectedOutcome?.length));
|
|
346
|
-
}
|
|
347
|
-
function diagnosisReference(diagnosis) {
|
|
348
|
-
return {
|
|
349
|
-
summary: diagnosis.summary,
|
|
350
|
-
rootCause: diagnosis.rootCause,
|
|
351
|
-
suggestedActions: [...diagnosis.suggestedActions],
|
|
352
|
-
confidence: diagnosis.confidence,
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
function artifactReferences(cycle) {
|
|
356
|
-
const artifacts = cycle.failureContext?.artifacts;
|
|
357
|
-
return [
|
|
358
|
-
cycle.timelinePath ?? artifacts?.timelinePath ? { kind: 'trace', path: cycle.timelinePath ?? artifacts.timelinePath } : undefined,
|
|
359
|
-
artifacts?.failureContextPath ? { kind: 'diagnostics', path: artifacts.failureContextPath } : undefined,
|
|
360
|
-
artifacts?.screenshotPath ? { kind: 'screenshot', path: artifacts.screenshotPath } : undefined,
|
|
361
|
-
].filter((artifact) => Boolean(artifact));
|
|
362
|
-
}
|
|
363
|
-
function toAgentVisibleFailure(cycle) {
|
|
364
|
-
const context = cycle.failureContext;
|
|
365
|
-
if (!context)
|
|
366
|
-
return undefined;
|
|
367
|
-
const codeByKind = {
|
|
368
|
-
'missing-element': 'selector_not_found',
|
|
369
|
-
'ambiguous-element': 'actionability_failed',
|
|
370
|
-
'wrong-text': 'assertion_failed',
|
|
371
|
-
'navigation-failed': 'navigation_failed',
|
|
372
|
-
'mock-not-called': 'assertion_failed',
|
|
373
|
-
'state-mismatch': 'assertion_failed',
|
|
374
|
-
timeout: 'step_failed',
|
|
375
|
-
disconnected: 'step_failed',
|
|
376
|
-
'test-error': 'step_failed',
|
|
377
|
-
};
|
|
378
|
-
return {
|
|
379
|
-
code: codeByKind[context.kind],
|
|
380
|
-
title: context.testName ?? cycle.testName ?? 'DevAssist candidate failed',
|
|
381
|
-
message: context.message,
|
|
382
|
-
timelineNodeId: context.artifacts?.timelineNodeId,
|
|
383
|
-
recoveryHints: (context.recoveryHints ?? []).map((hint) => ({
|
|
384
|
-
kind: 'manual',
|
|
385
|
-
description: hint.message,
|
|
386
|
-
})),
|
|
387
|
-
};
|
|
388
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Reporter, TestModule } from 'vitest/node';
|
|
2
|
-
export interface CollectedResult {
|
|
3
|
-
testName: string;
|
|
4
|
-
status: 'red' | 'green';
|
|
5
|
-
message?: string;
|
|
6
|
-
runIdentity?: {
|
|
7
|
-
runId: string;
|
|
8
|
-
testId: string;
|
|
9
|
-
attemptId: string;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export declare class ResultReporter implements Reporter {
|
|
13
|
-
private readonly finishedRuns;
|
|
14
|
-
private waiters;
|
|
15
|
-
/** Vitest 5 reports finished runs via onTestRunEnd instead of onFinished. */
|
|
16
|
-
onTestRunEnd(testModules: ReadonlyArray<TestModule>): void;
|
|
17
|
-
waitForNextRun(): Promise<TestModule[]>;
|
|
18
|
-
collectLatest(): CollectedResult[];
|
|
19
|
-
drain(): void;
|
|
20
|
-
}
|
|
21
|
-
export declare function collectResultsFromModules(modules: TestModule[]): CollectedResult[];
|
|
22
|
-
/** @deprecated Use {@link collectResultsFromModules}; kept for existing imports. */
|
|
23
|
-
export declare const collectResultsFromFiles: typeof collectResultsFromModules;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export class ResultReporter {
|
|
2
|
-
finishedRuns = [];
|
|
3
|
-
waiters = [];
|
|
4
|
-
/** Vitest 5 reports finished runs via onTestRunEnd instead of onFinished. */
|
|
5
|
-
onTestRunEnd(testModules) {
|
|
6
|
-
const modules = [...testModules];
|
|
7
|
-
// Vitest can emit an intermediate empty run while a persistent watcher
|
|
8
|
-
// refreshes its module specifications. It is not a completed focused run
|
|
9
|
-
// and must not resolve a rerun waiter with stale results.
|
|
10
|
-
if (modules.length === 0)
|
|
11
|
-
return;
|
|
12
|
-
this.finishedRuns.push(modules);
|
|
13
|
-
const waiters = this.waiters;
|
|
14
|
-
this.waiters = [];
|
|
15
|
-
for (const waiter of waiters)
|
|
16
|
-
waiter(modules);
|
|
17
|
-
}
|
|
18
|
-
waitForNextRun() {
|
|
19
|
-
return new Promise((resolve) => {
|
|
20
|
-
this.waiters.push(resolve);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
collectLatest() {
|
|
24
|
-
const modules = this.finishedRuns.at(-1) ?? [];
|
|
25
|
-
return collectResultsFromModules(modules);
|
|
26
|
-
}
|
|
27
|
-
drain() {
|
|
28
|
-
this.finishedRuns.length = 0;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export function collectResultsFromModules(modules) {
|
|
32
|
-
const results = [];
|
|
33
|
-
for (const module of modules) {
|
|
34
|
-
for (const testCase of module.children.allTests()) {
|
|
35
|
-
const result = testCase.result();
|
|
36
|
-
if (result.state !== 'passed' && result.state !== 'failed')
|
|
37
|
-
continue;
|
|
38
|
-
const identity = testCase.meta().fliwrightRun;
|
|
39
|
-
results.push({
|
|
40
|
-
...(identity ? { runIdentity: identity } : {}),
|
|
41
|
-
testName: testCase.name,
|
|
42
|
-
status: result.state === 'passed' ? 'green' : 'red',
|
|
43
|
-
message: result.errors?.map((error) => error.message).join('\n'),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return results;
|
|
48
|
-
}
|
|
49
|
-
/** @deprecated Use {@link collectResultsFromModules}; kept for existing imports. */
|
|
50
|
-
export const collectResultsFromFiles = collectResultsFromModules;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { InteractionSpec } from '../spec/InteractionSpec.js';
|
|
2
|
-
import type { SelectorSynthesisResult, WidgetCandidate } from '../selectors/SelectorSynthesizer.js';
|
|
3
|
-
export interface RedFirstTestGeneratorOptions {
|
|
4
|
-
flowId?: string;
|
|
5
|
-
testName?: string;
|
|
6
|
-
homeRoute?: string;
|
|
7
|
-
resetToHomeBeforeEach?: boolean;
|
|
8
|
-
widgets?: WidgetCandidate[];
|
|
9
|
-
}
|
|
10
|
-
export interface RedFirstTestSuiteGeneratorOptions extends Omit<RedFirstTestGeneratorOptions, 'flowId' | 'testName'> {
|
|
11
|
-
flowIds?: string[];
|
|
12
|
-
testNamePrefix?: string;
|
|
13
|
-
}
|
|
14
|
-
export interface GenerateRedFirstTestResult {
|
|
15
|
-
testCode: string;
|
|
16
|
-
testName: string;
|
|
17
|
-
flowId?: string;
|
|
18
|
-
warnings: string[];
|
|
19
|
-
selectorDiagnostics: SelectorSynthesisResult[];
|
|
20
|
-
}
|
|
21
|
-
export interface GenerateRedFirstTestSuiteResult {
|
|
22
|
-
testCode: string;
|
|
23
|
-
tests: Array<{
|
|
24
|
-
testName: string;
|
|
25
|
-
flowId?: string;
|
|
26
|
-
warnings: string[];
|
|
27
|
-
}>;
|
|
28
|
-
warnings: string[];
|
|
29
|
-
selectorDiagnostics: SelectorSynthesisResult[];
|
|
30
|
-
}
|
|
31
|
-
export declare function generateRedFirstTest(spec: InteractionSpec, options?: RedFirstTestGeneratorOptions): GenerateRedFirstTestResult;
|
|
32
|
-
export declare function generateRedFirstTestSuite(spec: InteractionSpec, options?: RedFirstTestSuiteGeneratorOptions): GenerateRedFirstTestSuiteResult;
|