Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test: pin a log shape, a JSDoc order and a queued probe

Yudhi Armyndharisbfb7ed967435
diff --git a/src/engine/adapters/baileys-events.ts b/src/engine/adapters/baileys-events.ts
index 2668acff6..35a3825e9 100644
--- a/src/engine/adapters/baileys-events.ts
+++ b/src/engine/adapters/baileys-events.ts
@@ -800,17 +800,6 @@ export class BaileysEvents {
}
}
- /**
- * The stored copy of a message id, or null when the store cannot answer.
- *
- * Deliberately fail-open: a locked database or a row whose JSON no longer parses must not be read
- * as "this was never sent". The caller's only other outcome is the catch above, which drops the
- * message outright, and Baileys acks the node before it emits the upsert, so WhatsApp does not
- * send it again. A repeat is absorbed where it matters: the webhook carries the same idempotency
- * key and the insert oracle holds the row to one. A WebSocket subscriber does see the frame twice,
- * which is the price paid here deliberately, because a message nobody ever hears about cannot be
- * recovered at all. The persist side of the same store is already written this way.
- */
/**
* What an edit, revoke or reaction targets: the stored copy, or the one still being processed. The
* in-flight copy is taken BEFORE the store is read, because an original that finishes while the read is
@@ -827,6 +816,17 @@ export class BaileysEvents {
return inFlight ? { key: inFlight.key, message: inFlight.message } : null;
}
+ /**
+ * The stored copy of a message id, or null when the store cannot answer.
+ *
+ * Deliberately fail-open: a locked database or a row whose JSON no longer parses must not be read
+ * as "this was never sent". The caller's only other outcome is the catch above, which drops the
+ * message outright, and Baileys acks the node before it emits the upsert, so WhatsApp does not
+ * send it again. A repeat is absorbed where it matters: the webhook carries the same idempotency
+ * key and the insert oracle holds the row to one. A WebSocket subscriber does see the frame twice,
+ * which is the price paid here deliberately, because a message nobody ever hears about cannot be
+ * recovered at all. The persist side of the same store is already written this way.
+ */
private async readStoredMessage(messageId: string, purpose: string): Promise<WAMessage | null> {
try {
return (await this.host.getStoredMessage(messageId)) ?? null;
diff --git a/src/modules/infra/infra-config.controller.spec.ts b/src/modules/infra/infra-config.controller.spec.ts
index 05e65425e..4efeaa981 100644
--- a/src/modules/infra/infra-config.controller.spec.ts
+++ b/src/modules/infra/infra-config.controller.spec.ts
@@ -176,8 +176,6 @@ describe('InfraConfigController.saveConfig local storage path', () => {
// With no boot snapshot recorded, every key in the environment counts as host-supplied.
process.env.STORAGE_LOCAL_PATH = '/srv/openwa/media';
try {
- useRealProbe();
-
newController().saveConfig(localAt(unwritable));
expect(resolveStorageRoot).not.toHaveBeenCalled();
diff --git a/src/modules/integration/redrive.service.spec.ts b/src/modules/integration/redrive.service.spec.ts
index 370b25d61..b8dac40f6 100644
--- a/src/modules/integration/redrive.service.spec.ts
+++ b/src/modules/integration/redrive.service.spec.ts
@@ -4,6 +4,7 @@ import { IntegrationDeliveryFailure } from './entities/integration-delivery-fail
import { IngressEvent } from './entities/ingress-event.entity';
import { Repository } from 'typeorm';
import { INGRESS_DISPATCH_TIMEOUT_MS } from './integration.constants';
+import { LoggerService } from '../../common/services/logger.service';
describe('RedriveService', () => {
let repo: jest.Mocked<Partial<Repository<IntegrationDeliveryFailure>>>;
@@ -38,14 +39,26 @@ describe('RedriveService', () => {
.mockRejectedValueOnce(new SyntaxError('Unexpected token o in JSON at position 1'))
.mockResolvedValueOnce([{ id: 'f1' }, { id: 'f2' }]);
(repo.findOneBy as jest.Mock).mockRejectedValueOnce(new SyntaxError('bad json')).mockResolvedValueOnce(healthy);
+ const logged = jest.spyOn(LoggerService.prototype, 'error').mockImplementation(() => undefined);
- const res = await makeSvc().redriveInstance('p', 'i', null);
+ try {
+ const res = await makeSvc().redriveInstance('p', 'i', null);
- expect(res.redriven).toBe(1);
- expect(ingressEnqueue.enqueue).toHaveBeenCalledTimes(1);
- expect(repo.update).toHaveBeenCalledWith({ id: 'f2' }, { redriven: true });
- // The unreadable row goes behind the readable ones, so a batch of them cannot starve the rest.
- expect(repo.increment).toHaveBeenCalledWith({ id: 'f1' }, 'attempts', 1);
+ expect(res.redriven).toBe(1);
+ expect(ingressEnqueue.enqueue).toHaveBeenCalledTimes(1);
+ expect(repo.update).toHaveBeenCalledWith({ id: 'f2' }, { redriven: true });
+ // The unreadable row goes behind the readable ones, so a batch of them cannot starve the rest.
+ expect(repo.increment).toHaveBeenCalledWith({ id: 'f1' }, 'attempts', 1);
+ // Its id and the action are fields of the log line, as an alert on the action reads them: not
+ // folded into the trace argument.
+ expect(logged).toHaveBeenCalledWith(
+ expect.stringContaining('could not be read'),
+ expect.any(String),
+ expect.objectContaining({ id: 'f1', action: 'ingress_redrive_row_unreadable' }),
+ );
+ } finally {
+ logged.mockRestore();
+ }
});
it('re-enqueues non-redriven inbound failures for an instance and marks them redriven', async () => {