openclaw/src/auto-reply/reply.raw-body.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

85 lines
2.8 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";
const agentMocks = vi.hoisted(() => ({
loadModelCatalog: vi.fn(),
webAuthExists: vi.fn().mockResolvedValue(true),
getWebAuthAgeMs: vi.fn().mockReturnValue(120_000),
readWebSelfId: vi.fn().mockReturnValue({ e164: "+1999" }),
}));
vi.mock("../agents/model-catalog.js", () => ({
loadModelCatalog: agentMocks.loadModelCatalog,
}));
vi.mock("../../extensions/whatsapp/src/session.js", () => ({
webAuthExists: agentMocks.webAuthExists,
getWebAuthAgeMs: agentMocks.getWebAuthAgeMs,
readWebSelfId: agentMocks.readWebSelfId,
}));
import { getReplyFromConfig } from "./reply.js";
const { withTempHome } = createTempHomeHarness({ prefix: "openclaw-rawbody-" });
describe("RawBody directive parsing", () => {
beforeEach(() => {
vi.stubEnv("OPENCLAW_TEST_FAST", "1");
runEmbeddedPiAgentMock.mockClear();
agentMocks.loadModelCatalog.mockClear();
agentMocks.loadModelCatalog.mockResolvedValue([
{ id: "claude-opus-4-5", name: "Opus 4.5", provider: "anthropic" },
]);
});
afterEach(() => {
vi.clearAllMocks();
});
it("handles directives and history in the prompt", async () => {
await withTempHome(async (home) => {
runEmbeddedPiAgentMock.mockResolvedValue({
payloads: [{ text: "ok" }],
meta: {
durationMs: 1,
agentMeta: { sessionId: "s", provider: "p", model: "m" },
},
});
const groupMessageCtx = {
Body: "/think:high status please",
BodyForAgent: "/think:high status please",
RawBody: "/think:high status please",
InboundHistory: [{ sender: "Peter", body: "hello", timestamp: 1700000000000 }],
From: "+1222",
To: "+1222",
ChatType: "group",
GroupSubject: "Ops",
SenderName: "Jake McInteer",
SenderE164: "+6421807830",
CommandAuthorized: true,
};
const res = await getReplyFromConfig(
groupMessageCtx,
{},
makeReplyConfig(home) as OpenClawConfig,
);
const text = Array.isArray(res) ? res[0]?.text : res?.text;
expect(text).toBe("ok");
expect(runEmbeddedPiAgentMock).toHaveBeenCalledOnce();
const prompt =
(runEmbeddedPiAgentMock.mock.calls[0]?.[0] as { prompt?: string } | undefined)?.prompt ??
"";
expect(prompt).toContain("Chat history since last reply (untrusted, for context):");
expect(prompt).toContain('"sender": "Peter"');
expect(prompt).toContain('"body": "hello"');
expect(prompt).toContain("status please");
expect(prompt).not.toContain("/think:high");
});
});
});