@devicecloud.dev/dcd 5.11.0-beta.1 → 5.11.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -3
- package/dist/commands/cloud.d.ts +1 -1
- package/dist/commands/cloud.js +7 -6
- package/dist/commands/device.d.ts +36 -0
- package/dist/commands/device.js +1151 -0
- package/dist/commands/live.d.ts +2 -0
- package/dist/commands/live.js +10 -1
- package/dist/commands/login.js +2 -17
- package/dist/commands/mcp.d.ts +13 -0
- package/dist/commands/mcp.js +180 -0
- package/dist/commands/upload.js +2 -8
- package/dist/config/flags/device.flags.d.ts +1 -1
- package/dist/config/flags/device.flags.js +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/gateways/device-gateway.d.ts +88 -0
- package/dist/gateways/device-gateway.js +140 -0
- package/dist/index.js +4 -0
- package/dist/mcp/bridge.d.ts +52 -0
- package/dist/mcp/bridge.js +288 -0
- package/dist/mcp/tools/run-cloud-test.d.ts +13 -0
- package/dist/mcp/tools/run-cloud-test.js +18 -8
- package/dist/methods.d.ts +24 -0
- package/dist/methods.js +147 -169
- package/dist/services/device-validation.service.js +1 -1
- package/dist/services/execution-plan.service.d.ts +27 -0
- package/dist/services/execution-plan.service.js +9 -1
- package/dist/services/metadata-extractor.service.d.ts +13 -0
- package/dist/services/metadata-extractor.service.js +35 -1
- package/dist/services/moropo.service.js +1 -1
- package/dist/services/results-polling.service.js +1 -1
- package/dist/types/domain/device-session.types.d.ts +211 -0
- package/dist/types/domain/device-session.types.js +5 -0
- package/dist/types/domain/device.types.d.ts +0 -2
- package/dist/types/domain/device.types.js +0 -2
- package/dist/types.d.ts +11 -0
- package/dist/utils/app-upload.d.ts +19 -0
- package/dist/utils/app-upload.js +63 -0
- package/dist/utils/auth.d.ts +0 -8
- package/dist/utils/auth.js +31 -27
- package/dist/utils/b2-retry.d.ts +49 -0
- package/dist/utils/b2-retry.js +77 -0
- package/dist/utils/browser.d.ts +16 -0
- package/dist/utils/browser.js +48 -0
- package/dist/utils/compatibility.d.ts +5 -7
- package/dist/utils/compatibility.js +5 -13
- package/dist/utils/device-artifacts.d.ts +55 -0
- package/dist/utils/device-artifacts.js +211 -0
- package/dist/utils/device-bundle.d.ts +35 -0
- package/dist/utils/device-bundle.js +162 -0
- package/dist/utils/device-matrix.js +1 -1
- package/dist/utils/device-output.d.ts +81 -0
- package/dist/utils/device-output.js +204 -0
- package/dist/utils/device-run.d.ts +29 -0
- package/dist/utils/device-run.js +113 -0
- package/dist/utils/mcp-install.d.ts +50 -0
- package/dist/utils/mcp-install.js +132 -0
- package/dist/utils/progress.d.ts +4 -0
- package/dist/utils/progress.js +45 -21
- package/package.json +2 -2
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dcd mcp`: one stdio MCP server with two sets of tools (dcd plan 4.4).
|
|
3
|
+
*
|
|
4
|
+
* - The `dcd_*` cloud-test tools, from the same in-process server `dcd-mcp`
|
|
5
|
+
* runs (createServer), reached over an in-memory transport.
|
|
6
|
+
* - The device tools, proxied from the hosted endpoint at `<api>/mcp`, so
|
|
7
|
+
* they are defined (and contract-tested) once, in the API. The bridge adds
|
|
8
|
+
* what a remote server can't do: `install_app` takes a local `app_path`,
|
|
9
|
+
* and `run` takes a local `path` (a flow file, or a directory uploaded as
|
|
10
|
+
* a bundle).
|
|
11
|
+
*
|
|
12
|
+
* Auth is the CLI's: an API key or a `dcd login` session (getContext). The
|
|
13
|
+
* hosted endpoint accepts both. A session is renewed before it expires; the
|
|
14
|
+
* one shared connection re-reads the auth on every request (RemoteDevices).
|
|
15
|
+
*
|
|
16
|
+
* stdout is the JSON-RPC channel: everything else goes to stderr.
|
|
17
|
+
*/
|
|
18
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
19
|
+
import * as path from 'node:path';
|
|
20
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
21
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
22
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
23
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
24
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
25
|
+
import { DeviceGateway } from '../gateways/device-gateway.js';
|
|
26
|
+
import { processDependencies, readTestYamlFileAsJson } from '../services/execution-plan.utils.js';
|
|
27
|
+
import { computeCommonRoot } from '../services/flow-paths.js';
|
|
28
|
+
import { uploadLocalApp } from '../utils/app-upload.js';
|
|
29
|
+
import { getCliVersion } from '../utils/cli.js';
|
|
30
|
+
import { uploadFlowBundle } from '../utils/device-bundle.js';
|
|
31
|
+
import { getContext, isReadOnly, logStderr } from './context.js';
|
|
32
|
+
import { errorResult, runTool } from './helpers.js';
|
|
33
|
+
import { createServer } from './server.js';
|
|
34
|
+
const INSTRUCTIONS = 'DeviceCloud tools. dcd_* tools run Maestro test suites in the cloud. The device tools lease a cloud iOS or Android device for you to drive: start_device, then inspect_screen / take_screenshot, launch_app, run, and stop_device when done. Call cheat_sheet first for Maestro syntax. Local files: install_app takes app_path and run takes path (a flow file or a directory), which this server uploads for you.';
|
|
35
|
+
/**
|
|
36
|
+
* How long one forwarded call may take. Longer than dcd_run_cloud_test's
|
|
37
|
+
* longest wait (3600s) plus an upload. The MCP client calling this server
|
|
38
|
+
* still applies its own timeout, and its cancel is passed through.
|
|
39
|
+
*/
|
|
40
|
+
export const CALL_TIMEOUT_MS = 2 * 60 * 60 * 1000;
|
|
41
|
+
const READ_ONLY_INSTRUCTIONS = 'DeviceCloud tools, read-only: nothing here starts a device, runs a test or changes anything. dcd_* tools read cloud test runs and their results. The device tools read open device sessions: list_devices, get_device_status, inspect_screen, take_screenshot, get_logs.';
|
|
42
|
+
/** The inputs this bridge adds to hosted tools, and what they say. */
|
|
43
|
+
const LOCAL_INPUTS = {
|
|
44
|
+
install_app: {
|
|
45
|
+
description: ' Or pass app_path, a build on this machine (.apk, or a simulator .app / .zip / Expo .tar.gz), which is uploaded first.',
|
|
46
|
+
properties: {
|
|
47
|
+
app_path: {
|
|
48
|
+
type: 'string',
|
|
49
|
+
description: 'A build on this machine to upload and install. Pass this, app_binary_id or app_url.',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
run: {
|
|
54
|
+
description: ' Or pass path: a flow file on this machine, or a directory of flows (flow picks the entry file inside it). A file that uses other files (runFlow, runScript, addMedia and the like) is uploaded with its folder; one that uses none is sent as yaml. Only the YAML files and the files the flows use (scripts, media) are uploaded, not builds or anything else in the directory.',
|
|
55
|
+
properties: {
|
|
56
|
+
path: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'A local flow file, or a directory of flows. Pass this, yaml or flow_upload_id.',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
/** A hosted tool with this bridge's local inputs added. */
|
|
64
|
+
export function withLocalInputs(tool) {
|
|
65
|
+
const extra = LOCAL_INPUTS[tool.name];
|
|
66
|
+
if (!extra)
|
|
67
|
+
return tool;
|
|
68
|
+
return {
|
|
69
|
+
...tool,
|
|
70
|
+
description: `${tool.description ?? ''}${extra.description}`,
|
|
71
|
+
inputSchema: {
|
|
72
|
+
...tool.inputSchema,
|
|
73
|
+
properties: { ...tool.inputSchema.properties, ...extra.properties },
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* For a single flow file that uses other files (runFlow, runScript, addMedia
|
|
79
|
+
* and the like): the folder to upload as a bundle, and the file's path
|
|
80
|
+
* inside it. Sent as yaml on its own, the flow would fail on the device with
|
|
81
|
+
* an invalid file path, because the files it uses would not be there. Null
|
|
82
|
+
* when the flow uses no other files, or can't be read (the device reports
|
|
83
|
+
* that itself).
|
|
84
|
+
*/
|
|
85
|
+
export function flowFileBundle(file) {
|
|
86
|
+
const absolute = path.resolve(file);
|
|
87
|
+
let deps;
|
|
88
|
+
try {
|
|
89
|
+
const { config, testSteps } = readTestYamlFileAsJson(absolute);
|
|
90
|
+
deps = processDependencies({ config, input: absolute, testSteps });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
// A missing file goes this way too, so the upload names it.
|
|
96
|
+
if (deps.allFiles.length === 0 && deps.allErrors.length === 0)
|
|
97
|
+
return null;
|
|
98
|
+
const dir = computeCommonRoot([absolute], deps.allFiles) || path.dirname(absolute);
|
|
99
|
+
return { dir, entry: path.relative(dir, absolute) };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Do the local part of a call (uploads, reading a file) and return the
|
|
103
|
+
* arguments the hosted tool takes.
|
|
104
|
+
*/
|
|
105
|
+
export async function resolveLocalInputs(name, args, ctx) {
|
|
106
|
+
if (name === 'install_app' && typeof args.app_path === 'string') {
|
|
107
|
+
const { app_path: filePath, ...rest } = args;
|
|
108
|
+
logStderr(`Uploading ${filePath}…`);
|
|
109
|
+
const binaryId = await uploadLocalApp({
|
|
110
|
+
...ctx,
|
|
111
|
+
filePath: filePath,
|
|
112
|
+
log: logStderr,
|
|
113
|
+
showProgress: false,
|
|
114
|
+
});
|
|
115
|
+
return { ...rest, app_binary_id: binaryId };
|
|
116
|
+
}
|
|
117
|
+
if (name === 'run' && typeof args.path === 'string') {
|
|
118
|
+
const { path: flowPath, ...rest } = args;
|
|
119
|
+
const info = await stat(flowPath).catch(() => null);
|
|
120
|
+
if (!info)
|
|
121
|
+
throw new Error(`No such file or directory: ${flowPath}`);
|
|
122
|
+
if (info.isDirectory()) {
|
|
123
|
+
logStderr(`Uploading the flows in ${flowPath}…`);
|
|
124
|
+
const bundle = await uploadFlowBundle({
|
|
125
|
+
...ctx,
|
|
126
|
+
dir: flowPath,
|
|
127
|
+
entry: typeof rest.flow === 'string' ? rest.flow : undefined,
|
|
128
|
+
log: logStderr,
|
|
129
|
+
});
|
|
130
|
+
return { ...rest, flow_upload_id: bundle.id };
|
|
131
|
+
}
|
|
132
|
+
const bundled = flowFileBundle(flowPath);
|
|
133
|
+
if (bundled) {
|
|
134
|
+
logStderr(`${flowPath} uses other files; uploading it with ${bundled.dir}…`);
|
|
135
|
+
const bundle = await uploadFlowBundle({ ...ctx, ...bundled, log: logStderr });
|
|
136
|
+
return { ...rest, flow: bundled.entry, flow_upload_id: bundle.id };
|
|
137
|
+
}
|
|
138
|
+
return { ...rest, yaml: await readFile(flowPath, 'utf8') };
|
|
139
|
+
}
|
|
140
|
+
return args;
|
|
141
|
+
}
|
|
142
|
+
/** How recent an open session must be to count as one a failed start may have made. */
|
|
143
|
+
export const START_RECOVERY_WINDOW_MS = 2 * 60 * 1000;
|
|
144
|
+
/**
|
|
145
|
+
* What to tell the agent when a start_device call failed without an answer
|
|
146
|
+
* (the connection dropped, or the server never replied). The request may
|
|
147
|
+
* still have started a session, which is billed while it runs, and an agent
|
|
148
|
+
* that just retries would end up with two. So list the open sessions started
|
|
149
|
+
* in the last couple of minutes, and say to check before starting again.
|
|
150
|
+
*/
|
|
151
|
+
export async function explainFailedStart(message, ctx, now = Date.now()) {
|
|
152
|
+
const head = `start_device failed: ${message}. The request may still have started a session, and a session is billed while it runs.`;
|
|
153
|
+
let recent;
|
|
154
|
+
try {
|
|
155
|
+
const { sessions } = await DeviceGateway.list(ctx.apiUrl, ctx.auth);
|
|
156
|
+
recent = sessions.filter((s) => now - Date.parse(s.created_at) <= START_RECOVERY_WINDOW_MS);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return `${head} Call list_devices to check for one before you call start_device again.`;
|
|
160
|
+
}
|
|
161
|
+
if (recent.length === 0) {
|
|
162
|
+
return `${head} No session was started in the last ${START_RECOVERY_WINDOW_MS / 60_000} minutes, so it is safe to call start_device again.`;
|
|
163
|
+
}
|
|
164
|
+
const listed = recent.map((s) => ({
|
|
165
|
+
client_label: s.client_label,
|
|
166
|
+
created_at: s.created_at,
|
|
167
|
+
id: s.id,
|
|
168
|
+
state: s.state,
|
|
169
|
+
}));
|
|
170
|
+
return `${head} Open sessions started in the last ${START_RECOVERY_WINDOW_MS / 60_000} minutes: ${JSON.stringify(listed)}. If one is yours, use it (get_device_status with wait: true until it is ready) instead of starting another. Otherwise stop it with stop_device. Check list_devices before you call start_device again.`;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The hosted device tools, over one connection made on first use and shared
|
|
174
|
+
* by every call.
|
|
175
|
+
*
|
|
176
|
+
* Auth goes on each request, not on the connection. Remaking the connection
|
|
177
|
+
* when a session is renewed would close it under calls still running (a `run`
|
|
178
|
+
* can take minutes), and they would fail with "Connection closed" while the
|
|
179
|
+
* flow carried on. The hosted /mcp is stateless, so nothing ties the
|
|
180
|
+
* connection to the auth it started with.
|
|
181
|
+
*/
|
|
182
|
+
class RemoteDevices {
|
|
183
|
+
connecting = null;
|
|
184
|
+
tools = null;
|
|
185
|
+
/** Calls that arrive together share one connect. A failed one is retried by the next call. */
|
|
186
|
+
connect() {
|
|
187
|
+
this.connecting ??= this.open().catch((error) => {
|
|
188
|
+
this.connecting = null;
|
|
189
|
+
throw error;
|
|
190
|
+
});
|
|
191
|
+
return this.connecting;
|
|
192
|
+
}
|
|
193
|
+
async open() {
|
|
194
|
+
const { apiUrl } = await getContext();
|
|
195
|
+
const client = new Client({ name: 'dcd-mcp-bridge', version: getCliVersion() });
|
|
196
|
+
await client.connect(new StreamableHTTPClientTransport(new URL(`${apiUrl}/mcp`), {
|
|
197
|
+
fetch: async (url, init) => {
|
|
198
|
+
const { auth } = await getContext();
|
|
199
|
+
const headers = new Headers(init?.headers);
|
|
200
|
+
for (const [key, value] of Object.entries(auth.headers))
|
|
201
|
+
headers.set(key, value);
|
|
202
|
+
return fetch(url, { ...init, headers });
|
|
203
|
+
},
|
|
204
|
+
}));
|
|
205
|
+
return client;
|
|
206
|
+
}
|
|
207
|
+
async list() {
|
|
208
|
+
if (this.tools)
|
|
209
|
+
return this.tools;
|
|
210
|
+
const client = await this.connect();
|
|
211
|
+
const { tools } = await client.listTools();
|
|
212
|
+
this.tools = tools;
|
|
213
|
+
return tools;
|
|
214
|
+
}
|
|
215
|
+
has(name) {
|
|
216
|
+
return this.tools?.some((t) => t.name === name) ?? false;
|
|
217
|
+
}
|
|
218
|
+
/** Annotated read-only by the hosted server: changes nothing, costs nothing. */
|
|
219
|
+
isReadOnly(name) {
|
|
220
|
+
return this.tools?.find((t) => t.name === name)?.annotations?.readOnlyHint === true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Build the `dcd mcp` server. Without a reachable hosted endpoint (no
|
|
225
|
+
* credentials yet, or an API without it), it still serves the dcd_* tools
|
|
226
|
+
* and says why on stderr.
|
|
227
|
+
*/
|
|
228
|
+
export async function createBridgeServer(opts = {}) {
|
|
229
|
+
const callTimeoutMs = opts.callTimeoutMs ?? CALL_TIMEOUT_MS;
|
|
230
|
+
const [localClientSide, localServerSide] = InMemoryTransport.createLinkedPair();
|
|
231
|
+
await createServer().connect(localServerSide);
|
|
232
|
+
const local = new Client({ name: 'dcd-mcp-bridge', version: getCliVersion() });
|
|
233
|
+
await local.connect(localClientSide);
|
|
234
|
+
const localNames = new Set((await local.listTools()).tools.map((t) => t.name));
|
|
235
|
+
const remote = new RemoteDevices();
|
|
236
|
+
const readOnly = isReadOnly();
|
|
237
|
+
const server = new Server({ name: 'devicecloud', version: getCliVersion() }, {
|
|
238
|
+
capabilities: { tools: {} },
|
|
239
|
+
instructions: readOnly ? READ_ONLY_INSTRUCTIONS : INSTRUCTIONS,
|
|
240
|
+
});
|
|
241
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
242
|
+
const { tools: localTools } = await local.listTools();
|
|
243
|
+
let deviceTools = [];
|
|
244
|
+
try {
|
|
245
|
+
deviceTools = (await remote.list())
|
|
246
|
+
// Read-only mode keeps only the tools that change nothing.
|
|
247
|
+
.filter((t) => !readOnly || t.annotations?.readOnlyHint === true)
|
|
248
|
+
.map((t) => withLocalInputs(t));
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
logStderr(`Device tools unavailable: ${error instanceof Error ? error.message : String(error)}. Serving the dcd_* tools only.`);
|
|
252
|
+
}
|
|
253
|
+
return { tools: [...localTools, ...deviceTools] };
|
|
254
|
+
});
|
|
255
|
+
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
256
|
+
// The client's own timeout and cancel apply, not the SDK's 60s default:
|
|
257
|
+
// dcd_run_cloud_test can wait an hour, and a device run or upload is long.
|
|
258
|
+
const options = { signal: extra.signal, timeout: callTimeoutMs, resetTimeoutOnProgress: true };
|
|
259
|
+
const { name } = request.params;
|
|
260
|
+
const args = (request.params.arguments ?? {});
|
|
261
|
+
if (localNames.has(name)) {
|
|
262
|
+
return (await local.callTool({ name, arguments: args }, undefined, options));
|
|
263
|
+
}
|
|
264
|
+
return runTool(`device ${name}`, async () => {
|
|
265
|
+
await remote.list();
|
|
266
|
+
if (!remote.has(name))
|
|
267
|
+
return errorResult(`Unknown tool: ${name}`);
|
|
268
|
+
// The list hides these in read-only mode; refuse them if called anyway.
|
|
269
|
+
if (readOnly && !remote.isReadOnly(name)) {
|
|
270
|
+
return errorResult(`${name} is not available in read-only mode.`);
|
|
271
|
+
}
|
|
272
|
+
const client = await remote.connect();
|
|
273
|
+
const ctx = await getContext();
|
|
274
|
+
const remoteArgs = await resolveLocalInputs(name, args, ctx);
|
|
275
|
+
try {
|
|
276
|
+
return (await client.callTool({ name, arguments: remoteArgs }, undefined, options));
|
|
277
|
+
}
|
|
278
|
+
catch (error) {
|
|
279
|
+
// A tool's own refusal comes back as a result. A throw means no answer
|
|
280
|
+
// arrived, so for a start the session's fate is unknown.
|
|
281
|
+
if (name !== 'start_device' || extra.signal.aborted)
|
|
282
|
+
throw error;
|
|
283
|
+
return errorResult(await explainFailedStart(error instanceof Error ? error.message : String(error), ctx));
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
return server;
|
|
288
|
+
}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { type IExecutionPlan } from '../../services/execution-plan.service.js';
|
|
3
|
+
import { type FlowMetadataEntry } from '../../services/flow-paths.js';
|
|
4
|
+
/**
|
|
5
|
+
* The flows a dry run lists: the ones a real run would submit, after the
|
|
6
|
+
* include/exclude tags and excludeFlows, as `dcd cloud --dry-run` lists
|
|
7
|
+
* them. `flowMetadata` holds every flow in the folder, filtered out or not,
|
|
8
|
+
* so it can't be the list.
|
|
9
|
+
*/
|
|
10
|
+
export declare function dryRunFlows(executionPlan: Pick<IExecutionPlan, 'flowsToRun' | 'sequence'>, testMetadataMap: Record<string, FlowMetadataEntry>, commonRoot: string): {
|
|
11
|
+
file: string;
|
|
12
|
+
flowName: string;
|
|
13
|
+
tags: string[];
|
|
14
|
+
}[];
|
|
2
15
|
/**
|
|
3
16
|
* Submit a Maestro flow (or directory of flows) to devicecloud.dev.
|
|
4
17
|
*
|
|
@@ -3,7 +3,7 @@ import { z } from 'zod';
|
|
|
3
3
|
import { ApiGateway } from '../../gateways/api-gateway.js';
|
|
4
4
|
import { plan } from '../../services/execution-plan.service.js';
|
|
5
5
|
import { isSubmitEndpointMissing, submitWithRetry, } from '../../services/flow-submit.service.js';
|
|
6
|
-
import { computeCommonRoot, buildTestMetadataMap } from '../../services/flow-paths.js';
|
|
6
|
+
import { computeCommonRoot, buildTestMetadataMap, } from '../../services/flow-paths.js';
|
|
7
7
|
import { DeviceValidationService } from '../../services/device-validation.service.js';
|
|
8
8
|
import { platformFromAppFile } from '../../services/notices.service.js';
|
|
9
9
|
import { TestSubmissionService } from '../../services/test-submission.service.js';
|
|
@@ -13,6 +13,7 @@ import { refreshAuth } from '../../utils/auth.js';
|
|
|
13
13
|
import { getCliVersion } from '../../utils/cli.js';
|
|
14
14
|
import { fetchCompatibilityData } from '../../utils/compatibility.js';
|
|
15
15
|
import { checkKekForEncryption, resolveEncryption } from '../../utils/envelope.js';
|
|
16
|
+
import { toPortableRelativePath } from '../../utils/paths.js';
|
|
16
17
|
import { getConsoleUrl } from '../../utils/styling.js';
|
|
17
18
|
import { getContext, logStderr } from '../context.js';
|
|
18
19
|
import { jsonResult, runTool } from '../helpers.js';
|
|
@@ -20,6 +21,19 @@ const SUPPORTED_APP_EXTENSIONS = ['.apk', '.app', '.zip'];
|
|
|
20
21
|
const POLL_INTERVAL_MS = 10_000;
|
|
21
22
|
const TERMINAL_STATUSES = new Set(['PASSED', 'FAILED', 'CANCELLED', 'ERROR']);
|
|
22
23
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
24
|
+
/**
|
|
25
|
+
* The flows a dry run lists: the ones a real run would submit, after the
|
|
26
|
+
* include/exclude tags and excludeFlows, as `dcd cloud --dry-run` lists
|
|
27
|
+
* them. `flowMetadata` holds every flow in the folder, filtered out or not,
|
|
28
|
+
* so it can't be the list.
|
|
29
|
+
*/
|
|
30
|
+
export function dryRunFlows(executionPlan, testMetadataMap, commonRoot) {
|
|
31
|
+
return [...executionPlan.flowsToRun, ...(executionPlan.sequence?.flows ?? [])].map((absolute) => {
|
|
32
|
+
const file = toPortableRelativePath(absolute, commonRoot);
|
|
33
|
+
const meta = testMetadataMap[file];
|
|
34
|
+
return { file, flowName: meta?.flowName ?? path.parse(absolute).name, tags: meta?.tags ?? [] };
|
|
35
|
+
});
|
|
36
|
+
}
|
|
23
37
|
/**
|
|
24
38
|
* Submit a Maestro flow (or directory of flows) to devicecloud.dev.
|
|
25
39
|
*
|
|
@@ -55,7 +69,7 @@ export function registerRunCloudTest(server) {
|
|
|
55
69
|
iosVersion: z.string().optional().describe('iOS version, e.g. "17"'),
|
|
56
70
|
iosDevice: z.string().optional().describe('iOS device, e.g. "iphone-14"'),
|
|
57
71
|
androidApiLevel: z.string().optional().describe('Android API level, e.g. "34"'),
|
|
58
|
-
androidDevice: z.string().optional().describe('Android device, e.g. "pixel-
|
|
72
|
+
androidDevice: z.string().optional().describe('Android device, e.g. "pixel-10"'),
|
|
59
73
|
googlePlay: z.boolean().optional().describe('Use a Google Play-enabled Android image'),
|
|
60
74
|
name: z.string().optional().describe('A name for this run'),
|
|
61
75
|
env: z
|
|
@@ -95,7 +109,7 @@ export function registerRunCloudTest(server) {
|
|
|
95
109
|
.min(30)
|
|
96
110
|
.max(3600)
|
|
97
111
|
.optional()
|
|
98
|
-
.describe('Max seconds to wait when wait is true (default 600)'),
|
|
112
|
+
.describe('Max seconds to wait when wait is true (default 600). A flow with DEVICECLOUD_OVERRIDE_EXTENDED_RUNTIME: true in its env can run for up to 20 minutes, so raise this when the run includes one.'),
|
|
99
113
|
},
|
|
100
114
|
annotations: {
|
|
101
115
|
title: 'Run a cloud test',
|
|
@@ -143,11 +157,7 @@ export function registerRunCloudTest(server) {
|
|
|
143
157
|
if (args.dryRun) {
|
|
144
158
|
return jsonResult({
|
|
145
159
|
dryRun: true,
|
|
146
|
-
flows:
|
|
147
|
-
file,
|
|
148
|
-
flowName: meta.flowName,
|
|
149
|
-
tags: meta.tags,
|
|
150
|
-
})),
|
|
160
|
+
flows: dryRunFlows(executionPlan, testMetadataMap, commonRoot),
|
|
151
161
|
sequentialFlowCount: executionPlan.sequence?.flows.length ?? 0,
|
|
152
162
|
});
|
|
153
163
|
}
|
package/dist/methods.d.ts
CHANGED
|
@@ -16,6 +16,21 @@ interface UploadBinaryConfig {
|
|
|
16
16
|
log?: boolean;
|
|
17
17
|
}
|
|
18
18
|
export declare const uploadBinary: (config: UploadBinaryConfig) => Promise<string>;
|
|
19
|
+
type UploadResult = {
|
|
20
|
+
error: Error | null;
|
|
21
|
+
success: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Validates upload results and throws if all uploads failed. The message names
|
|
25
|
+
* both failures: the Supabase error alone hid every Backblaze failure behind
|
|
26
|
+
* it, which is what made a dropped B2 request look like a Supabase outage.
|
|
27
|
+
* @param supabase - Result of the Supabase upload
|
|
28
|
+
* @param backblaze - Result of the Backblaze upload
|
|
29
|
+
* @param b2 - Backblaze configuration
|
|
30
|
+
* @param debug - Enable debug logging
|
|
31
|
+
* @returns void - throws error if all uploads failed
|
|
32
|
+
*/
|
|
33
|
+
export declare function validateUploadResults(supabase: UploadResult, backblaze: UploadResult, b2: unknown, debug: boolean): void;
|
|
19
34
|
/**
|
|
20
35
|
* Storage reference for an already-uploaded flow zip, threaded into the
|
|
21
36
|
* `submitFlowTest` JSON body so the API can locate the staged file.
|
|
@@ -47,6 +62,15 @@ export declare const uploadFlowZip: (config: {
|
|
|
47
62
|
buffer: Buffer;
|
|
48
63
|
debug?: boolean;
|
|
49
64
|
}) => Promise<FlowZipUploadResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Picks the upload URL for one attempt at one part. The API mints one URL per
|
|
67
|
+
* part, but each is bound to the large file rather than to a part number (the
|
|
68
|
+
* part number travels in `X-Bz-Part-Number`), so any of them can carry any
|
|
69
|
+
* part. A retry moves on to the next one, which is what B2 asks for after a
|
|
70
|
+
* 503 or a dropped connection. Parts upload one at a time, so no URL is ever
|
|
71
|
+
* in use twice at once.
|
|
72
|
+
*/
|
|
73
|
+
export declare function partUploadUrlFor<T>(urls: T[], partNumber: number, attempt: number): T;
|
|
50
74
|
/**
|
|
51
75
|
* Writes JSON data to a file with error handling
|
|
52
76
|
* @param filePath - Path to the output JSON file
|