@midscene/test 1.12.6-beta-20260910093036.0 → 1.12.6
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/es/1~891.mjs +19 -39
- package/dist/es/1~891.mjs.map +1 -1
- package/dist/es/cli/index.mjs +26 -44
- package/dist/es/cli/index.mjs.map +1 -1
- package/dist/es/index.mjs +0 -3
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/midscene/index.mjs +43 -32
- package/dist/es/midscene/index.mjs.map +1 -1
- package/dist/es/test-cli.mjs +37 -49
- package/dist/es/test-cli.mjs.map +1 -1
- package/dist/lib/0~458.js +19 -39
- package/dist/lib/0~458.js.map +1 -1
- package/dist/lib/cli/index.js +26 -44
- package/dist/lib/cli/index.js.map +1 -1
- package/dist/lib/index.js +0 -3
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/midscene/index.js +253 -262
- package/dist/lib/midscene/index.js.map +1 -1
- package/dist/lib/test-cli.js +37 -49
- package/dist/lib/test-cli.js.map +1 -1
- package/dist/types/cli/index.d.ts +12 -13
- package/dist/types/index.d.ts +1 -7
- package/dist/types/midscene/index.d.ts +21 -21
- package/package.json +8 -48
- package/dist/es/android/index.mjs +0 -182
- package/dist/es/android/index.mjs.map +0 -1
- package/dist/es/harmony/index.mjs +0 -182
- package/dist/es/harmony/index.mjs.map +0 -1
- package/dist/es/ios/index.mjs +0 -182
- package/dist/es/ios/index.mjs.map +0 -1
- package/dist/es/playwright/index.mjs +0 -366
- package/dist/es/playwright/index.mjs.map +0 -1
- package/dist/lib/android/index.js +0 -255
- package/dist/lib/android/index.js.map +0 -1
- package/dist/lib/harmony/index.js +0 -252
- package/dist/lib/harmony/index.js.map +0 -1
- package/dist/lib/ios/index.js +0 -255
- package/dist/lib/ios/index.js.map +0 -1
- package/dist/lib/playwright/index.js +0 -412
- package/dist/lib/playwright/index.js.map +0 -1
- package/dist/types/android/index.d.ts +0 -140
- package/dist/types/harmony/index.d.ts +0 -137
- package/dist/types/ios/index.d.ts +0 -143
- package/dist/types/playwright/index.d.ts +0 -229
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommonAgentTestRunnerApi } from '@midscene/core/agent/test
|
|
1
|
+
import { CommonAgentTestRunnerApi } from '@midscene/core/agent/test';
|
|
2
2
|
import type { z } from 'zod/v4';
|
|
3
3
|
|
|
4
4
|
declare type Awaitable<T> = T | Promise<T>;
|
|
@@ -59,7 +59,7 @@ declare interface DefineNodeOptions<TInput = unknown, TData = unknown, TContext
|
|
|
59
59
|
/** Object field populated by string shorthand. Omit or set false to disable it. */
|
|
60
60
|
stringInputKey?: string | false;
|
|
61
61
|
inputSchema?: NodeInputSchema;
|
|
62
|
-
execute(
|
|
62
|
+
execute(execution: NodeExecutionContext<TInput, TContext>): NodeExecutionReturn<TData>;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
export declare const defineProjectSetup: <TProjectContext>(definition: ProjectSetupDefinition<TProjectContext>) => ProjectSetupDefinition<TProjectContext>;
|
|
@@ -74,8 +74,9 @@ declare type DocumentNodePhase = 'beforeAll' | 'afterAll';
|
|
|
74
74
|
|
|
75
75
|
export declare interface ExecutionProjectDefinition<TProjectContext = unknown> {
|
|
76
76
|
name: string;
|
|
77
|
-
platform: TestPlatform;
|
|
78
77
|
setup?: ProjectSetupDefinition<TProjectContext>;
|
|
78
|
+
/** Project-local Nodes override global Nodes with the same name. */
|
|
79
|
+
nodes?: readonly NodeDefinition<any, any, TProjectContext>[];
|
|
79
80
|
files?: TestFileSelection;
|
|
80
81
|
tags?: TestTagSelection;
|
|
81
82
|
retry?: number;
|
|
@@ -88,8 +89,13 @@ export declare type JsonValue = JsonPrimitive | readonly JsonValue[] | {
|
|
|
88
89
|
readonly [key: string]: JsonValue;
|
|
89
90
|
};
|
|
90
91
|
|
|
92
|
+
export declare interface LoadedExecutionProject<TProjectContext = unknown> extends ResolvedExecutionProject<TProjectContext> {
|
|
93
|
+
/** Effective Nodes: globals plus project-local overrides. */
|
|
94
|
+
readonly nodes: NodeRegistry;
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
export declare interface LoadedTestProject<TContext = undefined> {
|
|
92
|
-
projects: readonly
|
|
98
|
+
projects: readonly LoadedExecutionProject<TContext>[];
|
|
93
99
|
hasExplicitProjects: boolean;
|
|
94
100
|
test: ResolvedTestOptions;
|
|
95
101
|
output: ResolvedTestOutputDefinition;
|
|
@@ -162,9 +168,8 @@ declare type NodeInputSchema = z.ZodObject;
|
|
|
162
168
|
|
|
163
169
|
/** Options passed to an external package's synchronous createMidsceneTestNodes() factory. */
|
|
164
170
|
export declare interface NodePackageOptions<TContext, TAgent = MidsceneUIAgent> {
|
|
165
|
-
platform: TestPlatform;
|
|
166
171
|
/** Access runtime resources only from a Node's execute() handler. */
|
|
167
|
-
getAgent(
|
|
172
|
+
getAgent(execution: NodeExecutionContext<unknown, TContext>): Awaitable<TAgent>;
|
|
168
173
|
}
|
|
169
174
|
|
|
170
175
|
declare class NodeRegistry {
|
|
@@ -210,7 +215,6 @@ declare interface NormalizedStepMeta {
|
|
|
210
215
|
|
|
211
216
|
declare interface ProjectRuntimeResult<TProjectContext = unknown> {
|
|
212
217
|
projectName: string;
|
|
213
|
-
platform: string;
|
|
214
218
|
status: 'success' | 'failed';
|
|
215
219
|
setupError?: WorkflowError;
|
|
216
220
|
teardownErrors?: readonly WorkflowError[];
|
|
@@ -228,7 +232,6 @@ export declare interface ProjectSetupContext<TProjectContext = unknown> {
|
|
|
228
232
|
|
|
229
233
|
export declare interface ProjectSetupDefinition<TProjectContext = unknown> {
|
|
230
234
|
name: string;
|
|
231
|
-
platform?: TestPlatform | readonly TestPlatform[];
|
|
232
235
|
setup(ctx: ProjectSetupContext<TProjectContext>): Awaitable<TProjectContext>;
|
|
233
236
|
}
|
|
234
237
|
|
|
@@ -244,7 +247,6 @@ export declare interface ProjectTeardownContext<TProjectContext = unknown> {
|
|
|
244
247
|
export declare interface ResolvedExecutionProject<TProjectContext = unknown> {
|
|
245
248
|
readonly projectId: string;
|
|
246
249
|
readonly name: string;
|
|
247
|
-
readonly platform: TestPlatform;
|
|
248
250
|
readonly setup?: ProjectSetupDefinition<TProjectContext>;
|
|
249
251
|
readonly files?: TestFileSelection;
|
|
250
252
|
readonly tags: Readonly<Required<TestTagSelection>>;
|
|
@@ -285,7 +287,6 @@ declare interface StepRunResult<TOutputData = unknown> {
|
|
|
285
287
|
export declare interface TestExecutionProjectRunResult {
|
|
286
288
|
projectId: string;
|
|
287
289
|
name: string;
|
|
288
|
-
platform: TestPlatform;
|
|
289
290
|
status: 'success' | 'failed';
|
|
290
291
|
retry: number;
|
|
291
292
|
fileSelection: TestFileSelection;
|
|
@@ -314,8 +315,6 @@ export declare interface TestOutputDefinition {
|
|
|
314
315
|
reportDir?: string;
|
|
315
316
|
}
|
|
316
317
|
|
|
317
|
-
export declare type TestPlatform = 'web' | 'android' | 'ios' | 'harmony' | 'computer';
|
|
318
|
-
|
|
319
318
|
export declare type TestProjectCaseRunResult = CaseRunOutcome & {
|
|
320
319
|
documentId: string;
|
|
321
320
|
};
|
|
@@ -332,7 +331,7 @@ export declare interface TestProjectDefinition<TContext = undefined> {
|
|
|
332
331
|
projects?: readonly ExecutionProjectDefinition<TContext>[];
|
|
333
332
|
test?: TestOptions;
|
|
334
333
|
output?: TestOutputDefinition;
|
|
335
|
-
nodes
|
|
334
|
+
nodes?: readonly NodeDefinition<any, any, TContext>[];
|
|
336
335
|
}
|
|
337
336
|
|
|
338
337
|
export declare interface TestProjectRunOptions {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -152,7 +152,7 @@ export declare interface DefineNodeOptions<TInput = unknown, TData = unknown, TC
|
|
|
152
152
|
/** Object field populated by string shorthand. Omit or set false to disable it. */
|
|
153
153
|
stringInputKey?: string | false;
|
|
154
154
|
inputSchema?: NodeInputSchema;
|
|
155
|
-
execute(
|
|
155
|
+
execute(execution: NodeExecutionContext<TInput, TContext>): NodeExecutionReturn<TData>;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
export declare type DefineNodeWithSchemaOptions<TSchema extends NodeInputSchema, TData = unknown, TContext = unknown> = Omit<DefineNodeOptions<z.output<TSchema>, TData, TContext>, 'inputSchema'> & {
|
|
@@ -337,7 +337,6 @@ export declare interface ProjectRuntimeOptions<TProjectContext = unknown> {
|
|
|
337
337
|
|
|
338
338
|
export declare interface ProjectRuntimeResult<TProjectContext = unknown> {
|
|
339
339
|
projectName: string;
|
|
340
|
-
platform: string;
|
|
341
340
|
status: 'success' | 'failed';
|
|
342
341
|
setupError?: WorkflowError;
|
|
343
342
|
teardownErrors?: readonly WorkflowError[];
|
|
@@ -355,7 +354,6 @@ declare interface ProjectSetupContext<TProjectContext = unknown> {
|
|
|
355
354
|
|
|
356
355
|
declare interface ProjectSetupDefinition<TProjectContext = unknown> {
|
|
357
356
|
name: string;
|
|
358
|
-
platform?: TestPlatform | readonly TestPlatform[];
|
|
359
357
|
setup(ctx: ProjectSetupContext<TProjectContext>): Awaitable<TProjectContext>;
|
|
360
358
|
}
|
|
361
359
|
|
|
@@ -384,7 +382,6 @@ export declare class ProjectTeardownError extends WorkflowError {
|
|
|
384
382
|
declare interface ResolvedExecutionProject<TProjectContext = unknown> {
|
|
385
383
|
readonly projectId: string;
|
|
386
384
|
readonly name: string;
|
|
387
|
-
readonly platform: TestPlatform;
|
|
388
385
|
readonly setup?: ProjectSetupDefinition<TProjectContext>;
|
|
389
386
|
readonly files?: TestFileSelection;
|
|
390
387
|
readonly tags: Readonly<Required<TestTagSelection>>;
|
|
@@ -504,7 +501,6 @@ declare interface StringInputNodeDefinition {
|
|
|
504
501
|
declare interface TestExecutionProjectRunResult {
|
|
505
502
|
projectId: string;
|
|
506
503
|
name: string;
|
|
507
|
-
platform: TestPlatform;
|
|
508
504
|
status: 'success' | 'failed';
|
|
509
505
|
retry: number;
|
|
510
506
|
fileSelection: TestFileSelection;
|
|
@@ -523,8 +519,6 @@ declare interface TestFileSelection {
|
|
|
523
519
|
exclude?: readonly string[];
|
|
524
520
|
}
|
|
525
521
|
|
|
526
|
-
declare type TestPlatform = 'web' | 'android' | 'ios' | 'harmony' | 'computer';
|
|
527
|
-
|
|
528
522
|
declare type TestProjectCaseRunResult = CaseRunOutcome & {
|
|
529
523
|
documentId: string;
|
|
530
524
|
};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { AgentTestRunnerNodeDefinition } from '@midscene/core/agent/test
|
|
2
|
-
import { AgentTestRunnerNodeProvider } from '@midscene/core/agent/test
|
|
3
|
-
import { aiActInputSchema } from '@midscene/core/agent/test
|
|
4
|
-
import { aiActOptionsInputSchema } from '@midscene/core/agent/test
|
|
5
|
-
import { aiAssertInputSchema } from '@midscene/core/agent/test
|
|
6
|
-
import { aiAssertOptionsInputSchema } from '@midscene/core/agent/test
|
|
7
|
-
import { aiTapInputSchema } from '@midscene/core/agent/test
|
|
8
|
-
import { CommonAgentTestRunnerApi } from '@midscene/core/agent/test
|
|
9
|
-
import { insightInputSchema } from '@midscene/core/agent/test
|
|
10
|
-
import { insightOptionsInputSchema } from '@midscene/core/agent/test
|
|
11
|
-
import { locateOptionsInputSchema } from '@midscene/core/agent/test
|
|
12
|
-
import { promptImageInputSchema } from '@midscene/core/agent/test
|
|
13
|
-
import { recordToReportInputSchema } from '@midscene/core/agent/test
|
|
14
|
-
import { recordToReportOptionsInputSchema } from '@midscene/core/agent/test
|
|
15
|
-
import { reportScreenshotInputSchema } from '@midscene/core/agent/test
|
|
16
|
-
import { structuredUserPromptInputSchema } from '@midscene/core/agent/test
|
|
17
|
-
import { userPromptInputSchema } from '@midscene/core/agent/test
|
|
1
|
+
import { AgentTestRunnerNodeDefinition } from '@midscene/core/agent/test';
|
|
2
|
+
import { AgentTestRunnerNodeProvider } from '@midscene/core/agent/test';
|
|
3
|
+
import { aiActInputSchema } from '@midscene/core/agent/test';
|
|
4
|
+
import { aiActOptionsInputSchema } from '@midscene/core/agent/test';
|
|
5
|
+
import { aiAssertInputSchema } from '@midscene/core/agent/test';
|
|
6
|
+
import { aiAssertOptionsInputSchema } from '@midscene/core/agent/test';
|
|
7
|
+
import { aiTapInputSchema } from '@midscene/core/agent/test';
|
|
8
|
+
import { CommonAgentTestRunnerApi } from '@midscene/core/agent/test';
|
|
9
|
+
import { insightInputSchema } from '@midscene/core/agent/test';
|
|
10
|
+
import { insightOptionsInputSchema } from '@midscene/core/agent/test';
|
|
11
|
+
import { locateOptionsInputSchema } from '@midscene/core/agent/test';
|
|
12
|
+
import { promptImageInputSchema } from '@midscene/core/agent/test';
|
|
13
|
+
import { recordToReportInputSchema } from '@midscene/core/agent/test';
|
|
14
|
+
import { recordToReportOptionsInputSchema } from '@midscene/core/agent/test';
|
|
15
|
+
import { reportScreenshotInputSchema } from '@midscene/core/agent/test';
|
|
16
|
+
import { structuredUserPromptInputSchema } from '@midscene/core/agent/test';
|
|
17
|
+
import { userPromptInputSchema } from '@midscene/core/agent/test';
|
|
18
18
|
import { z } from 'zod/v4';
|
|
19
19
|
|
|
20
20
|
export declare interface AgentProvider<TContext> {
|
|
21
|
-
getAgent(runId: string,
|
|
21
|
+
getAgent(runId: string, execution: NodeExecutionContext<unknown, TContext>): Awaitable<MidsceneUIAgent>;
|
|
22
22
|
releaseAgent?(runId: string): Awaitable<AgentReleaseResult | void>;
|
|
23
23
|
dispose?(): Awaitable<void>;
|
|
24
24
|
}
|
|
@@ -59,12 +59,12 @@ declare interface CaseExecutionContext {
|
|
|
59
59
|
declare type CaseNodePhase = 'beforeEach' | 'steps' | 'afterEach';
|
|
60
60
|
|
|
61
61
|
/** Adapt Agent-owned descriptions to executable Midscene Test Nodes. */
|
|
62
|
-
export declare const createAgentTestRunnerNodes: <TContext>(definitions: readonly AgentTestRunnerNodeDefinition[], getAgent: (
|
|
62
|
+
export declare const createAgentTestRunnerNodes: <TContext>(definitions: readonly AgentTestRunnerNodeDefinition[], getAgent: (execution: NodeExecutionContext<unknown, TContext>) => Awaitable<unknown>) => readonly NodeDefinition<any, any, TContext>[];
|
|
63
63
|
|
|
64
64
|
export declare function createMidsceneNodes<TContext>(options: CreateMidsceneNodesOptions<TContext>): readonly NodeDefinition<any, any, TContext>[];
|
|
65
65
|
|
|
66
66
|
export declare interface CreateMidsceneNodesOptions<TContext> {
|
|
67
|
-
getAgent?(
|
|
67
|
+
getAgent?(execution: NodeExecutionContext<unknown, TContext>): Awaitable<MidsceneUIAgent>;
|
|
68
68
|
agentProvider?: AgentProvider<TContext>;
|
|
69
69
|
/** Agent class that declares the Agent-backed Nodes to register. */
|
|
70
70
|
agentClass: AgentTestRunnerNodeProvider;
|
|
@@ -77,7 +77,7 @@ declare interface DefineNodeOptions<TInput = unknown, TData = unknown, TContext
|
|
|
77
77
|
/** Object field populated by string shorthand. Omit or set false to disable it. */
|
|
78
78
|
stringInputKey?: string | false;
|
|
79
79
|
inputSchema?: NodeInputSchema;
|
|
80
|
-
execute(
|
|
80
|
+
execute(execution: NodeExecutionContext<TInput, TContext>): NodeExecutionReturn<TData>;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
declare type DocumentNodePhase = 'beforeAll' | 'afterAll';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/test",
|
|
3
3
|
"description": "Midscene Test: an extensible YAML testing framework and Node SDK.",
|
|
4
|
-
"version": "1.12.6
|
|
4
|
+
"version": "1.12.6",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/web-infra-dev/midscene.git",
|
|
@@ -29,26 +29,6 @@
|
|
|
29
29
|
"types": "./dist/types/midscene/index.d.ts",
|
|
30
30
|
"import": "./dist/es/midscene/index.mjs",
|
|
31
31
|
"require": "./dist/lib/midscene/index.js"
|
|
32
|
-
},
|
|
33
|
-
"./playwright": {
|
|
34
|
-
"types": "./dist/types/playwright/index.d.ts",
|
|
35
|
-
"import": "./dist/es/playwright/index.mjs",
|
|
36
|
-
"require": "./dist/lib/playwright/index.js"
|
|
37
|
-
},
|
|
38
|
-
"./android": {
|
|
39
|
-
"types": "./dist/types/android/index.d.ts",
|
|
40
|
-
"import": "./dist/es/android/index.mjs",
|
|
41
|
-
"require": "./dist/lib/android/index.js"
|
|
42
|
-
},
|
|
43
|
-
"./ios": {
|
|
44
|
-
"types": "./dist/types/ios/index.d.ts",
|
|
45
|
-
"import": "./dist/es/ios/index.mjs",
|
|
46
|
-
"require": "./dist/lib/ios/index.js"
|
|
47
|
-
},
|
|
48
|
-
"./harmony": {
|
|
49
|
-
"types": "./dist/types/harmony/index.d.ts",
|
|
50
|
-
"import": "./dist/es/harmony/index.mjs",
|
|
51
|
-
"require": "./dist/lib/harmony/index.js"
|
|
52
32
|
}
|
|
53
33
|
},
|
|
54
34
|
"files": [
|
|
@@ -63,8 +43,8 @@
|
|
|
63
43
|
"tsx": "^4.19.2",
|
|
64
44
|
"yargs": "17.7.2",
|
|
65
45
|
"zod": "^3.25.1",
|
|
66
|
-
"@midscene/
|
|
67
|
-
"@midscene/
|
|
46
|
+
"@midscene/shared": "1.12.6",
|
|
47
|
+
"@midscene/core": "1.12.6"
|
|
68
48
|
},
|
|
69
49
|
"devDependencies": {
|
|
70
50
|
"@rslib/core": "^0.18.3",
|
|
@@ -74,31 +54,11 @@
|
|
|
74
54
|
"playwright": "^1.45.0",
|
|
75
55
|
"typescript": "^5.8.3",
|
|
76
56
|
"vitest": "3.0.5",
|
|
77
|
-
"@midscene/android": "1.12.6
|
|
78
|
-
"@midscene/
|
|
79
|
-
"@midscene/
|
|
80
|
-
"@midscene/
|
|
81
|
-
"@midscene/
|
|
82
|
-
},
|
|
83
|
-
"peerDependencies": {
|
|
84
|
-
"playwright": "^1.45.0",
|
|
85
|
-
"@midscene/android": "1.12.6-beta-20260910093036.0",
|
|
86
|
-
"@midscene/ios": "1.12.6-beta-20260910093036.0",
|
|
87
|
-
"@midscene/harmony": "1.12.6-beta-20260910093036.0"
|
|
88
|
-
},
|
|
89
|
-
"peerDependenciesMeta": {
|
|
90
|
-
"@midscene/android": {
|
|
91
|
-
"optional": true
|
|
92
|
-
},
|
|
93
|
-
"@midscene/harmony": {
|
|
94
|
-
"optional": true
|
|
95
|
-
},
|
|
96
|
-
"@midscene/ios": {
|
|
97
|
-
"optional": true
|
|
98
|
-
},
|
|
99
|
-
"playwright": {
|
|
100
|
-
"optional": true
|
|
101
|
-
}
|
|
57
|
+
"@midscene/android": "1.12.6",
|
|
58
|
+
"@midscene/harmony": "1.12.6",
|
|
59
|
+
"@midscene/web": "1.12.6",
|
|
60
|
+
"@midscene/ios": "1.12.6",
|
|
61
|
+
"@midscene/computer": "1.12.6"
|
|
102
62
|
},
|
|
103
63
|
"engines": {
|
|
104
64
|
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { androidAgentTestRunnerNodeDefinitions, launchInputSchema, runAdbShellInputSchema, runAdbShellOptionsInputSchema, terminateInputSchema } from "@midscene/android/test-runner";
|
|
2
|
-
import "@midscene/core/agent/test-runner";
|
|
3
|
-
import { getDebug } from "@midscene/shared/logger";
|
|
4
|
-
import { z } from "zod/v4";
|
|
5
|
-
function _define_property(obj, key, value) {
|
|
6
|
-
if (key in obj) Object.defineProperty(obj, key, {
|
|
7
|
-
value: value,
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true,
|
|
10
|
-
writable: true
|
|
11
|
-
});
|
|
12
|
-
else obj[key] = value;
|
|
13
|
-
return obj;
|
|
14
|
-
}
|
|
15
|
-
class WorkflowError extends Error {
|
|
16
|
-
toJSON() {
|
|
17
|
-
return {
|
|
18
|
-
name: this.name,
|
|
19
|
-
message: this.message,
|
|
20
|
-
code: this.code,
|
|
21
|
-
...void 0 === this.details ? {} : {
|
|
22
|
-
details: this.details
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
constructor(message, options = {}){
|
|
27
|
-
super(message, {
|
|
28
|
-
cause: options.cause
|
|
29
|
-
}), _define_property(this, "code", void 0), _define_property(this, "details", void 0);
|
|
30
|
-
this.name = new.target.name;
|
|
31
|
-
this.code = options.code ?? 'WORKFLOW_ERROR';
|
|
32
|
-
this.details = options.details;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
class errors_NodeDefinitionError extends WorkflowError {
|
|
36
|
-
constructor(message, details){
|
|
37
|
-
super(message, {
|
|
38
|
-
code: 'NODE_DEFINITION_ERROR',
|
|
39
|
-
details
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
class NodeExecutionError extends WorkflowError {
|
|
44
|
-
constructor(node, cause){
|
|
45
|
-
const causeMessage = cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');
|
|
46
|
-
super(`Node "${node}" failed: ${causeMessage}`, {
|
|
47
|
-
code: 'NODE_EXECUTION_ERROR',
|
|
48
|
-
details: {
|
|
49
|
-
node
|
|
50
|
-
},
|
|
51
|
-
cause
|
|
52
|
-
}), _define_property(this, "node", void 0);
|
|
53
|
-
this.node = node;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const validateOptionalText = (value, field, node)=>{
|
|
57
|
-
if (void 0 !== value && ('string' != typeof value || 0 === value.trim().length)) throw new errors_NodeDefinitionError(`Node "${node}" ${field} must be a non-empty string.`, {
|
|
58
|
-
node,
|
|
59
|
-
field
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
const validateInputSchema = (schema, node)=>{
|
|
63
|
-
if (void 0 === schema) return;
|
|
64
|
-
if (!(schema instanceof z.ZodObject)) throw new errors_NodeDefinitionError(`Node "${node}" inputSchema must be a Zod object schema.`, {
|
|
65
|
-
node,
|
|
66
|
-
field: 'inputSchema'
|
|
67
|
-
});
|
|
68
|
-
if ('$' in schema.shape) throw new errors_NodeDefinitionError(`Node "${node}" inputSchema must not declare "$" as an input property.`, {
|
|
69
|
-
node,
|
|
70
|
-
field: 'inputSchema.$'
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
const validateDefinition = (options)=>{
|
|
74
|
-
if (!options || 'object' != typeof options) throw new errors_NodeDefinitionError('Node definition must be an object.');
|
|
75
|
-
if ('string' != typeof options.name || 0 === options.name.trim().length) throw new errors_NodeDefinitionError('Node name must be a non-empty string.');
|
|
76
|
-
validateOptionalText(options.title, 'title', options.name);
|
|
77
|
-
validateOptionalText(options.description, "description", options.name);
|
|
78
|
-
if (void 0 !== options.stringInputKey && false !== options.stringInputKey && ('string' != typeof options.stringInputKey || 0 === options.stringInputKey.trim().length)) throw new errors_NodeDefinitionError(`Node "${options.name}" stringInputKey must be a non-empty string or false.`, {
|
|
79
|
-
node: options.name,
|
|
80
|
-
field: 'stringInputKey'
|
|
81
|
-
});
|
|
82
|
-
validateInputSchema(options.inputSchema, options.name);
|
|
83
|
-
if ('string' == typeof options.stringInputKey && options.inputSchema instanceof z.ZodObject && !(options.stringInputKey in options.inputSchema.shape)) throw new errors_NodeDefinitionError(`Node "${options.name}" stringInputKey must reference a field in inputSchema.`, {
|
|
84
|
-
node: options.name,
|
|
85
|
-
field: 'stringInputKey'
|
|
86
|
-
});
|
|
87
|
-
if ('function' != typeof options.execute) throw new errors_NodeDefinitionError(`Node "${options.name}" must provide an execute function.`, {
|
|
88
|
-
node: options.name
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
function define_node_defineNode(options) {
|
|
92
|
-
validateDefinition(options);
|
|
93
|
-
return options;
|
|
94
|
-
}
|
|
95
|
-
z.strictObject({
|
|
96
|
-
duration: z.number().positive().describe('How long to wait.'),
|
|
97
|
-
unit: z["enum"]([
|
|
98
|
-
'ms',
|
|
99
|
-
's',
|
|
100
|
-
'min'
|
|
101
|
-
]).default('ms').describe('Duration unit: milliseconds, seconds, or minutes.')
|
|
102
|
-
});
|
|
103
|
-
const createAgentTestRunnerNodes = (definitions, getAgent)=>{
|
|
104
|
-
const activeAgentCalls = new WeakMap();
|
|
105
|
-
const runAgentCall = async (node, ctx, agent, call, captureExecutions = true)=>{
|
|
106
|
-
const scopeId = 'case' === ctx.scope ? ctx.case.runId : ctx.document.documentRunId;
|
|
107
|
-
const activeCall = activeAgentCalls.get(agent);
|
|
108
|
-
if (activeCall) throw new NodeExecutionError(node, new Error(`The same Agent instance cannot execute overlapping Midscene Test Steps. Active scope: ${activeCall.scopeId} (${activeCall.node}); requested scope: ${scopeId} (${node}).`));
|
|
109
|
-
activeAgentCalls.set(agent, {
|
|
110
|
-
scopeId,
|
|
111
|
-
node
|
|
112
|
-
});
|
|
113
|
-
let removeListener;
|
|
114
|
-
let sawExecutionWithoutId = false;
|
|
115
|
-
const stopListening = ()=>{
|
|
116
|
-
const remove = removeListener;
|
|
117
|
-
removeListener = void 0;
|
|
118
|
-
remove?.();
|
|
119
|
-
};
|
|
120
|
-
const stopListeningOnAbort = ()=>stopListening();
|
|
121
|
-
try {
|
|
122
|
-
if (captureExecutions && agent.addDumpUpdateListener) {
|
|
123
|
-
removeListener = agent.addDumpUpdateListener((_dump, execution)=>{
|
|
124
|
-
if (!execution) return;
|
|
125
|
-
if (!execution.id) {
|
|
126
|
-
sawExecutionWithoutId = true;
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
ctx.report.addTrace({
|
|
130
|
-
type: 'midscene-execution',
|
|
131
|
-
executionId: execution.id
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
if (ctx.signal.aborted) stopListening();
|
|
135
|
-
else ctx.signal.addEventListener('abort', stopListeningOnAbort, {
|
|
136
|
-
once: true
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return await call();
|
|
140
|
-
} finally{
|
|
141
|
-
ctx.signal.removeEventListener('abort', stopListeningOnAbort);
|
|
142
|
-
try {
|
|
143
|
-
stopListening();
|
|
144
|
-
} finally{
|
|
145
|
-
activeAgentCalls.delete(agent);
|
|
146
|
-
}
|
|
147
|
-
if (sawExecutionWithoutId) warnReportTrace(`Skipped a report trace without a stable execution id for ${node} in scope ${scopeId}.`);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
return definitions.map((definition)=>define_node_defineNode({
|
|
151
|
-
name: definition.name,
|
|
152
|
-
...void 0 === definition.title ? {} : {
|
|
153
|
-
title: definition.title
|
|
154
|
-
},
|
|
155
|
-
...void 0 === definition.description ? {} : {
|
|
156
|
-
description: definition.description
|
|
157
|
-
},
|
|
158
|
-
...void 0 === definition.stringInputKey ? {} : {
|
|
159
|
-
stringInputKey: definition.stringInputKey
|
|
160
|
-
},
|
|
161
|
-
inputSchema: definition.inputSchema,
|
|
162
|
-
async execute (ctx) {
|
|
163
|
-
const agent = await getAgent(ctx);
|
|
164
|
-
const call = async ()=>definition.execute(agent, ctx.input, {
|
|
165
|
-
signal: ctx.signal
|
|
166
|
-
});
|
|
167
|
-
if ('object' != typeof agent || null === agent) return call();
|
|
168
|
-
return runAgentCall(definition.name, ctx, agent, call);
|
|
169
|
-
}
|
|
170
|
-
}));
|
|
171
|
-
};
|
|
172
|
-
const warnReportTrace = getDebug('test-runner:report-trace', {
|
|
173
|
-
console: true
|
|
174
|
-
});
|
|
175
|
-
function createAndroidNodes(options) {
|
|
176
|
-
if (!options || 'object' != typeof options) throw new errors_NodeDefinitionError('createAndroidNodes() options must be an object.');
|
|
177
|
-
if ('function' != typeof options.getAgent) throw new errors_NodeDefinitionError('createAndroidNodes() requires getAgent().');
|
|
178
|
-
return createAgentTestRunnerNodes(androidAgentTestRunnerNodeDefinitions, options.getAgent);
|
|
179
|
-
}
|
|
180
|
-
export { createAndroidNodes, launchInputSchema, runAdbShellInputSchema, runAdbShellOptionsInputSchema, terminateInputSchema };
|
|
181
|
-
|
|
182
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"android/index.mjs","sources":["../../../src/errors.ts","../../../src/node/define-node.ts","../../../src/midscene/index.ts","../../../src/android/index.ts"],"sourcesContent":["import type { z } from 'zod/v4';\n\nexport interface WorkflowErrorOptions {\n code?: string;\n details?: unknown;\n cause?: unknown;\n}\n\nexport class WorkflowError extends Error {\n readonly code: string;\n readonly details?: unknown;\n\n constructor(message: string, options: WorkflowErrorOptions = {}) {\n super(message, { cause: options.cause });\n this.name = new.target.name;\n this.code = options.code ?? 'WORKFLOW_ERROR';\n this.details = options.details;\n }\n\n toJSON(): Record<string, unknown> {\n return {\n name: this.name,\n message: this.message,\n code: this.code,\n ...(this.details === undefined ? {} : { details: this.details }),\n };\n }\n}\n\nexport class WorkflowParseError extends WorkflowError {\n constructor(message: string, details?: unknown, cause?: unknown) {\n super(message, { code: 'WORKFLOW_PARSE_ERROR', details, cause });\n }\n}\n\nexport class NodeDefinitionError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_DEFINITION_ERROR', details });\n }\n}\n\nexport class DuplicateNodeError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is already registered.`, {\n code: 'DUPLICATE_NODE',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeNotFoundError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string) {\n super(`Node \"${node}\" is not registered.`, {\n code: 'NODE_NOT_FOUND',\n details: { node },\n });\n this.node = node;\n }\n}\n\nexport class NodeInputValidationError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'NODE_INPUT_VALIDATION_ERROR', details });\n }\n\n static fromZod(node: string, error: z.ZodError): NodeInputValidationError {\n const issues = error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map(String).join('.'),\n message: issue.message,\n }));\n const firstIssue = issues[0];\n const path = firstIssue?.path || '<root>';\n const message = firstIssue?.message ?? 'invalid input';\n return new NodeInputValidationError(\n `Node \"${node}\" input validation failed at \"${path}\": ${message}`,\n { node, issues },\n );\n }\n}\n\nexport class StepTimeoutError extends WorkflowError {\n readonly timeoutMs: number;\n readonly node?: string;\n\n constructor(timeoutMs: number, node?: string) {\n super(\n node\n ? `Node \"${node}\" timed out after ${timeoutMs}ms.`\n : `Step timed out after ${timeoutMs}ms.`,\n {\n code: 'STEP_TIMEOUT',\n details: { timeoutMs, ...(node === undefined ? {} : { node }) },\n },\n );\n this.timeoutMs = timeoutMs;\n this.node = node;\n }\n}\n\nexport class NodeExecutionError extends WorkflowError {\n readonly node: string;\n\n constructor(node: string, cause: unknown) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Node \"${node}\" failed: ${causeMessage}`, {\n code: 'NODE_EXECUTION_ERROR',\n details: { node },\n cause,\n });\n this.node = node;\n }\n}\n\nexport class WorkflowLifecycleError extends WorkflowError {\n constructor(message: string, details?: unknown) {\n super(message, { code: 'WORKFLOW_LIFECYCLE_ERROR', details });\n }\n}\n\nexport class ProjectSetupError extends WorkflowError {\n constructor(cause: unknown, details: { projectName: string }) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" setup failed: ${causeMessage}`, {\n code: 'PROJECT_SETUP_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class ProjectTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: { projectName: string; registrationIndex: number },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(`Project \"${details.projectName}\" teardown failed: ${causeMessage}`, {\n code: 'PROJECT_TEARDOWN_ERROR',\n details,\n cause,\n });\n }\n}\n\nexport class NodeScopeTeardownError extends WorkflowError {\n constructor(\n cause: unknown,\n details: {\n scope: 'case' | 'document';\n scopeId: string;\n node: string;\n registrationIndex: number;\n },\n ) {\n const causeMessage =\n cause instanceof Error ? cause.message : String(cause ?? 'Unknown error');\n super(\n `${details.scope === 'case' ? 'Case attempt' : 'Workflow document'} node teardown failed for \"${details.node}\": ${causeMessage}`,\n { code: 'NODE_SCOPE_TEARDOWN_ERROR', details, cause },\n );\n }\n}\n\nexport class FatalDeviceError extends WorkflowError {\n constructor(message: string, cause?: unknown) {\n super(message, { code: 'FATAL_DEVICE_ERROR', cause });\n }\n}\n\nexport const isFatalDeviceError = (error: unknown): boolean => {\n if (error instanceof FatalDeviceError) return true;\n if (error instanceof WorkflowError && error.code === 'FATAL_DEVICE_ERROR') {\n return true;\n }\n if (\n error instanceof Error &&\n /device offline|device not found|(?:adb|bdc|device) connection (?:was )?closed/i.test(\n error.message,\n )\n ) {\n return true;\n }\n return error instanceof Error && error.cause !== undefined\n ? isFatalDeviceError(error.cause)\n : false;\n};\n\nexport class CaseExecutionError extends WorkflowError {\n readonly result: import('./engine/types').CaseRunResult;\n\n constructor(result: import('./engine/types').CaseRunResult) {\n super(`Case \"${result.name}\" failed.`, {\n code: 'CASE_EXECUTION_FAILED',\n details: { caseId: result.caseId, runId: result.runId },\n });\n this.result = result;\n }\n}\n\nexport class WorkflowDocumentExecutionError extends WorkflowError {\n readonly result: import('./engine/types').WorkflowDocumentRunResult;\n\n constructor(result: import('./engine/types').WorkflowDocumentRunResult) {\n super(`Workflow document \"${result.sourcePath}\" failed.`, {\n code: 'WORKFLOW_DOCUMENT_EXECUTION_FAILED',\n details: {\n documentId: result.documentId,\n documentRunId: result.documentRunId,\n },\n });\n this.result = result;\n }\n}\n\nexport function normalizeNodeExecutionError(\n error: unknown,\n node: string,\n): WorkflowError {\n return error instanceof WorkflowError\n ? error\n : new NodeExecutionError(node, error);\n}\n","import { z } from 'zod/v4';\nimport { NodeDefinitionError } from '../errors';\nimport type {\n DefineNodeOptions,\n DefineNodeWithSchemaOptions,\n NodeDefinition,\n NodeDefinitionWithSchema,\n NodeInputSchema,\n} from './types';\n\nconst validateOptionalText = (\n value: unknown,\n field: 'title' | 'description',\n node: string,\n): void => {\n if (\n value !== undefined &&\n (typeof value !== 'string' || value.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${node}\" ${field} must be a non-empty string.`,\n { node, field },\n );\n }\n};\n\nconst validateInputSchema = (schema: unknown, node: string): void => {\n if (schema === undefined) return;\n if (!(schema instanceof z.ZodObject)) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must be a Zod object schema.`,\n { node, field: 'inputSchema' },\n );\n }\n if ('$' in schema.shape) {\n throw new NodeDefinitionError(\n `Node \"${node}\" inputSchema must not declare \"$\" as an input property.`,\n { node, field: 'inputSchema.$' },\n );\n }\n};\n\nconst validateDefinition = (options: {\n name: string;\n title?: unknown;\n description?: unknown;\n stringInputKey?: unknown;\n inputSchema?: unknown;\n execute: unknown;\n}): void => {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError('Node definition must be an object.');\n }\n\n if (typeof options.name !== 'string' || options.name.trim().length === 0) {\n throw new NodeDefinitionError('Node name must be a non-empty string.');\n }\n\n validateOptionalText(options.title, 'title', options.name);\n validateOptionalText(options.description, 'description', options.name);\n if (\n options.stringInputKey !== undefined &&\n options.stringInputKey !== false &&\n (typeof options.stringInputKey !== 'string' ||\n options.stringInputKey.trim().length === 0)\n ) {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" stringInputKey must be a non-empty string or false.`,\n { node: options.name, field: 'stringInputKey' },\n );\n }\n validateInputSchema(options.inputSchema, options.name);\n\n if (\n typeof options.stringInputKey === 'string' &&\n options.inputSchema instanceof z.ZodObject &&\n !(options.stringInputKey in options.inputSchema.shape)\n ) {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" stringInputKey must reference a field in inputSchema.`,\n { node: options.name, field: 'stringInputKey' },\n );\n }\n\n if (typeof options.execute !== 'function') {\n throw new NodeDefinitionError(\n `Node \"${options.name}\" must provide an execute function.`,\n { node: options.name },\n );\n }\n};\n\nexport function defineNode<\n TSchema extends NodeInputSchema,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeWithSchemaOptions<TSchema, TData, TContext>,\n): NodeDefinitionWithSchema<TSchema, TData, TContext>;\n\nexport function defineNode<\n TInput = unknown,\n TData = unknown,\n TContext = unknown,\n>(\n options: DefineNodeOptions<TInput, TData, TContext>,\n): NodeDefinition<TInput, TData, TContext>;\n\nexport function defineNode(\n options: DefineNodeOptions<any, any, any>,\n): NodeDefinition<any, any, any> {\n validateDefinition(options);\n return options;\n}\n","import {\n type AgentTestRunnerNodeDefinition,\n type AgentTestRunnerNodeProvider,\n type CommonAgentTestRunnerApi,\n aiActInputSchema,\n aiActOptionsInputSchema,\n aiAssertInputSchema,\n aiAssertOptionsInputSchema,\n aiTapInputSchema,\n insightInputSchema,\n insightOptionsInputSchema,\n locateOptionsInputSchema,\n promptImageInputSchema,\n recordToReportInputSchema,\n recordToReportOptionsInputSchema,\n reportScreenshotInputSchema,\n structuredUserPromptInputSchema,\n userPromptInputSchema,\n} from '@midscene/core/agent/test-runner';\nimport { getDebug } from '@midscene/shared/logger';\nimport { z } from 'zod/v4';\nimport type { Awaitable } from '../engine/types';\nimport { NodeDefinitionError, NodeExecutionError } from '../errors';\nimport { defineNode } from '../node/define-node';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\nexport type MidsceneUIAgent = CommonAgentTestRunnerApi & {\n addDumpUpdateListener?(\n listener: (dump: string, execution?: MidsceneExecutionRef) => void,\n ): () => void;\n};\n\nexport {\n aiActInputSchema,\n aiActOptionsInputSchema,\n aiAssertInputSchema,\n aiAssertOptionsInputSchema,\n aiTapInputSchema,\n insightInputSchema,\n insightOptionsInputSchema,\n locateOptionsInputSchema,\n promptImageInputSchema,\n recordToReportInputSchema,\n recordToReportOptionsInputSchema,\n reportScreenshotInputSchema,\n structuredUserPromptInputSchema,\n userPromptInputSchema,\n};\n\nexport interface MidsceneExecutionRef {\n id?: string;\n}\n\nexport interface AgentProvider<TContext> {\n getAgent(\n runId: string,\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n // biome-ignore lint/suspicious/noConfusingVoidType: providers without a report intentionally return void.\n releaseAgent?(runId: string): Awaitable<AgentReleaseResult | void>;\n dispose?(): Awaitable<void>;\n}\n\nexport interface AgentReleaseResult {\n /** Absolute path to the finalized report for this Agent scope. */\n reportPath?: string;\n}\n\nexport const waitInputSchema = z.strictObject({\n duration: z.number().positive().describe('How long to wait.'),\n unit: z\n .enum(['ms', 's', 'min'])\n .default('ms')\n .describe('Duration unit: milliseconds, seconds, or minutes.'),\n});\n\nexport type AiActNodeInput = z.infer<typeof aiActInputSchema>;\nexport type AiAssertNodeInput = z.infer<typeof aiAssertInputSchema>;\nexport type AiTapNodeInput = z.infer<typeof aiTapInputSchema>;\nexport type InsightNodeInput = z.infer<typeof insightInputSchema>;\nexport type RecordToReportNodeInput = z.infer<typeof recordToReportInputSchema>;\nexport type WaitNodeInput = z.infer<typeof waitInputSchema>;\n\nexport interface CreateMidsceneNodesOptions<TContext> {\n getAgent?(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<MidsceneUIAgent>;\n agentProvider?: AgentProvider<TContext>;\n /** Agent class that declares the Agent-backed Nodes to register. */\n agentClass: AgentTestRunnerNodeProvider;\n}\n\nconst waitFor = async (durationMs: number, signal: AbortSignal) => {\n if (signal.aborted) {\n throw signal.reason ?? new Error('Wait aborted.');\n }\n await new Promise<void>((resolve, reject) => {\n const timeout = setTimeout(() => {\n signal.removeEventListener('abort', abort);\n resolve();\n }, durationMs);\n const abort = () => {\n clearTimeout(timeout);\n reject(signal.reason ?? new Error('Wait aborted.'));\n };\n signal.addEventListener('abort', abort, { once: true });\n });\n};\n\n/** Adapt Agent-owned descriptions to executable Midscene Test Nodes. */\nexport const createAgentTestRunnerNodes = <TContext>(\n definitions: readonly AgentTestRunnerNodeDefinition[],\n getAgent: (\n ctx: NodeExecutionContext<unknown, TContext>,\n ) => Awaitable<unknown>,\n): readonly NodeDefinition<any, any, TContext>[] => {\n const activeAgentCalls = new WeakMap<\n MidsceneUIAgent,\n { scopeId: string; node: string }\n >();\n const runAgentCall = async <T>(\n node: string,\n ctx: NodeExecutionContext<unknown, TContext>,\n agent: MidsceneUIAgent,\n call: () => Promise<T>,\n captureExecutions = true,\n ): Promise<T> => {\n const scopeId =\n ctx.scope === 'case' ? ctx.case.runId : ctx.document.documentRunId;\n const activeCall = activeAgentCalls.get(agent);\n if (activeCall) {\n throw new NodeExecutionError(\n node,\n new Error(\n `The same Agent instance cannot execute overlapping Midscene Test Steps. Active scope: ${activeCall.scopeId} (${activeCall.node}); requested scope: ${scopeId} (${node}).`,\n ),\n );\n }\n\n activeAgentCalls.set(agent, { scopeId, node });\n let removeListener: (() => void) | undefined;\n let sawExecutionWithoutId = false;\n const stopListening = () => {\n const remove = removeListener;\n removeListener = undefined;\n remove?.();\n };\n const stopListeningOnAbort = () => stopListening();\n try {\n if (captureExecutions && agent.addDumpUpdateListener) {\n removeListener = agent.addDumpUpdateListener((_dump, execution) => {\n if (!execution) return;\n if (!execution.id) {\n sawExecutionWithoutId = true;\n return;\n }\n ctx.report.addTrace({\n type: 'midscene-execution',\n executionId: execution.id,\n });\n });\n if (ctx.signal.aborted) stopListening();\n else {\n ctx.signal.addEventListener('abort', stopListeningOnAbort, {\n once: true,\n });\n }\n }\n return await call();\n } finally {\n ctx.signal.removeEventListener('abort', stopListeningOnAbort);\n try {\n stopListening();\n } finally {\n activeAgentCalls.delete(agent);\n }\n if (sawExecutionWithoutId) {\n warnReportTrace(\n `Skipped a report trace without a stable execution id for ${node} in scope ${scopeId}.`,\n );\n }\n }\n };\n\n return definitions.map((definition) =>\n defineNode({\n name: definition.name,\n ...(definition.title === undefined ? {} : { title: definition.title }),\n ...(definition.description === undefined\n ? {}\n : { description: definition.description }),\n ...(definition.stringInputKey === undefined\n ? {}\n : { stringInputKey: definition.stringInputKey }),\n inputSchema: definition.inputSchema,\n async execute(ctx) {\n const agent = await getAgent(ctx);\n const call = async () =>\n definition.execute(agent, ctx.input, { signal: ctx.signal });\n if (typeof agent !== 'object' || agent === null) return call();\n return runAgentCall(\n definition.name,\n ctx,\n agent as MidsceneUIAgent,\n call,\n );\n },\n }),\n );\n};\n\nconst warnReportTrace = getDebug('test-runner:report-trace', {\n console: true,\n});\n\nexport function createMidsceneNodes<TContext>(\n options: CreateMidsceneNodesOptions<TContext>,\n): readonly NodeDefinition<any, any, TContext>[] {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() options must be an object.',\n );\n }\n if (\n typeof options.agentProvider?.getAgent !== 'function' &&\n typeof options.getAgent !== 'function'\n ) {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires getAgent or agentProvider.getAgent.',\n );\n }\n if (\n !options.agentClass ||\n typeof options.agentClass.getTestRunnerNodeDefinitions !== 'function'\n ) {\n throw new NodeDefinitionError(\n 'createMidsceneNodes() requires agentClass.getTestRunnerNodeDefinitions().',\n );\n }\n\n const registeredAgentScopes = new Set<string>();\n const getExecutionId = (ctx: NodeExecutionContext<unknown, TContext>) =>\n ctx.scope === 'case' ? ctx.case.runId : ctx.document.documentRunId;\n const getAgent = async (\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Promise<MidsceneUIAgent> => {\n if (!options.agentProvider) return options.getAgent!(ctx);\n const runId = getExecutionId(ctx);\n if (\n options.agentProvider.releaseAgent &&\n !registeredAgentScopes.has(runId)\n ) {\n registeredAgentScopes.add(runId);\n ctx.onTeardown(async () => {\n try {\n const released = await options.agentProvider!.releaseAgent!(runId);\n return released?.reportPath\n ? { reportPaths: [released.reportPath] }\n : undefined;\n } finally {\n registeredAgentScopes.delete(runId);\n }\n });\n }\n return options.agentProvider.getAgent(runId, ctx);\n };\n\n const agentDefinitions = options.agentClass.getTestRunnerNodeDefinitions();\n\n return [\n ...createAgentTestRunnerNodes(agentDefinitions, getAgent),\n defineNode<typeof waitInputSchema, unknown, TContext>({\n name: 'wait',\n description: 'Wait for a fixed duration while honoring cancellation.',\n stringInputKey: false,\n inputSchema: waitInputSchema,\n async execute(ctx) {\n const multiplier =\n ctx.input.unit === 'min'\n ? 60_000\n : ctx.input.unit === 's'\n ? 1_000\n : 1;\n const durationMs = ctx.input.duration * multiplier;\n await waitFor(durationMs, ctx.signal);\n return { summary: `Waited ${durationMs}ms` };\n },\n }),\n ];\n}\n","import type { AndroidAgent } from '@midscene/android';\nimport {\n androidAgentTestRunnerNodeDefinitions,\n launchInputSchema,\n runAdbShellInputSchema,\n runAdbShellOptionsInputSchema,\n terminateInputSchema,\n} from '@midscene/android/test-runner';\nexport type {\n LaunchNodeInput,\n RunAdbShellNodeInput,\n TerminateNodeInput,\n} from '@midscene/android/test-runner';\nimport type { Awaitable } from '../engine/types';\nimport { NodeDefinitionError } from '../errors';\nimport { createAgentTestRunnerNodes } from '../midscene';\nimport type { NodeDefinition, NodeExecutionContext } from '../node/types';\n\nexport {\n launchInputSchema,\n runAdbShellInputSchema,\n runAdbShellOptionsInputSchema,\n terminateInputSchema,\n};\n\nexport type AndroidRunnerAgent = Pick<\n AndroidAgent,\n 'launch' | 'terminate' | 'runAdbShell' | 'back' | 'home' | 'recentApps'\n>;\n\nexport interface CreateAndroidNodesOptions<TContext> {\n getAgent(\n ctx: NodeExecutionContext<unknown, TContext>,\n ): Awaitable<AndroidRunnerAgent>;\n}\n\nexport function createAndroidNodes<TContext>(\n options: CreateAndroidNodesOptions<TContext>,\n): readonly NodeDefinition<any, any, TContext>[] {\n if (!options || typeof options !== 'object') {\n throw new NodeDefinitionError(\n 'createAndroidNodes() options must be an object.',\n );\n }\n if (typeof options.getAgent !== 'function') {\n throw new NodeDefinitionError('createAndroidNodes() requires getAgent().');\n }\n\n return createAgentTestRunnerNodes(\n androidAgentTestRunnerNodeDefinitions,\n options.getAgent,\n );\n}\n"],"names":["WorkflowError","Error","undefined","message","options","NodeDefinitionError","details","NodeExecutionError","node","cause","causeMessage","String","validateOptionalText","value","field","validateInputSchema","schema","z","validateDefinition","defineNode","createAgentTestRunnerNodes","definitions","getAgent","activeAgentCalls","WeakMap","runAgentCall","ctx","agent","call","captureExecutions","scopeId","activeCall","removeListener","sawExecutionWithoutId","stopListening","remove","stopListeningOnAbort","_dump","execution","warnReportTrace","definition","getDebug","createAndroidNodes","androidAgentTestRunnerNodeDefinitions"],"mappings":";;;;;;;;;;;;;;AAQO,MAAMA,sBAAsB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