@openclaw/whatsapp 2026.5.2 → 2026.5.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-control-BQ3tCkH8.js +288 -0
- package/dist/account-config-CNQ33oav.js +47 -0
- package/dist/account-ids-DG18xddX.js +5 -0
- package/dist/accounts-BDqgpFEB.js +116 -0
- package/dist/action-runtime-DTGNgG-i.js +74 -0
- package/dist/action-runtime-api.js +2 -0
- package/dist/action-runtime.runtime.js +2 -0
- package/dist/active-listener-N7GFKsuN.js +11 -0
- package/dist/agent-tools-login-DpRxLNRB.js +89 -0
- package/dist/api.js +148 -0
- package/dist/audio-preflight.runtime-Bcdsl_ri.js +7 -0
- package/dist/auth-presence.js +32 -0
- package/dist/auth-store-BjCb50Ry.js +381 -0
- package/dist/channel-DQ-5Xoj9.js +542 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel-react-action-Df20qAy9.js +42 -0
- package/dist/channel.runtime-DKXRnA8x.js +55 -0
- package/dist/channel.setup-DOHR2BGp.js +20 -0
- package/dist/command-policy-O8sRnqUV.js +8 -0
- package/dist/config-schema-Dmo66Ubb.js +27 -0
- package/dist/connection-controller-BiHAsTM8.js +596 -0
- package/dist/connection-controller-registry-D_iIGz5m.js +22 -0
- package/dist/constants-DLGCIbfl.js +4 -0
- package/dist/constants.js +2 -0
- package/dist/contract-api.js +19 -0
- package/dist/creds-files-_2V8jzQa.js +19 -0
- package/dist/directory-config-DVs4ffXu.js +37 -0
- package/dist/directory-contract-api.js +2 -0
- package/dist/doctor-A9tXm9Om.js +48 -0
- package/dist/doctor-contract-api.js +10 -0
- package/dist/group-session-contract-B8QBn0I2.js +15 -0
- package/dist/identity-QHAlV7Fu.js +75 -0
- package/dist/index.js +18 -0
- package/dist/legacy-session-surface-api.js +8 -0
- package/dist/legacy-state-migrations-api.js +2 -0
- package/dist/light-runtime-api.js +5 -0
- package/dist/login-DymdrKca.js +52 -0
- package/dist/login-qr-DIS0Iv-7.js +378 -0
- package/dist/login-qr-api.js +2 -0
- package/dist/login-qr-runtime.js +16 -0
- package/dist/monitor-C4Fhg_lD.js +3349 -0
- package/dist/normalize-CWYiGkXw.js +2 -0
- package/dist/normalize-target-BPVHNsM5.js +74 -0
- package/dist/outbound-adapter-BssVnZdz.js +29 -0
- package/dist/outbound-base-Bq1UYEK5.js +119 -0
- package/dist/outbound-media-contract-CGss_QHy.js +163 -0
- package/dist/outbound-payload-test-api.js +2 -0
- package/dist/quoted-message-TENQzyxV.js +108 -0
- package/dist/reaction-level-CRVEVAfi.js +16 -0
- package/dist/reply-resolver.runtime-BRCgoO4C.js +2 -0
- package/dist/resolve-outbound-target-CN-Wo6IY.js +39 -0
- package/dist/rolldown-runtime-RkAeH_Qm.js +27 -0
- package/dist/runtime-6fZ67abR.js +8 -0
- package/dist/runtime-api.js +15 -0
- package/dist/runtime-group-policy-Gp1lQ0at.js +11 -0
- package/dist/secret-contract-api.js +5 -0
- package/dist/security-contract-DqH8JDX6.js +26 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-CIyLFxdZ.js +234 -0
- package/dist/session-contract-B0efQf9P.js +27 -0
- package/dist/session-errors-CSuKZPub.js +63 -0
- package/dist/session.runtime-C1eSE_KK.js +13 -0
- package/dist/setup-core-DZKvpzbH.js +46 -0
- package/dist/setup-entry.js +23 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/setup-surface-ieFnIW4g.js +344 -0
- package/dist/shared-D_wzSVar.js +307 -0
- package/dist/state-migrations-DnCdvoYD.js +39 -0
- package/dist/targets.js +2 -0
- package/dist/test-api.js +3 -0
- package/dist/text-runtime-C1zNiZeO.js +116 -0
- package/package.json +14 -6
- package/action-runtime-api.ts +0 -1
- package/action-runtime.runtime.ts +0 -1
- package/api.ts +0 -213
- package/auth-presence.ts +0 -80
- package/channel-config-api.ts +0 -1
- package/channel-plugin-api.ts +0 -3
- package/config-api.ts +0 -4
- package/constants.ts +0 -1
- package/contract-api.ts +0 -29
- package/directory-contract-api.ts +0 -4
- package/doctor-contract-api.ts +0 -8
- package/index.test.ts +0 -13
- package/index.ts +0 -16
- package/legacy-session-surface-api.ts +0 -6
- package/legacy-state-migrations-api.ts +0 -1
- package/light-runtime-api.ts +0 -12
- package/login-qr-api.ts +0 -1
- package/login-qr-runtime.ts +0 -23
- package/outbound-payload-test-api.ts +0 -1
- package/runtime-api.ts +0 -84
- package/secret-contract-api.ts +0 -4
- package/security-contract-api.ts +0 -4
- package/setup-entry.test.ts +0 -21
- package/setup-entry.ts +0 -21
- package/setup-plugin-api.ts +0 -3
- package/src/account-config.ts +0 -77
- package/src/account-ids.ts +0 -13
- package/src/account-types.ts +0 -5
- package/src/accounts.test.ts +0 -182
- package/src/accounts.ts +0 -176
- package/src/accounts.whatsapp-auth.test.ts +0 -59
- package/src/action-runtime-target-auth.ts +0 -27
- package/src/action-runtime.test.ts +0 -330
- package/src/action-runtime.ts +0 -76
- package/src/active-listener.test.ts +0 -65
- package/src/active-listener.ts +0 -17
- package/src/agent-tools-login.test.ts +0 -81
- package/src/agent-tools-login.ts +0 -113
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -27
- package/src/auth-store.runtime.ts +0 -1
- package/src/auth-store.test.ts +0 -311
- package/src/auth-store.ts +0 -502
- package/src/auto-reply/config.runtime.ts +0 -16
- package/src/auto-reply/constants.ts +0 -1
- package/src/auto-reply/deliver-reply.test.ts +0 -843
- package/src/auto-reply/deliver-reply.ts +0 -279
- package/src/auto-reply/loggers.ts +0 -6
- package/src/auto-reply/mentions.ts +0 -131
- package/src/auto-reply/monitor/ack-reaction.test.ts +0 -170
- package/src/auto-reply/monitor/ack-reaction.ts +0 -99
- package/src/auto-reply/monitor/audio-preflight.runtime.ts +0 -9
- package/src/auto-reply/monitor/broadcast.ts +0 -153
- package/src/auto-reply/monitor/commands.ts +0 -19
- package/src/auto-reply/monitor/echo.ts +0 -64
- package/src/auto-reply/monitor/group-activation.runtime.ts +0 -1
- package/src/auto-reply/monitor/group-activation.test.ts +0 -189
- package/src/auto-reply/monitor/group-activation.ts +0 -73
- package/src/auto-reply/monitor/group-gating.audio-preflight.test.ts +0 -103
- package/src/auto-reply/monitor/group-gating.runtime.ts +0 -8
- package/src/auto-reply/monitor/group-gating.ts +0 -217
- package/src/auto-reply/monitor/group-members.test.ts +0 -56
- package/src/auto-reply/monitor/group-members.ts +0 -65
- package/src/auto-reply/monitor/inbound-context.test.ts +0 -97
- package/src/auto-reply/monitor/inbound-context.ts +0 -92
- package/src/auto-reply/monitor/inbound-dispatch.runtime.ts +0 -21
- package/src/auto-reply/monitor/inbound-dispatch.test.ts +0 -895
- package/src/auto-reply/monitor/inbound-dispatch.ts +0 -422
- package/src/auto-reply/monitor/last-route.test.ts +0 -37
- package/src/auto-reply/monitor/last-route.ts +0 -61
- package/src/auto-reply/monitor/message-line.runtime.ts +0 -38
- package/src/auto-reply/monitor/message-line.ts +0 -54
- package/src/auto-reply/monitor/on-message.audio-preflight.test.ts +0 -354
- package/src/auto-reply/monitor/on-message.ts +0 -291
- package/src/auto-reply/monitor/peer.ts +0 -17
- package/src/auto-reply/monitor/process-message.audio-preflight.test.ts +0 -420
- package/src/auto-reply/monitor/process-message.test.ts +0 -355
- package/src/auto-reply/monitor/process-message.ts +0 -531
- package/src/auto-reply/monitor/runtime-api.ts +0 -30
- package/src/auto-reply/monitor-state.test.ts +0 -64
- package/src/auto-reply/monitor-state.ts +0 -106
- package/src/auto-reply/monitor.ts +0 -600
- package/src/auto-reply/reply-resolver.runtime.ts +0 -1
- package/src/auto-reply/types.ts +0 -48
- package/src/auto-reply/util.ts +0 -63
- package/src/auto-reply/web-auto-reply-monitor.test.ts +0 -687
- package/src/auto-reply/web-auto-reply-utils.test.ts +0 -392
- package/src/auto-reply.broadcast-groups.combined.test.ts +0 -246
- package/src/auto-reply.broadcast-groups.test-harness.ts +0 -47
- package/src/auto-reply.impl.ts +0 -6
- package/src/auto-reply.test-harness.ts +0 -421
- package/src/auto-reply.ts +0 -1
- package/src/auto-reply.web-auto-reply.compresses-common-formats-jpeg-cap.test.ts +0 -427
- package/src/auto-reply.web-auto-reply.connection-and-logging.e2e.test.ts +0 -908
- package/src/auto-reply.web-auto-reply.last-route.test.ts +0 -184
- package/src/channel-actions.runtime.ts +0 -7
- package/src/channel-actions.test.ts +0 -216
- package/src/channel-actions.ts +0 -84
- package/src/channel-outbound.test.ts +0 -131
- package/src/channel-outbound.ts +0 -36
- package/src/channel-react-action.runtime.ts +0 -7
- package/src/channel-react-action.test.ts +0 -294
- package/src/channel-react-action.ts +0 -84
- package/src/channel.runtime.ts +0 -117
- package/src/channel.setup.test.ts +0 -461
- package/src/channel.setup.ts +0 -28
- package/src/channel.ts +0 -339
- package/src/command-policy.ts +0 -7
- package/src/config-accessors.test.ts +0 -34
- package/src/config-accessors.ts +0 -22
- package/src/config-schema.test.ts +0 -121
- package/src/config-schema.ts +0 -6
- package/src/config-ui-hints.ts +0 -24
- package/src/connection-controller-registry.test.ts +0 -27
- package/src/connection-controller-registry.ts +0 -49
- package/src/connection-controller.test.ts +0 -282
- package/src/connection-controller.ts +0 -679
- package/src/creds-files.ts +0 -19
- package/src/creds-persistence.ts +0 -102
- package/src/directory-config.test.ts +0 -60
- package/src/directory-config.ts +0 -40
- package/src/directory-contract.test.ts +0 -56
- package/src/doctor-contract.ts +0 -11
- package/src/doctor.test.ts +0 -74
- package/src/doctor.ts +0 -56
- package/src/group-intro.ts +0 -15
- package/src/group-policy.test.ts +0 -36
- package/src/group-policy.ts +0 -40
- package/src/group-session-contract.ts +0 -20
- package/src/group-session-key.test.ts +0 -53
- package/src/group-session-key.ts +0 -41
- package/src/heartbeat.ts +0 -34
- package/src/identity.ts +0 -164
- package/src/inbound/access-control.test-harness.ts +0 -37
- package/src/inbound/access-control.test.ts +0 -375
- package/src/inbound/access-control.ts +0 -237
- package/src/inbound/dedupe.ts +0 -132
- package/src/inbound/extract.test.ts +0 -282
- package/src/inbound/extract.ts +0 -488
- package/src/inbound/lifecycle.ts +0 -39
- package/src/inbound/media.node.test.ts +0 -83
- package/src/inbound/media.ts +0 -102
- package/src/inbound/monitor.ts +0 -890
- package/src/inbound/runtime-api.ts +0 -7
- package/src/inbound/save-media.runtime.ts +0 -1
- package/src/inbound/send-api.test.ts +0 -319
- package/src/inbound/send-api.ts +0 -145
- package/src/inbound/send-result.ts +0 -61
- package/src/inbound/types.ts +0 -106
- package/src/inbound-context.contract.test.ts +0 -32
- package/src/inbound-policy.ts +0 -231
- package/src/inbound.media.test.ts +0 -320
- package/src/inbound.test.ts +0 -290
- package/src/inbound.ts +0 -9
- package/src/login-qr.test.ts +0 -483
- package/src/login-qr.ts +0 -542
- package/src/login.coverage.test.ts +0 -133
- package/src/login.test.ts +0 -89
- package/src/login.ts +0 -70
- package/src/logout.test.ts +0 -162
- package/src/media.test.ts +0 -480
- package/src/media.ts +0 -10
- package/src/monitor-inbox.allows-messages-from-senders-allowfrom-list.test-support.ts +0 -400
- package/src/monitor-inbox.append-upsert.test-support.ts +0 -133
- package/src/monitor-inbox.behavior.test.ts +0 -5
- package/src/monitor-inbox.blocks-messages-from-unauthorized-senders-not-allowfrom.test-support.ts +0 -362
- package/src/monitor-inbox.captures-media-path-image-messages.test-support.ts +0 -306
- package/src/monitor-inbox.streams-inbound-messages.test-support.ts +0 -729
- package/src/monitor-inbox.test-harness.ts +0 -304
- package/src/normalize-target.ts +0 -123
- package/src/normalize.ts +0 -7
- package/src/outbound-adapter.poll.test.ts +0 -62
- package/src/outbound-adapter.sendpayload.test.ts +0 -195
- package/src/outbound-adapter.ts +0 -36
- package/src/outbound-base.test.ts +0 -560
- package/src/outbound-base.ts +0 -244
- package/src/outbound-media-contract.ts +0 -278
- package/src/outbound-media.runtime.ts +0 -36
- package/src/outbound-payload.contract.test.ts +0 -61
- package/src/outbound-send-deps.ts +0 -1
- package/src/outbound-test-support.ts +0 -16
- package/src/pairing-security.test-harness.ts +0 -59
- package/src/qr-image.ts +0 -1
- package/src/qr-terminal.ts +0 -1
- package/src/quoted-message.test.ts +0 -83
- package/src/quoted-message.ts +0 -184
- package/src/reaction-level.test.ts +0 -94
- package/src/reaction-level.ts +0 -21
- package/src/reconnect.test.ts +0 -51
- package/src/reconnect.ts +0 -55
- package/src/resolve-outbound-target.test.ts +0 -288
- package/src/resolve-outbound-target.ts +0 -58
- package/src/resolve-target.test.ts +0 -120
- package/src/runtime-api.ts +0 -59
- package/src/runtime-group-policy.ts +0 -16
- package/src/runtime.ts +0 -9
- package/src/security-contract.ts +0 -47
- package/src/security-fix.ts +0 -71
- package/src/send.test.ts +0 -534
- package/src/send.ts +0 -292
- package/src/session-contract.test.ts +0 -31
- package/src/session-contract.ts +0 -43
- package/src/session-errors.ts +0 -125
- package/src/session-route.test.ts +0 -41
- package/src/session-route.ts +0 -32
- package/src/session.runtime.ts +0 -8
- package/src/session.test.ts +0 -559
- package/src/session.ts +0 -330
- package/src/setup-core.ts +0 -52
- package/src/setup-finalize.ts +0 -446
- package/src/setup-surface.test.ts +0 -367
- package/src/setup-surface.ts +0 -69
- package/src/setup-test-helpers.ts +0 -216
- package/src/shared.ts +0 -291
- package/src/socket-timing.test.ts +0 -49
- package/src/socket-timing.ts +0 -38
- package/src/state-migrations.ts +0 -54
- package/src/status-issues.test.ts +0 -137
- package/src/status-issues.ts +0 -185
- package/src/system-prompt.test.ts +0 -199
- package/src/system-prompt.ts +0 -31
- package/src/targets-runtime.ts +0 -180
- package/src/test-helpers.ts +0 -690
- package/src/text-runtime.test.ts +0 -162
- package/src/text-runtime.ts +0 -11
- package/src/vcard.ts +0 -84
- package/targets.ts +0 -5
- package/test-api.ts +0 -2
- package/tsconfig.json +0 -16
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
import "./test-helpers.js";
|
|
2
|
-
import { EventEmitter } from "node:events";
|
|
3
|
-
import fs from "node:fs/promises";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { resetInboundDedupe } from "openclaw/plugin-sdk/reply-dedupe";
|
|
7
|
-
import { resetLogger, setLoggerOverride } from "openclaw/plugin-sdk/runtime-env";
|
|
8
|
-
import { mockPinnedHostnameResolution } from "openclaw/plugin-sdk/test-env";
|
|
9
|
-
import { afterAll, afterEach, beforeAll, beforeEach, vi, type Mock } from "vitest";
|
|
10
|
-
import type { WebChannelStatus } from "./auto-reply/types.js";
|
|
11
|
-
import type { WebInboundMessage, WebListenerCloseReason } from "./inbound.js";
|
|
12
|
-
import type { WhatsAppSendKind, WhatsAppSendResult } from "./inbound/send-result.js";
|
|
13
|
-
import {
|
|
14
|
-
resetBaileysMocks as _resetBaileysMocks,
|
|
15
|
-
resetLoadConfigMock as _resetLoadConfigMock,
|
|
16
|
-
} from "./test-helpers.js";
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
resetLoadConfigMock,
|
|
20
|
-
setLoadConfigMock,
|
|
21
|
-
setRuntimeConfigSourceSnapshotMock,
|
|
22
|
-
} from "./test-helpers.js";
|
|
23
|
-
|
|
24
|
-
// Avoid exporting inferred vitest mock types (TS2742 under pnpm + d.ts emit).
|
|
25
|
-
type AnyExport = any;
|
|
26
|
-
type MockWebListener = {
|
|
27
|
-
close: () => Promise<void>;
|
|
28
|
-
onClose: Promise<WebListenerCloseReason>;
|
|
29
|
-
signalClose: () => void;
|
|
30
|
-
sendMessage: () => Promise<WhatsAppSendResult>;
|
|
31
|
-
sendPoll: () => Promise<WhatsAppSendResult>;
|
|
32
|
-
sendReaction: () => Promise<WhatsAppSendResult>;
|
|
33
|
-
sendComposingTo: () => Promise<void>;
|
|
34
|
-
};
|
|
35
|
-
type UnknownMock = Mock<(...args: unknown[]) => unknown>;
|
|
36
|
-
type AsyncUnknownMock = Mock<(...args: unknown[]) => Promise<unknown>>;
|
|
37
|
-
type WebAutoReplyRuntime = {
|
|
38
|
-
log: UnknownMock;
|
|
39
|
-
error: UnknownMock;
|
|
40
|
-
exit: UnknownMock;
|
|
41
|
-
};
|
|
42
|
-
type WebAutoReplyMonitorHarness = {
|
|
43
|
-
runtime: WebAutoReplyRuntime;
|
|
44
|
-
controller: AbortController;
|
|
45
|
-
run: Promise<unknown>;
|
|
46
|
-
};
|
|
47
|
-
type MockSessionSocket = {
|
|
48
|
-
ev: {
|
|
49
|
-
on: ReturnType<typeof vi.fn>;
|
|
50
|
-
off: ReturnType<typeof vi.fn>;
|
|
51
|
-
};
|
|
52
|
-
ws: EventEmitter & {
|
|
53
|
-
close: ReturnType<typeof vi.fn>;
|
|
54
|
-
};
|
|
55
|
-
user: { id: string };
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const TEST_NET_IP = "93.184.216.34";
|
|
59
|
-
const WEB_AUTO_REPLY_SOCKETS_KEY = Symbol.for("openclaw:webAutoReplySessionSockets");
|
|
60
|
-
|
|
61
|
-
function getSessionSockets(): MockSessionSocket[] {
|
|
62
|
-
const store = globalThis as Record<PropertyKey, unknown>;
|
|
63
|
-
if (!Array.isArray(store[WEB_AUTO_REPLY_SOCKETS_KEY])) {
|
|
64
|
-
store[WEB_AUTO_REPLY_SOCKETS_KEY] = [];
|
|
65
|
-
}
|
|
66
|
-
return store[WEB_AUTO_REPLY_SOCKETS_KEY] as MockSessionSocket[];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
vi.mock("./session.js", async () => {
|
|
70
|
-
const actual = await vi.importActual<typeof import("./session.js")>("./session.js");
|
|
71
|
-
return {
|
|
72
|
-
...actual,
|
|
73
|
-
createWaSocket: vi.fn(async () => {
|
|
74
|
-
const ws = new EventEmitter() as MockSessionSocket["ws"];
|
|
75
|
-
ws.close = vi.fn();
|
|
76
|
-
const socket: MockSessionSocket = {
|
|
77
|
-
ev: {
|
|
78
|
-
on: vi.fn(),
|
|
79
|
-
off: vi.fn(),
|
|
80
|
-
},
|
|
81
|
-
ws,
|
|
82
|
-
user: { id: "123@s.whatsapp.net" },
|
|
83
|
-
};
|
|
84
|
-
getSessionSockets().push(socket);
|
|
85
|
-
return socket;
|
|
86
|
-
}),
|
|
87
|
-
waitForWaConnection: vi.fn().mockResolvedValue(undefined),
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
export function getLastWebAutoReplySessionSocket(): MockSessionSocket {
|
|
92
|
-
const last = getSessionSockets().at(-1);
|
|
93
|
-
if (!last) {
|
|
94
|
-
throw new Error("No WhatsApp Web auto-reply test socket created");
|
|
95
|
-
}
|
|
96
|
-
return last;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function resetWebAutoReplySessionSockets() {
|
|
100
|
-
getSessionSockets().length = 0;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
vi.mock("openclaw/plugin-sdk/agent-runtime", () => ({
|
|
104
|
-
abortEmbeddedPiRun: vi.fn().mockReturnValue(false),
|
|
105
|
-
appendCronStyleCurrentTimeLine: (text: string) => text,
|
|
106
|
-
isEmbeddedPiRunActive: vi.fn().mockReturnValue(false),
|
|
107
|
-
isEmbeddedPiRunStreaming: vi.fn().mockReturnValue(false),
|
|
108
|
-
queueEmbeddedPiMessage: vi.fn().mockReturnValue(false),
|
|
109
|
-
resolveEmbeddedSessionLane: (key: string) => `session:${key.trim() || "main"}`,
|
|
110
|
-
resolveIdentityNamePrefix: (cfg: { messages?: { responsePrefix?: string } }, _agentId: string) =>
|
|
111
|
-
cfg.messages?.responsePrefix,
|
|
112
|
-
resolveMessagePrefix: (cfg: { messages?: { messagePrefix?: string } }) =>
|
|
113
|
-
cfg.messages?.messagePrefix,
|
|
114
|
-
runEmbeddedPiAgent: vi.fn(),
|
|
115
|
-
}));
|
|
116
|
-
|
|
117
|
-
async function rmDirWithRetries(
|
|
118
|
-
dir: string,
|
|
119
|
-
opts?: { attempts?: number; delayMs?: number },
|
|
120
|
-
): Promise<void> {
|
|
121
|
-
const attempts = opts?.attempts ?? 10;
|
|
122
|
-
const delayMs = opts?.delayMs ?? 5;
|
|
123
|
-
// Some tests can leave async session-store writes in-flight; recursive deletion can race and throw ENOTEMPTY.
|
|
124
|
-
// Let Node handle retries (faster than re-walking the tree in JS on each retry).
|
|
125
|
-
try {
|
|
126
|
-
await fs.rm(dir, {
|
|
127
|
-
recursive: true,
|
|
128
|
-
force: true,
|
|
129
|
-
maxRetries: attempts,
|
|
130
|
-
retryDelay: delayMs,
|
|
131
|
-
});
|
|
132
|
-
return;
|
|
133
|
-
} catch {
|
|
134
|
-
// Fall back for older Node implementations (or unexpected retry behavior).
|
|
135
|
-
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
136
|
-
try {
|
|
137
|
-
await fs.rm(dir, { recursive: true, force: true });
|
|
138
|
-
return;
|
|
139
|
-
} catch (retryErr) {
|
|
140
|
-
const code =
|
|
141
|
-
retryErr && typeof retryErr === "object" && "code" in retryErr
|
|
142
|
-
? String((retryErr as { code?: unknown }).code)
|
|
143
|
-
: null;
|
|
144
|
-
if (code === "ENOTEMPTY" || code === "EBUSY" || code === "EPERM") {
|
|
145
|
-
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
throw retryErr;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
await fs.rm(dir, { recursive: true, force: true });
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
let previousHome: string | undefined;
|
|
157
|
-
let tempHome: string | undefined;
|
|
158
|
-
let tempHomeRoot: string | undefined;
|
|
159
|
-
let tempHomeId = 0;
|
|
160
|
-
|
|
161
|
-
export function installWebAutoReplyTestHomeHooks() {
|
|
162
|
-
beforeAll(async () => {
|
|
163
|
-
tempHomeRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-web-home-suite-"));
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
beforeEach(async () => {
|
|
167
|
-
resetInboundDedupe();
|
|
168
|
-
previousHome = process.env.HOME;
|
|
169
|
-
tempHome = path.join(tempHomeRoot ?? os.tmpdir(), `case-${++tempHomeId}`);
|
|
170
|
-
await fs.mkdir(tempHome, { recursive: true });
|
|
171
|
-
process.env.HOME = tempHome;
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
afterEach(async () => {
|
|
175
|
-
process.env.HOME = previousHome;
|
|
176
|
-
tempHome = undefined;
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
afterAll(async () => {
|
|
180
|
-
if (tempHomeRoot) {
|
|
181
|
-
await rmDirWithRetries(tempHomeRoot);
|
|
182
|
-
tempHomeRoot = undefined;
|
|
183
|
-
}
|
|
184
|
-
tempHomeId = 0;
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export async function makeSessionStore(
|
|
189
|
-
entries: Record<string, unknown> = {},
|
|
190
|
-
): Promise<{ storePath: string; cleanup: () => Promise<void> }> {
|
|
191
|
-
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-session-"));
|
|
192
|
-
const storePath = path.join(dir, "sessions.json");
|
|
193
|
-
await fs.writeFile(storePath, JSON.stringify(entries));
|
|
194
|
-
const cleanup = async () => {
|
|
195
|
-
await rmDirWithRetries(dir);
|
|
196
|
-
};
|
|
197
|
-
return {
|
|
198
|
-
storePath,
|
|
199
|
-
cleanup,
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export function installWebAutoReplyUnitTestHooks(opts?: { pinDns?: boolean }) {
|
|
204
|
-
let resolvePinnedHostnameSpy: { mockRestore: () => unknown } | undefined;
|
|
205
|
-
|
|
206
|
-
beforeEach(async () => {
|
|
207
|
-
vi.clearAllMocks();
|
|
208
|
-
resetWebAutoReplySessionSockets();
|
|
209
|
-
_resetBaileysMocks();
|
|
210
|
-
_resetLoadConfigMock();
|
|
211
|
-
if (opts?.pinDns) {
|
|
212
|
-
resolvePinnedHostnameSpy = mockPinnedHostnameResolution([TEST_NET_IP]);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
afterEach(() => {
|
|
217
|
-
resolvePinnedHostnameSpy?.mockRestore();
|
|
218
|
-
resolvePinnedHostnameSpy = undefined;
|
|
219
|
-
resetLogger();
|
|
220
|
-
setLoggerOverride(null);
|
|
221
|
-
vi.useRealTimers();
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export function createWebListenerFactoryCapture(): AnyExport {
|
|
226
|
-
let capturedOnMessage: ((msg: WebInboundMessage) => Promise<void>) | undefined;
|
|
227
|
-
let capturedOptions:
|
|
228
|
-
| {
|
|
229
|
-
onMessage: (msg: WebInboundMessage) => Promise<void>;
|
|
230
|
-
debounceMs?: number;
|
|
231
|
-
selfChatMode?: boolean;
|
|
232
|
-
}
|
|
233
|
-
| undefined;
|
|
234
|
-
const listenerFactory = async (opts: {
|
|
235
|
-
onMessage: (msg: WebInboundMessage) => Promise<void>;
|
|
236
|
-
debounceMs?: number;
|
|
237
|
-
selfChatMode?: boolean;
|
|
238
|
-
}) => {
|
|
239
|
-
capturedOnMessage = opts.onMessage;
|
|
240
|
-
capturedOptions = opts;
|
|
241
|
-
return { close: vi.fn() };
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
return {
|
|
245
|
-
listenerFactory,
|
|
246
|
-
getOnMessage: () => capturedOnMessage,
|
|
247
|
-
getLastOptions: () => capturedOptions,
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export function createMockWebListener(): MockWebListener {
|
|
252
|
-
return {
|
|
253
|
-
close: vi.fn(async () => undefined),
|
|
254
|
-
onClose: new Promise<WebListenerCloseReason>(() => {}),
|
|
255
|
-
signalClose: vi.fn(),
|
|
256
|
-
sendMessage: vi.fn(async () => createAcceptedWhatsAppSendResult("text", "msg-1")),
|
|
257
|
-
sendPoll: vi.fn(async () => createAcceptedWhatsAppSendResult("poll", "poll-1")),
|
|
258
|
-
sendReaction: vi.fn(async () => createAcceptedWhatsAppSendResult("reaction", "reaction-1")),
|
|
259
|
-
sendComposingTo: vi.fn(async () => undefined),
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
export function createAcceptedWhatsAppSendResult(
|
|
264
|
-
kind: WhatsAppSendKind,
|
|
265
|
-
id: string,
|
|
266
|
-
): WhatsAppSendResult {
|
|
267
|
-
return {
|
|
268
|
-
kind,
|
|
269
|
-
messageId: id,
|
|
270
|
-
messageIds: [id],
|
|
271
|
-
keys: [{ id }],
|
|
272
|
-
providerAccepted: true,
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export function createScriptedWebListenerFactory(): AnyExport {
|
|
277
|
-
const onMessages: Array<(msg: WebInboundMessage) => Promise<void>> = [];
|
|
278
|
-
const closeResolvers: Array<(reason: unknown) => void> = [];
|
|
279
|
-
const listeners: MockWebListener[] = [];
|
|
280
|
-
|
|
281
|
-
const listenerFactory = vi.fn(
|
|
282
|
-
async (opts: { onMessage: (msg: WebInboundMessage) => Promise<void> }) => {
|
|
283
|
-
onMessages.push(opts.onMessage);
|
|
284
|
-
let resolveClose: (reason: unknown) => void = () => {};
|
|
285
|
-
const onClose = new Promise<WebListenerCloseReason>((res) => {
|
|
286
|
-
resolveClose = res as (reason: unknown) => void;
|
|
287
|
-
closeResolvers.push(resolveClose);
|
|
288
|
-
});
|
|
289
|
-
const listener: MockWebListener = {
|
|
290
|
-
...createMockWebListener(),
|
|
291
|
-
onClose,
|
|
292
|
-
signalClose: vi.fn((reason?: unknown) => resolveClose(reason)),
|
|
293
|
-
};
|
|
294
|
-
listeners.push(listener);
|
|
295
|
-
return listener;
|
|
296
|
-
},
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
return {
|
|
300
|
-
listenerFactory,
|
|
301
|
-
listeners,
|
|
302
|
-
getOnMessage: (index = onMessages.length - 1) => onMessages[index],
|
|
303
|
-
resolveClose: (index: number, reason?: unknown) => closeResolvers[index]?.(reason),
|
|
304
|
-
getListenerCount: () => listenerFactory.mock.calls.length,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export function createWebInboundDeliverySpies(): AnyExport {
|
|
309
|
-
return {
|
|
310
|
-
sendMedia: vi.fn().mockResolvedValue(createAcceptedWhatsAppSendResult("media", "m1")),
|
|
311
|
-
reply: vi.fn().mockResolvedValue(createAcceptedWhatsAppSendResult("text", "r1")),
|
|
312
|
-
sendComposing: vi.fn(),
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function createWebAutoReplyRuntime(): WebAutoReplyRuntime {
|
|
317
|
-
return {
|
|
318
|
-
log: vi.fn(),
|
|
319
|
-
error: vi.fn(),
|
|
320
|
-
exit: vi.fn(),
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
export function startWebAutoReplyMonitor(params: {
|
|
325
|
-
monitorWebChannelFn: (...args: unknown[]) => Promise<unknown>;
|
|
326
|
-
listenerFactory: unknown;
|
|
327
|
-
sleep: UnknownMock | AsyncUnknownMock;
|
|
328
|
-
signal?: AbortSignal;
|
|
329
|
-
heartbeatSeconds?: number;
|
|
330
|
-
transportTimeoutMs?: number;
|
|
331
|
-
messageTimeoutMs?: number;
|
|
332
|
-
watchdogCheckMs?: number;
|
|
333
|
-
reconnect?: { initialMs: number; maxMs: number; maxAttempts: number; factor: number };
|
|
334
|
-
accountId?: string;
|
|
335
|
-
statusSink?: (status: WebChannelStatus) => void;
|
|
336
|
-
}): WebAutoReplyMonitorHarness {
|
|
337
|
-
const runtime = createWebAutoReplyRuntime();
|
|
338
|
-
const controller = new AbortController();
|
|
339
|
-
const run = params.monitorWebChannelFn(
|
|
340
|
-
false,
|
|
341
|
-
params.listenerFactory as never,
|
|
342
|
-
true,
|
|
343
|
-
async () => ({ text: "ok" }),
|
|
344
|
-
runtime as never,
|
|
345
|
-
params.signal ?? controller.signal,
|
|
346
|
-
{
|
|
347
|
-
heartbeatSeconds: params.heartbeatSeconds ?? 1,
|
|
348
|
-
transportTimeoutMs: params.transportTimeoutMs,
|
|
349
|
-
messageTimeoutMs: params.messageTimeoutMs,
|
|
350
|
-
watchdogCheckMs: params.watchdogCheckMs,
|
|
351
|
-
reconnect: params.reconnect ?? { initialMs: 10, maxMs: 10, maxAttempts: 3, factor: 1.1 },
|
|
352
|
-
sleep: params.sleep,
|
|
353
|
-
accountId: params.accountId,
|
|
354
|
-
statusSink: params.statusSink,
|
|
355
|
-
},
|
|
356
|
-
);
|
|
357
|
-
|
|
358
|
-
return { runtime, controller, run };
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
export async function sendWebGroupInboundMessage(params: {
|
|
362
|
-
onMessage: (msg: WebInboundMessage) => Promise<void>;
|
|
363
|
-
body: string;
|
|
364
|
-
id: string;
|
|
365
|
-
senderE164: string;
|
|
366
|
-
senderName: string;
|
|
367
|
-
mentionedJids?: string[];
|
|
368
|
-
selfE164?: string;
|
|
369
|
-
selfJid?: string;
|
|
370
|
-
spies: ReturnType<typeof createWebInboundDeliverySpies>;
|
|
371
|
-
conversationId?: string;
|
|
372
|
-
accountId?: string;
|
|
373
|
-
}) {
|
|
374
|
-
const conversationId = params.conversationId ?? "123@g.us";
|
|
375
|
-
const accountId = params.accountId ?? "default";
|
|
376
|
-
await params.onMessage({
|
|
377
|
-
body: params.body,
|
|
378
|
-
from: conversationId,
|
|
379
|
-
conversationId,
|
|
380
|
-
chatId: conversationId,
|
|
381
|
-
chatType: "group",
|
|
382
|
-
to: "+2",
|
|
383
|
-
accountId,
|
|
384
|
-
id: params.id,
|
|
385
|
-
senderE164: params.senderE164,
|
|
386
|
-
senderName: params.senderName,
|
|
387
|
-
mentionedJids: params.mentionedJids,
|
|
388
|
-
selfE164: params.selfE164,
|
|
389
|
-
selfJid: params.selfJid,
|
|
390
|
-
sendComposing: params.spies.sendComposing,
|
|
391
|
-
reply: params.spies.reply,
|
|
392
|
-
sendMedia: params.spies.sendMedia,
|
|
393
|
-
} as WebInboundMessage);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
export async function sendWebDirectInboundMessage(params: {
|
|
397
|
-
onMessage: (msg: WebInboundMessage) => Promise<void>;
|
|
398
|
-
body: string;
|
|
399
|
-
id: string;
|
|
400
|
-
from: string;
|
|
401
|
-
to: string;
|
|
402
|
-
spies: ReturnType<typeof createWebInboundDeliverySpies>;
|
|
403
|
-
accountId?: string;
|
|
404
|
-
timestamp?: number;
|
|
405
|
-
}) {
|
|
406
|
-
const accountId = params.accountId ?? "default";
|
|
407
|
-
await params.onMessage({
|
|
408
|
-
accountId,
|
|
409
|
-
id: params.id,
|
|
410
|
-
from: params.from,
|
|
411
|
-
conversationId: params.from,
|
|
412
|
-
to: params.to,
|
|
413
|
-
body: params.body,
|
|
414
|
-
timestamp: params.timestamp ?? Date.now(),
|
|
415
|
-
chatType: "direct",
|
|
416
|
-
chatId: `direct:${params.from}`,
|
|
417
|
-
sendComposing: params.spies.sendComposing,
|
|
418
|
-
reply: params.spies.reply,
|
|
419
|
-
sendMedia: params.spies.sendMedia,
|
|
420
|
-
} as WebInboundMessage);
|
|
421
|
-
}
|
package/src/auto-reply.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./auto-reply.impl.js";
|