@becrafter/prompt-manager 0.1.17 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/env.example +1 -1
- package/package.json +19 -7
- package/packages/server/server.js +2 -1
- package/packages/server/services/TerminalService.js +247 -13
- package/packages/server/toolm/tool-sync.service.js +8 -0
- package/packages/server/utils/config.js +1 -1
- package/packages/web/css/{main.3b61356b384d2f11f47f.css → main.196f434e6a88cd448158.css} +10 -0
- package/packages/web/index.html +1 -1
- package/packages/web/{main.77c2c4b553ca3fac223b.js → main.b427a9e6f77a32a2f87f.js} +2 -2
- package/app/desktop/assets/app.1.png +0 -0
- package/app/desktop/assets/app.png +0 -0
- package/app/desktop/assets/icons/icon.icns +0 -0
- package/app/desktop/assets/icons/icon.ico +0 -0
- package/app/desktop/assets/icons/icon.png +0 -0
- package/app/desktop/assets/icons/tray.png +0 -0
- package/app/desktop/assets/templates/about.html +0 -147
- package/app/desktop/assets/tray.1.png +0 -0
- package/app/desktop/assets/tray.png +0 -0
- package/app/desktop/docs/ASSETS_PLANNING.md +0 -351
- package/app/desktop/docs/REFACTORING_SUMMARY.md +0 -205
- package/app/desktop/main.js +0 -340
- package/app/desktop/package-lock.json +0 -6912
- package/app/desktop/package.json +0 -119
- package/app/desktop/preload.js +0 -7
- package/app/desktop/src/core/error-handler.js +0 -108
- package/app/desktop/src/core/event-emitter.js +0 -84
- package/app/desktop/src/core/logger.js +0 -130
- package/app/desktop/src/core/state-manager.js +0 -125
- package/app/desktop/src/services/module-loader.js +0 -330
- package/app/desktop/src/services/runtime-manager.js +0 -398
- package/app/desktop/src/services/service-manager.js +0 -210
- package/app/desktop/src/services/update-manager.js +0 -267
- package/app/desktop/src/ui/about-dialog-manager.js +0 -208
- package/app/desktop/src/ui/admin-window-manager.js +0 -757
- package/app/desktop/src/ui/splash-manager.js +0 -253
- package/app/desktop/src/ui/tray-manager.js +0 -186
- package/app/desktop/src/utils/icon-manager.js +0 -133
- package/app/desktop/src/utils/path-utils.js +0 -58
- package/app/desktop/src/utils/resource-paths.js +0 -49
- package/app/desktop/src/utils/resource-sync.js +0 -260
- package/app/desktop/src/utils/runtime-sync.js +0 -241
- package/app/desktop/src/utils/self-check.js +0 -288
- package/app/desktop/src/utils/template-renderer.js +0 -284
- package/app/desktop/src/utils/version-utils.js +0 -59
- package/packages/server/.eslintrc.js +0 -70
- package/packages/server/.husky/pre-commit +0 -8
- package/packages/server/.husky/pre-push +0 -8
- package/packages/server/.prettierrc +0 -14
- package/packages/server/dev-server.js +0 -90
- package/packages/server/jsdoc.conf.json +0 -39
- package/packages/server/package.json +0 -85
- package/packages/server/playwright.config.js +0 -62
- package/packages/server/scripts/generate-docs.js +0 -300
- package/packages/server/tests/e2e/terminal-e2e.test.js +0 -315
- package/packages/server/tests/integration/terminal-websocket.test.js +0 -372
- package/packages/server/tests/integration/tools.test.js +0 -264
- package/packages/server/tests/setup.js +0 -45
- package/packages/server/tests/unit/TerminalService.test.js +0 -410
- package/packages/server/tests/unit/WebSocketService.test.js +0 -403
- package/packages/server/tests/unit/core.test.js +0 -94
- package/packages/server/typedoc.json +0 -52
- package/packages/server/vitest.config.js +0 -74
- /package/packages/web/{main.77c2c4b553ca3fac223b.js.LICENSE.txt → main.b427a9e6f77a32a2f87f.js.LICENSE.txt} +0 -0
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WebSocketService 单元测试
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
// Mock all modules before imports
|
|
8
|
-
vi.mock('ws', () => ({
|
|
9
|
-
WebSocketServer: vi.fn(),
|
|
10
|
-
WebSocket: vi.fn()
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
vi.mock('../../utils/logger.js', () => ({
|
|
14
|
-
logger: {
|
|
15
|
-
info: vi.fn(),
|
|
16
|
-
error: vi.fn(),
|
|
17
|
-
debug: vi.fn(),
|
|
18
|
-
warn: vi.fn()
|
|
19
|
-
}
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
vi.mock('../../services/TerminalService.js', () => ({
|
|
23
|
-
terminalService: {
|
|
24
|
-
createSession: vi.fn(),
|
|
25
|
-
getSession: vi.fn(),
|
|
26
|
-
removeSession: vi.fn()
|
|
27
|
-
}
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
// Now import the modules
|
|
31
|
-
import { WebSocketService, WebSocketConnection } from '../../services/WebSocketService.js';
|
|
32
|
-
import { terminalService } from '../../services/TerminalService.js';
|
|
33
|
-
import { WebSocketServer } from 'ws';
|
|
34
|
-
|
|
35
|
-
describe('WebSocketService', () => {
|
|
36
|
-
let webSocketService;
|
|
37
|
-
let mockWss;
|
|
38
|
-
let mockWs;
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
vi.clearAllMocks();
|
|
42
|
-
|
|
43
|
-
// Mock WebSocket Server
|
|
44
|
-
mockWss = {
|
|
45
|
-
on: vi.fn(),
|
|
46
|
-
close: vi.fn()
|
|
47
|
-
};
|
|
48
|
-
WebSocketServer.mockImplementation(() => mockWss);
|
|
49
|
-
|
|
50
|
-
// Mock WebSocket
|
|
51
|
-
mockWs = {
|
|
52
|
-
readyState: 1, // WebSocket.OPEN
|
|
53
|
-
OPEN: 1,
|
|
54
|
-
send: vi.fn(),
|
|
55
|
-
close: vi.fn(),
|
|
56
|
-
ping: vi.fn(),
|
|
57
|
-
on: vi.fn()
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// 创建服务实例
|
|
61
|
-
webSocketService = new WebSocketService({
|
|
62
|
-
port: 8081,
|
|
63
|
-
maxConnections: 5
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
afterEach(async () => {
|
|
68
|
-
if (webSocketService) {
|
|
69
|
-
// 清理连接以避免 close 方法错误
|
|
70
|
-
webSocketService.connections.clear();
|
|
71
|
-
try {
|
|
72
|
-
await webSocketService.stop();
|
|
73
|
-
} catch (error) {
|
|
74
|
-
// 忽略清理时的错误
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe('constructor', () => {
|
|
80
|
-
it('应该使用默认选项初始化', () => {
|
|
81
|
-
const service = new WebSocketService();
|
|
82
|
-
expect(service.options.port).toBe(8081);
|
|
83
|
-
expect(service.options.maxConnections).toBe(100);
|
|
84
|
-
expect(service.connections.size).toBe(0);
|
|
85
|
-
expect(service.isRunning).toBe(false);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('应该使用自定义选项初始化', () => {
|
|
89
|
-
const customOptions = {
|
|
90
|
-
port: 9090,
|
|
91
|
-
maxConnections: 50,
|
|
92
|
-
heartbeatInterval: 60000
|
|
93
|
-
};
|
|
94
|
-
const service = new WebSocketService(customOptions);
|
|
95
|
-
expect(service.options.port).toBe(9090);
|
|
96
|
-
expect(service.options.maxConnections).toBe(50);
|
|
97
|
-
expect(service.options.heartbeatInterval).toBe(60000);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('start', () => {
|
|
102
|
-
it('应该成功启动WebSocket服务', async () => {
|
|
103
|
-
// 模拟服务器启动成功
|
|
104
|
-
let listeningCallback;
|
|
105
|
-
mockWss.on.mockImplementation((event, callback) => {
|
|
106
|
-
if (event === 'listening') {
|
|
107
|
-
listeningCallback = callback;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const startPromise = webSocketService.start();
|
|
112
|
-
|
|
113
|
-
// 触发listening事件
|
|
114
|
-
listeningCallback();
|
|
115
|
-
|
|
116
|
-
await startPromise;
|
|
117
|
-
|
|
118
|
-
expect(webSocketService.isRunning).toBe(true);
|
|
119
|
-
expect(WebSocketServer).toHaveBeenCalledWith({
|
|
120
|
-
port: 8081,
|
|
121
|
-
host: '0.0.0.0',
|
|
122
|
-
maxConnections: 5
|
|
123
|
-
});
|
|
124
|
-
expect(mockWss.on).toHaveBeenCalledWith('connection', expect.any(Function));
|
|
125
|
-
expect(mockWss.on).toHaveBeenCalledWith('error', expect.any(Function));
|
|
126
|
-
expect(mockWss.on).toHaveBeenCalledWith('listening', expect.any(Function));
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('应该在已经运行时抛出错误', async () => {
|
|
130
|
-
webSocketService.isRunning = true;
|
|
131
|
-
|
|
132
|
-
await expect(webSocketService.start()).rejects.toThrow('WebSocket service is already running');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('应该在服务器错误时抛出错误', async () => {
|
|
136
|
-
const error = new Error('Server error');
|
|
137
|
-
mockWss.on.mockImplementation((event, callback) => {
|
|
138
|
-
if (event === 'error') {
|
|
139
|
-
callback(error);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
await expect(webSocketService.start()).rejects.toThrow('Server error');
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('stop', () => {
|
|
148
|
-
it('应该成功停止WebSocket服务', async () => {
|
|
149
|
-
// 设置为运行状态
|
|
150
|
-
webSocketService.isRunning = true;
|
|
151
|
-
webSocketService.wss = mockWss;
|
|
152
|
-
|
|
153
|
-
// 添加一个连接
|
|
154
|
-
const mockConnection = {
|
|
155
|
-
close: vi.fn(),
|
|
156
|
-
ws: { readyState: 1 }
|
|
157
|
-
};
|
|
158
|
-
webSocketService.connections.set('test-client', mockConnection);
|
|
159
|
-
|
|
160
|
-
await webSocketService.stop();
|
|
161
|
-
|
|
162
|
-
expect(webSocketService.isRunning).toBe(false);
|
|
163
|
-
expect(mockConnection.close).toHaveBeenCalledWith(1001, 'Server shutdown');
|
|
164
|
-
expect(mockWss.close).toHaveBeenCalled();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('应该在未运行时不执行任何操作', async () => {
|
|
168
|
-
webSocketService.isRunning = false;
|
|
169
|
-
|
|
170
|
-
await webSocketService.stop();
|
|
171
|
-
|
|
172
|
-
expect(mockWss.close).not.toHaveBeenCalled();
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('handleConnection', () => {
|
|
177
|
-
beforeEach(() => {
|
|
178
|
-
webSocketService.isRunning = true;
|
|
179
|
-
webSocketService.wss = mockWss;
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('应该处理新的连接', () => {
|
|
183
|
-
const mockRequest = {
|
|
184
|
-
socket: {
|
|
185
|
-
remoteAddress: '127.0.0.1'
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// 确保 mockWs 有正确的 readyState
|
|
190
|
-
mockWs.readyState = 1;
|
|
191
|
-
mockWs.OPEN = 1;
|
|
192
|
-
|
|
193
|
-
webSocketService.handleConnection(mockWs, mockRequest);
|
|
194
|
-
|
|
195
|
-
expect(webSocketService.connections.size).toBe(1);
|
|
196
|
-
expect(mockWs.send).toHaveBeenCalledWith(
|
|
197
|
-
expect.stringContaining('"type":"welcome"')
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('应该在超过最大连接数时拒绝连接', () => {
|
|
202
|
-
// 添加最大数量的连接
|
|
203
|
-
for (let i = 0; i < 5; i++) {
|
|
204
|
-
webSocketService.connections.set(`client-${i}`, {});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
webSocketService.handleConnection(mockWs, {});
|
|
208
|
-
|
|
209
|
-
expect(mockWs.close).toHaveBeenCalledWith(1013, 'Server overload');
|
|
210
|
-
expect(webSocketService.connections.size).toBe(5);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe('broadcast', () => {
|
|
215
|
-
beforeEach(() => {
|
|
216
|
-
// 添加模拟连接
|
|
217
|
-
const connection1 = {
|
|
218
|
-
send: vi.fn(),
|
|
219
|
-
ws: { readyState: 1, OPEN: 1 }
|
|
220
|
-
};
|
|
221
|
-
const connection2 = {
|
|
222
|
-
send: vi.fn(),
|
|
223
|
-
ws: { readyState: 1, OPEN: 1 }
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
webSocketService.connections.set('client1', connection1);
|
|
227
|
-
webSocketService.connections.set('client2', connection2);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
it('应该向所有连接广播消息', () => {
|
|
231
|
-
const message = { type: 'test', data: 'broadcast data' };
|
|
232
|
-
|
|
233
|
-
webSocketService.broadcast('test', { data: 'broadcast data' });
|
|
234
|
-
|
|
235
|
-
const connections = Array.from(webSocketService.connections.values());
|
|
236
|
-
expect(connections[0].send).toHaveBeenCalledWith('test', { data: 'broadcast data' });
|
|
237
|
-
expect(connections[1].send).toHaveBeenCalledWith('test', { data: 'broadcast data' });
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
describe('getStatus', () => {
|
|
242
|
-
it('应该返回正确的服务状态', () => {
|
|
243
|
-
webSocketService.isRunning = true;
|
|
244
|
-
webSocketService.options.port = 8081;
|
|
245
|
-
webSocketService.options.host = '0.0.0.0';
|
|
246
|
-
webSocketService.options.maxConnections = 5;
|
|
247
|
-
|
|
248
|
-
// 添加一个活跃连接
|
|
249
|
-
const activeConnection = {
|
|
250
|
-
ws: { readyState: 1, OPEN: 1 } // WebSocket.OPEN
|
|
251
|
-
};
|
|
252
|
-
webSocketService.connections.set('active', activeConnection);
|
|
253
|
-
|
|
254
|
-
const status = webSocketService.getStatus();
|
|
255
|
-
|
|
256
|
-
expect(status).toHaveProperty('isRunning', true);
|
|
257
|
-
expect(status).toHaveProperty('port', 8081);
|
|
258
|
-
expect(status).toHaveProperty('host', '0.0.0.0');
|
|
259
|
-
expect(status).toHaveProperty('totalConnections', 1);
|
|
260
|
-
expect(status).toHaveProperty('activeConnections', 1);
|
|
261
|
-
expect(status).toHaveProperty('maxConnections', 5);
|
|
262
|
-
expect(status).toHaveProperty('uptime');
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
describe('WebSocketConnection', () => {
|
|
268
|
-
let connection;
|
|
269
|
-
let mockWs;
|
|
270
|
-
|
|
271
|
-
beforeEach(() => {
|
|
272
|
-
vi.clearAllMocks();
|
|
273
|
-
|
|
274
|
-
mockWs = {
|
|
275
|
-
readyState: 1, // WebSocket.OPEN
|
|
276
|
-
OPEN: 1,
|
|
277
|
-
send: vi.fn(),
|
|
278
|
-
close: vi.fn(),
|
|
279
|
-
ping: vi.fn(),
|
|
280
|
-
on: vi.fn()
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// 清理之前的 mock 调用记录
|
|
284
|
-
terminalService.createSession.mockClear();
|
|
285
|
-
terminalService.getSession.mockClear();
|
|
286
|
-
terminalService.removeSession.mockClear();
|
|
287
|
-
|
|
288
|
-
// 创建连接实例
|
|
289
|
-
connection = new WebSocketConnection(mockWs, 'test-client');
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
describe('constructor', () => {
|
|
293
|
-
it('应该正确初始化连接', () => {
|
|
294
|
-
expect(connection.clientId).toBe('test-client');
|
|
295
|
-
expect(connection.ws).toBe(mockWs);
|
|
296
|
-
expect(connection.isAuthenticated).toBe(false);
|
|
297
|
-
expect(connection.sessionId).toBeNull();
|
|
298
|
-
expect(mockWs.on).toHaveBeenCalledWith('message', expect.any(Function));
|
|
299
|
-
expect(mockWs.on).toHaveBeenCalledWith('close', expect.any(Function));
|
|
300
|
-
expect(mockWs.on).toHaveBeenCalledWith('error', expect.any(Function));
|
|
301
|
-
expect(mockWs.on).toHaveBeenCalledWith('pong', expect.any(Function));
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
describe.skip('handleMessage', () => {
|
|
306
|
-
// 这些测试需要更深入的 mock 重构,暂时跳过
|
|
307
|
-
it.skip('应该处理终端创建消息', async () => {
|
|
308
|
-
// TODO: 修复 terminalService mock 交互问题
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it.skip('应该处理终端数据消息', async () => {
|
|
312
|
-
// TODO: 修复 terminalService mock 交互问题
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it.skip('应该处理终端调整大小消息', async () => {
|
|
316
|
-
// TODO: 修复 terminalService mock 交互问题
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it('应该处理ping消息', () => {
|
|
320
|
-
const message = { type: 'ping' };
|
|
321
|
-
|
|
322
|
-
const messageHandler = mockWs.on.mock.calls.find(call => call[0] === 'message')[1];
|
|
323
|
-
messageHandler(JSON.stringify(message));
|
|
324
|
-
|
|
325
|
-
expect(mockWs.send).toHaveBeenCalledWith(
|
|
326
|
-
expect.stringContaining('"type":"pong"')
|
|
327
|
-
);
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
it('应该处理未知消息类型', () => {
|
|
331
|
-
const message = { type: 'unknown' };
|
|
332
|
-
|
|
333
|
-
const messageHandler = mockWs.on.mock.calls.find(call => call[0] === 'message')[1];
|
|
334
|
-
messageHandler(JSON.stringify(message));
|
|
335
|
-
|
|
336
|
-
expect(mockWs.send).toHaveBeenCalledWith(
|
|
337
|
-
expect.stringContaining('"type":"error"')
|
|
338
|
-
);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
describe('send', () => {
|
|
343
|
-
it('应该发送消息', () => {
|
|
344
|
-
const data = { test: 'data' };
|
|
345
|
-
|
|
346
|
-
connection.send('test', data);
|
|
347
|
-
|
|
348
|
-
// 检查 mockWs.send 被调用,并验证调用参数包含正确的 JSON 结构
|
|
349
|
-
expect(mockWs.send).toHaveBeenCalledTimes(1);
|
|
350
|
-
const sentMessage = JSON.parse(mockWs.send.mock.calls[0][0]);
|
|
351
|
-
|
|
352
|
-
expect(sentMessage.type).toBe('test');
|
|
353
|
-
expect(sentMessage.clientId).toBe('test-client');
|
|
354
|
-
expect(sentMessage.test).toBe('data');
|
|
355
|
-
expect(typeof sentMessage.timestamp).toBe('number');
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
it('应该在连接未打开时不发送消息', () => {
|
|
359
|
-
mockWs.readyState = 0; // WebSocket.CONNECTING
|
|
360
|
-
|
|
361
|
-
connection.send('test', { data: 'test' });
|
|
362
|
-
|
|
363
|
-
expect(mockWs.send).not.toHaveBeenCalled();
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
describe('sendError', () => {
|
|
368
|
-
it('应该发送错误消息', () => {
|
|
369
|
-
connection.sendError('Test error', 'Error details');
|
|
370
|
-
|
|
371
|
-
// 检查 mockWs.send 被调用,并验证调用参数包含正确的 JSON 结构
|
|
372
|
-
expect(mockWs.send).toHaveBeenCalledTimes(1);
|
|
373
|
-
const sentMessage = JSON.parse(mockWs.send.mock.calls[0][0]);
|
|
374
|
-
|
|
375
|
-
expect(sentMessage.type).toBe('error');
|
|
376
|
-
expect(sentMessage.clientId).toBe('test-client');
|
|
377
|
-
expect(sentMessage.message).toBe('Test error');
|
|
378
|
-
expect(sentMessage.details).toBe('Error details');
|
|
379
|
-
expect(typeof sentMessage.timestamp).toBe('number');
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
describe('getInfo', () => {
|
|
384
|
-
it('应该返回连接信息', () => {
|
|
385
|
-
const info = connection.getInfo();
|
|
386
|
-
|
|
387
|
-
expect(info).toHaveProperty('clientId', 'test-client');
|
|
388
|
-
expect(info).toHaveProperty('connectedAt');
|
|
389
|
-
expect(info).toHaveProperty('lastActivity');
|
|
390
|
-
expect(info).toHaveProperty('sessionId', null);
|
|
391
|
-
expect(info).toHaveProperty('isAuthenticated', false);
|
|
392
|
-
expect(info).toHaveProperty('readyState', mockWs.readyState);
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
describe('close', () => {
|
|
397
|
-
it('应该关闭连接', () => {
|
|
398
|
-
connection.close(1000, 'Test close');
|
|
399
|
-
|
|
400
|
-
expect(mockWs.close).toHaveBeenCalledWith(1000, 'Test close');
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 核心库功能测试
|
|
3
|
-
* 测试库是否能正确导入和使用
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, it, expect, beforeAll } from 'vitest';
|
|
7
|
-
import path from 'path';
|
|
8
|
-
import { fileURLToPath } from 'url';
|
|
9
|
-
|
|
10
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
-
const __dirname = path.dirname(__filename);
|
|
12
|
-
|
|
13
|
-
// 获取server包的index.js路径
|
|
14
|
-
const serverIndexPath = path.join(__dirname, '../../index.js');
|
|
15
|
-
|
|
16
|
-
describe('核心库导入测试', () => {
|
|
17
|
-
let coreModules = {};
|
|
18
|
-
|
|
19
|
-
beforeAll(async () => {
|
|
20
|
-
// 动态导入所有导出的函数和对象
|
|
21
|
-
coreModules = await import(serverIndexPath);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('应该成功导入所有模块', () => {
|
|
25
|
-
expect(coreModules).toBeDefined();
|
|
26
|
-
expect(Object.keys(coreModules).length).toBeGreaterThan(0);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('应该导出服务器相关函数', () => {
|
|
30
|
-
expect(typeof coreModules.startServer).toBe('function');
|
|
31
|
-
expect(typeof coreModules.stopServer).toBe('function');
|
|
32
|
-
expect(typeof coreModules.getServerState).toBe('function');
|
|
33
|
-
expect(typeof coreModules.getServerAddress).toBe('function');
|
|
34
|
-
expect(typeof coreModules.isServerRunning).toBe('function');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('应该导出核心对象', () => {
|
|
38
|
-
expect(typeof coreModules.app).toBe('function');
|
|
39
|
-
expect(typeof coreModules.config).toBe('object');
|
|
40
|
-
expect(typeof coreModules.logger).toBe('object');
|
|
41
|
-
expect(typeof coreModules.util).toBe('object');
|
|
42
|
-
expect(typeof coreModules.promptManager).toBe('object');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('应该导出MCP相关函数', () => {
|
|
46
|
-
expect(typeof coreModules.getMcpServer).toBe('function');
|
|
47
|
-
expect(typeof coreModules.handleGetPrompt).toBe('function');
|
|
48
|
-
expect(typeof coreModules.handleSearchPrompts).toBe('function');
|
|
49
|
-
expect(typeof coreModules.handleReloadPrompts).toBe('function');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('应该导出路由相关对象', () => {
|
|
53
|
-
expect(typeof coreModules.adminRouter).toBe('function');
|
|
54
|
-
expect(typeof coreModules.openRouter).toBe('function');
|
|
55
|
-
expect(typeof coreModules.adminAuthMiddleware).toBe('function');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('配置对象应该有正确的方法', () => {
|
|
59
|
-
expect(typeof coreModules.config.getPort).toBe('function');
|
|
60
|
-
expect(typeof coreModules.config.getPromptsDir).toBe('function');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('日志对象应该有正确的方法', () => {
|
|
64
|
-
expect(typeof coreModules.logger.info).toBe('function');
|
|
65
|
-
expect(typeof coreModules.logger.error).toBe('function');
|
|
66
|
-
expect(typeof coreModules.logger.warn).toBe('function');
|
|
67
|
-
expect(typeof coreModules.logger.debug).toBe('function');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('工具对象应该正确导出', () => {
|
|
71
|
-
expect(coreModules.util).toBeDefined();
|
|
72
|
-
expect(typeof coreModules.util).toBe('object');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('提示词管理器应该正确导出', () => {
|
|
76
|
-
expect(coreModules.promptManager).toBeDefined();
|
|
77
|
-
expect(typeof coreModules.promptManager).toBe('object');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('服务器状态函数应该正常工作', async () => {
|
|
81
|
-
expect(typeof coreModules.getServerAddress).toBe('function');
|
|
82
|
-
expect(typeof coreModules.isServerRunning).toBe('function');
|
|
83
|
-
|
|
84
|
-
// 测试函数调用
|
|
85
|
-
const state = coreModules.getServerState();
|
|
86
|
-
expect(typeof state).toBe('object');
|
|
87
|
-
|
|
88
|
-
const address = coreModules.getServerAddress();
|
|
89
|
-
expect(typeof address).toBe('string');
|
|
90
|
-
|
|
91
|
-
const isRunning = await coreModules.isServerRunning();
|
|
92
|
-
expect(typeof isRunning).toBe('boolean');
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"entryPoints": [
|
|
3
|
-
"./index.js",
|
|
4
|
-
"./services/",
|
|
5
|
-
"./utils/",
|
|
6
|
-
"./mcp/",
|
|
7
|
-
"./api/",
|
|
8
|
-
"./toolm/"
|
|
9
|
-
],
|
|
10
|
-
"out": "./docs/typedoc/",
|
|
11
|
-
"exclude": [
|
|
12
|
-
"node_modules/",
|
|
13
|
-
"dist/",
|
|
14
|
-
"coverage/",
|
|
15
|
-
"tests/",
|
|
16
|
-
"test-results/",
|
|
17
|
-
"**/*.test.js",
|
|
18
|
-
"**/*.spec.js"
|
|
19
|
-
],
|
|
20
|
-
"excludePrivate": true,
|
|
21
|
-
"excludeProtected": false,
|
|
22
|
-
"excludeInternal": true,
|
|
23
|
-
"hideGenerator": true,
|
|
24
|
-
"sort": ["source-order"],
|
|
25
|
-
"kindSortOrder": [
|
|
26
|
-
"Class",
|
|
27
|
-
"Interface",
|
|
28
|
-
"Type alias",
|
|
29
|
-
"Variable",
|
|
30
|
-
"Function",
|
|
31
|
-
"Enum",
|
|
32
|
-
"Namespace"
|
|
33
|
-
],
|
|
34
|
-
"categorizeByGroup": true,
|
|
35
|
-
"defaultCategory": "Other",
|
|
36
|
-
"categoryOrder": [
|
|
37
|
-
"Services",
|
|
38
|
-
"Utils",
|
|
39
|
-
"MCP",
|
|
40
|
-
"API",
|
|
41
|
-
"Tools",
|
|
42
|
-
"*"
|
|
43
|
-
],
|
|
44
|
-
"plugin": [
|
|
45
|
-
"typedoc-plugin-markdown",
|
|
46
|
-
"typedoc-plugin-mermaid"
|
|
47
|
-
],
|
|
48
|
-
"readme": "none",
|
|
49
|
-
"gitRevision": "main",
|
|
50
|
-
"sourceLinkTemplate": "https://github.com/BeCrafter/prompt-manager/blob/{gitRevision}/{path}#L{line}",
|
|
51
|
-
"tsconfig": "./tsconfig.json"
|
|
52
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vitest 配置文件
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { defineConfig } from 'vitest/config';
|
|
6
|
-
|
|
7
|
-
export default defineConfig({
|
|
8
|
-
test: {
|
|
9
|
-
// 测试环境
|
|
10
|
-
environment: 'node',
|
|
11
|
-
|
|
12
|
-
// 全局配置
|
|
13
|
-
globals: true,
|
|
14
|
-
|
|
15
|
-
// 设置文件
|
|
16
|
-
setupFiles: ['./tests/setup.js'],
|
|
17
|
-
|
|
18
|
-
// 测试文件匹配模式
|
|
19
|
-
include: [
|
|
20
|
-
'tests/**/*.test.js',
|
|
21
|
-
'tests/**/*.spec.js'
|
|
22
|
-
],
|
|
23
|
-
|
|
24
|
-
// 排除文件
|
|
25
|
-
exclude: [
|
|
26
|
-
'node_modules',
|
|
27
|
-
'dist',
|
|
28
|
-
'tests/e2e/**'
|
|
29
|
-
],
|
|
30
|
-
|
|
31
|
-
// 覆盖率配置
|
|
32
|
-
coverage: {
|
|
33
|
-
provider: 'v8',
|
|
34
|
-
reporter: ['text', 'json', 'html'],
|
|
35
|
-
exclude: [
|
|
36
|
-
'node_modules',
|
|
37
|
-
'dist',
|
|
38
|
-
'tests',
|
|
39
|
-
'**/*.test.js',
|
|
40
|
-
'**/*.spec.js'
|
|
41
|
-
],
|
|
42
|
-
thresholds: {
|
|
43
|
-
global: {
|
|
44
|
-
branches: 70,
|
|
45
|
-
functions: 70,
|
|
46
|
-
lines: 70,
|
|
47
|
-
statements: 70
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
// 测试超时
|
|
53
|
-
testTimeout: 10000,
|
|
54
|
-
|
|
55
|
-
// 钩子超时
|
|
56
|
-
hookTimeout: 10000,
|
|
57
|
-
|
|
58
|
-
// 并发测试
|
|
59
|
-
threads: true,
|
|
60
|
-
|
|
61
|
-
// 监听模式配置
|
|
62
|
-
watch: false,
|
|
63
|
-
|
|
64
|
-
// 报告器
|
|
65
|
-
reporter: ['verbose', 'html']
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
// 解析配置
|
|
69
|
-
resolve: {
|
|
70
|
-
alias: {
|
|
71
|
-
'@': '/Users/mark/code/GitHub/BeCrafter/prompt-manager/packages/server'
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
File without changes
|