@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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -2
  3. package/dist/baseline/AppCapabilityResetAdapter.d.ts +6 -0
  4. package/dist/baseline/AppCapabilityResetAdapter.js +41 -0
  5. package/dist/baseline/BaselineManager.d.ts +67 -0
  6. package/dist/baseline/BaselineManager.js +145 -0
  7. package/dist/baseline/StorageResetAdapter.d.ts +19 -0
  8. package/dist/baseline/StorageResetAdapter.js +43 -0
  9. package/dist/daemon/DaemonTransport.d.ts +37 -0
  10. package/dist/daemon/DaemonTransport.js +1 -0
  11. package/dist/daemon/FlutterDaemonController.d.ts +19 -0
  12. package/dist/daemon/FlutterDaemonController.js +109 -0
  13. package/dist/daemon/FlutterDaemonEndpointSource.d.ts +23 -0
  14. package/dist/daemon/FlutterDaemonEndpointSource.js +37 -0
  15. package/dist/daemon/ReloadStrategy.d.ts +28 -0
  16. package/dist/daemon/ReloadStrategy.js +72 -0
  17. package/dist/daemon/SubprocessDaemonTransport.d.ts +29 -0
  18. package/dist/daemon/SubprocessDaemonTransport.js +155 -0
  19. package/dist/devassist/DevAssistCoordinator.d.ts +74 -0
  20. package/dist/devassist/DevAssistCoordinator.js +388 -0
  21. package/dist/diagnostics/TddFailureContext.d.ts +56 -0
  22. package/dist/diagnostics/TddFailureContext.js +220 -0
  23. package/dist/executor/FocusedRerunRecipe.d.ts +7 -0
  24. package/dist/executor/FocusedRerunRecipe.js +57 -0
  25. package/dist/executor/PersistentTestExecutor.d.ts +59 -0
  26. package/dist/executor/PersistentTestExecutor.js +242 -0
  27. package/dist/executor/ResultReporter.d.ts +23 -0
  28. package/dist/executor/ResultReporter.js +50 -0
  29. package/dist/generator/RedFirstTestGenerator.d.ts +32 -0
  30. package/dist/generator/RedFirstTestGenerator.js +189 -0
  31. package/dist/index.d.ts +36 -0
  32. package/dist/index.js +20 -0
  33. package/dist/repair/TddRepairPlanner.d.ts +54 -0
  34. package/dist/repair/TddRepairPlanner.js +132 -0
  35. package/dist/runtime/TddRuntime.d.ts +87 -0
  36. package/dist/runtime/TddRuntime.js +589 -0
  37. package/dist/selectors/SelectorSynthesizer.d.ts +34 -0
  38. package/dist/selectors/SelectorSynthesizer.js +174 -0
  39. package/dist/spec/InteractionSpec.d.ts +94 -0
  40. package/dist/spec/InteractionSpec.js +236 -0
  41. package/dist/spec/InteractionSpecCoverage.d.ts +17 -0
  42. package/dist/spec/InteractionSpecCoverage.js +69 -0
  43. package/dist/types.d.ts +314 -0
  44. package/dist/types.js +2 -0
  45. package/dist/workflow/RedFirstWorkflow.d.ts +28 -0
  46. package/dist/workflow/RedFirstWorkflow.js +33 -0
  47. package/package.json +42 -3
