mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-19 15:14:47 +00:00
test: tighten tools effective assertions
This commit is contained in:
@@ -60,6 +60,15 @@ const runtimeMocks = vi.hoisted(() => ({
|
||||
vi.mock("./tools-effective.runtime.js", () => runtimeMocks);
|
||||
|
||||
type RespondCall = [boolean, unknown?, { code: number; message: string }?];
|
||||
type ToolsEffectivePayload = {
|
||||
agentId?: string;
|
||||
profile?: string;
|
||||
groups?: Array<{
|
||||
id?: string;
|
||||
source?: string;
|
||||
tools?: Array<{ id?: string; source?: string }>;
|
||||
}>;
|
||||
};
|
||||
|
||||
function createInvokeParams(params: Record<string, unknown>) {
|
||||
const respond = vi.fn();
|
||||
@@ -77,6 +86,13 @@ function createInvokeParams(params: Record<string, unknown>) {
|
||||
};
|
||||
}
|
||||
|
||||
function resolveEffectiveToolInventoryArg(callIndex = 0): Record<string, unknown> | undefined {
|
||||
const calls = runtimeMocks.resolveEffectiveToolInventory.mock.calls as unknown as Array<
|
||||
[Record<string, unknown>]
|
||||
>;
|
||||
return calls[callIndex]?.[0];
|
||||
}
|
||||
|
||||
describe("tools.effective handler", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -146,32 +162,25 @@ describe("tools.effective handler", () => {
|
||||
await invoke();
|
||||
const call = respond.mock.calls[0] as RespondCall | undefined;
|
||||
expect(call?.[0]).toBe(true);
|
||||
expect(call?.[1]).toMatchObject({
|
||||
agentId: "main",
|
||||
profile: "coding",
|
||||
groups: [
|
||||
{
|
||||
id: "core",
|
||||
source: "core",
|
||||
tools: [{ id: "exec", source: "core" }],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(runtimeMocks.resolveEffectiveToolInventory).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
senderIsOwner: false,
|
||||
currentChannelId: "channel-1",
|
||||
currentThreadTs: "thread-2",
|
||||
accountId: "acct-1",
|
||||
groupId: "group-4",
|
||||
groupChannel: "#ops",
|
||||
groupSpace: "workspace-5",
|
||||
replyToMode: "first",
|
||||
messageProvider: "telegram",
|
||||
modelProvider: "openai",
|
||||
modelId: "gpt-4.1",
|
||||
}),
|
||||
);
|
||||
const payload = call?.[1] as ToolsEffectivePayload | undefined;
|
||||
expect(payload?.agentId).toBe("main");
|
||||
expect(payload?.profile).toBe("coding");
|
||||
expect(payload?.groups?.[0]?.id).toBe("core");
|
||||
expect(payload?.groups?.[0]?.source).toBe("core");
|
||||
expect(payload?.groups?.[0]?.tools?.[0]?.id).toBe("exec");
|
||||
expect(payload?.groups?.[0]?.tools?.[0]?.source).toBe("core");
|
||||
const inventoryParams = resolveEffectiveToolInventoryArg();
|
||||
expect(inventoryParams?.senderIsOwner).toBe(false);
|
||||
expect(inventoryParams?.currentChannelId).toBe("channel-1");
|
||||
expect(inventoryParams?.currentThreadTs).toBe("thread-2");
|
||||
expect(inventoryParams?.accountId).toBe("acct-1");
|
||||
expect(inventoryParams?.groupId).toBe("group-4");
|
||||
expect(inventoryParams?.groupChannel).toBe("#ops");
|
||||
expect(inventoryParams?.groupSpace).toBe("workspace-5");
|
||||
expect(inventoryParams?.replyToMode).toBe("first");
|
||||
expect(inventoryParams?.messageProvider).toBe("telegram");
|
||||
expect(inventoryParams?.modelProvider).toBe("openai");
|
||||
expect(inventoryParams?.modelId).toBe("gpt-4.1");
|
||||
});
|
||||
|
||||
it("serves repeated requests from the fresh inventory cache", async () => {
|
||||
@@ -306,11 +315,7 @@ describe("tools.effective handler", () => {
|
||||
const { respond, invoke } = createInvokeParams({ sessionKey: "main:abc" });
|
||||
await invoke();
|
||||
|
||||
expect(runtimeMocks.resolveEffectiveToolInventory).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
currentThreadTs: "42",
|
||||
}),
|
||||
);
|
||||
expect(resolveEffectiveToolInventoryArg()?.currentThreadTs).toBe("42");
|
||||
expect((respond.mock.calls[0] as RespondCall | undefined)?.[0]).toBe(true);
|
||||
});
|
||||
|
||||
@@ -326,9 +331,7 @@ describe("tools.effective handler", () => {
|
||||
req: { type: "req", id: "req-1", method: "tools.effective" },
|
||||
isWebchatConnect: () => false,
|
||||
});
|
||||
expect(runtimeMocks.resolveEffectiveToolInventory).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ senderIsOwner: true }),
|
||||
);
|
||||
expect(resolveEffectiveToolInventoryArg()?.senderIsOwner).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects agent ids that do not match the session agent", async () => {
|
||||
|
||||
Reference in New Issue
Block a user