Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
192
test/mocks/baileys.ts
Normal file
192
test/mocks/baileys.ts
Normal file
@@ -0,0 +1,192 @@
|
||||
// Baileys mock provides a lightweight WhatsApp socket facade for tests.
|
||||
import { EventEmitter } from "node:events";
|
||||
import { vi } from "vitest";
|
||||
|
||||
type BaileysExports = typeof import("baileys");
|
||||
type FetchLatestBaileysVersionFn = BaileysExports["fetchLatestBaileysVersion"];
|
||||
type MakeCacheableSignalKeyStoreFn = BaileysExports["makeCacheableSignalKeyStore"];
|
||||
type MakeWASocketFn = BaileysExports["makeWASocket"];
|
||||
type UseMultiFileAuthStateFn = BaileysExports["useMultiFileAuthState"];
|
||||
type DownloadMediaMessageFn = BaileysExports["downloadMediaMessage"];
|
||||
type ExtractMessageContentFn = BaileysExports["extractMessageContent"];
|
||||
type GetContentTypeFn = BaileysExports["getContentType"];
|
||||
type NormalizeMessageContentFn = BaileysExports["normalizeMessageContent"];
|
||||
type IsJidGroupFn = BaileysExports["isJidGroup"];
|
||||
type MessageContentInput = Parameters<NormalizeMessageContentFn>[0];
|
||||
type MessageContentOutput = ReturnType<NormalizeMessageContentFn>;
|
||||
type MessageContentType = ReturnType<GetContentTypeFn>;
|
||||
|
||||
export type MockBaileysSocket = {
|
||||
ev: EventEmitter;
|
||||
ws: { close: ReturnType<typeof vi.fn> };
|
||||
sendPresenceUpdate: ReturnType<typeof vi.fn>;
|
||||
sendMessage: ReturnType<typeof vi.fn>;
|
||||
readMessages: ReturnType<typeof vi.fn>;
|
||||
groupFetchAllParticipating: ReturnType<typeof vi.fn>;
|
||||
user?: { id?: string };
|
||||
};
|
||||
|
||||
type MockBaileysModule = {
|
||||
BufferJSON: {
|
||||
replacer: (key: string, value: unknown) => unknown;
|
||||
reviver: (key: string, value: unknown) => unknown;
|
||||
};
|
||||
DisconnectReason: { loggedOut: number };
|
||||
extractMessageContent: ReturnType<typeof vi.fn<ExtractMessageContentFn>>;
|
||||
fetchLatestBaileysVersion: ReturnType<typeof vi.fn<FetchLatestBaileysVersionFn>>;
|
||||
getContentType: ReturnType<typeof vi.fn<GetContentTypeFn>>;
|
||||
isJidGroup: ReturnType<typeof vi.fn<IsJidGroupFn>>;
|
||||
makeCacheableSignalKeyStore: ReturnType<typeof vi.fn<MakeCacheableSignalKeyStoreFn>>;
|
||||
makeWASocket: ReturnType<typeof vi.fn<MakeWASocketFn>>;
|
||||
normalizeMessageContent: ReturnType<typeof vi.fn<NormalizeMessageContentFn>>;
|
||||
useMultiFileAuthState: ReturnType<typeof vi.fn<UseMultiFileAuthStateFn>>;
|
||||
jidToE164?: (jid: string) => string | null;
|
||||
proto?: unknown;
|
||||
downloadMediaMessage?: ReturnType<typeof vi.fn<DownloadMediaMessageFn>>;
|
||||
};
|
||||
|
||||
const MESSAGE_WRAPPER_KEYS = [
|
||||
"ephemeralMessage",
|
||||
"viewOnceMessage",
|
||||
"viewOnceMessageV2",
|
||||
"viewOnceMessageV2Extension",
|
||||
"documentWithCaptionMessage",
|
||||
] as const;
|
||||
|
||||
const MESSAGE_CONTENT_KEYS = [
|
||||
"conversation",
|
||||
"extendedTextMessage",
|
||||
"imageMessage",
|
||||
"videoMessage",
|
||||
"audioMessage",
|
||||
"documentMessage",
|
||||
"stickerMessage",
|
||||
"locationMessage",
|
||||
"liveLocationMessage",
|
||||
"contactMessage",
|
||||
"contactsArrayMessage",
|
||||
"buttonsResponseMessage",
|
||||
"listResponseMessage",
|
||||
"templateButtonReplyMessage",
|
||||
"interactiveResponseMessage",
|
||||
"buttonsMessage",
|
||||
"listMessage",
|
||||
] as const;
|
||||
|
||||
type MessageLike = Record<string, unknown>;
|
||||
|
||||
export function mockNormalizeMessageContent(message: MessageContentInput): MessageContentOutput {
|
||||
let current = message as unknown;
|
||||
while (current && typeof current === "object") {
|
||||
let unwrapped = false;
|
||||
for (const key of MESSAGE_WRAPPER_KEYS) {
|
||||
const candidate = (current as MessageLike)[key];
|
||||
if (
|
||||
candidate &&
|
||||
typeof candidate === "object" &&
|
||||
"message" in (candidate as MessageLike) &&
|
||||
(candidate as { message?: unknown }).message
|
||||
) {
|
||||
current = (candidate as { message: unknown }).message;
|
||||
unwrapped = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!unwrapped) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return current as MessageContentOutput;
|
||||
}
|
||||
|
||||
export function mockGetContentType(message: MessageContentInput): MessageContentType {
|
||||
const normalized = mockNormalizeMessageContent(message);
|
||||
if (!normalized || typeof normalized !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
for (const key of MESSAGE_CONTENT_KEYS) {
|
||||
if ((normalized as MessageLike)[key] != null) {
|
||||
return key as MessageContentType;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function mockExtractMessageContent(message: MessageContentInput): MessageContentOutput {
|
||||
const normalized = mockNormalizeMessageContent(message);
|
||||
if (!normalized || typeof normalized !== "object") {
|
||||
return normalized;
|
||||
}
|
||||
const contentType = mockGetContentType(normalized);
|
||||
if (!contentType || contentType === "conversation") {
|
||||
return normalized;
|
||||
}
|
||||
const candidate = (normalized as MessageLike)[contentType];
|
||||
return (
|
||||
candidate && typeof candidate === "object" ? candidate : normalized
|
||||
) as MessageContentOutput;
|
||||
}
|
||||
|
||||
export function mockIsJidGroup(jid: string | undefined | null): boolean {
|
||||
return typeof jid === "string" && jid.endsWith("@g.us");
|
||||
}
|
||||
|
||||
export function createMockBaileys(): {
|
||||
mod: MockBaileysModule;
|
||||
lastSocket: () => MockBaileysSocket;
|
||||
} {
|
||||
const sockets: MockBaileysSocket[] = [];
|
||||
const makeWASocket = vi.fn<MakeWASocketFn>((_opts) => {
|
||||
const ev = new EventEmitter();
|
||||
const sock: MockBaileysSocket = {
|
||||
ev,
|
||||
ws: { close: vi.fn() },
|
||||
sendPresenceUpdate: vi.fn().mockResolvedValue(undefined),
|
||||
sendMessage: vi.fn().mockResolvedValue({ key: { id: "msg123" } }),
|
||||
readMessages: vi.fn().mockResolvedValue(undefined),
|
||||
groupFetchAllParticipating: vi.fn().mockResolvedValue({}),
|
||||
user: { id: "123@s.whatsapp.net" },
|
||||
};
|
||||
setImmediate(() => ev.emit("connection.update", { connection: "open" }));
|
||||
sockets.push(sock);
|
||||
return sock as unknown as ReturnType<MakeWASocketFn>;
|
||||
});
|
||||
|
||||
const mod: MockBaileysModule = {
|
||||
BufferJSON: {
|
||||
replacer: (_key: string, value: unknown) => value,
|
||||
reviver: (_key: string, value: unknown) => value,
|
||||
},
|
||||
DisconnectReason: { loggedOut: 401 },
|
||||
extractMessageContent: vi.fn<ExtractMessageContentFn>((message) =>
|
||||
mockExtractMessageContent(message),
|
||||
),
|
||||
fetchLatestBaileysVersion: vi
|
||||
.fn<FetchLatestBaileysVersionFn>()
|
||||
.mockResolvedValue({ version: [1, 2, 3], isLatest: true }),
|
||||
getContentType: vi.fn<GetContentTypeFn>((message) => mockGetContentType(message)),
|
||||
isJidGroup: vi.fn<IsJidGroupFn>((jid) => mockIsJidGroup(jid)),
|
||||
makeCacheableSignalKeyStore: vi.fn<MakeCacheableSignalKeyStoreFn>((keys) => keys),
|
||||
makeWASocket,
|
||||
normalizeMessageContent: vi.fn<NormalizeMessageContentFn>((message) =>
|
||||
mockNormalizeMessageContent(message),
|
||||
),
|
||||
useMultiFileAuthState: vi.fn<UseMultiFileAuthStateFn>(async () => ({
|
||||
state: { creds: {}, keys: {} } as Awaited<ReturnType<UseMultiFileAuthStateFn>>["state"],
|
||||
saveCreds: vi.fn(),
|
||||
})),
|
||||
jidToE164: (jid: string) => jid.replace(/@.*$/, "").replace(/^/, "+"),
|
||||
downloadMediaMessage: vi.fn<DownloadMediaMessageFn>().mockResolvedValue(Buffer.from("img")),
|
||||
};
|
||||
|
||||
return {
|
||||
mod,
|
||||
lastSocket: () => {
|
||||
const last = sockets.at(-1);
|
||||
if (!last) {
|
||||
throw new Error("No Baileys sockets created");
|
||||
}
|
||||
return last;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user