mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 12:51:24 +00:00
perf(test): collapse isolated cron heartbeat delivery cases
This commit is contained in:
@@ -115,7 +115,7 @@ describe("runCronIsolatedAgentTurn", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("delivers when response has HEARTBEAT_OK but includes media", async () => {
|
it("handles media heartbeat delivery and announce cleanup modes", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
const storePath = await writeSessionStore(home);
|
const storePath = await writeSessionStore(home);
|
||||||
const deps: CliDeps = {
|
const deps: CliDeps = {
|
||||||
@@ -128,6 +128,7 @@ describe("runCronIsolatedAgentTurn", () => {
|
|||||||
sendMessageSignal: vi.fn(),
|
sendMessageSignal: vi.fn(),
|
||||||
sendMessageIMessage: vi.fn(),
|
sendMessageIMessage: vi.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Media should still be delivered even if text is just HEARTBEAT_OK.
|
// Media should still be delivered even if text is just HEARTBEAT_OK.
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
||||||
payloads: [{ text: "HEARTBEAT_OK", mediaUrl: "https://example.com/img.png" }],
|
payloads: [{ text: "HEARTBEAT_OK", mediaUrl: "https://example.com/img.png" }],
|
||||||
@@ -137,7 +138,7 @@ describe("runCronIsolatedAgentTurn", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = await runCronIsolatedAgentTurn({
|
const mediaRes = await runCronIsolatedAgentTurn({
|
||||||
cfg: makeCfg(home, storePath),
|
cfg: makeCfg(home, storePath),
|
||||||
deps,
|
deps,
|
||||||
job: {
|
job: {
|
||||||
@@ -152,25 +153,12 @@ describe("runCronIsolatedAgentTurn", () => {
|
|||||||
lane: "cron",
|
lane: "cron",
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.status).toBe("ok");
|
expect(mediaRes.status).toBe("ok");
|
||||||
expect(deps.sendMessageTelegram).toHaveBeenCalled();
|
expect(deps.sendMessageTelegram).toHaveBeenCalled();
|
||||||
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
|
expect(runSubagentAnnounceFlow).not.toHaveBeenCalled();
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("uses shared announce flow when heartbeat ack padding exceeds configured limit", async () => {
|
vi.mocked(runSubagentAnnounceFlow).mockClear();
|
||||||
await withTempHome(async (home) => {
|
vi.mocked(deps.sendMessageTelegram).mockClear();
|
||||||
const storePath = await writeSessionStore(home);
|
|
||||||
const deps: CliDeps = {
|
|
||||||
sendMessageWhatsApp: vi.fn(),
|
|
||||||
sendMessageTelegram: vi.fn().mockResolvedValue({
|
|
||||||
messageId: "t1",
|
|
||||||
chatId: "123",
|
|
||||||
}),
|
|
||||||
sendMessageDiscord: vi.fn(),
|
|
||||||
sendMessageSignal: vi.fn(),
|
|
||||||
sendMessageIMessage: vi.fn(),
|
|
||||||
};
|
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
||||||
payloads: [{ text: "HEARTBEAT_OK 🦞" }],
|
payloads: [{ text: "HEARTBEAT_OK 🦞" }],
|
||||||
meta: {
|
meta: {
|
||||||
@@ -188,7 +176,7 @@ describe("runCronIsolatedAgentTurn", () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await runCronIsolatedAgentTurn({
|
const keepRes = await runCronIsolatedAgentTurn({
|
||||||
cfg,
|
cfg,
|
||||||
deps,
|
deps,
|
||||||
job: {
|
job: {
|
||||||
@@ -203,47 +191,17 @@ describe("runCronIsolatedAgentTurn", () => {
|
|||||||
lane: "cron",
|
lane: "cron",
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.status).toBe("ok");
|
expect(keepRes.status).toBe("ok");
|
||||||
expect(runSubagentAnnounceFlow).toHaveBeenCalledTimes(1);
|
expect(runSubagentAnnounceFlow).toHaveBeenCalledTimes(1);
|
||||||
const announceArgs = vi.mocked(runSubagentAnnounceFlow).mock.calls[0]?.[0] as
|
const keepArgs = vi.mocked(runSubagentAnnounceFlow).mock.calls[0]?.[0] as
|
||||||
| { cleanup?: "keep" | "delete" }
|
| { cleanup?: "keep" | "delete" }
|
||||||
| undefined;
|
| undefined;
|
||||||
expect(announceArgs?.cleanup).toBe("keep");
|
expect(keepArgs?.cleanup).toBe("keep");
|
||||||
expect(deps.sendMessageTelegram).not.toHaveBeenCalled();
|
expect(deps.sendMessageTelegram).not.toHaveBeenCalled();
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("passes cleanup=delete to announce flow when job.deleteAfterRun is true", async () => {
|
vi.mocked(runSubagentAnnounceFlow).mockClear();
|
||||||
await withTempHome(async (home) => {
|
|
||||||
const storePath = await writeSessionStore(home);
|
|
||||||
const deps: CliDeps = {
|
|
||||||
sendMessageWhatsApp: vi.fn(),
|
|
||||||
sendMessageTelegram: vi.fn().mockResolvedValue({
|
|
||||||
messageId: "t1",
|
|
||||||
chatId: "123",
|
|
||||||
}),
|
|
||||||
sendMessageDiscord: vi.fn(),
|
|
||||||
sendMessageSignal: vi.fn(),
|
|
||||||
sendMessageIMessage: vi.fn(),
|
|
||||||
};
|
|
||||||
vi.mocked(runEmbeddedPiAgent).mockResolvedValue({
|
|
||||||
payloads: [{ text: "HEARTBEAT_OK 🦞" }],
|
|
||||||
meta: {
|
|
||||||
durationMs: 5,
|
|
||||||
agentMeta: { sessionId: "s", provider: "p", model: "m" },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const cfg = makeCfg(home, storePath);
|
const deleteRes = await runCronIsolatedAgentTurn({
|
||||||
cfg.agents = {
|
|
||||||
...cfg.agents,
|
|
||||||
defaults: {
|
|
||||||
...cfg.agents?.defaults,
|
|
||||||
heartbeat: { ackMaxChars: 0 },
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const res = await runCronIsolatedAgentTurn({
|
|
||||||
cfg,
|
cfg,
|
||||||
deps,
|
deps,
|
||||||
job: {
|
job: {
|
||||||
@@ -259,12 +217,12 @@ describe("runCronIsolatedAgentTurn", () => {
|
|||||||
lane: "cron",
|
lane: "cron",
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.status).toBe("ok");
|
expect(deleteRes.status).toBe("ok");
|
||||||
expect(runSubagentAnnounceFlow).toHaveBeenCalledTimes(1);
|
expect(runSubagentAnnounceFlow).toHaveBeenCalledTimes(1);
|
||||||
const announceArgs = vi.mocked(runSubagentAnnounceFlow).mock.calls[0]?.[0] as
|
const deleteArgs = vi.mocked(runSubagentAnnounceFlow).mock.calls[0]?.[0] as
|
||||||
| { cleanup?: "keep" | "delete" }
|
| { cleanup?: "keep" | "delete" }
|
||||||
| undefined;
|
| undefined;
|
||||||
expect(announceArgs?.cleanup).toBe("delete");
|
expect(deleteArgs?.cleanup).toBe("delete");
|
||||||
expect(deps.sendMessageTelegram).not.toHaveBeenCalled();
|
expect(deps.sendMessageTelegram).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user