@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
package/lib/utils.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
import { spawnSync } from "child_process";
|
|
4
|
+
import crypto from "crypto";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import http from "http";
|
|
7
|
+
import https from "https";
|
|
8
|
+
import os from "os";
|
|
9
|
+
import { posix as posixPath, win32 as win32Path } from "path";
|
|
10
|
+
import util from "util";
|
|
11
|
+
import zlib from "zlib";
|
|
12
|
+
var gzipAsync = util.promisify(zlib.gzip);
|
|
13
|
+
var gunzipAsync = util.promisify(zlib.gunzip);
|
|
14
|
+
var gunzipSync = zlib.gunzipSync;
|
|
15
|
+
var brotliCompressAsync = util.promisify(zlib.brotliCompress);
|
|
16
|
+
var brotliCompressSync = zlib.brotliCompressSync;
|
|
17
|
+
async function existsAsync(aPath) {
|
|
18
|
+
return fs.promises.stat(aPath).then(() => true).catch((e) => false);
|
|
19
|
+
}
|
|
20
|
+
function extractEnvConfiguration() {
|
|
21
|
+
const ENV_PREFIX = "FK_ENV_";
|
|
22
|
+
return Object.fromEntries(
|
|
23
|
+
Object.entries(process.env).filter(([key]) => key.toUpperCase().startsWith(ENV_PREFIX.toUpperCase())).map(([key, value]) => [key.substring(ENV_PREFIX.length).toLowerCase(), (value ?? "").trim().toLowerCase()])
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function sha1File(filePath) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const hash = crypto.createHash("sha1");
|
|
29
|
+
const stream = fs.createReadStream(filePath);
|
|
30
|
+
stream.on("data", (chunk) => {
|
|
31
|
+
hash.update(chunk);
|
|
32
|
+
});
|
|
33
|
+
stream.on("end", () => {
|
|
34
|
+
resolve(hash.digest("hex"));
|
|
35
|
+
});
|
|
36
|
+
stream.on("error", (err) => {
|
|
37
|
+
reject(err);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function sha1Buffer(data) {
|
|
42
|
+
const hash = crypto.createHash("sha1");
|
|
43
|
+
hash.update(data);
|
|
44
|
+
return hash.digest("hex");
|
|
45
|
+
}
|
|
46
|
+
async function retryWithBackoff(job, backoff = []) {
|
|
47
|
+
for (const timeout of backoff) {
|
|
48
|
+
try {
|
|
49
|
+
return await job();
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e instanceof AggregateError)
|
|
52
|
+
console.error(`[flakiness.io err]`, e.errors[0].message);
|
|
53
|
+
else if (e instanceof Error)
|
|
54
|
+
console.error(`[flakiness.io err]`, e.message);
|
|
55
|
+
else
|
|
56
|
+
console.error(`[flakiness.io err]`, e);
|
|
57
|
+
await new Promise((x) => setTimeout(x, timeout));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return await job();
|
|
61
|
+
}
|
|
62
|
+
var httpUtils;
|
|
63
|
+
((httpUtils2) => {
|
|
64
|
+
function createRequest({ url, method = "get", headers = {} }) {
|
|
65
|
+
let resolve;
|
|
66
|
+
let reject;
|
|
67
|
+
const responseDataPromise = new Promise((a, b) => {
|
|
68
|
+
resolve = a;
|
|
69
|
+
reject = b;
|
|
70
|
+
});
|
|
71
|
+
const protocol = url.startsWith("https") ? https : http;
|
|
72
|
+
const request = protocol.request(url, { method, headers }, (res) => {
|
|
73
|
+
const chunks = [];
|
|
74
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
75
|
+
res.on("end", () => {
|
|
76
|
+
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300)
|
|
77
|
+
resolve(Buffer.concat(chunks));
|
|
78
|
+
else
|
|
79
|
+
reject(new Error(`Request to ${url} failed with ${res.statusCode}`));
|
|
80
|
+
});
|
|
81
|
+
res.on("error", (error) => reject(error));
|
|
82
|
+
});
|
|
83
|
+
request.on("error", reject);
|
|
84
|
+
return { request, responseDataPromise };
|
|
85
|
+
}
|
|
86
|
+
httpUtils2.createRequest = createRequest;
|
|
87
|
+
async function getBuffer(url, backoff) {
|
|
88
|
+
return await retryWithBackoff(async () => {
|
|
89
|
+
const { request, responseDataPromise } = createRequest({ url });
|
|
90
|
+
request.end();
|
|
91
|
+
return await responseDataPromise;
|
|
92
|
+
}, backoff);
|
|
93
|
+
}
|
|
94
|
+
httpUtils2.getBuffer = getBuffer;
|
|
95
|
+
async function getText(url, backoff) {
|
|
96
|
+
const buffer = await getBuffer(url, backoff);
|
|
97
|
+
return buffer.toString("utf-8");
|
|
98
|
+
}
|
|
99
|
+
httpUtils2.getText = getText;
|
|
100
|
+
async function getJSON(url) {
|
|
101
|
+
return JSON.parse(await getText(url));
|
|
102
|
+
}
|
|
103
|
+
httpUtils2.getJSON = getJSON;
|
|
104
|
+
async function postText(url, text, backoff) {
|
|
105
|
+
const headers = {
|
|
106
|
+
"Content-Type": "application/json",
|
|
107
|
+
"Content-Length": Buffer.byteLength(text) + ""
|
|
108
|
+
};
|
|
109
|
+
return await retryWithBackoff(async () => {
|
|
110
|
+
const { request, responseDataPromise } = createRequest({ url, headers, method: "post" });
|
|
111
|
+
request.write(text);
|
|
112
|
+
request.end();
|
|
113
|
+
return await responseDataPromise;
|
|
114
|
+
}, backoff);
|
|
115
|
+
}
|
|
116
|
+
httpUtils2.postText = postText;
|
|
117
|
+
async function postJSON(url, json, backoff) {
|
|
118
|
+
const buffer = await postText(url, JSON.stringify(json), backoff);
|
|
119
|
+
return JSON.parse(buffer.toString("utf-8"));
|
|
120
|
+
}
|
|
121
|
+
httpUtils2.postJSON = postJSON;
|
|
122
|
+
})(httpUtils || (httpUtils = {}));
|
|
123
|
+
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");
|
|
124
|
+
function stripAnsi(str) {
|
|
125
|
+
return str.replace(ansiRegex, "");
|
|
126
|
+
}
|
|
127
|
+
function shell(command, args, options) {
|
|
128
|
+
try {
|
|
129
|
+
const result = spawnSync(command, args, { encoding: "utf-8", ...options });
|
|
130
|
+
if (result.status !== 0) {
|
|
131
|
+
console.log(result);
|
|
132
|
+
console.log(options);
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
return result.stdout.trim();
|
|
136
|
+
} catch (e) {
|
|
137
|
+
console.log(e);
|
|
138
|
+
return void 0;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function readLinuxOSRelease() {
|
|
142
|
+
const osReleaseText = fs.readFileSync("/etc/os-release", "utf-8");
|
|
143
|
+
return new Map(osReleaseText.toLowerCase().split("\n").filter((line) => line.includes("=")).map((line) => {
|
|
144
|
+
line = line.trim();
|
|
145
|
+
let [key, value] = line.split("=");
|
|
146
|
+
if (value.startsWith('"') && value.endsWith('"'))
|
|
147
|
+
value = value.substring(1, value.length - 1);
|
|
148
|
+
return [key, value];
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
function osLinuxInfo() {
|
|
152
|
+
const arch = shell(`uname`, [`-m`]);
|
|
153
|
+
const osReleaseMap = readLinuxOSRelease();
|
|
154
|
+
const name = osReleaseMap.get("name") ?? shell(`uname`);
|
|
155
|
+
const version = osReleaseMap.get("version_id");
|
|
156
|
+
return { name, arch, version };
|
|
157
|
+
}
|
|
158
|
+
function osDarwinInfo() {
|
|
159
|
+
const name = "macos";
|
|
160
|
+
const arch = shell(`uname`, [`-m`]);
|
|
161
|
+
const version = shell(`sw_vers`, [`-productVersion`]);
|
|
162
|
+
return { name, arch, version };
|
|
163
|
+
}
|
|
164
|
+
function osWinInfo() {
|
|
165
|
+
const name = "win";
|
|
166
|
+
const arch = process.arch;
|
|
167
|
+
const version = os.release();
|
|
168
|
+
return { name, arch, version };
|
|
169
|
+
}
|
|
170
|
+
function getOSInfo() {
|
|
171
|
+
if (process.platform === "darwin")
|
|
172
|
+
return osDarwinInfo();
|
|
173
|
+
if (process.platform === "win32")
|
|
174
|
+
return osWinInfo();
|
|
175
|
+
return osLinuxInfo();
|
|
176
|
+
}
|
|
177
|
+
function inferRunUrl() {
|
|
178
|
+
if (process.env.GITHUB_REPOSITORY && process.env.GITHUB_RUN_ID)
|
|
179
|
+
return `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
|
|
180
|
+
return void 0;
|
|
181
|
+
}
|
|
182
|
+
function parseStringDate(dateString) {
|
|
183
|
+
return +new Date(dateString);
|
|
184
|
+
}
|
|
185
|
+
function gitCommitInfo(gitRepo) {
|
|
186
|
+
const sha = shell(`git`, ["rev-parse", "HEAD"], {
|
|
187
|
+
cwd: gitRepo,
|
|
188
|
+
encoding: "utf-8"
|
|
189
|
+
});
|
|
190
|
+
assert(sha, `FAILED: git rev-parse HEAD @ ${gitRepo}`);
|
|
191
|
+
return sha.trim();
|
|
192
|
+
}
|
|
193
|
+
function computeGitRoot(somePathInsideGitRepo) {
|
|
194
|
+
const root = shell(`git`, ["rev-parse", "--show-toplevel"], {
|
|
195
|
+
cwd: somePathInsideGitRepo,
|
|
196
|
+
encoding: "utf-8"
|
|
197
|
+
});
|
|
198
|
+
assert(root, `FAILED: git rev-parse --show-toplevel HEAD @ ${somePathInsideGitRepo}`);
|
|
199
|
+
return normalizePath(root);
|
|
200
|
+
}
|
|
201
|
+
var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
|
|
202
|
+
var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
|
|
203
|
+
function normalizePath(aPath) {
|
|
204
|
+
if (IS_WIN32_PATH.test(aPath)) {
|
|
205
|
+
aPath = aPath.split(win32Path.sep).join(posixPath.sep);
|
|
206
|
+
}
|
|
207
|
+
if (IS_ALMOST_POSIX_PATH.test(aPath))
|
|
208
|
+
return "/" + aPath[0] + aPath.substring(2);
|
|
209
|
+
return aPath;
|
|
210
|
+
}
|
|
211
|
+
function getCallerLocation(gitRoot, offset = 0) {
|
|
212
|
+
const err = new Error();
|
|
213
|
+
const stack = err.stack?.split("\n");
|
|
214
|
+
const caller = stack?.[2 + offset]?.trim();
|
|
215
|
+
const match = caller?.match(/\((.*):(\d+):(\d+)\)$/);
|
|
216
|
+
if (!match)
|
|
217
|
+
return void 0;
|
|
218
|
+
const [, filePath, line, column] = match;
|
|
219
|
+
return {
|
|
220
|
+
file: gitFilePath(gitRoot, normalizePath(filePath)),
|
|
221
|
+
line: Number(line),
|
|
222
|
+
column: Number(column)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function parseStackLocations() {
|
|
226
|
+
const err = new Error();
|
|
227
|
+
const stack = err.stack?.split("\n").slice(2);
|
|
228
|
+
if (!stack)
|
|
229
|
+
return [];
|
|
230
|
+
const result = [];
|
|
231
|
+
for (const caller of stack) {
|
|
232
|
+
const match = caller.trim().match(/\((.*):(\d+):(\d+)\)$/);
|
|
233
|
+
if (!match)
|
|
234
|
+
continue;
|
|
235
|
+
const [, file, line, column] = match;
|
|
236
|
+
result.push({ file, line, column });
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
function gitFilePath(gitRoot, absolutePath) {
|
|
241
|
+
return posixPath.relative(gitRoot, absolutePath);
|
|
242
|
+
}
|
|
243
|
+
function parseDurationMS(value) {
|
|
244
|
+
if (isNaN(value))
|
|
245
|
+
throw new Error("Duration cannot be NaN");
|
|
246
|
+
if (value < 0)
|
|
247
|
+
throw new Error(`Duration cannot be less than 0, found ${value}`);
|
|
248
|
+
return value | 0;
|
|
249
|
+
}
|
|
250
|
+
function createEnvironment(options) {
|
|
251
|
+
const osInfo = getOSInfo();
|
|
252
|
+
return {
|
|
253
|
+
name: options.name,
|
|
254
|
+
systemData: {
|
|
255
|
+
osArch: osInfo.arch,
|
|
256
|
+
osName: osInfo.name,
|
|
257
|
+
osVersion: osInfo.version
|
|
258
|
+
},
|
|
259
|
+
userSuppliedData: {
|
|
260
|
+
...extractEnvConfiguration(),
|
|
261
|
+
...options.userSuppliedData ?? {}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function createEnvironments(projects) {
|
|
266
|
+
const envConfiguration = extractEnvConfiguration();
|
|
267
|
+
const osInfo = getOSInfo();
|
|
268
|
+
let uniqueNames = /* @__PURE__ */ new Set();
|
|
269
|
+
const result = /* @__PURE__ */ new Map();
|
|
270
|
+
for (const project of projects) {
|
|
271
|
+
let defaultName = project.name;
|
|
272
|
+
if (!defaultName.trim())
|
|
273
|
+
defaultName = "anonymous";
|
|
274
|
+
let name = defaultName;
|
|
275
|
+
for (let i = 2; uniqueNames.has(name); ++i)
|
|
276
|
+
name = `${defaultName}-${i}`;
|
|
277
|
+
uniqueNames.add(defaultName);
|
|
278
|
+
result.set(project, {
|
|
279
|
+
name,
|
|
280
|
+
systemData: {
|
|
281
|
+
osArch: osInfo.arch,
|
|
282
|
+
osName: osInfo.name,
|
|
283
|
+
osVersion: osInfo.version
|
|
284
|
+
},
|
|
285
|
+
userSuppliedData: {
|
|
286
|
+
...envConfiguration,
|
|
287
|
+
...project.metadata
|
|
288
|
+
},
|
|
289
|
+
opaqueData: {
|
|
290
|
+
project
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
export {
|
|
297
|
+
brotliCompressAsync,
|
|
298
|
+
brotliCompressSync,
|
|
299
|
+
computeGitRoot,
|
|
300
|
+
createEnvironment,
|
|
301
|
+
createEnvironments,
|
|
302
|
+
existsAsync,
|
|
303
|
+
extractEnvConfiguration,
|
|
304
|
+
getCallerLocation,
|
|
305
|
+
getOSInfo,
|
|
306
|
+
gitCommitInfo,
|
|
307
|
+
gitFilePath,
|
|
308
|
+
gunzipAsync,
|
|
309
|
+
gunzipSync,
|
|
310
|
+
gzipAsync,
|
|
311
|
+
httpUtils,
|
|
312
|
+
inferRunUrl,
|
|
313
|
+
normalizePath,
|
|
314
|
+
parseDurationMS,
|
|
315
|
+
parseStackLocations,
|
|
316
|
+
parseStringDate,
|
|
317
|
+
retryWithBackoff,
|
|
318
|
+
sha1Buffer,
|
|
319
|
+
sha1File,
|
|
320
|
+
shell,
|
|
321
|
+
stripAnsi
|
|
322
|
+
};
|
|
323
|
+
//# sourceMappingURL=utils.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flakiness/sdk",
|
|
3
|
+
"version": "0.95.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"bin": {
|
|
6
|
+
"flakiness": "./lib/cli/cli.js"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
"./uploader": {
|
|
10
|
+
"import": "./lib/reportUploader.js",
|
|
11
|
+
"require": "./lib/reportUploader.js",
|
|
12
|
+
"types": "./types/src/reportUploader.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./utils": {
|
|
15
|
+
"import": "./lib/utils.js",
|
|
16
|
+
"require": "./lib/utils.js",
|
|
17
|
+
"types": "./types/src/utils.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./playwright": {
|
|
20
|
+
"import": "./lib/playwrightJSONReport.js",
|
|
21
|
+
"require": "./lib/playwrightJSONReport.js",
|
|
22
|
+
"types": "./types/src/playwrightJSONReport.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./junit": {
|
|
25
|
+
"import": "./lib/junit.js",
|
|
26
|
+
"require": "./lib/junit.js",
|
|
27
|
+
"types": "./types/src/junit.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./playwright-test": {
|
|
30
|
+
"import": "./lib/playwright-test.js",
|
|
31
|
+
"require": "./lib/playwright-test.js",
|
|
32
|
+
"types": "./types/src/playwright-test.d.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"description": "",
|
|
37
|
+
"types": "./types/index.d.ts",
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [],
|
|
42
|
+
"author": "Degu Labs, Inc",
|
|
43
|
+
"license": "Fair Source 100",
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@playwright/test": "^1.54.0",
|
|
46
|
+
"@flakiness/server": "0.95.0",
|
|
47
|
+
"@types/babel__code-frame": "^7.0.6"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@babel/code-frame": "^7.26.2",
|
|
51
|
+
"@flakiness/shared": "0.95.0",
|
|
52
|
+
"@flakiness/report": "0.95.0",
|
|
53
|
+
"@rgrove/parse-xml": "^4.2.0",
|
|
54
|
+
"commander": "^13.1.0",
|
|
55
|
+
"debug": "^4.3.7",
|
|
56
|
+
"zod": "^3.25.23"
|
|
57
|
+
}
|
|
58
|
+
}
|