@alwaysmeticulous/downloading-helpers 2.223.0 → 2.225.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.
@@ -0,0 +1,13 @@
1
+ import { TestRunDataLocations } from "@alwaysmeticulous/client";
2
+ import { AxiosInstance } from "axios";
3
+ /**
4
+ * Download scope for test run data:
5
+ * - `everything`: Download all available test run data
6
+ * - `coverageByReplayPrOnly`: Download only coverageByReplayPr
7
+ */
8
+ export declare const DOWNLOAD_SCOPES: readonly ["everything", "coverage-by-replay-pr-only"];
9
+ export type TestRunDownloadScope = (typeof DOWNLOAD_SCOPES)[number];
10
+ export declare const getOrFetchTestRunData: (client: AxiosInstance, testRunId: string, downloadScope?: TestRunDownloadScope) => Promise<{
11
+ fileName: string;
12
+ data: TestRunDataLocations;
13
+ }>;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOrFetchTestRunData = exports.DOWNLOAD_SCOPES = void 0;
7
+ const promises_1 = require("fs/promises");
8
+ const path_1 = require("path");
9
+ const client_1 = require("@alwaysmeticulous/client");
10
+ const common_1 = require("@alwaysmeticulous/common");
11
+ const loglevel_1 = __importDefault(require("loglevel"));
12
+ const download_file_1 = require("./download-file");
13
+ const local_data_utils_1 = require("./local-data.utils");
14
+ /**
15
+ * Download scope for test run data:
16
+ * - `everything`: Download all available test run data
17
+ * - `coverageByReplayPrOnly`: Download only coverageByReplayPr
18
+ */
19
+ exports.DOWNLOAD_SCOPES = [
20
+ "everything",
21
+ "coverage-by-replay-pr-only",
22
+ ];
23
+ const DOWNLOAD_SCOPE_TO_FILES_TO_DOWNLOAD = {
24
+ everything: /.*/,
25
+ "coverage-by-replay-pr-only": /^coverageByReplayPr/,
26
+ };
27
+ const shouldDownloadFile = (fileType, downloadScope) => {
28
+ return DOWNLOAD_SCOPE_TO_FILES_TO_DOWNLOAD[downloadScope].test(fileType);
29
+ };
30
+ const TEST_RUN_PREVIOUSLY_DOWNLOADED_FILE_NAME = "previously-downloaded.txt";
31
+ const getOrFetchTestRunData = async (client, testRunId, downloadScope = "everything") => {
32
+ const logger = loglevel_1.default.getLogger(common_1.METICULOUS_LOGGER_NAME);
33
+ const testRunDir = (0, path_1.join)((0, common_1.getMeticulousLocalDataDir)(), "test-runs", (0, local_data_utils_1.sanitizeFilename)(testRunId));
34
+ await (0, promises_1.mkdir)(testRunDir, { recursive: true });
35
+ const releaseLock = await (0, local_data_utils_1.waitToAcquireLockOnDirectory)(testRunDir);
36
+ try {
37
+ const previouslyDownloadedFile = (0, path_1.join)(testRunDir, TEST_RUN_PREVIOUSLY_DOWNLOADED_FILE_NAME);
38
+ // Check what we have already downloaded. This is passed to the downloading function
39
+ // to avoid downloading the same thing twice. This is particularly important because
40
+ // a concurrent process might be using the previously downloaded data, so we don't
41
+ // want to overwrite it while it's being read.
42
+ let previouslyDownloadedScope = undefined;
43
+ if (await (0, local_data_utils_1.fileExists)(previouslyDownloadedFile)) {
44
+ const fileContents = await (0, promises_1.readFile)(previouslyDownloadedFile, "utf-8");
45
+ if (exports.DOWNLOAD_SCOPES.includes(fileContents)) {
46
+ previouslyDownloadedScope = fileContents;
47
+ if (previouslyDownloadedScope === downloadScope ||
48
+ previouslyDownloadedScope === "everything") {
49
+ logger.debug(`Test run data already downloaded at ${testRunDir}`);
50
+ const testRunData = await (0, client_1.getTestRunData)({ client, testRunId });
51
+ return { fileName: testRunDir, data: testRunData };
52
+ }
53
+ else {
54
+ // Instead of trying to reason about how to combine the two scopes, let's bump
55
+ // to downloading everything which is guaranteed to be a superset.
56
+ logger.debug(`Test run data is partially downloaded at ${testRunDir}, will now download everything`);
57
+ downloadScope = "everything";
58
+ }
59
+ }
60
+ else {
61
+ throw new Error(`Error: Unknown previously download scope "${fileContents}"`);
62
+ }
63
+ }
64
+ logger.info("Fetching test run data locations...");
65
+ const testRunData = await (0, client_1.getTestRunData)({ client, testRunId });
66
+ if (!testRunData) {
67
+ logger.error("Error: Could not retrieve test run data. This may be an invalid test run");
68
+ process.exit(1);
69
+ }
70
+ logger.info("Downloading test run data...");
71
+ const downloadPromises = Object.entries(testRunData)
72
+ .filter(([fileType]) => shouldDownloadFile(fileType, downloadScope))
73
+ .map(([fileType, location]) => {
74
+ if (location == null) {
75
+ return null;
76
+ }
77
+ const url = location.signedUrl;
78
+ const filePath = location.filePath;
79
+ if (typeof url !== "string" || typeof filePath !== "string") {
80
+ return null;
81
+ }
82
+ return async () => {
83
+ logger.info(`Downloading and extracting ${fileType}...`);
84
+ await (0, download_file_1.downloadAndExtractFile)(location.signedUrl, filePath, testRunDir);
85
+ if (filePath.endsWith(".json")) {
86
+ const fileContents = await (0, promises_1.readFile)(filePath, "utf-8");
87
+ const json = JSON.parse(fileContents);
88
+ await (0, promises_1.writeFile)(filePath, JSON.stringify(json, null, 2), "utf-8");
89
+ }
90
+ };
91
+ })
92
+ .filter((promise) => promise !== null);
93
+ await Promise.all(downloadPromises.map((fn) => fn()));
94
+ await (0, promises_1.writeFile)(previouslyDownloadedFile, downloadScope, "utf-8");
95
+ logger.info("Test run data downloaded.");
96
+ return { fileName: testRunDir, data: testRunData };
97
+ }
98
+ finally {
99
+ await releaseLock();
100
+ }
101
+ };
102
+ exports.getOrFetchTestRunData = getOrFetchTestRunData;
103
+ //# sourceMappingURL=test-runs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-runs.js","sourceRoot":"","sources":["../../src/file-downloads/test-runs.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAyD;AACzD,+BAA4B;AAC5B,qDAAgF;AAChF,qDAGkC;AAElC,wDAA2B;AAC3B,mDAAyD;AACzD,yDAI4B;AAE5B;;;;GAIG;AACU,QAAA,eAAe,GAAG;IAC7B,YAAY;IACZ,4BAA4B;CACpB,CAAC;AAIX,MAAM,mCAAmC,GAGrC;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,EAAE;gBAC3D,OAAO,IAAI,CAAC;aACb;YAED,OAAO,KAAK,IAAI,EAAE;gBAChB,MAAM,CAAC,IAAI,CAAC,8BAA8B,QAAQ,KAAK,CAAC,CAAC;gBACzD,MAAM,IAAA,sCAAsB,EAC1B,QAAQ,CAAC,SAAS,EAClB,QAAQ,EACR,UAAU,CACX,CAAC;gBACF,IAAI,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;oBAC9B,MAAM,YAAY,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;oBACvD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;oBACtC,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;iBACnE;YACH,CAAC,CAAC;QACJ,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,OAAO,EAAkC,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC;QAEzE,MAAM,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAEtD,MAAM,IAAA,oBAAS,EAAC,wBAAwB,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QAClE,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAEzC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;KACpD;YAAS;QACR,MAAM,WAAW,EAAE,CAAC;KACrB;AACH,CAAC,CAAC;AArGW,QAAA,qBAAqB,yBAqGhC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { sanitizeFilename } from "./file-downloads/local-data.utils";
2
2
  export { getOrFetchReplay, getOrFetchReplayArchive, DownloadScope, } from "./scripts/replays";
