openclaw/src/auto-reply/reply.heartbeat-typing.test.ts
scoootscooob 16505718e8
refactor: move WhatsApp channel implementation to extensions/ (#45725)
* 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
2026-03-14 02:44:55 -07:00

62 lines
1.9 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { runEmbeddedPiAgentMock } from "./reply.directive.directive-behavior.e2e-mocks.js";
import { createTempHomeHarness, makeReplyConfig } from "./reply.test-harness.js";
vi.mock(
"../agents/model-fallback.js",
async () => await import("../test-utils/model-fallback.mock.js"),
);
const webMocks = vi.hoisted(() => ({
webAuthExists: vi.fn().mockResolvedValue(true),
getWebAuthAgeMs: vi.fn().mockReturnValue(120_000),
readWebSelfId: vi.fn().mockReturnValue({ e164: "+1999" }),
}));
vi.mock("../../extensions/whatsapp/src/session.js", () => webMocks);
import { getReplyFromConfig } from "./reply.js";
const { withTempHome } = createTempHomeHarness({
prefix: "openclaw-typing-",
beforeEachCase: () => runEmbeddedPiAgentMock.mockClear(),
});
afterEach(() => {
vi.restoreAllMocks();
});
describe("getReplyFromConfig typing (heartbeat)", () => {
async function runReplyFlow(isHeartbeat: boolean): Promise<ReturnType<typeof vi.fn>> {
const onReplyStart = vi.fn();
await withTempHome(async (home) => {
runEmbeddedPiAgentMock.mockResolvedValueOnce({
payloads: [{ text: "ok" }],
meta: {},
});
await getReplyFromConfig(
{ Body: "hi", From: "+1000", To: "+2000", Provider: "whatsapp" },
{ onReplyStart, isHeartbeat },
makeReplyConfig(home) as unknown as OpenClawConfig,
);
});
return onReplyStart;
}
beforeEach(() => {
vi.stubEnv("OPENCLAW_TEST_FAST", "1");
});
it("starts typing for normal runs", async () => {
const onReplyStart = await runReplyFlow(false);
expect(onReplyStart).toHaveBeenCalled();
});
it("does not start typing for heartbeat runs", async () => {
const onReplyStart = await runReplyFlow(true);
expect(onReplyStart).not.toHaveBeenCalled();
});
});