mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
fix: prefer target entry for plugin commands
This commit is contained in:
@@ -72,4 +72,41 @@ describe("handlePluginCommand", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("prefers the target session entry from sessionStore for plugin command metadata", async () => {
|
||||
matchPluginCommandMock.mockReturnValue({
|
||||
command: { name: "card" },
|
||||
args: "",
|
||||
});
|
||||
executePluginCommandMock.mockResolvedValue({ text: "from plugin" });
|
||||
|
||||
const params = buildPluginParams(
|
||||
"/card",
|
||||
{
|
||||
commands: { text: true },
|
||||
channels: { whatsapp: { allowFrom: ["*"] } },
|
||||
} as OpenClawConfig,
|
||||
);
|
||||
params.sessionEntry = {
|
||||
sessionId: "wrapper-session",
|
||||
sessionFile: "/tmp/wrapper-session.jsonl",
|
||||
updatedAt: Date.now(),
|
||||
} as HandleCommandsParams["sessionEntry"];
|
||||
params.sessionStore = {
|
||||
[params.sessionKey]: {
|
||||
sessionId: "target-session",
|
||||
sessionFile: "/tmp/target-session.jsonl",
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
};
|
||||
|
||||
await handlePluginCommand(params, true);
|
||||
|
||||
expect(executePluginCommandMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
sessionId: "target-session",
|
||||
sessionFile: "/tmp/target-session.jsonl",
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,6 +19,7 @@ export const handlePluginCommand: CommandHandler = async (
|
||||
allowTextCommands,
|
||||
): Promise<CommandHandlerResult | null> => {
|
||||
const { command, cfg } = params;
|
||||
const targetSessionEntry = params.sessionStore?.[params.sessionKey] ?? params.sessionEntry;
|
||||
|
||||
if (!allowTextCommands) {
|
||||
return null;
|
||||
@@ -40,8 +41,8 @@ export const handlePluginCommand: CommandHandler = async (
|
||||
isAuthorizedSender: command.isAuthorizedSender,
|
||||
gatewayClientScopes: params.ctx.GatewayClientScopes,
|
||||
sessionKey: params.sessionKey,
|
||||
sessionId: params.sessionEntry?.sessionId,
|
||||
sessionFile: params.sessionEntry?.sessionFile,
|
||||
sessionId: targetSessionEntry?.sessionId,
|
||||
sessionFile: targetSessionEntry?.sessionFile,
|
||||
commandBody: command.commandBodyNormalized,
|
||||
config: cfg,
|
||||
from: command.from,
|
||||
|
||||
Reference in New Issue
Block a user