Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
build: run the participant-arity patcher in the image and on install
Yudhi Armyndharis6a7b01282f31
diff --git a/Dockerfile b/Dockerfileindex 0fe0ee653..37b105ef8 100644--- a/Dockerfile+++ b/Dockerfile@@ -120,7 +120,7 @@ COPY package*.json ./# scripts/postinstall.js rides along: `npm ci` below runs the hook, which fails# when the file is missing. With the patcher present the hook applies it in# --best-effort mode; the explicit fatal run right after is the real gate.-COPY scripts/postinstall.js scripts/patch-wwebjs-201832.js scripts/wwebjs-201832.patch scripts/patch-wwebjs-newsletter-preview.js scripts/patch-wwebjs-status.js scripts/patch-wwebjs-ready-sync.js scripts/patch-baileys-appstate.js scripts/patch-baileys-newsletter-create.js ./scripts/+COPY scripts/postinstall.js scripts/patch-wwebjs-201832.js scripts/wwebjs-201832.patch scripts/patch-wwebjs-newsletter-preview.js scripts/patch-wwebjs-status.js scripts/patch-wwebjs-ready-sync.js scripts/patch-wwebjs-participant-arity.js scripts/patch-baileys-appstate.js scripts/patch-baileys-newsletter-create.js ./scripts/# Install production dependencies only, then apply the backports. The status patcher runs after# the two patchers it depends on: its transforms were written against the tree they leave behind.@@ -132,6 +132,7 @@ RUN npm ci --omit=dev \&& node scripts/patch-wwebjs-newsletter-preview.js \&& node scripts/patch-wwebjs-status.js \&& node scripts/patch-wwebjs-ready-sync.js \+ && node scripts/patch-wwebjs-participant-arity.js \&& node scripts/patch-baileys-appstate.js \&& node scripts/patch-baileys-newsletter-create.js \&& npm cache clean --forcediff --git a/package.json b/package.jsonindex 306455ff6..a2bc2aec5 100644--- a/package.json+++ b/package.json@@ -37,7 +37,7 @@"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"","lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix","test": "jest",- "test:scripts": "node --test scripts/postinstall.spec.js scripts/patch-wwebjs-newsletter-preview.spec.js scripts/patch-wwebjs-status.spec.js scripts/patch-wwebjs-ready-sync.spec.js scripts/patch-baileys-appstate.spec.js scripts/patch-baileys-newsletter-create.spec.js scripts/dockerfile-patchers.spec.js scripts/check-upstream-surface.spec.mjs scripts/check-sdk-docs.spec.mjs",+ "test:scripts": "node --test scripts/postinstall.spec.js scripts/patch-wwebjs-newsletter-preview.spec.js scripts/patch-wwebjs-status.spec.js scripts/patch-wwebjs-ready-sync.spec.js scripts/patch-wwebjs-participant-arity.spec.js scripts/patch-baileys-appstate.spec.js scripts/patch-baileys-newsletter-create.spec.js scripts/dockerfile-patchers.spec.js scripts/check-upstream-surface.spec.mjs scripts/check-sdk-docs.spec.mjs","test:watch": "jest --watch","test:cov": "jest --coverage","test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",diff --git a/scripts/postinstall.js b/scripts/postinstall.jsindex 091f1bb3a..c1b0e6aa0 100644--- a/scripts/postinstall.js+++ b/scripts/postinstall.js@@ -1,7 +1,7 @@/*** Post-install hook (npm `postinstall`).*- * Seven conditional steps, each skipped when its target is absent so the hook is a no-op where the+ * Eight conditional steps, each skipped when its target is absent so the hook is a no-op where the* piece is missing (the Docker builder stage copies package*.json long before any source):** 1. `npm ci` inside dashboard/ when dashboard/ exists — the dashboard carries its own lockfile and@@ -21,11 +21,13 @@* repairs, gated the same way as step 3.* 5. `node scripts/patch-wwebjs-ready-sync.js --best-effort` when present — the readiness* marker + hasSynced level-check, gated the same way.- * 6. `node scripts/patch-baileys-appstate.js --best-effort` when present — the app-state resync+ * 6. `node scripts/patch-wwebjs-participant-arity.js --best-effort` when present — makes the group+ * participant writes report which requested ids resolved to members, gated the same way.+ * 7. `node scripts/patch-baileys-appstate.js --best-effort` when present — the app-state resync* bound, gated the same way.- * 7. `node scripts/patch-baileys-newsletter-create.js --best-effort` when present — the- * newsletter-create parse fix. Steps 6-7 are the Baileys patches, so a Baileys-only install- * runs those and skips 2-5.+ * 8. `node scripts/patch-baileys-newsletter-create.js --best-effort` when present — the+ * newsletter-create parse fix. Steps 7-8 are the Baileys patches, so a Baileys-only install+ * runs those and skips 2-6.** Structured like scripts/patch-wwebjs-201832.js: pure planning + injectable spawn, so the spec* (scripts/postinstall.spec.js, node:test) exercises every branch without a real npm run.@@ -105,6 +107,15 @@ function planSteps(root, env = process.env) {options: { stdio: 'inherit', cwd: root, env: cleanEnv },});}+ const participantArityPatcher = path.join(root, 'scripts', 'patch-wwebjs-participant-arity.js');+ if (fs.existsSync(participantArityPatcher)) {+ steps.push({+ name: 'whatsapp-web.js participant batch truth (scripts/patch-wwebjs-participant-arity.js --best-effort)',+ command: process.execPath,+ args: [participantArityPatcher, '--best-effort'],+ options: { stdio: 'inherit', cwd: root, env: cleanEnv },+ });+ }const baileysAppStatePatcher = path.join(root, 'scripts', 'patch-baileys-appstate.js');if (fs.existsSync(baileysAppStatePatcher)) {steps.push({diff --git a/scripts/postinstall.spec.js b/scripts/postinstall.spec.jsindex 3853eab2f..b708cccab 100644--- a/scripts/postinstall.spec.js+++ b/scripts/postinstall.spec.js@@ -24,11 +24,12 @@ function makeRoot({previewPatcher = false,statusPatcher = false,readySyncPatcher = false,+ participantArityPatcher = false,baileysPatcher = false,} = {}) {const root = fs.mkdtempSync(path.join(os.tmpdir(), 'openwa-postinstall-'));if (dashboard) fs.mkdirSync(path.join(root, 'dashboard'));- if (patcher || previewPatcher || statusPatcher || readySyncPatcher || baileysPatcher) {+ if (patcher || previewPatcher || statusPatcher || readySyncPatcher || participantArityPatcher || baileysPatcher) {fs.mkdirSync(path.join(root, 'scripts'));}if (patcher) {@@ -43,6 +44,9 @@ function makeRoot({if (readySyncPatcher) {fs.writeFileSync(path.join(root, 'scripts', 'patch-wwebjs-ready-sync.js'), '// stub\n');}+ if (participantArityPatcher) {+ fs.writeFileSync(path.join(root, 'scripts', 'patch-wwebjs-participant-arity.js'), '// stub\n');+ }if (baileysPatcher) {fs.writeFileSync(path.join(root, 'scripts', 'patch-baileys-appstate.js'), '// stub\n');}@@ -113,6 +117,14 @@ test('planSteps: ready-sync patcher plans its own best-effort repair', () => {assert.deepEqual(steps[0].args.slice(1), ['--best-effort']);});+test('planSteps: participant-arity patcher plans its own best-effort repair', () => {+ const steps = planSteps(makeRoot({ participantArityPatcher: true }));+ assert.equal(steps.length, 1);+ assert.equal(steps[0].command, process.execPath);+ assert.match(steps[0].args[0], /patch-wwebjs-participant-arity\.js$/);+ assert.deepEqual(steps[0].args.slice(1), ['--best-effort']);+});+test('planSteps: dashboard and all patchers run in stable order', () => {const steps = planSteps(makeRoot({@@ -121,16 +133,18 @@ test('planSteps: dashboard and all patchers run in stable order', () => {previewPatcher: true,statusPatcher: true,readySyncPatcher: true,+ participantArityPatcher: true,baileysPatcher: true,}),);- assert.equal(steps.length, 6);+ assert.equal(steps.length, 7);assert.equal(steps[0].command, 'npm ci');assert.match(steps[1].args[0], /patch-wwebjs-201832\.js$/);assert.match(steps[2].args[0], /patch-wwebjs-newsletter-preview\.js$/);assert.match(steps[3].args[0], /patch-wwebjs-status\.js$/);assert.match(steps[4].args[0], /patch-wwebjs-ready-sync\.js$/);- assert.match(steps[5].args[0], /patch-baileys-appstate\.js$/);+ assert.match(steps[5].args[0], /patch-wwebjs-participant-arity\.js$/);+ assert.match(steps[6].args[0], /patch-baileys-appstate\.js$/);});test('run: nothing to do exits 0 and never spawns', () => {