@argos-ci/core 6.2.3 → 6.3.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.
Files changed (2) hide show
  1. package/dist/index.mjs +59 -21
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -1133,6 +1133,27 @@ const chunk = (collection, size) => {
1133
1133
  return result;
1134
1134
  };
1135
1135
  /**
1136
+ * Split items into chunks whose serialized JSON size stays under `maxBytes`.
1137
+ * An item larger than `maxBytes` on its own gets its own chunk.
1138
+ */
1139
+ const chunkBySize = (items, maxBytes) => {
1140
+ const chunks = [];
1141
+ let current = [];
1142
+ let currentBytes = 0;
1143
+ for (const item of items) {
1144
+ const size = Buffer.byteLength(JSON.stringify(item));
1145
+ if (current.length > 0 && currentBytes + size > maxBytes) {
1146
+ chunks.push(current);
1147
+ current = [];
1148
+ currentBytes = 0;
1149
+ }
1150
+ current.push(item);
1151
+ currentBytes += size;
1152
+ }
1153
+ if (current.length > 0) chunks.push(current);
1154
+ return chunks;
1155
+ };
1156
+ /**
1136
1157
  * Map over a collection asynchronously, processing at most `size` items
1137
1158
  * concurrently to limit memory pressure.
1138
1159
  */
@@ -1488,6 +1509,12 @@ async function skip(params) {
1488
1509
  * Limits concurrency to avoid memory pressure when handling many screenshots.
1489
1510
  */
1490
1511
  const CHUNK_SIZE = 10;
1512
+ /**
1513
+ * Maximum serialized size (in bytes) of the screenshots sent in a single
1514
+ * `updateBuild` request. Kept below the API request body size limit (3MB) to
1515
+ * leave room for the rest of the body (build metadata, etc.).
1516
+ */
1517
+ const MAX_UPDATE_BUILD_SCREENSHOTS_BYTES = 2 * 1024 * 1024;
1491
1518
  const PLAYWRIGHT_TRACE_CONTENT_TYPE = "application/zip";
1492
1519
  /**
1493
1520
  * Upload screenshots to Argos.
@@ -1625,28 +1652,39 @@ async function upload(params) {
1625
1652
  });
1626
1653
  }) ?? []]);
1627
1654
  debug("Updating build");
1628
- const uploadBuildResponse = await apiClient.PUT("/builds/{buildId}", {
1629
- params: { path: { buildId: result.build.id } },
1630
- body: {
1631
- screenshots: snapshots.map((snapshot) => ({
1632
- key: snapshot.hash,
1633
- name: snapshot.name,
1634
- metadata: snapshot.metadata,
1635
- pwTraceKey: snapshot.pwTrace?.hash ?? null,
1636
- threshold: snapshot.threshold ?? config?.threshold ?? null,
1637
- baseName: snapshot.baseName,
1638
- parentName: snapshot.parentName,
1639
- contentType: snapshot.contentType
1640
- })),
1641
- parallel: config.parallel,
1642
- parallelTotal: config.parallelTotal,
1643
- parallelIndex: config.parallelIndex,
1644
- metadata: params.metadata
1645
- }
1646
- });
1647
- if (uploadBuildResponse.error) throwAPIError(uploadBuildResponse.error, uploadBuildResponse.response);
1655
+ const screenshotChunks = chunkBySize(snapshots.map((snapshot) => ({
1656
+ key: snapshot.hash,
1657
+ name: snapshot.name,
1658
+ metadata: snapshot.metadata,
1659
+ pwTraceKey: snapshot.pwTrace?.hash ?? null,
1660
+ threshold: snapshot.threshold ?? config?.threshold ?? null,
1661
+ baseName: snapshot.baseName,
1662
+ parentName: snapshot.parentName,
1663
+ contentType: snapshot.contentType
1664
+ })), MAX_UPDATE_BUILD_SCREENSHOTS_BYTES);
1665
+ if (screenshotChunks.length === 0) screenshotChunks.push([]);
1666
+ const groupsRequests = !config.parallel || config.parallelIndex != null;
1667
+ let build = null;
1668
+ for (let index = 0; index < screenshotChunks.length; index++) {
1669
+ const isLast = index === screenshotChunks.length - 1;
1670
+ debug(`Updating build (request ${index + 1}/${screenshotChunks.length})`);
1671
+ const uploadBuildResponse = await apiClient.PUT("/builds/{buildId}", {
1672
+ params: { path: { buildId: result.build.id } },
1673
+ body: {
1674
+ screenshots: screenshotChunks[index] ?? [],
1675
+ parallel: config.parallel,
1676
+ parallelTotal: config.parallelTotal,
1677
+ parallelIndex: config.parallelIndex,
1678
+ final: groupsRequests ? isLast : true,
1679
+ metadata: isLast ? params.metadata : void 0
1680
+ }
1681
+ });
1682
+ if (uploadBuildResponse.error) throwAPIError(uploadBuildResponse.error, uploadBuildResponse.response);
1683
+ if (isLast) build = uploadBuildResponse.data.build;
1684
+ }
1685
+ if (!build) throw new Error("Invariant: the build was not updated");
1648
1686
  return {
1649
- build: uploadBuildResponse.data.build,
1687
+ build,
1650
1688
  screenshots: snapshots
1651
1689
  };
1652
1690
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/core",
3
3
  "description": "Node.js SDK for visual testing with Argos.",
4
- "version": "6.2.3",
4
+ "version": "6.3.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -39,7 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@argos-ci/api-client": "0.22.1",
42
+ "@argos-ci/api-client": "0.23.0",
43
43
  "@argos-ci/util": "4.0.0",
44
44
  "convict": "^6.2.5",
45
45
  "debug": "^4.4.3",
@@ -68,5 +68,5 @@
68
68
  "lint": "eslint .",
69
69
  "test": "vitest"
70
70
  },
71
- "gitHead": "70ab43ebd8cbeeb25bb95e978556bbe754b8c073"
71
+ "gitHead": "a2fb6e1a811e66f3839293ea5a71e93fee838aac"
72
72
  }