mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-22 15:31:07 +00:00
* refactor: move WhatsApp channel from src/web/ to extensions/whatsapp/ Move all WhatsApp implementation code (77 source/test files + 9 channel plugin files) from src/web/ and src/channels/plugins/*/whatsapp* to extensions/whatsapp/src/. - Leave thin re-export shims at all original locations so cross-cutting imports continue to resolve - Update plugin-sdk/whatsapp.ts to only re-export generic framework utilities; channel-specific functions imported locally by the extension - Update vi.mock paths in 15 cross-cutting test files - Rename outbound.ts -> send.ts to match extension naming conventions and avoid false positive in cfg-threading guard test - Widen tsconfig.plugin-sdk.dts.json rootDir to support shim->extension cross-directory references Part of the core-channels-to-extensions migration (PR 6/10). * style: format WhatsApp extension files * fix: correct stale import paths in WhatsApp extension tests Fix vi.importActual, test mock, and hardcoded source paths that weren't updated during the file move: - media.test.ts: vi.importActual path - onboarding.test.ts: vi.importActual path - test-helpers.ts: test/mocks/baileys.js path - monitor-inbox.test-harness.ts: incomplete media/store mock - login.test.ts: hardcoded source file path - message-action-runner.media.test.ts: vi.mock/importActual path
135 lines
3.6 KiB
TypeScript
135 lines
3.6 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { setActivePluginRegistry } from "../plugins/runtime.js";
|
|
import { stripAnsi } from "../terminal/ansi.js";
|
|
import { createTestRegistry } from "../test-utils/channel-plugins.js";
|
|
import type { HealthSummary } from "./health.js";
|
|
import { healthCommand } from "./health.js";
|
|
|
|
const callGatewayMock = vi.fn();
|
|
const logWebSelfIdMock = vi.fn();
|
|
|
|
function createRecentSessionRows(now = Date.now()) {
|
|
return [
|
|
{ key: "main", updatedAt: now - 60_000, age: 60_000 },
|
|
{ key: "foo", updatedAt: null, age: null },
|
|
];
|
|
}
|
|
|
|
vi.mock("../gateway/call.js", () => ({
|
|
callGateway: (...args: unknown[]) => callGatewayMock(...args),
|
|
}));
|
|
|
|
vi.mock("../../extensions/whatsapp/src/auth-store.js", () => ({
|
|
webAuthExists: vi.fn(async () => true),
|
|
getWebAuthAgeMs: vi.fn(() => 0),
|
|
logWebSelfId: (...args: unknown[]) => logWebSelfIdMock(...args),
|
|
}));
|
|
|
|
describe("healthCommand (coverage)", () => {
|
|
const runtime = {
|
|
log: vi.fn(),
|
|
error: vi.fn(),
|
|
exit: vi.fn(),
|
|
};
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
setActivePluginRegistry(
|
|
createTestRegistry([
|
|
{
|
|
pluginId: "whatsapp",
|
|
source: "test",
|
|
plugin: {
|
|
id: "whatsapp",
|
|
meta: {
|
|
id: "whatsapp",
|
|
label: "WhatsApp",
|
|
selectionLabel: "WhatsApp",
|
|
docsPath: "/channels/whatsapp",
|
|
blurb: "WhatsApp test stub.",
|
|
},
|
|
capabilities: { chatTypes: ["direct", "group"] },
|
|
config: {
|
|
listAccountIds: () => ["default"],
|
|
resolveAccount: () => ({}),
|
|
},
|
|
status: {
|
|
logSelfId: () => logWebSelfIdMock(),
|
|
},
|
|
},
|
|
},
|
|
]),
|
|
);
|
|
});
|
|
|
|
it("prints the rich text summary when linked and configured", async () => {
|
|
const recent = createRecentSessionRows();
|
|
callGatewayMock.mockResolvedValueOnce({
|
|
ok: true,
|
|
ts: Date.now(),
|
|
durationMs: 5,
|
|
channels: {
|
|
whatsapp: {
|
|
accountId: "default",
|
|
linked: true,
|
|
authAgeMs: 5 * 60_000,
|
|
},
|
|
telegram: {
|
|
accountId: "default",
|
|
configured: true,
|
|
probe: {
|
|
ok: true,
|
|
elapsedMs: 7,
|
|
bot: { username: "bot" },
|
|
webhook: { url: "https://example.com/h" },
|
|
},
|
|
},
|
|
discord: {
|
|
accountId: "default",
|
|
configured: false,
|
|
},
|
|
},
|
|
channelOrder: ["whatsapp", "telegram", "discord"],
|
|
channelLabels: {
|
|
whatsapp: "WhatsApp",
|
|
telegram: "Telegram",
|
|
discord: "Discord",
|
|
},
|
|
heartbeatSeconds: 60,
|
|
defaultAgentId: "main",
|
|
agents: [
|
|
{
|
|
agentId: "main",
|
|
isDefault: true,
|
|
heartbeat: {
|
|
enabled: true,
|
|
every: "1m",
|
|
everyMs: 60_000,
|
|
prompt: "hi",
|
|
target: "last",
|
|
ackMaxChars: 160,
|
|
},
|
|
sessions: {
|
|
path: "/tmp/sessions.json",
|
|
count: 2,
|
|
recent,
|
|
},
|
|
},
|
|
],
|
|
sessions: {
|
|
path: "/tmp/sessions.json",
|
|
count: 2,
|
|
recent,
|
|
},
|
|
} satisfies HealthSummary);
|
|
|
|
await healthCommand({ json: false, timeoutMs: 1000 }, runtime as never);
|
|
|
|
expect(runtime.exit).not.toHaveBeenCalled();
|
|
expect(stripAnsi(runtime.log.mock.calls.map((c) => String(c[0])).join("\n"))).toMatch(
|
|
/WhatsApp: linked/i,
|
|
);
|
|
expect(logWebSelfIdMock).toHaveBeenCalled();
|
|
});
|
|
});
|