@devicecloud.dev/dcd 4.1.2-beta.1 → 4.1.3
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/cloud.d.ts +26 -34
- package/dist/commands/cloud.js +117 -465
- package/dist/commands/status.d.ts +6 -0
- package/dist/commands/status.js +19 -1
- package/dist/config/flags/api.flags.d.ts +7 -0
- package/dist/config/flags/api.flags.js +19 -0
- package/dist/config/flags/binary.flags.d.ts +8 -0
- package/dist/config/flags/binary.flags.js +20 -0
- package/dist/config/flags/device.flags.d.ts +14 -0
- package/dist/config/flags/device.flags.js +46 -0
- package/dist/config/flags/environment.flags.d.ts +11 -0
- package/dist/config/flags/environment.flags.js +37 -0
- package/dist/config/flags/execution.flags.d.ts +13 -0
- package/dist/config/flags/execution.flags.js +50 -0
- package/dist/config/flags/output.flags.d.ts +18 -0
- package/dist/config/flags/output.flags.js +61 -0
- package/dist/constants.d.ts +28 -24
- package/dist/constants.js +21 -206
- package/dist/gateways/api-gateway.d.ts +3 -3
- package/dist/methods.d.ts +0 -4
- package/dist/methods.js +15 -80
- package/dist/services/device-validation.service.d.ts +29 -0
- package/dist/services/device-validation.service.js +72 -0
- package/dist/{plan.d.ts → services/execution-plan.service.d.ts} +1 -1
- package/dist/{plan.js → services/execution-plan.service.js} +10 -10
- package/dist/{planMethods.js → services/execution-plan.utils.js} +0 -1
- package/dist/services/metadata-extractor.service.d.ts +46 -0
- package/dist/services/metadata-extractor.service.js +138 -0
- package/dist/services/moropo.service.d.ts +20 -0
- package/dist/services/moropo.service.js +113 -0
- package/dist/services/report-download.service.d.ts +40 -0
- package/dist/services/report-download.service.js +110 -0
- package/dist/services/results-polling.service.d.ts +45 -0
- package/dist/services/results-polling.service.js +210 -0
- package/dist/services/test-submission.service.d.ts +41 -0
- package/dist/services/test-submission.service.js +116 -0
- package/dist/services/version.service.d.ts +31 -0
- package/dist/services/version.service.js +81 -0
- package/dist/types/{schema.types.d.ts → generated/schema.types.d.ts} +349 -349
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +24 -0
- package/dist/utils/compatibility.d.ts +5 -0
- package/dist/utils/connectivity.d.ts +29 -0
- package/dist/utils/connectivity.js +100 -0
- package/oclif.manifest.json +195 -209
- package/package.json +2 -9
- /package/dist/{planMethods.d.ts → services/execution-plan.utils.d.ts} +0 -0
- /package/dist/types/{device.types.d.ts → domain/device.types.d.ts} +0 -0
- /package/dist/types/{device.types.js → domain/device.types.js} +0 -0
- /package/dist/types/{schema.types.js → generated/schema.types.js} +0 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MetadataExtractorService = exports.IosZipMetadataExtractor = exports.IosAppMetadataExtractor = exports.AndroidMetadataExtractor = void 0;
|
|
4
|
+
const AppInfoParser = require("app-info-parser");
|
|
5
|
+
const bplist_parser_1 = require("bplist-parser");
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
const StreamZip = require("node-stream-zip");
|
|
9
|
+
const plist_1 = require("plist");
|
|
10
|
+
/**
|
|
11
|
+
* Extracts metadata from Android APK files
|
|
12
|
+
*/
|
|
13
|
+
class AndroidMetadataExtractor {
|
|
14
|
+
canHandle(filePath) {
|
|
15
|
+
return filePath.endsWith('.apk');
|
|
16
|
+
}
|
|
17
|
+
async extract(filePath) {
|
|
18
|
+
const parser = new AppInfoParser(filePath);
|
|
19
|
+
const result = await parser.parse();
|
|
20
|
+
return { appId: result.package, platform: 'android' };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AndroidMetadataExtractor = AndroidMetadataExtractor;
|
|
24
|
+
/**
|
|
25
|
+
* Extracts metadata from iOS .app directories
|
|
26
|
+
*/
|
|
27
|
+
class IosAppMetadataExtractor {
|
|
28
|
+
canHandle(filePath) {
|
|
29
|
+
return filePath.endsWith('.app');
|
|
30
|
+
}
|
|
31
|
+
async extract(filePath) {
|
|
32
|
+
const infoPlistPath = path.normalize(path.join(filePath, 'Info.plist'));
|
|
33
|
+
const buffer = await (0, promises_1.readFile)(infoPlistPath);
|
|
34
|
+
const data = await this.parseInfoPlist(buffer);
|
|
35
|
+
const appId = data.CFBundleIdentifier;
|
|
36
|
+
return { appId, platform: 'ios' };
|
|
37
|
+
}
|
|
38
|
+
async parseInfoPlist(buffer) {
|
|
39
|
+
let data;
|
|
40
|
+
const bufferType = buffer[0];
|
|
41
|
+
if (bufferType === 60 ||
|
|
42
|
+
bufferType === '<' ||
|
|
43
|
+
bufferType === 239) {
|
|
44
|
+
data = (0, plist_1.parse)(buffer.toString());
|
|
45
|
+
}
|
|
46
|
+
else if (bufferType === 98) {
|
|
47
|
+
data = (0, bplist_parser_1.parseBuffer)(buffer)[0];
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error('Unknown plist buffer type.');
|
|
51
|
+
}
|
|
52
|
+
return data;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.IosAppMetadataExtractor = IosAppMetadataExtractor;
|
|
56
|
+
/**
|
|
57
|
+
* Extracts metadata from iOS .zip files containing .app bundles
|
|
58
|
+
*/
|
|
59
|
+
class IosZipMetadataExtractor {
|
|
60
|
+
canHandle(filePath) {
|
|
61
|
+
return filePath.endsWith('.zip');
|
|
62
|
+
}
|
|
63
|
+
async extract(filePath) {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const zip = new StreamZip({ file: filePath });
|
|
66
|
+
zip.on('ready', () => {
|
|
67
|
+
// Get all entries and sort them by path depth
|
|
68
|
+
const entries = Object.values(zip.entries());
|
|
69
|
+
const sortedEntries = entries.sort((a, b) => {
|
|
70
|
+
const aDepth = a.name.split('/').length;
|
|
71
|
+
const bDepth = b.name.split('/').length;
|
|
72
|
+
return aDepth - bDepth;
|
|
73
|
+
});
|
|
74
|
+
// Find the first Info.plist in the shallowest directory
|
|
75
|
+
const infoPlist = sortedEntries.find((e) => e.name.endsWith('.app/Info.plist'));
|
|
76
|
+
if (!infoPlist) {
|
|
77
|
+
reject(new Error('Failed to find info plist'));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const buffer = zip.entryDataSync(infoPlist.name);
|
|
81
|
+
this.parseInfoPlist(buffer)
|
|
82
|
+
.then((data) => {
|
|
83
|
+
const appId = data.CFBundleIdentifier;
|
|
84
|
+
zip.close();
|
|
85
|
+
resolve({ appId, platform: 'ios' });
|
|
86
|
+
})
|
|
87
|
+
.catch(reject);
|
|
88
|
+
});
|
|
89
|
+
zip.on('error', reject);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async parseInfoPlist(buffer) {
|
|
93
|
+
let data;
|
|
94
|
+
const bufferType = buffer[0];
|
|
95
|
+
if (bufferType === 60 ||
|
|
96
|
+
bufferType === '<' ||
|
|
97
|
+
bufferType === 239) {
|
|
98
|
+
data = (0, plist_1.parse)(buffer.toString());
|
|
99
|
+
}
|
|
100
|
+
else if (bufferType === 98) {
|
|
101
|
+
data = (0, bplist_parser_1.parseBuffer)(buffer)[0];
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw new Error('Unknown plist buffer type.');
|
|
105
|
+
}
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.IosZipMetadataExtractor = IosZipMetadataExtractor;
|
|
110
|
+
/**
|
|
111
|
+
* Service for extracting app metadata from various file formats
|
|
112
|
+
*/
|
|
113
|
+
class MetadataExtractorService {
|
|
114
|
+
extractors = [
|
|
115
|
+
new AndroidMetadataExtractor(),
|
|
116
|
+
new IosZipMetadataExtractor(),
|
|
117
|
+
new IosAppMetadataExtractor(),
|
|
118
|
+
];
|
|
119
|
+
/**
|
|
120
|
+
* Extract app metadata from a file
|
|
121
|
+
* @param filePath - Path to the app file (.apk, .app, or .zip)
|
|
122
|
+
* @returns App metadata or undefined if extraction fails
|
|
123
|
+
*/
|
|
124
|
+
async extract(filePath) {
|
|
125
|
+
const extractor = this.extractors.find((e) => e.canHandle(filePath));
|
|
126
|
+
if (!extractor) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return await extractor.extract(filePath);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
console.warn('Failed to extract app metadata, please share with support@devicecloud.dev so we can improve our parsing.');
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.MetadataExtractorService = MetadataExtractorService;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface MoropoDownloadOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
branchName?: string;
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
json?: boolean;
|
|
6
|
+
logger?: (message: string) => void;
|
|
7
|
+
quiet?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Service for downloading and extracting Moropo tests from the Moropo API
|
|
11
|
+
*/
|
|
12
|
+
export declare class MoropoService {
|
|
13
|
+
private readonly MOROPO_API_URL;
|
|
14
|
+
/**
|
|
15
|
+
* Download and extract Moropo tests from the API
|
|
16
|
+
* @param options Download configuration options
|
|
17
|
+
* @returns Path to the extracted Moropo tests directory
|
|
18
|
+
*/
|
|
19
|
+
downloadAndExtract(options: MoropoDownloadOptions): Promise<string>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MoropoService = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const fs = require("node:fs");
|
|
6
|
+
const os = require("node:os");
|
|
7
|
+
const path = require("node:path");
|
|
8
|
+
const StreamZip = require("node-stream-zip");
|
|
9
|
+
/**
|
|
10
|
+
* Service for downloading and extracting Moropo tests from the Moropo API
|
|
11
|
+
*/
|
|
12
|
+
class MoropoService {
|
|
13
|
+
MOROPO_API_URL = 'https://api.moropo.com/tests';
|
|
14
|
+
/**
|
|
15
|
+
* Download and extract Moropo tests from the API
|
|
16
|
+
* @param options Download configuration options
|
|
17
|
+
* @returns Path to the extracted Moropo tests directory
|
|
18
|
+
*/
|
|
19
|
+
async downloadAndExtract(options) {
|
|
20
|
+
const { apiKey, branchName = 'main', debug = false, quiet = false, json = false, logger } = options;
|
|
21
|
+
if (debug && logger) {
|
|
22
|
+
logger('DEBUG: Moropo v1 API key detected, downloading tests from Moropo API');
|
|
23
|
+
logger(`DEBUG: Using branch name: ${branchName}`);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
if (!quiet && !json) {
|
|
27
|
+
core_1.ux.action.start('Downloading Moropo tests', 'Initializing', {
|
|
28
|
+
stdout: true,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const response = await fetch(this.MOROPO_API_URL, {
|
|
32
|
+
headers: {
|
|
33
|
+
accept: 'application/zip',
|
|
34
|
+
'x-app-api-key': apiKey,
|
|
35
|
+
'x-branch-name': branchName,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new Error(`Failed to download Moropo tests: ${response.statusText}`);
|
|
40
|
+
}
|
|
41
|
+
const contentLength = response.headers.get('content-length');
|
|
42
|
+
const totalSize = contentLength
|
|
43
|
+
? Number.parseInt(contentLength, 10)
|
|
44
|
+
: 0;
|
|
45
|
+
let downloadedSize = 0;
|
|
46
|
+
const moropoDir = path.join(os.tmpdir(), `moropo-tests-${Date.now()}`);
|
|
47
|
+
if (debug && logger) {
|
|
48
|
+
logger(`DEBUG: Extracting Moropo tests to: ${moropoDir}`);
|
|
49
|
+
}
|
|
50
|
+
// Create moropo directory if it doesn't exist
|
|
51
|
+
if (!fs.existsSync(moropoDir)) {
|
|
52
|
+
fs.mkdirSync(moropoDir, { recursive: true });
|
|
53
|
+
}
|
|
54
|
+
// Write zip file to moropo directory
|
|
55
|
+
const zipPath = path.join(moropoDir, 'moropo-tests.zip');
|
|
56
|
+
const fileStream = fs.createWriteStream(zipPath);
|
|
57
|
+
const reader = response.body?.getReader();
|
|
58
|
+
if (!reader) {
|
|
59
|
+
throw new Error('Failed to get response reader');
|
|
60
|
+
}
|
|
61
|
+
let readerResult = await reader.read();
|
|
62
|
+
while (!readerResult.done) {
|
|
63
|
+
const { value } = readerResult;
|
|
64
|
+
downloadedSize += value.length;
|
|
65
|
+
if (!quiet && !json && totalSize) {
|
|
66
|
+
const progress = Math.round((downloadedSize / totalSize) * 100);
|
|
67
|
+
core_1.ux.action.status = `Downloading: ${progress}%`;
|
|
68
|
+
}
|
|
69
|
+
fileStream.write(value);
|
|
70
|
+
readerResult = await reader.read();
|
|
71
|
+
}
|
|
72
|
+
fileStream.end();
|
|
73
|
+
await new Promise((resolve) => {
|
|
74
|
+
fileStream.on('finish', () => {
|
|
75
|
+
resolve();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
if (!quiet && !json) {
|
|
79
|
+
core_1.ux.action.status = 'Extracting tests...';
|
|
80
|
+
}
|
|
81
|
+
// Extract zip file
|
|
82
|
+
// eslint-disable-next-line new-cap
|
|
83
|
+
const zip = new StreamZip.async({ file: zipPath });
|
|
84
|
+
await zip.extract(null, moropoDir);
|
|
85
|
+
await zip.close();
|
|
86
|
+
// Delete zip file after extraction
|
|
87
|
+
fs.unlinkSync(zipPath);
|
|
88
|
+
if (!quiet && !json) {
|
|
89
|
+
core_1.ux.action.stop('completed');
|
|
90
|
+
}
|
|
91
|
+
if (debug && logger) {
|
|
92
|
+
logger('DEBUG: Successfully extracted Moropo tests');
|
|
93
|
+
}
|
|
94
|
+
// Create config.yaml file
|
|
95
|
+
const configPath = path.join(moropoDir, 'config.yaml');
|
|
96
|
+
fs.writeFileSync(configPath, 'flows:\n- ./**/*.yaml\n- ./*.yaml\n');
|
|
97
|
+
if (debug && logger) {
|
|
98
|
+
logger('DEBUG: Created config.yaml file');
|
|
99
|
+
}
|
|
100
|
+
return moropoDir;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (!quiet && !json) {
|
|
104
|
+
core_1.ux.action.stop('failed');
|
|
105
|
+
}
|
|
106
|
+
if (debug && logger) {
|
|
107
|
+
logger(`DEBUG: Error downloading/extracting Moropo tests: ${error}`);
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`Failed to download/extract Moropo tests: ${error}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.MoropoService = MoropoService;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface DownloadOptions {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
apiUrl: string;
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
logger?: (message: string) => void;
|
|
6
|
+
uploadId: string;
|
|
7
|
+
warnLogger?: (message: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface ArtifactsDownloadOptions extends DownloadOptions {
|
|
10
|
+
artifactsPath?: string;
|
|
11
|
+
downloadType: 'ALL' | 'FAILED';
|
|
12
|
+
}
|
|
13
|
+
export interface ReportDownloadOptions extends DownloadOptions {
|
|
14
|
+
allurePath?: string;
|
|
15
|
+
htmlPath?: string;
|
|
16
|
+
junitPath?: string;
|
|
17
|
+
reportType: 'allure' | 'html' | 'junit';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Service for downloading test artifacts and reports
|
|
21
|
+
*/
|
|
22
|
+
export declare class ReportDownloadService {
|
|
23
|
+
/**
|
|
24
|
+
* Download test artifacts as a zip file
|
|
25
|
+
* @param options Download configuration
|
|
26
|
+
*/
|
|
27
|
+
downloadArtifacts(options: ArtifactsDownloadOptions): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Handle downloading reports based on the report type specified
|
|
30
|
+
* @param options Report download configuration
|
|
31
|
+
*/
|
|
32
|
+
downloadReports(options: ReportDownloadOptions): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Download a specific report type
|
|
35
|
+
* @param type Report type to download
|
|
36
|
+
* @param filePath Path where report should be saved
|
|
37
|
+
* @param options Download configuration
|
|
38
|
+
*/
|
|
39
|
+
private downloadReport;
|
|
40
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReportDownloadService = void 0;
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
const api_gateway_1 = require("../gateways/api-gateway");
|
|
6
|
+
/**
|
|
7
|
+
* Service for downloading test artifacts and reports
|
|
8
|
+
*/
|
|
9
|
+
class ReportDownloadService {
|
|
10
|
+
/**
|
|
11
|
+
* Download test artifacts as a zip file
|
|
12
|
+
* @param options Download configuration
|
|
13
|
+
*/
|
|
14
|
+
async downloadArtifacts(options) {
|
|
15
|
+
const { apiUrl, apiKey, uploadId, downloadType, artifactsPath = './artifacts.zip', debug = false, logger, warnLogger, } = options;
|
|
16
|
+
try {
|
|
17
|
+
if (debug && logger) {
|
|
18
|
+
logger(`DEBUG: Downloading artifacts: ${downloadType}`);
|
|
19
|
+
}
|
|
20
|
+
await api_gateway_1.ApiGateway.downloadArtifactsZip(apiUrl, apiKey, uploadId, downloadType, artifactsPath);
|
|
21
|
+
if (logger) {
|
|
22
|
+
logger('\n');
|
|
23
|
+
logger(`Test artifacts have been downloaded to ${artifactsPath}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
if (debug && logger) {
|
|
28
|
+
logger(`DEBUG: Error downloading artifacts: ${error}`);
|
|
29
|
+
}
|
|
30
|
+
if (warnLogger) {
|
|
31
|
+
warnLogger('Failed to download artifacts');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Handle downloading reports based on the report type specified
|
|
37
|
+
* @param options Report download configuration
|
|
38
|
+
*/
|
|
39
|
+
async downloadReports(options) {
|
|
40
|
+
const { reportType, junitPath, allurePath, htmlPath, warnLogger, ...downloadOptions } = options;
|
|
41
|
+
switch (reportType) {
|
|
42
|
+
case 'junit': {
|
|
43
|
+
const reportPath = path.resolve(process.cwd(), junitPath || 'report.xml');
|
|
44
|
+
await this.downloadReport('junit', reportPath, {
|
|
45
|
+
...downloadOptions,
|
|
46
|
+
warnLogger,
|
|
47
|
+
});
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
case 'allure': {
|
|
51
|
+
const reportPath = path.resolve(process.cwd(), allurePath || 'report.html');
|
|
52
|
+
await this.downloadReport('allure', reportPath, {
|
|
53
|
+
...downloadOptions,
|
|
54
|
+
warnLogger,
|
|
55
|
+
});
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case 'html': {
|
|
59
|
+
const htmlReportPath = path.resolve(process.cwd(), htmlPath || 'report.html');
|
|
60
|
+
await this.downloadReport('html', htmlReportPath, {
|
|
61
|
+
...downloadOptions,
|
|
62
|
+
warnLogger,
|
|
63
|
+
});
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
default: {
|
|
67
|
+
if (warnLogger) {
|
|
68
|
+
warnLogger(`Unknown report type: ${reportType}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Download a specific report type
|
|
75
|
+
* @param type Report type to download
|
|
76
|
+
* @param filePath Path where report should be saved
|
|
77
|
+
* @param options Download configuration
|
|
78
|
+
*/
|
|
79
|
+
async downloadReport(type, filePath, options) {
|
|
80
|
+
const { apiUrl, apiKey, uploadId, debug = false, logger, warnLogger } = options;
|
|
81
|
+
try {
|
|
82
|
+
if (debug && logger) {
|
|
83
|
+
logger(`DEBUG: Downloading ${type.toUpperCase()} report`);
|
|
84
|
+
}
|
|
85
|
+
await api_gateway_1.ApiGateway.downloadReportGeneric(apiUrl, apiKey, uploadId, type, filePath);
|
|
86
|
+
if (logger) {
|
|
87
|
+
logger(`${type.toUpperCase()} test report has been downloaded to ${filePath}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (debug && logger) {
|
|
92
|
+
logger(`DEBUG: Error downloading ${type.toUpperCase()} report: ${error}`);
|
|
93
|
+
}
|
|
94
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
95
|
+
if (warnLogger) {
|
|
96
|
+
warnLogger(`Failed to download ${type.toUpperCase()} report: ${errorMessage}`);
|
|
97
|
+
if (errorMessage.includes('404')) {
|
|
98
|
+
warnLogger(`No ${type.toUpperCase()} reports found for this upload. Make sure your tests generated results.`);
|
|
99
|
+
}
|
|
100
|
+
else if (errorMessage.includes('EACCES') || errorMessage.includes('EPERM')) {
|
|
101
|
+
warnLogger('Permission denied. Check write permissions for the current directory.');
|
|
102
|
+
}
|
|
103
|
+
else if (errorMessage.includes('ENOENT')) {
|
|
104
|
+
warnLogger('Directory does not exist. Make sure you have write access to the current directory.');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.ReportDownloadService = ReportDownloadService;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { paths } from '../types/generated/schema.types';
|
|
2
|
+
type TestResult = paths['/results/{uploadId}']['get']['responses']['200']['content']['application/json']['results'][number];
|
|
3
|
+
/**
|
|
4
|
+
* Custom error for run failures that includes the polling result
|
|
5
|
+
*/
|
|
6
|
+
export declare class RunFailedError extends Error {
|
|
7
|
+
result: PollingResult;
|
|
8
|
+
constructor(result: PollingResult);
|
|
9
|
+
}
|
|
10
|
+
export interface PollingOptions {
|
|
11
|
+
apiKey: string;
|
|
12
|
+
apiUrl: string;
|
|
13
|
+
consoleUrl: string;
|
|
14
|
+
debug?: boolean;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
logger?: (message: string) => void;
|
|
17
|
+
quiet?: boolean;
|
|
18
|
+
uploadId: string;
|
|
19
|
+
}
|
|
20
|
+
export interface PollingResult {
|
|
21
|
+
consoleUrl: string;
|
|
22
|
+
status: 'FAILED' | 'PASSED';
|
|
23
|
+
tests: Array<{
|
|
24
|
+
durationSeconds: null | number;
|
|
25
|
+
failReason?: string;
|
|
26
|
+
name: string;
|
|
27
|
+
status: string;
|
|
28
|
+
}>;
|
|
29
|
+
uploadId: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Service for polling test results from the API
|
|
33
|
+
*/
|
|
34
|
+
export declare class ResultsPollingService {
|
|
35
|
+
private readonly MAX_SEQUENTIAL_FAILURES;
|
|
36
|
+
private readonly POLL_INTERVAL_MS;
|
|
37
|
+
/**
|
|
38
|
+
* Poll for test results until all tests complete
|
|
39
|
+
* @param results Initial test results from submission
|
|
40
|
+
* @param options Polling configuration
|
|
41
|
+
* @returns Promise that resolves with final test results or rejects if tests fail
|
|
42
|
+
*/
|
|
43
|
+
pollUntilComplete(results: TestResult[], options: PollingOptions): Promise<PollingResult>;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResultsPollingService = exports.RunFailedError = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const cli_ux_1 = require("@oclif/core/lib/cli-ux");
|
|
6
|
+
const api_gateway_1 = require("../gateways/api-gateway");
|
|
7
|
+
const methods_1 = require("../methods");
|
|
8
|
+
const connectivity_1 = require("../utils/connectivity");
|
|
9
|
+
/**
|
|
10
|
+
* Custom error for run failures that includes the polling result
|
|
11
|
+
*/
|
|
12
|
+
class RunFailedError extends Error {
|
|
13
|
+
result;
|
|
14
|
+
constructor(result) {
|
|
15
|
+
super('RUN_FAILED');
|
|
16
|
+
this.result = result;
|
|
17
|
+
this.name = 'RunFailedError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.RunFailedError = RunFailedError;
|
|
21
|
+
/**
|
|
22
|
+
* Service for polling test results from the API
|
|
23
|
+
*/
|
|
24
|
+
class ResultsPollingService {
|
|
25
|
+
MAX_SEQUENTIAL_FAILURES = 10;
|
|
26
|
+
POLL_INTERVAL_MS = 5000;
|
|
27
|
+
/**
|
|
28
|
+
* Poll for test results until all tests complete
|
|
29
|
+
* @param results Initial test results from submission
|
|
30
|
+
* @param options Polling configuration
|
|
31
|
+
* @returns Promise that resolves with final test results or rejects if tests fail
|
|
32
|
+
*/
|
|
33
|
+
async pollUntilComplete(results, options) {
|
|
34
|
+
const { apiUrl, apiKey, uploadId, consoleUrl, quiet = false, json = false, debug = false, logger } = options;
|
|
35
|
+
if (!json) {
|
|
36
|
+
core_1.ux.action.start('Waiting for results', 'Initializing', {
|
|
37
|
+
stdout: true,
|
|
38
|
+
});
|
|
39
|
+
if (logger) {
|
|
40
|
+
logger('\nYou can safely close this terminal and the tests will continue\n');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
let sequentialPollFailures = 0;
|
|
44
|
+
let previousSummary = '';
|
|
45
|
+
if (debug && logger) {
|
|
46
|
+
logger(`DEBUG: Starting polling loop for results`);
|
|
47
|
+
}
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const intervalId = setInterval(async () => {
|
|
50
|
+
try {
|
|
51
|
+
if (debug && logger) {
|
|
52
|
+
logger(`DEBUG: Polling for results: ${uploadId}`);
|
|
53
|
+
}
|
|
54
|
+
const { results: updatedResults } = await api_gateway_1.ApiGateway.getResultsForUpload(apiUrl, apiKey, uploadId);
|
|
55
|
+
if (!updatedResults) {
|
|
56
|
+
throw new Error('no results');
|
|
57
|
+
}
|
|
58
|
+
if (debug && logger) {
|
|
59
|
+
logger(`DEBUG: Poll received ${updatedResults.length} results`);
|
|
60
|
+
for (const result of updatedResults) {
|
|
61
|
+
logger(`DEBUG: Result status: ${result.test_file_name} - ${result.status}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Calculate summary statistics
|
|
65
|
+
const statusCounts = {};
|
|
66
|
+
for (const result of updatedResults) {
|
|
67
|
+
statusCounts[result.status] = (statusCounts[result.status] || 0) + 1;
|
|
68
|
+
}
|
|
69
|
+
const passed = statusCounts.PASSED || 0;
|
|
70
|
+
const failed = statusCounts.FAILED || 0;
|
|
71
|
+
const pending = statusCounts.PENDING || 0;
|
|
72
|
+
const running = statusCounts.RUNNING || 0;
|
|
73
|
+
const total = updatedResults.length;
|
|
74
|
+
const completed = passed + failed;
|
|
75
|
+
// Display quantitative summary in quiet mode only
|
|
76
|
+
const summary = `${completed}/${total} | ✓ ${passed} | ✗ ${failed} | ▶ ${running} | ⏸ ${pending}`;
|
|
77
|
+
if (!json) {
|
|
78
|
+
if (quiet) {
|
|
79
|
+
// Only update status when the summary changes in quiet mode
|
|
80
|
+
if (summary !== previousSummary) {
|
|
81
|
+
core_1.ux.action.status = summary;
|
|
82
|
+
previousSummary = summary;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Show detailed table in non-quiet mode (no summary)
|
|
87
|
+
core_1.ux.action.status =
|
|
88
|
+
'\nStatus Test\n─────────── ───────────────';
|
|
89
|
+
for (const { retry_of: isRetry, status, test_file_name: test, } of updatedResults) {
|
|
90
|
+
core_1.ux.action.status += `\n${status.padEnd(10, ' ')} ${test} ${isRetry ? '(retry)' : ''}`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (updatedResults.every((result) => !['PENDING', 'RUNNING'].includes(result.status))) {
|
|
95
|
+
if (debug && logger) {
|
|
96
|
+
logger(`DEBUG: All tests completed, stopping poll`);
|
|
97
|
+
}
|
|
98
|
+
if (!json) {
|
|
99
|
+
core_1.ux.action.stop('completed');
|
|
100
|
+
if (logger) {
|
|
101
|
+
logger('\n');
|
|
102
|
+
}
|
|
103
|
+
const hasFailedTests = updatedResults.some((result) => result.status === 'FAILED');
|
|
104
|
+
(0, cli_ux_1.table)(updatedResults, {
|
|
105
|
+
status: { get: (row) => row.status },
|
|
106
|
+
test: {
|
|
107
|
+
get: (row) => `${row.test_file_name} ${row.retry_of ? '(retry)' : ''}`,
|
|
108
|
+
},
|
|
109
|
+
duration: {
|
|
110
|
+
get: (row) => row.duration_seconds
|
|
111
|
+
? (0, methods_1.formatDurationSeconds)(Number(row.duration_seconds))
|
|
112
|
+
: '-',
|
|
113
|
+
},
|
|
114
|
+
...(hasFailedTests && {
|
|
115
|
+
// eslint-disable-next-line camelcase
|
|
116
|
+
fail_reason: {
|
|
117
|
+
get: (row) => row.status === 'FAILED' && row.fail_reason
|
|
118
|
+
? row.fail_reason
|
|
119
|
+
: '',
|
|
120
|
+
},
|
|
121
|
+
}),
|
|
122
|
+
}, { printLine: logger });
|
|
123
|
+
if (logger) {
|
|
124
|
+
logger('\n');
|
|
125
|
+
logger('Run completed, you can access the results at:');
|
|
126
|
+
logger(consoleUrl);
|
|
127
|
+
logger('\n');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
clearInterval(intervalId);
|
|
131
|
+
const resultsWithoutEarlierTries = updatedResults.filter((result) => {
|
|
132
|
+
const originalTryId = result.retry_of || result.id;
|
|
133
|
+
const tries = updatedResults.filter((r) => r.retry_of === originalTryId || r.id === originalTryId);
|
|
134
|
+
return result.id === Math.max(...tries.map((t) => t.id));
|
|
135
|
+
});
|
|
136
|
+
const output = {
|
|
137
|
+
consoleUrl,
|
|
138
|
+
status: resultsWithoutEarlierTries.some((result) => result.status === 'FAILED')
|
|
139
|
+
? 'FAILED'
|
|
140
|
+
: 'PASSED',
|
|
141
|
+
tests: resultsWithoutEarlierTries.map((r) => ({
|
|
142
|
+
durationSeconds: r.duration_seconds,
|
|
143
|
+
failReason: r.status === 'FAILED'
|
|
144
|
+
? r.fail_reason || 'No reason provided'
|
|
145
|
+
: undefined,
|
|
146
|
+
name: r.test_file_name,
|
|
147
|
+
status: r.status,
|
|
148
|
+
})),
|
|
149
|
+
uploadId,
|
|
150
|
+
};
|
|
151
|
+
if (output.status === 'FAILED') {
|
|
152
|
+
if (debug && logger) {
|
|
153
|
+
logger(`DEBUG: Some tests failed, returning failed status`);
|
|
154
|
+
}
|
|
155
|
+
reject(new RunFailedError(output));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
if (debug && logger) {
|
|
159
|
+
logger(`DEBUG: All tests passed, returning success status`);
|
|
160
|
+
}
|
|
161
|
+
sequentialPollFailures = 0;
|
|
162
|
+
resolve(output);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
sequentialPollFailures++;
|
|
168
|
+
if (debug && logger) {
|
|
169
|
+
logger(`DEBUG: Error polling for results: ${error}`);
|
|
170
|
+
logger(`DEBUG: Sequential poll failures: ${sequentialPollFailures}`);
|
|
171
|
+
}
|
|
172
|
+
if (sequentialPollFailures > this.MAX_SEQUENTIAL_FAILURES) {
|
|
173
|
+
// dropped poll requests shouldn't err user CI
|
|
174
|
+
clearInterval(intervalId);
|
|
175
|
+
// Check if the failure is due to internet connectivity issues
|
|
176
|
+
if (debug && logger) {
|
|
177
|
+
logger('DEBUG: Checking internet connectivity...');
|
|
178
|
+
}
|
|
179
|
+
const connectivityCheck = await (0, connectivity_1.checkInternetConnectivity)();
|
|
180
|
+
if (debug && logger) {
|
|
181
|
+
logger(`DEBUG: ${connectivityCheck.message}`);
|
|
182
|
+
for (const result of connectivityCheck.endpointResults) {
|
|
183
|
+
if (result.success) {
|
|
184
|
+
logger(`DEBUG: ✓ ${result.endpoint} - ${result.statusCode} (${result.latencyMs}ms)`);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
logger(`DEBUG: ✗ ${result.endpoint} - ${result.error} (${result.latencyMs}ms)`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (!connectivityCheck.connected) {
|
|
192
|
+
// Build detailed error message with endpoint diagnostics
|
|
193
|
+
const endpointDetails = connectivityCheck.endpointResults
|
|
194
|
+
.map((r) => ` - ${r.endpoint}: ${r.error} (${r.latencyMs}ms)`)
|
|
195
|
+
.join('\n');
|
|
196
|
+
reject(new Error(`Unable to fetch results after ${this.MAX_SEQUENTIAL_FAILURES} attempts.\n\nInternet connectivity check failed - all test endpoints unreachable:\n${endpointDetails}\n\nPlease verify your network connection and DNS resolution.`));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
reject(new Error(`unable to fetch results after ${this.MAX_SEQUENTIAL_FAILURES} attempts`));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (logger) {
|
|
203
|
+
logger('unable to fetch results, trying again...');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}, this.POLL_INTERVAL_MS);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.ResultsPollingService = ResultsPollingService;
|