-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.test.ts
More file actions
80 lines (69 loc) · 2.28 KB
/
index.test.ts
File metadata and controls
80 lines (69 loc) · 2.28 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
74
75
76
77
78
79
80
import { afterEach, describe, expect, it, jest } from "bun:test"
import { BmClient } from "./bm-client.ts"
import plugin from "./index.ts"
describe("plugin service lifecycle", () => {
afterEach(() => {
jest.restoreAllMocks()
})
it("starts MCP client, ensures project path, and stops cleanly", async () => {
const startSpy = jest
.spyOn(BmClient.prototype, "start")
.mockResolvedValue(undefined)
const ensureProjectSpy = jest
.spyOn(BmClient.prototype, "ensureProject")
.mockResolvedValue(undefined)
const readNoteSpy = jest
.spyOn(BmClient.prototype, "readNote")
.mockRejectedValue(new Error("Entity not found"))
const writeNoteSpy = jest
.spyOn(BmClient.prototype, "writeNote")
.mockResolvedValue(undefined as any)
const stopSpy = jest
.spyOn(BmClient.prototype, "stop")
.mockResolvedValue(undefined)
const services: Array<{
id: string
start: (ctx: { workspaceDir?: string }) => Promise<void>
stop: () => Promise<void>
}> = []
const api = {
pluginConfig: {
project: "test-project",
projectPath: "memory/",
},
logger: {
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
debug: jest.fn(),
},
registerTool: jest.fn(),
registerCommand: jest.fn(),
registerCli: jest.fn(),
registerContextEngine: jest.fn(),
registerService: jest.fn((service: any) => {
services.push(service)
}),
on: jest.fn(),
}
plugin.register(api as any)
expect(services).toHaveLength(1)
expect(api.registerContextEngine).toHaveBeenCalledWith(
"openclaw-basic-memory",
expect.any(Function),
)
expect(api.on).not.toHaveBeenCalled()
await services[0].start({ workspaceDir: "/tmp/workspace" })
expect(startSpy).toHaveBeenCalledWith({ cwd: "/tmp/workspace" })
expect(ensureProjectSpy).toHaveBeenCalledWith("/tmp/workspace/memory")
// Schema seed: readNote throws "not found" → writeNote called
expect(readNoteSpy).toHaveBeenCalledWith("schema/Task")
expect(writeNoteSpy).toHaveBeenCalledWith(
"Task",
expect.stringContaining("type: schema"),
"schema",
)
await services[0].stop()
expect(stopSpy).toHaveBeenCalledTimes(1)
})
})