mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 03:52:42 +00:00
Agent: guard reminder promises behind cron scheduling
This commit is contained in:
committed by
Vignesh
parent
0cff8bc4e6
commit
5a26d1c622
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { handleToolExecutionStart } from "./pi-embedded-subscribe.handlers.tools.js";
|
||||
import {
|
||||
handleToolExecutionEnd,
|
||||
handleToolExecutionStart,
|
||||
} from "./pi-embedded-subscribe.handlers.tools.js";
|
||||
|
||||
function createTestContext() {
|
||||
const onBlockReplyFlush = vi.fn();
|
||||
@@ -25,6 +28,8 @@ function createTestContext() {
|
||||
messagingToolSentTexts: [],
|
||||
messagingToolSentTextsNormalized: [],
|
||||
messagingToolSentTargets: [],
|
||||
successfulCronAdds: 0,
|
||||
toolMetas: [],
|
||||
},
|
||||
shouldEmitToolResult: () => false,
|
||||
emitToolSummary: vi.fn(),
|
||||
@@ -69,3 +74,57 @@ describe("handleToolExecutionStart read path checks", () => {
|
||||
expect(String(warn.mock.calls[0]?.[0] ?? "")).toContain("read tool called without path");
|
||||
});
|
||||
});
|
||||
|
||||
describe("handleToolExecutionEnd cron.add commitment tracking", () => {
|
||||
it("increments successfulCronAdds when cron add succeeds", async () => {
|
||||
const { ctx } = createTestContext();
|
||||
await handleToolExecutionStart(
|
||||
ctx as never,
|
||||
{
|
||||
type: "tool_execution_start",
|
||||
toolName: "cron",
|
||||
toolCallId: "tool-cron-1",
|
||||
args: { action: "add", job: { name: "reminder" } },
|
||||
} as never,
|
||||
);
|
||||
|
||||
await handleToolExecutionEnd(
|
||||
ctx as never,
|
||||
{
|
||||
type: "tool_execution_end",
|
||||
toolName: "cron",
|
||||
toolCallId: "tool-cron-1",
|
||||
isError: false,
|
||||
result: { details: { status: "ok" } },
|
||||
} as never,
|
||||
);
|
||||
|
||||
expect(ctx.state.successfulCronAdds).toBe(1);
|
||||
});
|
||||
|
||||
it("does not increment successfulCronAdds when cron add fails", async () => {
|
||||
const { ctx } = createTestContext();
|
||||
await handleToolExecutionStart(
|
||||
ctx as never,
|
||||
{
|
||||
type: "tool_execution_start",
|
||||
toolName: "cron",
|
||||
toolCallId: "tool-cron-2",
|
||||
args: { action: "add", job: { name: "reminder" } },
|
||||
} as never,
|
||||
);
|
||||
|
||||
await handleToolExecutionEnd(
|
||||
ctx as never,
|
||||
{
|
||||
type: "tool_execution_end",
|
||||
toolName: "cron",
|
||||
toolCallId: "tool-cron-2",
|
||||
isError: true,
|
||||
result: { details: { status: "error" } },
|
||||
} as never,
|
||||
);
|
||||
|
||||
expect(ctx.state.successfulCronAdds).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user