test(server): 增强 auth/ws/sse 测试覆盖率
- auth/token.ts: 50% → 100% - 新增 authMiddleware 中间件完整测试 - 覆盖本地 IP 检测、远程认证、跳过路径等场景 - 新增 getAuthContext 测试 - ws.ts: 90% → 98% - 新增 Blob/非标准数据类型处理测试 - 新增 addMessage 返回 null 场景测试 - 新增 tool_response 和 permission_response 边界测试 - sse.ts: 新增事件格式化和统计测试 测试数量: 344 → 369 (+25) 总体覆盖率: 80.82% → 82.98%
This commit is contained in:
@@ -140,6 +140,41 @@ describe('SSE Handler', () => {
|
||||
expect(typeof stats.sessions).toBe('number');
|
||||
expect(typeof stats.subscribers).toBe('number');
|
||||
});
|
||||
|
||||
it('初始状态统计为 0', () => {
|
||||
const stats = getSSEStats();
|
||||
expect(stats.sessions).toBe(0);
|
||||
expect(stats.subscribers).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('事件格式化', () => {
|
||||
it('emitEvent 格式化带 event 字段的事件', () => {
|
||||
// 无订阅者时调用不会抛错,但内部会格式化
|
||||
emitEvent('test-session', {
|
||||
event: 'custom_event',
|
||||
data: { timestamp: 12345, payload: { key: 'value' } },
|
||||
});
|
||||
// 测试不抛错即为通过
|
||||
});
|
||||
|
||||
it('emitEvent 格式化不带 event 字段的事件', () => {
|
||||
emitEvent('test-session', {
|
||||
data: { timestamp: 12345, payload: null },
|
||||
});
|
||||
});
|
||||
|
||||
it('复杂 payload 数据正确序列化', () => {
|
||||
expect(() => {
|
||||
emitStatusEvent('session-1', 'processing', {
|
||||
nested: { deep: { value: [1, 2, 3] } },
|
||||
array: ['a', 'b', 'c'],
|
||||
number: 42,
|
||||
boolean: true,
|
||||
null: null,
|
||||
});
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleSSE - SSE 路由处理', () => {
|
||||
|
||||
Reference in New Issue
Block a user