Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

chore: sweep stale comments, docs, and test wording

Yudhi Armyndharis83c764fdd571
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f135dc0f2..01f81ff81 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -157,6 +157,8 @@ jobs:
# read files and assert content — no runtime behavior — so they run as their own jest selection
# (`test:docs`) instead of padding the unit lane; `testPathIgnorePatterns` in package.json keeps
# the default run to behavioral suites only. The two lists must stay in sync.
+ # `--testPathIgnorePatterns` must stay AFTER the positional paths in `test:docs` — jest array
+ # options greedily consume trailing positionals.
- name: Run doc-lint tests
run: npm run test:docs
diff --git a/docs/09-testing-strategy.md b/docs/09-testing-strategy.md
index 9e4db76a3..698a5ab29 100644
--- a/docs/09-testing-strategy.md
+++ b/docs/09-testing-strategy.md
@@ -214,10 +214,10 @@ authoritative gate. Current policy:
| `src/modules/template/` | 77% | 99% | 92% | 89% |
| `src/modules/webhook/` | 72% | 89% | 90% | 87% |
-Set each floor about five points below that scope's measured coverage, so it catches a real
-regression without failing on ordinary churn. Floors track measured coverage: they are reset when
-coverage legitimately moves — a refactor relocating covered logic, a lane split changing which
-specs a lane runs — and they exist to catch regressions, not to force coverage.
+When raising a floor, set it about five points below that scope's measured coverage, so it catches
+a real regression without failing on ordinary churn. When coverage legitimately shifts — a refactor
+relocating covered logic, a lane split changing which specs a lane runs — reset the floor to the
+newly measured coverage instead. Floors exist to catch regressions, not to force coverage.
Two behaviours of Jest's threshold matching are worth knowing before adding a scope:
diff --git a/docs/11-operational-runbooks.md b/docs/11-operational-runbooks.md
index 7921de0ab..a86319a3c 100644
--- a/docs/11-operational-runbooks.md
+++ b/docs/11-operational-runbooks.md
@@ -496,8 +496,9 @@ git checkout v<old-version>
docker compose build openwa-api
# 3. Restore from the pre-upgrade backup (both DBs + sessions) — the archive step 2 produced is
-# "$BACKUP_DIR/openwa-backup-<timestamp>.tar.gz"
-./scripts/restore.sh "$BACKUP_DIR/openwa-backup-<timestamp>.tar.gz"
+# "$BACKUP_DIR/openwa-backup-<timestamp>.tar.gz". The databases in place still hold the failed
+# upgrade's data, so the restore refuses to touch them without --force
+./scripts/restore.sh "$BACKUP_DIR/openwa-backup-<timestamp>.tar.gz" --force
# 4. Start with old version
docker compose up -d
diff --git a/scripts/restore.sh b/scripts/restore.sh
index 4af64e970..c309b0bbd 100755
--- a/scripts/restore.sh
+++ b/scripts/restore.sh
@@ -190,14 +190,15 @@ snapshot_external_db() {
# A restore target that already holds a working install's tables is LIVE: overwriting it destroys
# real data, and the pre-restore snapshot is a convenience, not a recovery guarantee. Probe with
-# the same sqlite3 CLI backup.sh snapshots with; a missing file — or one with no tables yet, as a
+# the same sqlite3 CLI backup.sh snapshots with, opened read-only so the guard itself cannot touch
+# the target it is guarding; a missing file — or one with no tables yet, as a
# fresh install leaves behind — is safe to restore over. Without the CLI there is no way to prove
# the file empty, so any non-empty target counts as live rather than guessed safe.
db_appears_live() {
target="$1"
[ -f "$target" ] || return 1
if command -v sqlite3 >/dev/null 2>&1; then
- tables="$(sqlite3 "$target" "SELECT count(*) FROM sqlite_master;" 2>/dev/null)" || return 0
+ tables="$(sqlite3 -readonly "$target" "SELECT count(*) FROM sqlite_master;" 2>/dev/null)" || return 0
[ "${tables:-0}" -gt 0 ]
else
[ -s "$target" ]
diff --git a/src/common/interceptors/request-metrics.interceptor.ts b/src/common/interceptors/request-metrics.interceptor.ts
index a581ff20e..b2ff1b9f1 100644
--- a/src/common/interceptors/request-metrics.interceptor.ts
+++ b/src/common/interceptors/request-metrics.interceptor.ts
@@ -17,8 +17,8 @@ import { claimHttpRequestMetrics } from '../middleware/request-metrics.middlewar
* is claimed here synchronously so the middleware (which runs first) skips it — exactly one
* observation per response across the pair.
*
- * Route label: the Express route pattern when available (bounded — `/api/sessions/:id`, not the raw
- * URL), falling back to `Controller#handler` (always available, strictly bounded).
+ * Route label: the Express route pattern when available (bounded — `/api/sessions/:sessionId`, not
+ * the raw URL), falling back to `Controller#handler` (always available, strictly bounded).
*/
const SKIPPED_PREFIXES = ['/api/health', '/api/metrics'];
diff --git a/src/modules/automation/automation-rule.controller.spec.ts b/src/modules/automation/automation-rule.controller.spec.ts
index 4be21015d..d74521c5e 100644
--- a/src/modules/automation/automation-rule.controller.spec.ts
+++ b/src/modules/automation/automation-rule.controller.spec.ts
@@ -38,7 +38,9 @@ describe('AutomationRuleController', () => {
beforeEach(() => jest.clearAllMocks());
it('create delegates to the service and projects the entity onto the response DTO', async () => {
- const dto = { name: 'Greet new enquiries', replyText: 'Thanks for reaching out — we reply within the hour.' };
+ // Distinct from ruleEntity()'s name/replyText, so a projection that reads the DTO's slots
+ // instead of the entity's cannot pass by echoing identical values.
+ const dto = { name: 'Away-hours autoresponder', replyText: 'We are closed — we reply next business day.' };
service.create.mockResolvedValue(ruleEntity());
const result = await controller.create('s1', dto);
diff --git a/src/modules/infra/infra-access-control.spec.ts b/src/modules/infra/infra-access-control.spec.ts
index 5eb708c04..6881e12e6 100644
--- a/src/modules/infra/infra-access-control.spec.ts
+++ b/src/modules/infra/infra-access-control.spec.ts
@@ -28,7 +28,7 @@ import { InfraStorageController } from './infra-storage.controller';
import { REQUIRED_ROLE_KEY } from '../auth/decorators/auth.decorators';
import { ApiKeyRole } from '../auth/entities/api-key.entity';
-describe('Infra controllers access control (Vuln 2)', () => {
+describe('Infra controllers access control', () => {
const reflector = new Reflector();
// Every mutating, data-exfiltration, and operational-read endpoint must require
diff --git a/src/modules/infra/infra-config.controller.spec.ts b/src/modules/infra/infra-config.controller.spec.ts
index d446b295b..97f6f786c 100644
--- a/src/modules/infra/infra-config.controller.spec.ts
+++ b/src/modules/infra/infra-config.controller.spec.ts
@@ -1088,9 +1088,9 @@ describe('InfraConfigController.requestRestart constrains teardown to managed pr
});
});
-// C002: the infra module exposed sensitive ADMIN operations (credential config write, restart/Docker
-// orchestration, full-DB + storage export/import) with no audit trail. Each now emits an AuditAction.
-describe('InfraConfigController C002 audit trail (light-dependency handlers)', () => {
+// The infra module's sensitive ADMIN operations (credential config write, restart/Docker
+// orchestration, full-DB + storage export/import) must leave an audit trail — each emits an AuditAction.
+describe('InfraConfigController audit trail (light-dependency handlers)', () => {
const makeAudit = (): { logInfo: jest.Mock } => ({ logInfo: jest.fn().mockResolvedValue(null) });
// Positional constructor: (engineFactory, dockerService, shutdownService, auditService?).
diff --git a/src/modules/infra/infra-data.controller.spec.ts b/src/modules/infra/infra-data.controller.spec.ts
index 064cb78d0..db6ce585c 100644
--- a/src/modules/infra/infra-data.controller.spec.ts
+++ b/src/modules/infra/infra-data.controller.spec.ts
@@ -1412,7 +1412,7 @@ describe('InfraDataController.import/export preserves every data-DB table', () =
});
});
-describe('InfraDataController C002 audit trail — import emits only on a committed restore', () => {
+describe('InfraDataController audit trail — import emits only on a committed restore', () => {
let ds: DataSource;
const cfg = { get: (key: string, def?: unknown) => (key === 'dataDatabase.type' ? 'sqlite' : def) };
const build = (audit: { logInfo: jest.Mock }): InfraDataController =>
@@ -1890,9 +1890,9 @@ describe('InfraDataController.importData status_updates + runtime reconciliation
});
});
-// C002: the infra module exposed sensitive ADMIN operations (credential config write, restart/Docker
-// orchestration, full-DB + storage export/import) with no audit trail. Each now emits an AuditAction.
-describe('InfraDataController C002 audit trail (light-dependency handlers)', () => {
+// The infra module's sensitive ADMIN operations (credential config write, restart/Docker
+// orchestration, full-DB + storage export/import) must leave an audit trail — each emits an AuditAction.
+describe('InfraDataController audit trail (light-dependency handlers)', () => {
const makeAudit = (): { logInfo: jest.Mock } => ({ logInfo: jest.fn().mockResolvedValue(null) });
// Positional constructor: (config, dataDs, auditService?, sessionService?, lidMappingStore?).
diff --git a/src/modules/infra/infra-data.controller.ts b/src/modules/infra/infra-data.controller.ts
index 3637ef816..6f75798ed 100644
--- a/src/modules/infra/infra-data.controller.ts
+++ b/src/modules/infra/infra-data.controller.ts
@@ -456,7 +456,7 @@ export class InfraDataController {
};
// Audit the full-DB export: this payload carries plugin-instance secrets, so WHO pulled
- // a dump (and the per-table row counts) is exactly the trail C002 was missing. Data itself is never
+ // a dump (and the per-table row counts) must land in the audit log. Data itself is never
// logged — only counts.
await this.auditService?.logInfo(AuditAction.INFRA_DATA_EXPORTED, { metadata: { counts } });
diff --git a/src/modules/infra/infra-storage.controller.spec.ts b/src/modules/infra/infra-storage.controller.spec.ts
index a41822d67..f59bea0a9 100644
--- a/src/modules/infra/infra-storage.controller.spec.ts
+++ b/src/modules/infra/infra-storage.controller.spec.ts
@@ -29,7 +29,7 @@ import { BadRequestException } from '@nestjs/common';
import { InfraStorageController } from './infra-storage.controller';
import { AuditAction } from '../audit/entities/audit-log.entity';
-describe('InfraStorageController.importStorage filePath validation (Vuln 3)', () => {
+describe('InfraStorageController.importStorage filePath validation', () => {
function buildController(storage: Partial<{ importFromStream: jest.Mock; getCurrentStorageType: jest.Mock }>) {
return new InfraStorageController(storage as never);
}
@@ -246,9 +246,9 @@ describe('InfraStorageController storage stream failures surface as request erro
});
});
-// C002: the infra module exposed sensitive ADMIN operations (credential config write, restart/Docker
-// orchestration, full-DB + storage export/import) with no audit trail. Each now emits an AuditAction.
-describe('InfraStorageController C002 audit trail (light-dependency handlers)', () => {
+// The infra module's sensitive ADMIN operations (credential config write, restart/Docker
+// orchestration, full-DB + storage export/import) must leave an audit trail — each emits an AuditAction.
+describe('InfraStorageController audit trail (light-dependency handlers)', () => {
const makeAudit = (): { logInfo: jest.Mock } => ({ logInfo: jest.fn().mockResolvedValue(null) });
// Positional constructor: (storageService, auditService?). auditService is the last @Optional arg.
diff --git a/src/modules/session/session-engine-controls.ts b/src/modules/session/session-engine-controls.ts
index a187b4685..26f1e70bd 100644
--- a/src/modules/session/session-engine-controls.ts
+++ b/src/modules/session/session-engine-controls.ts
@@ -350,7 +350,7 @@ export class SessionEngineControls {
const engine = this.engines.get(id);
if (!engine) {
- throw new BadRequestException('Session is not started. Call POST /sessions/:id/start first.');
+ throw new BadRequestException('Session is not started. Call POST /sessions/:sessionId/start first.');
}
// Mark as tearing down BEFORE cleanup so an in-flight reconnect can't resurrect it.
@@ -418,7 +418,7 @@ export class SessionEngineControls {
// refusal. A wedged engine torn down earlier is reaped by the next start()'s orphan sweep (and
// by process exit), not by force-kill.
if (!engine) {
- throw new BadRequestException('Session is not started. Call POST /sessions/:id/start first.');
+ throw new BadRequestException('Session is not started. Call POST /sessions/:sessionId/start first.');
}
// Mark as tearing down BEFORE cleanup so an in-flight reconnect can't resurrect it.
diff --git a/src/modules/session/session.service.ts b/src/modules/session/session.service.ts
index a6a68b9ab..c7b53be85 100644
--- a/src/modules/session/session.service.ts
+++ b/src/modules/session/session.service.ts
@@ -479,7 +479,7 @@ export class SessionService implements OnModuleDestroy, OnModuleInit, OnApplicat
const engine = this.engines.get(id);
if (!engine) {
- throw new BadRequestException('Session is not started. Call POST /sessions/:id/start first.');
+ throw new BadRequestException('Session is not started. Call POST /sessions/:sessionId/start first.');
}
const qrCode = engine.getQRCode();
@@ -506,7 +506,7 @@ export class SessionService implements OnModuleDestroy, OnModuleInit, OnApplicat
const engine = this.engines.get(id);
if (!engine) {
- throw new BadRequestException('Session is not started. Call POST /sessions/:id/start first.');
+ throw new BadRequestException('Session is not started. Call POST /sessions/:sessionId/start first.');
}
if (session.status === SessionStatus.READY) {
throw new BadRequestException('Session is already authenticated, no pairing needed');