mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 22:54:31 +00:00
refactor(test): table telegram heartbeat account cases
This commit is contained in:
@@ -461,16 +461,20 @@ describe("resolveHeartbeatIntervalMs", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes through accountId for telegram heartbeats", async () => {
|
async function expectTelegramHeartbeatAccountId(params: {
|
||||||
|
heartbeat: Record<string, unknown>;
|
||||||
|
telegram: Record<string, unknown>;
|
||||||
|
expectedAccountId: string | undefined;
|
||||||
|
}): Promise<void> {
|
||||||
await withTempTelegramHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
|
await withTempTelegramHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
|
||||||
const cfg: OpenClawConfig = {
|
const cfg: OpenClawConfig = {
|
||||||
agents: {
|
agents: {
|
||||||
defaults: {
|
defaults: {
|
||||||
workspace: tmpDir,
|
workspace: tmpDir,
|
||||||
heartbeat: { every: "5m", target: "telegram" },
|
heartbeat: params.heartbeat as never,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
channels: { telegram: { botToken: "test-bot-token-123" } },
|
channels: { telegram: params.telegram as never },
|
||||||
session: { store: storePath },
|
session: { store: storePath },
|
||||||
};
|
};
|
||||||
const sessionKey = resolveMainSessionKey(cfg);
|
const sessionKey = resolveMainSessionKey(cfg);
|
||||||
@@ -500,108 +504,39 @@ describe("resolveHeartbeatIntervalMs", () => {
|
|||||||
expect(sendTelegram).toHaveBeenCalledWith(
|
expect(sendTelegram).toHaveBeenCalledWith(
|
||||||
"123456",
|
"123456",
|
||||||
"Hello from heartbeat",
|
"Hello from heartbeat",
|
||||||
expect.objectContaining({ accountId: undefined, verbose: false }),
|
expect.objectContaining({ accountId: params.expectedAccountId, verbose: false }),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
it("uses explicit heartbeat accountId for telegram delivery", async () => {
|
it.each([
|
||||||
await withTempTelegramHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
|
{
|
||||||
const cfg: OpenClawConfig = {
|
title: "passes through accountId for telegram heartbeats",
|
||||||
agents: {
|
heartbeat: { every: "5m", target: "telegram" },
|
||||||
defaults: {
|
telegram: { botToken: "test-bot-token-123" },
|
||||||
workspace: tmpDir,
|
expectedAccountId: undefined,
|
||||||
heartbeat: { every: "5m", target: "telegram", accountId: "work" },
|
},
|
||||||
},
|
{
|
||||||
|
title: "does not pre-resolve telegram accountId (allows config-only account tokens)",
|
||||||
|
heartbeat: { every: "5m", target: "telegram" },
|
||||||
|
telegram: {
|
||||||
|
accounts: {
|
||||||
|
work: { botToken: "test-bot-token-123" },
|
||||||
},
|
},
|
||||||
channels: {
|
},
|
||||||
telegram: {
|
expectedAccountId: undefined,
|
||||||
accounts: {
|
},
|
||||||
work: { botToken: "test-bot-token-123" },
|
{
|
||||||
},
|
title: "uses explicit heartbeat accountId for telegram delivery",
|
||||||
},
|
heartbeat: { every: "5m", target: "telegram", accountId: "work" },
|
||||||
|
telegram: {
|
||||||
|
accounts: {
|
||||||
|
work: { botToken: "test-bot-token-123" },
|
||||||
},
|
},
|
||||||
session: { store: storePath },
|
},
|
||||||
};
|
expectedAccountId: "work",
|
||||||
const sessionKey = resolveMainSessionKey(cfg);
|
},
|
||||||
|
])("$title", async ({ heartbeat, telegram, expectedAccountId }) => {
|
||||||
await seedSessionStore(storePath, sessionKey, {
|
await expectTelegramHeartbeatAccountId({ heartbeat, telegram, expectedAccountId });
|
||||||
lastChannel: "telegram",
|
|
||||||
lastProvider: "telegram",
|
|
||||||
lastTo: "123456",
|
|
||||||
});
|
|
||||||
|
|
||||||
replySpy.mockResolvedValue({ text: "Hello from heartbeat" });
|
|
||||||
const sendTelegram = vi.fn().mockResolvedValue({
|
|
||||||
messageId: "m1",
|
|
||||||
chatId: "123456",
|
|
||||||
});
|
|
||||||
|
|
||||||
await runHeartbeatOnce({
|
|
||||||
cfg,
|
|
||||||
deps: {
|
|
||||||
sendTelegram,
|
|
||||||
getQueueSize: () => 0,
|
|
||||||
nowMs: () => 0,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(sendTelegram).toHaveBeenCalledTimes(1);
|
|
||||||
expect(sendTelegram).toHaveBeenCalledWith(
|
|
||||||
"123456",
|
|
||||||
"Hello from heartbeat",
|
|
||||||
expect.objectContaining({ accountId: "work", verbose: false }),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not pre-resolve telegram accountId (allows config-only account tokens)", async () => {
|
|
||||||
await withTempTelegramHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
|
|
||||||
const cfg: OpenClawConfig = {
|
|
||||||
agents: {
|
|
||||||
defaults: {
|
|
||||||
workspace: tmpDir,
|
|
||||||
heartbeat: { every: "5m", target: "telegram" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
channels: {
|
|
||||||
telegram: {
|
|
||||||
accounts: {
|
|
||||||
work: { botToken: "test-bot-token-123" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
session: { store: storePath },
|
|
||||||
};
|
|
||||||
const sessionKey = resolveMainSessionKey(cfg);
|
|
||||||
|
|
||||||
await seedSessionStore(storePath, sessionKey, {
|
|
||||||
lastChannel: "telegram",
|
|
||||||
lastProvider: "telegram",
|
|
||||||
lastTo: "123456",
|
|
||||||
});
|
|
||||||
|
|
||||||
replySpy.mockResolvedValue({ text: "Hello from heartbeat" });
|
|
||||||
const sendTelegram = vi.fn().mockResolvedValue({
|
|
||||||
messageId: "m1",
|
|
||||||
chatId: "123456",
|
|
||||||
});
|
|
||||||
|
|
||||||
await runHeartbeatOnce({
|
|
||||||
cfg,
|
|
||||||
deps: {
|
|
||||||
sendTelegram,
|
|
||||||
getQueueSize: () => 0,
|
|
||||||
nowMs: () => 0,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(sendTelegram).toHaveBeenCalledTimes(1);
|
|
||||||
expect(sendTelegram).toHaveBeenCalledWith(
|
|
||||||
"123456",
|
|
||||||
"Hello from heartbeat",
|
|
||||||
expect.objectContaining({ accountId: undefined, verbose: false }),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user