@uipath/test-manager-tool 1.206.0-preview.303 → 1.207.0-preview.305
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 +52 -386
- package/dist/{attachment.input-77h243bm.js → attachment.input-e3t82ag2.js} +3 -3
- package/dist/{index-zy5jpz1m.js → index-9m2pakfb.js} +2 -2
- package/dist/index-cwvh8262.js +6 -0
- package/dist/{index-8tsnwy9w.js → index-q9vmbp0w.js} +3 -3
- package/dist/index.js +11 -8
- package/dist/local-test-package-stpgbzs8.js +228 -0
- package/dist/{migration-import-run-as5rrfvn.js → migration-import-run-29hzw92p.js} +17 -421
- package/dist/node-n81k72s2.js +5622 -0
- package/dist/{tool-967s3mts.js → tool-246df0cd.js} +142 -12
- package/dist/{tool-0650qfw3.js → tool-4xdq18pz.js} +389 -163
- package/dist/tool-b24ehgnz.js +9087 -0
- package/dist/tool-begvxz7a.js +1291 -0
- package/dist/tool-bvkzq6jr.js +401 -0
- package/dist/{tool-6mpkbszw.js → tool-f4ytsjzn.js} +6 -4
- package/dist/{tool-s7ja999v.js → tool-fspr1btk.js} +738 -10807
- package/dist/{tool-1nkyed5m.js → tool-hm0kg56c.js} +3 -3
- package/dist/tool-mphfxa9g.js +915 -0
- package/dist/{tool-fz859vt8.js → tool-w2tgc8pr.js} +70 -413
- package/dist/{tool-vgc9gpy6.js → tool-y8kmsg4w.js} +1 -1
- package/dist/tool.js +11 -8
- package/package.json +2 -2
|
@@ -0,0 +1,1291 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getFileSystem,
|
|
3
|
+
catchError,
|
|
4
|
+
RESULTS,
|
|
5
|
+
carriedErrorCode,
|
|
6
|
+
classifyThrownError,
|
|
7
|
+
extractErrorDetails2,
|
|
8
|
+
logger,
|
|
9
|
+
EXIT_CODES,
|
|
10
|
+
exitCodeForResult,
|
|
11
|
+
SuccessOutput,
|
|
12
|
+
OutputFormatter,
|
|
13
|
+
processContext,
|
|
14
|
+
isGuid,
|
|
15
|
+
PollOutcome,
|
|
16
|
+
ErrorDecision,
|
|
17
|
+
pollUntil
|
|
18
|
+
} from "./tool-4xdq18pz.js";
|
|
19
|
+
import {
|
|
20
|
+
FolderDtoFeedTypeEnum2,
|
|
21
|
+
FoldersApi2,
|
|
22
|
+
PackageFeedsApi2,
|
|
23
|
+
ProcessesApi2,
|
|
24
|
+
createApiClient2,
|
|
25
|
+
resolveFolder2
|
|
26
|
+
} from "./tool-246df0cd.js";
|
|
27
|
+
import {
|
|
28
|
+
TERMINAL_STATUSES,
|
|
29
|
+
msToDuration,
|
|
30
|
+
DEFAULT_TEST_CASE_VERSION,
|
|
31
|
+
TM_FORBIDDEN_MESSAGE,
|
|
32
|
+
instructiveError
|
|
33
|
+
} from "./tool-bvkzq6jr.js";
|
|
34
|
+
import {
|
|
35
|
+
UiPathTestManagementHubCommonEnumsObjectType2,
|
|
36
|
+
UiPathTestManagementHubCommonEnumsExecutionType2,
|
|
37
|
+
UiPathTestManagementHubCommonEnumsTestCaseLogExecutionStatus2,
|
|
38
|
+
UiPathTestManagementHubTestManagementAbstractionsEnumsFilterType2,
|
|
39
|
+
TestCaseLogArtifactsApi2,
|
|
40
|
+
TestCaseLogsApi2,
|
|
41
|
+
TestExecutionsApi2,
|
|
42
|
+
TestSetsApi2
|
|
43
|
+
} from "./tool-hm0kg56c.js";
|
|
44
|
+
|
|
45
|
+
// src/mappers/input/testcase.input.ts
|
|
46
|
+
function toGetPackageEntryPointsRequest(projectId, folderKey, distinctByPackageEntryPointIdAndPackageName, search, top, skip, packageNames) {
|
|
47
|
+
return {
|
|
48
|
+
projectId,
|
|
49
|
+
folderKey,
|
|
50
|
+
search,
|
|
51
|
+
top,
|
|
52
|
+
skip,
|
|
53
|
+
distinctByPackageEntryPointIdAndPackageName,
|
|
54
|
+
packageNames
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function toUpdatePackageAutomationRequest(testCaseId, projectId, options) {
|
|
58
|
+
return {
|
|
59
|
+
id: testCaseId,
|
|
60
|
+
projectId,
|
|
61
|
+
uiPathTestManagementHubTestManagementAbstractionsDTOsUpdateTestCasePackageAutomationRequest: {
|
|
62
|
+
packageEntryPointUniqueId: options.packageEntryPointUniqueId,
|
|
63
|
+
packageIdentifier: options.packageIdentifier,
|
|
64
|
+
packageEntryPointName: options.packageEntryPointName,
|
|
65
|
+
folderKey: options.folderKey,
|
|
66
|
+
packageSourceName: options.packageSourceName
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function toStartExecuteRequest(projectId, testCaseIds, options) {
|
|
71
|
+
const hasTargetOptions = options.runtimeType || options.robotUserKey || options.machineKey || options.hostMachineName || options.serviceUserName;
|
|
72
|
+
return {
|
|
73
|
+
projectId,
|
|
74
|
+
executionType: options.executionType,
|
|
75
|
+
asyncMode: options.asyncMode,
|
|
76
|
+
uiPathTestManagementHubTestManagementAbstractionsDTOsCreateTestSetAndStartExecutionRequestDto: {
|
|
77
|
+
testCaseIds,
|
|
78
|
+
...options.name && { name: options.name },
|
|
79
|
+
...options.folderKey && { folderKey: options.folderKey },
|
|
80
|
+
...hasTargetOptions && {
|
|
81
|
+
executionTargetOptions: {
|
|
82
|
+
...options.runtimeType && {
|
|
83
|
+
runtimeType: options.runtimeType
|
|
84
|
+
},
|
|
85
|
+
...options.robotUserKey && {
|
|
86
|
+
robotUserKey: options.robotUserKey
|
|
87
|
+
},
|
|
88
|
+
...options.machineKey && {
|
|
89
|
+
machineKey: options.machineKey
|
|
90
|
+
},
|
|
91
|
+
...options.hostMachineName && {
|
|
92
|
+
hostMachineName: options.hostMachineName
|
|
93
|
+
},
|
|
94
|
+
...options.serviceUserName && {
|
|
95
|
+
serviceUserName: options.serviceUserName
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
...options.testSetPackages && {
|
|
100
|
+
testSetPackages: options.testSetPackages
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/utils/package-automation.ts
|
|
107
|
+
var ENTRY_POINT_PAGE_SIZE = 100;
|
|
108
|
+
var ENTRY_POINT_MAX_PAGES = 50;
|
|
109
|
+
async function resolveAutomationFolder(folderKey, tenant) {
|
|
110
|
+
if (!isGuid(folderKey)) {
|
|
111
|
+
throw instructiveError(`Folder key '${folderKey}' is not a UUID.`, "Pass the folder's Key from 'uip or folders list'.", "invalid_argument");
|
|
112
|
+
}
|
|
113
|
+
const foldersApi = await createApiClient2(FoldersApi2, { tenant });
|
|
114
|
+
const result = await foldersApi.foldersGet({
|
|
115
|
+
$filter: `Key eq ${folderKey}`,
|
|
116
|
+
$top: 1
|
|
117
|
+
});
|
|
118
|
+
const folder = result.value?.[0];
|
|
119
|
+
if (!folder?.displayName) {
|
|
120
|
+
throw instructiveError(`Folder with key '${folderKey}' not found.`, "List the folders you can see with 'uip or folders list' and pass one of their Key values.", "not_found");
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
displayName: folder.displayName,
|
|
124
|
+
linkFolderKey: folder.feedType === FolderDtoFeedTypeEnum2.Processes ? null : folderKey
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function readEntryPointPage(response) {
|
|
128
|
+
if (Array.isArray(response)) {
|
|
129
|
+
return { items: response };
|
|
130
|
+
}
|
|
131
|
+
const record = response ?? {};
|
|
132
|
+
const items = record.data ?? [];
|
|
133
|
+
const paging = record.paging;
|
|
134
|
+
const total = paging?.total ?? record.total;
|
|
135
|
+
return { items, total };
|
|
136
|
+
}
|
|
137
|
+
function matchesPackageName(entryPoint, packageName) {
|
|
138
|
+
return (entryPoint.packageName ?? "").toLowerCase() === packageName.toLowerCase();
|
|
139
|
+
}
|
|
140
|
+
async function fetchPackageEntryPoints(orchestratorApi, projectId, folderKey, search = "") {
|
|
141
|
+
const all = [];
|
|
142
|
+
for (let page = 0;; page++) {
|
|
143
|
+
if (page >= ENTRY_POINT_MAX_PAGES) {
|
|
144
|
+
throw instructiveError(`Folder exposes more than ${ENTRY_POINT_MAX_PAGES * ENTRY_POINT_PAGE_SIZE} test entry points.`, "Narrow the selection with --package-name or --test-name.", "invalid_argument");
|
|
145
|
+
}
|
|
146
|
+
const response = await orchestratorApi.orchestratorGetUniquePackageEntryPoints(toGetPackageEntryPointsRequest(projectId, folderKey ?? undefined, true, search, ENTRY_POINT_PAGE_SIZE, page * ENTRY_POINT_PAGE_SIZE));
|
|
147
|
+
const { items, total } = readEntryPointPage(response);
|
|
148
|
+
all.push(...items);
|
|
149
|
+
if (all.length >= (total ?? all.length) || items.length < ENTRY_POINT_PAGE_SIZE) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return all;
|
|
154
|
+
}
|
|
155
|
+
var TEST_CASE_PAGE_SIZE = 100;
|
|
156
|
+
var TEST_CASE_MAX_PAGES = 100;
|
|
157
|
+
async function fetchTestCasesByName(testCasesApi, projectId) {
|
|
158
|
+
const byName = new Map;
|
|
159
|
+
let rowsRead = 0;
|
|
160
|
+
let reportedTotal;
|
|
161
|
+
const tooMany = () => instructiveError(`Project holds more than ${TEST_CASE_MAX_PAGES * TEST_CASE_PAGE_SIZE} test cases — too many to index for automation linking.`, "Link the automations from a smaller Test Manager project, or use 'uip tm testcases link-automation' per test.", "invalid_argument");
|
|
162
|
+
for (let page = 0;; page++) {
|
|
163
|
+
if (page > TEST_CASE_MAX_PAGES || page === TEST_CASE_MAX_PAGES && reportedTotal !== undefined) {
|
|
164
|
+
throw tooMany();
|
|
165
|
+
}
|
|
166
|
+
const response = await testCasesApi.testCasesGetTestCases({
|
|
167
|
+
projectId,
|
|
168
|
+
top: TEST_CASE_PAGE_SIZE,
|
|
169
|
+
skip: page * TEST_CASE_PAGE_SIZE,
|
|
170
|
+
orderby: "name asc"
|
|
171
|
+
});
|
|
172
|
+
const items = response.data ?? [];
|
|
173
|
+
if (page === TEST_CASE_MAX_PAGES) {
|
|
174
|
+
if (items.length > 0) {
|
|
175
|
+
throw tooMany();
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
rowsRead += items.length;
|
|
180
|
+
for (const testCase of items) {
|
|
181
|
+
const key = (testCase.name ?? "").toLowerCase();
|
|
182
|
+
if (!key || byName.has(key))
|
|
183
|
+
continue;
|
|
184
|
+
byName.set(key, {
|
|
185
|
+
id: testCase.id ?? "",
|
|
186
|
+
objKey: testCase.objKey ?? ""
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
reportedTotal = response.paging?.total ?? reportedTotal;
|
|
190
|
+
if (items.length < TEST_CASE_PAGE_SIZE || reportedTotal !== undefined && rowsRead >= reportedTotal) {
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return byName;
|
|
195
|
+
}
|
|
196
|
+
async function linkPackageEntryPoints(testCasesApi, input) {
|
|
197
|
+
const { projectId, entryPoints, folder, dryRun } = input;
|
|
198
|
+
assertDistinctEntryPointNames(entryPoints);
|
|
199
|
+
const byName = await fetchTestCasesByName(testCasesApi, projectId);
|
|
200
|
+
const rows = [];
|
|
201
|
+
for (const entryPoint of entryPoints) {
|
|
202
|
+
const testName = entryPoint.name ?? "";
|
|
203
|
+
const existing = byName.get(testName.toLowerCase());
|
|
204
|
+
if (dryRun) {
|
|
205
|
+
rows.push(toRow(entryPoint, existing, existing ? "WouldReuse" : "WouldCreate"));
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const [failure, linked] = await catchError(createAndLink(testCasesApi, {
|
|
209
|
+
projectId,
|
|
210
|
+
entryPoint,
|
|
211
|
+
existing,
|
|
212
|
+
folder
|
|
213
|
+
}));
|
|
214
|
+
if (failure) {
|
|
215
|
+
throw wrapLinkFailure(failure, testName, rows.length, entryPoints.length);
|
|
216
|
+
}
|
|
217
|
+
byName.set(testName.toLowerCase(), linked.testCase);
|
|
218
|
+
rows.push(toRow(entryPoint, linked.testCase, linked.action));
|
|
219
|
+
}
|
|
220
|
+
return rows;
|
|
221
|
+
}
|
|
222
|
+
function wrapLinkFailure(failure, testName, done, total) {
|
|
223
|
+
const original = failure;
|
|
224
|
+
const wrapped = new Error(`Linked ${done} of ${total} tests, then failed on '${testName}': ${failure.message}`, { cause: failure });
|
|
225
|
+
if (original.status !== undefined)
|
|
226
|
+
wrapped.status = original.status;
|
|
227
|
+
if (original.response !== undefined)
|
|
228
|
+
wrapped.response = original.response;
|
|
229
|
+
wrapped.instructions = "Run the same command again — test cases that already exist are reused, so it picks up where it stopped.";
|
|
230
|
+
return wrapped;
|
|
231
|
+
}
|
|
232
|
+
function toRow(entryPoint, testCase, action) {
|
|
233
|
+
return {
|
|
234
|
+
TestName: entryPoint.name ?? "",
|
|
235
|
+
PackageName: entryPoint.packageName ?? "",
|
|
236
|
+
PackageVersion: entryPoint.packageAppVersion ?? "",
|
|
237
|
+
TestCaseKey: testCase?.objKey ?? "",
|
|
238
|
+
TestCaseId: testCase?.id ?? "",
|
|
239
|
+
Action: action
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function assertDistinctEntryPointNames(entryPoints) {
|
|
243
|
+
const seen = new Set;
|
|
244
|
+
const collisions = new Set;
|
|
245
|
+
for (const entryPoint of entryPoints) {
|
|
246
|
+
const key = (entryPoint.name ?? "").toLowerCase();
|
|
247
|
+
if (seen.has(key))
|
|
248
|
+
collisions.add(entryPoint.name ?? "");
|
|
249
|
+
seen.add(key);
|
|
250
|
+
}
|
|
251
|
+
if (collisions.size > 0) {
|
|
252
|
+
throw instructiveError(`Test names appear in more than one package: ${[...collisions].join(", ")}. A test case can hold one automation, so linking both would overwrite the first.`, "Pass --package-name to pick which package's tests to link, or --test-name to link the ones that do not collide.", "invalid_argument");
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
async function createAndLink(testCasesApi, input) {
|
|
256
|
+
const { projectId, entryPoint, existing, folder } = input;
|
|
257
|
+
const testName = entryPoint.name ?? "";
|
|
258
|
+
let testCase = existing;
|
|
259
|
+
if (!testCase) {
|
|
260
|
+
const created = await testCasesApi.testCasesCreate({
|
|
261
|
+
projectId,
|
|
262
|
+
uiPathTestManagementHubTestManagementAbstractionsDTOsCreateTestCaseRequest: {
|
|
263
|
+
name: testName,
|
|
264
|
+
description: "",
|
|
265
|
+
projectId,
|
|
266
|
+
version: DEFAULT_TEST_CASE_VERSION
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
testCase = { id: created.id ?? "", objKey: created.objKey ?? "" };
|
|
270
|
+
}
|
|
271
|
+
await testCasesApi.testCasesUpdateTestCasePackageAutomation(toUpdatePackageAutomationRequest(testCase.id, projectId, {
|
|
272
|
+
packageEntryPointUniqueId: entryPoint.packageEntryPointId ?? null,
|
|
273
|
+
packageIdentifier: entryPoint.packageName ?? null,
|
|
274
|
+
packageEntryPointName: testName,
|
|
275
|
+
folderKey: folder.linkFolderKey,
|
|
276
|
+
packageSourceName: folder.displayName
|
|
277
|
+
}));
|
|
278
|
+
return { testCase, action: existing ? "Reused" : "Created" };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/utils/package-version.ts
|
|
282
|
+
var APP_VERSION = /^\d+\.\d+$/;
|
|
283
|
+
var FULL_VERSION = /^\d+(\.\d+){2,3}(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$/;
|
|
284
|
+
function isAppVersion(input) {
|
|
285
|
+
return APP_VERSION.test(input);
|
|
286
|
+
}
|
|
287
|
+
function isFullVersion(input) {
|
|
288
|
+
return FULL_VERSION.test(input);
|
|
289
|
+
}
|
|
290
|
+
function parse(raw) {
|
|
291
|
+
if (!isFullVersion(raw))
|
|
292
|
+
return;
|
|
293
|
+
const withoutBuild = raw.split("+")[0] ?? raw;
|
|
294
|
+
const dash = withoutBuild.indexOf("-");
|
|
295
|
+
const core = dash < 0 ? withoutBuild : withoutBuild.slice(0, dash);
|
|
296
|
+
const prerelease = dash < 0 ? "" : withoutBuild.slice(dash + 1);
|
|
297
|
+
return { numbers: core.split(".").map(Number), prerelease };
|
|
298
|
+
}
|
|
299
|
+
function appVersionOf(version) {
|
|
300
|
+
const [major, minor] = version.split(/[.-]/).map(Number);
|
|
301
|
+
return `${major}.${minor}`;
|
|
302
|
+
}
|
|
303
|
+
function sameVersion(a, b) {
|
|
304
|
+
const length = Math.max(a.numbers.length, b.numbers.length);
|
|
305
|
+
for (let i = 0;i < length; i++) {
|
|
306
|
+
if ((a.numbers[i] ?? 0) !== (b.numbers[i] ?? 0))
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
return a.prerelease.toLowerCase() === b.prerelease.toLowerCase();
|
|
310
|
+
}
|
|
311
|
+
function normalized(version) {
|
|
312
|
+
const numbers = version.numbers.length === 4 && version.numbers[3] === 0 ? version.numbers.slice(0, 3) : version.numbers;
|
|
313
|
+
const core = numbers.join(".");
|
|
314
|
+
return version.prerelease ? `${core}-${version.prerelease}` : core;
|
|
315
|
+
}
|
|
316
|
+
var TRANSIENT_PATCH_EPOCH_MS = Date.UTC(2019, 0, 1);
|
|
317
|
+
function transientVersion(projectVersion, now = new Date) {
|
|
318
|
+
const parsed = parse(projectVersion);
|
|
319
|
+
if (!parsed)
|
|
320
|
+
return;
|
|
321
|
+
const [major, minor] = parsed.numbers;
|
|
322
|
+
const patch = Math.floor((now.getTime() - TRANSIENT_PATCH_EPOCH_MS) / 1000);
|
|
323
|
+
const core = `${major}.${minor}.${patch}`;
|
|
324
|
+
return parsed.prerelease ? `${core}-${parsed.prerelease}` : core;
|
|
325
|
+
}
|
|
326
|
+
async function resolveRunVersion(packageName, input, feed) {
|
|
327
|
+
const listHint = `List the versions with 'uip or packages versions ${packageName}'.`;
|
|
328
|
+
if (isAppVersion(input)) {
|
|
329
|
+
const app = appVersionOf(input);
|
|
330
|
+
const pick = await feed.latest(app, false) ?? await feed.latest(app, true);
|
|
331
|
+
if (pick === undefined) {
|
|
332
|
+
throw instructiveError(`No ${app}.x version of ${packageName} is uploaded.`, listHint, "not_found");
|
|
333
|
+
}
|
|
334
|
+
return pick;
|
|
335
|
+
}
|
|
336
|
+
const requested = parse(input);
|
|
337
|
+
if (!requested) {
|
|
338
|
+
throw instructiveError(`'${input}' is not a package version.`, "Pass an app version such as 1.0, or a full version such as 1.0.244878764.", "invalid_argument");
|
|
339
|
+
}
|
|
340
|
+
const app = appVersionOf(input);
|
|
341
|
+
const notUploaded = () => instructiveError(`Version ${input} of ${packageName} is not uploaded.`, listHint, "not_found");
|
|
342
|
+
const newest = await feed.latest(app, requested.prerelease !== "");
|
|
343
|
+
if (newest === undefined)
|
|
344
|
+
throw notUploaded();
|
|
345
|
+
const parsedNewest = parse(newest);
|
|
346
|
+
if (parsedNewest && sameVersion(parsedNewest, requested))
|
|
347
|
+
return newest;
|
|
348
|
+
if (!await feed.has(normalized(requested)))
|
|
349
|
+
throw notUploaded();
|
|
350
|
+
throw instructiveError(`${packageName} ${input} is not the latest ${app}.x patch (${newest} is). Test Manager always runs the latest patch of an app version.`, `Pass --package-version ${newest}, or --package-version ${app} to run the latest ${app}.x.`, "invalid_argument");
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/mappers/input/testset.input.ts
|
|
354
|
+
function toFilteredTestCasesRequest(projectId, labels, top, skip, ids) {
|
|
355
|
+
return {
|
|
356
|
+
projectId,
|
|
357
|
+
uiPathTestManagementHubTestManagementAbstractionsRequestModelsTestCasesFilterRequestModel: { labels, top, skip, ...ids === undefined ? {} : { ids } }
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function toDynamicTestCasesRequest(projectId, testSetId, top, skip) {
|
|
361
|
+
return {
|
|
362
|
+
projectId,
|
|
363
|
+
uiPathTestManagementHubTestManagementAbstractionsRequestModelsTestCasesFilterRequestModel: {
|
|
364
|
+
projectid: projectId,
|
|
365
|
+
testsetid: testSetId,
|
|
366
|
+
onlyDynamicallyAssigned: true,
|
|
367
|
+
top,
|
|
368
|
+
skip
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function toGetDynamicLabelsRequest(projectId, testSetId) {
|
|
373
|
+
return {
|
|
374
|
+
projectId,
|
|
375
|
+
objectId: testSetId,
|
|
376
|
+
objectType: UiPathTestManagementHubCommonEnumsObjectType2.TestSet,
|
|
377
|
+
filterType: UiPathTestManagementHubTestManagementAbstractionsEnumsFilterType2.TestCasesByLabel
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
function toAssignDynamicLabelsRequest(projectId, testSetId, labels) {
|
|
381
|
+
return {
|
|
382
|
+
projectId,
|
|
383
|
+
objectId: testSetId,
|
|
384
|
+
objectType: UiPathTestManagementHubCommonEnumsObjectType2.TestSet,
|
|
385
|
+
uiPathTestManagementHubTestManagementAbstractionsDTOsCreateObjectFilterRequest: {
|
|
386
|
+
filterType: UiPathTestManagementHubTestManagementAbstractionsEnumsFilterType2.TestCasesByLabel,
|
|
387
|
+
filterExpression: labels
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function toPlaywrightProjectContextRequest(projectId, testSetId) {
|
|
392
|
+
return { id: testSetId, projectId };
|
|
393
|
+
}
|
|
394
|
+
function toUpdateTestSetPackagesRequest(projectId, testSetId, packageName, version, projects) {
|
|
395
|
+
return {
|
|
396
|
+
id: testSetId,
|
|
397
|
+
projectId,
|
|
398
|
+
uiPathTestManagementHubTestManagementAbstractionsDTOsUpdateTestSetPackageRequest: [{ packageName, version, playwrightProjects: projects }]
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function toTransientTestSetRequest(packageName, packageVersion, folderPath, feedId, now = new Date) {
|
|
402
|
+
return {
|
|
403
|
+
name: `CI_${now.toISOString()}_${packageName}_${packageVersion}`,
|
|
404
|
+
description: "uip tm run --type package",
|
|
405
|
+
packageIdentifier: packageName,
|
|
406
|
+
version: packageVersion,
|
|
407
|
+
folderName: folderPath,
|
|
408
|
+
...feedId ? { feedId } : {}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// src/utils/override-parameters.ts
|
|
413
|
+
var FORMAT_HINT = 'The file must be a JSON array like [{"name": "Param", "value": "v"}], with an optional "type" per entry.';
|
|
414
|
+
async function readOverrideParameters(inputPath) {
|
|
415
|
+
const raw = await getFileSystem().readFile(inputPath, "utf-8");
|
|
416
|
+
if (raw === null) {
|
|
417
|
+
throw instructiveError(`Input file '${inputPath}' was not found.`, "Pass the path of an existing JSON file to --input-path.", "invalid_argument");
|
|
418
|
+
}
|
|
419
|
+
let parsed;
|
|
420
|
+
try {
|
|
421
|
+
parsed = JSON.parse(raw);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
throw instructiveError(`Input file '${inputPath}' is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, FORMAT_HINT, "invalid_argument");
|
|
424
|
+
}
|
|
425
|
+
if (!Array.isArray(parsed)) {
|
|
426
|
+
throw instructiveError(`Input file '${inputPath}' must hold a JSON array.`, FORMAT_HINT, "invalid_argument");
|
|
427
|
+
}
|
|
428
|
+
const parameters = parsed.map((entry, index) => toParameter(entry, index, inputPath));
|
|
429
|
+
rejectDuplicates(parameters, inputPath);
|
|
430
|
+
return parameters;
|
|
431
|
+
}
|
|
432
|
+
function rejectDuplicates(parameters, inputPath) {
|
|
433
|
+
const seen = new Set;
|
|
434
|
+
for (const { name } of parameters) {
|
|
435
|
+
const key = name.toLowerCase();
|
|
436
|
+
if (seen.has(key)) {
|
|
437
|
+
throw instructiveError(`Input file '${inputPath}' has more than one entry for "${name}".`, "Keep one entry per input name.", "invalid_argument");
|
|
438
|
+
}
|
|
439
|
+
seen.add(key);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function toParameter(entry, index, inputPath) {
|
|
443
|
+
const bad = (what) => instructiveError(`Entry ${index + 1} in '${inputPath}' ${what}.`, FORMAT_HINT, "invalid_argument");
|
|
444
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
445
|
+
throw bad("is not an object");
|
|
446
|
+
}
|
|
447
|
+
const { name, value, type } = entry;
|
|
448
|
+
if (typeof name !== "string" || name.trim() === "") {
|
|
449
|
+
throw bad('has no "name"');
|
|
450
|
+
}
|
|
451
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
|
|
452
|
+
throw bad(`("${name}") has no "value", or it is not text, a number or true/false`);
|
|
453
|
+
}
|
|
454
|
+
if (type !== undefined && typeof type !== "string") {
|
|
455
|
+
throw bad(`("${name}") has a "type" that is not text`);
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
name: name.trim(),
|
|
459
|
+
value: String(value),
|
|
460
|
+
...type ? { type: type.trim() } : {}
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function matchOverrideParameters(definitions, inputs) {
|
|
464
|
+
if (definitions.length === 0)
|
|
465
|
+
return inputs;
|
|
466
|
+
return definitions.flatMap((def) => {
|
|
467
|
+
const match = inputs.find((p) => isMatch(p, def));
|
|
468
|
+
return match ? [{ name: def.name, type: def.type, value: match.value }] : [];
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
function unmatchedOverrideParameters(definitions, inputs) {
|
|
472
|
+
if (definitions.length === 0)
|
|
473
|
+
return [];
|
|
474
|
+
return inputs.filter((p) => !definitions.some((def) => isMatch(p, def)));
|
|
475
|
+
}
|
|
476
|
+
function isMatch(input, def) {
|
|
477
|
+
return input.name.toLowerCase() === def.name.toLowerCase() && (!input.type || input.type.toLowerCase() === def.type.toLowerCase());
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// src/utils/request-pacer.ts
|
|
481
|
+
var DEFAULTS = {
|
|
482
|
+
maxInFlight: 10,
|
|
483
|
+
lowRemaining: 50,
|
|
484
|
+
maxRetries: 3
|
|
485
|
+
};
|
|
486
|
+
var FALLBACK_WAIT_MS = 5000;
|
|
487
|
+
var MAX_WAIT_MS = 300000;
|
|
488
|
+
|
|
489
|
+
class RequestPacer {
|
|
490
|
+
maxInFlight;
|
|
491
|
+
lowRemaining;
|
|
492
|
+
maxRetries;
|
|
493
|
+
leftMs;
|
|
494
|
+
limit;
|
|
495
|
+
active = 0;
|
|
496
|
+
successes = 0;
|
|
497
|
+
pausedUntil = 0;
|
|
498
|
+
waiters = [];
|
|
499
|
+
constructor(options = {}) {
|
|
500
|
+
this.maxInFlight = options.maxInFlight ?? DEFAULTS.maxInFlight;
|
|
501
|
+
this.lowRemaining = options.lowRemaining ?? DEFAULTS.lowRemaining;
|
|
502
|
+
this.maxRetries = options.maxRetries ?? DEFAULTS.maxRetries;
|
|
503
|
+
this.leftMs = options.leftMs ?? (() => Number.POSITIVE_INFINITY);
|
|
504
|
+
this.limit = this.maxInFlight;
|
|
505
|
+
}
|
|
506
|
+
get currentLimit() {
|
|
507
|
+
return this.limit;
|
|
508
|
+
}
|
|
509
|
+
async run(call) {
|
|
510
|
+
for (let attempt = 0;; attempt++) {
|
|
511
|
+
await this.acquire();
|
|
512
|
+
const [error, result] = await catchError(call());
|
|
513
|
+
this.release();
|
|
514
|
+
if (!error) {
|
|
515
|
+
this.onSuccess(result.headers);
|
|
516
|
+
return result.value;
|
|
517
|
+
}
|
|
518
|
+
const waitMs = rateLimitWaitMs(error);
|
|
519
|
+
if (waitMs === undefined || attempt >= this.maxRetries) {
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
if (this.leftMs() < waitMs) {
|
|
523
|
+
logger.debug("Rate limited, and the time budget cannot cover the wait; giving up on this request");
|
|
524
|
+
throw error;
|
|
525
|
+
}
|
|
526
|
+
this.onRateLimited(waitMs);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
async acquire() {
|
|
530
|
+
for (;; ) {
|
|
531
|
+
const pause = this.pausedUntil - Date.now();
|
|
532
|
+
if (pause > 0) {
|
|
533
|
+
if (this.leftMs() < pause)
|
|
534
|
+
throw new PacerBudgetError;
|
|
535
|
+
await sleep(pause);
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
if (this.active < this.limit) {
|
|
539
|
+
this.active++;
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
await new Promise((resolve) => this.waiters.push(resolve));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
release() {
|
|
546
|
+
this.active--;
|
|
547
|
+
const waiting = this.waiters;
|
|
548
|
+
this.waiters = [];
|
|
549
|
+
for (const wake of waiting)
|
|
550
|
+
wake();
|
|
551
|
+
}
|
|
552
|
+
onSuccess(headers) {
|
|
553
|
+
const remaining = Number(headers?.get("RateLimit-Remaining"));
|
|
554
|
+
if (headers?.has("RateLimit-Remaining") && remaining < this.lowRemaining) {
|
|
555
|
+
if (this.limit !== 1) {
|
|
556
|
+
logger.debug(`Only ${remaining} calls left in the rate-limit window; slowing to one at a time`);
|
|
557
|
+
}
|
|
558
|
+
this.limit = 1;
|
|
559
|
+
this.successes = 0;
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
this.successes++;
|
|
563
|
+
if (this.limit < this.maxInFlight && this.successes >= this.limit) {
|
|
564
|
+
this.limit++;
|
|
565
|
+
this.successes = 0;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
onRateLimited(waitMs) {
|
|
569
|
+
const until = Date.now() + waitMs + jitterMs(250);
|
|
570
|
+
this.pausedUntil = Math.max(this.pausedUntil, until);
|
|
571
|
+
this.limit = 1;
|
|
572
|
+
this.successes = 0;
|
|
573
|
+
logger.debug(`Rate limited by Test Manager; pausing ${Math.round(waitMs / 1000)}s, then resuming one at a time`);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
class PacerBudgetError extends Error {
|
|
578
|
+
constructor() {
|
|
579
|
+
super("Rate limited by Test Manager, and the time budget cannot cover the wait.");
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function rateLimitWaitMs(error) {
|
|
583
|
+
const response = error?.response;
|
|
584
|
+
if (response?.status !== 429)
|
|
585
|
+
return;
|
|
586
|
+
const headers = response.headers;
|
|
587
|
+
const reset = Number(headers.get("RateLimit-Reset"));
|
|
588
|
+
if (headers.has("RateLimit-Reset") && Number.isFinite(reset) && reset >= 0) {
|
|
589
|
+
return Math.min(reset * 1000, MAX_WAIT_MS);
|
|
590
|
+
}
|
|
591
|
+
const retryAfter = headers.get("Retry-After");
|
|
592
|
+
if (retryAfter) {
|
|
593
|
+
const seconds = Number(retryAfter);
|
|
594
|
+
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
595
|
+
return Math.min(seconds * 1000, MAX_WAIT_MS);
|
|
596
|
+
}
|
|
597
|
+
const date = Date.parse(retryAfter);
|
|
598
|
+
if (!Number.isNaN(date)) {
|
|
599
|
+
return Math.min(Math.max(0, date - Date.now()), MAX_WAIT_MS);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return FALLBACK_WAIT_MS;
|
|
603
|
+
}
|
|
604
|
+
function jitterMs(max) {
|
|
605
|
+
const value = new Uint32Array(1);
|
|
606
|
+
globalThis.crypto.getRandomValues(value);
|
|
607
|
+
return (value[0] ?? 0) % max;
|
|
608
|
+
}
|
|
609
|
+
function sleep(ms) {
|
|
610
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// src/utils/test-report.ts
|
|
614
|
+
async function buildExecutionReport(tmConfig, projectId, executionId, options = {}) {
|
|
615
|
+
logger.debug(`Fetching execution stats for ${executionId}`);
|
|
616
|
+
const stats = await new TestExecutionsApi2(tmConfig).testExecutionsGetByIdWithStats({ id: executionId, projectId });
|
|
617
|
+
const testSetName = stats.name ?? executionId;
|
|
618
|
+
const testSetId = stats.testSetId ?? "";
|
|
619
|
+
logger.debug(`Execution: '${testSetName}', status: ${stats.status}`);
|
|
620
|
+
logger.debug("Fetching test case logs");
|
|
621
|
+
const allLogs = await fetchAllTestCaseLogs(new TestCaseLogsApi2(tmConfig), projectId, executionId);
|
|
622
|
+
const artifactsApi = new TestCaseLogArtifactsApi2(tmConfig);
|
|
623
|
+
const skipsAssertions = (log) => options.assertionsFor === "notPassed" && log.result === "Passed";
|
|
624
|
+
const pacer = new RequestPacer({ leftMs: options.leftMs });
|
|
625
|
+
const assertionsNotRead = [];
|
|
626
|
+
const testCaseExecutions = await Promise.all(allLogs.map(async (log) => {
|
|
627
|
+
if (skipsAssertions(log))
|
|
628
|
+
return toTestCaseRun(log, []);
|
|
629
|
+
const assertions = options.leftMs && options.leftMs() <= 0 ? undefined : await readAssertions(artifactsApi, pacer, projectId, log);
|
|
630
|
+
const run = toTestCaseRun(log, assertions ?? []);
|
|
631
|
+
if (assertions === undefined)
|
|
632
|
+
assertionsNotRead.push(run.Name);
|
|
633
|
+
return run;
|
|
634
|
+
}));
|
|
635
|
+
logger.debug(`Fetched ${allLogs.length} test case log(s)`);
|
|
636
|
+
const packages = options.packages ? options.packages : await fetchTestSetPackages(new TestSetsApi2(tmConfig), projectId, testSetId);
|
|
637
|
+
const folderName = options.folderName ?? await lookUpFolderName(stats.folderKey, options.tenant);
|
|
638
|
+
const passed = countStatus(testCaseExecutions, "Passed");
|
|
639
|
+
const failed = countStatus(testCaseExecutions, "Failed");
|
|
640
|
+
const cancelled = countStatus(testCaseExecutions, "Cancelled");
|
|
641
|
+
const testSetRun = {
|
|
642
|
+
Id: executionId,
|
|
643
|
+
TestSetKey: stats.testSetObjKey ?? testSetId,
|
|
644
|
+
Name: testSetName,
|
|
645
|
+
FolderName: folderName,
|
|
646
|
+
TestCasesCount: testCaseExecutions.length,
|
|
647
|
+
FailuresCount: failed,
|
|
648
|
+
ErrorsCount: 0,
|
|
649
|
+
CanceledCount: cancelled,
|
|
650
|
+
DurationMs: stats.duration ?? 0,
|
|
651
|
+
StartTime: stats.executionStart?.toISOString() ?? new Date().toISOString(),
|
|
652
|
+
Packages: packages,
|
|
653
|
+
Status: stats.status?.toString() ?? "Unknown",
|
|
654
|
+
TestCaseExecutions: testCaseExecutions
|
|
655
|
+
};
|
|
656
|
+
return {
|
|
657
|
+
report: { TestManagerTestSetRuns: [testSetRun] },
|
|
658
|
+
testSetName,
|
|
659
|
+
total: testCaseExecutions.length,
|
|
660
|
+
passed,
|
|
661
|
+
failed,
|
|
662
|
+
cancelled,
|
|
663
|
+
expectedTotal: (stats.passed ?? 0) + (stats.failed ?? 0) + (stats.none ?? 0),
|
|
664
|
+
assertionsNotRead
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
function countStatus(runs, status) {
|
|
668
|
+
return runs.filter((run) => run.Status === status).length;
|
|
669
|
+
}
|
|
670
|
+
async function readAssertions(artifactsApi, pacer, projectId, log) {
|
|
671
|
+
const [error, raw] = await catchError(pacer.run(async () => {
|
|
672
|
+
const response = await artifactsApi.testCaseLogArtifactsGetAssertionsRaw({
|
|
673
|
+
id: log.id ?? "",
|
|
674
|
+
projectId
|
|
675
|
+
});
|
|
676
|
+
return {
|
|
677
|
+
value: await response.value(),
|
|
678
|
+
headers: response.raw.headers
|
|
679
|
+
};
|
|
680
|
+
}));
|
|
681
|
+
if (error) {
|
|
682
|
+
logger.debug(`Could not read the assertions of test case log ${log.id}: ${error.message}`);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
return raw.map((a) => ({
|
|
686
|
+
Message: a.message ?? "",
|
|
687
|
+
Succeeded: a.succeeded ?? true
|
|
688
|
+
}));
|
|
689
|
+
}
|
|
690
|
+
function statusOf(log) {
|
|
691
|
+
const result = log.result ?? "Unknown";
|
|
692
|
+
if (result === "Passed" || result === "Failed")
|
|
693
|
+
return result;
|
|
694
|
+
const status = String(log.status ?? "").toLowerCase();
|
|
695
|
+
if (status === UiPathTestManagementHubCommonEnumsTestCaseLogExecutionStatus2.Cancelled) {
|
|
696
|
+
return "Cancelled";
|
|
697
|
+
}
|
|
698
|
+
if (status === UiPathTestManagementHubCommonEnumsTestCaseLogExecutionStatus2.Failed) {
|
|
699
|
+
return "Failed";
|
|
700
|
+
}
|
|
701
|
+
return result;
|
|
702
|
+
}
|
|
703
|
+
function toTestCaseRun(log, assertions) {
|
|
704
|
+
const logId = log.id ?? "";
|
|
705
|
+
const tc = log.testCase;
|
|
706
|
+
let durationMs = 0;
|
|
707
|
+
if (log.executionStart && log.executionEnd) {
|
|
708
|
+
durationMs = log.executionEnd.getTime() - log.executionStart.getTime();
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
Id: logId,
|
|
712
|
+
TestCaseId: log.testCaseId ?? "",
|
|
713
|
+
Name: tc?.packageEntryPointName ?? tc?.name ?? log.automationTestCaseName ?? "Unknown",
|
|
714
|
+
Status: statusOf(log),
|
|
715
|
+
JobKey: log.jobKey ?? "",
|
|
716
|
+
Assertions: assertions,
|
|
717
|
+
Info: log.info ?? "",
|
|
718
|
+
PackageIdentifier: tc?.packageIdentifier ?? "",
|
|
719
|
+
StartTime: log.executionStart?.toISOString() ?? new Date().toISOString(),
|
|
720
|
+
DurationMs: durationMs,
|
|
721
|
+
DataVariationIdentifier: log.variationId ?? "",
|
|
722
|
+
EntryPointPath: tc?.packageEntryPointName ?? "",
|
|
723
|
+
VersionNumber: log.testCaseVersion ?? tc?.packageVersion ?? "",
|
|
724
|
+
InputArguments: log.inputArguments ?? "",
|
|
725
|
+
OutputArguments: log.outputArguments ?? ""
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
async function lookUpFolderName(folderKey, tenant) {
|
|
729
|
+
if (!folderKey)
|
|
730
|
+
return "";
|
|
731
|
+
const { resolveFolder } = await import("./index-q9vmbp0w.js");
|
|
732
|
+
const [error, folder] = await catchError(resolveFolder({ folderKey }, { tenant }));
|
|
733
|
+
if (error) {
|
|
734
|
+
logger.debug(`Could not read folder ${folderKey} for the report: ${error.message}`);
|
|
735
|
+
return "";
|
|
736
|
+
}
|
|
737
|
+
return folder?.path ?? "";
|
|
738
|
+
}
|
|
739
|
+
async function fetchAllTestCaseLogs(api, projectId, testExecutionId) {
|
|
740
|
+
const byId = new Map;
|
|
741
|
+
const top = 50;
|
|
742
|
+
let skip = 0;
|
|
743
|
+
while (true) {
|
|
744
|
+
const page = await api.testCaseLogsGetTestCaseLogsByTestExecutionId({
|
|
745
|
+
testExecutionId,
|
|
746
|
+
projectId,
|
|
747
|
+
top,
|
|
748
|
+
skip,
|
|
749
|
+
orderby: "Id asc"
|
|
750
|
+
});
|
|
751
|
+
const items = page.data ?? [];
|
|
752
|
+
for (const item of items)
|
|
753
|
+
byId.set(item.id ?? `#${byId.size}`, item);
|
|
754
|
+
const hasNextPage = page.paging?.nextPage === true;
|
|
755
|
+
if (!hasNextPage || items.length < top)
|
|
756
|
+
break;
|
|
757
|
+
skip += top;
|
|
758
|
+
}
|
|
759
|
+
const endOf = (log) => log.executionEnd?.getTime() ?? Number.NEGATIVE_INFINITY;
|
|
760
|
+
return [...byId.values()].sort((a, b) => {
|
|
761
|
+
const left = endOf(a);
|
|
762
|
+
const right = endOf(b);
|
|
763
|
+
if (left === right)
|
|
764
|
+
return 0;
|
|
765
|
+
return left < right ? 1 : -1;
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
async function fetchTestSetPackages(api, projectId, testSetId) {
|
|
769
|
+
if (!testSetId)
|
|
770
|
+
return [];
|
|
771
|
+
const [err, result] = await catchError(api.testSetsGetTestSetPackages({ id: testSetId, projectId }));
|
|
772
|
+
if (err)
|
|
773
|
+
return [];
|
|
774
|
+
return result.map((p) => ({
|
|
775
|
+
Name: p.packageName ?? "",
|
|
776
|
+
Version: p.version ?? ""
|
|
777
|
+
}));
|
|
778
|
+
}
|
|
779
|
+
async function fetchRetryableTestCaseLogIds(api, projectId, testExecutionId) {
|
|
780
|
+
const failed = await fetchTestCaseLogIds(api, projectId, testExecutionId, {
|
|
781
|
+
onlyFailed: true
|
|
782
|
+
});
|
|
783
|
+
const cancelled = await fetchTestCaseLogIds(api, projectId, testExecutionId, {
|
|
784
|
+
statuses: [
|
|
785
|
+
UiPathTestManagementHubCommonEnumsTestCaseLogExecutionStatus2.Cancelled
|
|
786
|
+
]
|
|
787
|
+
});
|
|
788
|
+
return [...new Set([...failed, ...cancelled])];
|
|
789
|
+
}
|
|
790
|
+
async function fetchTestCaseLogIds(api, projectId, testExecutionId, filter) {
|
|
791
|
+
const ids = [];
|
|
792
|
+
const top = 50;
|
|
793
|
+
let skip = 0;
|
|
794
|
+
while (true) {
|
|
795
|
+
const page = await api.testCaseLogsGetTestCaseLogsByTestExecutionId({
|
|
796
|
+
testExecutionId,
|
|
797
|
+
projectId,
|
|
798
|
+
...filter,
|
|
799
|
+
top,
|
|
800
|
+
skip
|
|
801
|
+
});
|
|
802
|
+
const typedPage = page;
|
|
803
|
+
const items = typedPage.data ?? [];
|
|
804
|
+
for (const item of items) {
|
|
805
|
+
if (typeof item.id === "string" && item.id.length > 0) {
|
|
806
|
+
ids.push(item.id);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
const hasNextPage = typedPage.paging?.nextPage === true;
|
|
810
|
+
if (!hasNextPage || items.length < top)
|
|
811
|
+
break;
|
|
812
|
+
skip += top;
|
|
813
|
+
}
|
|
814
|
+
return ids;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// src/utils/wait-for-execution.ts
|
|
818
|
+
var DEFAULT_TIMEOUT_MS = 1800000;
|
|
819
|
+
var DEFAULT_INTERVAL_MS = 60000;
|
|
820
|
+
var MAX_EXECUTION_TIMEOUT_S = 7 * 24 * 3600;
|
|
821
|
+
function pollExecution(executionId, options) {
|
|
822
|
+
const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
823
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
824
|
+
const executionsApi = new TestExecutionsApi2(options.tmConfig);
|
|
825
|
+
return pollUntil({
|
|
826
|
+
fn: () => executionsApi.testExecutionsGetByIdWithStats({
|
|
827
|
+
id: executionId,
|
|
828
|
+
projectId: options.projectId
|
|
829
|
+
}),
|
|
830
|
+
until: (stats) => TERMINAL_STATUSES.has((stats.status ?? "pending").toLowerCase()) && (options.minRunId === undefined || (stats.runId ?? 0) >= options.minRunId),
|
|
831
|
+
getStatus: (stats) => stats.status ?? "pending",
|
|
832
|
+
label: `execution ${executionId}`,
|
|
833
|
+
logPrefix: "wait",
|
|
834
|
+
intervalMs,
|
|
835
|
+
timeoutMs,
|
|
836
|
+
logIntervalMs: intervalMs,
|
|
837
|
+
maxConsecutiveErrors: 3,
|
|
838
|
+
onError: stopOnPermanentError,
|
|
839
|
+
signal: processContext.pollSignal
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
function stopOnPermanentError(error) {
|
|
843
|
+
return classifyThrownError(error).retry === "RetryWillNotFix" ? ErrorDecision.Abort : undefined;
|
|
844
|
+
}
|
|
845
|
+
async function reportPollError(error) {
|
|
846
|
+
const failure = await extractErrorDetails2(error, {
|
|
847
|
+
forbiddenMessage: TM_FORBIDDEN_MESSAGE
|
|
848
|
+
});
|
|
849
|
+
OutputFormatter.error({
|
|
850
|
+
Result: failure.result,
|
|
851
|
+
ErrorCode: failure.errorCode,
|
|
852
|
+
Message: failure.message,
|
|
853
|
+
Instructions: failure.details,
|
|
854
|
+
Retry: failure.retry
|
|
855
|
+
});
|
|
856
|
+
processContext.exit(exitCodeForResult(failure.result));
|
|
857
|
+
}
|
|
858
|
+
function reportTerminalExecution(executionId, stats, successCode) {
|
|
859
|
+
const status = stats.status ?? "pending";
|
|
860
|
+
const passed = stats.passed ?? 0;
|
|
861
|
+
const failed = stats.failed ?? 0;
|
|
862
|
+
const none = stats.none ?? 0;
|
|
863
|
+
const data = {
|
|
864
|
+
ExecutionId: executionId,
|
|
865
|
+
Status: status,
|
|
866
|
+
EndTime: stats.executionFinished?.toISOString() ?? new Date().toISOString(),
|
|
867
|
+
Duration: msToDuration(stats.duration ?? 0),
|
|
868
|
+
Passed: passed,
|
|
869
|
+
Failed: failed,
|
|
870
|
+
None: none
|
|
871
|
+
};
|
|
872
|
+
const cancelled = status.toLowerCase() === "cancelled";
|
|
873
|
+
if (!cancelled && failed === 0) {
|
|
874
|
+
OutputFormatter.success(new SuccessOutput(successCode, data));
|
|
875
|
+
processContext.exit(0);
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
const project = stats.projectId ? ` --project-id ${stats.projectId}` : "";
|
|
879
|
+
const logs = `uip tm executions testcaselogs list --execution-id ${executionId}${project}`;
|
|
880
|
+
const report = `download a JUnit report with 'uip tm result download --execution-id ${executionId}${project}'`;
|
|
881
|
+
OutputFormatter.error({
|
|
882
|
+
Result: RESULTS.Failure,
|
|
883
|
+
Code: cancelled ? "ExecutionCancelled" : "ExecutionTestsFailed",
|
|
884
|
+
ErrorCode: "execution_failed",
|
|
885
|
+
Message: cancelled ? `Execution '${executionId}' was cancelled.` : `${failed} of ${passed + failed + none} tests failed in execution '${executionId}'.`,
|
|
886
|
+
Instructions: cancelled ? `See which tests got a result with '${logs}', or ${report}.` : `List the failed tests with '${logs} --results Failed', or ${report}.`,
|
|
887
|
+
Retry: "RetryWillNotFix",
|
|
888
|
+
Data: data
|
|
889
|
+
});
|
|
890
|
+
processContext.exit(1);
|
|
891
|
+
}
|
|
892
|
+
async function handleExecutionWait(executionId, options) {
|
|
893
|
+
const [pollError, result] = await catchError(pollExecution(executionId, options));
|
|
894
|
+
if (pollError) {
|
|
895
|
+
const { message, details } = await extractErrorDetails2(pollError, {
|
|
896
|
+
forbiddenMessage: TM_FORBIDDEN_MESSAGE
|
|
897
|
+
});
|
|
898
|
+
OutputFormatter.error({
|
|
899
|
+
Result: "Failure",
|
|
900
|
+
Message: message,
|
|
901
|
+
Instructions: details
|
|
902
|
+
});
|
|
903
|
+
processContext.exit(1);
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
if (result.outcome === PollOutcome.Completed) {
|
|
907
|
+
if (!result.data) {
|
|
908
|
+
OutputFormatter.error({
|
|
909
|
+
Result: "Failure",
|
|
910
|
+
Message: `Execution '${executionId}' completed but returned no data.`,
|
|
911
|
+
Instructions: "Check execution status manually."
|
|
912
|
+
});
|
|
913
|
+
processContext.exit(1);
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
reportTerminalExecution(executionId, result.data, "ExecutionWaitComplete");
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
const timedOut = result.outcome === PollOutcome.Timeout;
|
|
920
|
+
if (!timedOut && result.error) {
|
|
921
|
+
await reportPollError(result.error);
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
const lastStatus = result.data?.status ?? "unknown";
|
|
925
|
+
const messages = {
|
|
926
|
+
[PollOutcome.Timeout]: `Timed out after ${Math.round(result.elapsedMs / 1000)}s. Last status: ${lastStatus}`,
|
|
927
|
+
[PollOutcome.Interrupted]: `Interrupted. Last status: ${lastStatus}`
|
|
928
|
+
};
|
|
929
|
+
OutputFormatter.error({
|
|
930
|
+
Result: timedOut ? RESULTS.TimeoutError : RESULTS.Failure,
|
|
931
|
+
...timedOut ? { ErrorCode: "timeout" } : {},
|
|
932
|
+
Message: messages[result.outcome] ?? `Polling failed for execution '${executionId}'.`,
|
|
933
|
+
Instructions: timedOut ? "Increase --timeout or check the execution status manually." : "Check execution status manually."
|
|
934
|
+
});
|
|
935
|
+
processContext.exit(timedOut ? EXIT_CODES.TimeoutError : 1);
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// src/utils/run-package.ts
|
|
939
|
+
var PACKAGE_LOOKUP_INTERVAL_MS = 5000;
|
|
940
|
+
var PACKAGE_WAIT_MAX_MS = 5 * 60000;
|
|
941
|
+
function cappedWait(remainingMs, capMs) {
|
|
942
|
+
return remainingMs === 0 ? capMs : Math.min(remainingMs, capMs);
|
|
943
|
+
}
|
|
944
|
+
var TRANSIENT_CREATION_INTERVAL_MS = 1e4;
|
|
945
|
+
var RETRY_START_DELAY_MS = 1e4;
|
|
946
|
+
var RETRY_MIN_MARGIN_MS = 30000;
|
|
947
|
+
var RETRY_START_ATTEMPTS = 3;
|
|
948
|
+
var EXECUTION_TYPE = UiPathTestManagementHubCommonEnumsExecutionType2.Automated;
|
|
949
|
+
var STARTED_RUN = Symbol("startedRun");
|
|
950
|
+
var RUN_MAY_HAVE_STARTED = Symbol("runMayHaveStarted");
|
|
951
|
+
function tagStartedRun(error, started) {
|
|
952
|
+
return Object.assign(error, { [STARTED_RUN]: started });
|
|
953
|
+
}
|
|
954
|
+
function startedRunOf(error) {
|
|
955
|
+
const tagged = error?.[STARTED_RUN];
|
|
956
|
+
if (tagged)
|
|
957
|
+
return tagged;
|
|
958
|
+
if (error instanceof RunPackageTimeoutError && error.executionId !== undefined) {
|
|
959
|
+
const started = {
|
|
960
|
+
executionId: error.executionId,
|
|
961
|
+
retries: error.retries ?? 0
|
|
962
|
+
};
|
|
963
|
+
tagStartedRun(error, started);
|
|
964
|
+
return started;
|
|
965
|
+
}
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
function runMayHaveStarted(error) {
|
|
969
|
+
return Boolean(error?.[RUN_MAY_HAVE_STARTED]);
|
|
970
|
+
}
|
|
971
|
+
function tagRunMayHaveStarted(error) {
|
|
972
|
+
return Object.assign(error, { [RUN_MAY_HAVE_STARTED]: true });
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
class RunPackageTimeoutError extends Error {
|
|
976
|
+
phase;
|
|
977
|
+
instructions;
|
|
978
|
+
executionId;
|
|
979
|
+
retries;
|
|
980
|
+
reportPath;
|
|
981
|
+
constructor(phase, instructions) {
|
|
982
|
+
super(`Timed out while ${phase}.`);
|
|
983
|
+
this.phase = phase;
|
|
984
|
+
this.instructions = instructions;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
class Deadline {
|
|
989
|
+
timeoutMs;
|
|
990
|
+
endsAt;
|
|
991
|
+
constructor(timeoutMs) {
|
|
992
|
+
this.timeoutMs = timeoutMs;
|
|
993
|
+
this.endsAt = timeoutMs > 0 ? Date.now() + timeoutMs : 0;
|
|
994
|
+
}
|
|
995
|
+
leftMs() {
|
|
996
|
+
if (this.endsAt === 0)
|
|
997
|
+
return Number.POSITIVE_INFINITY;
|
|
998
|
+
return Math.max(0, this.endsAt - Date.now());
|
|
999
|
+
}
|
|
1000
|
+
remainingMs(phase, instructions) {
|
|
1001
|
+
if (this.endsAt === 0)
|
|
1002
|
+
return 0;
|
|
1003
|
+
const left = this.endsAt - Date.now();
|
|
1004
|
+
if (left <= 0)
|
|
1005
|
+
throw new RunPackageTimeoutError(phase, instructions);
|
|
1006
|
+
return left;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
var FOLDERS_WITH_OWN_FEED = new Set([
|
|
1010
|
+
FolderDtoFeedTypeEnum2.FolderHierarchy,
|
|
1011
|
+
FolderDtoFeedTypeEnum2.PersonalWorkspace
|
|
1012
|
+
]);
|
|
1013
|
+
async function resolveRunFolder(input, tenant) {
|
|
1014
|
+
const folderLabel = input.folderPath ?? input.folderKey ?? "";
|
|
1015
|
+
const [lookupError, folder] = await catchError(fromOrchestrator("read the folder", folderLabel, resolveFolder2(input, { tenant })));
|
|
1016
|
+
if (lookupError) {
|
|
1017
|
+
if (!isNotFound(lookupError))
|
|
1018
|
+
throw lookupError;
|
|
1019
|
+
throw instructiveError(`Folder '${folderLabel}' not found.`, "List the folders you can see with 'uip or folders list' and pass one of their FullyQualifiedName or Key values.", "not_found");
|
|
1020
|
+
}
|
|
1021
|
+
if (!folder) {
|
|
1022
|
+
throw instructiveError("No folder given.", "Pass --folder-path (e.g. Shared) or --folder-key.", "invalid_argument");
|
|
1023
|
+
}
|
|
1024
|
+
if (!FOLDERS_WITH_OWN_FEED.has(folder.feedType)) {
|
|
1025
|
+
return { path: folder.path, key: folder.key };
|
|
1026
|
+
}
|
|
1027
|
+
const feedsApi = await createApiClient2(PackageFeedsApi2, { tenant });
|
|
1028
|
+
const feedId = await fromOrchestrator("read the folder's package feed", folder.path, feedsApi.packageFeedsGetFolderFeed({ folderId: folder.id }));
|
|
1029
|
+
return {
|
|
1030
|
+
path: folder.path,
|
|
1031
|
+
key: folder.key,
|
|
1032
|
+
...feedId ? { feedId } : {}
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
async function resolvePackageVersion(packageName, input, folder, tenant) {
|
|
1036
|
+
const processesApi = await createApiClient2(ProcessesApi2, {
|
|
1037
|
+
tenant,
|
|
1038
|
+
...folder.feedId ? { folderKey: folder.key } : {}
|
|
1039
|
+
});
|
|
1040
|
+
const highest = async (filter) => {
|
|
1041
|
+
const response = await fromOrchestrator(`list the versions of ${packageName}`, folder.path, processesApi.processesGetProcessVersionsByProcessid({
|
|
1042
|
+
processId: packageName,
|
|
1043
|
+
feedId: folder.feedId,
|
|
1044
|
+
$filter: filter,
|
|
1045
|
+
$orderby: "Version desc",
|
|
1046
|
+
$top: 1,
|
|
1047
|
+
$select: "Version"
|
|
1048
|
+
}));
|
|
1049
|
+
return response.value?.[0]?.version ?? undefined;
|
|
1050
|
+
};
|
|
1051
|
+
const resolved = await resolveRunVersion(packageName, input, {
|
|
1052
|
+
latest: (appVersion, prerelease) => highest(`startswith(Version,'${appVersion}.') and ${prerelease ? "" : "not "}contains(Version,'-')`),
|
|
1053
|
+
has: async (version) => await highest(`Version eq '${version.replace(/'/g, "''")}'`) !== undefined
|
|
1054
|
+
});
|
|
1055
|
+
logger.debug(`Package version ${input} resolves to ${resolved}`);
|
|
1056
|
+
return resolved;
|
|
1057
|
+
}
|
|
1058
|
+
async function resolveUploadedPackageVersion(packageName, input, folder, tenant, deadline) {
|
|
1059
|
+
const resolveVisibleVersion = async () => {
|
|
1060
|
+
let [error, resolved] = await catchError(resolvePackageVersion(packageName, input, folder, tenant));
|
|
1061
|
+
if (!error)
|
|
1062
|
+
return { version: resolved };
|
|
1063
|
+
if (carriedErrorCode(error) === "invalid_argument") {
|
|
1064
|
+
[error, resolved] = await catchError(resolvePackageVersion(packageName, input, folder, tenant));
|
|
1065
|
+
if (!error)
|
|
1066
|
+
return { version: resolved };
|
|
1067
|
+
}
|
|
1068
|
+
if (carriedErrorCode(error) === "not_found") {
|
|
1069
|
+
return {};
|
|
1070
|
+
}
|
|
1071
|
+
if (classifyThrownError(error).retry !== "RetryWillNotFix")
|
|
1072
|
+
throw error;
|
|
1073
|
+
return { error };
|
|
1074
|
+
};
|
|
1075
|
+
const label = `${packageName} ${input}`;
|
|
1076
|
+
const instructions = `Orchestrator accepted ${label} but has not indexed it yet. Wait a few minutes and run again.`;
|
|
1077
|
+
logger.debug(`Checking Orchestrator for uploaded package ${label}`);
|
|
1078
|
+
const result = await pollUntil({
|
|
1079
|
+
fn: resolveVisibleVersion,
|
|
1080
|
+
until: (probe) => probe.version !== undefined || probe.error !== undefined,
|
|
1081
|
+
label: `uploaded package ${label}`,
|
|
1082
|
+
logPrefix: "run",
|
|
1083
|
+
intervalMs: PACKAGE_LOOKUP_INTERVAL_MS,
|
|
1084
|
+
timeoutMs: cappedWait(deadline.remainingMs("waiting for the uploaded package", instructions), PACKAGE_WAIT_MAX_MS),
|
|
1085
|
+
maxConsecutiveErrors: 3,
|
|
1086
|
+
signal: processContext.pollSignal
|
|
1087
|
+
});
|
|
1088
|
+
assertCompleted(result, "waiting for the uploaded package", instructions);
|
|
1089
|
+
if (result.data?.error)
|
|
1090
|
+
throw result.data.error;
|
|
1091
|
+
if (result.data?.version === undefined) {
|
|
1092
|
+
throw instructiveError(`Orchestrator reported ${label} without a version.`, instructions, "server_error");
|
|
1093
|
+
}
|
|
1094
|
+
return result.data.version;
|
|
1095
|
+
}
|
|
1096
|
+
function isNotFound(error) {
|
|
1097
|
+
const status = error.response?.status;
|
|
1098
|
+
return status === 404 || error.message.startsWith("Folder not found");
|
|
1099
|
+
}
|
|
1100
|
+
async function fromOrchestrator(what, folderLabel, call) {
|
|
1101
|
+
const [error, result] = await catchError(call);
|
|
1102
|
+
if (!error)
|
|
1103
|
+
return result;
|
|
1104
|
+
const status = error.response?.status;
|
|
1105
|
+
if (status !== 403)
|
|
1106
|
+
throw error;
|
|
1107
|
+
throw instructiveError(`Orchestrator refused to ${what} (403).`, `The login needs Orchestrator access: OrchestratorApiUserAccess, or the OR.Folders.Read and OR.Execution (or OR.Execution.Read) scopes, and a role on folder '${folderLabel}' that can view folders and packages. 'uip login status --detailed' shows the scopes.`, "permission_denied");
|
|
1108
|
+
}
|
|
1109
|
+
async function waitForPackageInTestManager(api, pkg, folder, deadline) {
|
|
1110
|
+
const label = `${pkg.packageName} ${pkg.packageVersion}`;
|
|
1111
|
+
const instructions = `Test Manager has not indexed ${label}, although Orchestrator has it. Wait a few minutes and run again; if it persists, check the package in Test Manager.`;
|
|
1112
|
+
const lookup = () => api.isPackageAvailable({
|
|
1113
|
+
packageIdentifier: pkg.packageName,
|
|
1114
|
+
version: pkg.packageVersion,
|
|
1115
|
+
feedId: folder.feedId
|
|
1116
|
+
});
|
|
1117
|
+
const [probeError, available] = await catchError(lookup());
|
|
1118
|
+
if (probeError)
|
|
1119
|
+
throw probeError;
|
|
1120
|
+
if (available)
|
|
1121
|
+
return;
|
|
1122
|
+
logger.debug(`Waiting for Test Manager to see package ${label}`);
|
|
1123
|
+
const result = await pollUntil({
|
|
1124
|
+
fn: lookup,
|
|
1125
|
+
until: (available) => available,
|
|
1126
|
+
label: `package ${label}`,
|
|
1127
|
+
logPrefix: "run",
|
|
1128
|
+
intervalMs: PACKAGE_LOOKUP_INTERVAL_MS,
|
|
1129
|
+
timeoutMs: cappedWait(deadline.remainingMs("waiting for the package", instructions), PACKAGE_WAIT_MAX_MS),
|
|
1130
|
+
maxConsecutiveErrors: 3,
|
|
1131
|
+
signal: processContext.pollSignal
|
|
1132
|
+
});
|
|
1133
|
+
assertCompleted(result, "waiting for the package", instructions);
|
|
1134
|
+
}
|
|
1135
|
+
async function createTransientTestSet(api, projectId, pkg, folder, deadline) {
|
|
1136
|
+
const request = toTransientTestSetRequest(pkg.packageName, pkg.packageVersion, folder.path, folder.feedId);
|
|
1137
|
+
const instructions = "Run again with a larger --timeout. A package with many tests takes longer to turn into test cases.";
|
|
1138
|
+
deadline.remainingMs("creating the test set", instructions);
|
|
1139
|
+
logger.debug(`Creating test set '${request.name}'`);
|
|
1140
|
+
const testSetId = await api.createTransientTestSet(projectId, request);
|
|
1141
|
+
const result = await pollUntil({
|
|
1142
|
+
fn: () => api.getCreationStatus(projectId, testSetId),
|
|
1143
|
+
until: (status) => status === "Created" || status === "Failed",
|
|
1144
|
+
getStatus: (status) => status ?? "Unknown",
|
|
1145
|
+
label: `test set ${testSetId}`,
|
|
1146
|
+
logPrefix: "run",
|
|
1147
|
+
intervalMs: TRANSIENT_CREATION_INTERVAL_MS,
|
|
1148
|
+
timeoutMs: deadline.remainingMs("creating the test set", instructions),
|
|
1149
|
+
maxConsecutiveErrors: 3,
|
|
1150
|
+
signal: processContext.pollSignal
|
|
1151
|
+
});
|
|
1152
|
+
assertCompleted(result, "creating the test set", instructions);
|
|
1153
|
+
if (result.data === "Failed") {
|
|
1154
|
+
throw instructiveError(`Test Manager could not create the test set for ${pkg.packageName} ${pkg.packageVersion}.`, `This happens when a newer ${appVersionOf(pkg.packageVersion)}.x patch was uploaded after the run started, or when the package has no tests. Run again, or check the package in folder '${folder.path}'.`, "server_error");
|
|
1155
|
+
}
|
|
1156
|
+
return testSetId;
|
|
1157
|
+
}
|
|
1158
|
+
async function applyInputOverrides(api, projectId, testSetId, inputs) {
|
|
1159
|
+
if (inputs.length === 0)
|
|
1160
|
+
return { applied: 0, ignored: [], declared: [] };
|
|
1161
|
+
const definitions = await api.getParameters(projectId, testSetId);
|
|
1162
|
+
const unmatched = unmatchedOverrideParameters(definitions, inputs);
|
|
1163
|
+
if (unmatched.length > 0) {
|
|
1164
|
+
logger.warn(`No test in the package declares ${unmatched.map((p) => `'${p.name}'`).join(", ")}; ${unmatched.length === 1 ? "it was" : "they were"} not applied. Declared: ${definitions.map((d) => d.name).join(", ")}.`);
|
|
1165
|
+
}
|
|
1166
|
+
const overrides = matchOverrideParameters(definitions, inputs);
|
|
1167
|
+
if (overrides.length > 0) {
|
|
1168
|
+
await api.overrideParameters(projectId, testSetId, overrides);
|
|
1169
|
+
}
|
|
1170
|
+
logger.debug(`Applied ${overrides.length} parameter override(s)`);
|
|
1171
|
+
return {
|
|
1172
|
+
applied: overrides.length,
|
|
1173
|
+
ignored: unmatched.map((p) => p.name),
|
|
1174
|
+
declared: definitions.map((d) => d.name)
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
async function runAndRetry(api, testSetId, maxRetries, options) {
|
|
1178
|
+
options.deadline.remainingMs("starting the tests", "Run again with a larger --timeout.");
|
|
1179
|
+
const [startError, execution] = await catchError(new TestSetsApi2(options.tmConfig).testSetsStartExecute({
|
|
1180
|
+
id: testSetId,
|
|
1181
|
+
projectId: options.projectId,
|
|
1182
|
+
executionType: EXECUTION_TYPE,
|
|
1183
|
+
asyncMode: true
|
|
1184
|
+
}));
|
|
1185
|
+
if (startError) {
|
|
1186
|
+
const status = startError.response?.status;
|
|
1187
|
+
if (typeof status !== "number" || status >= 200 && status < 300 || status === 408 || status >= 500) {
|
|
1188
|
+
throw tagRunMayHaveStarted(startError);
|
|
1189
|
+
}
|
|
1190
|
+
throw startError;
|
|
1191
|
+
}
|
|
1192
|
+
const executionId = execution.id;
|
|
1193
|
+
if (!executionId) {
|
|
1194
|
+
throw tagRunMayHaveStarted(instructiveError("Test Manager started the run but returned no execution id.", "Check the project's executions in Test Manager.", "server_error"));
|
|
1195
|
+
}
|
|
1196
|
+
logger.debug(`Execution started: ${executionId}`);
|
|
1197
|
+
let retries = 0;
|
|
1198
|
+
const [error, stats] = await catchError((async () => {
|
|
1199
|
+
let latest = await waitForExecution(executionId, options);
|
|
1200
|
+
while (retries < maxRetries && !allPassed(latest)) {
|
|
1201
|
+
if (!hasTimeForRetry(options)) {
|
|
1202
|
+
logger.warn("Not enough of --timeout is left to re-run the failed tests; reporting the last result.");
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
const previousRunId = latest.runId;
|
|
1206
|
+
const started = await retryFailed(api, executionId, options);
|
|
1207
|
+
if (!started)
|
|
1208
|
+
break;
|
|
1209
|
+
retries++;
|
|
1210
|
+
logger.debug(`Retry ${retries} of ${maxRetries} started`);
|
|
1211
|
+
if (previousRunId === undefined) {
|
|
1212
|
+
await sleep2(Math.min(RETRY_START_DELAY_MS, options.deadline.leftMs()));
|
|
1213
|
+
}
|
|
1214
|
+
latest = await waitForExecution(executionId, options, previousRunId === undefined ? undefined : previousRunId + 1);
|
|
1215
|
+
}
|
|
1216
|
+
return latest;
|
|
1217
|
+
})());
|
|
1218
|
+
if (error) {
|
|
1219
|
+
if (error instanceof RunPackageTimeoutError) {
|
|
1220
|
+
error.executionId = executionId;
|
|
1221
|
+
error.retries = retries;
|
|
1222
|
+
}
|
|
1223
|
+
throw tagStartedRun(error, { executionId, retries });
|
|
1224
|
+
}
|
|
1225
|
+
return { executionId, stats, retries };
|
|
1226
|
+
}
|
|
1227
|
+
function allPassed(stats) {
|
|
1228
|
+
return (stats.failed ?? 0) === 0 && (stats.none ?? 0) === 0;
|
|
1229
|
+
}
|
|
1230
|
+
function hasTimeForRetry(options) {
|
|
1231
|
+
return options.deadline.leftMs() >= options.intervalMs + RETRY_MIN_MARGIN_MS;
|
|
1232
|
+
}
|
|
1233
|
+
async function retryFailed(api, executionId, options) {
|
|
1234
|
+
const retryIds = await fetchRetryableTestCaseLogIds(new TestCaseLogsApi2(options.tmConfig), options.projectId, executionId);
|
|
1235
|
+
if (retryIds.length === 0)
|
|
1236
|
+
return false;
|
|
1237
|
+
for (let attempt = 1;; attempt++) {
|
|
1238
|
+
options.deadline.remainingMs("re-running the failed tests", `Check execution ${executionId} in Test Manager, or run again with a larger --timeout.`);
|
|
1239
|
+
const [error] = await catchError(async () => {
|
|
1240
|
+
await api.executeTestCaseLogs(options.projectId, executionId, {
|
|
1241
|
+
executionType: EXECUTION_TYPE,
|
|
1242
|
+
testCaseLogIds: retryIds
|
|
1243
|
+
});
|
|
1244
|
+
});
|
|
1245
|
+
if (!error)
|
|
1246
|
+
return true;
|
|
1247
|
+
if (attempt >= RETRY_START_ATTEMPTS || !isTransient(error))
|
|
1248
|
+
throw error;
|
|
1249
|
+
logger.debug(`Starting the re-run failed (attempt ${attempt} of ${RETRY_START_ATTEMPTS}); trying again`);
|
|
1250
|
+
await sleep2(Math.min(options.intervalMs, options.deadline.leftMs()));
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
function isTransient(error) {
|
|
1254
|
+
const status = error?.response?.status;
|
|
1255
|
+
return status === 429 || status === 503;
|
|
1256
|
+
}
|
|
1257
|
+
async function waitForExecution(executionId, options, minRunId) {
|
|
1258
|
+
const instructions = `The tests may still be running. Check execution ${executionId} in Test Manager, or run again with a larger --timeout.`;
|
|
1259
|
+
const result = await pollExecution(executionId, {
|
|
1260
|
+
tmConfig: options.tmConfig,
|
|
1261
|
+
projectId: options.projectId,
|
|
1262
|
+
intervalMs: options.intervalMs,
|
|
1263
|
+
timeoutMs: options.deadline.remainingMs("waiting for the tests", instructions),
|
|
1264
|
+
minRunId
|
|
1265
|
+
});
|
|
1266
|
+
assertCompleted(result, "waiting for the tests", instructions);
|
|
1267
|
+
if (!result.data) {
|
|
1268
|
+
throw instructiveError(`Execution '${executionId}' finished but returned no data.`, "Check the execution in Test Manager.", "server_error");
|
|
1269
|
+
}
|
|
1270
|
+
return result.data;
|
|
1271
|
+
}
|
|
1272
|
+
function assertCompleted(result, phase, instructions) {
|
|
1273
|
+
if (result.outcome === PollOutcome.Completed)
|
|
1274
|
+
return;
|
|
1275
|
+
if (result.outcome === PollOutcome.Timeout) {
|
|
1276
|
+
throw new RunPackageTimeoutError(phase, instructions);
|
|
1277
|
+
}
|
|
1278
|
+
if (result.error)
|
|
1279
|
+
throw result.error;
|
|
1280
|
+
if (result.outcome === PollOutcome.Failed) {
|
|
1281
|
+
throw new Error(`Polling failed while ${phase}.`);
|
|
1282
|
+
}
|
|
1283
|
+
throw instructiveError(`Stopped while ${phase}.`, instructions, "unknown_error");
|
|
1284
|
+
}
|
|
1285
|
+
function sleep2(ms) {
|
|
1286
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
export { buildExecutionReport, toGetPackageEntryPointsRequest, toUpdatePackageAutomationRequest, toStartExecuteRequest, resolveAutomationFolder, matchesPackageName, fetchPackageEntryPoints, linkPackageEntryPoints, readOverrideParameters, matchOverrideParameters, isAppVersion, isFullVersion, transientVersion, toFilteredTestCasesRequest, toDynamicTestCasesRequest, toGetDynamicLabelsRequest, toAssignDynamicLabelsRequest, toPlaywrightProjectContextRequest, toUpdateTestSetPackagesRequest, DEFAULT_TIMEOUT_MS, DEFAULT_INTERVAL_MS, MAX_EXECUTION_TIMEOUT_S, stopOnPermanentError, reportPollError, reportTerminalExecution, handleExecutionWait, startedRunOf, runMayHaveStarted, RunPackageTimeoutError, Deadline, resolveRunFolder, resolvePackageVersion, resolveUploadedPackageVersion, waitForPackageInTestManager, createTransientTestSet, applyInputOverrides, runAndRetry };
|
|
1290
|
+
|
|
1291
|
+
//# debugId=5366C23A46960D5B64756E2164756E21
|