mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:08:28 +00:00
refactor(runtime): split runtime builders and stabilize cron tool seam
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { callGatewayMock } = vi.hoisted(() => ({
|
||||
callGatewayMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../../gateway/call.js", () => ({
|
||||
callGateway: (opts: unknown) => callGatewayMock(opts),
|
||||
const { callGatewayToolMock } = vi.hoisted(() => ({
|
||||
callGatewayToolMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../agent-scope.js", () => ({
|
||||
@@ -16,12 +12,15 @@ import { createCronTool } from "./cron-tool.js";
|
||||
|
||||
describe("cron tool flat-params", () => {
|
||||
beforeEach(() => {
|
||||
callGatewayMock.mockReset();
|
||||
callGatewayMock.mockResolvedValue({ ok: true });
|
||||
callGatewayToolMock.mockReset();
|
||||
callGatewayToolMock.mockResolvedValue({ ok: true });
|
||||
});
|
||||
|
||||
it("preserves explicit top-level sessionKey during flat-params recovery", async () => {
|
||||
const tool = createCronTool({ agentSessionKey: "agent:main:discord:channel:ops" });
|
||||
const tool = createCronTool(
|
||||
{ agentSessionKey: "agent:main:discord:channel:ops" },
|
||||
{ callGatewayTool: callGatewayToolMock },
|
||||
);
|
||||
await tool.execute("call-flat-session-key", {
|
||||
action: "add",
|
||||
sessionKey: "agent:main:telegram:group:-100123:topic:99",
|
||||
@@ -29,11 +28,12 @@ describe("cron tool flat-params", () => {
|
||||
message: "do stuff",
|
||||
});
|
||||
|
||||
const call = callGatewayMock.mock.calls[0]?.[0] as {
|
||||
method?: string;
|
||||
params?: { sessionKey?: string };
|
||||
};
|
||||
expect(call.method).toBe("cron.add");
|
||||
expect(call.params?.sessionKey).toBe("agent:main:telegram:group:-100123:topic:99");
|
||||
const [method, _gatewayOpts, params] = callGatewayToolMock.mock.calls[0] as [
|
||||
string,
|
||||
unknown,
|
||||
{ sessionKey?: string },
|
||||
];
|
||||
expect(method).toBe("cron.add");
|
||||
expect(params.sessionKey).toBe("agent:main:telegram:group:-100123:topic:99");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user