Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(storage): stream the export tarball without archiver

Yudhi Armyndharis8c6c273d3224
diff --git a/docs/08-development-guidelines.md b/docs/08-development-guidelines.md
index df2269356..8687f9745 100644
--- a/docs/08-development-guidelines.md
+++ b/docs/08-development-guidelines.md
@@ -426,9 +426,6 @@ describe('resolveReconnectConfig', () => {
```typescript
// test/app.e2e-spec.ts
-// archiver is ESM-only and AppModule pulls it in; stub it so ts-jest (CommonJS) can load the graph.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
diff --git a/package-lock.json b/package-lock.json
index 6be9fe114..dd67cf798 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -29,7 +29,6 @@
"@socket.io/redis-adapter": "^8.3.0",
"@whiskeysockets/baileys": "7.0.0-rc14",
"adm-zip": "^0.6.1",
- "archiver": "^8.0.0",
"audio-decode": "^2.2.3",
"better-sqlite3": "^13.0.3",
"bullmq": "^6.3.13",
@@ -61,7 +60,6 @@
"@nestjs/cli": "^11.0.24",
"@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.2.7",
- "@types/archiver": "^8.0.0",
"@types/dockerode": "^4.0.2",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
@@ -4203,6 +4201,7 @@
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
"integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==",
+ "dev": true,
"license": "MIT",
"optional": true,
"engines": {
@@ -4731,17 +4730,6 @@
"tslib": "^2.4.0"
}
},
- "node_modules/@types/archiver": {
- "version": "8.0.0",
- "resolved": "https://registry.npmjs.org/@types/archiver/-/archiver-8.0.0.tgz",
- "integrity": "sha512-YpXPbEuv9+eUIPPQWUPahj3cvs9isWRuF+J4z+KbdYVDO3rWorWQFxUVHnwPu2AgKwvgpki5F2VMX0Xx+mX45A==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "@types/node": "*",
- "@types/readdir-glob": "*"
- }
- },
"node_modules/@types/babel__core": {
"version": "7.20.5",
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
@@ -5022,16 +5010,6 @@
"dev": true,
"license": "MIT"
},
- "node_modules/@types/readdir-glob": {
- "version": "1.1.5",
- "resolved": "https://registry.npmjs.org/@types/readdir-glob/-/readdir-glob-1.1.5.tgz",
- "integrity": "sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "@types/node": "*"
- }
- },
"node_modules/@types/send": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz",
@@ -6040,6 +6018,7 @@
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"license": "MIT",
+ "optional": true,
"dependencies": {
"event-target-shim": "^5.0.0"
},
@@ -6277,26 +6256,6 @@
"integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==",
"license": "MIT"
},
- "node_modules/archiver": {
- "version": "8.0.0",
- "resolved": "https://registry.npmjs.org/archiver/-/archiver-8.0.0.tgz",
- "integrity": "sha512-fV1orZfsnPn9BaSByR/qE67rJCLJEy2Ox5bq7nJh+jquWaNh6Sfec75kJ2T6PtdGUbPQlrVoSVCEOa5SdiTQ1g==",
- "license": "MIT",
- "dependencies": {
- "async": "^3.2.4",
- "buffer-crc32": "^1.0.0",
- "is-stream": "^4.0.0",
- "lazystream": "^1.0.0",
- "normalize-path": "^3.0.0",
- "readable-stream": "^4.0.0",
- "readdir-glob": "^3.0.0",
- "tar-stream": "^3.0.0",
- "zip-stream": "^7.0.2"
- },
- "engines": {
- "node": ">=18"
- }
- },
"node_modules/archiver-utils": {
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/archiver-utils/-/archiver-utils-5.0.2.tgz",
@@ -6395,18 +6354,6 @@
"url": "https://github.com/sponsors/isaacs"
}
},
- "node_modules/archiver/node_modules/is-stream": {
- "version": "4.0.1",
- "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-4.0.1.tgz",
- "integrity": "sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==",
- "license": "MIT",
- "engines": {
- "node": ">=18"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
- }
- },
"node_modules/arg": {
"version": "4.1.3",
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
@@ -6447,7 +6394,8 @@
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz",
"integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==",
- "license": "MIT"
+ "license": "MIT",
+ "optional": true
},
"node_modules/async-mutex": {
"version": "0.5.0",
@@ -6626,6 +6574,7 @@
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz",
"integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==",
+ "dev": true,
"license": "MIT",
"engines": {
"node": "18 || 20 || >=22"
@@ -6856,6 +6805,7 @@
"version": "5.0.12",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz",
"integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==",
+ "dev": true,
"license": "MIT",
"dependencies": {
"balanced-match": "^4.0.2"
@@ -6950,6 +6900,7 @@
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-1.0.0.tgz",
"integrity": "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w==",
"license": "MIT",
+ "optional": true,
"engines": {
"node": ">=8.0.0"
}
@@ -7420,34 +7371,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
- "node_modules/compress-commons": {
- "version": "7.0.1",
- "resolved": "https://registry.npmjs.org/compress-commons/-/compress-commons-7.0.1.tgz",
- "integrity": "sha512-g0S8KAD8qf4+V//pr3BfB1aBnARLXNz2Gx+jmHU0LEriUuoQUOPOulVquHKTJ8+EAIIO7fhseNDr9wK5Q9FKBQ==",
- "license": "MIT",
- "dependencies": {
- "crc-32": "^1.2.0",
- "crc32-stream": "^7.0.1",
- "is-stream": "^4.0.0",
- "normalize-path": "^3.0.0",
- "readable-stream": "^4.0.0"
- },
- "engines": {
- "node": ">=18"
- }
- },
- "node_modules/compress-commons/node_modules/is-stream": {
- "version": "4.0.1",
- "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-4.0.1.tgz",
- "integrity": "sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==",
- "license": "MIT",
- "engines": {
- "node": ">=18"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
- }
- },
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -7692,7 +7615,8 @@
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
- "license": "MIT"
+ "license": "MIT",
+ "optional": true
},
"node_modules/cors": {
"version": "2.8.6",
@@ -7757,6 +7681,7 @@
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
"integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
"license": "Apache-2.0",
+ "optional": true,
"bin": {
"crc32": "bin/crc32.njs"
},
@@ -7764,19 +7689,6 @@
"node": ">=0.8"
}
},
- "node_modules/crc32-stream": {
- "version": "7.0.1",
- "resolved": "https://registry.npmjs.org/crc32-stream/-/crc32-stream-7.0.1.tgz",
- "integrity": "sha512-IBWsY8xznyQrcHn8h4bC8/4ErNke5elzgG8GcqF4RFPw6aHkWWRc7Tgw6upjaTX/CT/yQgqYENkxYsTYN+hW2g==",
- "license": "MIT",
- "dependencies": {
- "crc-32": "^1.2.0",
- "readable-stream": "^4.0.0"
- },
- "engines": {
- "node": ">=18"
- }
- },
"node_modules/create-require": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
@@ -8624,6 +8536,7 @@
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==",
"license": "MIT",
+ "optional": true,
"engines": {
"node": ">=6"
}
@@ -8638,6 +8551,7 @@
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",
+ "devOptional": true,
"license": "MIT",
"engines": {
"node": ">=0.8.x"
@@ -10534,6 +10448,7 @@
"resolved": "https://registry.npmjs.org/lazystream/-/lazystream-1.0.1.tgz",
"integrity": "sha512-b94GiNHQNy6JNTrt5w6zNyffMrNkXZb3KTkCZJb2V1xaEGCk093vkZ2jk3tpaeP33/OiXC+WvK9AxUebnf5nbw==",
"license": "MIT",
+ "optional": true,
"dependencies": {
"readable-stream": "^2.0.5"
},
@@ -10545,13 +10460,15 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
- "license": "MIT"
+ "license": "MIT",
+ "optional": true
},
"node_modules/lazystream/node_modules/readable-stream": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
"license": "MIT",
+ "optional": true,
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
@@ -10566,13 +10483,15 @@
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
- "license": "MIT"
+ "license": "MIT",
+ "optional": true
},
"node_modules/lazystream/node_modules/string_decoder": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"license": "MIT",
+ "optional": true,
"dependencies": {
"safe-buffer": "~5.1.0"
}
@@ -11266,6 +11185,7 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz",
"integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==",
+ "devOptional": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
@@ -11980,6 +11900,7 @@
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
"license": "MIT",
+ "optional": true,
"engines": {
"node": ">= 0.6.0"
}
@@ -11988,7 +11909,8 @@
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
- "license": "MIT"
+ "license": "MIT",
+ "optional": true
},
"node_modules/process-warning": {
"version": "5.0.0",
@@ -12364,6 +12286,7 @@
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz",
"integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==",
"license": "MIT",
+ "optional": true,
"dependencies": {
"abort-controller": "^3.0.0",
"buffer": "^6.0.3",
@@ -12394,41 +12317,12 @@
}
],
"license": "MIT",
+ "optional": true,
"dependencies": {
"base64-js": "^1.3.1",
"ieee754": "^1.2.1"
}
},
- "node_modules/readdir-glob": {
- "version": "3.0.0",
- "resolved": "https://registry.npmjs.org/readdir-glob/-/readdir-glob-3.0.0.tgz",
- "integrity": "sha512-AhNB2KgKeVJr16nK9LLZbJNWnYoT23ZrumNKFDebHBdkC8KHSqWo871JAUhoWC/RtjEVdqNMFpM6qrwRbaUqpw==",
- "license": "Apache-2.0",
- "dependencies": {
- "minimatch": "^10.2.2"
- },
- "engines": {
- "node": ">=18"
- },
- "funding": {
- "url": "https://github.com/sponsors/yqnn"
- }
- },
- "node_modules/readdir-glob/node_modules/minimatch": {
- "version": "10.2.5",
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.5.tgz",
- "integrity": "sha512-MULkVLfKGYDFYejP07QOurDLLQpcjk7Fw+7jXS2R2czRQzR56yHRveU5NDJEOviH+hETZKSkIk5c+T23GjFUMg==",
- "license": "BlueOak-1.0.0",
- "dependencies": {
- "brace-expansion": "^5.0.5"
- },
- "engines": {
- "node": "18 || 20 || >=22"
- },
- "funding": {
- "url": "https://github.com/sponsors/isaacs"
- }
- },
"node_modules/readdirp": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz",
@@ -15180,20 +15074,6 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
- "node_modules/zip-stream": {
- "version": "7.0.5",
- "resolved": "https://registry.npmjs.org/zip-stream/-/zip-stream-7.0.5.tgz",
- "integrity": "sha512-dSvYKdvLsAHCDqPOhIwk/q5CvuWtTB3Dgpoe0uVEFjTzIOAmsQpprX25InCvrvJsirEbu1OHyy67n/kAj1Sw/w==",
- "license": "MIT",
- "dependencies": {
- "compress-commons": "^7.0.0",
- "normalize-path": "^3.0.0",
- "readable-stream": "^4.0.0"
- },
- "engines": {
- "node": ">=18"
- }
- },
"node_modules/zod": {
"version": "4.6.7",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",
diff --git a/package.json b/package.json
index e8f20e6c2..f53357924 100644
--- a/package.json
+++ b/package.json
@@ -87,7 +87,6 @@
"@socket.io/redis-adapter": "^8.3.0",
"@whiskeysockets/baileys": "7.0.0-rc14",
"adm-zip": "^0.6.1",
- "archiver": "^8.0.0",
"audio-decode": "^2.2.3",
"better-sqlite3": "^13.0.3",
"bullmq": "^6.3.13",
@@ -119,7 +118,6 @@
"@nestjs/cli": "^11.0.24",
"@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.2.7",
- "@types/archiver": "^8.0.0",
"@types/dockerode": "^4.0.2",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
@@ -198,7 +196,6 @@
"moduleNameMapper": {
"^@whiskeysockets/baileys$": "<rootDir>/../test/__mocks__/@whiskeysockets/baileys.ts",
"^@whiskeysockets/baileys/(.*)$": "<rootDir>/../test/__mocks__/@whiskeysockets/baileys.ts",
- "^archiver$": "<rootDir>/../test/__mocks__/archiver.ts",
"^https-proxy-agent$": "<rootDir>/../test/__mocks__/https-proxy-agent.ts",
"^puppeteer$": "<rootDir>/../test/__mocks__/puppeteer.ts",
"^socks-proxy-agent$": "<rootDir>/../test/__mocks__/socks-proxy-agent.ts"
diff --git a/src/common/storage/s3-key-prefix.spec.ts b/src/common/storage/s3-key-prefix.spec.ts
index 4c14df9e2..4c1d2306c 100644
--- a/src/common/storage/s3-key-prefix.spec.ts
+++ b/src/common/storage/s3-key-prefix.spec.ts
@@ -3,9 +3,6 @@ import * as os from 'os';
import * as path from 'path';
import { ConfigService } from '@nestjs/config';
-// archiver is ESM-only and never used here; stub it before StorageService is imported.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
const mockSend = jest.fn();
jest.mock('@aws-sdk/client-s3', () => ({
S3Client: jest.fn().mockImplementation(() => ({ send: mockSend })),
diff --git a/src/common/storage/storage-local-files.ts b/src/common/storage/storage-local-files.ts
index 7d46e9f3f..e811166a3 100644
--- a/src/common/storage/storage-local-files.ts
+++ b/src/common/storage/storage-local-files.ts
@@ -56,7 +56,9 @@ export async function* iterateLocalFiles(localPath: string, prefix = ''): AsyncG
}
for (const entry of entries) {
- const relativePath = dir ? path.join(dir, entry.name) : entry.name;
+ // Keys use "/" on every host: the archive carries them verbatim, and a key with a backslash would
+ // restore as a different file on another host.
+ const relativePath = dir ? path.posix.join(dir, entry.name) : entry.name;
if (entry.isDirectory()) {
queue.push({ dir: relativePath, depth: depth + 1 });
} else if (entry.isFile()) {
diff --git a/src/common/storage/storage-transfer.spec.ts b/src/common/storage/storage-transfer.spec.ts
index df0c2aa8e..3fd62d0da 100644
--- a/src/common/storage/storage-transfer.spec.ts
+++ b/src/common/storage/storage-transfer.spec.ts
@@ -3,47 +3,6 @@ import { PassThrough, Readable } from 'stream';
import * as tar from 'tar-stream';
import { createGzip } from 'zlib';
-// archiver v8 is ESM-only and ts-jest cannot load it here. This stand-in keeps the parts of its
-// TarArchive contract the export relies on: a stream entry with a known size is piped straight into
-// the tar pack (without one it is collected first), 'entry' fires once the entry is written, and an
-// entry failure is emitted as 'error'. The real archiver runs in test/storage-export-streaming.e2e-spec.ts.
-jest.mock('archiver', () => {
- /* eslint-disable @typescript-eslint/no-require-imports */
- const { EventEmitter } = require('events') as typeof import('events');
- const tar = require('tar-stream') as typeof import('tar-stream');
- const { createGzip } = require('zlib') as typeof import('zlib');
- /* eslint-enable @typescript-eslint/no-require-imports */
- class TarArchive extends EventEmitter {
- private readonly pack = tar.pack();
- private readonly gzip = createGzip();
- constructor() {
- super();
- this.pack.pipe(this.gzip);
- }
- pipe(destination: NodeJS.WritableStream): NodeJS.WritableStream {
- return this.gzip.pipe(destination);
- }
- append(source: Readable, data: { name: string; stats?: { size: number } }): void {
- const done = (err?: Error | null): void => void (err ? this.emit('error', err) : this.emit('entry', data));
- if (data.stats) {
- source.pipe(this.pack.entry({ name: data.name, size: data.stats.size }, done));
- return;
- }
- const chunks: Buffer[] = [];
- source.on('data', (chunk: Buffer) => chunks.push(chunk));
- source.on('end', () => this.pack.entry({ name: data.name }, Buffer.concat(chunks), done));
- }
- finalize(): Promise<void> {
- this.pack.finalize();
- return Promise.resolve();
- }
- abort(): void {
- this.pack.destroy();
- }
- }
- return { TarArchive };
-});
-
import {
createExportStream,
DEFAULT_IMPORT_MAX_BYTES,
@@ -182,6 +141,28 @@ describe('createExportStream streams one file at a time', () => {
expect(imported.get(files[1])?.equals(contentFor(files[1]))).toBe(true);
});
+ // A key is an opaque name. A backslash, a doubled slash or a leading `word:` belongs to it, and an archive that
+ // rewrites any of them restores the file under a different key.
+ it.each([true, false])(
+ 'writes every key under exactly the name it is stored by (size reported: %s)',
+ async withSize => {
+ const names = [
+ 'media/back\\slash.bin',
+ 'media/dir//double.bin',
+ '628123:[email protected]/c.jpg',
+ 'status:x/y.bin',
+ ];
+ const { openFile } = trackingOpener({}, withSize);
+ const logger = makeLogger();
+ const output = await createExportStream(() => Promise.resolve(names), openFile, logger as never);
+
+ const imported = await importAll(output, logger);
+
+ expect([...imported.keys()]).toEqual(names);
+ expect(imported.get(names[0])?.equals(contentFor(names[0]))).toBe(true);
+ },
+ );
+
it('fails the output with a read error part-way through a file and stops opening files', async () => {
const { stats, openFile } = trackingOpener({ 'media/file-b.bin': 'read' });
const output = await createExportStream(() => Promise.resolve(files), openFile, makeLogger() as never);
diff --git a/src/common/storage/storage-transfer.ts b/src/common/storage/storage-transfer.ts
index c6f08d1f6..0b372789b 100644
--- a/src/common/storage/storage-transfer.ts
+++ b/src/common/storage/storage-transfer.ts
@@ -1,7 +1,5 @@
-import { TarArchive } from 'archiver';
import * as tar from 'tar-stream';
-import { createGunzip } from 'zlib';
-import * as fs from 'fs';
+import { createGunzip, createGzip } from 'zlib';
import { Readable, PassThrough, Transform, pipeline } from 'stream';
import { LoggerService } from '../services/logger.service';
import { positiveIntFromEnv } from '../utils/env-int';
@@ -34,14 +32,16 @@ export function isMissingObjectError(error: unknown): boolean {
// ============================================================================
/**
- * A file opened for export. `size` is the byte length the tar header declares; without it archiver
- * has to buffer that one entry to learn its length.
+ * A file opened for export. `size` is the byte length the tar header declares; without it the entry
+ * has to be buffered to learn its length.
*/
export interface ExportFileSource {
stream: Readable;
size?: number;
}
+type TarPack = ReturnType<typeof tar.pack>;
+
// Returns the output as soon as the file list is known and fills the archive in the background, one
// entry at a time: each file is opened only after the previous entry has been written through to the
// consumer, so memory holds one file's in-flight chunks, not the whole store. A file deleted since the
@@ -73,21 +73,27 @@ export async function createExportStream(
}
const output = new PassThrough();
- const archive = new TarArchive({
- gzip: true,
- gzipOptions: { level: 6 },
- });
+ const pack = tar.pack();
+ const gzip = createGzip({ level: 6 });
- // Surface archive-level failures (gzip/finalize) on the returned stream instead of
- // letting them become an unhandled rejection or a silently truncated download.
- archive.on('error', (err: Error) => {
+ // Surface archive-level failures (tar/gzip) on the returned stream instead of letting them become an
+ // uncaught 'error' event or a silently truncated download.
+ const failArchive = (err: Error): void => {
logger.error('Export archive failed', String(err));
output.destroy(err);
- });
+ };
+ pack.on('error', failArchive);
+ gzip.on('error', failArchive);
- archive.pipe(output);
+ pack.pipe(gzip).pipe(output);
+ // The output closes early when the archive fails or the consumer goes away: release the tar and gzip
+ // streams with whatever they still buffer. After a clean finish both have ended, so this does nothing.
+ output.once('close', () => {
+ pack.destroy();
+ gzip.destroy();
+ });
- appendEntries(files, openFile, archive, output, logger).catch((err: Error) => output.destroy(err));
+ appendEntries(files, openFile, pack, output, logger).catch((err: Error) => output.destroy(err));
return output;
}
@@ -105,10 +111,40 @@ function enforceSize(file: string, size: number | undefined): Transform {
});
}
+/**
+ * Write one tar entry from `source` and call `done` once it is complete or torn down. A known size is
+ * piped straight into the entry; without one the source is buffered first, since a tar header has to
+ * declare the length up front. A failed entry also destroys the pack, which fails the output through
+ * its 'error' listener, so the entry's own error is not needed here; it still needs a listener of its
+ * own, because an 'error' event nothing listens for would crash the process.
+ */
+function writeEntry(
+ pack: TarPack,
+ source: Readable,
+ header: { name: string; mode: number; mtime: Date },
+ size: number | undefined,
+ output: PassThrough,
+ done: () => void,
+): void {
+ if (size !== undefined) {
+ const sink = pack.entry({ ...header, size }, () => done());
+ sink.on('error', () => undefined);
+ source.pipe(sink);
+ return;
+ }
+ const chunks: Buffer[] = [];
+ source.on('data', (chunk: Buffer) => chunks.push(chunk));
+ source.on('end', () => {
+ // The pack is gone once the output closed, and adding an entry to a destroyed pack throws.
+ if (output.destroyed) return;
+ pack.entry(header, Buffer.concat(chunks), () => done()).on('error', () => undefined);
+ });
+}
+
async function appendEntries(
files: string[],
openFile: (filePath: string) => Promise<ExportFileSource>,
- archive: TarArchive,
+ pack: TarPack,
output: PassThrough,
logger: LoggerService,
): Promise<void> {
@@ -136,11 +172,10 @@ async function appendEntries(
stream.destroy();
break;
}
- // The tar sink fails with an error nothing can listen for when an entry's length differs from the
- // size in its header, which would crash the process. A file rewritten between open and read does
- // that, so the length is checked here and a mismatch fails the export like a read error, before
- // the sink sees the extra byte or the early end. pipeline() also forwards a source error, which
- // pipe() does not.
+ // The tar sink fails with a bare "Size mismatch" when an entry's length differs from the size in
+ // its header. A file rewritten between open and read does that, so the length is checked here and
+ // a mismatch fails the export like a read error, naming the file, before the sink sees the extra
+ // byte or the early end. pipeline() also forwards a source error, which pipe() does not.
const entry = pipeline(stream, enforceSize(file, size), err => {
if (!err || output.destroyed) return;
logger.error(`Export failed reading file: ${file}`, String(err));
@@ -148,26 +183,18 @@ async function appendEntries(
});
await new Promise<void>(resolve => {
const done = (): void => {
- archive.removeListener('entry', done);
output.removeListener('close', done);
resolve();
};
- archive.on('entry', done);
output.on('close', done);
- // Mode and date are set explicitly: archiver derives both from `stats` when present, and this
- // stand-in carries only the size.
- const stats = size === undefined ? undefined : ({ size } as fs.Stats);
- archive.append(entry, { name: file, mode: 0o644, date: new Date(), stats });
+ writeEntry(pack, entry, { name: file, mode: 0o644, mtime: new Date() }, size, output, done);
});
if (output.destroyed) {
stream.destroy();
break;
}
}
- if (output.destroyed) {
- archive.abort();
- return;
- }
+ if (output.destroyed) return;
// Same reasoning as the entry-count warning in createExportStream, for the import's total-bytes cap.
const localByteCap = positiveIntFromEnv('STORAGE_IMPORT_MAX_TOTAL_BYTES', DEFAULT_IMPORT_MAX_TOTAL_BYTES);
const warnAboveBytes = Math.min(localByteCap, DEFAULT_IMPORT_MAX_TOTAL_BYTES);
@@ -188,9 +215,7 @@ async function appendEntries(
'Raise STORAGE_IMPORT_MAX_BYTES on the destination before restoring this archive.',
);
}
- // finalize() rejections also emit via the 'error' handler above; catch the promise so it
- // never surfaces as an unhandled rejection.
- archive.finalize().catch(() => undefined);
+ pack.finalize();
}
// ============================================================================
diff --git a/src/common/storage/storage.service.s3-reprobe.spec.ts b/src/common/storage/storage.service.s3-reprobe.spec.ts
index 504f876da..1bd8b9e1b 100644
--- a/src/common/storage/storage.service.s3-reprobe.spec.ts
+++ b/src/common/storage/storage.service.s3-reprobe.spec.ts
@@ -4,11 +4,6 @@ import * as path from 'path';
import { Readable } from 'stream';
import { ConfigService } from '@nestjs/config';
-// `archiver` v8 ships ESM-only, which ts-jest can't parse transitively. These tests never touch the
-// export path (archiver's only consumer), so a lightweight stub suffices — same approach as the
-// other storage specs. Must run before importing StorageService.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
// Mock the AWS SDK so no real network call is made. Each test drives `mockSend`: HeadBucket probes
// (boot + re-probe) and GetObject reads are distinguished by the mocked command constructors.
const mockSend = jest.fn();
diff --git a/src/common/storage/storage.service.s3.spec.ts b/src/common/storage/storage.service.s3.spec.ts
index 92ed17f20..1578c14a9 100644
--- a/src/common/storage/storage.service.s3.spec.ts
+++ b/src/common/storage/storage.service.s3.spec.ts
@@ -3,11 +3,6 @@ import * as os from 'os';
import * as path from 'path';
import { ConfigService } from '@nestjs/config';
-// `archiver` v8 ships ESM-only, which ts-jest can't parse transitively. These tests never touch the
-// export path (archiver's only consumer), so a lightweight stub suffices — same approach as the local
-// spec. Must run before importing StorageService.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
// Mock the AWS SDK so no real network call is made: HeadBucket resolves (bucket reachable), and the
// S3Client constructor is a jest.fn so each test can assert on the exact config it received.
jest.mock('@aws-sdk/client-s3', () => {
diff --git a/src/common/storage/storage.service.spec.ts b/src/common/storage/storage.service.spec.ts
index ce2e2f14c..488c48c7c 100644
--- a/src/common/storage/storage.service.spec.ts
+++ b/src/common/storage/storage.service.spec.ts
@@ -6,11 +6,6 @@ import { createGzip } from 'zlib';
import { PassThrough, Readable } from 'stream';
import { ConfigService } from '@nestjs/config';
-// `archiver` v8 ships as ESM only, which ts-jest cannot parse when StorageService
-// is imported transitively. These tests never exercise the export path (which is
-// the only consumer of archiver), so a lightweight stub is sufficient.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
import { StorageService } from './storage.service';
import * as transfer from './storage-transfer';
@@ -360,10 +355,10 @@ describe('StorageService.createExportStream enumerates the whole store', () => {
const iterateFiles = jest.spyOn(service, 'iterateFiles').mockImplementation(async function* () {
yield await Promise.resolve('media/a.bin');
});
- // No read stub: the enumerator runs before the archive is constructed, and `archiver` is mocked
- // at the top of this file, so the call rejects there and no file is ever opened. Which
- // enumeration was used is settled by then, and that is the whole claim here.
- await service.createExportStream().catch(() => undefined);
+ // No read stub: the file does not exist, so the export skips it with a warning. Which enumeration
+ // was used is settled before that, and that is the whole claim here.
+ const output = await service.createExportStream();
+ output.destroy();
expect(iterateFiles).toHaveBeenCalled();
expect(listFiles).not.toHaveBeenCalled();
@@ -386,6 +381,23 @@ describe('StorageService.createExportStream enumerates the whole store', () => {
create.mockRestore();
});
+ // An S3 console "Create folder" leaves a zero-byte object whose key ends in "/". It holds no file, and as an
+ // archive entry of file type it would fail the import that restores the archive onto a local store.
+ it('leaves out an S3 folder placeholder, which holds no file', async () => {
+ const { service } = makeService();
+ jest.spyOn(service, 'iterateFiles').mockImplementation(async function* () {
+ yield await Promise.resolve('sess1/');
+ yield 'sess1/a.bin';
+ yield 'sess1/deep/';
+ });
+ const create = jest.spyOn(transfer, 'createExportStream').mockResolvedValue(new PassThrough());
+
+ await service.createExportStream();
+
+ expect(await create.mock.calls[0][0]()).toEqual(['sess1/a.bin']);
+ create.mockRestore();
+ });
+
/**
* The count is the OTHER half of the same fix and had no test of its own — reverting it to the
* capped listing left the suite green. It is the pre-check an operator runs before that migration,
diff --git a/src/common/storage/storage.service.ts b/src/common/storage/storage.service.ts
index 9202148c8..52eba8956 100644
--- a/src/common/storage/storage.service.ts
+++ b/src/common/storage/storage.service.ts
@@ -467,6 +467,9 @@ export class StorageService implements OnModuleDestroy {
}
private isExportableKey(file: string): boolean {
+ // A key ending in "/" is a folder placeholder an S3 console leaves behind: it holds no file, and written to
+ // the archive as one it would fail the import that restores it onto a local store.
+ if (file.endsWith('/')) return false;
if (isSafeStorageKey(file)) return true;
this.logger.warn(`Skipping an unsafe storage key in the export: ${JSON.stringify(file)}`);
return false;
diff --git a/src/modules/chat-media/chat-media-archive.service.spec.ts b/src/modules/chat-media/chat-media-archive.service.spec.ts
index bee128482..ceb3c620e 100644
--- a/src/modules/chat-media/chat-media-archive.service.spec.ts
+++ b/src/modules/chat-media/chat-media-archive.service.spec.ts
@@ -4,8 +4,6 @@ import * as path from 'path';
import { DataSource, IsNull, Not, Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
import { StorageService } from '../../common/storage/storage.service';
import { Message, MessageDirection, MessageStatus } from '../message/entities/message.entity';
import { ChatMediaArchiveService, CHAT_MEDIA_PREFIX } from './chat-media-archive.service';
diff --git a/src/modules/infra/infra-access-control.spec.ts b/src/modules/infra/infra-access-control.spec.ts
index f4930806b..bbdf1a49a 100644
--- a/src/modules/infra/infra-access-control.spec.ts
+++ b/src/modules/infra/infra-access-control.spec.ts
@@ -1,8 +1,3 @@
-// StorageService (imported transitively by the infra controllers) pulls in `archiver`
-// v8, which is ESM-only and cannot be parsed by ts-jest. The controller logic
-// under test never touches archiver, so a lightweight stub is sufficient.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
// saveConfig writes the generated env via fs.writeFileSync and reads the existing file
// via fs.existsSync/readFileSync; mock those so tests assert produced content without
// touching the filesystem. existsSync defaults to false (no prior config).
diff --git a/src/modules/infra/infra-config.controller.spec.ts b/src/modules/infra/infra-config.controller.spec.ts
index 4efeaa981..6c1b68eff 100644
--- a/src/modules/infra/infra-config.controller.spec.ts
+++ b/src/modules/infra/infra-config.controller.spec.ts
@@ -2,11 +2,6 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
-// StorageService (imported transitively by the infra controllers) pulls in `archiver`
-// v8, which is ESM-only and cannot be parsed by ts-jest. The controller logic
-// under test never touches archiver, so a lightweight stub is sufficient.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
// saveConfig writes the generated env via fs.writeFileSync and reads the existing file
// via fs.existsSync/readFileSync; mock those so tests assert produced content without
// touching the filesystem. existsSync defaults to false (no prior config).
diff --git a/src/modules/infra/infra-data.controller.spec.ts b/src/modules/infra/infra-data.controller.spec.ts
index 7105e74ea..99d51d927 100644
--- a/src/modules/infra/infra-data.controller.spec.ts
+++ b/src/modules/infra/infra-data.controller.spec.ts
@@ -1,8 +1,3 @@
-// StorageService (imported transitively by the infra controllers) pulls in `archiver`
-// v8, which is ESM-only and cannot be parsed by ts-jest. The controller logic
-// under test never touches archiver, so a lightweight stub is sufficient.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
// saveConfig writes the generated env via fs.writeFileSync and reads the existing file
// via fs.existsSync/readFileSync; mock those so tests assert produced content without
// touching the filesystem. existsSync defaults to false (no prior config) — except for
diff --git a/src/modules/infra/infra-data.import.pg.spec.ts b/src/modules/infra/infra-data.import.pg.spec.ts
index 19648db82..3fa7e4939 100644
--- a/src/modules/infra/infra-data.import.pg.spec.ts
+++ b/src/modules/infra/infra-data.import.pg.spec.ts
@@ -24,10 +24,6 @@ import { SendIdempotencyKey } from '../message/entities/send-idempotency-key.ent
import { AutomationRule } from '../automation/entities/automation-rule.entity';
import { postgresUtcExtra } from '../../database/postgres-utc';
-// StorageService (imported transitively by the infra controllers) pulls in `archiver`, which is
-// ESM-only and cannot be parsed by ts-jest; the import never touches it.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
/**
* The replace-all import trims send_idempotency_keys with a statement that compares the claim's
* varchar sessionId with sessions.id, a uuid on PostgreSQL. The comparison only holds because the
diff --git a/src/modules/infra/infra-status.controller.spec.ts b/src/modules/infra/infra-status.controller.spec.ts
index 40fd3f60f..a025aefed 100644
--- a/src/modules/infra/infra-status.controller.spec.ts
+++ b/src/modules/infra/infra-status.controller.spec.ts
@@ -1,8 +1,3 @@
-// StorageService (imported transitively by the infra controllers) pulls in `archiver`
-// v8, which is ESM-only and cannot be parsed by ts-jest. The controller logic
-// under test never touches archiver, so a lightweight stub is sufficient.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
// saveConfig writes the generated env via fs.writeFileSync and reads the existing file
// via fs.existsSync/readFileSync; mock those so tests assert produced content without
// touching the filesystem. existsSync defaults to false (no prior config).
diff --git a/src/modules/infra/infra-storage.controller.spec.ts b/src/modules/infra/infra-storage.controller.spec.ts
index aed2a53f0..152d09905 100644
--- a/src/modules/infra/infra-storage.controller.spec.ts
+++ b/src/modules/infra/infra-storage.controller.spec.ts
@@ -3,11 +3,6 @@ import * as os from 'os';
import * as path from 'path';
import { Readable, Writable } from 'stream';
-// StorageService (imported transitively by the infra controllers) pulls in `archiver`
-// v8, which is ESM-only and cannot be parsed by ts-jest. The controller logic
-// under test never touches archiver, so a lightweight stub is sufficient.
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
// saveConfig writes the generated env via fs.writeFileSync and reads the existing file
// via fs.existsSync/readFileSync; mock those so tests assert produced content without
// touching the filesystem. existsSync defaults to false (no prior config).
diff --git a/src/modules/status-store/status-store.service.spec.ts b/src/modules/status-store/status-store.service.spec.ts
index 03bf4ce75..dac588925 100644
--- a/src/modules/status-store/status-store.service.spec.ts
+++ b/src/modules/status-store/status-store.service.spec.ts
@@ -4,8 +4,6 @@ import * as path from 'path';
import { DataSource, Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
-jest.mock('archiver', () => ({ default: jest.fn() }));
-
import { StorageService } from '../../common/storage/storage.service';
import { LidMappingStoreService } from '../../engine/identity/lid-mapping-store.service';
import { LidMapping } from '../../engine/identity/lid-mapping.entity';
diff --git a/src/modules/webhook/webhook-recovery.pg.spec.ts b/src/modules/webhook/webhook-recovery.pg.spec.ts
index d4e7a9e15..e62f13fa6 100644
--- a/src/modules/webhook/webhook-recovery.pg.spec.ts
+++ b/src/modules/webhook/webhook-recovery.pg.spec.ts
@@ -14,7 +14,6 @@ import { ChatMediaArchiveService } from '../chat-media/chat-media-archive.servic
import type { StorageService } from '../../common/storage/storage.service';
import { mergeSentMetadata, updateMessageMetadata } from '../message/message-metadata';
-jest.mock('archiver', () => ({ default: jest.fn() }));
const describePostgres = process.env.DATABASE_TYPE === 'postgres' ? describe : describe.skip;
describePostgres('webhook and media recovery on PostgreSQL', () => {
diff --git a/test/__mocks__/archiver.ts b/test/__mocks__/archiver.ts
deleted file mode 100644
index 605d44574..000000000
--- a/test/__mocks__/archiver.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-/**
- * Unit-test stub for `archiver` (ESM-only). ts-jest runs in CommonJS mode, so any source file that
- * imports it — directly (StorageService) or transitively (anything that injects StorageService or a
- * module built on it, e.g. StatusStoreService) — fails to parse without this stub once pulled into the
- * unit test graph. None of the unit suites exercise the tar/zip export path itself, so stubs for
- * TarArchive and default export are sufficient. Jest applies this stub in the e2e lane too (test/ is
- * that config's rootDir); storage-export-streaming.e2e-spec.ts calls jest.unmock('archiver') to
- * exercise the real tar/zip export path.
- */
-
-interface TarArchiveStub {
- on: (event: string, listener: (...args: unknown[]) => void) => TarArchiveStub;
- pipe: (destination: unknown) => TarArchiveStub;
- append: (source: unknown, metadata?: unknown) => TarArchiveStub;
- finalize: () => Promise<void>;
-}
-
-function makeTarArchiveStub(): TarArchiveStub {
- const stub: TarArchiveStub = {
- on: jest.fn(() => stub),
- pipe: jest.fn(() => stub),
- append: jest.fn(() => stub),
- finalize: jest.fn(() => Promise.resolve()),
- };
- return stub;
-}
-
-export const TarArchive = jest.fn(makeTarArchiveStub);
-
-export default jest.fn();
diff --git a/test/app.e2e-spec.ts b/test/app.e2e-spec.ts
index 7462766b3..3fef75a1a 100644
--- a/test/app.e2e-spec.ts
+++ b/test/app.e2e-spec.ts
@@ -1,7 +1,3 @@
-// archiver v8 is ESM-only and is pulled in transitively via the @Global StorageModule when
-// AppModule boots; stub it so ts-jest (CommonJS) can load the module graph.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
@@ -14,7 +10,7 @@ import { renderHttpRequestMetrics, resetHttpRequestMetrics } from './../src/comm
/**
* Smoke e2e: the previous test asserted a non-existent Hello-World route and failed to
- * even compile (ESM archiver). This boots the real app (SQLite, no queue) and checks the
+ * even compile. This boots the real app (SQLite, no queue) and checks the
* public health route, the auth boundary, and unknown-route handling.
*/
describe('App smoke (e2e)', () => {
diff --git a/test/automation-rules.e2e-spec.ts b/test/automation-rules.e2e-spec.ts
index 23c014d41..a6441266f 100644
--- a/test/automation-rules.e2e-spec.ts
+++ b/test/automation-rules.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
diff --git a/test/baileys-engine.e2e-spec.ts b/test/baileys-engine.e2e-spec.ts
index 0baba32a8..14f753daf 100644
--- a/test/baileys-engine.e2e-spec.ts
+++ b/test/baileys-engine.e2e-spec.ts
@@ -1,5 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
// Stub the heavy Baileys lib: the boot gate only verifies registration/enable, never a socket connect.
jest.mock('@whiskeysockets/baileys', () => ({
__esModule: true,
diff --git a/test/chat-scope.e2e-spec.ts b/test/chat-scope.e2e-spec.ts
index 8f11d43f6..d2c1a8a33 100644
--- a/test/chat-scope.e2e-spec.ts
+++ b/test/chat-scope.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
diff --git a/test/global-routes-session-scope.e2e-spec.ts b/test/global-routes-session-scope.e2e-spec.ts
index c92db1b99..2c0a80f3c 100644
--- a/test/global-routes-session-scope.e2e-spec.ts
+++ b/test/global-routes-session-scope.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
diff --git a/test/group-invite-code-role.e2e-spec.ts b/test/group-invite-code-role.e2e-spec.ts
index 76d0d0398..359a38c8f 100644
--- a/test/group-invite-code-role.e2e-spec.ts
+++ b/test/group-invite-code-role.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
diff --git a/test/infra-session-scope.e2e-spec.ts b/test/infra-session-scope.e2e-spec.ts
index 7b566d5ff..b7e1c846d 100644
--- a/test/infra-session-scope.e2e-spec.ts
+++ b/test/infra-session-scope.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
diff --git a/test/ingress-instance-throttle.e2e-spec.ts b/test/ingress-instance-throttle.e2e-spec.ts
index ab35affc5..c54c5f092 100644
--- a/test/ingress-instance-throttle.e2e-spec.ts
+++ b/test/ingress-instance-throttle.e2e-spec.ts
@@ -1,7 +1,3 @@
-// archiver v8 is ESM-only and is pulled in transitively via the @Global StorageModule when
-// AppModule boots; stub it so ts-jest (CommonJS) can load the module graph.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
// IngressService reads these per delivery; set them before AppModule is imported anyway, since the
// ingress guard sizes its own tier from INGRESS_INSTANCE_TTL once at boot.
process.env.INGRESS_INSTANCE_LIMIT = '3';
diff --git a/test/ingress-ip-throttle.e2e-spec.ts b/test/ingress-ip-throttle.e2e-spec.ts
index c4b10221c..265310faf 100644
--- a/test/ingress-ip-throttle.e2e-spec.ts
+++ b/test/ingress-ip-throttle.e2e-spec.ts
@@ -1,7 +1,3 @@
-// archiver v8 is ESM-only and is pulled in transitively via the @Global StorageModule when
-// AppModule boots; stub it so ts-jest (CommonJS) can load the module graph.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
// Set BEFORE AppModule is imported: InstanceThrottlerGuard reads these in onModuleInit (once, at
// boot), not per request. The per-instance limit is left at its default and never binds here: it is
// charged only after signature verification, and every request below names an unknown instance.
diff --git a/test/integration-fabric.e2e-spec.ts b/test/integration-fabric.e2e-spec.ts
index cf55c08a3..7f862cd1f 100644
--- a/test/integration-fabric.e2e-spec.ts
+++ b/test/integration-fabric.e2e-spec.ts
@@ -1,7 +1,3 @@
-// archiver v8 is ESM-only and is pulled in transitively via the @Global StorageModule when
-// AppModule boots; stub it so ts-jest (CommonJS) can load the module graph.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { createHash, createHmac, randomBytes } from 'node:crypto';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
diff --git a/test/integration-instance.e2e-spec.ts b/test/integration-instance.e2e-spec.ts
index b3d32f46b..71e72703c 100644
--- a/test/integration-instance.e2e-spec.ts
+++ b/test/integration-instance.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only; stub it so ts-jest can load the module graph.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
// Seed the well-known dev-admin-key BEFORE AppModule is imported (mirrors mcp-auth.e2e-spec.ts's
// pattern of setting the enabling env var ahead of the import).
process.env.ALLOW_DEV_API_KEY = 'true';
diff --git a/test/jest-e2e.json b/test/jest-e2e.json
index 37642d36d..6cf28c43b 100644
--- a/test/jest-e2e.json
+++ b/test/jest-e2e.json
@@ -8,7 +8,7 @@
"^.+\\.(t|j)s$": "ts-jest"
},
"transformIgnorePatterns": [
- "node_modules/(?!(archiver|compress-commons|crc32-stream|zip-stream|archiver-utils|is-stream|readdir-glob|https-proxy-agent|socks-proxy-agent|agent-base|proxy-agent-negotiate)/)"
+ "node_modules/(?!(https-proxy-agent|socks-proxy-agent|agent-base|proxy-agent-negotiate)/)"
],
"moduleNameMapper": {
"^puppeteer$": "<rootDir>/__mocks__/puppeteer.ts"
diff --git a/test/mcp-auth.e2e-spec.ts b/test/mcp-auth.e2e-spec.ts
index 8a993bf85..da5ff3a74 100644
--- a/test/mcp-auth.e2e-spec.ts
+++ b/test/mcp-auth.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only; stub it so ts-jest can load the module graph.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
// Enable the MCP server before AppModule is imported.
process.env.MCP_ENABLED = 'true';
diff --git a/test/message-send.e2e-spec.ts b/test/message-send.e2e-spec.ts
index d7802aca2..502332193 100644
--- a/test/message-send.e2e-spec.ts
+++ b/test/message-send.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
diff --git a/test/plugins-session-scope.e2e-spec.ts b/test/plugins-session-scope.e2e-spec.ts
index 119acbe54..054f5ee90 100644
--- a/test/plugins-session-scope.e2e-spec.ts
+++ b/test/plugins-session-scope.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
diff --git a/test/queue-on.e2e-spec.ts b/test/queue-on.e2e-spec.ts
index 308914997..def9d82c7 100644
--- a/test/queue-on.e2e-spec.ts
+++ b/test/queue-on.e2e-spec.ts
@@ -1,7 +1,3 @@
-// archiver v8 is ESM-only and is pulled in transitively via the @Global StorageModule when
-// AppModule boots; stub it so ts-jest (CommonJS) can load the module graph.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { spawnSync } from 'node:child_process';
// Queue-on boot env, set BEFORE AppModule is imported below: QUEUE_ENABLED is read at module-eval
diff --git a/test/search.e2e-spec.ts b/test/search.e2e-spec.ts
index 095c781f4..8e6aab376 100644
--- a/test/search.e2e-spec.ts
+++ b/test/search.e2e-spec.ts
@@ -1,7 +1,3 @@
-// archiver v8 is ESM-only and is pulled in transitively via the @Global StorageModule when
-// AppModule boots; stub it so ts-jest (CommonJS) can load the module graph (same as other e2e specs).
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
// Seed the well-known dev-admin-key (ApiKeyRole.ADMIN, so it satisfies @RequireRole(OPERATOR))
// BEFORE AppModule is imported, mirroring integration-instance.e2e-spec.ts's env-first pattern.
process.env.ALLOW_DEV_API_KEY = 'true';
diff --git a/test/session-proxy.e2e-spec.ts b/test/session-proxy.e2e-spec.ts
index 9e2ea8431..e6af700bf 100644
--- a/test/session-proxy.e2e-spec.ts
+++ b/test/session-proxy.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import http from 'http';
import { AddressInfo } from 'net';
import { Test, TestingModule } from '@nestjs/testing';
diff --git a/test/session-scope.e2e-spec.ts b/test/session-scope.e2e-spec.ts
index 3245fd7b7..4e77dd4b5 100644
--- a/test/session-scope.e2e-spec.ts
+++ b/test/session-scope.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { getRepositoryToken } from '@nestjs/typeorm';
diff --git a/test/session-teardown-pending-http.e2e-spec.ts b/test/session-teardown-pending-http.e2e-spec.ts
index 04e2a344a..9cc16ae59 100644
--- a/test/session-teardown-pending-http.e2e-spec.ts
+++ b/test/session-teardown-pending-http.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import { ConflictException, HttpStatus, INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import request from 'supertest';
diff --git a/test/storage-export-streaming.e2e-spec.ts b/test/storage-export-streaming.e2e-spec.ts
index c501430ae..4948560b4 100644
--- a/test/storage-export-streaming.e2e-spec.ts
+++ b/test/storage-export-streaming.e2e-spec.ts
@@ -1,6 +1,3 @@
-// test/__mocks__/archiver.ts replaces archiver in every suite under test/; this one needs the real one.
-jest.unmock('archiver');
-
import { randomBytes } from 'crypto';
import * as fs from 'fs';
import * as os from 'os';
@@ -80,11 +77,10 @@ describe('Local storage export completeness', () => {
});
/**
- * The storage export runs against the real archiver here (the unit config stubs it). An export of a
- * large media store must not read every file into memory before anything consumes the archive:
- * files are opened one at a time, each only after the previous entry was written through.
+ * An export of a large media store must not read every file into memory before anything consumes the
+ * archive: files are opened one at a time, each only after the previous entry was written through.
*/
-describe('Storage export streams one file at a time (e2e, real archiver)', () => {
+describe('Storage export streams one file at a time (e2e)', () => {
const FILE_BYTES = 1024 * 1024;
const makeLogger = () => ({ warn: jest.fn(), error: jest.fn(), log: jest.fn(), debug: jest.fn() });
@@ -134,8 +130,8 @@ describe('Storage export streams one file at a time (e2e, real archiver)', () =>
const { stats, openFile } = trackingOpener();
const output = await createExportStream(() => Promise.resolve(files), openFile, makeLogger() as never);
- // Let the background loop run as far as it can without a reader. The pipeline's own buffers (about
- // a megabyte in archiver) absorb a file or two; everything past that has to wait for the reader.
+ // Let the background loop run as far as it can without a reader. The pipeline's own buffers absorb
+ // a file or two; everything past that has to wait for the reader.
await new Promise(resolve => setTimeout(resolve, 300));
expect(stats.opened).toBeLessThanOrEqual(3);
output.destroy();
diff --git a/test/webhooks.e2e-spec.ts b/test/webhooks.e2e-spec.ts
index a05b440ad..285152707 100644
--- a/test/webhooks.e2e-spec.ts
+++ b/test/webhooks.e2e-spec.ts
@@ -1,6 +1,3 @@
-// archiver v8 is ESM-only (pulled in transitively via @Global StorageModule); stub for ts-jest CJS.
-jest.mock('archiver', () => ({ TarArchive: jest.fn() }));
-
import http from 'http';
import crypto from 'crypto';
import { AddressInfo } from 'net';