feat(round-16): AI意图情绪分析/展会名片双向互换/雷达爬虫清洗/离线多媒体缓存 (103套件1101测试全绿)

这个提交包含在:
wikiboss
2026-09-21 02:17:06 +08:00
父节点 e6d06f762c
当前提交 8c003b70cd
共有 8 个文件被更改,包括 805 次插入 和 0 次删除

查看文件

@@ -0,0 +1,77 @@
import {
RadarBotFilterService,
detectBotUserAgent,
isRateLimitSuspicious,
TrafficFilterResult,
} from '../../../src/modules/crm/service/bot-filter';
describe('Point 63 (P2): 访客雷达异常流量与出海社交抓取机器爬虫清洗过滤', () => {
let service: RadarBotFilterService;
beforeEach(() => {
service = new RadarBotFilterService();
});
describe('1. detectBotUserAgent (爬虫与社交卡片抓取器识别)', () => {
it('应精准识别 Googlebot、Bingbot 与主流搜索引擎爬虫', () => {
const googleUa = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
const res = detectBotUserAgent(googleUa);
expect(res.isBot).toBe(true);
expect(res.botType).toBe('SEARCH_CRAWLER');
});
it('应精准识别 WhatsApp 与 Twitter/LinkedIn 社交预览卡片抓取器', () => {
const waUa = 'WhatsApp/2.21.12.21 A';
const waRes = detectBotUserAgent(waUa);
expect(waRes.isBot).toBe(true);
expect(waRes.botType).toBe('SOCIAL_PREVIEW');
const twUa = 'Twitterbot/1.0';
const twRes = detectBotUserAgent(twUa);
expect(twRes.isBot).toBe(true);
expect(twRes.botType).toBe('SOCIAL_PREVIEW');
});
it('应拦截 curl、Python Requests、Postman 等自动化脚本工具', () => {
expect(detectBotUserAgent('python-requests/2.28.1').isBot).toBe(true);
expect(detectBotUserAgent('curl/7.68.0').isBot).toBe(true);
});
it('真实手机移动端浏览器访问应判定为正常用户 (isBot = false)', () => {
const mobileUa = 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1';
const res = detectBotUserAgent(mobileUa);
expect(res.isBot).toBe(false);
expect(res.botType).toBeUndefined();
});
});
describe('2. isRateLimitSuspicious (超高频空刷异常检测)', () => {
it('1秒内发生超过 10 次访问请求应判定为异常刷量', () => {
const timestamps = Array(12).fill(Date.now());
expect(isRateLimitSuspicious(timestamps)).toBe(true);
});
it('正常人类浏览间隔应判定为合法流量', () => {
const timestamps = [Date.now() - 5000, Date.now() - 2000, Date.now()];
expect(isRateLimitSuspicious(timestamps)).toBe(false);
});
});
describe('3. RadarBotFilterService 综合过滤清洗', () => {
it('应标记机器人流量并决定是否计入 CRM 真实意向得分', async () => {
const botTraffic = await service.filterIncomingTraffic({
ip: '66.249.66.1',
userAgent: 'Googlebot/2.1',
});
expect(botTraffic.shouldRecordLead).toBe(false);
expect(botTraffic.category).toBe('CRAWLER');
const humanTraffic = await service.filterIncomingTraffic({
ip: '94.200.12.34',
userAgent: 'Mozilla/5.0 (Linux; Android 14) Chrome/120.0 Mobile Safari/537.36',
});
expect(humanTraffic.shouldRecordLead).toBe(true);
expect(humanTraffic.category).toBe('HUMAN');
});
});
});