3
3
  export { getOrFetchRecordedSession, getOrFetchRecordedSessionData, } from "./file-downloads/sessions";
4
+ export { getOrFetchTestRunData, type TestRunDownloadScope, DOWNLOAD_SCOPES as TEST_RUN_DOWNLOAD_SCOPES, } from "./file-downloads/test-runs";
4
5
  export { fetchAsset, checkIfAssetsOutdated } from "./scripts/replay-assets";
5
6
  export { downloadFile, downloadAndExtractFile, } from "./file-downloads/download-file";
6
7
  export { getReplayDir } from "./scripts/replays";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getReplayDir = exports.downloadAndExtractFile = exports.downloadFile = exports.checkIfAssetsOutdated = exports.fetchAsset = exports.getOrFetchRecordedSessionData = exports.getOrFetchRecordedSession = exports.getOrFetchReplayArchive = exports.getOrFetchReplay = exports.sanitizeFilename = void 0;
3
+ exports.getReplayDir = exports.downloadAndExtractFile = exports.downloadFile = exports.checkIfAssetsOutdated = exports.fetchAsset = exports.TEST_RUN_DOWNLOAD_SCOPES = exports.getOrFetchTestRunData = exports.getOrFetchRecordedSessionData = exports.getOrFetchRecordedSession = exports.getOrFetchReplayArchive = exports.getOrFetchReplay = exports.sanitizeFilename = void 0;
4
4
  var local_data_utils_1 = require("./file-downloads/local-data.utils");
