mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 05:13:43 +00:00
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import "./isolated-agent.mocks.js";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { runSubagentAnnounceFlow } from "../agents/subagent-announce.js";
|
|
import {
|
|
createCliDeps,
|
|
mockAgentPayloads,
|
|
runTelegramAnnounceTurn,
|
|
} from "./isolated-agent.delivery.test-helpers.js";
|
|
import { withTempCronHome, writeSessionStore } from "./isolated-agent.test-harness.js";
|
|
import { setupIsolatedAgentTurnMocks } from "./isolated-agent.test-setup.js";
|
|
|
|
describe("runCronIsolatedAgentTurn forum topic delivery", () => {
|
|
beforeEach(() => {
|
|
setupIsolatedAgentTurnMocks();
|
|
});
|
|
|
|
it("uses direct delivery for text-only forum topic targets", async () => {
|
|
await withTempCronHome(async (home) => {
|
|
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
|
|
const deps = createCliDeps();
|
|
mockAgentPayloads([{ text: "forum message" }]);
|
|
|
|
const res = await runTelegramAnnounceTurn({
|
|
home,
|
|
storePath,
|
|
deps,
|
|
delivery: { mode: "announce", channel: "telegram", to: "123:topic:42" },
|
|
});
|
|
|
|
expect(res.status).toBe("ok");
|
|
expect(res.delivered).toBe(true);
|
|
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
|
|
expect(deps.sendMessageTelegram).toHaveBeenCalledTimes(1);
|
|
expect(deps.sendMessageTelegram).toHaveBeenCalledWith(
|
|
"123",
|
|
"forum message",
|
|
expect.objectContaining({
|
|
messageThreadId: 42,
|
|
}),
|
|
);
|
|
});
|
|
});
|
|
|
|
it("keeps text-only non-threaded targets on announce flow", async () => {
|
|
await withTempCronHome(async (home) => {
|
|
const storePath = await writeSessionStore(home, { lastProvider: "webchat", lastTo: "" });
|
|
const deps = createCliDeps();
|
|
mockAgentPayloads([{ text: "plain message" }]);
|
|
|
|
const res = await runTelegramAnnounceTurn({
|
|
home,
|
|
storePath,
|
|
deps,
|
|
delivery: { mode: "announce", channel: "telegram", to: "123" },
|
|
});
|
|
|
|
expect(res.status).toBe("ok");
|
|
expect(runSubagentAnnounceFlow).toHaveBeenCalledTimes(1);
|
|
const announceArgs = vi.mocked(runSubagentAnnounceFlow).mock.calls[0]?.[0] as
|
|
| { expectsCompletionMessage?: boolean }
|
|
| undefined;
|
|
expect(announceArgs?.expectsCompletionMessage).toBe(true);
|
|
expect(deps.sendMessageTelegram).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|