refactor(runtime): split runtime builders and stabilize cron tool seam

This commit is contained in:
Peter Steinberger
2026-02-19 16:09:50 +01:00
parent e1e91bdb4a
commit cc9be84b9c
4 changed files with 274 additions and 207 deletions

View File

@@ -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");
});
});