@flakiness/sdk 0.95.0 → 0.96.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/lib/utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/utils.ts
2
+ import { FlakinessReport } from "@flakiness/report";
2
3
  import assert from "assert";
3
4
  import { spawnSync } from "child_process";
4
5
  import crypto from "crypto";
@@ -6,14 +7,7 @@ import fs from "fs";
6
7
  import http from "http";
7
8
  import https from "https";
8
9
  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;
10
+ import path, { posix as posixPath, win32 as win32Path } from "path";
17
11
  async function existsAsync(aPath) {
18
12
  return fs.promises.stat(aPath).then(() => true).catch((e) => false);
19
13
  }
@@ -38,6 +32,10 @@ function sha1File(filePath) {
38
32
  });
39
33
  });
40
34
  }
35
+ var FLAKINESS_DBG = !!process.env.FLAKINESS_DBG;
36
+ function errorText(error) {
37
+ return FLAKINESS_DBG ? error.stack : error.message;
38
+ }
41
39
  function sha1Buffer(data) {
42
40
  const hash = crypto.createHash("sha1");
43
41
  hash.update(data);
@@ -49,9 +47,9 @@ async function retryWithBackoff(job, backoff = []) {
49
47
  return await job();
50
48
  } catch (e) {
51
49
  if (e instanceof AggregateError)
52
- console.error(`[flakiness.io err]`, e.errors[0].message);
50
+ console.error(`[flakiness.io err]`, errorText(e.errors[0]));
53
51
  else if (e instanceof Error)
54
- console.error(`[flakiness.io err]`, e.message);
52
+ console.error(`[flakiness.io err]`, errorText(e));
55
53
  else
56
54
  console.error(`[flakiness.io err]`, e);
57
55
  await new Promise((x) => setTimeout(x, timeout));
@@ -69,6 +67,7 @@ var httpUtils;
69
67
  reject = b;
70
68
  });
71
69
  const protocol = url.startsWith("https") ? https : http;
70
+ headers = Object.fromEntries(Object.entries(headers).filter(([key, value]) => value !== void 0));
72
71
  const request = protocol.request(url, { method, headers }, (res) => {
73
72
  const chunks = [];
74
73
  res.on("data", (chunk) => chunks.push(chunk));
@@ -190,6 +189,40 @@ function gitCommitInfo(gitRepo) {
190
189
  assert(sha, `FAILED: git rev-parse HEAD @ ${gitRepo}`);
191
190
  return sha.trim();
192
191
  }
192
+ async function resolveAttachmentPaths(report, attachmentsDir) {
193
+ const attachmentFiles = await listFilesRecursively(attachmentsDir);
194
+ const filenameToPath = new Map(attachmentFiles.map((file) => [path.basename(file), file]));
195
+ const attachmentIdToPath = /* @__PURE__ */ new Map();
196
+ const missingAttachments = /* @__PURE__ */ new Set();
197
+ FlakinessReport.visitTests(report, (test) => {
198
+ for (const attempt of test.attempts) {
199
+ for (const attachment of attempt.attachments ?? []) {
200
+ const attachmentPath = filenameToPath.get(attachment.id);
201
+ if (!attachmentPath) {
202
+ missingAttachments.add(attachment.id);
203
+ } else {
204
+ attachmentIdToPath.set(attachment.id, {
205
+ contentType: attachment.contentType,
206
+ id: attachment.id,
207
+ path: attachmentPath
208
+ });
209
+ }
210
+ }
211
+ }
212
+ });
213
+ return { attachmentIdToPath, missingAttachments: Array.from(missingAttachments) };
214
+ }
215
+ async function listFilesRecursively(dir, result = []) {
216
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
217
+ for (const entry of entries) {
218
+ const fullPath = path.join(dir, entry.name);
219
+ if (entry.isDirectory())
220
+ await listFilesRecursively(fullPath, result);
221
+ else
222
+ result.push(fullPath);
223
+ }
224
+ return result;
225
+ }
193
226
  function computeGitRoot(somePathInsideGitRepo) {
194
227
  const root = shell(`git`, ["rev-parse", "--show-toplevel"], {
195
228
  cwd: somePathInsideGitRepo,
@@ -294,26 +327,23 @@ function createEnvironments(projects) {
294
327
  return result;
295
328
  }
296
329
  export {
297
- brotliCompressAsync,
298
- brotliCompressSync,
299
330
  computeGitRoot,
300
331
  createEnvironment,
301
332
  createEnvironments,
333
+ errorText,
302
334
  existsAsync,
303
335
  extractEnvConfiguration,
304
336
  getCallerLocation,
305
337
  getOSInfo,
306
338
  gitCommitInfo,
307
339
  gitFilePath,
308
- gunzipAsync,
309
- gunzipSync,
310
- gzipAsync,
311
340
  httpUtils,
312
341
  inferRunUrl,
313
342
  normalizePath,
314
343
  parseDurationMS,
315
344
  parseStackLocations,
316
345
  parseStringDate,
346
+ resolveAttachmentPaths,
317
347
  retryWithBackoff,
318
348
  sha1Buffer,
319
349
  sha1File,
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@flakiness/sdk",
3
- "version": "0.95.0",
3
+ "version": "0.96.0",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "flakiness": "./lib/cli/cli.js"
7
7
  },
8
8
  "exports": {
9
+ "./localReportApi": {
10
+ "types": "./types/src/localReportApi.d.ts"
11
+ },
9
12
  "./uploader": {
10
13
  "import": "./lib/reportUploader.js",
11
14
  "require": "./lib/reportUploader.js",
@@ -42,17 +45,24 @@
42
45
  "author": "Degu Labs, Inc",
43
46
  "license": "Fair Source 100",
44
47
  "devDependencies": {
48
+ "@flakiness/server": "0.96.0",
45
49
  "@playwright/test": "^1.54.0",
46
- "@flakiness/server": "0.95.0",
47
- "@types/babel__code-frame": "^7.0.6"
50
+ "@types/babel__code-frame": "^7.0.6",
51
+ "@types/compression": "^1.8.1",
52
+ "@types/express": "^4.17.20"
48
53
  },
49
54
  "dependencies": {
50
55
  "@babel/code-frame": "^7.26.2",
51
- "@flakiness/shared": "0.95.0",
52
- "@flakiness/report": "0.95.0",
56
+ "@flakiness/report": "0.96.0",
57
+ "@flakiness/shared": "0.96.0",
53
58
  "@rgrove/parse-xml": "^4.2.0",
59
+ "body-parser": "^1.20.3",
54
60
  "commander": "^13.1.0",
61
+ "compression": "^1.8.1",
55
62
  "debug": "^4.3.7",
63
+ "express": "^4.21.2",
64
+ "express-async-errors": "^3.1.1",
65
+ "open": "^10.2.0",
56
66
  "zod": "^3.25.23"
57
67
  }
58
68
  }