test: guard message tool mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 08:37:12 +01:00
parent 0fbbba0c6f
commit 6812215d4b
+25 -14
View File
@@ -103,6 +103,24 @@ const mocks = vi.hoisted(() => ({
),
}));
type RunMessageActionInput = {
agentId?: string;
cfg?: unknown;
params?: Record<string, unknown>;
requesterSenderId?: string;
sandboxRoot?: string;
senderIsOwner?: boolean;
sessionKey?: string;
toolContext?: {
currentThreadTs?: string;
replyToMode?: string;
};
};
function firstRunMessageActionInput(): RunMessageActionInput | undefined {
return mocks.runMessageAction.mock.calls.at(0)?.[0] as RunMessageActionInput | undefined;
}
const openClawToolsFactoryMocks = vi.hoisted(() => {
const tool = (name: string) => ({
name,
@@ -330,14 +348,7 @@ async function executeSend(params: {
action: "send",
...params.action,
});
return mocks.runMessageAction.mock.calls[0]?.[0] as
| {
params?: Record<string, unknown>;
sandboxRoot?: string;
requesterSenderId?: string;
senderIsOwner?: boolean;
}
| undefined;
return firstRunMessageActionInput();
}
describe("message tool secret scoping", () => {
@@ -474,7 +485,7 @@ describe("message tool secret scoping", () => {
expect(secretResolveCall.allowedPaths).toEqual(
new Set(["channels.discord.token", "channels.discord.accounts.ops.token"]),
);
expect(mocks.runMessageAction.mock.calls[0]?.[0]?.cfg).toBe(resolvedConfig);
expect(firstRunMessageActionInput()?.cfg).toBe(resolvedConfig);
});
});
@@ -494,7 +505,7 @@ describe("message tool agent routing", () => {
message: "hi",
});
const call = mocks.runMessageAction.mock.calls[0]?.[0];
const call = firstRunMessageActionInput();
expect(call?.agentId).toBe("alpha");
expect(call?.sessionKey).toBe("agent:alpha:main");
});
@@ -517,7 +528,7 @@ describe("message tool agent routing", () => {
message: "stay in thread",
});
const call = mocks.runMessageAction.mock.calls[0]?.[0];
const call = firstRunMessageActionInput();
expect(call?.toolContext?.currentThreadTs).toBe("111.222");
expect(call?.toolContext?.replyToMode).toBe("all");
});
@@ -541,7 +552,7 @@ describe("message tool agent routing", () => {
message: "send at channel level",
});
const call = mocks.runMessageAction.mock.calls[0]?.[0];
const call = firstRunMessageActionInput();
expect(call?.toolContext?.currentThreadTs).toBe("111.222");
expect(call?.toolContext?.replyToMode).toBe("off");
});
@@ -567,7 +578,7 @@ describe("message tool agent routing", () => {
message: "stay in thread",
});
const call = mocks.runMessageAction.mock.calls[0]?.[0];
const call = firstRunMessageActionInput();
expect(call?.toolContext?.currentThreadTs).toBe("111.222");
expect(call?.toolContext?.replyToMode).toBe("all");
});
@@ -615,7 +626,7 @@ describe("message tool explicit target guard", () => {
filePath: "/tmp/report.png",
});
const call = mocks.runMessageAction.mock.calls[0]?.[0];
const call = firstRunMessageActionInput();
expect(call?.params?.target).toBe("channel:C999");
});
});