@flakiness/sdk 0.95.0
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/LICENSE +45 -0
- package/README.md +30 -0
- package/lib/cli/cli.js +1435 -0
- package/lib/cli/cmd-convert.js +413 -0
- package/lib/cli/cmd-download.js +494 -0
- package/lib/cli/cmd-link.js +463 -0
- package/lib/cli/cmd-login.js +414 -0
- package/lib/cli/cmd-logout.js +378 -0
- package/lib/cli/cmd-serve.js +7 -0
- package/lib/cli/cmd-status.js +460 -0
- package/lib/cli/cmd-unlink.js +166 -0
- package/lib/cli/cmd-upload-playwright-json.js +818 -0
- package/lib/cli/cmd-upload.js +512 -0
- package/lib/cli/cmd-whoami.js +387 -0
- package/lib/createTestStepSnippets.js +32 -0
- package/lib/flakinessLink.js +161 -0
- package/lib/flakinessSession.js +373 -0
- package/lib/junit.js +311 -0
- package/lib/playwright-test.js +933 -0
- package/lib/playwrightJSONReport.js +432 -0
- package/lib/reportUploader.js +447 -0
- package/lib/serverapi.js +331 -0
- package/lib/systemUtilizationSampler.js +71 -0
- package/lib/utils.js +323 -0
- package/package.json +58 -0
- package/types/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli/cmd-upload.ts
|
|
4
|
+
import { FlakinessReport } from "@flakiness/report";
|
|
5
|
+
import fs2 from "fs/promises";
|
|
6
|
+
import path from "path";
|
|
7
|
+
|
|
8
|
+
// src/reportUploader.ts
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import { URL as URL2 } from "url";
|
|
11
|
+
import { brotliCompressSync as brotliCompressSync2 } from "zlib";
|
|
12
|
+
|
|
13
|
+
// ../server/lib/common/typedHttp.js
|
|
14
|
+
var TypedHTTP;
|
|
15
|
+
((TypedHTTP2) => {
|
|
16
|
+
TypedHTTP2.StatusCodes = {
|
|
17
|
+
Informational: {
|
|
18
|
+
CONTINUE: 100,
|
|
19
|
+
SWITCHING_PROTOCOLS: 101,
|
|
20
|
+
PROCESSING: 102,
|
|
21
|
+
EARLY_HINTS: 103
|
|
22
|
+
},
|
|
23
|
+
Success: {
|
|
24
|
+
OK: 200,
|
|
25
|
+
CREATED: 201,
|
|
26
|
+
ACCEPTED: 202,
|
|
27
|
+
NON_AUTHORITATIVE_INFORMATION: 203,
|
|
28
|
+
NO_CONTENT: 204,
|
|
29
|
+
RESET_CONTENT: 205,
|
|
30
|
+
PARTIAL_CONTENT: 206,
|
|
31
|
+
MULTI_STATUS: 207
|
|
32
|
+
},
|
|
33
|
+
Redirection: {
|
|
34
|
+
MULTIPLE_CHOICES: 300,
|
|
35
|
+
MOVED_PERMANENTLY: 301,
|
|
36
|
+
MOVED_TEMPORARILY: 302,
|
|
37
|
+
SEE_OTHER: 303,
|
|
38
|
+
NOT_MODIFIED: 304,
|
|
39
|
+
USE_PROXY: 305,
|
|
40
|
+
TEMPORARY_REDIRECT: 307,
|
|
41
|
+
PERMANENT_REDIRECT: 308
|
|
42
|
+
},
|
|
43
|
+
ClientErrors: {
|
|
44
|
+
BAD_REQUEST: 400,
|
|
45
|
+
UNAUTHORIZED: 401,
|
|
46
|
+
PAYMENT_REQUIRED: 402,
|
|
47
|
+
FORBIDDEN: 403,
|
|
48
|
+
NOT_FOUND: 404,
|
|
49
|
+
METHOD_NOT_ALLOWED: 405,
|
|
50
|
+
NOT_ACCEPTABLE: 406,
|
|
51
|
+
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
52
|
+
REQUEST_TIMEOUT: 408,
|
|
53
|
+
CONFLICT: 409,
|
|
54
|
+
GONE: 410,
|
|
55
|
+
LENGTH_REQUIRED: 411,
|
|
56
|
+
PRECONDITION_FAILED: 412,
|
|
57
|
+
REQUEST_TOO_LONG: 413,
|
|
58
|
+
REQUEST_URI_TOO_LONG: 414,
|
|
59
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
60
|
+
REQUESTED_RANGE_NOT_SATISFIABLE: 416,
|
|
61
|
+
EXPECTATION_FAILED: 417,
|
|
62
|
+
IM_A_TEAPOT: 418,
|
|
63
|
+
INSUFFICIENT_SPACE_ON_RESOURCE: 419,
|
|
64
|
+
METHOD_FAILURE: 420,
|
|
65
|
+
MISDIRECTED_REQUEST: 421,
|
|
66
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
67
|
+
LOCKED: 423,
|
|
68
|
+
FAILED_DEPENDENCY: 424,
|
|
69
|
+
UPGRADE_REQUIRED: 426,
|
|
70
|
+
PRECONDITION_REQUIRED: 428,
|
|
71
|
+
TOO_MANY_REQUESTS: 429,
|
|
72
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
73
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451
|
|
74
|
+
},
|
|
75
|
+
ServerErrors: {
|
|
76
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
77
|
+
NOT_IMPLEMENTED: 501,
|
|
78
|
+
BAD_GATEWAY: 502,
|
|
79
|
+
SERVICE_UNAVAILABLE: 503,
|
|
80
|
+
GATEWAY_TIMEOUT: 504,
|
|
81
|
+
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
82
|
+
INSUFFICIENT_STORAGE: 507,
|
|
83
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const AllErrorCodes = {
|
|
87
|
+
...TypedHTTP2.StatusCodes.ClientErrors,
|
|
88
|
+
...TypedHTTP2.StatusCodes.ServerErrors
|
|
89
|
+
};
|
|
90
|
+
class HttpError extends Error {
|
|
91
|
+
constructor(status, message) {
|
|
92
|
+
super(message);
|
|
93
|
+
this.status = status;
|
|
94
|
+
}
|
|
95
|
+
static withCode(code, message) {
|
|
96
|
+
const statusCode = AllErrorCodes[code];
|
|
97
|
+
const defaultMessage = code.split("_").map((word) => word.charAt(0) + word.slice(1).toLowerCase()).join(" ");
|
|
98
|
+
return new HttpError(statusCode, message ?? defaultMessage);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
TypedHTTP2.HttpError = HttpError;
|
|
102
|
+
function isInformationalResponse(response) {
|
|
103
|
+
return response.status >= 100 && response.status < 200;
|
|
104
|
+
}
|
|
105
|
+
TypedHTTP2.isInformationalResponse = isInformationalResponse;
|
|
106
|
+
function isSuccessResponse(response) {
|
|
107
|
+
return response.status >= 200 && response.status < 300;
|
|
108
|
+
}
|
|
109
|
+
TypedHTTP2.isSuccessResponse = isSuccessResponse;
|
|
110
|
+
function isRedirectResponse(response) {
|
|
111
|
+
return response.status >= 300 && response.status < 400;
|
|
112
|
+
}
|
|
113
|
+
TypedHTTP2.isRedirectResponse = isRedirectResponse;
|
|
114
|
+
function isErrorResponse(response) {
|
|
115
|
+
return response.status >= 400 && response.status < 600;
|
|
116
|
+
}
|
|
117
|
+
TypedHTTP2.isErrorResponse = isErrorResponse;
|
|
118
|
+
function info(status) {
|
|
119
|
+
return { status };
|
|
120
|
+
}
|
|
121
|
+
TypedHTTP2.info = info;
|
|
122
|
+
function ok(data, status) {
|
|
123
|
+
return {
|
|
124
|
+
status: status ?? TypedHTTP2.StatusCodes.Success.OK,
|
|
125
|
+
data
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
TypedHTTP2.ok = ok;
|
|
129
|
+
function redirect(url, status = 302) {
|
|
130
|
+
return { status, url };
|
|
131
|
+
}
|
|
132
|
+
TypedHTTP2.redirect = redirect;
|
|
133
|
+
function error(message, status = TypedHTTP2.StatusCodes.ServerErrors.INTERNAL_SERVER_ERROR) {
|
|
134
|
+
return { status, message };
|
|
135
|
+
}
|
|
136
|
+
TypedHTTP2.error = error;
|
|
137
|
+
class Router {
|
|
138
|
+
constructor(_resolveContext) {
|
|
139
|
+
this._resolveContext = _resolveContext;
|
|
140
|
+
}
|
|
141
|
+
static create() {
|
|
142
|
+
return new Router(async (e) => e.ctx);
|
|
143
|
+
}
|
|
144
|
+
rawMethod(method, route) {
|
|
145
|
+
return {
|
|
146
|
+
[method]: {
|
|
147
|
+
method,
|
|
148
|
+
input: route.input,
|
|
149
|
+
etag: route.etag,
|
|
150
|
+
resolveContext: this._resolveContext,
|
|
151
|
+
handler: route.handler
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
get(route) {
|
|
156
|
+
return this.rawMethod("GET", {
|
|
157
|
+
...route,
|
|
158
|
+
handler: (...args) => Promise.resolve(route.handler(...args)).then((result) => TypedHTTP2.ok(result))
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
post(route) {
|
|
162
|
+
return this.rawMethod("POST", {
|
|
163
|
+
...route,
|
|
164
|
+
handler: (...args) => Promise.resolve(route.handler(...args)).then((result) => TypedHTTP2.ok(result))
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
use(resolveContext) {
|
|
168
|
+
return new Router(async (options) => {
|
|
169
|
+
const m = await this._resolveContext(options);
|
|
170
|
+
return resolveContext({ ...options, ctx: m });
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
TypedHTTP2.Router = Router;
|
|
175
|
+
function createClient(base, fetchCallback) {
|
|
176
|
+
function buildUrl(path2, input, options) {
|
|
177
|
+
const method = path2.at(-1);
|
|
178
|
+
const url = new URL(path2.slice(0, path2.length - 1).join("/"), base);
|
|
179
|
+
const signal = options?.signal;
|
|
180
|
+
let body = void 0;
|
|
181
|
+
if (method === "GET" && input)
|
|
182
|
+
url.searchParams.set("input", JSON.stringify(input));
|
|
183
|
+
else if (method !== "GET" && input)
|
|
184
|
+
body = JSON.stringify(input);
|
|
185
|
+
return {
|
|
186
|
+
url,
|
|
187
|
+
method,
|
|
188
|
+
headers: body ? { "Content-Type": "application/json" } : void 0,
|
|
189
|
+
body,
|
|
190
|
+
signal
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function createProxy(path2 = []) {
|
|
194
|
+
return new Proxy(() => {
|
|
195
|
+
}, {
|
|
196
|
+
get(target, prop) {
|
|
197
|
+
if (typeof prop === "symbol")
|
|
198
|
+
return void 0;
|
|
199
|
+
if (prop === "prepare")
|
|
200
|
+
return (input, options) => buildUrl(path2, input, options);
|
|
201
|
+
const newPath = [...path2, prop];
|
|
202
|
+
return createProxy(newPath);
|
|
203
|
+
},
|
|
204
|
+
apply(target, thisArg, args) {
|
|
205
|
+
const options = buildUrl(path2, args[0], args[1]);
|
|
206
|
+
return fetchCallback(options.url, {
|
|
207
|
+
method: options.method,
|
|
208
|
+
body: options.body,
|
|
209
|
+
headers: options.headers,
|
|
210
|
+
signal: options.signal
|
|
211
|
+
}).then(async (response) => {
|
|
212
|
+
if (response.status >= 200 && response.status < 300) {
|
|
213
|
+
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
214
|
+
const text = await response.text();
|
|
215
|
+
return text.length ? JSON.parse(text) : void 0;
|
|
216
|
+
}
|
|
217
|
+
return await response.blob();
|
|
218
|
+
}
|
|
219
|
+
if (response.status >= 400 && response.status < 600) {
|
|
220
|
+
const text = await response.text();
|
|
221
|
+
if (text)
|
|
222
|
+
throw new Error(`HTTP request failed with status ${response.status}: ${text}`);
|
|
223
|
+
else
|
|
224
|
+
throw new Error(`HTTP request failed with status ${response.status}`);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return createProxy();
|
|
231
|
+
}
|
|
232
|
+
TypedHTTP2.createClient = createClient;
|
|
233
|
+
})(TypedHTTP || (TypedHTTP = {}));
|
|
234
|
+
|
|
235
|
+
// src/utils.ts
|
|
236
|
+
import http from "http";
|
|
237
|
+
import https from "https";
|
|
238
|
+
import util from "util";
|
|
239
|
+
import zlib from "zlib";
|
|
240
|
+
var gzipAsync = util.promisify(zlib.gzip);
|
|
241
|
+
var gunzipAsync = util.promisify(zlib.gunzip);
|
|
242
|
+
var gunzipSync = zlib.gunzipSync;
|
|
243
|
+
var brotliCompressAsync = util.promisify(zlib.brotliCompress);
|
|
244
|
+
var brotliCompressSync = zlib.brotliCompressSync;
|
|
245
|
+
async function retryWithBackoff(job, backoff = []) {
|
|
246
|
+
for (const timeout of backoff) {
|
|
247
|
+
try {
|
|
248
|
+
return await job();
|
|
249
|
+
} catch (e) {
|
|
250
|
+
if (e instanceof AggregateError)
|
|
251
|
+
console.error(`[flakiness.io err]`, e.errors[0].message);
|
|
252
|
+
else if (e instanceof Error)
|
|
253
|
+
console.error(`[flakiness.io err]`, e.message);
|
|
254
|
+
else
|
|
255
|
+
console.error(`[flakiness.io err]`, e);
|
|
256
|
+
await new Promise((x) => setTimeout(x, timeout));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return await job();
|
|
260
|
+
}
|
|
261
|
+
var httpUtils;
|
|
262
|
+
((httpUtils2) => {
|
|
263
|
+
function createRequest({ url, method = "get", headers = {} }) {
|
|
264
|
+
let resolve;
|
|
265
|
+
let reject;
|
|
266
|
+
const responseDataPromise = new Promise((a, b) => {
|
|
267
|
+
resolve = a;
|
|
268
|
+
reject = b;
|
|
269
|
+
});
|
|
270
|
+
const protocol = url.startsWith("https") ? https : http;
|
|
271
|
+
const request = protocol.request(url, { method, headers }, (res) => {
|
|
272
|
+
const chunks = [];
|
|
273
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
274
|
+
res.on("end", () => {
|
|
275
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
|
|
276
|
+
resolve(Buffer.concat(chunks));
|
|
277
|
+
else
|
|
278
|
+
reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
|
|
279
|
+
});
|
|
280
|
+
res.on("error", (error) => reject(error));
|
|
281
|
+
});
|
|
282
|
+
request.on("error", reject);
|
|
283
|
+
return { request, responseDataPromise };
|
|
284
|
+
}
|
|
285
|
+
httpUtils2.createRequest = createRequest;
|
|
286
|
+
async function getBuffer(url, backoff) {
|
|
287
|
+
return await retryWithBackoff(async () => {
|
|
288
|
+
const { request, responseDataPromise } = createRequest({ url });
|
|
289
|
+
request.end();
|
|
290
|
+
return await responseDataPromise;
|
|
291
|
+
}, backoff);
|
|
292
|
+
}
|
|
293
|
+
httpUtils2.getBuffer = getBuffer;
|
|
294
|
+
async function getText(url, backoff) {
|
|
295
|
+
const buffer = await getBuffer(url, backoff);
|
|
296
|
+
return buffer.toString("utf-8");
|
|
297
|
+
}
|
|
298
|
+
httpUtils2.getText = getText;
|
|
299
|
+
async function getJSON(url) {
|
|
300
|
+
return JSON.parse(await getText(url));
|
|
301
|
+
}
|
|
302
|
+
httpUtils2.getJSON = getJSON;
|
|
303
|
+
async function postText(url, text, backoff) {
|
|
304
|
+
const headers = {
|
|
305
|
+
"Content-Type": "application/json",
|
|
306
|
+
"Content-Length": Buffer.byteLength(text) + ""
|
|
307
|
+
};
|
|
308
|
+
return await retryWithBackoff(async () => {
|
|
309
|
+
const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
|
|
310
|
+
request.write(text);
|
|
311
|
+
request.end();
|
|
312
|
+
return await responseDataPromise;
|
|
313
|
+
}, backoff);
|
|
314
|
+
}
|
|
315
|
+
httpUtils2.postText = postText;
|
|
316
|
+
async function postJSON(url, json, backoff) {
|
|
317
|
+
const buffer = await postText(url, JSON.stringify(json), backoff);
|
|
318
|
+
return JSON.parse(buffer.toString("utf-8"));
|
|
319
|
+
}
|
|
320
|
+
httpUtils2.postJSON = postJSON;
|
|
321
|
+
})(httpUtils || (httpUtils = {}));
|
|
322
|
+
var ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", "g");
|
|
323
|
+
var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
|
|
324
|
+
var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
|
|
325
|
+
|
|
326
|
+
// src/serverapi.ts
|
|
327
|
+
function createServerAPI(endpoint, options) {
|
|
328
|
+
endpoint += "/api/";
|
|
329
|
+
const fetcher = options?.auth ? (url, init) => fetch(url, {
|
|
330
|
+
...init,
|
|
331
|
+
headers: {
|
|
332
|
+
...init.headers,
|
|
333
|
+
"Authorization": `Bearer ${options.auth}`
|
|
334
|
+
}
|
|
335
|
+
}) : fetch;
|
|
336
|
+
if (options?.retries)
|
|
337
|
+
return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
|
|
338
|
+
return TypedHTTP.createClient(endpoint, fetcher);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/reportUploader.ts
|
|
342
|
+
var ReportUploader = class _ReportUploader {
|
|
343
|
+
static optionsFromEnv(overrides) {
|
|
344
|
+
const flakinessAccessToken = overrides?.flakinessAccessToken ?? process.env["FLAKINESS_ACCESS_TOKEN"];
|
|
345
|
+
if (!flakinessAccessToken)
|
|
346
|
+
return void 0;
|
|
347
|
+
const flakinessEndpoint = overrides?.flakinessEndpoint ?? process.env["FLAKINESS_ENDPOINT"] ?? "https://flakiness.io";
|
|
348
|
+
return { flakinessAccessToken, flakinessEndpoint };
|
|
349
|
+
}
|
|
350
|
+
static async upload(options) {
|
|
351
|
+
const uploaderOptions = _ReportUploader.optionsFromEnv(options);
|
|
352
|
+
if (!uploaderOptions) {
|
|
353
|
+
options.log?.(`[flakiness.io] Uploading skipped since no FLAKINESS_ACCESS_TOKEN is specified`);
|
|
354
|
+
return void 0;
|
|
355
|
+
}
|
|
356
|
+
const uploader = new _ReportUploader(uploaderOptions);
|
|
357
|
+
const upload = uploader.createUpload(options.report, options.attachments);
|
|
358
|
+
const uploadResult = await upload.upload();
|
|
359
|
+
if (!uploadResult.success) {
|
|
360
|
+
options.log?.(`[flakiness.io] X Failed to upload to ${uploaderOptions.flakinessEndpoint}: ${uploadResult.message}`);
|
|
361
|
+
return { errorMessage: uploadResult.message };
|
|
362
|
+
}
|
|
363
|
+
options.log?.(`[flakiness.io] \u2713 Report uploaded ${uploadResult.message ?? ""}`);
|
|
364
|
+
if (uploadResult.reportUrl)
|
|
365
|
+
options.log?.(`[flakiness.io] ${uploadResult.reportUrl}`);
|
|
366
|
+
}
|
|
367
|
+
_options;
|
|
368
|
+
constructor(options) {
|
|
369
|
+
this._options = options;
|
|
370
|
+
}
|
|
371
|
+
createUpload(report, attachments) {
|
|
372
|
+
const upload = new ReportUpload(this._options, report, attachments);
|
|
373
|
+
return upload;
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
var HTTP_BACKOFF = [100, 500, 1e3, 1e3, 1e3, 1e3];
|
|
377
|
+
var ReportUpload = class {
|
|
378
|
+
_report;
|
|
379
|
+
_attachments;
|
|
380
|
+
_options;
|
|
381
|
+
_api;
|
|
382
|
+
constructor(options, report, attachments) {
|
|
383
|
+
this._options = options;
|
|
384
|
+
this._report = report;
|
|
385
|
+
this._attachments = attachments;
|
|
386
|
+
this._api = createServerAPI(this._options.flakinessEndpoint, { retries: HTTP_BACKOFF });
|
|
387
|
+
}
|
|
388
|
+
async upload(options) {
|
|
389
|
+
const response = await this._api.run.startUpload.POST({
|
|
390
|
+
flakinessAccessToken: this._options.flakinessAccessToken,
|
|
391
|
+
attachmentIds: this._attachments.map((attachment) => attachment.id)
|
|
392
|
+
}).then((result) => ({ result, error: void 0 })).catch((e) => ({ result: void 0, error: e }));
|
|
393
|
+
if (response?.error || !response.result)
|
|
394
|
+
return { success: false, message: `flakiness.io returned error: ${response.error.message}` };
|
|
395
|
+
await Promise.all([
|
|
396
|
+
this._uploadReport(JSON.stringify(this._report), response.result.report_upload_url, options?.syncCompression ?? false),
|
|
397
|
+
...this._attachments.map((attachment) => {
|
|
398
|
+
const uploadURL = response.result.attachment_upload_urls[attachment.id];
|
|
399
|
+
if (!uploadURL)
|
|
400
|
+
throw new Error("Internal error: missing upload URL for attachment!");
|
|
401
|
+
return this._uploadAttachment(attachment, uploadURL);
|
|
402
|
+
})
|
|
403
|
+
]);
|
|
404
|
+
const response2 = await this._api.run.completeUpload.POST({
|
|
405
|
+
upload_token: response.result.upload_token
|
|
406
|
+
}).then((result) => ({ result, error: void 0 })).catch((e) => ({ error: e, result: void 0 }));
|
|
407
|
+
const url = response2?.result?.report_url ? new URL2(response2?.result.report_url, this._options.flakinessEndpoint).toString() : void 0;
|
|
408
|
+
return { success: true, reportUrl: url };
|
|
409
|
+
}
|
|
410
|
+
async _uploadReport(data, uploadUrl, syncCompression) {
|
|
411
|
+
const compressed = syncCompression ? brotliCompressSync2(data) : await brotliCompressAsync(data);
|
|
412
|
+
const headers = {
|
|
413
|
+
"Content-Type": "application/json",
|
|
414
|
+
"Content-Length": Buffer.byteLength(compressed) + "",
|
|
415
|
+
"Content-Encoding": "br"
|
|
416
|
+
};
|
|
417
|
+
await retryWithBackoff(async () => {
|
|
418
|
+
const { request, responseDataPromise } = httpUtils.createRequest({
|
|
419
|
+
url: uploadUrl,
|
|
420
|
+
headers,
|
|
421
|
+
method: "put"
|
|
422
|
+
});
|
|
423
|
+
request.write(compressed);
|
|
424
|
+
request.end();
|
|
425
|
+
await responseDataPromise;
|
|
426
|
+
}, HTTP_BACKOFF);
|
|
427
|
+
}
|
|
428
|
+
async _uploadAttachment(attachment, uploadUrl) {
|
|
429
|
+
const bytesLength = attachment.path ? (await fs.promises.stat(attachment.path)).size : attachment.body ? Buffer.byteLength(attachment.body) : 0;
|
|
430
|
+
const headers = {
|
|
431
|
+
"Content-Type": attachment.contentType,
|
|
432
|
+
"Content-Length": bytesLength + ""
|
|
433
|
+
};
|
|
434
|
+
await retryWithBackoff(async () => {
|
|
435
|
+
const { request, responseDataPromise } = httpUtils.createRequest({
|
|
436
|
+
url: uploadUrl,
|
|
437
|
+
headers,
|
|
438
|
+
method: "put"
|
|
439
|
+
});
|
|
440
|
+
if (attachment.path) {
|
|
441
|
+
fs.createReadStream(attachment.path).pipe(request);
|
|
442
|
+
} else {
|
|
443
|
+
if (attachment.body)
|
|
444
|
+
request.write(attachment.body);
|
|
445
|
+
request.end();
|
|
446
|
+
}
|
|
447
|
+
await responseDataPromise;
|
|
448
|
+
}, HTTP_BACKOFF);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// src/cli/cmd-upload.ts
|
|
453
|
+
async function cmdUpload(relativePath, options) {
|
|
454
|
+
const fullPath = path.resolve(relativePath);
|
|
455
|
+
if (!await fs2.access(fullPath, fs2.constants.F_OK).then(() => true).catch(() => false)) {
|
|
456
|
+
console.error(`Error: path ${fullPath} is not accessible`);
|
|
457
|
+
process.exit(1);
|
|
458
|
+
}
|
|
459
|
+
const attachmentsDir = options.attachmentsDir ?? path.dirname(fullPath);
|
|
460
|
+
const attachmentFiles = await listFilesRecursively(attachmentsDir);
|
|
461
|
+
const attachmentIdToPath = new Map(attachmentFiles.map((file) => [path.basename(file), file]));
|
|
462
|
+
const text = await fs2.readFile(fullPath, "utf-8");
|
|
463
|
+
const report = JSON.parse(text);
|
|
464
|
+
const attachments = [];
|
|
465
|
+
const missingAttachments = [];
|
|
466
|
+
FlakinessReport.visitTests(report, (test) => {
|
|
467
|
+
for (const attempt of test.attempts) {
|
|
468
|
+
for (const attachment of attempt.attachments ?? []) {
|
|
469
|
+
const file = attachmentIdToPath.get(attachment.id);
|
|
470
|
+
if (!file) {
|
|
471
|
+
missingAttachments.push(attachment);
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
attachments.push({
|
|
475
|
+
contentType: attachment.contentType,
|
|
476
|
+
id: attachment.id,
|
|
477
|
+
path: file
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
if (missingAttachments.length && !options.ignoreMissingAttachments) {
|
|
483
|
+
console.log(`Missing ${missingAttachments.length} attachments - exiting. Use --ignore-missing-attachments to force upload.`);
|
|
484
|
+
process.exit(1);
|
|
485
|
+
}
|
|
486
|
+
const uploader = new ReportUploader({
|
|
487
|
+
flakinessAccessToken: options.accessToken,
|
|
488
|
+
flakinessEndpoint: options.endpoint
|
|
489
|
+
});
|
|
490
|
+
const upload = uploader.createUpload(report, attachments);
|
|
491
|
+
const uploadResult = await upload.upload();
|
|
492
|
+
if (!uploadResult.success) {
|
|
493
|
+
console.log(`[flakiness.io] X Failed to upload to ${options.endpoint}: ${uploadResult.message}`);
|
|
494
|
+
} else {
|
|
495
|
+
console.log(`[flakiness.io] \u2713 Report uploaded ${uploadResult.reportUrl ?? uploadResult.message ?? ""}`);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
async function listFilesRecursively(dir, result = []) {
|
|
499
|
+
const entries = await fs2.readdir(dir, { withFileTypes: true });
|
|
500
|
+
for (const entry of entries) {
|
|
501
|
+
const fullPath = path.join(dir, entry.name);
|
|
502
|
+
if (entry.isDirectory())
|
|
503
|
+
await listFilesRecursively(fullPath, result);
|
|
504
|
+
else
|
|
505
|
+
result.push(fullPath);
|
|
506
|
+
}
|
|
507
|
+
return result;
|
|
508
|
+
}
|
|
509
|
+
export {
|
|
510
|
+
cmdUpload
|
|
511
|
+
};
|
|
512
|
+
//# sourceMappingURL=cmd-upload.js.map
|