2026-03-01 20:51:45 -06:00
|
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
|
|
2026-03-02 04:35:40 +00:00
|
|
|
const { resolvePluginToolsMock } = vi.hoisted(() => ({
|
|
|
|
|
resolvePluginToolsMock: vi.fn((params?: unknown) => {
|
|
|
|
|
void params;
|
|
|
|
|
return [];
|
|
|
|
|
}),
|
|
|
|
|
}));
|
2026-03-01 20:51:45 -06:00
|
|
|
|
|
|
|
|
vi.mock("../plugins/tools.js", () => ({
|
2026-03-02 12:22:59 +08:00
|
|
|
resolvePluginTools: resolvePluginToolsMock,
|
2026-03-01 20:51:45 -06:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
import { createOpenClawTools } from "./openclaw-tools.js";
|
|
|
|
|
|
|
|
|
|
describe("createOpenClawTools plugin context", () => {
|
|
|
|
|
it("forwards trusted requester sender identity to plugin tool context", () => {
|
|
|
|
|
createOpenClawTools({
|
|
|
|
|
config: {} as never,
|
|
|
|
|
requesterSenderId: "trusted-sender",
|
|
|
|
|
senderIsOwner: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(resolvePluginToolsMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
context: expect.objectContaining({
|
|
|
|
|
requesterSenderId: "trusted-sender",
|
|
|
|
|
senderIsOwner: true,
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-03-02 15:11:51 -08:00
|
|
|
|
|
|
|
|
it("forwards ephemeral sessionId to plugin tool context", () => {
|
|
|
|
|
createOpenClawTools({
|
|
|
|
|
config: {} as never,
|
|
|
|
|
agentSessionKey: "agent:main:telegram:direct:12345",
|
|
|
|
|
sessionId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(resolvePluginToolsMock).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
context: expect.objectContaining({
|
|
|
|
|
sessionKey: "agent:main:telegram:direct:12345",
|
|
|
|
|
sessionId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
2026-03-01 20:51:45 -06:00
|
|
|
});
|