@devicecloud.dev/dcd 5.11.0-beta.7 → 5.11.0-beta.8
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/commands/device.js
CHANGED
|
@@ -767,7 +767,13 @@ const runSub = defineCommand({
|
|
|
767
767
|
let body;
|
|
768
768
|
if (dir) {
|
|
769
769
|
ctx.progress(ui.running(`Uploading the flows in ${colors.highlight(dir)}…`));
|
|
770
|
-
const bundle = await uploadFlowBundle({
|
|
770
|
+
const bundle = await uploadFlowBundle({
|
|
771
|
+
apiUrl: ctx.apiUrl,
|
|
772
|
+
auth: ctx.auth,
|
|
773
|
+
dir,
|
|
774
|
+
entry,
|
|
775
|
+
log: ctx.progress,
|
|
776
|
+
});
|
|
771
777
|
ctx.progress(ui.success(`Uploaded ${bundle.files} files`));
|
|
772
778
|
body = {
|
|
773
779
|
flowUploadId: bundle.id,
|
package/dist/mcp/bridge.js
CHANGED
|
@@ -47,7 +47,7 @@ const LOCAL_INPUTS = {
|
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
49
|
run: {
|
|
50
|
-
description: ' Or pass path: a flow file on this machine (sent as yaml), or a directory of flows (
|
|
50
|
+
description: ' Or pass path: a flow file on this machine (sent as yaml), or a directory of flows (flow picks the entry file inside it). Only the YAML files and the files the flows use (scripts, media) are uploaded, not builds or anything else in the directory.',
|
|
51
51
|
properties: {
|
|
52
52
|
path: {
|
|
53
53
|
type: 'string',
|
|
@@ -93,7 +93,12 @@ export async function resolveLocalInputs(name, args, ctx) {
|
|
|
93
93
|
throw new Error(`No such file or directory: ${flowPath}`);
|
|
94
94
|
if (info.isDirectory()) {
|
|
95
95
|
logStderr(`Uploading the flows in ${flowPath}…`);
|
|
96
|
-
const bundle = await uploadFlowBundle({
|
|
96
|
+
const bundle = await uploadFlowBundle({
|
|
97
|
+
...ctx,
|
|
98
|
+
dir: flowPath,
|
|
99
|
+
entry: typeof rest.flow === 'string' ? rest.flow : undefined,
|
|
100
|
+
log: logStderr,
|
|
101
|
+
});
|
|
97
102
|
return { ...rest, flow_upload_id: bundle.id };
|
|
98
103
|
}
|
|
99
104
|
return { ...rest, yaml: await readFile(flowPath, 'utf8') };
|
|
@@ -43,6 +43,27 @@ interface IFlowSequence {
|
|
|
43
43
|
* accepts: YAML `true` or the string `'true'`.
|
|
44
44
|
*/
|
|
45
45
|
export declare function countExtendedRuntimeFlows(flowOverrides: Record<string, Record<string, unknown>>): number;
|
|
46
|
+
/**
|
|
47
|
+
* Resolve `config.yaml`'s `includedPaths` globs into absolute file paths.
|
|
48
|
+
*
|
|
49
|
+
* This is the general-purpose escape hatch for shipping files the flow
|
|
50
|
+
* commands don't reference: `assertScreenshot` baselines above all, but also
|
|
51
|
+
* fixtures, test data and certificates. Only `addMedia` / `runFlow` /
|
|
52
|
+
* `runScript` arguments are discovered by walking the flows, so without this
|
|
53
|
+
* key such files are silently absent from the uploaded zip.
|
|
54
|
+
*
|
|
55
|
+
* Glob semantics deliberately mirror `flows:` (`applyFlowGlobs`): patterns
|
|
56
|
+
* resolve against the workspace root, never the config file's directory, so
|
|
57
|
+
* `--config ci/workspace.yaml` behaves identically to an auto-detected config.
|
|
58
|
+
*
|
|
59
|
+
* @param workspaceConfig - Validated workspace config
|
|
60
|
+
* @param normalizedInput - Normalized path to the workspace directory
|
|
61
|
+
* @param warn - Sink for non-fatal problems
|
|
62
|
+
* @param debug - Whether to emit debug logging
|
|
63
|
+
* @returns Absolute paths of every matched file, deduped and sorted
|
|
64
|
+
* @throws Error if a pattern escapes the workspace root
|
|
65
|
+
*/
|
|
66
|
+
export declare function resolveIncludedPaths(workspaceConfig: IWorkspaceConfig, normalizedInput: string, warn: (message: string) => void, debug?: boolean): string[];
|
|
46
67
|
/**
|
|
47
68
|
* Generate execution plan for test flows
|
|
48
69
|
*
|
|
@@ -218,7 +218,7 @@ const INCLUDED_PATHS_BYTES_WARN_THRESHOLD = 50 * 1024 * 1024;
|
|
|
218
218
|
* @returns Absolute paths of every matched file, deduped and sorted
|
|
219
219
|
* @throws Error if a pattern escapes the workspace root
|
|
220
220
|
*/
|
|
221
|
-
function resolveIncludedPaths(workspaceConfig, normalizedInput, warn, debug = false) {
|
|
221
|
+
export function resolveIncludedPaths(workspaceConfig, normalizedInput, warn, debug = false) {
|
|
222
222
|
const patterns = workspaceConfig.includedPaths;
|
|
223
223
|
if (!patterns || patterns.length === 0)
|
|
224
224
|
return [];
|
|
@@ -2,16 +2,29 @@ import type { AuthContext } from '../types/domain/auth.types.js';
|
|
|
2
2
|
import type { DeviceFlowBundle } from '../types/domain/device-session.types.js';
|
|
3
3
|
/** The API's limit on a bundle (dcd plan 2.5b). */
|
|
4
4
|
export declare const MAX_BUNDLE_BYTES: number;
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The files under `dir` a bundle needs, relative to it, in a stable order:
|
|
7
|
+
* every YAML file (flows, subflows, config), the files the flows use
|
|
8
|
+
* (runScript, addMedia, assertScreenshot and the like), and config's
|
|
9
|
+
* includedPaths. Nothing else: an agent's samples folder sent 265 MB of .apk
|
|
10
|
+
* and .zip files with its flows.
|
|
11
|
+
*
|
|
12
|
+
* `entry` is the one flow that will run. Its files must all be inside `dir`.
|
|
13
|
+
* Without an entry every flow may run, so that goes for all of them. Another
|
|
14
|
+
* flow's missing file doesn't stop the entry running, so it is left out.
|
|
15
|
+
*/
|
|
16
|
+
export declare function bundleFiles(dir: string, entry?: string, warn?: (message: string) => void): string[];
|
|
7
17
|
export interface UploadFlowBundleOptions {
|
|
8
18
|
apiUrl: string;
|
|
9
19
|
auth: AuthContext;
|
|
10
20
|
dir: string;
|
|
21
|
+
/** The one flow that will run, a path inside `dir`. Omitted, all of them. */
|
|
22
|
+
entry?: string;
|
|
11
23
|
log: (message: string) => void;
|
|
12
24
|
}
|
|
13
25
|
/**
|
|
14
|
-
* Zip a directory
|
|
26
|
+
* Zip the files a directory's flows need (bundleFiles) and upload them as a
|
|
27
|
+
* flow bundle: ask the API for
|
|
15
28
|
* upload URLs, PUT the zip to both copies, then register it with its
|
|
16
29
|
* SHA-256. Encrypted like `dcd cloud`'s flow zips when the org's default
|
|
17
30
|
* (or DCD_ENCRYPT) says so. Entries are relative to `dir`, so a run's
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { readdirSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
import { DeviceGateway } from '../gateways/device-gateway.js';
|
|
5
5
|
import { compressFilesFromRelativePath } from '../methods.js';
|
|
6
|
+
import { resolveIncludedPaths } from '../services/execution-plan.service.js';
|
|
7
|
+
import { isWorkspaceConfigFile, loadWorkspaceConfig, processDependencies, readTestYamlFileAsJson, } from '../services/execution-plan.utils.js';
|
|
6
8
|
import { detectCiContext } from './ci.js';
|
|
7
9
|
import { CliError, getCliVersion } from './cli.js';
|
|
8
10
|
import { fetchCompatibilityData } from './compatibility.js';
|
|
@@ -15,13 +17,76 @@ function skipped(relativePath) {
|
|
|
15
17
|
.split(path.sep)
|
|
16
18
|
.some((part) => part === 'node_modules' || (part.startsWith('.') && part !== '.'));
|
|
17
19
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const YAML_FILE = /\.ya?ml$/i;
|
|
21
|
+
/** Every file under `dir`, relative to it. */
|
|
22
|
+
function allFiles(dir) {
|
|
20
23
|
return readdirSync(dir, { recursive: true, withFileTypes: true })
|
|
21
24
|
.filter((entry) => entry.isFile())
|
|
22
25
|
.map((entry) => path.relative(dir, path.join(entry.parentPath, entry.name)))
|
|
23
|
-
.filter((file) => !skipped(file))
|
|
24
|
-
|
|
26
|
+
.filter((file) => !skipped(file));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The files under `dir` a bundle needs, relative to it, in a stable order:
|
|
30
|
+
* every YAML file (flows, subflows, config), the files the flows use
|
|
31
|
+
* (runScript, addMedia, assertScreenshot and the like), and config's
|
|
32
|
+
* includedPaths. Nothing else: an agent's samples folder sent 265 MB of .apk
|
|
33
|
+
* and .zip files with its flows.
|
|
34
|
+
*
|
|
35
|
+
* `entry` is the one flow that will run. Its files must all be inside `dir`.
|
|
36
|
+
* Without an entry every flow may run, so that goes for all of them. Another
|
|
37
|
+
* flow's missing file doesn't stop the entry running, so it is left out.
|
|
38
|
+
*/
|
|
39
|
+
export function bundleFiles(dir, entry, warn = () => { }) {
|
|
40
|
+
const root = path.resolve(dir);
|
|
41
|
+
const yamlFiles = allFiles(dir).filter((file) => YAML_FILE.test(file));
|
|
42
|
+
const entryFile = entry === undefined ? undefined : path.normalize(entry);
|
|
43
|
+
if (entryFile !== undefined && !yamlFiles.includes(entryFile)) {
|
|
44
|
+
throw new CliError(`No flow ${entry} in ${dir}.`);
|
|
45
|
+
}
|
|
46
|
+
const needed = new Set(yamlFiles);
|
|
47
|
+
const problems = [];
|
|
48
|
+
const add = (absolute, strict, from) => {
|
|
49
|
+
const relative = path.relative(root, absolute);
|
|
50
|
+
if (relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
51
|
+
if (strict)
|
|
52
|
+
problems.push(`${from} uses ${absolute}, which is outside ${dir}. Pass a directory that holds both.`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
needed.add(relative);
|
|
56
|
+
};
|
|
57
|
+
for (const file of yamlFiles) {
|
|
58
|
+
const absolute = path.join(root, file);
|
|
59
|
+
const strict = entryFile === undefined || entryFile === file;
|
|
60
|
+
if (isWorkspaceConfigFile(absolute))
|
|
61
|
+
continue;
|
|
62
|
+
let deps;
|
|
63
|
+
try {
|
|
64
|
+
const { config, testSteps } = readTestYamlFileAsJson(absolute);
|
|
65
|
+
deps = processDependencies({ config, input: absolute, testSteps });
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// Not a flow (a data file, say), or one Maestro will report itself.
|
|
69
|
+
if (entryFile === file)
|
|
70
|
+
throw new CliError(error.message);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (strict)
|
|
74
|
+
problems.push(...deps.allErrors);
|
|
75
|
+
for (const dep of deps.allFiles) {
|
|
76
|
+
if (existsSync(dep))
|
|
77
|
+
add(dep, strict, file);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const name of ['config.yaml', 'config.yml']) {
|
|
81
|
+
if (!yamlFiles.includes(name))
|
|
82
|
+
continue;
|
|
83
|
+
const config = loadWorkspaceConfig(path.join(root, name), warn);
|
|
84
|
+
for (const file of resolveIncludedPaths(config, root, warn))
|
|
85
|
+
add(file, true, name);
|
|
86
|
+
}
|
|
87
|
+
if (problems.length > 0)
|
|
88
|
+
throw new CliError(problems.join('\n'));
|
|
89
|
+
return [...needed].sort();
|
|
25
90
|
}
|
|
26
91
|
/** PUT the zip to one signed URL. The URL is the credential. */
|
|
27
92
|
async function put(url, body) {
|
|
@@ -46,16 +111,17 @@ async function put(url, body) {
|
|
|
46
111
|
return false;
|
|
47
112
|
}
|
|
48
113
|
/**
|
|
49
|
-
* Zip a directory
|
|
114
|
+
* Zip the files a directory's flows need (bundleFiles) and upload them as a
|
|
115
|
+
* flow bundle: ask the API for
|
|
50
116
|
* upload URLs, PUT the zip to both copies, then register it with its
|
|
51
117
|
* SHA-256. Encrypted like `dcd cloud`'s flow zips when the org's default
|
|
52
118
|
* (or DCD_ENCRYPT) says so. Entries are relative to `dir`, so a run's
|
|
53
119
|
* `flow` is a path inside it, e.g. `login.yaml`.
|
|
54
120
|
*/
|
|
55
121
|
export async function uploadFlowBundle(opts) {
|
|
56
|
-
const { apiUrl, auth, dir, log } = opts;
|
|
57
|
-
const files = bundleFiles(dir);
|
|
58
|
-
if (!files.some((f) =>
|
|
122
|
+
const { apiUrl, auth, dir, entry, log } = opts;
|
|
123
|
+
const files = bundleFiles(dir, entry, log);
|
|
124
|
+
if (!files.some((f) => YAML_FILE.test(f))) {
|
|
59
125
|
throw new CliError(`No flow files (.yaml) in ${dir}.`);
|
|
60
126
|
}
|
|
61
127
|
const zip = await compressFilesFromRelativePath(dir, files, '');
|
package/package.json
CHANGED