Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test: gate the coverage ignore list and re-derive the floors

Yudhi Armyndharis777b2e8d661d
diff --git a/docs/09-testing-strategy.md b/docs/09-testing-strategy.md
index 6b4b7b632..103436bd0 100644
--- a/docs/09-testing-strategy.md
+++ b/docs/09-testing-strategy.md
@@ -177,40 +177,40 @@ authoritative gate. Current policy:
| Scope | Branches | Functions | Lines | Statements |
| --------------------------- | -------- | --------- | ----- | ---------- |
-| Global | 44% | 38% | 45% | 44% |
+| Global | 61% | 70% | 68% | 67% |
| `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/` | 75% | 54% | 63% | 62% |
+| `src/common/services/` | 82% | 91% | 90% | 88% |
+| `src/common/storage/` | 75% | 85% | 84% | 80% |
+| `src/common/utils/` | 87% | 92% | 92% | 92% |
+| `src/config/` | 85% | 92% | 91% | 91% |
| `src/core/agent-tools/` | 88% | 87% | 83% | 83% |
-| `src/core/hooks/` | 81% | 73% | 85% | 84% |
-| `src/core/plugins/` | 72% | 74% | 81% | 80% |
+| `src/core/hooks/` | 84% | 73% | 86% | 85% |
+| `src/core/plugins/` | 73% | 76% | 82% | 81% |
| `src/database/` | 69% | 69% | 72% | 72% |
-| `src/engine/adapters/` | 74% | 84% | 83% | 83% |
+| `src/engine/adapters/` | 78% | 85% | 86% | 86% |
| `src/engine/identity/` | 85% | 95% | 94% | 93% |
-| `src/modules/audit/` | 50% | 21% | 59% | 57% |
-| `src/modules/auth/` | 65% | 62% | 67% | 65% |
-| `src/modules/automation/` | 67% | 57% | 83% | 79% |
+| `src/modules/audit/` | 59% | 45% | 73% | 70% |
+| `src/modules/auth/` | 76% | 85% | 86% | 86% |
+| `src/modules/automation/` | 67% | 86% | 83% | 79% |
| `src/modules/chat-media/` | 75% | 76% | 84% | 84% |
-| `src/modules/contact/` | 79% | 90% | 89% | 88% |
-| `src/modules/docker/` | 83% | 82% | 87% | 87% |
-| `src/modules/events/` | 70% | 84% | 81% | 80% |
-| `src/modules/group/` | 64% | 47% | 67% | 67% |
-| `src/modules/infra/` | 73% | 71% | 87% | 86% |
+| `src/modules/contact/` | 82% | 92% | 89% | 88% |
+| `src/modules/docker/` | 84% | 93% | 92% | 92% |
+| `src/modules/events/` | 72% | 84% | 84% | 82% |
+| `src/modules/group/` | 67% | 65% | 79% | 79% |
+| `src/modules/infra/` | 75% | 76% | 89% | 88% |
| `src/modules/integration/` | 76% | 83% | 90% | 89% |
| `src/modules/mcp/` | 62% | 81% | 78% | 78% |
| `src/modules/media/` | 71% | 87% | 89% | 88% |
-| `src/modules/message/` | 57% | 66% | 81% | 80% |
-| `src/modules/metrics/` | 61% | 65% | 68% | 65% |
-| `src/modules/plugins/` | 67% | 63% | 74% | 73% |
-| `src/modules/queue/` | 69% | 61% | 80% | 79% |
-| `src/modules/search/` | 66% | 87% | 71% | 71% |
+| `src/modules/message/` | 75% | 66% | 86% | 85% |
+| `src/modules/metrics/` | 64% | 65% | 70% | 67% |
+| `src/modules/plugins/` | 69% | 64% | 77% | 76% |
+| `src/modules/queue/` | 74% | 81% | 95% | 95% |
+| `src/modules/search/` | 69% | 87% | 78% | 78% |
| `src/modules/session/` | 75% | 79% | 88% | 87% |
-| `src/modules/stats/` | 67% | 63% | 71% | 69% |
+| `src/modules/stats/` | 67% | 63% | 78% | 76% |
| `src/modules/status-store/` | 79% | 83% | 92% | 91% |
-| `src/modules/status/` | 70% | 58% | 79% | 78% |
+| `src/modules/status/` | 70% | 60% | 83% | 82% |
| `src/modules/template/` | 77% | 99% | 92% | 89% |
| `src/modules/webhook/` | 72% | 89% | 90% | 87% |
diff --git a/package.json b/package.json
index aa9189a44..66a4d040c 100644
--- a/package.json
+++ b/package.json
@@ -199,10 +199,10 @@
"coverageDirectory": "../coverage",
"coverageThreshold": {
"global": {
- "branches": 44,
- "functions": 38,
- "lines": 45,
- "statements": 44
+ "branches": 61,
+ "functions": 70,
+ "lines": 68,
+ "statements": 67
},
"./src/common/cache/": {
"branches": 34,
@@ -217,28 +217,28 @@
"statements": 92
},
"./src/common/services/": {
- "branches": 74,
+ "branches": 82,
"functions": 91,
- "lines": 87,
- "statements": 84
+ "lines": 90,
+ "statements": 88
},
"./src/common/storage/": {
"branches": 75,
- "functions": 80,
- "lines": 80,
- "statements": 77
+ "functions": 85,
+ "lines": 84,
+ "statements": 80
},
"./src/common/utils/": {
- "branches": 86,
+ "branches": 87,
"functions": 92,
"lines": 92,
- "statements": 91
+ "statements": 92
},
"./src/config/": {
- "branches": 75,
- "functions": 54,
- "lines": 63,
- "statements": 62
+ "branches": 85,
+ "functions": 92,
+ "lines": 91,
+ "statements": 91
},
"./src/core/agent-tools/": {
"branches": 88,
@@ -247,16 +247,16 @@
"statements": 83
},
"./src/core/hooks/": {
- "branches": 81,
+ "branches": 84,
"functions": 73,
- "lines": 85,
- "statements": 84
+ "lines": 86,
+ "statements": 85
},
"./src/core/plugins/": {
- "branches": 72,
- "functions": 74,
- "lines": 81,
- "statements": 80
+ "branches": 73,
+ "functions": 76,
+ "lines": 82,
+ "statements": 81
},
"./src/database/": {
"branches": 69,
@@ -265,10 +265,10 @@
"statements": 72
},
"./src/engine/adapters/": {
- "branches": 74,
- "functions": 84,
- "lines": 83,
- "statements": 83
+ "branches": 78,
+ "functions": 85,
+ "lines": 86,
+ "statements": 86
},
"./src/engine/identity/": {
"branches": 85,
@@ -277,20 +277,20 @@
"statements": 93
},
"./src/modules/audit/": {
- "branches": 50,
- "functions": 21,
- "lines": 59,
- "statements": 57
+ "branches": 59,
+ "functions": 45,
+ "lines": 73,
+ "statements": 70
},
"./src/modules/auth/": {
- "branches": 65,
- "functions": 62,
- "lines": 67,
- "statements": 65
+ "branches": 76,
+ "functions": 85,
+ "lines": 86,
+ "statements": 86
},
"./src/modules/automation/": {
"branches": 67,
- "functions": 57,
+ "functions": 86,
"lines": 83,
"statements": 79
},
@@ -301,34 +301,34 @@
"statements": 84
},
"./src/modules/contact/": {
- "branches": 79,
- "functions": 90,
+ "branches": 82,
+ "functions": 92,
"lines": 89,
"statements": 88
},
"./src/modules/docker/": {
- "branches": 83,
- "functions": 82,
- "lines": 87,
- "statements": 87
+ "branches": 84,
+ "functions": 93,
+ "lines": 92,
+ "statements": 92
},
"./src/modules/events/": {
- "branches": 70,
+ "branches": 72,
"functions": 84,
- "lines": 81,
- "statements": 80
+ "lines": 84,
+ "statements": 82
},
"./src/modules/group/": {
- "branches": 64,
- "functions": 47,
- "lines": 67,
- "statements": 67
+ "branches": 67,
+ "functions": 65,
+ "lines": 79,
+ "statements": 79
},
"./src/modules/infra/": {
- "branches": 73,
- "functions": 71,
- "lines": 87,
- "statements": 86
+ "branches": 75,
+ "functions": 76,
+ "lines": 89,
+ "statements": 88
},
"./src/modules/integration/": {
"branches": 76,
@@ -349,34 +349,34 @@
"statements": 88
},
"./src/modules/message/": {
- "branches": 57,
+ "branches": 75,
"functions": 66,
- "lines": 81,
- "statements": 80
+ "lines": 86,
+ "statements": 85
},
"./src/modules/metrics/": {
- "branches": 61,
+ "branches": 64,
"functions": 65,
- "lines": 68,
- "statements": 65
+ "lines": 70,
+ "statements": 67
},
"./src/modules/plugins/": {
- "branches": 67,
- "functions": 63,
- "lines": 74,
- "statements": 73
+ "branches": 69,
+ "functions": 64,
+ "lines": 77,
+ "statements": 76
},
"./src/modules/queue/": {
- "branches": 69,
- "functions": 61,
- "lines": 80,
- "statements": 79
+ "branches": 74,
+ "functions": 81,
+ "lines": 95,
+ "statements": 95
},
"./src/modules/search/": {
- "branches": 66,
+ "branches": 69,
"functions": 87,
- "lines": 71,
- "statements": 71
+ "lines": 78,
+ "statements": 78
},
"./src/modules/session/": {
"branches": 75,
@@ -387,8 +387,8 @@
"./src/modules/stats/": {
"branches": 67,
"functions": 63,
- "lines": 71,
- "statements": 69
+ "lines": 78,
+ "statements": 76
},
"./src/modules/status-store/": {
"branches": 79,
@@ -398,9 +398,9 @@
},
"./src/modules/status/": {
"branches": 70,
- "functions": 58,
- "lines": 79,
- "statements": 78
+ "functions": 60,
+ "lines": 83,
+ "statements": 82
},
"./src/modules/template/": {
"branches": 77,
diff --git a/src/common/test-lane-partition.spec.ts b/src/common/test-lane-partition.spec.ts
index 5b1ff2007..ee2f66436 100644
--- a/src/common/test-lane-partition.spec.ts
+++ b/src/common/test-lane-partition.spec.ts
@@ -13,7 +13,7 @@ describe('Test lane partition', () => {
const repoRoot = join(__dirname, '..', '..');
const pkg = JSON.parse(readFileSync(join(repoRoot, 'package.json'), 'utf8')) as {
scripts: { 'test:docs'?: string };
- jest?: { testPathIgnorePatterns?: string[] };
+ jest?: { testPathIgnorePatterns?: string[]; coveragePathIgnorePatterns?: string[] };
};
/** Every spec path the `test:docs` script names as a positional, however the flags are ordered. */
@@ -51,6 +51,37 @@ describe('Test lane partition', () => {
}
});
+ /**
+ * `coveragePathIgnorePatterns` exists to keep the doc-lint suites out of the coverage
+ * DENOMINATORS: excluded from the unit lane, they would otherwise be counted as source files with
+ * 0% coverage and drag every floor down. So it has to mirror the ignore list, and it has to
+ * contain nothing else.
+ *
+ * The second half is the one that bites. Adding a real source path here removes that code from
+ * every ratio silently: the floors keep passing, on a smaller denominator, and coverage that
+ * never existed reads as coverage that does. The commit that introduced the array said it was
+ * "enforced by the lane-partition spec"; it never was, and this is that enforcement.
+ */
+ it('keeps the coverage ignore list a mirror of the test ignore list, and nothing more', () => {
+ const testIgnores = pkg.jest?.testPathIgnorePatterns ?? [];
+ const coverageIgnores = pkg.jest?.coveragePathIgnorePatterns ?? [];
+
+ // Vacuity guard: two empty arrays are trivially equal.
+ expect(coverageIgnores.length).toBeGreaterThan(20);
+
+ const testSet = new Set(testIgnores);
+ const coverageSet = new Set(coverageIgnores);
+ expect({
+ onlyInCoverage: [...coverageSet].filter(p => !testSet.has(p)),
+ onlyInTest: [...testSet].filter(p => !coverageSet.has(p)),
+ }).toEqual({ onlyInCoverage: [], onlyInTest: [] });
+
+ // A pattern that is neither `/node_modules/` nor a single spec file is a source path, and a
+ // source path here deletes that code from the coverage ratios.
+ const notASpec = coverageIgnores.filter(p => p !== '/node_modules/' && !p.endsWith('\\.spec\\.ts$'));
+ expect(notASpec).toEqual([]);
+ });
+
it('names suites that exist on disk', () => {
const paths = [...new Set([...docLane(), ...unitLaneExcludes().map(asPath)])];
expect(paths.length).toBeGreaterThan(20);