@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fliwright contributors.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fliwright/tdd
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Experimental persistent red-green-refactor runtime for Fliwright. This package
|
|
4
|
+
is published under the npm `next` tag while its Flutter daemon and restart
|
|
5
|
+
compatibility matrix is validated.
|
|
6
|
+
|
|
7
|
+
Most users should begin with `@fliwright/cli` and `@fliwright/vitest`. TDD
|
|
8
|
+
commands are available under `fliwright tdd`.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ResetAdapter } from './BaselineManager.js';
|
|
2
|
+
export declare const WebviewResetAdapter: ResetAdapter;
|
|
3
|
+
export declare const TimersResetAdapter: ResetAdapter;
|
|
4
|
+
export declare const IsolatesResetAdapter: ResetAdapter;
|
|
5
|
+
export declare const PermissionsResetAdapter: ResetAdapter;
|
|
6
|
+
export declare const AppCapabilityResetAdapters: ResetAdapter[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const RESET_CAPABILITY = 'fliwright.reset';
|
|
2
|
+
const RESET_METHOD = 'reset';
|
|
3
|
+
export const WebviewResetAdapter = createAppCapabilityResetAdapter('webview');
|
|
4
|
+
export const TimersResetAdapter = createAppCapabilityResetAdapter('timers');
|
|
5
|
+
export const IsolatesResetAdapter = createAppCapabilityResetAdapter('isolates');
|
|
6
|
+
export const PermissionsResetAdapter = createAppCapabilityResetAdapter('permissions');
|
|
7
|
+
export const AppCapabilityResetAdapters = [
|
|
8
|
+
WebviewResetAdapter,
|
|
9
|
+
TimersResetAdapter,
|
|
10
|
+
IsolatesResetAdapter,
|
|
11
|
+
PermissionsResetAdapter,
|
|
12
|
+
];
|
|
13
|
+
function createAppCapabilityResetAdapter(category) {
|
|
14
|
+
return {
|
|
15
|
+
category,
|
|
16
|
+
async reset(ctx) {
|
|
17
|
+
const app = ctx.driver.app;
|
|
18
|
+
if (!app)
|
|
19
|
+
return 'unsupported';
|
|
20
|
+
const supported = await supportsResetCapability(app);
|
|
21
|
+
if (!supported)
|
|
22
|
+
return 'unsupported';
|
|
23
|
+
await app.invoke(RESET_CAPABILITY, RESET_METHOD, {
|
|
24
|
+
category,
|
|
25
|
+
full: ctx.full,
|
|
26
|
+
});
|
|
27
|
+
return 'ok';
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async function supportsResetCapability(app) {
|
|
32
|
+
if (app.hasCapability) {
|
|
33
|
+
return await app.hasCapability(RESET_CAPABILITY);
|
|
34
|
+
}
|
|
35
|
+
if (app.listCapabilities) {
|
|
36
|
+
const capabilities = await app.listCapabilities();
|
|
37
|
+
return capabilities.some((capability) => (capability.name === RESET_CAPABILITY &&
|
|
38
|
+
capability.methods.includes(RESET_METHOD)));
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ResetAdapterResult, ResetCategory, ResetReport, Scenario } from '../types.js';
|
|
2
|
+
export interface ResetContext {
|
|
3
|
+
driver: {
|
|
4
|
+
page: {
|
|
5
|
+
resetToHome(options?: {
|
|
6
|
+
homeRoute?: string;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
mock: {
|
|
10
|
+
clear(): Promise<void>;
|
|
11
|
+
clearForeignRoutes?(): Promise<void>;
|
|
12
|
+
clearCalls(): Promise<void>;
|
|
13
|
+
loadRules?(mockDir?: string): Promise<void>;
|
|
14
|
+
listRules?(): Array<{
|
|
15
|
+
endpoint: string;
|
|
16
|
+
method: string;
|
|
17
|
+
rules: string[];
|
|
18
|
+
activeRule: string;
|
|
19
|
+
}>;
|
|
20
|
+
switchRule?(endpoint: string, ruleName: string, method?: string): Promise<void>;
|
|
21
|
+
};
|
|
22
|
+
state?: {
|
|
23
|
+
override(key: string, value: unknown): Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Optional bridge facade for `ext.fliwright.storage.reset`. Absent when the
|
|
27
|
+
* bridge does not expose the extension; the built-in {@link StorageResetAdapter}
|
|
28
|
+
* self-degrades to `'unsupported'` in that case (design §6.5 / §11).
|
|
29
|
+
*/
|
|
30
|
+
storage?: {
|
|
31
|
+
reset(seed?: Record<string, unknown>): Promise<StorageResetOutcome>;
|
|
32
|
+
};
|
|
33
|
+
app?: {
|
|
34
|
+
hasCapability?(name: string): Promise<boolean>;
|
|
35
|
+
listCapabilities?(): Promise<Array<{
|
|
36
|
+
name: string;
|
|
37
|
+
methods: string[];
|
|
38
|
+
}>>;
|
|
39
|
+
invoke(capability: string, method: string, input?: unknown): Promise<unknown>;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
scenario: Scenario;
|
|
43
|
+
full: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Result of a `ext.fliwright.storage.reset` call surfaced through the driver. */
|
|
46
|
+
export type StorageResetOutcome = {
|
|
47
|
+
status: 'ok';
|
|
48
|
+
clearedKeys?: number;
|
|
49
|
+
seededKeys?: number;
|
|
50
|
+
} | {
|
|
51
|
+
status: 'unsupported';
|
|
52
|
+
};
|
|
53
|
+
export interface ResetAdapter {
|
|
54
|
+
category: ResetCategory;
|
|
55
|
+
reset(ctx: ResetContext): Promise<'ok' | 'skipped' | 'unsupported' | ResetAdapterResult>;
|
|
56
|
+
}
|
|
57
|
+
export declare class BaselineManager {
|
|
58
|
+
private readonly driver;
|
|
59
|
+
private readonly adapters;
|
|
60
|
+
private baselineVersion;
|
|
61
|
+
constructor(driver: ResetContext['driver']);
|
|
62
|
+
get version(): number;
|
|
63
|
+
registerAdapter(adapter: ResetAdapter): void;
|
|
64
|
+
reset(scenario: Scenario, opts?: {
|
|
65
|
+
full?: boolean;
|
|
66
|
+
}): Promise<ResetReport>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { AppCapabilityResetAdapters } from './AppCapabilityResetAdapter.js';
|
|
2
|
+
import { StorageBackedResetAdapters } from './StorageResetAdapter.js';
|
|
3
|
+
export class BaselineManager {
|
|
4
|
+
driver;
|
|
5
|
+
adapters = new Map();
|
|
6
|
+
baselineVersion = 0;
|
|
7
|
+
constructor(driver) {
|
|
8
|
+
this.driver = driver;
|
|
9
|
+
this.registerAdapter({
|
|
10
|
+
category: 'navigation',
|
|
11
|
+
reset: async ({ driver: runtimeDriver, scenario }) => {
|
|
12
|
+
await runtimeDriver.page.resetToHome({ homeRoute: scenario.homeRoute });
|
|
13
|
+
return 'ok';
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
this.registerAdapter({
|
|
17
|
+
category: 'mock',
|
|
18
|
+
reset: async ({ driver: runtimeDriver, scenario }) => {
|
|
19
|
+
if (runtimeDriver.mock.clearForeignRoutes) {
|
|
20
|
+
await runtimeDriver.mock.clearForeignRoutes();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
await runtimeDriver.mock.clear();
|
|
24
|
+
}
|
|
25
|
+
await runtimeDriver.mock.clearCalls();
|
|
26
|
+
if (scenario.mockProfile) {
|
|
27
|
+
const profileResult = await applyMockProfile(runtimeDriver.mock, scenario.mockProfile, scenario.mockDir);
|
|
28
|
+
if (profileResult)
|
|
29
|
+
return profileResult;
|
|
30
|
+
}
|
|
31
|
+
return 'ok';
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
this.registerAdapter({
|
|
35
|
+
category: 'riverpod',
|
|
36
|
+
reset: async ({ driver: runtimeDriver, scenario }) => {
|
|
37
|
+
const overrides = scenario.riverpodOverrides ?? [];
|
|
38
|
+
if (overrides.length === 0)
|
|
39
|
+
return 'skipped';
|
|
40
|
+
if (!runtimeDriver.state) {
|
|
41
|
+
return {
|
|
42
|
+
category: 'riverpod',
|
|
43
|
+
status: 'unsupported',
|
|
44
|
+
message: 'Driver exposes no Riverpod state adapter.',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
for (const [index, override] of overrides.entries()) {
|
|
48
|
+
const normalized = normalizeRiverpodOverride(override);
|
|
49
|
+
if (!normalized) {
|
|
50
|
+
return {
|
|
51
|
+
category: 'riverpod',
|
|
52
|
+
status: 'unsupported',
|
|
53
|
+
message: `Invalid riverpodOverrides[${index}]; expected { provider | key, value }.`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
await runtimeDriver.state.override(normalized.key, normalized.value);
|
|
57
|
+
}
|
|
58
|
+
return 'ok';
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
// Self-degrading built-ins: return 'unsupported' (surfaced in ResetReport.unsupported) when the
|
|
62
|
+
// bridge storage.reset extension is absent. Design §6.5 / §11.
|
|
63
|
+
for (const adapter of StorageBackedResetAdapters) {
|
|
64
|
+
this.registerAdapter(adapter);
|
|
65
|
+
}
|
|
66
|
+
for (const adapter of AppCapabilityResetAdapters) {
|
|
67
|
+
this.registerAdapter(adapter);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
get version() {
|
|
71
|
+
return this.baselineVersion;
|
|
72
|
+
}
|
|
73
|
+
registerAdapter(adapter) {
|
|
74
|
+
this.adapters.set(adapter.category, adapter);
|
|
75
|
+
}
|
|
76
|
+
async reset(scenario, opts = {}) {
|
|
77
|
+
const full = opts.full ?? false;
|
|
78
|
+
const results = [];
|
|
79
|
+
for (const category of scenario.resetCategories) {
|
|
80
|
+
const adapter = this.adapters.get(category);
|
|
81
|
+
if (!adapter) {
|
|
82
|
+
results.push({ category, status: 'unsupported', message: `No reset adapter registered for ${category}` });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const result = await adapter.reset({ driver: this.driver, scenario, full });
|
|
87
|
+
results.push(typeof result === 'string' ? { category, status: result } : result);
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
results.push({
|
|
91
|
+
category,
|
|
92
|
+
status: 'unsupported',
|
|
93
|
+
message: error instanceof Error ? error.message : String(error),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
this.baselineVersion += 1;
|
|
98
|
+
return {
|
|
99
|
+
version: this.baselineVersion,
|
|
100
|
+
full,
|
|
101
|
+
results,
|
|
102
|
+
unsupported: results
|
|
103
|
+
.filter((result) => result.status === 'unsupported')
|
|
104
|
+
.map((result) => result.category),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function normalizeRiverpodOverride(value) {
|
|
109
|
+
if (!value || typeof value !== 'object')
|
|
110
|
+
return null;
|
|
111
|
+
const record = value;
|
|
112
|
+
const key = typeof record.provider === 'string'
|
|
113
|
+
? record.provider
|
|
114
|
+
: typeof record.key === 'string'
|
|
115
|
+
? record.key
|
|
116
|
+
: undefined;
|
|
117
|
+
if (!key)
|
|
118
|
+
return null;
|
|
119
|
+
if (!Object.prototype.hasOwnProperty.call(record, 'value'))
|
|
120
|
+
return null;
|
|
121
|
+
return { key, value: record.value };
|
|
122
|
+
}
|
|
123
|
+
async function applyMockProfile(mock, profile, mockDir) {
|
|
124
|
+
if (!mock.loadRules || !mock.listRules || !mock.switchRule) {
|
|
125
|
+
return {
|
|
126
|
+
category: 'mock',
|
|
127
|
+
status: 'unsupported',
|
|
128
|
+
message: 'Driver mock adapter does not support rule profiles.',
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
await mock.loadRules(mockDir);
|
|
132
|
+
const endpoints = mock.listRules();
|
|
133
|
+
const matching = endpoints.filter((endpoint) => endpoint.rules.includes(profile));
|
|
134
|
+
if (matching.length === 0) {
|
|
135
|
+
return {
|
|
136
|
+
category: 'mock',
|
|
137
|
+
status: 'unsupported',
|
|
138
|
+
message: `Mock profile '${profile}' was not found in loaded mock rules.`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
for (const endpoint of matching) {
|
|
142
|
+
await mock.switchRule(endpoint.endpoint, profile, endpoint.method);
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ResetAdapter } from './BaselineManager.js';
|
|
2
|
+
/**
|
|
3
|
+
* Built-in reset adapters for storage-backed categories (design §6.5, Gap C).
|
|
4
|
+
*
|
|
5
|
+
* Calls `ext.fliwright.storage.reset` through the driver's optional `storage`
|
|
6
|
+
* facade. Self-degrades to `'unsupported'` when:
|
|
7
|
+
* - the driver does not expose the `storage` facade (the bridge extension is
|
|
8
|
+
* absent), or
|
|
9
|
+
* - the bridge reports the host app did not register a storage-reset handler.
|
|
10
|
+
*
|
|
11
|
+
* Registered as BaselineManager built-ins (alongside navigation and mock), so the unsupported case
|
|
12
|
+
* is surfaced in `ResetReport.unsupported` / `RuntimeSnapshot.unsupportedState` rather than thrown.
|
|
13
|
+
* See design §11.
|
|
14
|
+
*/
|
|
15
|
+
export declare const StorageResetAdapter: ResetAdapter;
|
|
16
|
+
export declare const AuthTokensResetAdapter: ResetAdapter;
|
|
17
|
+
export declare const SecureStorageResetAdapter: ResetAdapter;
|
|
18
|
+
export declare const LocalDbResetAdapter: ResetAdapter;
|
|
19
|
+
export declare const StorageBackedResetAdapters: ResetAdapter[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in reset adapters for storage-backed categories (design §6.5, Gap C).
|
|
3
|
+
*
|
|
4
|
+
* Calls `ext.fliwright.storage.reset` through the driver's optional `storage`
|
|
5
|
+
* facade. Self-degrades to `'unsupported'` when:
|
|
6
|
+
* - the driver does not expose the `storage` facade (the bridge extension is
|
|
7
|
+
* absent), or
|
|
8
|
+
* - the bridge reports the host app did not register a storage-reset handler.
|
|
9
|
+
*
|
|
10
|
+
* Registered as BaselineManager built-ins (alongside navigation and mock), so the unsupported case
|
|
11
|
+
* is surfaced in `ResetReport.unsupported` / `RuntimeSnapshot.unsupportedState` rather than thrown.
|
|
12
|
+
* See design §11.
|
|
13
|
+
*/
|
|
14
|
+
export const StorageResetAdapter = createStorageBackedResetAdapter('storage');
|
|
15
|
+
export const AuthTokensResetAdapter = createStorageBackedResetAdapter('authTokens');
|
|
16
|
+
export const SecureStorageResetAdapter = createStorageBackedResetAdapter('secureStorage');
|
|
17
|
+
export const LocalDbResetAdapter = createStorageBackedResetAdapter('localDb');
|
|
18
|
+
function createStorageBackedResetAdapter(category) {
|
|
19
|
+
return {
|
|
20
|
+
category,
|
|
21
|
+
async reset(ctx) {
|
|
22
|
+
const storage = ctx.driver.storage;
|
|
23
|
+
if (!storage)
|
|
24
|
+
return 'unsupported';
|
|
25
|
+
const outcome = await storage.reset(seedForCategory(category, ctx.scenario.storageSeed));
|
|
26
|
+
return outcome.status === 'ok' ? 'ok' : 'unsupported';
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function seedForCategory(category, storageSeed) {
|
|
31
|
+
if (category === 'storage')
|
|
32
|
+
return storageSeed;
|
|
33
|
+
return {
|
|
34
|
+
__fliwrightResetCategory: category,
|
|
35
|
+
...(storageSeed ? { seed: storageSeed } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export const StorageBackedResetAdapters = [
|
|
39
|
+
StorageResetAdapter,
|
|
40
|
+
AuthTokensResetAdapter,
|
|
41
|
+
SecureStorageResetAdapter,
|
|
42
|
+
LocalDbResetAdapter,
|
|
43
|
+
];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface DaemonMessage {
|
|
2
|
+
id?: number | string;
|
|
3
|
+
method?: string;
|
|
4
|
+
params?: Record<string, unknown>;
|
|
5
|
+
result?: unknown;
|
|
6
|
+
error?: string | {
|
|
7
|
+
code: string | number;
|
|
8
|
+
message: string;
|
|
9
|
+
data?: unknown;
|
|
10
|
+
};
|
|
11
|
+
event?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface AppStartParams {
|
|
14
|
+
projectId?: string;
|
|
15
|
+
deviceId: string;
|
|
16
|
+
target?: string;
|
|
17
|
+
flutterArgs?: string[];
|
|
18
|
+
mode?: 'run' | 'drive';
|
|
19
|
+
}
|
|
20
|
+
export interface AppHandle {
|
|
21
|
+
appId: string;
|
|
22
|
+
deviceId: string;
|
|
23
|
+
wsUri: string;
|
|
24
|
+
supportsRestart: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Line transport over Flutter machine-mode JSON-RPC. Unit-tested via a fake;
|
|
28
|
+
* the real subprocess implementation is SubprocessDaemonTransport.
|
|
29
|
+
*/
|
|
30
|
+
export interface DaemonTransport {
|
|
31
|
+
connect?(): Promise<void>;
|
|
32
|
+
request<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
33
|
+
onEvent(handler: (message: DaemonMessage) => void): () => void;
|
|
34
|
+
dispose(options?: {
|
|
35
|
+
keepAppAlive?: boolean;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AppHandle, AppStartParams, DaemonMessage, DaemonTransport } from './DaemonTransport.js';
|
|
2
|
+
export declare class FlutterDaemonController {
|
|
3
|
+
private readonly transport;
|
|
4
|
+
private started;
|
|
5
|
+
private readonly handles;
|
|
6
|
+
constructor(transport: DaemonTransport);
|
|
7
|
+
start(): Promise<void>;
|
|
8
|
+
startApp(params: AppStartParams, opts?: {
|
|
9
|
+
debugPortTimeoutMs?: number;
|
|
10
|
+
}): Promise<AppHandle>;
|
|
11
|
+
reload(appId: string): Promise<void>;
|
|
12
|
+
restart(appId: string): Promise<void>;
|
|
13
|
+
stop(appId: string): Promise<void>;
|
|
14
|
+
dispose(options?: {
|
|
15
|
+
keepAppAlive?: boolean;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
protected waitForEvent(event: string, predicate: (message: DaemonMessage) => boolean, timeoutMs: number): Promise<DaemonMessage>;
|
|
18
|
+
private require;
|
|
19
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export class FlutterDaemonController {
|
|
2
|
+
transport;
|
|
3
|
+
started = false;
|
|
4
|
+
handles = new Map();
|
|
5
|
+
constructor(transport) {
|
|
6
|
+
this.transport = transport;
|
|
7
|
+
}
|
|
8
|
+
async start() {
|
|
9
|
+
if (this.started)
|
|
10
|
+
return;
|
|
11
|
+
await this.transport.connect?.();
|
|
12
|
+
// The transport owns machine-mode launch; no app RPC is sent before startApp.
|
|
13
|
+
this.started = true;
|
|
14
|
+
}
|
|
15
|
+
async startApp(params, opts = {}) {
|
|
16
|
+
if (!this.started)
|
|
17
|
+
await this.start();
|
|
18
|
+
const requestParams = {
|
|
19
|
+
deviceId: params.deviceId,
|
|
20
|
+
target: params.target ?? 'lib/main.dart',
|
|
21
|
+
};
|
|
22
|
+
if (params.projectId !== undefined)
|
|
23
|
+
requestParams.projectId = params.projectId;
|
|
24
|
+
if (params.mode !== undefined)
|
|
25
|
+
requestParams.mode = params.mode;
|
|
26
|
+
if (params.flutterArgs !== undefined)
|
|
27
|
+
requestParams.flutterArgs = params.flutterArgs;
|
|
28
|
+
const earlyEvents = [];
|
|
29
|
+
const stopBuffering = this.transport.onEvent((message) => { if (message.event === 'app.debugPort')
|
|
30
|
+
earlyEvents.push(message); });
|
|
31
|
+
try {
|
|
32
|
+
const result = await this.transport.request('app.start', requestParams);
|
|
33
|
+
const appId = result.appId;
|
|
34
|
+
if (!appId) {
|
|
35
|
+
throw new Error(`flutter daemon app.start returned no appId. Doctor: confirm the device is online `
|
|
36
|
+
+ `(\`flutter devices\`), the target "${requestParams.target}" exists, and the project compiles.`
|
|
37
|
+
+ ` Raw response: ${JSON.stringify(result)}.`);
|
|
38
|
+
}
|
|
39
|
+
const debugPort = earlyEvents.find((message) => message.params?.appId === appId) ?? await this.waitForEvent('app.debugPort', (m) => m.params?.appId === appId, opts.debugPortTimeoutMs ?? 60_000);
|
|
40
|
+
const wsUri = debugPort.params?.wsUri;
|
|
41
|
+
if (typeof wsUri !== 'string' || wsUri.length === 0) {
|
|
42
|
+
throw new Error(`flutter daemon app.debugPort for ${appId} carried no VM service wsUri. The app likely failed `
|
|
43
|
+
+ `to start. Doctor: run \`flutter run\` on the same target/device and read the console for `
|
|
44
|
+
+ `compile or runtime errors, then retry fliwright tdd start.`);
|
|
45
|
+
}
|
|
46
|
+
const handle = {
|
|
47
|
+
appId,
|
|
48
|
+
deviceId: result.deviceId ?? params.deviceId,
|
|
49
|
+
wsUri,
|
|
50
|
+
supportsRestart: result.supportsRestart ?? params.mode !== 'drive',
|
|
51
|
+
};
|
|
52
|
+
this.handles.set(appId, handle);
|
|
53
|
+
return handle;
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
stopBuffering();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async reload(appId) {
|
|
60
|
+
this.require(appId);
|
|
61
|
+
await this.transport.request('app.restart', { appId, fullRestart: false });
|
|
62
|
+
}
|
|
63
|
+
async restart(appId) {
|
|
64
|
+
const handle = this.require(appId);
|
|
65
|
+
if (!handle.supportsRestart)
|
|
66
|
+
throw new Error(`Hot restart not supported for app ${appId}`);
|
|
67
|
+
await this.transport.request('app.restart', { appId, fullRestart: true });
|
|
68
|
+
}
|
|
69
|
+
async stop(appId) {
|
|
70
|
+
this.require(appId);
|
|
71
|
+
await this.transport.request('app.stop', { appId });
|
|
72
|
+
this.handles.delete(appId);
|
|
73
|
+
}
|
|
74
|
+
async dispose(options = {}) {
|
|
75
|
+
if (options.keepAppAlive) {
|
|
76
|
+
for (const appId of this.handles.keys())
|
|
77
|
+
await this.transport.request('app.detach', { appId });
|
|
78
|
+
}
|
|
79
|
+
this.started = false;
|
|
80
|
+
this.handles.clear();
|
|
81
|
+
await this.transport.dispose(options);
|
|
82
|
+
}
|
|
83
|
+
async waitForEvent(event, predicate, timeoutMs) {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
let off;
|
|
86
|
+
const timer = setTimeout(() => {
|
|
87
|
+
off?.();
|
|
88
|
+
reject(event === 'app.debugPort'
|
|
89
|
+
? new Error(`Timed out after ${timeoutMs}ms waiting for the app's VM service (app.debugPort). `
|
|
90
|
+
+ `The app may still be building or may have crashed at startup. Doctor: check `
|
|
91
|
+
+ `\`flutter run\` console output on this target, then retry fliwright tdd start.`)
|
|
92
|
+
: new Error(`waitForEvent('${event}') timed out after ${timeoutMs}ms`));
|
|
93
|
+
}, timeoutMs);
|
|
94
|
+
off = this.transport.onEvent((message) => {
|
|
95
|
+
if (message.event === event && predicate(message)) {
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
off?.();
|
|
98
|
+
resolve(message);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
require(appId) {
|
|
104
|
+
const handle = this.handles.get(appId);
|
|
105
|
+
if (!handle)
|
|
106
|
+
throw new Error(`Unknown appId: ${appId}`);
|
|
107
|
+
return handle;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type VmServiceAcquisitionRequest, type VmServiceEndpoint, type VmServiceEndpointSource } from '@fliwright/core';
|
|
2
|
+
import type { AppHandle, AppStartParams } from './DaemonTransport.js';
|
|
3
|
+
type FlutterDaemonStarter = Pick<import('./FlutterDaemonController.js').FlutterDaemonController, 'startApp'>;
|
|
4
|
+
export interface FlutterDaemonEndpointSourceOptions {
|
|
5
|
+
controller: FlutterDaemonStarter;
|
|
6
|
+
projectId?: string;
|
|
7
|
+
deviceId: string;
|
|
8
|
+
target?: string;
|
|
9
|
+
flutterArgs?: string[];
|
|
10
|
+
mode?: AppStartParams['mode'];
|
|
11
|
+
debugPortTimeoutMs?: number;
|
|
12
|
+
scope?: VmServiceEndpoint['scope'];
|
|
13
|
+
}
|
|
14
|
+
/** Acquires the app.debugPort.wsUri emitted for the app this daemon starts. */
|
|
15
|
+
export declare class FlutterDaemonEndpointSource implements VmServiceEndpointSource {
|
|
16
|
+
private readonly options;
|
|
17
|
+
readonly name = "flutter-daemon";
|
|
18
|
+
private _lastApp?;
|
|
19
|
+
constructor(options: FlutterDaemonEndpointSourceOptions);
|
|
20
|
+
get lastApp(): AppHandle | undefined;
|
|
21
|
+
acquire(request?: VmServiceAcquisitionRequest): Promise<VmServiceEndpoint>;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { normalizeVmServiceUrl, } from '@fliwright/core';
|
|
2
|
+
/** Acquires the app.debugPort.wsUri emitted for the app this daemon starts. */
|
|
3
|
+
export class FlutterDaemonEndpointSource {
|
|
4
|
+
options;
|
|
5
|
+
name = 'flutter-daemon';
|
|
6
|
+
_lastApp;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
get lastApp() { return this._lastApp; }
|
|
11
|
+
async acquire(request = {}) {
|
|
12
|
+
if (this.options.flutterArgs?.includes('--release')) {
|
|
13
|
+
throw new Error('Managed VM Service acquisition does not support Flutter release mode.');
|
|
14
|
+
}
|
|
15
|
+
const deviceId = request.deviceId ?? this.options.deviceId;
|
|
16
|
+
const handle = await this.options.controller.startApp({
|
|
17
|
+
projectId: this.options.projectId,
|
|
18
|
+
deviceId,
|
|
19
|
+
target: this.options.target,
|
|
20
|
+
flutterArgs: this.options.flutterArgs,
|
|
21
|
+
mode: this.options.mode,
|
|
22
|
+
}, { debugPortTimeoutMs: this.options.debugPortTimeoutMs });
|
|
23
|
+
this._lastApp = handle;
|
|
24
|
+
const url = normalizeVmServiceUrl(handle.wsUri);
|
|
25
|
+
if (!url)
|
|
26
|
+
throw new Error('flutter daemon returned an invalid app.debugPort.wsUri');
|
|
27
|
+
return {
|
|
28
|
+
url,
|
|
29
|
+
kind: 'direct-vm',
|
|
30
|
+
source: this.name,
|
|
31
|
+
scope: this.options.scope ?? 'execution-worker',
|
|
32
|
+
appId: handle.appId,
|
|
33
|
+
deviceId: handle.deviceId,
|
|
34
|
+
acquiredAt: new Date().toISOString(),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TddCycleResult } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reload-vs-restart decision policy (design spec §6.4).
|
|
4
|
+
*
|
|
5
|
+
* Default mode is heuristic + path-based (no analyzer dependency). A later opt-in `strategy:
|
|
6
|
+
* 'precise'` upgrade would add AST-diff signals; the heuristic here is the safe default and errs
|
|
7
|
+
* toward "restart once more than be stale" only for signals that path inspection alone proves
|
|
8
|
+
* structural (generated code, pubspec/assets/l10n). Plain `.dart` changes are treated as reload;
|
|
9
|
+
* if reload fails to reflect a structural edit, the loop's auto-escalation (see `TddRuntime.cycle`)
|
|
10
|
+
* promotes the next pass to restart.
|
|
11
|
+
*/
|
|
12
|
+
/** Sync level the runtime should perform for this change set. */
|
|
13
|
+
export type SyncDecision = TddCycleResult['lastSync'];
|
|
14
|
+
/**
|
|
15
|
+
* Decide the sync level for a set of changed file paths since the last sync.
|
|
16
|
+
*
|
|
17
|
+
* - no changes → `none`
|
|
18
|
+
* - any generated / pubspec / assets / l10n path → `restart`
|
|
19
|
+
* - otherwise (plain `.dart` bodies, literals, UI) → `reload`
|
|
20
|
+
*/
|
|
21
|
+
export declare function decideSync(changes?: readonly string[]): SyncDecision;
|
|
22
|
+
/** True when a single changed path is provably structural by inspection alone. */
|
|
23
|
+
export declare function isStructuralFileChange(changePath: string): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* True when a red cycle result looks like a reload that failed to reflect a structural change and
|
|
26
|
+
* is therefore worth retrying with a restart.
|
|
27
|
+
*/
|
|
28
|
+
export declare function looksStructuralAfterReload(result: Pick<TddCycleResult, 'status' | 'lastSync' | 'failureContext'>): boolean;
|