@flakiness/sdk 0.148.0 → 0.149.1
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 +95 -2
- package/lib/{httpUtils.js → _internalUtils.js} +70 -13
- package/lib/_stable-hash.d.js +1 -0
- package/lib/browser.js +154 -0
- package/lib/ciUtils.js +42 -0
- package/lib/createEnvironment.js +92 -1
- package/lib/createTestStepSnippets.js +17 -122
- package/lib/flakinessProjectConfig.js +368 -25
- package/lib/gitWorktree.js +312 -0
- package/lib/index.js +827 -514
- package/lib/normalizeReport.js +114 -0
- package/lib/reportUtils.js +382 -111
- package/lib/reportUtilsBrowser.js +138 -0
- package/lib/showReport.js +401 -47
- package/lib/stripAnsi.js +9 -0
- package/lib/systemUtilizationSampler.js +21 -0
- package/lib/{reportUploader.js → uploadReport.js} +67 -63
- package/lib/visitTests.js +19 -0
- package/lib/writeReport.js +31 -0
- package/package.json +5 -7
- package/types/tsconfig.tsbuildinfo +1 -1
- package/lib/browser/index.js +0 -127
- package/lib/git.js +0 -55
- package/lib/localGit.js +0 -48
- package/lib/pathutils.js +0 -20
- package/lib/utils.js +0 -44
package/lib/browser/index.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// src/browser/index.ts
|
|
2
|
-
import { FlakinessReport } from "@flakiness/flakiness-report";
|
|
3
|
-
|
|
4
|
-
// src/reportUtils.ts
|
|
5
|
-
import { Multimap } from "@flakiness/shared/common/multimap.js";
|
|
6
|
-
import { xxHash, xxHashObject } from "@flakiness/shared/common/utils.js";
|
|
7
|
-
var ReportUtils;
|
|
8
|
-
((ReportUtils2) => {
|
|
9
|
-
function visitTests(report, testVisitor) {
|
|
10
|
-
function visitSuite(suite, parents) {
|
|
11
|
-
parents.push(suite);
|
|
12
|
-
for (const test of suite.tests ?? [])
|
|
13
|
-
testVisitor(test, parents);
|
|
14
|
-
for (const childSuite of suite.suites ?? [])
|
|
15
|
-
visitSuite(childSuite, parents);
|
|
16
|
-
parents.pop();
|
|
17
|
-
}
|
|
18
|
-
for (const test of report.tests ?? [])
|
|
19
|
-
testVisitor(test, []);
|
|
20
|
-
for (const suite of report.suites)
|
|
21
|
-
visitSuite(suite, []);
|
|
22
|
-
}
|
|
23
|
-
ReportUtils2.visitTests = visitTests;
|
|
24
|
-
function normalizeReport(report) {
|
|
25
|
-
const gEnvs = /* @__PURE__ */ new Map();
|
|
26
|
-
const gSuites = /* @__PURE__ */ new Map();
|
|
27
|
-
const gTests = new Multimap();
|
|
28
|
-
const gSuiteIds = /* @__PURE__ */ new Map();
|
|
29
|
-
const gTestIds = /* @__PURE__ */ new Map();
|
|
30
|
-
const gEnvIds = /* @__PURE__ */ new Map();
|
|
31
|
-
const gSuiteChildren = new Multimap();
|
|
32
|
-
const gSuiteTests = new Multimap();
|
|
33
|
-
for (const env of report.environments) {
|
|
34
|
-
const envId = computeEnvId(env);
|
|
35
|
-
gEnvs.set(envId, env);
|
|
36
|
-
gEnvIds.set(env, envId);
|
|
37
|
-
}
|
|
38
|
-
const usedEnvIds = /* @__PURE__ */ new Set();
|
|
39
|
-
function visitTests2(tests, suiteId) {
|
|
40
|
-
for (const test of tests ?? []) {
|
|
41
|
-
const testId = computeTestId(test, suiteId);
|
|
42
|
-
gTests.set(testId, test);
|
|
43
|
-
gTestIds.set(test, testId);
|
|
44
|
-
gSuiteTests.set(suiteId, test);
|
|
45
|
-
for (const attempt of test.attempts) {
|
|
46
|
-
const env = report.environments[attempt.environmentIdx];
|
|
47
|
-
const envId = gEnvIds.get(env);
|
|
48
|
-
usedEnvIds.add(envId);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
function visitSuite(suite, parentSuiteId) {
|
|
53
|
-
const suiteId = computeSuiteId(suite, parentSuiteId);
|
|
54
|
-
gSuites.set(suiteId, suite);
|
|
55
|
-
gSuiteIds.set(suite, suiteId);
|
|
56
|
-
for (const childSuite of suite.suites ?? []) {
|
|
57
|
-
visitSuite(childSuite, suiteId);
|
|
58
|
-
gSuiteChildren.set(suiteId, childSuite);
|
|
59
|
-
}
|
|
60
|
-
visitTests2(suite.tests ?? [], suiteId);
|
|
61
|
-
}
|
|
62
|
-
function transformTests(tests) {
|
|
63
|
-
const testIds = new Set(tests.map((test) => gTestIds.get(test)));
|
|
64
|
-
return [...testIds].map((testId) => {
|
|
65
|
-
const tests2 = gTests.getAll(testId);
|
|
66
|
-
const tags = tests2.map((test) => test.tags ?? []).flat();
|
|
67
|
-
return {
|
|
68
|
-
location: tests2[0].location,
|
|
69
|
-
title: tests2[0].title,
|
|
70
|
-
tags: tags.length ? tags : void 0,
|
|
71
|
-
attempts: tests2.map((t) => t.attempts).flat().map((attempt) => ({
|
|
72
|
-
...attempt,
|
|
73
|
-
environmentIdx: envIdToIndex.get(gEnvIds.get(report.environments[attempt.environmentIdx]))
|
|
74
|
-
}))
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function transformSuites(suites) {
|
|
79
|
-
const suiteIds = new Set(suites.map((suite) => gSuiteIds.get(suite)));
|
|
80
|
-
return [...suiteIds].map((suiteId) => {
|
|
81
|
-
const suite = gSuites.get(suiteId);
|
|
82
|
-
return {
|
|
83
|
-
location: suite.location,
|
|
84
|
-
title: suite.title,
|
|
85
|
-
type: suite.type,
|
|
86
|
-
suites: transformSuites(gSuiteChildren.getAll(suiteId)),
|
|
87
|
-
tests: transformTests(gSuiteTests.getAll(suiteId))
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
visitTests2(report.tests ?? [], "suiteless");
|
|
92
|
-
for (const suite of report.suites)
|
|
93
|
-
visitSuite(suite);
|
|
94
|
-
const newEnvironments = [...usedEnvIds];
|
|
95
|
-
const envIdToIndex = new Map(newEnvironments.map((envId, index) => [envId, index]));
|
|
96
|
-
return {
|
|
97
|
-
...report,
|
|
98
|
-
environments: newEnvironments.map((envId) => gEnvs.get(envId)),
|
|
99
|
-
suites: transformSuites(report.suites),
|
|
100
|
-
tests: transformTests(report.tests ?? [])
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
ReportUtils2.normalizeReport = normalizeReport;
|
|
104
|
-
function computeEnvId(env) {
|
|
105
|
-
return xxHashObject(env);
|
|
106
|
-
}
|
|
107
|
-
function computeSuiteId(suite, parentSuiteId) {
|
|
108
|
-
return xxHash([
|
|
109
|
-
parentSuiteId ?? "",
|
|
110
|
-
suite.type,
|
|
111
|
-
suite.location?.file ?? "",
|
|
112
|
-
suite.title
|
|
113
|
-
]);
|
|
114
|
-
}
|
|
115
|
-
function computeTestId(test, suiteId) {
|
|
116
|
-
return xxHash([
|
|
117
|
-
suiteId,
|
|
118
|
-
test.location?.file ?? "",
|
|
119
|
-
test.title
|
|
120
|
-
]);
|
|
121
|
-
}
|
|
122
|
-
})(ReportUtils || (ReportUtils = {}));
|
|
123
|
-
export {
|
|
124
|
-
FlakinessReport,
|
|
125
|
-
ReportUtils
|
|
126
|
-
};
|
|
127
|
-
//# sourceMappingURL=index.js.map
|
package/lib/git.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// src/git.ts
|
|
2
|
-
import assert from "assert";
|
|
3
|
-
|
|
4
|
-
// src/pathutils.ts
|
|
5
|
-
import { posix as posixPath, win32 as win32Path } from "path";
|
|
6
|
-
var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
|
|
7
|
-
var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
|
|
8
|
-
function normalizePath(aPath) {
|
|
9
|
-
if (IS_WIN32_PATH.test(aPath)) {
|
|
10
|
-
aPath = aPath.split(win32Path.sep).join(posixPath.sep);
|
|
11
|
-
}
|
|
12
|
-
if (IS_ALMOST_POSIX_PATH.test(aPath))
|
|
13
|
-
return "/" + aPath[0] + aPath.substring(2);
|
|
14
|
-
return aPath;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// src/utils.ts
|
|
18
|
-
import { spawnSync } from "child_process";
|
|
19
|
-
var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
|
|
20
|
-
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");
|
|
21
|
-
function shell(command, args, options) {
|
|
22
|
-
try {
|
|
23
|
-
const result = spawnSync(command, args, { encoding: "utf-8", ...options });
|
|
24
|
-
if (result.status !== 0) {
|
|
25
|
-
return void 0;
|
|
26
|
-
}
|
|
27
|
-
return result.stdout.trim();
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.error(e);
|
|
30
|
-
return void 0;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/git.ts
|
|
35
|
-
function gitCommitInfo(gitRepo) {
|
|
36
|
-
const sha = shell(`git`, ["rev-parse", "HEAD"], {
|
|
37
|
-
cwd: gitRepo,
|
|
38
|
-
encoding: "utf-8"
|
|
39
|
-
});
|
|
40
|
-
assert(sha, `FAILED: git rev-parse HEAD @ ${gitRepo}`);
|
|
41
|
-
return sha.trim();
|
|
42
|
-
}
|
|
43
|
-
function computeGitRoot(somePathInsideGitRepo) {
|
|
44
|
-
const root = shell(`git`, ["rev-parse", "--show-toplevel"], {
|
|
45
|
-
cwd: somePathInsideGitRepo,
|
|
46
|
-
encoding: "utf-8"
|
|
47
|
-
});
|
|
48
|
-
assert(root, `FAILED: git rev-parse --show-toplevel HEAD @ ${somePathInsideGitRepo}`);
|
|
49
|
-
return normalizePath(root);
|
|
50
|
-
}
|
|
51
|
-
export {
|
|
52
|
-
computeGitRoot,
|
|
53
|
-
gitCommitInfo
|
|
54
|
-
};
|
|
55
|
-
//# sourceMappingURL=git.js.map
|
package/lib/localGit.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// src/localGit.ts
|
|
2
|
-
import { exec } from "child_process";
|
|
3
|
-
import debug from "debug";
|
|
4
|
-
import { promisify } from "util";
|
|
5
|
-
var log = debug("fk:git");
|
|
6
|
-
var execAsync = promisify(exec);
|
|
7
|
-
async function listLocalCommits(gitRoot, head, count) {
|
|
8
|
-
const FIELD_SEPARATOR = "|~|";
|
|
9
|
-
const RECORD_SEPARATOR = "\0";
|
|
10
|
-
const prettyFormat = [
|
|
11
|
-
"%H",
|
|
12
|
-
// %H: Full commit hash
|
|
13
|
-
"%at",
|
|
14
|
-
// %at: Author date as a Unix timestamp (seconds since epoch)
|
|
15
|
-
"%an",
|
|
16
|
-
// %an: Author name
|
|
17
|
-
"%s",
|
|
18
|
-
// %s: Subject (the first line of the commit message)
|
|
19
|
-
"%P"
|
|
20
|
-
// %P: Parent hashes (space-separated)
|
|
21
|
-
].join(FIELD_SEPARATOR);
|
|
22
|
-
const command = `git log ${head} -n ${count} --pretty=format:"${prettyFormat}" -z`;
|
|
23
|
-
try {
|
|
24
|
-
const { stdout } = await execAsync(command, { cwd: gitRoot });
|
|
25
|
-
if (!stdout) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
return stdout.trim().split(RECORD_SEPARATOR).filter((record) => record).map((record) => {
|
|
29
|
-
const [commitId, timestampStr, author, message, parentsStr] = record.split(FIELD_SEPARATOR);
|
|
30
|
-
const parents = parentsStr ? parentsStr.split(" ").filter((p) => p) : [];
|
|
31
|
-
return {
|
|
32
|
-
commitId,
|
|
33
|
-
timestamp: parseInt(timestampStr, 10) * 1e3,
|
|
34
|
-
author,
|
|
35
|
-
message,
|
|
36
|
-
parents,
|
|
37
|
-
walkIndex: 0
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
} catch (error) {
|
|
41
|
-
log(`Failed to list commits for repository at ${gitRoot}:`, error);
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export {
|
|
46
|
-
listLocalCommits
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=localGit.js.map
|
package/lib/pathutils.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// src/pathutils.ts
|
|
2
|
-
import { posix as posixPath, win32 as win32Path } from "path";
|
|
3
|
-
var IS_WIN32_PATH = new RegExp("^[a-zA-Z]:\\\\", "i");
|
|
4
|
-
var IS_ALMOST_POSIX_PATH = new RegExp("^[a-zA-Z]:/", "i");
|
|
5
|
-
function normalizePath(aPath) {
|
|
6
|
-
if (IS_WIN32_PATH.test(aPath)) {
|
|
7
|
-
aPath = aPath.split(win32Path.sep).join(posixPath.sep);
|
|
8
|
-
}
|
|
9
|
-
if (IS_ALMOST_POSIX_PATH.test(aPath))
|
|
10
|
-
return "/" + aPath[0] + aPath.substring(2);
|
|
11
|
-
return aPath;
|
|
12
|
-
}
|
|
13
|
-
function gitFilePath(gitRoot, absolutePath) {
|
|
14
|
-
return posixPath.relative(gitRoot, absolutePath);
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
gitFilePath,
|
|
18
|
-
normalizePath
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=pathutils.js.map
|
package/lib/utils.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
import { spawnSync } from "child_process";
|
|
3
|
-
var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
|
|
4
|
-
function errorText(error) {
|
|
5
|
-
return FLAKINESS_DBG ? error.stack : error.message;
|
|
6
|
-
}
|
|
7
|
-
async function retryWithBackoff(job, backoff = []) {
|
|
8
|
-
for (const timeout of backoff) {
|
|
9
|
-
try {
|
|
10
|
-
return await job();
|
|
11
|
-
} catch (e) {
|
|
12
|
-
if (e instanceof AggregateError)
|
|
13
|
-
console.error(`[flakiness.io err]`, errorText(e.errors[0]));
|
|
14
|
-
else if (e instanceof Error)
|
|
15
|
-
console.error(`[flakiness.io err]`, errorText(e));
|
|
16
|
-
else
|
|
17
|
-
console.error(`[flakiness.io err]`, e);
|
|
18
|
-
await new Promise((x) => setTimeout(x, timeout));
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return await job();
|
|
22
|
-
}
|
|
23
|
-
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");
|
|
24
|
-
function stripAnsi(str) {
|
|
25
|
-
return str.replace(ansiRegex, "");
|
|
26
|
-
}
|
|
27
|
-
function shell(command, args, options) {
|
|
28
|
-
try {
|
|
29
|
-
const result = spawnSync(command, args, { encoding: "utf-8", ...options });
|
|
30
|
-
if (result.status !== 0) {
|
|
31
|
-
return void 0;
|
|
32
|
-
}
|
|
33
|
-
return result.stdout.trim();
|
|
34
|
-
} catch (e) {
|
|
35
|
-
console.error(e);
|
|
36
|
-
return void 0;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export {
|
|
40
|
-
retryWithBackoff,
|
|
41
|
-
shell,
|
|
42
|
-
stripAnsi
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=utils.js.map
|