Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(coverage): floor every substantial module, not just eight
Yudhi Armyndharis788f52034b2b
diff --git a/docs/09-testing-strategy.md b/docs/09-testing-strategy.mdindex 84ef4b179..d2344e77a 100644--- a/docs/09-testing-strategy.md+++ b/docs/09-testing-strategy.md@@ -160,17 +160,54 @@ authentication plumbing, public health endpoints, engine selection paths, and daCoverage thresholds are defined in `package.json` under the Jest configuration. Treat that file as theauthoritative gate. Current policy:-| Scope | Branches | Functions | Lines | Statements |-| -------------------------- | -------- | --------- | ----- | ---------- |-| Global | 58% | 58% | 66% | 65% |-| `src/common/security/` | 85% | 95% | 90% | 90% |-| `src/modules/auth/` | 62% | 70% | 72% | 72% |-| `src/engine/adapters/` | 63% | 63% | 70% | 70% |-| `src/modules/integration/` | 67% | 68% | 77% | 77% |-| `src/core/hooks/` | 80% | 70% | 82% | 81% |-| `src/modules/session/` | 50% | 63% | 74% | 72% |-| `src/modules/webhook/` | 65% | 83% | 84% | 80% |-| `src/modules/search/` | 58% | 72% | 58% | 58% |+| Scope | Branches | Functions | Lines | Statements |+| --------------------------- | -------- | --------- | ----- | ---------- |+| Global | 58% | 58% | 66% | 65% |+| `src/common/cache/` | 34% | 33% | 42% | 42% |+| `src/common/security/` | 85% | 95% | 93% | 92% |+| `src/common/services/` | 74% | 91% | 87% | 84% |+| `src/common/storage/` | 75% | 80% | 80% | 77% |+| `src/common/utils/` | 86% | 92% | 92% | 91% |+| `src/config/` | 88% | 92% | 91% | 91% |+| `src/core/agent-tools/` | 77% | 32% | 49% | 50% |+| `src/core/hooks/` | 81% | 73% | 85% | 84% |+| `src/core/plugins/` | 72% | 74% | 81% | 80% |+| `src/database/` | 62% | 61% | 67% | 66% |+| `src/engine/adapters/` | 74% | 84% | 83% | 83% |+| `src/engine/identity/` | 85% | 95% | 94% | 93% |+| `src/modules/audit/` | 59% | 45% | 72% | 68% |+| `src/modules/auth/` | 75% | 85% | 86% | 85% |+| `src/modules/chat-media/` | 78% | 81% | 92% | 90% |+| `src/modules/contact/` | 25% | 48% | 44% | 43% |+| `src/modules/docker/` | 26% | 52% | 37% | 38% |+| `src/modules/events/` | 70% | 84% | 81% | 80% |+| `src/modules/group/` | 64% | 47% | 67% | 67% |+| `src/modules/infra/` | 73% | 71% | 87% | 86% |+| `src/modules/integration/` | 76% | 83% | 90% | 89% |+| `src/modules/mcp/` | 33% | 48% | 45% | 46% |+| `src/modules/message/` | 57% | 66% | 81% | 80% |+| `src/modules/metrics/` | 61% | 65% | 68% | 65% |+| `src/modules/plugins/` | 67% | 63% | 74% | 73% |+| `src/modules/queue/` | 74% | 88% | 95% | 95% |+| `src/modules/search/` | 66% | 87% | 71% | 71% |+| `src/modules/session/` | 75% | 79% | 88% | 87% |+| `src/modules/stats/` | 67% | 63% | 71% | 69% |+| `src/modules/status-store/` | 79% | 83% | 92% | 91% |+| `src/modules/status/` | 47% | 45% | 62% | 60% |+| `src/modules/template/` | 43% | 52% | 70% | 67% |+| `src/modules/webhook/` | 72% | 89% | 90% | 87% |++Each floor sits roughly five points below that scope's measured coverage, so it catches a real+regression without failing on ordinary churn. Raise a floor when coverage rises; never lower one.++Two behaviours of Jest's threshold matching are worth knowing before adding a scope:++- A file counts toward **every** path key it matches — there is no most-specific-wins. Keys must+ therefore be disjoint, or a nested scope's files are graded twice and the parent floor becomes a+ restatement of the child.+- A file matched by any path key is **removed from the global group**. Global therefore grades only+ the scopes with no floor of their own, which is why its numbers are lower than the repository-wide+ figure and why adding a scope changes what Global means.The stricter scoped gates protect security-sensitive code and high-risk boundary layers. When addingsecurity, engine-adapter, or integration-fabric behavior, add focused regression tests instead of relyingdiff --git a/package.json b/package.jsonindex 47d99bc2e..2fe2982d4 100644--- a/package.json+++ b/package.json@@ -166,53 +166,203 @@"lines": 66,"statements": 65},+ "./src/common/cache/": {+ "branches": 34,+ "functions": 33,+ "lines": 42,+ "statements": 42+ },"./src/common/security/": {"branches": 85,"functions": 95,- "lines": 90,- "statements": 90+ "lines": 93,+ "statements": 92},- "./src/modules/auth/": {+ "./src/common/services/": {+ "branches": 74,+ "functions": 91,+ "lines": 87,+ "statements": 84+ },+ "./src/common/storage/": {+ "branches": 75,+ "functions": 80,+ "lines": 80,+ "statements": 77+ },+ "./src/common/utils/": {+ "branches": 86,+ "functions": 92,+ "lines": 92,+ "statements": 91+ },+ "./src/config/": {+ "branches": 88,+ "functions": 92,+ "lines": 91,+ "statements": 91+ },+ "./src/core/agent-tools/": {+ "branches": 77,+ "functions": 32,+ "lines": 49,+ "statements": 50+ },+ "./src/core/hooks/": {+ "branches": 81,+ "functions": 73,+ "lines": 85,+ "statements": 84+ },+ "./src/core/plugins/": {+ "branches": 72,+ "functions": 74,+ "lines": 81,+ "statements": 80+ },+ "./src/database/": {"branches": 62,- "functions": 70,- "lines": 72,- "statements": 72+ "functions": 61,+ "lines": 67,+ "statements": 66},"./src/engine/adapters/": {- "branches": 63,- "functions": 63,- "lines": 70,- "statements": 70+ "branches": 74,+ "functions": 84,+ "lines": 83,+ "statements": 83+ },+ "./src/engine/identity/": {+ "branches": 85,+ "functions": 95,+ "lines": 94,+ "statements": 93+ },+ "./src/modules/audit/": {+ "branches": 59,+ "functions": 45,+ "lines": 72,+ "statements": 68+ },+ "./src/modules/auth/": {+ "branches": 75,+ "functions": 85,+ "lines": 86,+ "statements": 85+ },+ "./src/modules/chat-media/": {+ "branches": 78,+ "functions": 81,+ "lines": 92,+ "statements": 90+ },+ "./src/modules/contact/": {+ "branches": 25,+ "functions": 48,+ "lines": 44,+ "statements": 43+ },+ "./src/modules/docker/": {+ "branches": 26,+ "functions": 52,+ "lines": 37,+ "statements": 38+ },+ "./src/modules/events/": {+ "branches": 70,+ "functions": 84,+ "lines": 81,+ "statements": 80+ },+ "./src/modules/group/": {+ "branches": 64,+ "functions": 47,+ "lines": 67,+ "statements": 67+ },+ "./src/modules/infra/": {+ "branches": 73,+ "functions": 71,+ "lines": 87,+ "statements": 86},"./src/modules/integration/": {+ "branches": 76,+ "functions": 83,+ "lines": 90,+ "statements": 89+ },+ "./src/modules/mcp/": {+ "branches": 33,+ "functions": 48,+ "lines": 45,+ "statements": 46+ },+ "./src/modules/message/": {+ "branches": 57,+ "functions": 66,+ "lines": 81,+ "statements": 80+ },+ "./src/modules/metrics/": {+ "branches": 61,+ "functions": 65,+ "lines": 68,+ "statements": 65+ },+ "./src/modules/plugins/": {"branches": 67,- "functions": 68,- "lines": 77,- "statements": 77+ "functions": 63,+ "lines": 74,+ "statements": 73},- "./src/core/hooks/": {- "branches": 80,- "functions": 70,- "lines": 82,- "statements": 81+ "./src/modules/queue/": {+ "branches": 74,+ "functions": 88,+ "lines": 95,+ "statements": 95+ },+ "./src/modules/search/": {+ "branches": 66,+ "functions": 87,+ "lines": 71,+ "statements": 71},"./src/modules/session/": {- "branches": 50,+ "branches": 75,+ "functions": 79,+ "lines": 88,+ "statements": 87+ },+ "./src/modules/stats/": {+ "branches": 67,"functions": 63,- "lines": 74,- "statements": 72+ "lines": 71,+ "statements": 69},- "./src/modules/webhook/": {- "branches": 65,+ "./src/modules/status-store/": {+ "branches": 79,"functions": 83,- "lines": 84,- "statements": 80+ "lines": 92,+ "statements": 91},- "./src/modules/search/": {- "branches": 58,- "functions": 72,- "lines": 58,- "statements": 58+ "./src/modules/status/": {+ "branches": 47,+ "functions": 45,+ "lines": 62,+ "statements": 60+ },+ "./src/modules/template/": {+ "branches": 43,+ "functions": 52,+ "lines": 70,+ "statements": 67+ },+ "./src/modules/webhook/": {+ "branches": 72,+ "functions": 89,+ "lines": 90,+ "statements": 87}},"testEnvironment": "node"diff --git a/src/common/docs-coverage-policy.spec.ts b/src/common/docs-coverage-policy.spec.tsnew file mode 100644index 000000000..423eb2a6f--- /dev/null+++ b/src/common/docs-coverage-policy.spec.ts@@ -0,0 +1,57 @@+import { readFileSync } from 'node:fs';+import { join } from 'node:path';++/**+ * `docs/09-testing-strategy.md` §9.5 restates the coverage floors from `package.json`, and calls that+ * file the authoritative gate. A restated table has no mechanism keeping it accurate: it was written+ * when there were eight scopes and would quietly rot now that there are more than thirty, leaving+ * contributors reading a floor the build does not enforce.+ *+ * This gate makes the two agree. It is deliberately a plain comparison of both directions — a scope+ * added to the config without the document, or left in the document after the config drops it, fails+ * here, as does any changed number.+ */+describe('docs/09 §9.5 matches the enforced coverage floors', () => {+ const METRICS = ['branches', 'functions', 'lines', 'statements'] as const;+ type Thresholds = Record<(typeof METRICS)[number], number>;++ const enforced = (): Map<string, Thresholds> => {+ const pkg = JSON.parse(readFileSync(join(__dirname, '..', '..', 'package.json'), 'utf8')) as {+ jest: { coverageThreshold: Record<string, Thresholds> };+ };+ return new Map(+ Object.entries(pkg.jest.coverageThreshold).map(([scope, t]) => [+ // The document names the global group "Global" and drops the leading `./` from paths.+ scope === 'global' ? 'Global' : scope.replace(/^\.\//, ''),+ t,+ ]),+ );+ };++ /** Parse the §9.5 table: `| scope | 58% | 58% | 66% | 65% |`, with paths written in backticks. */+ const documented = (): Map<string, Thresholds> => {+ const doc = readFileSync(join(__dirname, '..', '..', 'docs', '09-testing-strategy.md'), 'utf8');+ const section = doc.slice(doc.indexOf('## 9.5'), doc.indexOf('## 9.6'));+ const rows = new Map<string, Thresholds>();+ for (const line of section.split('\n')) {+ const cells = line.split('|').map(cell => cell.trim());+ // A data row is `| name | n% | n% | n% | n% |` — 4 numeric cells after the name.+ if (cells.length !== 7 || !METRICS.every((_, i) => /^\d+%$/.test(cells[i + 2]))) continue;+ const name = cells[1].replace(/`/g, '');+ rows.set(name, Object.fromEntries(METRICS.map((m, i) => [m, Number.parseInt(cells[i + 2], 10)])) as Thresholds);+ }+ return rows;+ };++ it('documents every enforced scope, and only those, with the same numbers', () => {+ const actual = enforced();+ const claimed = documented();++ // Guard the parser itself: an expression that silently matched nothing would make this vacuous.+ expect(claimed.size).toBeGreaterThan(8);+ expect([...claimed.keys()].sort()).toEqual([...actual.keys()].sort());+ for (const [scope, thresholds] of actual) {+ expect({ scope, ...claimed.get(scope) }).toEqual({ scope, ...thresholds });+ }+ });+});