5
5
  Object.defineProperty(exports, "sanitizeFilename", { enumerable: true, get: function () { return local_data_utils_1.sanitizeFilename; } });
6
6
  var replays_1 = require("./scripts/replays");
@@ -9,6 +9,9 @@ Object.defineProperty(exports, "getOrFetchReplayArchive", { enumerable: true, ge
9
9
  var sessions_1 = require("./file-downloads/sessions");
10
10
  Object.defineProperty(exports, "getOrFetchRecordedSession", { enumerable: true, get: function () { return sessions_1.getOrFetchRecordedSession; } });
11
11
  Object.defineProperty(exports, "getOrFetchRecordedSessionData", { enumerable: true, get: function () { return sessions_1.getOrFetchRecordedSessionData; } });
12
+ var test_runs_1 = require("./file-downloads/test-runs");
13
+ Object.defineProperty(exports, "getOrFetchTestRunData", { enumerable: true, get: function () { return test_runs_1.getOrFetchTestRunData; } });
14
+ Object.defineProperty(exports, "TEST_RUN_DOWNLOAD_SCOPES", { enumerable: true, get: function () { return test_runs_1.DOWNLOAD_SCOPES; } });
12
15
  var replay_assets_1 = require("./scripts/replay-assets");
13
16
  Object.defineProperty(exports, "fetchAsset", { enumerable: true, get: function () { return replay_assets_1.fetchAsset; } });
14
17
  Object.defineProperty(exports, "checkIfAssetsOutdated", { enumerable: true, get: function () { return replay_assets_1.checkIfAssetsOutdated; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sEAAqE;AAA5D,oHAAA,gBAAgB,OAAA;AACzB,6CAI2B;AAHzB,2GAAA,gBAAgB,OAAA;AAChB,kHAAA,uBAAuB,OAAA;AAGzB,sDAGmC;AAFjC,qHAAA,yBAAyB,OAAA;AACzB,yHAAA,6BAA6B,OAAA;AAE/B,yDAA4E;AAAnE,2GAAA,UAAU,OAAA;AAAE,sHAAA,qBAAqB,OAAA;AAC1C,gEAGwC;AAFtC,6GAAA,YAAY,OAAA;AACZ,uHAAA,sBAAsB,OAAA;AAExB,6CAAiD;AAAxC,uGAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sEAAqE;AAA5D,oHAAA,gBAAgB,OAAA;AACzB,6CAI2B;AAHzB,2GAAA,gBAAgB,OAAA;AAChB,kHAAA,uBAAuB,OAAA;AAGzB,sDAGmC;AAFjC,qHAAA,yBAAyB,OAAA;AACzB,yHAAA,6BAA6B,OAAA;AAE/B,wDAIoC;AAHlC,kHAAA,qBAAqB,OAAA;AAErB,qHAAA,eAAe,OAA4B;AAE7C,yDAA4E;AAAnE,2GAAA,UAAU,OAAA;AAAE,sHAAA,qBAAqB,OAAA;AAC1C,gEAGwC;AAFtC,6GAAA,YAAY,OAAA;AACZ,uHAAA,sBAAsB,OAAA;AAExB,6CAAiD;AAAxC,uGAAA,YAAY,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwaysmeticulous/downloading-helpers",
3
- "version": "2.223.0",
3
+ "version": "2.225.0",
4
4
  "description": "Helper utilities for downloading files & scripts required to execute replays",
5
5
  "license": "ISC",
6
6
  "main": "dist/index.js",
@@ -20,9 +20,9 @@
20
20
  "test": "jest"
21
21
  },
22
22
  "dependencies": {
23
- "@alwaysmeticulous/api": "^2.223.0",
24
- "@alwaysmeticulous/client": "^2.223.0",
25
- "@alwaysmeticulous/common": "^2.223.0",
23
+ "@alwaysmeticulous/api": "^2.225.0",
24
+ "@alwaysmeticulous/client": "^2.225.0",
25
+ "@alwaysmeticulous/common": "^2.225.0",
26
26
  "axios": "^1.7.9",
27
27
  "axios-retry": "^4.5.0",
28
28
  "extract-zip": "^2.0.1",
@@ -55,5 +55,5 @@
55
55
  "jest": {
56
56
  "preset": "../../jest.config.js"
57
57
  },
58
- "gitHead": "188a6f4ca991635721e66514cb62b7be847b0d0c"
58
+ "gitHead": "615032f8b34b25b5f2048639d31cecbbc013f2e6"
59
59
  }