@fliwright/vitest 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/dist/AttemptContext.d.ts +6 -1
- package/dist/AttemptContext.js +6 -1
- package/dist/TaskEndpointLease.d.ts +5 -1
- package/dist/TaskEndpointLease.js +46 -9
- package/dist/TaskManagedApp.d.ts +5 -0
- package/dist/TaskManagedApp.js +26 -0
- package/dist/TaskNativeSession.d.ts +17 -0
- package/dist/TaskNativeSession.js +140 -0
- package/dist/TaskScenarioPreparation.d.ts +14 -0
- package/dist/TaskScenarioPreparation.js +29 -0
- package/dist/TestRegistration.d.ts +2 -2
- package/dist/TestRegistration.js +2 -2
- package/dist/index.d.ts +18 -4
- package/dist/index.js +189 -56
- package/dist/preset.d.ts +3 -1
- package/dist/preset.js +4 -4
- package/dist/runner.js +63 -15
- package/package.json +4 -3
package/dist/AttemptContext.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RunArtifactStore, TimelineArtifactStore, TimelineRecorder } from '@fliwright/core';
|
|
2
|
-
import type { FliwrightLogger, RecordingMode, RunSession, RunSessionResult, TimelineRunMode, TimelineNode } from '@fliwright/core';
|
|
2
|
+
import type { FliwrightLogger, RecordingMode, RunSession, RunSessionResult, TimelineRunMode, TimelineNode, ScenarioDevicePreparation } from '@fliwright/core';
|
|
3
3
|
import type { RunnerTask } from 'vitest';
|
|
4
4
|
import { FinalizationBudget } from './FinalizationBudget.js';
|
|
5
5
|
/** Shared by the runner and fixture module, including separate Vitest module graphs. */
|
|
@@ -9,6 +9,11 @@ export declare class AttemptContext {
|
|
|
9
9
|
readonly testId: string;
|
|
10
10
|
readonly testName: string;
|
|
11
11
|
readonly attemptId: string;
|
|
12
|
+
managedApp?: import('@fliwright/core').ManagedAppAttemptEndpoint;
|
|
13
|
+
androidReadback?: import('@fliwright/core').AndroidAppReadbackReport;
|
|
14
|
+
managedAppDriver?: Promise<import('@fliwright/core').FliwrightDriver>;
|
|
15
|
+
cleanupManagedAppDriver?: (signal: AbortSignal) => Promise<void>;
|
|
16
|
+
devicePreparation?: ScenarioDevicePreparation;
|
|
12
17
|
recorder: TimelineRecorder;
|
|
13
18
|
artifactStore: TimelineArtifactStore;
|
|
14
19
|
runStore: RunArtifactStore;
|
package/dist/AttemptContext.js
CHANGED
|
@@ -11,6 +11,11 @@ export class AttemptContext {
|
|
|
11
11
|
testId;
|
|
12
12
|
testName;
|
|
13
13
|
attemptId;
|
|
14
|
+
managedApp;
|
|
15
|
+
androidReadback;
|
|
16
|
+
managedAppDriver;
|
|
17
|
+
cleanupManagedAppDriver;
|
|
18
|
+
devicePreparation;
|
|
14
19
|
recorder;
|
|
15
20
|
artifactStore;
|
|
16
21
|
runStore;
|
|
@@ -196,7 +201,7 @@ export class AttemptContext {
|
|
|
196
201
|
const evidence = await this.session.checkpoint({ kind, reason: 'failure', operationId: node.id });
|
|
197
202
|
if (signal.aborted)
|
|
198
203
|
return;
|
|
199
|
-
this.recorder.addArtifacts(node.id, (evidence.artifactPaths ?? []).map((path) => ({ kind, path })));
|
|
204
|
+
this.recorder.addArtifacts(node.id, (evidence.artifactPaths ?? []).map((path) => ({ kind, path, metadata: evidence.artifactMetadata })));
|
|
200
205
|
}
|
|
201
206
|
});
|
|
202
207
|
await this.finalizeStep('Failure projection', async (signal) => { await this.onFailure?.(error, node, signal); });
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { EndpointLease } from '@fliwright/core';
|
|
2
2
|
import type { RunnerTask } from 'vitest';
|
|
3
|
+
export declare function setTaskOwnershipErrorHandler(task: RunnerTask, handler: (error: unknown) => Promise<void>): void;
|
|
3
4
|
/** The runner and fixtures may live in separate Vitest module graphs. */
|
|
4
5
|
export declare function getTaskEndpointLease(task: RunnerTask): EndpointLease | undefined;
|
|
5
6
|
export declare function setTaskEndpointLease(task: RunnerTask, lease: EndpointLease): void;
|
|
7
|
+
/** Relaunch replaces endpoint ownership while retaining the task's device lease. */
|
|
8
|
+
export declare function releaseTaskAppEndpoint(task: RunnerTask): Promise<void>;
|
|
6
9
|
/** Runtime skip bypasses the final task hook; both runner and fixture must finish. */
|
|
7
|
-
export declare function
|
|
10
|
+
export declare function resetTaskOwnershipPhases(task: RunnerTask): void;
|
|
11
|
+
export declare function finishTaskEndpointLeasePhase(task: RunnerTask, phase: 'cleanupComplete' | 'skipFinalized', finalize?: () => Promise<void>): Promise<void>;
|
|
8
12
|
export declare function releaseTaskEndpointLease(task: RunnerTask): Promise<void>;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { releaseTaskNativeSession } from './TaskNativeSession.js';
|
|
1
2
|
const leaseKey = Symbol.for('@fliwright/vitest/task-endpoint-lease');
|
|
3
|
+
const releaseErrorKey = Symbol.for('@fliwright/vitest/task-ownership-release-error');
|
|
4
|
+
const phasesKey = Symbol.for('@fliwright/vitest/task-ownership-phases');
|
|
5
|
+
export function setTaskOwnershipErrorHandler(task, handler) {
|
|
6
|
+
task[releaseErrorKey] = handler;
|
|
7
|
+
}
|
|
2
8
|
/** The runner and fixtures may live in separate Vitest module graphs. */
|
|
3
9
|
export function getTaskEndpointLease(task) {
|
|
4
10
|
return task[leaseKey]?.lease;
|
|
@@ -6,23 +12,54 @@ export function getTaskEndpointLease(task) {
|
|
|
6
12
|
export function setTaskEndpointLease(task, lease) {
|
|
7
13
|
task[leaseKey] = { lease };
|
|
8
14
|
}
|
|
15
|
+
/** Relaunch replaces endpoint ownership while retaining the task's device lease. */
|
|
16
|
+
export async function releaseTaskAppEndpoint(task) {
|
|
17
|
+
await getTaskEndpointLease(task)?.release();
|
|
18
|
+
delete task[leaseKey];
|
|
19
|
+
}
|
|
9
20
|
/** Runtime skip bypasses the final task hook; both runner and fixture must finish. */
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
21
|
+
export function resetTaskOwnershipPhases(task) {
|
|
22
|
+
task[phasesKey] = {};
|
|
23
|
+
}
|
|
24
|
+
export async function finishTaskEndpointLeasePhase(task, phase, finalize) {
|
|
25
|
+
const state = task[phasesKey];
|
|
26
|
+
// Plain Vitest tasks can use this runner without Fliwright's auto fixture.
|
|
27
|
+
if (!state) {
|
|
28
|
+
if (finalize) {
|
|
29
|
+
await releaseTaskEndpointLease(task);
|
|
30
|
+
await finalize();
|
|
31
|
+
}
|
|
13
32
|
return;
|
|
33
|
+
}
|
|
14
34
|
state[phase] = true;
|
|
15
|
-
if (
|
|
35
|
+
if (finalize)
|
|
36
|
+
state.finalize = finalize;
|
|
37
|
+
if (state.cleanupComplete && state.skipFinalized) {
|
|
38
|
+
delete task[phasesKey];
|
|
16
39
|
await releaseTaskEndpointLease(task);
|
|
40
|
+
await state.finalize?.();
|
|
41
|
+
}
|
|
17
42
|
}
|
|
18
43
|
export async function releaseTaskEndpointLease(task) {
|
|
19
44
|
const lease = getTaskEndpointLease(task);
|
|
20
|
-
|
|
21
|
-
return;
|
|
45
|
+
const errors = [];
|
|
22
46
|
try {
|
|
23
|
-
await lease
|
|
47
|
+
await lease?.release();
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
errors.push(error);
|
|
51
|
+
}
|
|
52
|
+
delete task[leaseKey];
|
|
53
|
+
try {
|
|
54
|
+
await releaseTaskNativeSession(task);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
errors.push(...(error instanceof AggregateError ? error.errors : [error]));
|
|
24
58
|
}
|
|
25
|
-
|
|
26
|
-
|
|
59
|
+
for (const error of errors) {
|
|
60
|
+
const handler = task[releaseErrorKey];
|
|
61
|
+
if (!handler)
|
|
62
|
+
throw error;
|
|
63
|
+
await handler(error);
|
|
27
64
|
}
|
|
28
65
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type ScenarioExecutionMode, type TestScenario } from '@fliwright/core';
|
|
2
|
+
import type { RunnerTestCase } from 'vitest';
|
|
3
|
+
export declare function blockTaskManagedApp(task: RunnerTestCase): void;
|
|
4
|
+
/** Runs before the attempt's Adapter, endpoint acquisition and all Bridge work. */
|
|
5
|
+
export declare function prepareTaskManagedApp(task: RunnerTestCase, scenario: TestScenario | undefined, mode: ScenarioExecutionMode | undefined, signal: AbortSignal, nativeEnabled?: boolean): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { fingerprintScenario, prepareManagedAppAttempt, readManagedAppControl, ScenarioPreparationError } from '@fliwright/core';
|
|
2
|
+
import { requireAttemptContext } from './AttemptContext.js';
|
|
3
|
+
import { disposeTaskNativeAttempt } from './TaskNativeSession.js';
|
|
4
|
+
import { releaseTaskAppEndpoint } from './TaskEndpointLease.js';
|
|
5
|
+
const dirtyKey = Symbol.for('@fliwright/vitest/managed-app-cleanup-unconfirmed');
|
|
6
|
+
export function blockTaskManagedApp(task) { task[dirtyKey] = true; }
|
|
7
|
+
/** Runs before the attempt's Adapter, endpoint acquisition and all Bridge work. */
|
|
8
|
+
export async function prepareTaskManagedApp(task, scenario, mode, signal, nativeEnabled = false) {
|
|
9
|
+
if (mode !== 'managed-start' || !nativeEnabled)
|
|
10
|
+
return;
|
|
11
|
+
if (task[dirtyKey])
|
|
12
|
+
throw new ScenarioPreparationError('The previous managed app connection cleanup was not confirmed; a new managed run is required.');
|
|
13
|
+
const attempt = requireAttemptContext(task);
|
|
14
|
+
if (attempt.managedApp)
|
|
15
|
+
return;
|
|
16
|
+
const control = readManagedAppControl();
|
|
17
|
+
if (!control)
|
|
18
|
+
throw new ScenarioPreparationError('Managed device scenarios require a live app supervisor. Use managed CLI run/script or a Cloud Worker.');
|
|
19
|
+
signal.throwIfAborted();
|
|
20
|
+
await disposeTaskNativeAttempt(task);
|
|
21
|
+
await releaseTaskAppEndpoint(task);
|
|
22
|
+
attempt.managedApp = await prepareManagedAppAttempt(control, {
|
|
23
|
+
attemptKey: `${attempt.runId}/${task.id}/${attempt.attemptId}`,
|
|
24
|
+
...(scenario ? { scenarioName: scenario.name, scenarioFingerprint: fingerprintScenario(scenario) } : {}),
|
|
25
|
+
}, { signal });
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type NativeConfig, type NativeRuntime, type RunSession, type TestScenario } from '@fliwright/core';
|
|
2
|
+
import { type NativeDeviceSession } from '@fliwright/native';
|
|
3
|
+
import type { RunnerTask, RunnerTestCase } from 'vitest';
|
|
4
|
+
export type NativeDeviceProvider = (config: NativeConfig, options: {
|
|
5
|
+
signal: AbortSignal;
|
|
6
|
+
}) => Promise<NativeDeviceSession>;
|
|
7
|
+
export declare function hasTaskNativeRuntime(task: RunnerTask): boolean;
|
|
8
|
+
/** Called before acquiring the endpoint so separate VM URLs cannot bypass device exclusion. */
|
|
9
|
+
export declare function prepareTaskNativeSession(task: RunnerTask, config: NativeConfig | undefined, signal: AbortSignal, provider?: NativeDeviceProvider): Promise<void>;
|
|
10
|
+
export declare function quarantineTaskNativeSession(task: RunnerTask): Promise<void>;
|
|
11
|
+
export declare function taskNativeRuntime(task: RunnerTestCase, session: RunSession, attemptId: string): Promise<NativeRuntime>;
|
|
12
|
+
export declare function verifyTaskNativeBinding(task: RunnerTestCase, driver: {
|
|
13
|
+
sendRequest(method: string): Promise<unknown>;
|
|
14
|
+
}, attemptId: string, scenario?: TestScenario): Promise<void>;
|
|
15
|
+
export declare function disposeTaskNativeAttempt(task: RunnerTask): Promise<void>;
|
|
16
|
+
/** Release last, after endpoint ownership and all attempt evidence have finished. */
|
|
17
|
+
export declare function releaseTaskNativeSession(task: RunnerTask): Promise<void>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { NativeError, createAndroidAppReadback, fingerprintScenario, getAndroidScenarioPermissions } from '@fliwright/core';
|
|
2
|
+
import { openNativeDevice } from '@fliwright/native';
|
|
3
|
+
import { requireAttemptContext } from './AttemptContext.js';
|
|
4
|
+
const nativeKey = Symbol.for('@fliwright/vitest/task-native-session');
|
|
5
|
+
const stateFor = (task) => task[nativeKey];
|
|
6
|
+
export function hasTaskNativeRuntime(task) { return !!stateFor(task)?.runtime; }
|
|
7
|
+
/** Called before acquiring the endpoint so separate VM URLs cannot bypass device exclusion. */
|
|
8
|
+
export async function prepareTaskNativeSession(task, config, signal, provider = openNativeDevice) {
|
|
9
|
+
if (!config?.enabled)
|
|
10
|
+
return;
|
|
11
|
+
const existing = stateFor(task);
|
|
12
|
+
if (existing) {
|
|
13
|
+
if (existing.quarantined)
|
|
14
|
+
throw new NativeError('cleanup_failed', 'Managed app cleanup was not confirmed; restore the device before starting another attempt.');
|
|
15
|
+
if (existing.config !== JSON.stringify(config))
|
|
16
|
+
throw new NativeError('device_mismatch', 'Native configuration changed while this test owns the device.');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const owner = await provider(config, { signal });
|
|
20
|
+
if (signal.aborted) {
|
|
21
|
+
await owner.dispose();
|
|
22
|
+
throw new NativeError('cancelled', 'Native preparation cancelled.');
|
|
23
|
+
}
|
|
24
|
+
task[nativeKey] = { owner, config: JSON.stringify(config) };
|
|
25
|
+
}
|
|
26
|
+
export async function quarantineTaskNativeSession(task) {
|
|
27
|
+
const state = stateFor(task);
|
|
28
|
+
if (!state)
|
|
29
|
+
return;
|
|
30
|
+
state.quarantined = true;
|
|
31
|
+
if (!state.owner.quarantine)
|
|
32
|
+
throw new NativeError('cleanup_failed', 'Native device provider cannot quarantine unconfirmed app cleanup.');
|
|
33
|
+
await state.owner.quarantine('Managed app connection cleanup was not confirmed.');
|
|
34
|
+
}
|
|
35
|
+
export async function taskNativeRuntime(task, session, attemptId) {
|
|
36
|
+
const state = stateFor(task);
|
|
37
|
+
if (!state)
|
|
38
|
+
throw new NativeError('precondition_failed', 'Enable native automation and select a device/target app in the run configuration before using native or device fixtures.');
|
|
39
|
+
if (state.runtime && state.attemptId !== attemptId)
|
|
40
|
+
throw new NativeError('precondition_failed', 'The preceding native attempt was not cleaned up.');
|
|
41
|
+
if (!state.runtime) {
|
|
42
|
+
state.runtime = await state.owner.createRuntime({ signal: task.context.signal, runtime: { runSession: session } });
|
|
43
|
+
state.attemptId = attemptId;
|
|
44
|
+
}
|
|
45
|
+
return state.runtime;
|
|
46
|
+
}
|
|
47
|
+
export async function verifyTaskNativeBinding(task, driver, attemptId, scenario) {
|
|
48
|
+
const state = stateFor(task);
|
|
49
|
+
const attempt = requireAttemptContext(task), expected = attempt.managedApp?.nativeApp;
|
|
50
|
+
if (!state) {
|
|
51
|
+
if (expected)
|
|
52
|
+
throw new NativeError('precondition_failed', 'Android app readback requires the current native owner.');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (state.bindingAttemptId === attemptId)
|
|
56
|
+
return;
|
|
57
|
+
const signal = AbortSignal.any([task.context.signal, AbortSignal.timeout(expected ? 30000 : 5000)]);
|
|
58
|
+
let abort;
|
|
59
|
+
try {
|
|
60
|
+
const vm = await Promise.race([driver.sendRequest('getVM'), new Promise((_, reject) => {
|
|
61
|
+
abort = () => reject(new NativeError('device_mismatch', 'Flutter VM process identity could not be read within the binding budget.'));
|
|
62
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
63
|
+
if (signal.aborted)
|
|
64
|
+
abort();
|
|
65
|
+
})]);
|
|
66
|
+
const pid = vm && typeof vm === 'object' && 'pid' in vm ? vm.pid : undefined;
|
|
67
|
+
await state.owner.verifyAppProcess(pid, { signal });
|
|
68
|
+
if (expected) {
|
|
69
|
+
const node = attempt.recorder.startNode('step', 'Android app readback');
|
|
70
|
+
try {
|
|
71
|
+
if (!state.runtime || state.attemptId !== attemptId || !state.owner.inspectAppState || pid !== expected.pid) {
|
|
72
|
+
throw new NativeError('device_mismatch', 'Android app readback requires independent current process and native observation.');
|
|
73
|
+
}
|
|
74
|
+
const context = { attemptKey: `${attempt.runId}/${task.id}/${attemptId}`, attemptId,
|
|
75
|
+
managedAppGeneration: attempt.managedApp.generation, signal,
|
|
76
|
+
get scenarioFingerprint() { return scenario ? fingerprintScenario(scenario) : undefined; },
|
|
77
|
+
get permissionDeclaration() { return getAndroidScenarioPermissions(scenario); },
|
|
78
|
+
get identity() {
|
|
79
|
+
if (!state.runtime || state.attemptId !== attemptId)
|
|
80
|
+
throw new NativeError('device_mismatch', 'Android app readback runtime identity changed.');
|
|
81
|
+
return state.runtime.adapter.identity;
|
|
82
|
+
}, };
|
|
83
|
+
const readback = createAndroidAppReadback(expected, context, () => state.owner.inspectAppState(expected.permissions.map(item => item.permission), { signal, timeout: 30000 }));
|
|
84
|
+
attempt.androidReadback = await readback.consume(context);
|
|
85
|
+
attempt.recorder.passNode(node.id, { ...attempt.androidReadback });
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
attempt.recorder.failNode(node.id, { code: 'unknown', title: 'Android app readback', message: 'Independent Android app readback failed.', recoveryHints: [] });
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
signal.throwIfAborted();
|
|
93
|
+
state.bindingAttemptId = attemptId;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
if (abort)
|
|
97
|
+
signal.removeEventListener('abort', abort);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export async function disposeTaskNativeAttempt(task) {
|
|
101
|
+
const state = stateFor(task);
|
|
102
|
+
if (!state?.runtime)
|
|
103
|
+
return;
|
|
104
|
+
try {
|
|
105
|
+
await state.runtime.dispose();
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
state.runtime = undefined;
|
|
109
|
+
state.attemptId = undefined;
|
|
110
|
+
state.bindingAttemptId = undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Release last, after endpoint ownership and all attempt evidence have finished. */
|
|
114
|
+
export async function releaseTaskNativeSession(task) {
|
|
115
|
+
const state = stateFor(task);
|
|
116
|
+
if (!state)
|
|
117
|
+
return;
|
|
118
|
+
const errors = [];
|
|
119
|
+
try {
|
|
120
|
+
try {
|
|
121
|
+
await disposeTaskNativeAttempt(task);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
errors.push(error);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
await state.owner.dispose();
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
errors.push(error);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
delete task[nativeKey];
|
|
135
|
+
}
|
|
136
|
+
if (errors.length === 1)
|
|
137
|
+
throw errors[0];
|
|
138
|
+
if (errors.length)
|
|
139
|
+
throw new AggregateError(errors, 'Native attempt and device ownership cleanup failed.');
|
|
140
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type NativeConfig, type TestScenario, type ScenarioExecutionMode } from '@fliwright/core';
|
|
2
|
+
import type { RunnerTestCase } from 'vitest';
|
|
3
|
+
/** Worker-only declaration metadata, retained by fixture extension and omitted from JSON. */
|
|
4
|
+
export declare const taskScenarioKey: unique symbol;
|
|
5
|
+
export declare function taskScenario(task: RunnerTestCase, config: {
|
|
6
|
+
defaultScenario?: string;
|
|
7
|
+
scenarios?: Record<string, TestScenario>;
|
|
8
|
+
}): TestScenario | undefined;
|
|
9
|
+
export declare function validateTaskDeviceScenario(scenario: TestScenario | undefined, native: NativeConfig | undefined): void;
|
|
10
|
+
/** First setup runs outside the body timeout; automatic fixtures repeat this for retries. */
|
|
11
|
+
export declare function prepareTaskDeviceScenario(task: RunnerTestCase, scenario: TestScenario | undefined, config: {
|
|
12
|
+
native?: NativeConfig;
|
|
13
|
+
scenarioMode?: ScenarioExecutionMode;
|
|
14
|
+
}, signal: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { prepareScenarioDevice, ScenarioPreparationError, ScenarioResolver, validateScenarioDevicePreparation } from '@fliwright/core';
|
|
2
|
+
import { requireAttemptContext } from './AttemptContext.js';
|
|
3
|
+
import { taskNativeRuntime } from './TaskNativeSession.js';
|
|
4
|
+
/** Worker-only declaration metadata, retained by fixture extension and omitted from JSON. */
|
|
5
|
+
export const taskScenarioKey = Symbol.for('@fliwright/vitest/task-scenario');
|
|
6
|
+
export function taskScenario(task, config) {
|
|
7
|
+
const explicit = task.meta[taskScenarioKey];
|
|
8
|
+
return explicit ?? (config.defaultScenario ? new ScenarioResolver(config.scenarios ?? {}).resolve(config.defaultScenario) : undefined);
|
|
9
|
+
}
|
|
10
|
+
export function validateTaskDeviceScenario(scenario, native) {
|
|
11
|
+
if (!scenario || !validateScenarioDevicePreparation(scenario))
|
|
12
|
+
return;
|
|
13
|
+
if (!native?.enabled)
|
|
14
|
+
throw new ScenarioPreparationError(`Scenario '${scenario.name}' device preparation requires enabled native automation.`);
|
|
15
|
+
}
|
|
16
|
+
/** First setup runs outside the body timeout; automatic fixtures repeat this for retries. */
|
|
17
|
+
export async function prepareTaskDeviceScenario(task, scenario, config, signal) {
|
|
18
|
+
validateTaskDeviceScenario(scenario, config.native);
|
|
19
|
+
if (!scenario || !scenario.layers.some(layer => layer.kind === 'device'))
|
|
20
|
+
return;
|
|
21
|
+
const attempt = requireAttemptContext(task);
|
|
22
|
+
if (attempt.devicePreparation)
|
|
23
|
+
return;
|
|
24
|
+
const runtime = await taskNativeRuntime(task, attempt.session, attempt.attemptId);
|
|
25
|
+
attempt.devicePreparation = await prepareScenarioDevice(scenario, runtime, {
|
|
26
|
+
mode: config.scenarioMode ?? 'attach', attemptId: attempt.attemptId, signal,
|
|
27
|
+
managedAppGeneration: attempt.managedApp?.generation,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { RunnerTask, RunnerTestCase, TestAPI } from 'vitest';
|
|
1
|
+
import type { RunnerTask, RunnerTestCase, TaskMeta, TestAPI } from 'vitest';
|
|
2
2
|
type PrepareTask = (task: RunnerTestCase, signal: AbortSignal) => Promise<void>;
|
|
3
3
|
/** Bind preparation through public test metadata without wrapping the body.
|
|
4
4
|
* Symbol keys stay within the worker and are omitted from reporter serialization.
|
|
5
5
|
*/
|
|
6
|
-
export declare function withTaskPreparation<T extends object>(test: TestAPI<T>, prepare: PrepareTask): TestAPI<T>;
|
|
6
|
+
export declare function withTaskPreparation<T extends object>(test: TestAPI<T>, prepare: PrepareTask, metadata?: Partial<TaskMeta>): TestAPI<T>;
|
|
7
7
|
export declare function prepareRegisteredTask(task: RunnerTask, signal: AbortSignal): Promise<void>;
|
|
8
8
|
export {};
|
package/dist/TestRegistration.js
CHANGED
|
@@ -2,7 +2,7 @@ const prepareKey = Symbol.for('@fliwright/vitest/prepare-task');
|
|
|
2
2
|
/** Bind preparation through public test metadata without wrapping the body.
|
|
3
3
|
* Symbol keys stay within the worker and are omitted from reporter serialization.
|
|
4
4
|
*/
|
|
5
|
-
export function withTaskPreparation(test, prepare) {
|
|
5
|
+
export function withTaskPreparation(test, prepare, metadata = {}) {
|
|
6
6
|
const proxies = new WeakMap();
|
|
7
7
|
const variants = new Set(['concurrent', 'skip', 'only', 'todo', 'fails']);
|
|
8
8
|
const factories = new Set(['each', 'for', 'skipIf', 'runIf', 'extend']);
|
|
@@ -23,7 +23,7 @@ export function withTaskPreparation(test, prepare) {
|
|
|
23
23
|
: typeof handlerOrTimeout === 'number' ? { timeout: handlerOrTimeout } : {};
|
|
24
24
|
const handler = typeof optionsOrHandler === 'function' ? optionsOrHandler : handlerOrTimeout;
|
|
25
25
|
return Reflect.apply(fn, receiver, [name, {
|
|
26
|
-
...options, meta: { ...options.meta, [prepareKey]: prepare },
|
|
26
|
+
...options, meta: { ...options.meta, ...metadata, [prepareKey]: prepare },
|
|
27
27
|
}, handler]);
|
|
28
28
|
},
|
|
29
29
|
get(fn, property, receiver) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { afterAll, beforeAll, describe } from 'vitest';
|
|
2
|
-
import { AgentRuntime, AssertRuntime, AiRuntime, Assertion, FliwrightDriver, FlowRuntime, MockRuntime, TimelineArtifactStore } from '@fliwright/core';
|
|
2
|
+
import { AgentRuntime, AssertRuntime, AiRuntime, Assertion, FliwrightDriver, FlowRuntime, MockRuntime, TimelineArtifactStore, NativeLocator, CameraTestController, BiometricTestController } from '@fliwright/core';
|
|
3
|
+
import type { NativeConfig, NativePage, DeviceController, NativeAssertion } from '@fliwright/core';
|
|
3
4
|
import type { AiRuntimeConfig, AgentPolicy, FliwrightLogger, FliwrightLogLevel, FliwrightPlugin, FliwrightRecordingConfig, Locator, Page, ScenarioExecutionMode, TestScenario, TimelineRunMode, TimelineRecorder } from '@fliwright/core';
|
|
4
5
|
import type { TestAPI } from 'vitest';
|
|
6
|
+
import { type NativeDeviceProvider } from './TaskNativeSession.js';
|
|
5
7
|
export { FliwrightRunner, createFliwrightRunner } from './runner.js';
|
|
6
8
|
export type { FliwrightRunnerOptions, FliwrightRunnerConstructor } from './runner.js';
|
|
7
9
|
export { fliwrightPreset } from './preset.js';
|
|
8
10
|
export { FliwrightRecoveryReporter } from './RecoveryReporter.js';
|
|
9
11
|
export type { FliwrightVitestPresetOptions } from './preset.js';
|
|
12
|
+
export type { NativeDeviceProvider } from './TaskNativeSession.js';
|
|
10
13
|
export type FliwrightLogFormat = 'pretty' | 'compact' | 'jsonl' | 'silent';
|
|
11
14
|
export type FliwrightLogOutput = 'stderr' | 'stdout' | 'file' | 'jsonl-file';
|
|
12
15
|
export interface FliwrightLogConfig {
|
|
@@ -17,6 +20,7 @@ export interface FliwrightLogConfig {
|
|
|
17
20
|
jsonlPath?: string;
|
|
18
21
|
}
|
|
19
22
|
export interface FliwrightConfig {
|
|
23
|
+
native?: NativeConfig;
|
|
20
24
|
vmServiceUrl: string;
|
|
21
25
|
plugins?: FliwrightPlugin[];
|
|
22
26
|
timeout?: number;
|
|
@@ -43,7 +47,7 @@ export declare function defineConfig(overrides: Partial<FliwrightConfig> & {
|
|
|
43
47
|
/**
|
|
44
48
|
* Decide where run artifacts go for a fliwright test run.
|
|
45
49
|
* Precedence is implemented by @fliwright/core:
|
|
46
|
-
* explicit config.runsRoot > FLIWRIGHT_RUNS_ROOT env >
|
|
50
|
+
* explicit config.runsRoot > FLIWRIGHT_RUNS_ROOT env > machine-local project partition.
|
|
47
51
|
*/
|
|
48
52
|
export declare function resolveRunsRoot(config: {
|
|
49
53
|
runsRoot?: string;
|
|
@@ -63,6 +67,10 @@ interface FliwrightTimelineContext {
|
|
|
63
67
|
runSession?: import('@fliwright/core').RunSession;
|
|
64
68
|
}
|
|
65
69
|
export interface FliwrightFixtures {
|
|
70
|
+
cameraTest: CameraTestController;
|
|
71
|
+
biometricTest: BiometricTestController;
|
|
72
|
+
native: NativePage;
|
|
73
|
+
device: DeviceController;
|
|
66
74
|
driver: FliwrightDriver;
|
|
67
75
|
page: Page;
|
|
68
76
|
aiRuntime: AiRuntime;
|
|
@@ -74,14 +82,19 @@ export interface FliwrightFixtures {
|
|
|
74
82
|
logger: FliwrightLogger;
|
|
75
83
|
}
|
|
76
84
|
export type FliwrightTest = TestAPI<FliwrightFixtures>;
|
|
77
|
-
|
|
85
|
+
/** Vitest registration API with a named environment selected, including for/each and modifiers. */
|
|
86
|
+
export type ScenarioTest<TFixtures extends FliwrightFixtures = FliwrightFixtures> = TestAPI<TFixtures>;
|
|
78
87
|
export interface ScenarioEnabledFliwrightTest<TFixtures extends FliwrightFixtures = FliwrightFixtures> extends TestAPI<TFixtures> {
|
|
79
88
|
scenario(name: string): ScenarioTest<TFixtures>;
|
|
80
89
|
}
|
|
81
90
|
export type FliwrightProjectFixtures = Record<string, (fixtures: FliwrightFixtures, use: (value: unknown) => Promise<void>) => Promise<void>>;
|
|
82
91
|
export interface CreateFliwrightTestOptions {
|
|
92
|
+
/** Custom platform integration; the provider must verify VM/device process binding. */
|
|
93
|
+
nativeDeviceProvider?: NativeDeviceProvider;
|
|
83
94
|
/** When set, fixtures use this driver instead of the worker's endpoint-specific cache. */
|
|
84
|
-
driverProvider?: (
|
|
95
|
+
driverProvider?: (context: {
|
|
96
|
+
vmServiceUrl: string;
|
|
97
|
+
}) => Promise<FliwrightDriver>;
|
|
85
98
|
}
|
|
86
99
|
export declare function createFliwrightTest(config: FliwrightConfig, options?: CreateFliwrightTestOptions): ScenarioEnabledFliwrightTest;
|
|
87
100
|
export declare function extendFliwrightTest<TProjectFixtures extends Record<string, unknown>, TBaseFixtures extends FliwrightFixtures = FliwrightFixtures>(base: TestAPI<TBaseFixtures>, fixtures: {
|
|
@@ -93,4 +106,5 @@ export declare const script: ScenarioEnabledFliwrightTest<FliwrightFixtures>;
|
|
|
93
106
|
export declare function beforeEach(hook: FliwrightHook, timeout?: number): void;
|
|
94
107
|
export declare function afterEach(hook: FliwrightHook, timeout?: number): void;
|
|
95
108
|
export { afterAll, beforeAll, describe };
|
|
109
|
+
export declare function expect(locator: NativeLocator, title?: string): NativeAssertion;
|
|
96
110
|
export declare function expect(locator: Locator, title?: string): Assertion;
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,13 @@ import { afterAll, afterEach as vitestAfterEach, beforeAll, beforeEach as vitest
|
|
|
2
2
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
3
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join, resolve } from 'node:path';
|
|
5
|
-
import { AgentRuntime, AssertRuntime, AiRuntime, Assertion, FileLogSink, FliwrightDriver, FlowRuntime, JsonlLogSink, MockRuntime, PassiveAgent, Page as FliwrightPage, PrettyLogFormatter, readWorkspaceConfigSync, resolveFliwrightRunsRoot, resolveFliwrightCacheRoot, resolveFliwrightProjectRoot, StructuredLogger, RunArtifactStore, EvidenceCapture, createExpect, resolveAiConfig, ScenarioCoordinator, ScenarioResolver, fingerprintScenario, DEFAULT_FLIWRIGHT_CONFIG, EndpointLeaseManager, mergeFliwrightConfig, readFliwrightEnvironment, } from '@fliwright/core';
|
|
5
|
+
import { AgentRuntime, AssertRuntime, AiRuntime, Assertion, FileLogSink, FliwrightDriver, FlowRuntime, JsonlLogSink, MockRuntime, PassiveAgent, Page as FliwrightPage, PrettyLogFormatter, readWorkspaceConfigSync, resolveFliwrightRunsRoot, resolveFliwrightCacheRoot, resolveFliwrightProjectRoot, StructuredLogger, RunArtifactStore, EvidenceCapture, createExpect, resolveAiConfig, ScenarioCoordinator, ScenarioResolver, fingerprintScenario, DEFAULT_FLIWRIGHT_CONFIG, EndpointLeaseManager, mergeFliwrightConfig, readFliwrightEnvironment, NativeLocator, CameraTestController, BiometricTestController, } from '@fliwright/core';
|
|
6
6
|
import { requireAttemptContext } from './AttemptContext.js';
|
|
7
|
-
import { getTaskEndpointLease, setTaskEndpointLease, finishTaskEndpointLeasePhase } from './TaskEndpointLease.js';
|
|
7
|
+
import { getTaskEndpointLease, setTaskEndpointLease, finishTaskEndpointLeasePhase, resetTaskOwnershipPhases } from './TaskEndpointLease.js';
|
|
8
8
|
import { withTaskPreparation } from './TestRegistration.js';
|
|
9
|
+
import { prepareTaskNativeSession, taskNativeRuntime, verifyTaskNativeBinding } from './TaskNativeSession.js';
|
|
10
|
+
import { prepareTaskDeviceScenario, taskScenario, taskScenarioKey, validateTaskDeviceScenario } from './TaskScenarioPreparation.js';
|
|
11
|
+
import { prepareTaskManagedApp } from './TaskManagedApp.js';
|
|
9
12
|
export { FliwrightRunner, createFliwrightRunner } from './runner.js';
|
|
10
13
|
export { fliwrightPreset } from './preset.js';
|
|
11
14
|
export { FliwrightRecoveryReporter } from './RecoveryReporter.js';
|
|
@@ -20,7 +23,7 @@ export function defineConfig(overrides) {
|
|
|
20
23
|
/**
|
|
21
24
|
* Decide where run artifacts go for a fliwright test run.
|
|
22
25
|
* Precedence is implemented by @fliwright/core:
|
|
23
|
-
* explicit config.runsRoot > FLIWRIGHT_RUNS_ROOT env >
|
|
26
|
+
* explicit config.runsRoot > FLIWRIGHT_RUNS_ROOT env > machine-local project partition.
|
|
24
27
|
*/
|
|
25
28
|
export function resolveRunsRoot(config) {
|
|
26
29
|
return resolveFliwrightRunsRoot({
|
|
@@ -35,19 +38,57 @@ const pluginIds = new WeakMap();
|
|
|
35
38
|
const testContext = new AsyncLocalStorage();
|
|
36
39
|
let currentTestContext = null;
|
|
37
40
|
const scenarioConfigs = new WeakMap();
|
|
41
|
+
const nativeProviders = new WeakMap();
|
|
38
42
|
export function createFliwrightTest(config, options) {
|
|
39
43
|
// Persistent Vitest workers reuse fixture modules across reruns. Resolve
|
|
40
44
|
// process settings at fixture use so a new run does not retain the old root.
|
|
41
45
|
const resolveConfig = () => ({ ...config,
|
|
42
46
|
...mergeFliwrightConfig({ environment: readFliwrightEnvironment(process.env), explicit: config }),
|
|
43
47
|
});
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
const taskConfig = (task) => {
|
|
49
|
+
const config = resolveConfig();
|
|
50
|
+
const endpoint = requireAttemptContext(task).managedApp;
|
|
51
|
+
return endpoint ? { ...config, vmServiceUrl: endpoint.url } : config;
|
|
52
|
+
};
|
|
53
|
+
const resolveDriver = (task) => {
|
|
54
|
+
const attempt = requireAttemptContext(task);
|
|
55
|
+
const connect = () => options?.driverProvider
|
|
56
|
+
? options.driverProvider({ vmServiceUrl: taskConfig(task).vmServiceUrl })
|
|
57
|
+
: getSharedDriver(taskConfig(task), !!attempt.managedApp);
|
|
58
|
+
if (!attempt.managedApp)
|
|
59
|
+
return connect();
|
|
60
|
+
if (!attempt.managedAppDriver) {
|
|
61
|
+
const pending = attempt.managedAppDriver = connect();
|
|
62
|
+
attempt.cleanupManagedAppDriver = async (signal) => {
|
|
63
|
+
const driver = await pending.catch(() => undefined);
|
|
64
|
+
if (driver)
|
|
65
|
+
await driver.dispose({ signal });
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return attempt.managedAppDriver;
|
|
69
|
+
};
|
|
47
70
|
let fliwrightTest = vitestTest.extend({
|
|
71
|
+
_fliwrightNativeReadback: [async ({ task, timeline }, use) => {
|
|
72
|
+
const attempt = requireAttemptContext(task);
|
|
73
|
+
if (attempt.managedApp?.nativeApp) {
|
|
74
|
+
const scenario = taskScenario(task, resolveConfig());
|
|
75
|
+
await verifyTaskNativeBinding(task, await resolveDriver(task), attempt.attemptId, scenario);
|
|
76
|
+
}
|
|
77
|
+
void timeline;
|
|
78
|
+
await use(undefined);
|
|
79
|
+
}, { auto: true }],
|
|
48
80
|
_fliwrightEndpointLease: [async ({ task }, use) => {
|
|
49
81
|
await requireAttemptContext(task).beforeFixtures?.();
|
|
50
|
-
|
|
82
|
+
resetTaskOwnershipPhases(task);
|
|
83
|
+
await prepareTaskManagedApp(task, taskScenario(task, resolveConfig()), resolveConfig().scenarioMode, task.context.signal, resolveConfig().native?.enabled);
|
|
84
|
+
await prepareTaskDeviceScenario(task, taskScenario(task, resolveConfig()), resolveConfig(), task.context.signal);
|
|
85
|
+
if (resolveConfig().native?.enabled) {
|
|
86
|
+
const attempt = requireAttemptContext(task);
|
|
87
|
+
await taskNativeRuntime(task, attempt.session, attempt.attemptId);
|
|
88
|
+
}
|
|
89
|
+
const endpoint = taskConfig(task).vmServiceUrl.trim();
|
|
90
|
+
if (endpoint && !getTaskEndpointLease(task))
|
|
91
|
+
setTaskEndpointLease(task, await endpointLeases.acquire(endpoint, { signal: task.context.signal }));
|
|
51
92
|
if (endpoint && getTaskEndpointLease(task)) {
|
|
52
93
|
// A retry retains ownership but starts a fresh fixture lifecycle.
|
|
53
94
|
setTaskEndpointLease(task, getTaskEndpointLease(task));
|
|
@@ -71,8 +112,9 @@ export function createFliwrightTest(config, options) {
|
|
|
71
112
|
}
|
|
72
113
|
}
|
|
73
114
|
}, { auto: true }],
|
|
74
|
-
timeline: async ({ task }, use) => {
|
|
75
|
-
|
|
115
|
+
timeline: async ({ task, _fliwrightEndpointLease }, use) => {
|
|
116
|
+
void _fliwrightEndpointLease;
|
|
117
|
+
const config = taskConfig(task);
|
|
76
118
|
const testName = getTestName(task);
|
|
77
119
|
const attempt = requireAttemptContext(task);
|
|
78
120
|
const cwd = config.projectRoot ?? process.env.FLIWRIGHT_PROJECT_ROOT ?? config.timelineDir ?? resolveFliwrightProjectRoot();
|
|
@@ -92,13 +134,19 @@ export function createFliwrightTest(config, options) {
|
|
|
92
134
|
}
|
|
93
135
|
const timeline = { recorder: attempt.recorder,
|
|
94
136
|
artifactStore: attempt.artifactStore, runId: attempt.runId, logger, runSession: attempt.session };
|
|
137
|
+
if (config.native?.enabled) {
|
|
138
|
+
const runtime = await taskNativeRuntime(task, attempt.session, attempt.attemptId);
|
|
139
|
+
runtime.configureEvidence({ artifactStore: attempt.artifactStore,
|
|
140
|
+
timeoutMs: config.recording?.failureCaptureBudgetMs ?? DEFAULT_FLIWRIGHT_CONFIG.recording.failureCaptureBudgetMs,
|
|
141
|
+
getSignal: () => attempt.finalizationSignal });
|
|
142
|
+
}
|
|
95
143
|
attempt.onFailure = async (error, node, signal) => {
|
|
96
144
|
await writeFailureProjection(timeline, error, node, config, signal);
|
|
97
145
|
if (!signal.aborted)
|
|
98
146
|
attempt.failureContextPath = 'failures.json';
|
|
99
147
|
};
|
|
100
148
|
if (config.agentPolicy?.passive === true && (config.agentPolicy.onFailure ?? 'diagnose') === 'diagnose') {
|
|
101
|
-
attempt.beforeFinish = (signal) => diagnoseTimelineFailures(timeline, config, resolveDriver, signal, () => Math.max(1, attempt.finalization.remainingMs - attempt.persistenceReserveMs));
|
|
149
|
+
attempt.beforeFinish = (signal) => diagnoseTimelineFailures(timeline, config, () => resolveDriver(task), signal, () => Math.max(1, attempt.finalization.remainingMs - attempt.persistenceReserveMs));
|
|
102
150
|
}
|
|
103
151
|
const ctx = testContext.getStore();
|
|
104
152
|
if (ctx)
|
|
@@ -118,7 +166,7 @@ export function createFliwrightTest(config, options) {
|
|
|
118
166
|
await use(timeline);
|
|
119
167
|
},
|
|
120
168
|
driver: async ({ task, timeline }, use) => {
|
|
121
|
-
const driver = await resolveDriver();
|
|
169
|
+
const driver = await resolveDriver(task);
|
|
122
170
|
timeline.driver = driver;
|
|
123
171
|
const testName = getTestName(task);
|
|
124
172
|
const previous = currentTestContext;
|
|
@@ -126,6 +174,9 @@ export function createFliwrightTest(config, options) {
|
|
|
126
174
|
currentTestContext = ctx;
|
|
127
175
|
let useFailed = false;
|
|
128
176
|
try {
|
|
177
|
+
const scenario = taskScenario(task, resolveConfig());
|
|
178
|
+
driver.clearDiagnostics?.();
|
|
179
|
+
await verifyTaskNativeBinding(task, driver, requireAttemptContext(task).attemptId, scenario);
|
|
129
180
|
await testContext.run(ctx, async () => {
|
|
130
181
|
await use(driver);
|
|
131
182
|
});
|
|
@@ -136,7 +187,7 @@ export function createFliwrightTest(config, options) {
|
|
|
136
187
|
}
|
|
137
188
|
finally {
|
|
138
189
|
currentTestContext = previous;
|
|
139
|
-
if (options?.driverProvider) {
|
|
190
|
+
if (options?.driverProvider && !requireAttemptContext(task).managedApp) {
|
|
140
191
|
const attempt = requireAttemptContext(task);
|
|
141
192
|
try {
|
|
142
193
|
// Calling dispose even after an earlier stage exhausts its budget
|
|
@@ -156,6 +207,66 @@ export function createFliwrightTest(config, options) {
|
|
|
156
207
|
}
|
|
157
208
|
}
|
|
158
209
|
},
|
|
210
|
+
native: async ({ task, timeline, driver }, use) => {
|
|
211
|
+
void driver;
|
|
212
|
+
const attempt = requireAttemptContext(task);
|
|
213
|
+
await use((await taskNativeRuntime(task, attempt.session, attempt.attemptId)).native);
|
|
214
|
+
},
|
|
215
|
+
device: async ({ task, timeline, driver }, use) => {
|
|
216
|
+
void driver;
|
|
217
|
+
const attempt = requireAttemptContext(task);
|
|
218
|
+
await use((await taskNativeRuntime(task, attempt.session, attempt.attemptId)).device);
|
|
219
|
+
},
|
|
220
|
+
cameraTest: async ({ task, driver, timeline }, use) => {
|
|
221
|
+
const camera = await CameraTestController.create(driver.app, { runSession: timeline.runSession });
|
|
222
|
+
const errors = [];
|
|
223
|
+
try {
|
|
224
|
+
await use(camera);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
errors.push(error);
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const attempt = requireAttemptContext(task);
|
|
231
|
+
await attempt.finalization.run('Camera test cleanup', signal => camera.dispose({ signal }), attempt.persistenceReserveMs);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
errors.push(error);
|
|
235
|
+
if (task.result) {
|
|
236
|
+
task.result.state = 'fail';
|
|
237
|
+
delete task.result.pending;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (errors.length === 1)
|
|
241
|
+
throw errors[0];
|
|
242
|
+
if (errors.length)
|
|
243
|
+
throw new AggregateError(errors, 'Camera test body and cleanup failed.');
|
|
244
|
+
},
|
|
245
|
+
biometricTest: async ({ task, driver, timeline }, use) => {
|
|
246
|
+
const biometric = await BiometricTestController.create(driver.app, { runSession: timeline.runSession, signal: task.context.signal });
|
|
247
|
+
const errors = [];
|
|
248
|
+
try {
|
|
249
|
+
await use(biometric);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
errors.push(error);
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
const attempt = requireAttemptContext(task);
|
|
256
|
+
await attempt.finalization.run('Biometric test cleanup', signal => biometric.dispose({ signal }), attempt.persistenceReserveMs);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
errors.push(error);
|
|
260
|
+
if (task.result) {
|
|
261
|
+
task.result.state = 'fail';
|
|
262
|
+
delete task.result.pending;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (errors.length === 1)
|
|
266
|
+
throw errors[0];
|
|
267
|
+
if (errors.length)
|
|
268
|
+
throw new AggregateError(errors, 'Biometric test body and cleanup failed.');
|
|
269
|
+
},
|
|
159
270
|
page: async ({ task, timeline, driver }, use) => {
|
|
160
271
|
const config = resolveConfig();
|
|
161
272
|
timeline.driver = driver;
|
|
@@ -228,23 +339,36 @@ export function createFliwrightTest(config, options) {
|
|
|
228
339
|
const selected = resolveConfig().defaultScenario;
|
|
229
340
|
if (selected) {
|
|
230
341
|
fliwrightTest = fliwrightTest.extend({
|
|
231
|
-
_fliwrightDefaultScenario: [async ({ driver, timeline }, use) => {
|
|
342
|
+
_fliwrightDefaultScenario: [async ({ task, driver, timeline }, use) => {
|
|
232
343
|
const selectedScenario = new ScenarioResolver(resolveConfig().scenarios ?? {}).resolve(selected);
|
|
233
344
|
const node = timeline.recorder.startNode('step', `Scenario: ${selected}`);
|
|
234
|
-
|
|
235
|
-
|
|
345
|
+
const attempt = requireAttemptContext(task);
|
|
346
|
+
const report = await new ScenarioCoordinator(driver).apply(selectedScenario, { mode: resolveConfig().scenarioMode ?? 'attach',
|
|
347
|
+
attemptId: attempt.attemptId, devicePreparation: attempt.devicePreparation });
|
|
348
|
+
timeline.recorder.passNode(node.id, { scenarioName: selected, scenarioFingerprint: fingerprintScenario(selectedScenario),
|
|
349
|
+
...(report.mocks ? { mockRuleSet: report.mocks } : {}),
|
|
350
|
+
...(report.device ? { devicePreparation: report.device } : {}) });
|
|
236
351
|
await use(undefined);
|
|
237
352
|
}, { auto: true }],
|
|
238
353
|
});
|
|
239
354
|
}
|
|
240
|
-
return withScenarioSupport(fliwrightTest, resolveConfig);
|
|
355
|
+
return withScenarioSupport(fliwrightTest, resolveConfig, options?.nativeDeviceProvider);
|
|
241
356
|
}
|
|
242
|
-
function withScenarioSupport(test, resolveConfig) {
|
|
357
|
+
function withScenarioSupport(test, resolveConfig, nativeDeviceProvider) {
|
|
243
358
|
const prepare = async (task, signal) => {
|
|
244
359
|
const config = resolveConfig();
|
|
360
|
+
const scenario = taskScenario(task, config);
|
|
361
|
+
validateTaskDeviceScenario(scenario, config.native);
|
|
245
362
|
requireAttemptContext(task).configureRecordingPolicy({ recordingMode: config.recording?.mode,
|
|
246
363
|
testFinalizationBudgetMs: config.recording?.testFinalizationBudgetMs });
|
|
247
|
-
|
|
364
|
+
await prepareTaskNativeSession(task, config.native, signal, nativeDeviceProvider);
|
|
365
|
+
await prepareTaskManagedApp(task, scenario, config.scenarioMode, signal, config.native?.enabled);
|
|
366
|
+
if (config.native?.enabled) {
|
|
367
|
+
const attempt = requireAttemptContext(task);
|
|
368
|
+
await taskNativeRuntime(task, attempt.session, attempt.attemptId);
|
|
369
|
+
}
|
|
370
|
+
await prepareTaskDeviceScenario(task, scenario, config, signal);
|
|
371
|
+
const endpoint = (requireAttemptContext(task).managedApp?.url ?? config.vmServiceUrl).trim();
|
|
248
372
|
if (endpoint && !getTaskEndpointLease(task)) {
|
|
249
373
|
const lease = await endpointLeases.acquire(endpoint, { signal: AbortSignal.any([signal, task.context.signal]) });
|
|
250
374
|
if (signal.aborted) {
|
|
@@ -256,12 +380,13 @@ function withScenarioSupport(test, resolveConfig) {
|
|
|
256
380
|
};
|
|
257
381
|
const scenarioTest = withTaskPreparation(test, prepare);
|
|
258
382
|
scenarioConfigs.set(scenarioTest, resolveConfig);
|
|
383
|
+
nativeProviders.set(scenarioTest, nativeDeviceProvider);
|
|
259
384
|
scenarioTest.scenario = (scenarioName) => {
|
|
260
385
|
const config = resolveConfig();
|
|
261
386
|
if (config.defaultScenario && config.defaultScenario !== scenarioName)
|
|
262
387
|
throw new Error(`Explicit scenario '${scenarioName}' conflicts with selected scenario '${config.defaultScenario}'.`);
|
|
263
388
|
if (config.defaultScenario === scenarioName)
|
|
264
|
-
return
|
|
389
|
+
return scenarioTest;
|
|
265
390
|
const scenarios = config.scenarios;
|
|
266
391
|
if (!scenarios) {
|
|
267
392
|
throw new Error(`Test scenario '${scenarioName}' was requested, but defineConfig({ scenarios }) is missing.`);
|
|
@@ -270,20 +395,26 @@ function withScenarioSupport(test, resolveConfig) {
|
|
|
270
395
|
// The automatic fixture adds preparation without wrapping the handler, so
|
|
271
396
|
// Vitest still discovers and lazily injects its project fixture dependencies.
|
|
272
397
|
const prepared = scenarioTest.extend({
|
|
273
|
-
_fliwrightScenario: [async ({ driver, timeline }, use) => {
|
|
398
|
+
_fliwrightScenario: [async ({ task, driver, timeline }, use) => {
|
|
274
399
|
const scenarioNode = timeline.recorder.startNode('step', `Scenario: ${scenarioName}`);
|
|
275
400
|
await timeline.recorder.flushProgress();
|
|
276
|
-
|
|
401
|
+
const attempt = requireAttemptContext(task);
|
|
402
|
+
const report = await new ScenarioCoordinator(driver).apply(scenario, {
|
|
277
403
|
mode: config.scenarioMode ?? 'attach',
|
|
404
|
+
attemptId: attempt.attemptId, devicePreparation: attempt.devicePreparation,
|
|
278
405
|
});
|
|
279
406
|
timeline.recorder.passNode(scenarioNode.id, {
|
|
280
407
|
scenarioName, scenarioFingerprint: fingerprintScenario(scenario),
|
|
408
|
+
...(report.mocks ? { mockRuleSet: report.mocks } : {}),
|
|
409
|
+
...(report.device ? { devicePreparation: report.device } : {}),
|
|
281
410
|
});
|
|
282
411
|
await timeline.recorder.flushProgress();
|
|
283
412
|
await use(undefined);
|
|
284
413
|
}, { auto: true }],
|
|
285
414
|
});
|
|
286
|
-
|
|
415
|
+
const meta = {};
|
|
416
|
+
Object.assign(meta, { [taskScenarioKey]: scenario });
|
|
417
|
+
return withTaskPreparation(prepared, prepare, meta);
|
|
287
418
|
};
|
|
288
419
|
return scenarioTest;
|
|
289
420
|
}
|
|
@@ -292,7 +423,7 @@ export function extendFliwrightTest(base, fixtures) {
|
|
|
292
423
|
if (!resolveConfig)
|
|
293
424
|
throw new Error('extendFliwrightTest requires a base from createFliwrightTest or extendFliwrightTest.');
|
|
294
425
|
const extended = base.extend(fixtures);
|
|
295
|
-
return withScenarioSupport(extended, resolveConfig);
|
|
426
|
+
return withScenarioSupport(extended, resolveConfig, nativeProviders.get(base));
|
|
296
427
|
}
|
|
297
428
|
function configureRunSessionEvidence(timeline, page, config, getFinalizationSignal) {
|
|
298
429
|
const session = timeline.runSession;
|
|
@@ -301,36 +432,33 @@ function configureRunSessionEvidence(timeline, page, config, getFinalizationSign
|
|
|
301
432
|
const mode = config.recording?.mode ?? parseRecordingMode(process.env.FLIWRIGHT_RECORDING_MODE) ?? 'standard';
|
|
302
433
|
const budget = config.recording?.failureCaptureBudgetMs ?? DEFAULT_FLIWRIGHT_CONFIG.recording.failureCaptureBudgetMs;
|
|
303
434
|
const capture = new EvidenceCapture({ totalBudgetMs: budget, channelTimeoutMs: budget / 3 });
|
|
304
|
-
session.
|
|
305
|
-
mode
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return { status: channel.status, ...(artifact ? { artifactPaths: [artifact.path] } : {}),
|
|
332
|
-
...(channel.error ? { error: channel.error } : {}) };
|
|
333
|
-
},
|
|
435
|
+
session.registerEvidenceProvider('flutter', async (request) => {
|
|
436
|
+
if (mode === 'off' && request.reason !== 'explicit')
|
|
437
|
+
return { status: 'disabled' };
|
|
438
|
+
const signal = getFinalizationSignal();
|
|
439
|
+
const suffix = `${request.operationId ?? 'checkpoint'}-${request.reason}`;
|
|
440
|
+
const sources = {
|
|
441
|
+
screenshot: async () => {
|
|
442
|
+
const screenshot = await page.screenshot({ waitForAnimations: true });
|
|
443
|
+
signal?.throwIfAborted();
|
|
444
|
+
return timeline.artifactStore.writeScreenshot(suffix, screenshot);
|
|
445
|
+
},
|
|
446
|
+
snapshot: async () => {
|
|
447
|
+
const snapshot = await page.snapshot();
|
|
448
|
+
signal?.throwIfAborted();
|
|
449
|
+
return timeline.artifactStore.writeSnapshot(suffix, snapshot);
|
|
450
|
+
},
|
|
451
|
+
diagnostics: async () => {
|
|
452
|
+
const frame = await page.captureFrame({ screenshot: false, snapshot: false, diagnostics: true });
|
|
453
|
+
signal?.throwIfAborted();
|
|
454
|
+
return timeline.artifactStore.writeDiagnostics(suffix, frame.diagnostics ?? frame);
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
const result = await capture.capture(request.reason === 'failure' ? suffix : `${suffix}-${request.kind}`, request.reason === 'failure' ? sources : { [request.kind]: sources[request.kind] }, { signal });
|
|
458
|
+
const channel = result.channels[request.kind];
|
|
459
|
+
const artifact = channel.value;
|
|
460
|
+
return { status: channel.status, ...(artifact ? { artifactPaths: [artifact.path] } : {}),
|
|
461
|
+
...(channel.error ? { error: channel.error } : {}) };
|
|
334
462
|
});
|
|
335
463
|
}
|
|
336
464
|
async function captureTestLifecycleScreenshot(timeline, page, reason, signal) {
|
|
@@ -363,6 +491,8 @@ export function afterEach(hook, timeout) {
|
|
|
363
491
|
}
|
|
364
492
|
export { afterAll, beforeAll, describe };
|
|
365
493
|
export function expect(locator, title) {
|
|
494
|
+
if (locator instanceof NativeLocator)
|
|
495
|
+
return locator.expect(title);
|
|
366
496
|
const context = testContext.getStore() ?? currentTestContext;
|
|
367
497
|
const locatorTimeline = locator.assertionTimeline;
|
|
368
498
|
if (!context)
|
|
@@ -389,6 +519,7 @@ async function writeFailureProjection(timeline, error, node, config, signal) {
|
|
|
389
519
|
const [snapshot, diagnostics] = await Promise.all([readArtifact('snapshot'), readArtifact('diagnostics')]);
|
|
390
520
|
if (signal.aborted)
|
|
391
521
|
return;
|
|
522
|
+
const dartDiagnostics = timeline.driver?.getDiagnostics({ limit: 50, streams: ['Logging', 'Stderr', 'Isolate'] }) ?? [];
|
|
392
523
|
const screenshot = node.artifacts?.find((artifact) => artifact.kind === 'screenshot');
|
|
393
524
|
const original = error;
|
|
394
525
|
const lines = original.stack?.split('\n') ?? [];
|
|
@@ -409,6 +540,7 @@ async function writeFailureProjection(timeline, error, node, config, signal) {
|
|
|
409
540
|
assertion: { matcher: 'unknown', expected: 'pass', actual: original.message ?? String(error), timeout: config.timeout ?? 5000 },
|
|
410
541
|
widgetTree: snapshot ? JSON.parse(snapshot.toString()) : { error: 'Evidence unavailable' },
|
|
411
542
|
...(diagnostics ? { diagnostics: JSON.parse(diagnostics.toString()) } : {}),
|
|
543
|
+
...(dartDiagnostics.length ? { dartDiagnostics } : {}),
|
|
412
544
|
source: { file: source?.file ?? '<unknown>', line: source?.line ?? 0, snippet: original.message ?? String(error) },
|
|
413
545
|
...(screenshot && config.screenshot !== 'off' ? { screenshot: { mimeType: 'image/png', path: screenshot.path } } : {}),
|
|
414
546
|
timestamp: node.startedAt,
|
|
@@ -420,7 +552,7 @@ async function writeFailureProjection(timeline, error, node, config, signal) {
|
|
|
420
552
|
entries.push(timeline.runSession?.redactReport(entry) ?? entry);
|
|
421
553
|
await writeFile(outputPath, JSON.stringify(entries, null, 2), { signal });
|
|
422
554
|
}
|
|
423
|
-
async function getSharedDriver(config) {
|
|
555
|
+
async function getSharedDriver(config, fresh = false) {
|
|
424
556
|
const vmServiceUrl = toWebSocketUrl(config.vmServiceUrl);
|
|
425
557
|
if (!vmServiceUrl) {
|
|
426
558
|
throw new Error('No VM Service URL provided. Set FLIWRIGHT_VM_URL or FLIWRIGHT_VM_SERVICE_URL, or use createFliwrightTest({ vmServiceUrl }).');
|
|
@@ -428,7 +560,7 @@ async function getSharedDriver(config) {
|
|
|
428
560
|
const cacheRoot = resolveFliwrightCacheRoot({ cacheRoot: config.cacheRoot,
|
|
429
561
|
projectRoot: config.projectRoot ?? process.env.FLIWRIGHT_PROJECT_ROOT });
|
|
430
562
|
const key = `${sharedDriverCacheKey(vmServiceUrl, config.plugins)}:${cacheRoot}`;
|
|
431
|
-
let pending = sharedDrivers.get(key);
|
|
563
|
+
let pending = fresh ? undefined : sharedDrivers.get(key);
|
|
432
564
|
if (!pending) {
|
|
433
565
|
pending = (async () => {
|
|
434
566
|
const driver = new FliwrightDriver({ plugins: config.plugins, cacheRoot });
|
|
@@ -442,7 +574,8 @@ async function getSharedDriver(config) {
|
|
|
442
574
|
throw error;
|
|
443
575
|
}
|
|
444
576
|
})();
|
|
445
|
-
|
|
577
|
+
if (!fresh)
|
|
578
|
+
sharedDrivers.set(key, pending);
|
|
446
579
|
}
|
|
447
580
|
try {
|
|
448
581
|
return await pending;
|
package/dist/preset.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { FliwrightPathsConfig, FliwrightRecordingConfig, ScenarioExecutionMode, TestScenario } from '@fliwright/core';
|
|
1
|
+
import type { FliwrightPathsConfig, FliwrightRecordingConfig, ScenarioExecutionMode, TestScenario, NativeConfig, SupportSettingsDefinition } from '@fliwright/core';
|
|
2
2
|
export interface FliwrightVitestPresetOptions {
|
|
3
|
+
native?: NativeConfig;
|
|
4
|
+
supportSettings?: readonly SupportSettingsDefinition[];
|
|
3
5
|
runner?: string;
|
|
4
6
|
test?: Record<string, unknown>;
|
|
5
7
|
recording?: Partial<FliwrightRecordingConfig>;
|
package/dist/preset.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import { mergeFliwrightConfig, readFliwrightEnvironment, resolveFliwrightProjectRoot, resolveFliwrightRunsRoot, resolveFliwrightCacheRoot } from '@fliwright/core';
|
|
2
|
+
import { mergeFliwrightConfig, readFliwrightEnvironment, resolveFliwrightProjectRoot, resolveFliwrightRunsRoot, resolveFliwrightCacheRoot, writeFliwrightConfigSnapshot } from '@fliwright/core';
|
|
3
3
|
/** Returns a Vitest config fragment using the built Fliwright runner adapter. */
|
|
4
4
|
export function fliwrightPreset(options = {}) {
|
|
5
|
-
const config = mergeFliwrightConfig({ project: options, environment: readFliwrightEnvironment(process.env) });
|
|
6
5
|
const projectRoot = options.projectRoot ?? process.env.FLIWRIGHT_PROJECT_ROOT ?? resolveFliwrightProjectRoot();
|
|
7
|
-
config
|
|
6
|
+
const config = mergeFliwrightConfig({ project: options, environment: readFliwrightEnvironment(process.env), projectRoot });
|
|
7
|
+
config.runsRoot = resolveFliwrightRunsRoot({ projectRoot, runsRoot: config.runsRoot, env: process.env });
|
|
8
8
|
config.cacheRoot = resolveFliwrightCacheRoot({ projectRoot, cacheRoot: config.cacheRoot });
|
|
9
9
|
const reporters = options.test?.reporters ?? ['default'];
|
|
10
10
|
const env = {
|
|
11
11
|
FLIWRIGHT_PROJECT_ROOT: projectRoot,
|
|
12
|
-
|
|
12
|
+
FLIWRIGHT_CONFIG_PATH: writeFliwrightConfigSnapshot(config, { projectRoot, cacheRoot: config.cacheRoot }),
|
|
13
13
|
FLIWRIGHT_RECORDING_MODE: config.recording.mode,
|
|
14
14
|
...(config.runsRoot ? { FLIWRIGHT_RUNS_ROOT: config.runsRoot } : {}),
|
|
15
15
|
};
|
package/dist/runner.js
CHANGED
|
@@ -4,8 +4,10 @@ import { appendFile } from 'node:fs/promises';
|
|
|
4
4
|
import { relative } from 'node:path';
|
|
5
5
|
import { RunSession, registerRunSession, unregisterRunSession } from '@fliwright/core';
|
|
6
6
|
import { AttemptContext, setAttemptContext } from './AttemptContext.js';
|
|
7
|
-
import { releaseTaskEndpointLease, finishTaskEndpointLeasePhase } from './TaskEndpointLease.js';
|
|
7
|
+
import { releaseTaskEndpointLease, finishTaskEndpointLeasePhase, setTaskOwnershipErrorHandler } from './TaskEndpointLease.js';
|
|
8
8
|
import { prepareRegisteredTask } from './TestRegistration.js';
|
|
9
|
+
import { disposeTaskNativeAttempt, hasTaskNativeRuntime, quarantineTaskNativeSession } from './TaskNativeSession.js';
|
|
10
|
+
import { blockTaskManagedApp } from './TaskManagedApp.js';
|
|
9
11
|
/** Compose the lifecycle with an existing VitestTestRunner subclass, retaining its constructor and hooks.
|
|
10
12
|
* The base runner must call its own Vitest super hooks to preserve assertion/snapshot semantics.
|
|
11
13
|
*/
|
|
@@ -81,6 +83,7 @@ export function createFliwrightRunner(BaseRunner) {
|
|
|
81
83
|
await context?.captureRunnerFailures(task, 'setup-or-body');
|
|
82
84
|
}
|
|
83
85
|
await this.finishAttempt(task, outcome);
|
|
86
|
+
await releaseTaskEndpointLease(task);
|
|
84
87
|
await this.finalizeTask(task, outcome);
|
|
85
88
|
}
|
|
86
89
|
finally {
|
|
@@ -149,13 +152,8 @@ export function createFliwrightRunner(BaseRunner) {
|
|
|
149
152
|
record.context.runnerEntered = false;
|
|
150
153
|
// Runtime skip returns before onAfterRunTask too.
|
|
151
154
|
if (record.observedStatus === 'skipped') {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
await this.finalizeTask(task, 'skipped');
|
|
155
|
-
}
|
|
156
|
-
finally {
|
|
157
|
-
await finishTaskEndpointLeasePhase(task, 'skipFinalized');
|
|
158
|
-
}
|
|
155
|
+
await this.finishAttempt(task, 'skipped');
|
|
156
|
+
await finishTaskEndpointLeasePhase(task, 'skipFinalized', () => this.finalizeTask(task, outcomeForTask(task)));
|
|
159
157
|
}
|
|
160
158
|
}
|
|
161
159
|
async onAfterRunTask(task) {
|
|
@@ -170,6 +168,7 @@ export function createFliwrightRunner(BaseRunner) {
|
|
|
170
168
|
: finalStatus;
|
|
171
169
|
await this.finishAttempt(task, observedStatus);
|
|
172
170
|
}
|
|
171
|
+
await releaseTaskEndpointLease(task);
|
|
173
172
|
await this.finalizeTask(task, outcomeForTask(task));
|
|
174
173
|
}
|
|
175
174
|
finally {
|
|
@@ -186,6 +185,25 @@ export function createFliwrightRunner(BaseRunner) {
|
|
|
186
185
|
testPath: sourceTestPath(task),
|
|
187
186
|
});
|
|
188
187
|
const context = new AttemptContext(session, runId, task.id, task.name, attemptId);
|
|
188
|
+
setTaskOwnershipErrorHandler(task, async (error) => {
|
|
189
|
+
const message = session.redactReport(error instanceof Error ? error.message : String(error));
|
|
190
|
+
task.result ??= { state: 'fail' };
|
|
191
|
+
task.result.state = 'fail';
|
|
192
|
+
// Vitest applies a pending skip after fixture teardown, even if teardown
|
|
193
|
+
// changed state to fail. Cleanup failure must survive that projection.
|
|
194
|
+
delete task.result.pending;
|
|
195
|
+
(task.result.errors ??= []).push({ name: 'OwnershipCleanupError', message });
|
|
196
|
+
context.recordEvidenceIssue(error);
|
|
197
|
+
context.runnerErrors.push({ message, phase: 'teardown' });
|
|
198
|
+
const result = this.completed.get(task.id)?.at(-1)?.result ?? task.fliwrightSessionResult;
|
|
199
|
+
if (result) {
|
|
200
|
+
result.status = result.attemptOutcome = result.testOutcome = 'failed';
|
|
201
|
+
if (result.evidenceStatus !== 'disabled')
|
|
202
|
+
result.evidenceStatus = 'partial';
|
|
203
|
+
result.runnerErrors = [...context.runnerErrors];
|
|
204
|
+
await context.persist(result, result.finalized === true);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
189
207
|
if (attemptIndex > 0)
|
|
190
208
|
context.ignorePriorFailures(task);
|
|
191
209
|
const record = { session, context, attemptIndex, started: false };
|
|
@@ -209,13 +227,8 @@ export function createFliwrightRunner(BaseRunner) {
|
|
|
209
227
|
await this.finishAttempt(task, active.observedStatus ?? 'failed');
|
|
210
228
|
await this.startAttempt(task, this.completed.get(task.id)?.length ?? 0);
|
|
211
229
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
await this.finalizeTask(task, 'skipped');
|
|
215
|
-
}
|
|
216
|
-
finally {
|
|
217
|
-
await finishTaskEndpointLeasePhase(task, 'skipFinalized');
|
|
218
|
-
}
|
|
230
|
+
await this.finishAttempt(task, 'skipped');
|
|
231
|
+
await finishTaskEndpointLeasePhase(task, 'skipFinalized', () => this.finalizeTask(task, outcomeForTask(task)));
|
|
219
232
|
};
|
|
220
233
|
this.active.set(task.id, record);
|
|
221
234
|
registerRunSession(task.id, session);
|
|
@@ -231,6 +244,41 @@ export function createFliwrightRunner(BaseRunner) {
|
|
|
231
244
|
if (record.context.beforeFinish) {
|
|
232
245
|
await record.context.finalizeStep('Passive diagnosis', (signal) => record.context.beforeFinish(signal));
|
|
233
246
|
}
|
|
247
|
+
if (record.context.cleanupManagedAppDriver)
|
|
248
|
+
try {
|
|
249
|
+
await record.context.finalization.run('Managed app connection cleanup', signal => record.context.cleanupManagedAppDriver(signal), record.context.persistenceReserveMs);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
status = 'failed';
|
|
253
|
+
if (task.type === 'test')
|
|
254
|
+
blockTaskManagedApp(task);
|
|
255
|
+
task.result ??= { state: 'fail' };
|
|
256
|
+
task.result.state = 'fail';
|
|
257
|
+
(task.result.errors ??= []).push({ name: 'ManagedAppCleanupError', message: error instanceof Error ? error.message : String(error) });
|
|
258
|
+
delete task.result.pending;
|
|
259
|
+
record.context.recordEvidenceIssue(error);
|
|
260
|
+
record.context.runnerErrors.push({ message: error instanceof Error ? error.message : String(error), phase: 'teardown' });
|
|
261
|
+
try {
|
|
262
|
+
await quarantineTaskNativeSession(task);
|
|
263
|
+
}
|
|
264
|
+
catch (cleanup) {
|
|
265
|
+
record.context.recordEvidenceIssue(cleanup);
|
|
266
|
+
record.context.runnerErrors.push({ message: cleanup instanceof Error ? cleanup.message : String(cleanup), phase: 'teardown' });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (hasTaskNativeRuntime(task))
|
|
270
|
+
try {
|
|
271
|
+
await record.context.finalization.run('Native attempt cleanup', () => disposeTaskNativeAttempt(task), record.context.persistenceReserveMs);
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
status = 'failed';
|
|
275
|
+
task.result ??= { state: 'fail' };
|
|
276
|
+
task.result.state = 'fail';
|
|
277
|
+
(task.result.errors ??= []).push({ name: 'NativeCleanupError', message: error instanceof Error ? error.message : String(error) });
|
|
278
|
+
delete task.result.pending;
|
|
279
|
+
record.context.recordEvidenceIssue(error);
|
|
280
|
+
record.context.runnerErrors.push({ message: error instanceof Error ? error.message : String(error), phase: 'teardown' });
|
|
281
|
+
}
|
|
234
282
|
const result = await record.session.finish({ status, evidenceStatus: 'complete' });
|
|
235
283
|
result.expectedFailure = isExpectedFailure(task);
|
|
236
284
|
if (record.context.evidenceErrors.length && result.evidenceStatus !== 'disabled')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fliwright/vitest",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Vitest fixtures and lifecycle integration for Fliwright Flutter E2E tests.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -47,10 +47,11 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"vitest": "5.0.5",
|
|
50
|
-
"@fliwright/core": "0.1.
|
|
50
|
+
"@fliwright/core": "0.1.1",
|
|
51
|
+
"@fliwright/native": "0.1.1"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@types/node": "^
|
|
54
|
+
"@types/node": "^26.0.1",
|
|
54
55
|
"typescript": "^5.5.0"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|