Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(ci): run the contract-shape and docs gates on the release path
Yudhi Armyndharis6c9f22c55c87
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 287252f25..320c55389 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -117,6 +117,12 @@ jobs:- name: Check SDK docs cover the shipped client surfacerun: npm run check:sdk-docs+ # The typed-SDK wire-shape gate: the last lane gate ci.yml runs that this workflow lacked, so+ # a tag could publish SDK builds whose mapped response types had drifted from the contract+ # while the branch path would have caught it.+ - name: Check contract shapes across the typed SDKs+ run: npm run check:contract-shapes+test:name: Testruns-on: ubuntu-latest@@ -153,6 +159,11 @@ jobs:- name: Run script unit testsrun: npm run test:scripts+ # The repo-file drift specs (docs, trees, gates) run on the branch path; a tag is the one+ # place that must not be verified less than the branch it came from.+ - name: Run docs unit tests+ run: npm run test:docs+- name: Run e2e smoke testsrun: npm run test:e2eenv:diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2c46339f9..20cf9c1c1 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+- The release (tag) workflow runs `check:contract-shapes` and `test:docs` like the branch CI, and a spec locks every ci.yml lint/test gate command into the release path; both ran only on branches.- Both bundled Compose files forward every documented runtime knob; `WEBHOOK_SSRF_REDIRECTS`, `PLUGIN_INSTALL_REQUIRE_PIN` and ~75 other `.env` settings were unreachable in the container. A spec now derives the required list from `.env.example`.- Ingress delivery ids BullMQ refuses at enqueue (numeric, `redrive:<uuid>`, `0:`-led) are hashed to a legal job id, namespaced by plugin/instance; the old refusal read as a Redis failure and silently degraded the delivery to inline dispatch with no retry.- One precise unique-violation predicate (`23505`, `SQLITE_CONSTRAINT_UNIQUE`/`_PRIMARYKEY`): the old prefix match treated every SQLite constraint failure (FK/NOT NULL/CHECK) as a duplicate, swallowing genuine persistence failures and answering misleading 409s.diff --git a/package.json b/package.jsonindex 0dc309c9a..9855f7a60 100644--- a/package.json+++ b/package.json@@ -42,7 +42,7 @@"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-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 scripts/check-audit.spec.mjs scripts/check-contract-shapes.spec.mjs",- "test:docs": "jest src/common/changelog-sections.spec.ts src/common/ci-privilege-gate.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 --testPathIgnorePatterns=/node_modules/",+ "test:docs": "jest src/common/changelog-sections.spec.ts src/common/ci-privilege-gate.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/common/release-gate-parity.spec.ts --testPathIgnorePatterns=/node_modules/","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",@@ -150,6 +150,7 @@"/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$",diff --git a/src/common/ci-privilege-gate.spec.ts b/src/common/ci-privilege-gate.spec.tsindex 9f4a4b91d..e1eccff2c 100644--- a/src/common/ci-privilege-gate.spec.ts+++ b/src/common/ci-privilege-gate.spec.ts@@ -1,6 +1,7 @@import * as fs from 'fs';import * as path from 'path';import * as yaml from 'js-yaml';+import { executableLines } from './workflow-lines';/*** The published image has no `USER` directive by design: docker-entrypoint.sh starts as root to fix@@ -23,27 +24,6 @@ function workflowOf(file: string): Workflow {return yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as Workflow;}-/**- * A `run:` block with its shell comments removed.- *- * The gate below exists because the script's only appearance in ci.yml was once inside a comment,- * and a substring match cannot tell a command from a mention — so `# ./scripts/x.sh disabled` would- * have satisfied the very check written to catch that. Only executable lines count.- */-export function executableLines(run: string): string {- return run- .split('\n')- .map(line => {- const hash = line.indexOf('#');- if (hash === -1) return line;- // A '#' inside quotes is data, not a comment — keep the line whole rather than truncating it.- const before = line.slice(0, hash);- const quotes = (before.match(/["']/g) ?? []).length;- return quotes % 2 === 1 ? line : before;- })- .join('\n');-}-function runCommandsOf(file: string): string[] {return Object.values(workflowOf(file).jobs ?? {}).flatMap(job =>(job.steps ?? []).map(step => executableLines(step.run ?? '')),diff --git a/src/common/release-gate-parity.spec.ts b/src/common/release-gate-parity.spec.tsnew file mode 100644index 000000000..551719465--- /dev/null+++ b/src/common/release-gate-parity.spec.ts@@ -0,0 +1,53 @@+import * as fs from 'fs';+import * as path from 'path';+import * as yaml from 'js-yaml';+import { executableLines } from './workflow-lines';++/**+ * The release workflow publishes the image and the GitHub Release from a tag push. A tag starts+ * release.yml ALONE (ci.yml triggers on branches), so whatever gate the tag path skips is a gate a+ * release never ran; the workflow's own header states the invariant ("a tag can never publish+ * something the branch gate would have refused"; "the release gate must not be laxer than the PR+ * gate"). Both sides drifted before: check:contract-shapes and test:docs ran only on branches, so+ * an SDK wire-shape regression or a repo-file drift could ride a tag to publication while the same+ * commit would have failed CI.+ *+ * This locks the invariant structurally: every gate command (npm/npx lines) in ci.yml's lint and+ * test jobs must also run in release.yml's lint and test jobs (the workflow header and the check:audit step comment both state+ * the invariant; this spec makes it enforced). The release jobs may run MORE+ * (its lint also carries the audit gate); only the subset direction is asserted.+ */++const workflowDir = path.join(__dirname, '..', '..', '.github', 'workflows');++type Step = { run?: string };+type Workflow = { jobs?: Record<string, { steps?: Step[] }> };++const gateCommands = (file: string, job: string): string[] => {+ const workflow = yaml.load(fs.readFileSync(path.join(workflowDir, file), 'utf8')) as Workflow;+ const steps = workflow.jobs?.[job]?.steps ?? [];+ if (steps.length === 0) throw new Error(`${file} has no "${job}" job: the parity spec drifted`);+ return steps.flatMap(step =>+ executableLines(step.run ?? '')+ .split('\n')+ .map(line => line.trim())+ .filter(line => /^npx |^npm /.test(line)),+ );+};++describe('release gate parity (the tag path runs every branch gate)', () => {+ it.each(['lint', 'test'])('%s: every ci.yml gate command also runs in release.yml', job => {+ const ci = gateCommands('ci.yml', job);+ const release = gateCommands('release.yml', job);+ // Non-vacuity: both parsers must find real gate lanes, or the subset assertion below binds nothing.+ // The test lane legitimately has only 4-5 commands, so the floor is what the lane actually owns.+ expect(ci.length).toBeGreaterThanOrEqual(4);+ expect(release.length).toBeGreaterThanOrEqual(4);+ expect(ci.filter(command => !release.includes(command))).toEqual([]);+ });++ it('the two gates this spec was born from still run on the tag path', () => {+ expect(gateCommands('release.yml', 'lint')).toContain('npm run check:contract-shapes');+ expect(gateCommands('release.yml', 'test')).toContain('npm run test:docs');+ });+});diff --git a/src/common/workflow-lines.ts b/src/common/workflow-lines.tsnew file mode 100644index 000000000..c15ac598f--- /dev/null+++ b/src/common/workflow-lines.ts@@ -0,0 +1,22 @@+/**+ * A `run:` block with its shell comments removed.+ *+ * Exists because a script's only appearance in a workflow can be inside a comment, and a substring+ * match cannot tell a command from a mention — so `# ./scripts/x.sh disabled` would satisfy the+ * very checks written to catch that. Only executable lines count. Shared by the workflow-gate+ * specs (ci-privilege-gate, release-gate-parity); lives outside a .spec so importing it does not+ * drag another spec's describe blocks into the importing suite's run.+ */+export function executableLines(run: string): string {+ return run+ .split('\n')+ .map(line => {+ const hash = line.indexOf('#');+ if (hash === -1) return line;+ // A '#' inside quotes is data, not a comment — keep the line whole rather than truncating it.+ const before = line.slice(0, hash);+ const quotes = (before.match(/["']/g) ?? []).length;+ return quotes % 2 === 1 ? line : before;+ })+ .join('\n');+}