@@ -0,0 +1,314 @@
1
+ import type { RepairProposal, RepairResult } from '@fliwright/core';
2
+ import type { AppHandle, AppStartParams } from './daemon/DaemonTransport.js';
3
+ import type { TddFailureContext } from './diagnostics/TddFailureContext.js';
4
+ export type ResetCategory = 'navigation' | 'riverpod' | 'mock' | 'storage' | 'secureStorage' | 'authTokens' | 'webview' | 'localDb' | 'timers' | 'isolates' | 'permissions';
5
+ export interface Scenario {
6
+ homeRoute: string;
7
+ resetCategories: ResetCategory[];
8
+ riverpodOverrides?: unknown[];
9
+ mockProfile?: string;
10
+ mockDir?: string;
11
+ storageSeed?: Record<string, unknown>;
12
+ }
13
+ export interface ResetAdapterResult {
14
+ category: ResetCategory;
15
+ status: 'ok' | 'skipped' | 'unsupported';
16
+ message?: string;
17
+ }
18
+ export interface ResetReport {
19
+ version: number;
20
+ full: boolean;
21
+ results: ResetAdapterResult[];
22
+ unsupported: ResetCategory[];
23
+ }
24
+ export interface RuntimeSnapshot {
25
+ connected: boolean;
26
+ daemonStatus: 'running' | 'stopped' | 'unknown';
27
+ appId?: string;
28
+ supportsRestart: boolean;
29
+ launchMode: 'start' | 'attach';
30
+ restartCapable: boolean;
31
+ driverConnections: number;
32
+ fixtureDriverSharing: 'in-process-provider' | 'vm-service-url';
33
+ notes?: string[];
34
+ focusedTest?: {
35
+ file: string;
36
+ testName?: string;
37
+ };
38
+ lastResult?: TddCycleResult;
39
+ baselineVersion: number;
40
+ unsupportedState?: ResetCategory[];
41
+ updatedAtMs?: number;
42
+ }
43
+ export interface StartOpts {
44
+ sharedConfig?: Partial<import('@fliwright/core').FliwrightProjectConfig>;
45
+ app?: AppStartParams;
46
+ vmServiceUrl?: string;
47
+ configRoot: string;
48
+ launchMode?: 'start' | 'attach';
49
+ scenario?: Scenario;
50
+ defaultScenario?: string;
51
+ /**
52
+ * Optional path the runtime writes its {@link RuntimeSnapshot} to after each state change
53
+ * (start/focus/cycle/reconnect/stop), as a best-effort, non-blocking JSON dump. Lets read-only
54
+ * monitors (e.g. the VS Code TDD Loop panel) observe the loop without a second driver connection.
55
+ * Defaults to `<projectRoot>/.fliwright/tdd-status.json` when set by the CLI layer.
56
+ */
57
+ statusFilePath?: string;
58
+ }
59
+ export interface CycleOpts {
60
+ /** How to sync the app before this cycle. `'auto'` decides from {@link changes} (design §6.4). */
61
+ sync?: 'none' | 'reload' | 'restart' | 'auto';
62
+ fullReset?: boolean;
63
+ /**
64
+ * File paths changed since the last sync. Used only when {@link sync} is `'auto'` to choose
65
+ * reload vs restart via `decideSync`. Ignored for explicit sync levels.
66
+ */
67
+ changes?: string[];
68
+ /**
69
+ * When true (default), a `reload` cycle that fails with a structural-looking error is retried
70
+ * once with a hot restart + full reset, if the runtime can restart. Set false to keep the raw
71
+ * reload result. Design §6.4 fallback-escalation rule.
72
+ */
73
+ autoEscalate?: boolean;
74
+ /**
75
+ * Per-cycle wall-clock budget (ms) covering sync + reset + rerun. On expiry the caller receives a
76
+ * red `timeout` result immediately, but the in-flight body is allowed to finish so the next cycle
77
+ * never overlaps the single-threaded executor. Design §8 Timeout. Default {@link DEFAULT_CYCLE_TIMEOUT_MS}.
78
+ */
79
+ timeoutMs?: number;
80
+ /**
81
+ * Run an inline AI repair closed loop (design §7 P3 / §10 P3). When set, a red initial cycle is
82
+ * followed by repair → cycle again, up to {@link TddRepairOpts.iterations} (default 3).
83
+ * - `'suggest'`: stop after emitting the repair diff/plan (no apply, no loop).
84
+ * - `'safe-apply'`: apply only guarded safe repairs and loop until green or the cap.
85
+ * Additive: omitted → identical to today's behavior. Requires a repair planner wired into
86
+ * {@link TddRuntimeDeps.repair}.
87
+ */
88
+ repair?: TddRepairOpts;
89
+ }
90
+ /**
91
+ * Options for the AI repair closed loop (design §7 P3).
92
+ *
93
+ * - `'suggest'` emits a repair plan (diff + proposed safe actions) for agent approval and applies
94
+ * nothing; the loop does not iterate.
95
+ * - `'safe-apply'` applies only guarded safe repairs (those that pass the AgentRepair guardrail)
96
+ * and loops `cycle(red) → repair → cycle` until green or the iteration cap.
97
+ */
98
+ export interface TddRepairOpts {
99
+ mode: 'suggest' | 'safe-apply';
100
+ /**
101
+ * Maximum number of repair→cycle iterations in safe-apply mode. Default 3. Ignored for 'suggest'
102
+ * (which never loops). The cap prevents unbounded AI edits; reaching it still red is a terminal
103
+ * state surfaced to the agent.
104
+ */
105
+ iterations?: number;
106
+ }
107
+ /**
108
+ * One proposed repair action with its guardrail verdict. `safe` is true only when the AgentRepair
109
+ * `validate()` guard accepts it (i.e. it is a bounded runtime action, never a `codePatch`).
110
+ */
111
+ export interface TddRepairProposalEntry {
112
+ proposal: RepairProposal;
113
+ /** True when the guardrail accepts this proposal; false when rejected as unsafe/unsupported. */
114
+ safe: boolean;
115
+ /** Rejection reason from the guardrail, when `safe` is false. */
116
+ reason?: string;
117
+ }
118
+ /**
119
+ * A repair plan: the proposed patch text (for agent approval / `suggest` mode) plus the individual
120
+ * repair actions and their guardrail verdicts. In `suggest` mode this is returned without applying;
121
+ * in `safe-apply` mode only the `safe` entries are executed.
122
+ */
123
+ export interface TddRepairPlan {
124
+ mode: 'suggest' | 'safe-apply';
125
+ /** Human/agent-readable patch/diff describing the proposed minimal fix. */
126
+ diff: string;
127
+ /** Individual proposed repair actions with their guardrail verdicts. */
128
+ proposals: TddRepairProposalEntry[];
129
+ }
130
+ /**
131
+ * The outcome of one repair step inside the closed loop: the plan proposed, and (in safe-apply mode)
132
+ * the AgentRepair execute results for the actions actually attempted.
133
+ */
134
+ export interface TddRepairStep {
135
+ /** 1-based index of this repair iteration within the loop. */
136
+ iteration: number;
137
+ plan: TddRepairPlan;
138
+ /** Only populated in safe-apply mode: one AgentRepair result per safe proposal that was executed. */
139
+ applied?: RepairResult[];
140
+ }
141
+ /**
142
+ * The full repair trace returned by the closed loop. Empty when no repair was requested, when the
143
+ * initial cycle was already green, or when no repair planner is configured.
144
+ */
145
+ export interface TddRepairTrace {
146
+ mode: 'suggest' | 'safe-apply';
147
+ /** Per-iteration repair steps (one for each cycle(red) → repair pass). */
148
+ steps: TddRepairStep[];
149
+ /** True when the iteration cap was reached while still red. */
150
+ capped: boolean;
151
+ }
152
+ /** Default per-cycle timeout (design §8). Generous: real reruns are sub-second; restarts are seconds. */
153
+ export declare const DEFAULT_CYCLE_TIMEOUT_MS = 60000;
154
+ export interface TddCycleResult {
155
+ status: 'red' | 'green';
156
+ testName?: string;
157
+ file: string;
158
+ durationMs: number;
159
+ lastSync: 'reload' | 'restart' | 'none';
160
+ /** True only when an automatic reload failure retry escalated this cycle to one restart. */
161
+ syncEscalated?: boolean;
162
+ baselineVersion: number;
163
+ failure?: {
164
+ message?: string;
165
+ };
166
+ failureContext?: TddFailureContext;
167
+ /** Existing per-test timeline produced by @fliwright/vitest, available for both red and green runs. */
168
+ timelinePath?: string;
169
+ timelineNodeId?: string;
170
+ unsupportedState?: ResetCategory[];
171
+ }
172
+ export interface TddSyncResult {
173
+ lastSync: TddCycleResult['lastSync'];
174
+ snapshot: RuntimeSnapshot;
175
+ }
176
+ export interface TddRuntimeDeps {
177
+ daemon?: {
178
+ start(): Promise<void>;
179
+ startApp(params: AppStartParams): Promise<AppHandle>;
180
+ reload(appId: string): Promise<void>;
181
+ restart(appId: string): Promise<void>;
182
+ stop(appId: string): Promise<void>;
183
+ dispose(options?: {
184
+ keepAppAlive?: boolean;
185
+ }): Promise<void>;
186
+ };
187
+ executor?: {
188
+ boot(opts: {
189
+ sharedConfig?: StartOpts['sharedConfig'];
190
+ configRoot: string;
191
+ vmServiceUrl?: string;
192
+ driverProvider: () => Promise<unknown>;
193
+ defaultScenario?: string;
194
+ scenarioMode?: 'managed-start' | 'attach';
195
+ }): Promise<void>;
196
+ rerun(file: string, testName?: string): Promise<{
197
+ status: 'red' | 'green';
198
+ testName?: string;
199
+ failure?: {
200
+ message?: string;
201
+ };
202
+ timelinePath?: string;
203
+ timelineNodeId?: string;
204
+ failureDetails?: {
205
+ source?: {
206
+ file: string;
207
+ line: number;
208
+ snippet: string;
209
+ };
210
+ assertion?: {
211
+ matcher: string;
212
+ expected: string;
213
+ actual: string;
214
+ timeout: number;
215
+ };
216
+ artifacts?: {
217
+ failureContextPath?: string;
218
+ screenshotPath?: string;
219
+ screenshotBase64?: string;
220
+ widgetTree?: unknown;
221
+ timelinePath?: string;
222
+ timelineNodeId?: string;
223
+ };
224
+ };
225
+ }>;
226
+ dispose(): Promise<void>;
227
+ };
228
+ driverFactory?: () => {
229
+ connect(vmServiceUrl: string): Promise<void>;
230
+ dispose(options?: {
231
+ signal?: AbortSignal;
232
+ }): Promise<void>;
233
+ page: {
234
+ resetToHome(options?: {
235
+ homeRoute?: string;
236
+ }): Promise<void>;
237
+ };
238
+ mock: {
239
+ clear(): Promise<void>;
240
+ clearCalls(): Promise<void>;
241
+ loadRules?(mockDir?: string): Promise<void>;
242
+ listRules?(): Array<{
243
+ endpoint: string;
244
+ method: string;
245
+ rules: string[];
246
+ activeRule: string;
247
+ }>;
248
+ switchRule?(endpoint: string, ruleName: string, method?: string): Promise<void>;
249
+ };
250
+ state?: {
251
+ override(key: string, value: unknown): Promise<void>;
252
+ };
253
+ storage?: {
254
+ reset(seed?: Record<string, unknown>): Promise<{
255
+ status: 'ok' | 'unsupported';
256
+ clearedKeys?: number;
257
+ seededKeys?: number;
258
+ message?: string;
259
+ }>;
260
+ };
261
+ app?: {
262
+ hasCapability?(name: string): Promise<boolean>;
263
+ listCapabilities?(): Promise<Array<{
264
+ name: string;
265
+ methods: string[];
266
+ }>>;
267
+ invoke(capability: string, method: string, input?: unknown): Promise<unknown>;
268
+ };
269
+ reloadSources?(): Promise<unknown>;
270
+ };
271
+ baseline?: {
272
+ reset(scenario: Scenario, opts: {
273
+ full?: boolean;
274
+ }): Promise<ResetReport>;
275
+ get version(): number;
276
+ };
277
+ /**
278
+ * Optional AI repair planner (design §6.2 `repair?: AgentRepair`, wired in P3). When absent, the
279
+ * cycle behaves identically to today (no repair loop). When present, a cycle requested with
280
+ * {@link CycleOpts.repair} runs the closed loop: cycle(red) → repair → cycle, capped by an
281
+ * iteration limit, applying only guardrail-safe repairs in 'safe-apply' mode.
282
+ *
283
+ * Exposed as a minimal interface so production can pass a `TddRepairPlanner` while tests inject a
284
+ * fake without depending on `@fliwright/core`'s `AgentRepair` directly.
285
+ */
286
+ repair?: TddRepairPlannerLike;
287
+ }
288
+ /**
289
+ * Minimal repair-planner contract injected into {@link TddRuntimeDeps.repair}. Production wires a
290
+ * {@link TddRepairPlanner} backed by `@fliwright/core`'s `AgentRepair`; tests pass a fake that
291
+ * proposes deterministic patches.
292
+ */
293
+ export interface TddRepairPlannerLike {
294
+ /**
295
+ * Propose a minimal repair plan for a red cycle result.
296
+ *
297
+ * - `'suggest'`: returns the plan (diff + proposed actions with guardrail verdicts) and applies
298
+ * nothing. The loop does not iterate.
299
+ * - `'safe-apply'`: applies only the guardrail-safe proposals via the underlying `AgentRepair`
300
+ * and returns the plan plus the execute results for the attempted actions.
301
+ */
302
+ propose(result: TddCycleResult, mode: 'suggest' | 'safe-apply'): Promise<TddRepairPlan & {
303
+ applied?: RepairResult[];
304
+ }>;
305
+ }
306
+ /**
307
+ * Result of a cycle that ran the optional repair closed loop. When no repair was requested the
308
+ * runtime returns a plain {@link TddCycleResult}; when {@link CycleOpts.repair} is set, the cycle
309
+ * returns this shape carrying the final cycle outcome plus the repair trace.
310
+ */
311
+ export interface TddRepairCycleResult extends TddCycleResult {
312
+ /** Repair trace: diffs suggested/applied across the loop. Empty iff the initial cycle was green. */
313
+ repair: TddRepairTrace;
314
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ /** Default per-cycle timeout (design §8). Generous: real reruns are sub-second; restarts are seconds. */
2
+ export const DEFAULT_CYCLE_TIMEOUT_MS = 60_000;
@@ -0,0 +1,28 @@
1
+ import type { RedFirstTestGeneratorOptions } from '../generator/RedFirstTestGenerator.js';
2
+ import type { InteractionSpec } from '../spec/InteractionSpec.js';
3
+ import type { InteractionSpecCoverageReport } from '../spec/InteractionSpecCoverage.js';
4
+ import type { SelectorSynthesisResult } from '../selectors/SelectorSynthesizer.js';
5
+ export type RedFirstWorkflowStatus = 'ready-to-run' | 'needs-output-file' | 'needs-coverage-review' | 'needs-selector-review';
6
+ export interface RedFirstWorkflowOptions extends RedFirstTestGeneratorOptions {
7
+ testFile?: string;
8
+ }
9
+ export interface RedFirstWorkflowContext {
10
+ testName: string;
11
+ flowId?: string;
12
+ testFile?: string;
13
+ selectorDiagnostics: SelectorSynthesisResult[];
14
+ }
15
+ export interface RedFirstWorkflowPlan {
16
+ status: RedFirstWorkflowStatus;
17
+ context: RedFirstWorkflowContext;
18
+ coverage: InteractionSpecCoverageReport;
19
+ }
20
+ export interface PrepareRedFirstWorkflowResult {
21
+ testCode: string;
22
+ testName: string;
23
+ flowId?: string;
24
+ warnings: string[];
25
+ selectorDiagnostics: SelectorSynthesisResult[];
26
+ workflow: RedFirstWorkflowPlan;
27
+ }
28
+ export declare function prepareRedFirstWorkflow(spec: InteractionSpec, options?: RedFirstWorkflowOptions): PrepareRedFirstWorkflowResult;
@@ -0,0 +1,33 @@
1
+ import { generateRedFirstTest } from '../generator/RedFirstTestGenerator.js';
2
+ import { analyzeInteractionSpecCoverage } from '../spec/InteractionSpecCoverage.js';
3
+ export function prepareRedFirstWorkflow(spec, options = {}) {
4
+ const generated = generateRedFirstTest(spec, options);
5
+ const coverage = analyzeInteractionSpecCoverage(spec);
6
+ const context = {
7
+ testName: generated.testName,
8
+ flowId: generated.flowId,
9
+ testFile: options.testFile,
10
+ selectorDiagnostics: generated.selectorDiagnostics,
11
+ };
12
+ const status = workflowStatus(context, coverage);
13
+ return {
14
+ ...generated,
15
+ workflow: {
16
+ status,
17
+ context,
18
+ coverage,
19
+ },
20
+ };
21
+ }
22
+ function workflowStatus(context, coverage) {
23
+ const needsSelectorReview = context.selectorDiagnostics.some((diagnostic) => (diagnostic.status === 'ambiguous'
24
+ || diagnostic.status === 'missing'
25
+ || diagnostic.status === 'hint-only'));
26
+ if (needsSelectorReview)
27
+ return 'needs-selector-review';
28
+ if (coverage.status === 'has-gaps')
29
+ return 'needs-coverage-review';
30
+ if (!context.testFile)
31
+ return 'needs-output-file';
32
+ return 'ready-to-run';
33
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@fliwright/tdd",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Experimental persistent red-green-refactor workflows for Fliwright.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/0x01lab/fliwright.git",
9
+ "directory": "packages/fliwright-tdd"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/0x01lab/fliwright/issues"
13
+ },
14
+ "homepage": "https://github.com/0x01lab/fliwright#readme",
15
+ "type": "module",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "engines": {
24
+ "node": "^22.12.0 || ^24.0.0 || >=26.0.0"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "tag": "next"
29
+ },
30
+ "dependencies": {
31
+ "vitest": "5.0.5",
32
+ "@fliwright/core": "0.1.0",
33
+ "@fliwright/vitest": "0.1.0"
34
+ },
35
+ "devDependencies": {
36
+ "typescript": "^5.5.0"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "test": "vitest run",
41
+ "lint": "tsc --noEmit",
42
+ "test:e2e:daemon": "node spike/e2e-daemon-conformance.mjs",
43
+ "test:e2e:cycle": "node spike/e2e-tdd-cycle.mjs"
44
+ }
6
45
  }