test: merge command hook cases
This commit is contained in:
parent
48a9aa152c
commit
060654e947
@ -1473,52 +1473,56 @@ describe("handleCommands identity", () => {
|
||||
});
|
||||
|
||||
describe("handleCommands hooks", () => {
|
||||
it("triggers hooks for /new with arguments", async () => {
|
||||
const cfg = {
|
||||
commands: { text: true },
|
||||
channels: { whatsapp: { allowFrom: ["*"] } },
|
||||
} as OpenClawConfig;
|
||||
const params = buildParams("/new take notes", cfg);
|
||||
const spy = vi.spyOn(internalHooks, "triggerInternalHook").mockResolvedValue();
|
||||
|
||||
await handleCommands(params);
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(expect.objectContaining({ type: "command", action: "new" }));
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it("triggers hooks for native /new routed to target sessions", async () => {
|
||||
const cfg = {
|
||||
commands: { text: true },
|
||||
channels: { telegram: { allowFrom: ["*"] } },
|
||||
} as OpenClawConfig;
|
||||
const params = buildParams("/new", cfg, {
|
||||
Provider: "telegram",
|
||||
Surface: "telegram",
|
||||
CommandSource: "native",
|
||||
CommandTargetSessionKey: "agent:main:telegram:direct:123",
|
||||
SessionKey: "telegram:slash:123",
|
||||
SenderId: "123",
|
||||
From: "telegram:123",
|
||||
To: "slash:123",
|
||||
CommandAuthorized: true,
|
||||
});
|
||||
params.sessionKey = "agent:main:telegram:direct:123";
|
||||
const spy = vi.spyOn(internalHooks, "triggerInternalHook").mockResolvedValue();
|
||||
|
||||
await handleCommands(params);
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
type: "command",
|
||||
action: "new",
|
||||
sessionKey: "agent:main:telegram:direct:123",
|
||||
context: expect.objectContaining({
|
||||
workspaceDir: testWorkspaceDir,
|
||||
it("triggers hooks for /new commands", async () => {
|
||||
const cases = [
|
||||
{
|
||||
name: "text command with arguments",
|
||||
params: buildParams("/new take notes", {
|
||||
commands: { text: true },
|
||||
channels: { whatsapp: { allowFrom: ["*"] } },
|
||||
} as OpenClawConfig),
|
||||
expectedCall: expect.objectContaining({ type: "command", action: "new" }),
|
||||
},
|
||||
{
|
||||
name: "native command routed to target session",
|
||||
params: (() => {
|
||||
const params = buildParams(
|
||||
"/new",
|
||||
{
|
||||
commands: { text: true },
|
||||
channels: { telegram: { allowFrom: ["*"] } },
|
||||
} as OpenClawConfig,
|
||||
{
|
||||
Provider: "telegram",
|
||||
Surface: "telegram",
|
||||
CommandSource: "native",
|
||||
CommandTargetSessionKey: "agent:main:telegram:direct:123",
|
||||
SessionKey: "telegram:slash:123",
|
||||
SenderId: "123",
|
||||
From: "telegram:123",
|
||||
To: "slash:123",
|
||||
CommandAuthorized: true,
|
||||
},
|
||||
);
|
||||
params.sessionKey = "agent:main:telegram:direct:123";
|
||||
return params;
|
||||
})(),
|
||||
expectedCall: expect.objectContaining({
|
||||
type: "command",
|
||||
action: "new",
|
||||
sessionKey: "agent:main:telegram:direct:123",
|
||||
context: expect.objectContaining({
|
||||
workspaceDir: testWorkspaceDir,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
spy.mockRestore();
|
||||
},
|
||||
] as const;
|
||||
for (const testCase of cases) {
|
||||
const spy = vi.spyOn(internalHooks, "triggerInternalHook").mockResolvedValue();
|
||||
await handleCommands(testCase.params);
|
||||
expect(spy, testCase.name).toHaveBeenCalledWith(testCase.expectedCall);
|
||||
spy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user