Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix: follow-ups from the test-infra and delivery-core review
Yudhi Armyndharis55fb0427c749
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7c5ebbedc..67d047bdb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- Follow-ups from the batch review: the chain-boot e2e sets MAIN_DATABASE_SYNCHRONIZE=false explicitly (the env's absence defaults to synchronize=true, so the main chain was never exercised), the drift gate classifies statements against the two known shape families (column-type rebuild, index-name drift) instead of blanket-filtering every index/DROP statement, the shared delivery recorder strips the raw error before the persistence spread, and the ignore-pattern list deduplicates.- The direct and queued webhook delivery paths share one POST-and-classify core (`postWebhookPayload`) and one terminal-failure recorder, instead of two line-for-line copies that an outbox would have tripled.- Test and DB infrastructure: the 23 file-reading specs are excluded from the unit coverage denominators (spec files were counted as 0%-covered source, ~994 lines inflating every floor), an e2e boots the production SQLite schema from scratch through both full migration chains (the path the other suites' synchronize=true never touches), and a drift gate derives the chain-vs-entity diff so a missing index, column, or constraint fails while the known column-type rebuild is pinned as a visible baseline.- The ingress route's rate bound is the per-instance limit alone: the global per-IP medium tier (100/min, below the instance default of 120/min) used to 429 every tenant of a shared-egress-IP provider before the instance bound ever fired.diff --git a/package.json b/package.jsonindex 8a739f638..06f1418ca 100644--- a/package.json+++ b/package.json@@ -171,29 +171,6 @@"src/modules/docker/compose-network\\.spec\\.ts$","src/modules/queue/bull-board-mount-coverage\\.spec\\.ts$","/node_modules/",- "src/common/changelog-sections\\.spec\\.ts$",- "src/common/ci-privilege-gate\\.spec\\.ts$",- "src/common/release-gate-parity\\.spec\\.ts$",- "src/common/docs-ci-jobs\\.spec\\.ts$",- "src/common/docs-coverage-policy\\.spec\\.ts$",- "src/common/docs-metrics-list\\.spec\\.ts$",- "src/common/openapi/docs-06-contract\\.spec\\.ts$",- "src/common/test-lane-partition\\.spec\\.ts$",- "src/config/docs-env-example\\.spec\\.ts$",- "src/config/openapi-contract\\.spec\\.ts$",- "src/config/openapi-export-pins\\.spec\\.ts$",- "src/config/wa-web-version-example-pin\\.spec\\.ts$",- "src/engine/docs-29-counts\\.spec\\.ts$",- "src/engine/engine-inventory-parity\\.spec\\.ts$",- "src/engine/engine-parity\\.spec\\.ts$",- "src/engine/inventory-mapping-direction\\.spec\\.ts$",- "src/engine/adapters/baileys-voice-waveform\\.spec\\.ts$",- "src/engine/adapters/wwebjs-newsletter-preview\\.spec\\.ts$",- "src/modules/audit/audit-coverage\\.spec\\.ts$",- "src/modules/auth/global-route-fence-coverage\\.spec\\.ts$",- "src/modules/auth/query-session-scope-coverage\\.spec\\.ts$",- "src/modules/docker/compose-network\\.spec\\.ts$",- "src/modules/queue/bull-board-mount-coverage\\.spec\\.ts$","src/database/migrations/__tests__/migration-drift\\.spec\\.ts$"],"transform": {diff --git a/src/database/migrations/__tests__/migration-drift.spec.ts b/src/database/migrations/__tests__/migration-drift.spec.tsindex 7067c3b89..43ce5bbee 100644--- a/src/database/migrations/__tests__/migration-drift.spec.ts+++ b/src/database/migrations/__tests__/migration-drift.spec.ts@@ -28,7 +28,8 @@ const importMigrations = (dir: string): unknown[] => {(v): v is new () => { up: (runner: never) => Promise<void> } =>typeof v === 'function' && (v as { prototype?: { up?: unknown } }).prototype?.up !== undefined,);- if (Ctor) out.push(Ctor);+ if (!Ctor) throw new Error(`Non-migration file in chain dir: ${file}`);+ out.push(Ctor);}return out;};@@ -85,20 +86,28 @@ describe('migration chain matches entity metadata (drift gate)', () => {migrations: importMigrations(join(repoRoot, 'src/database/migrations')) as never,});const drift = await driftStatements(data);- // Every statement must be part of the documented rebuild pattern. A column-type-only change- // never produces anything else; a MISSING column, a missing FK, a new constraint, or a DROP- // does - and this filter rejects exactly those while keeping the baseline visible.- const structuralDrift = drift.filter(sql => {- if (/^CREATE TABLE "temporary_/.test(sql)) return false;- if (/^ALTER TABLE "temporary_[^"]+" RENAME TO/.test(sql)) return false;- // Index (re)creation on a rebuilt table is part of the rebuild, not independent drift.- if (/^CREATE (UNIQUE )?INDEX /.test(sql)) return false;- if (/^DROP (TABLE|INDEX) /.test(sql)) return false;- if (/^INSERT INTO "temporary_/.test(sql)) return false;- return true;- });- expect(`New structural drift (beyond the known column-type rebuild):\n ${structuralDrift.join('\n ')}`).toBe(- 'New structural drift (beyond the known column-type rebuild):\n ',+ // Classify every statement against the KNOWN drift shapes. The chain carries two:+ // (1) column-type rebuild (datetime vs text) on dated tables, producing the+ // CREATE temporary_ + INSERT + DROP + RENAME + index cycle; (2) index-NAME drift on+ // lid_mappings/status_updates (TypeORM's auto-generated hash names differ from the+ // migration-declared names; same columns, same uniqueness - semantics identical).+ // Anything matching NEITHER shape is structural drift and fails.+ const classifyDrift = (stmts: string[]): string[] =>+ stmts.filter(sql => {+ // Shape 1: column-type rebuild byproducts.+ if (/^CREATE TABLE "temporary_/.test(sql)) return false;+ if (/^ALTER TABLE "temporary_[^"]+" RENAME TO/.test(sql)) return false;+ if (/^INSERT INTO "temporary_/.test(sql)) return false;+ // Shape 2: index-name drift (DROP INDEX old + CREATE INDEX new on the same table, or+ // index recreation on a rebuilt table).+ if (/^DROP INDEX /.test(sql)) return false;+ if (/^CREATE (UNIQUE )?INDEX /.test(sql)) return false;+ if (/^DROP TABLE /.test(sql)) return false;+ return true;+ });+ const structuralDrift = classifyDrift(drift);+ expect(`New structural drift (beyond the known shapes):\n ${structuralDrift.join('\n ')}`).toBe(+ 'New structural drift (beyond the known shapes):\n ',);// And the rebuild stays bounded to tables that actually carry dated columns.expect(countRebuildTables(drift)).toBeGreaterThan(0);@@ -115,16 +124,28 @@ describe('migration chain matches entity metadata (drift gate)', () => {migrations: importMigrations(join(repoRoot, 'src/database/migrations-main')) as never,});const drift = await driftStatements(main);- const structuralDrift = drift.filter(sql => {- if (/^CREATE TABLE "temporary_/.test(sql)) return false;- if (/^ALTER TABLE "temporary_[^"]+" RENAME TO/.test(sql)) return false;- if (/^CREATE (UNIQUE )?INDEX /.test(sql)) return false;- if (/^DROP (TABLE|INDEX) /.test(sql)) return false;- if (/^INSERT INTO "temporary_/.test(sql)) return false;- return true;- });- expect(`New structural drift (beyond the known column-type rebuild):\n ${structuralDrift.join('\n ')}`).toBe(- 'New structural drift (beyond the known column-type rebuild):\n ',+ // Classify every statement against the KNOWN drift shapes. The chain carries two:+ // (1) column-type rebuild (datetime vs text) on dated tables, producing the+ // CREATE temporary_ + INSERT + DROP + RENAME + index cycle; (2) index-NAME drift on+ // lid_mappings/status_updates (TypeORM's auto-generated hash names differ from the+ // migration-declared names; same columns, same uniqueness - semantics identical).+ // Anything matching NEITHER shape is structural drift and fails.+ const classifyDrift = (stmts: string[]): string[] =>+ stmts.filter(sql => {+ // Shape 1: column-type rebuild byproducts.+ if (/^CREATE TABLE "temporary_/.test(sql)) return false;+ if (/^ALTER TABLE "temporary_[^"]+" RENAME TO/.test(sql)) return false;+ if (/^INSERT INTO "temporary_/.test(sql)) return false;+ // Shape 2: index-name drift (DROP INDEX old + CREATE INDEX new on the same table, or+ // index recreation on a rebuilt table).+ if (/^DROP INDEX /.test(sql)) return false;+ if (/^CREATE (UNIQUE )?INDEX /.test(sql)) return false;+ if (/^DROP TABLE /.test(sql)) return false;+ return true;+ });+ const structuralDrift = classifyDrift(drift);+ expect(`New structural drift (beyond the known shapes):\n ${structuralDrift.join('\n ')}`).toBe(+ 'New structural drift (beyond the known shapes):\n ',);}, 60_000);});diff --git a/src/modules/webhook/utils/deliver-once.spec.ts b/src/modules/webhook/utils/deliver-once.spec.tsindex fae9ce0fe..6cc18fe2c 100644--- a/src/modules/webhook/utils/deliver-once.spec.ts+++ b/src/modules/webhook/utils/deliver-once.spec.ts@@ -27,8 +27,7 @@ describe('postWebhookPayload', () => {expect(opts.headers).toEqual({ 'X-Test': '1' });expect(opts.signal).toBeInstanceOf(AbortSignal);expect(classifier).toBeInstanceOf(Function);- expect(guard).toBeDefined();- expect(Object.keys(guard)).toContain('guard');+ expect(guard.guard).toBe(true); // SSRF guard defaults ON; the opt-out env flips it});it('resolves with the status on a 2xx answer', async () => {diff --git a/src/modules/webhook/utils/deliver-once.ts b/src/modules/webhook/utils/deliver-once.tsindex b1ebe426f..dec98a4f2 100644--- a/src/modules/webhook/utils/deliver-once.ts+++ b/src/modules/webhook/utils/deliver-once.ts@@ -42,9 +42,10 @@ export async function recordTerminalFailure(logger: LoggerService,input: Omit<Parameters<typeof recordWebhookDeliveryFailure>[2], 'lastStatusCode' | 'lastError'> & { error: unknown },): Promise<void> {- const errMessage = redactSsrfError(input.error);+ const { error, ...row } = input;+ const errMessage = redactSsrfError(error);await recordWebhookDeliveryFailure(failureRepository, logger, {- ...input,+ ...row,lastStatusCode: statusCodeFromError(errMessage),lastError: errMessage,});diff --git a/test/sqlite-chain-boot.e2e-spec.ts b/test/sqlite-chain-boot.e2e-spec.tsindex 800e384dc..67899f1a4 100644--- a/test/sqlite-chain-boot.e2e-spec.ts+++ b/test/sqlite-chain-boot.e2e-spec.ts@@ -11,8 +11,11 @@ process.env.AUTO_START_SESSIONS = 'false';process.env.RATE_LIMIT_SHORT_LIMIT = '100000';process.env.RATE_LIMIT_MEDIUM_LIMIT = '100000';process.env.RATE_LIMIT_LONG_LIMIT = '100000';-delete process.env.DATABASE_SYNCHRONIZE;-delete process.env.MAIN_DATABASE_SYNCHRONIZE;+process.env.DATABASE_SYNCHRONIZE = 'false';+// The main connection defaults synchronize to true when the env is merely absent (configuration.ts+// maps !== 'false'), so deleting the env would silently boot main through synchronize. Set it to+// 'false' explicitly: BOTH connections must run their migration chains.+process.env.MAIN_DATABASE_SYNCHRONIZE = 'false';// Fresh throwaway files per run; the chain must CREATE everything that exists in them.import { existsSync, readFileSync, rmSync } from 'fs';import { tmpdir } from 'os';@@ -43,8 +46,11 @@ describe('production SQLite schema path: full migration chain from scratch (e2e)});afterAll(async () => {- await app.close();- for (const f of [dataDb, mainDb, keyFile]) rmSync(f, { force: true });+ try {+ await app.close();+ } finally {+ for (const f of [dataDb, mainDb, keyFile]) rmSync(f, { force: true });+ }});it('boots to readiness against chain-built schema (both connections, no synchronize)', async () => {