@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,460 @@
|
|
|
1
|
+
// src/flakinessLink.ts
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
// src/utils.ts
|
|
6
|
+
import assert from "assert";
|
|
7
|
+
import { spawnSync } from "child_process";
|
|
8
|
+
import http from "http";
|
|
9
|
+
import https from "https";
|
|
10
|
+
import { posix as posixPath, win32 as win32Path } from "path";
|
|
11
|
+
import util from "util";
|
|
12
|
+
import zlib from "zlib";
|
|
13
|
+
var gzipAsync = util.promisify(zlib.gzip);
|
|
14
|
+
var gunzipAsync = util.promisify(zlib.gunzip);
|
|
15
|
+
var gunzipSync = zlib.gunzipSync;
|
|
16
|
+
var brotliCompressAsync = util.promisify(zlib.brotliCompress);
|
|
17
|
+
var brotliCompressSync = zlib.brotliCompressSync;
|
|
18
|
+
async function retryWithBackoff(job, backoff = []) {
|
|
19
|
+
for (const timeout of backoff) {
|
|
20
|
+
try {
|
|
21
|
+
return await job();
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (e instanceof AggregateError)
|
|
24
|
+
console.error(`[flakiness.io err]`, e.errors[0].message);
|
|
25
|
+
else if (e instanceof Error)
|
|
26
|
+
console.error(`[flakiness.io err]`, e.message);
|
|
27
|
+
else
|
|
28
|
+
console.error(`[flakiness.io err]`, e);
|
|
29
|
+
await new Promise((x) => setTimeout(x, timeout));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return await job();
|
|
33
|
+
}
|
|
34
|
+
var httpUtils;
|
|
35
|
+
((httpUtils2) => {
|
|
36
|
+
function createRequest({ url, method = "get", headers = {} }) {
|
|
37
|
+
let resolve;
|
|
38
|
+
let reject;
|
|
39
|
+
const responseDataPromise = new Promise((a, b) => {
|
|
40
|
+
resolve = a;
|
|
41
|
+
reject = b;
|
|
42
|
+
});
|
|
43
|
+
const protocol = url.startsWith("https") ? https : http;
|
|
44
|
+
const request = protocol.request(url, { method, headers }, (res) => {
|
|
45
|
+
const chunks = [];
|
|
46
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
47
|
+
res.on("end", () => {
|
|
48
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
|
|
49
|
+
resolve(Buffer.concat(chunks));
|
|
50
|
+
else
|
|
51
|
+
reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
|
|
52
|
+
});
|
|
53
|
+
res.on("error", (error) => reject(error));
|
|
54
|
+
});
|
|
55
|
+
request.on("error", reject);
|
|
56
|
+
return { request, responseDataPromise };
|
|
57
|
+
}
|
|
58
|
+
httpUtils2.createRequest = createRequest;
|
|
59
|
+
async function getBuffer(url, backoff) {
|
|
60
|
+
return await retryWithBackoff(async () => {
|
|
61
|
+
const { request, responseDataPromise } = createRequest({ url });
|
|
62
|
+
request.end();
|
|
63
|
+
return await responseDataPromise;
|
|
64
|
+
}, backoff);
|
|
65
|
+
}
|
|
66
|
+
httpUtils2.getBuffer = getBuffer;
|
|
67
|
+
async function getText(url, backoff) {
|
|
68
|
+
const buffer = await getBuffer(url, backoff);
|
|
69
|
+
return buffer.toString("utf-8");
|
|
70
|
+
}
|
|
71
|
+
httpUtils2.getText = getText;
|
|
72
|
+
async function getJSON(url) {
|
|
73
|
+
return JSON.parse(await getText(url));
|
|
74
|
+
}
|
|
75
|
+
httpUtils2.getJSON = getJSON;
|
|
76
|
+
async function postText(url, text, backoff) {
|
|
77
|
+
const headers = {
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
"Content-Length": Buffer.byteLength(text) + ""
|
|
80
|
+
};
|
|
81
|
+
return await retryWithBackoff(async () => {
|
|
82
|
+
const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
|
|
83
|
+
request.write(text);
|
|
84
|
+
request.end();
|
|
85
|
+
return await responseDataPromise;
|
|
86
|
+
}, backoff);
|
|
87
|
+
}
|
|
88
|
+
httpUtils2.postText = postText;
|
|
89
|
+
async function postJSON(url, json, backoff) {
|
|
90
|
+
const buffer = await postText(url, JSON.stringify(json), backoff);
|
|
91
|
+
return JSON.parse(buffer.toString("utf-8"));
|
|
92
|
+
}
|
|
93
|
+
httpUtils2.postJSON = postJSON;
|
|
94
|
+
})(httpUtils || (httpUtils = {}));
|
|
95
|
+
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");
|
|
96
|
+
function shell(command, args, options) {
|
|
97
|
+
try {
|
|
98
|
+
const result = spawnSync(command, args, { encoding: "utf-8", ...options });
|
|
99
|
+
if (result.status !== 0) {
|
|
100
|
+
console.log(result);
|
|
101
|
+
console.log(options);
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
return result.stdout.trim();
|
|
105
|
+
} catch (e) {
|
|
106
|
+
console.log(e);
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function computeGitRoot(somePathInsideGitRepo) {
|
|
111
|
+
const root = shell(`git`, ["rev-parse", "--show-toplevel"], {
|
|
112
|
+
cwd: somePathInsideGitRepo,
|
|
113
|
+
encoding: "utf-8"
|
|
114
|
+
});
|
|
115
|
+
assert(root, `FAILED: git rev-parse --show-toplevel HEAD @ ${somePathInsideGitRepo}`);
|
|
116
|
+
return normalizePath(root);
|
|
117
|
+
}
|
|
118
|
+
var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
|
|
119
|
+
var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
|
|
120
|
+
function normalizePath(aPath) {
|
|
121
|
+
if (IS_WIN32_PATH.test(aPath)) {
|
|
122
|
+
aPath = aPath.split(win32Path.sep).join(posixPath.sep);
|
|
123
|
+
}
|
|
124
|
+
if (IS_ALMOST_POSIX_PATH.test(aPath))
|
|
125
|
+
return "/" + aPath[0] + aPath.substring(2);
|
|
126
|
+
return aPath;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/flakinessLink.ts
|
|
130
|
+
var GIT_ROOT = computeGitRoot(process.cwd());
|
|
131
|
+
var CONFIG_DIR = path.join(GIT_ROOT, ".flakiness");
|
|
132
|
+
var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
133
|
+
var FlakinessLink = class _FlakinessLink {
|
|
134
|
+
constructor(_config) {
|
|
135
|
+
this._config = _config;
|
|
136
|
+
}
|
|
137
|
+
static async load() {
|
|
138
|
+
const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
|
|
139
|
+
if (!data)
|
|
140
|
+
return void 0;
|
|
141
|
+
const json = JSON.parse(data);
|
|
142
|
+
return new _FlakinessLink(json);
|
|
143
|
+
}
|
|
144
|
+
static async remove() {
|
|
145
|
+
await fs.unlink(CONFIG_PATH).catch((e) => void 0);
|
|
146
|
+
}
|
|
147
|
+
path() {
|
|
148
|
+
return CONFIG_PATH;
|
|
149
|
+
}
|
|
150
|
+
projectId() {
|
|
151
|
+
return this._config.projectId;
|
|
152
|
+
}
|
|
153
|
+
async save() {
|
|
154
|
+
await fs.mkdir(CONFIG_DIR, { recursive: true });
|
|
155
|
+
await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/flakinessSession.ts
|
|
160
|
+
import fs2 from "fs/promises";
|
|
161
|
+
import os from "os";
|
|
162
|
+
import path2 from "path";
|
|
163
|
+
|
|
164
|
+
// ../server/lib/common/typedHttp.js
|
|
165
|
+
var TypedHTTP;
|
|
166
|
+
((TypedHTTP2) => {
|
|
167
|
+
TypedHTTP2.StatusCodes = {
|
|
168
|
+
Informational: {
|
|
169
|
+
CONTINUE: 100,
|
|
170
|
+
SWITCHING_PROTOCOLS: 101,
|
|
171
|
+
PROCESSING: 102,
|
|
172
|
+
EARLY_HINTS: 103
|
|
173
|
+
},
|
|
174
|
+
Success: {
|
|
175
|
+
OK: 200,
|
|
176
|
+
CREATED: 201,
|
|
177
|
+
ACCEPTED: 202,
|
|
178
|
+
NON_AUTHORITATIVE_INFORMATION: 203,
|
|
179
|
+
NO_CONTENT: 204,
|
|
180
|
+
RESET_CONTENT: 205,
|
|
181
|
+
PARTIAL_CONTENT: 206,
|
|
182
|
+
MULTI_STATUS: 207
|
|
183
|
+
},
|
|
184
|
+
Redirection: {
|
|
185
|
+
MULTIPLE_CHOICES: 300,
|
|
186
|
+
MOVED_PERMANENTLY: 301,
|
|
187
|
+
MOVED_TEMPORARILY: 302,
|
|
188
|
+
SEE_OTHER: 303,
|
|
189
|
+
NOT_MODIFIED: 304,
|
|
190
|
+
USE_PROXY: 305,
|
|
191
|
+
TEMPORARY_REDIRECT: 307,
|
|
192
|
+
PERMANENT_REDIRECT: 308
|
|
193
|
+
},
|
|
194
|
+
ClientErrors: {
|
|
195
|
+
BAD_REQUEST: 400,
|
|
196
|
+
UNAUTHORIZED: 401,
|
|
197
|
+
PAYMENT_REQUIRED: 402,
|
|
198
|
+
FORBIDDEN: 403,
|
|
199
|
+
NOT_FOUND: 404,
|
|
200
|
+
METHOD_NOT_ALLOWED: 405,
|
|
201
|
+
NOT_ACCEPTABLE: 406,
|
|
202
|
+
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
203
|
+
REQUEST_TIMEOUT: 408,
|
|
204
|
+
CONFLICT: 409,
|
|
205
|
+
GONE: 410,
|
|
206
|
+
LENGTH_REQUIRED: 411,
|
|
207
|
+
PRECONDITION_FAILED: 412,
|
|
208
|
+
REQUEST_TOO_LONG: 413,
|
|
209
|
+
REQUEST_URI_TOO_LONG: 414,
|
|
210
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
211
|
+
REQUESTED_RANGE_NOT_SATISFIABLE: 416,
|
|
212
|
+
EXPECTATION_FAILED: 417,
|
|
213
|
+
IM_A_TEAPOT: 418,
|
|
214
|
+
INSUFFICIENT_SPACE_ON_RESOURCE: 419,
|
|
215
|
+
METHOD_FAILURE: 420,
|
|
216
|
+
MISDIRECTED_REQUEST: 421,
|
|
217
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
218
|
+
LOCKED: 423,
|
|
219
|
+
FAILED_DEPENDENCY: 424,
|
|
220
|
+
UPGRADE_REQUIRED: 426,
|
|
221
|
+
PRECONDITION_REQUIRED: 428,
|
|
222
|
+
TOO_MANY_REQUESTS: 429,
|
|
223
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
224
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451
|
|
225
|
+
},
|
|
226
|
+
ServerErrors: {
|
|
227
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
228
|
+
NOT_IMPLEMENTED: 501,
|
|
229
|
+
BAD_GATEWAY: 502,
|
|
230
|
+
SERVICE_UNAVAILABLE: 503,
|
|
231
|
+
GATEWAY_TIMEOUT: 504,
|
|
232
|
+
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
233
|
+
INSUFFICIENT_STORAGE: 507,
|
|
234
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
const AllErrorCodes = {
|
|
238
|
+
...TypedHTTP2.StatusCodes.ClientErrors,
|
|
239
|
+
...TypedHTTP2.StatusCodes.ServerErrors
|
|
240
|
+
};
|
|
241
|
+
class HttpError extends Error {
|
|
242
|
+
constructor(status, message) {
|
|
243
|
+
super(message);
|
|
244
|
+
this.status = status;
|
|
245
|
+
}
|
|
246
|
+
static withCode(code, message) {
|
|
247
|
+
const statusCode = AllErrorCodes[code];
|
|
248
|
+
const defaultMessage = code.split("_").map((word) => word.charAt(0) + word.slice(1).toLowerCase()).join(" ");
|
|
249
|
+
return new HttpError(statusCode, message ?? defaultMessage);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
TypedHTTP2.HttpError = HttpError;
|
|
253
|
+
function isInformationalResponse(response) {
|
|
254
|
+
return response.status >= 100 && response.status < 200;
|
|
255
|
+
}
|
|
256
|
+
TypedHTTP2.isInformationalResponse = isInformationalResponse;
|
|
257
|
+
function isSuccessResponse(response) {
|
|
258
|
+
return response.status >= 200 && response.status < 300;
|
|
259
|
+
}
|
|
260
|
+
TypedHTTP2.isSuccessResponse = isSuccessResponse;
|
|
261
|
+
function isRedirectResponse(response) {
|
|
262
|
+
return response.status >= 300 && response.status < 400;
|
|
263
|
+
}
|
|
264
|
+
TypedHTTP2.isRedirectResponse = isRedirectResponse;
|
|
265
|
+
function isErrorResponse(response) {
|
|
266
|
+
return response.status >= 400 && response.status < 600;
|
|
267
|
+
}
|
|
268
|
+
TypedHTTP2.isErrorResponse = isErrorResponse;
|
|
269
|
+
function info(status) {
|
|
270
|
+
return { status };
|
|
271
|
+
}
|
|
272
|
+
TypedHTTP2.info = info;
|
|
273
|
+
function ok(data, status) {
|
|
274
|
+
return {
|
|
275
|
+
status: status ?? TypedHTTP2.StatusCodes.Success.OK,
|
|
276
|
+
data
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
TypedHTTP2.ok = ok;
|
|
280
|
+
function redirect(url, status = 302) {
|
|
281
|
+
return { status, url };
|
|
282
|
+
}
|
|
283
|
+
TypedHTTP2.redirect = redirect;
|
|
284
|
+
function error(message, status = TypedHTTP2.StatusCodes.ServerErrors.INTERNAL_SERVER_ERROR) {
|
|
285
|
+
return { status, message };
|
|
286
|
+
}
|
|
287
|
+
TypedHTTP2.error = error;
|
|
288
|
+
class Router {
|
|
289
|
+
constructor(_resolveContext) {
|
|
290
|
+
this._resolveContext = _resolveContext;
|
|
291
|
+
}
|
|
292
|
+
static create() {
|
|
293
|
+
return new Router(async (e) => e.ctx);
|
|
294
|
+
}
|
|
295
|
+
rawMethod(method, route) {
|
|
296
|
+
return {
|
|
297
|
+
[method]: {
|
|
298
|
+
method,
|
|
299
|
+
input: route.input,
|
|
300
|
+
etag: route.etag,
|
|
301
|
+
resolveContext: this._resolveContext,
|
|
302
|
+
handler: route.handler
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
get(route) {
|
|
307
|
+
return this.rawMethod("GET", {
|
|
308
|
+
...route,
|
|
309
|
+
handler: (...args) => Promise.resolve(route.handler(...args)).then((result) => TypedHTTP2.ok(result))
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
post(route) {
|
|
313
|
+
return this.rawMethod("POST", {
|
|
314
|
+
...route,
|
|
315
|
+
handler: (...args) => Promise.resolve(route.handler(...args)).then((result) => TypedHTTP2.ok(result))
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
use(resolveContext) {
|
|
319
|
+
return new Router(async (options) => {
|
|
320
|
+
const m = await this._resolveContext(options);
|
|
321
|
+
return resolveContext({ ...options, ctx: m });
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
TypedHTTP2.Router = Router;
|
|
326
|
+
function createClient(base, fetchCallback) {
|
|
327
|
+
function buildUrl(path3, input, options) {
|
|
328
|
+
const method = path3.at(-1);
|
|
329
|
+
const url = new URL(path3.slice(0, path3.length - 1).join("/"), base);
|
|
330
|
+
const signal = options?.signal;
|
|
331
|
+
let body = void 0;
|
|
332
|
+
if (method === "GET" && input)
|
|
333
|
+
url.searchParams.set("input", JSON.stringify(input));
|
|
334
|
+
else if (method !== "GET" && input)
|
|
335
|
+
body = JSON.stringify(input);
|
|
336
|
+
return {
|
|
337
|
+
url,
|
|
338
|
+
method,
|
|
339
|
+
headers: body ? { "Content-Type": "application/json" } : void 0,
|
|
340
|
+
body,
|
|
341
|
+
signal
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function createProxy(path3 = []) {
|
|
345
|
+
return new Proxy(() => {
|
|
346
|
+
}, {
|
|
347
|
+
get(target, prop) {
|
|
348
|
+
if (typeof prop === "symbol")
|
|
349
|
+
return void 0;
|
|
350
|
+
if (prop === "prepare")
|
|
351
|
+
return (input, options) => buildUrl(path3, input, options);
|
|
352
|
+
const newPath = [...path3, prop];
|
|
353
|
+
return createProxy(newPath);
|
|
354
|
+
},
|
|
355
|
+
apply(target, thisArg, args) {
|
|
356
|
+
const options = buildUrl(path3, args[0], args[1]);
|
|
357
|
+
return fetchCallback(options.url, {
|
|
358
|
+
method: options.method,
|
|
359
|
+
body: options.body,
|
|
360
|
+
headers: options.headers,
|
|
361
|
+
signal: options.signal
|
|
362
|
+
}).then(async (response) => {
|
|
363
|
+
if (response.status >= 200 && response.status < 300) {
|
|
364
|
+
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
365
|
+
const text = await response.text();
|
|
366
|
+
return text.length ? JSON.parse(text) : void 0;
|
|
367
|
+
}
|
|
368
|
+
return await response.blob();
|
|
369
|
+
}
|
|
370
|
+
if (response.status >= 400 && response.status < 600) {
|
|
371
|
+
const text = await response.text();
|
|
372
|
+
if (text)
|
|
373
|
+
throw new Error(`HTTP request failed with status ${response.status}: ${text}`);
|
|
374
|
+
else
|
|
375
|
+
throw new Error(`HTTP request failed with status ${response.status}`);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return createProxy();
|
|
382
|
+
}
|
|
383
|
+
TypedHTTP2.createClient = createClient;
|
|
384
|
+
})(TypedHTTP || (TypedHTTP = {}));
|
|
385
|
+
|
|
386
|
+
// src/serverapi.ts
|
|
387
|
+
function createServerAPI(endpoint, options) {
|
|
388
|
+
endpoint += "/api/";
|
|
389
|
+
const fetcher = options?.auth ? (url, init) => fetch(url, {
|
|
390
|
+
...init,
|
|
391
|
+
headers: {
|
|
392
|
+
...init.headers,
|
|
393
|
+
"Authorization": `Bearer ${options.auth}`
|
|
394
|
+
}
|
|
395
|
+
}) : fetch;
|
|
396
|
+
if (options?.retries)
|
|
397
|
+
return TypedHTTP.createClient(endpoint, (url, init) => retryWithBackoff(() => fetcher(url, init), options.retries));
|
|
398
|
+
return TypedHTTP.createClient(endpoint, fetcher);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// src/flakinessSession.ts
|
|
402
|
+
var CONFIG_DIR2 = (() => {
|
|
403
|
+
const configDir = process.platform === "darwin" ? path2.join(os.homedir(), "Library", "Application Support", "flakiness") : process.platform === "win32" ? path2.join(os.homedir(), "AppData", "Roaming", "flakiness") : path2.join(os.homedir(), ".config", "flakiness");
|
|
404
|
+
return configDir;
|
|
405
|
+
})();
|
|
406
|
+
var CONFIG_PATH2 = path2.join(CONFIG_DIR2, "config.json");
|
|
407
|
+
var FlakinessSession = class _FlakinessSession {
|
|
408
|
+
constructor(_config) {
|
|
409
|
+
this._config = _config;
|
|
410
|
+
this.api = createServerAPI(this._config.endpoint, { auth: this._config.token });
|
|
411
|
+
}
|
|
412
|
+
static async load() {
|
|
413
|
+
const data = await fs2.readFile(CONFIG_PATH2, "utf-8").catch((e) => void 0);
|
|
414
|
+
if (!data)
|
|
415
|
+
return void 0;
|
|
416
|
+
const json = JSON.parse(data);
|
|
417
|
+
return new _FlakinessSession(json);
|
|
418
|
+
}
|
|
419
|
+
static async remove() {
|
|
420
|
+
await fs2.unlink(CONFIG_PATH2).catch((e) => void 0);
|
|
421
|
+
}
|
|
422
|
+
api;
|
|
423
|
+
endpoint() {
|
|
424
|
+
return this._config.endpoint;
|
|
425
|
+
}
|
|
426
|
+
path() {
|
|
427
|
+
return CONFIG_PATH2;
|
|
428
|
+
}
|
|
429
|
+
sessionToken() {
|
|
430
|
+
return this._config.token;
|
|
431
|
+
}
|
|
432
|
+
async save() {
|
|
433
|
+
await fs2.mkdir(CONFIG_DIR2, { recursive: true });
|
|
434
|
+
await fs2.writeFile(CONFIG_PATH2, JSON.stringify(this._config, null, 2));
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
// src/cli/cmd-status.ts
|
|
439
|
+
async function cmdStatus() {
|
|
440
|
+
const session = await FlakinessSession.load();
|
|
441
|
+
if (!session) {
|
|
442
|
+
console.log(`user: not logged in`);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const user = await session.api.user.whoami.GET();
|
|
446
|
+
console.log(`user: ${user.userName} (${user.userLogin})`);
|
|
447
|
+
const link = await FlakinessLink.load();
|
|
448
|
+
if (!link) {
|
|
449
|
+
console.log(`project: <not linked>`);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const project = await session.api.project.getProject.GET({
|
|
453
|
+
projectPublicId: link.projectId()
|
|
454
|
+
});
|
|
455
|
+
console.log(`project: ${session.endpoint()}/${project.org.orgSlug}/${project.projectSlug}`);
|
|
456
|
+
}
|
|
457
|
+
export {
|
|
458
|
+
cmdStatus
|
|
459
|
+
};
|
|
460
|
+
//# sourceMappingURL=cmd-status.js.map
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// src/flakinessLink.ts
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import path from "path";
|
|
4
|
+
|
|
5
|
+
// src/utils.ts
|
|
6
|
+
import assert from "assert";
|
|
7
|
+
import { spawnSync } from "child_process";
|
|
8
|
+
import http from "http";
|
|
9
|
+
import https from "https";
|
|
10
|
+
import { posix as posixPath, win32 as win32Path } from "path";
|
|
11
|
+
import util from "util";
|
|
12
|
+
import zlib from "zlib";
|
|
13
|
+
var gzipAsync = util.promisify(zlib.gzip);
|
|
14
|
+
var gunzipAsync = util.promisify(zlib.gunzip);
|
|
15
|
+
var gunzipSync = zlib.gunzipSync;
|
|
16
|
+
var brotliCompressAsync = util.promisify(zlib.brotliCompress);
|
|
17
|
+
var brotliCompressSync = zlib.brotliCompressSync;
|
|
18
|
+
async function retryWithBackoff(job, backoff = []) {
|
|
19
|
+
for (const timeout of backoff) {
|
|
20
|
+
try {
|
|
21
|
+
return await job();
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (e instanceof AggregateError)
|
|
24
|
+
console.error(`[flakiness.io err]`, e.errors[0].message);
|
|
25
|
+
else if (e instanceof Error)
|
|
26
|
+
console.error(`[flakiness.io err]`, e.message);
|
|
27
|
+
else
|
|
28
|
+
console.error(`[flakiness.io err]`, e);
|
|
29
|
+
await new Promise((x) => setTimeout(x, timeout));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return await job();
|
|
33
|
+
}
|
|
34
|
+
var httpUtils;
|
|
35
|
+
((httpUtils2) => {
|
|
36
|
+
function createRequest({ url, method = "get", headers = {} }) {
|
|
37
|
+
let resolve;
|
|
38
|
+
let reject;
|
|
39
|
+
const responseDataPromise = new Promise((a, b) => {
|
|
40
|
+
resolve = a;
|
|
41
|
+
reject = b;
|
|
42
|
+
});
|
|
43
|
+
const protocol = url.startsWith("https") ? https : http;
|
|
44
|
+
const request = protocol.request(url, { method, headers }, (res) => {
|
|
45
|
+
const chunks = [];
|
|
46
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
47
|
+
res.on("end", () => {
|
|
48
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
|
|
49
|
+
resolve(Buffer.concat(chunks));
|
|
50
|
+
else
|
|
51
|
+
reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
|
|
52
|
+
});
|
|
53
|
+
res.on("error", (error) => reject(error));
|
|
54
|
+
});
|
|
55
|
+
request.on("error", reject);
|
|
56
|
+
return { request, responseDataPromise };
|
|
57
|
+
}
|
|
58
|
+
httpUtils2.createRequest = createRequest;
|
|
59
|
+
async function getBuffer(url, backoff) {
|
|
60
|
+
return await retryWithBackoff(async () => {
|
|
61
|
+
const { request, responseDataPromise } = createRequest({ url });
|
|
62
|
+
request.end();
|
|
63
|
+
return await responseDataPromise;
|
|
64
|
+
}, backoff);
|
|
65
|
+
}
|
|
66
|
+
httpUtils2.getBuffer = getBuffer;
|
|
67
|
+
async function getText(url, backoff) {
|
|
68
|
+
const buffer = await getBuffer(url, backoff);
|
|
69
|
+
return buffer.toString("utf-8");
|
|
70
|
+
}
|
|
71
|
+
httpUtils2.getText = getText;
|
|
72
|
+
async function getJSON(url) {
|
|
73
|
+
return JSON.parse(await getText(url));
|
|
74
|
+
}
|
|
75
|
+
httpUtils2.getJSON = getJSON;
|
|
76
|
+
async function postText(url, text, backoff) {
|
|
77
|
+
const headers = {
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
"Content-Length": Buffer.byteLength(text) + ""
|
|
80
|
+
};
|
|
81
|
+
return await retryWithBackoff(async () => {
|
|
82
|
+
const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
|
|
83
|
+
request.write(text);
|
|
84
|
+
request.end();
|
|
85
|
+
return await responseDataPromise;
|
|
86
|
+
}, backoff);
|
|
87
|
+
}
|
|
88
|
+
httpUtils2.postText = postText;
|
|
89
|
+
async function postJSON(url, json, backoff) {
|
|
90
|
+
const buffer = await postText(url, JSON.stringify(json), backoff);
|
|
91
|
+
return JSON.parse(buffer.toString("utf-8"));
|
|
92
|
+
}
|
|
93
|
+
httpUtils2.postJSON = postJSON;
|
|
94
|
+
})(httpUtils || (httpUtils = {}));
|
|
95
|
+
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");
|
|
96
|
+
function shell(command, args, options) {
|
|
97
|
+
try {
|
|
98
|
+
const result = spawnSync(command, args, { encoding: "utf-8", ...options });
|
|
99
|
+
if (result.status !== 0) {
|
|
100
|
+
console.log(result);
|
|
101
|
+
console.log(options);
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
return result.stdout.trim();
|
|
105
|
+
} catch (e) {
|
|
106
|
+
console.log(e);
|
|
107
|
+
return void 0;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function computeGitRoot(somePathInsideGitRepo) {
|
|
111
|
+
const root = shell(`git`, ["rev-parse", "--show-toplevel"], {
|
|
112
|
+
cwd: somePathInsideGitRepo,
|
|
113
|
+
encoding: "utf-8"
|
|
114
|
+
});
|
|
115
|
+
assert(root, `FAILED: git rev-parse --show-toplevel HEAD @ ${somePathInsideGitRepo}`);
|
|
116
|
+
return normalizePath(root);
|
|
117
|
+
}
|
|
118
|
+
var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
|
|
119
|
+
var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
|
|
120
|
+
function normalizePath(aPath) {
|
|
121
|
+
if (IS_WIN32_PATH.test(aPath)) {
|
|
122
|
+
aPath = aPath.split(win32Path.sep).join(posixPath.sep);
|
|
123
|
+
}
|
|
124
|
+
if (IS_ALMOST_POSIX_PATH.test(aPath))
|
|
125
|
+
return "/" + aPath[0] + aPath.substring(2);
|
|
126
|
+
return aPath;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/flakinessLink.ts
|
|
130
|
+
var GIT_ROOT = computeGitRoot(process.cwd());
|
|
131
|
+
var CONFIG_DIR = path.join(GIT_ROOT, ".flakiness");
|
|
132
|
+
var CONFIG_PATH = path.join(CONFIG_DIR, "config.json");
|
|
133
|
+
var FlakinessLink = class _FlakinessLink {
|
|
134
|
+
constructor(_config) {
|
|
135
|
+
this._config = _config;
|
|
136
|
+
}
|
|
137
|
+
static async load() {
|
|
138
|
+
const data = await fs.readFile(CONFIG_PATH, "utf-8").catch((e) => void 0);
|
|
139
|
+
if (!data)
|
|
140
|
+
return void 0;
|
|
141
|
+
const json = JSON.parse(data);
|
|
142
|
+
return new _FlakinessLink(json);
|
|
143
|
+
}
|
|
144
|
+
static async remove() {
|
|
145
|
+
await fs.unlink(CONFIG_PATH).catch((e) => void 0);
|
|
146
|
+
}
|
|
147
|
+
path() {
|
|
148
|
+
return CONFIG_PATH;
|
|
149
|
+
}
|
|
150
|
+
projectId() {
|
|
151
|
+
return this._config.projectId;
|
|
152
|
+
}
|
|
153
|
+
async save() {
|
|
154
|
+
await fs.mkdir(CONFIG_DIR, { recursive: true });
|
|
155
|
+
await fs.writeFile(CONFIG_PATH, JSON.stringify(this._config, null, 2));
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/cli/cmd-unlink.ts
|
|
160
|
+
async function cmdUnlink() {
|
|
161
|
+
await FlakinessLink.remove();
|
|
162
|
+
}
|
|
163
|
+
export {
|
|
164
|
+
cmdUnlink
|
|
165
|
+
};
|
|
166
|
+
//# sourceMappingURL=cmd-unlink.js.map
|