-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.test.ts
More file actions
73 lines (65 loc) · 2.25 KB
/
index.test.ts
File metadata and controls
73 lines (65 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { describe, expect, it, vi } from "vitest";
const controllerState = vi.hoisted(() => ({
createService: vi.fn(() => ({ start: vi.fn(), stop: vi.fn() })),
handleConversationBindingResolved: vi.fn(),
handleInboundClaim: vi.fn(),
handleTelegramInteractive: vi.fn(),
handleDiscordInteractive: vi.fn(),
handleCommand: vi.fn(),
}));
vi.mock("./src/controller.js", () => ({
CodexPluginController: class {
createService = controllerState.createService;
handleConversationBindingResolved = controllerState.handleConversationBindingResolved;
handleInboundClaim = controllerState.handleInboundClaim;
handleTelegramInteractive = controllerState.handleTelegramInteractive;
handleDiscordInteractive = controllerState.handleDiscordInteractive;
handleCommand = controllerState.handleCommand;
},
}));
const { default: plugin } = await import("./index.js");
describe("plugin registration", () => {
it("loads without the binding resolved hook on older OpenClaw cores", () => {
const api = {
registerService: vi.fn(),
registerInteractiveHandler: vi.fn(),
registerCommand: vi.fn(),
on: vi.fn(),
};
expect(() => plugin.register(api as never)).not.toThrow();
expect(api.registerService).toHaveBeenCalledTimes(1);
expect(api.on).toHaveBeenCalledWith("inbound_claim", expect.any(Function));
expect(api.registerInteractiveHandler).toHaveBeenCalledTimes(2);
expect(api.registerCommand).toHaveBeenCalled();
expect(api.registerCommand.mock.calls.map(([params]) => params.name)).toEqual([
"cas_resume",
"cas_detach",
"cas_status",
"cas_stop",
"cas_steer",
"cas_plan",
"cas_review",
"cas_compact",
"cas_skills",
"cas_experimental",
"cas_mcp",
"cas_fast",
"cas_model",
"cas_permissions",
"cas_init",
"cas_diff",
"cas_rename",
]);
});
it("registers the binding resolved hook when available", () => {
const api = {
registerService: vi.fn(),
registerInteractiveHandler: vi.fn(),
registerCommand: vi.fn(),
on: vi.fn(),
onConversationBindingResolved: vi.fn(),
};
plugin.register(api as never);
expect(api.onConversationBindingResolved).toHaveBeenCalledTimes(1);
});
});