feat(round-16): AI意图情绪分析/展会名片双向互换/雷达爬虫清洗/离线多媒体缓存 (103套件1101测试全绿)
这个提交包含在:
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户