goal-compliance-rules-smoke.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env node
  2. const { buildGoalStrategy, detectGoal, SUGGESTION_RULES } = require('../mcp/src/features/tihao-sourcing/goal-strategy');
  3. const { buildComplianceCheck, detectComplianceRisks, BANNED_WORD_REPLACEMENTS, PLATFORM_RULES, SAFE_WORDS } = require('../mcp/src/features/tihao-sourcing/compliance-rules');
  4. const { enrichCriteriaWithExperience } = require('../mcp/src/features/tihao-sourcing/experience-rules');
  5. function main() {
  6. // 投放目标识别
  7. assert(detectGoal('需要找博主做种草转化,带货成交') === 'seed_conversion', '应识别种草转化');
  8. assert(detectGoal('品牌曝光,提升知名度,破圈传播') === 'brand_exposure', '应识别品牌曝光');
  9. assert(detectGoal('搜索引流,卡小蓝词,关键词沉淀') === 'search_drain', '应识别搜索引流');
  10. assert(detectGoal('大促活动冲量,同城本地铺量') === 'campaign_volume', '应识别活动冲量');
  11. // 1.5 倍提号规则
  12. const strategy = buildGoalStrategy({ rawText: '种草转化', targetCount: 10 });
  13. assert(strategy.goalLabel === '种草转化', '目标中文标签应正确');
  14. assert(strategy.suggestionCount === 15, '10 位需求应提 15 位(1.5 倍)');
  15. assert(strategy.suggestionRules.length === 3, '应有 3 条提号规则');
  16. assert(SUGGESTION_RULES.some(rule => rule.id === 'suggest-1.5x'), '应有 1.5 倍提号规则');
  17. assert(SUGGESTION_RULES.some(rule => rule.id === 'style-match-80'), '应有 80% 风格匹配规则');
  18. // 合规词检测
  19. const risks = detectComplianceRisks('这个产品美白祛痘效果第一,是平替神器');
  20. const banned = risks.map(item => item.banned);
  21. assert(banned.includes('美白'), '应检出美白');
  22. assert(banned.includes('祛痘'), '应检出祛痘');
  23. assert(banned.includes('第一'), '应检出第一');
  24. assert(BANNED_WORD_REPLACEMENTS.some(item => item.banned === '美白' && item.safe.includes('提亮肤色')), '美白应替换为提亮肤色');
  25. // 合规检查结构
  26. const compliance = buildComplianceCheck({ rawText: '美白产品', platforms: ['xiaohongshu', 'douyin'] });
  27. assert(compliance.bannedHits.length >= 1, '应检出美白高危词');
  28. assert(compliance.platformRules.length === 2, '两个平台特规');
  29. assert(compliance.safeWords.length > 0 && SAFE_WORDS.includes('皮肤屏障'), '应有安全词库');
  30. assert(PLATFORM_RULES.douyin && PLATFORM_RULES.xiaohongshu && PLATFORM_RULES.bilibili, '三个平台特规齐全');
  31. // 接入 experience-rules
  32. const enriched = enrichCriteriaWithExperience({ rawText: '美白种草转化,目标10位', targetCount: 10, platforms: ['xiaohongshu'], keywords: ['美白'] });
  33. assert(enriched.goalStrategy && enriched.goalStrategy.goalLabel, '应输出 goalStrategy');
  34. assert(enriched.compliance && enriched.compliance.bannedWordReplacements, '应输出 compliance');
  35. console.log(JSON.stringify({
  36. ok: true,
  37. goalStrategies: Object.keys(require('../mcp/src/features/tihao-sourcing/goal-strategy').GOAL_STRATEGIES).length,
  38. suggestionRuleCount: SUGGESTION_RULES.length,
  39. bannedWordCount: BANNED_WORD_REPLACEMENTS.length,
  40. platformRuleCount: Object.keys(PLATFORM_RULES).length,
  41. safeWordCount: SAFE_WORDS.length
  42. }, null, 2));
  43. }
  44. function assert(condition, message) {
  45. if (!condition) throw new Error(message);
  46. }
  47. if (require.main === module) main();