winner12-copywriter-mcp
Version:
MCP tool for generating social media content for winner12 AI football prediction website
214 lines • 9.52 kB
JavaScript
/**
* 合规性验证器单元测试
* 测试内容合规验证的各种场景和边界条件
*/
import { ContentComplianceValidator } from '../utils/ContentComplianceValidator.js';
import { ContentProcessor } from '../utils/ContentProcessor.js';
// 测试数据
const testCases = {
// 违规内容测试
violations: {
gambling_language: [
'今天的预测:皇马必胜!置信度90%',
'这场比赛稳赢,胜率高达85%',
'跟着我投注就对了,必胜无疑!'
],
missing_ai_label: [
'皇马 vs 巴萨的比赛分析来了',
'今天为大家带来专业预测'
],
missing_disclaimer: [
'[🤖 AI生成] 皇马 vs 巴萨预测分析',
'[🤖 AI生成] 今天的比赛数据显示...'
],
engagement_bait: [
'[🤖 AI生成] 比赛分析 ⚠️ 免责声明 💭 在评论区分享你的预测吧!',
'[🤖 AI生成] 数据洞察 ⚠️ 仅供参考 评论你的答案获得奖励!'
]
},
// 合规内容测试
compliant: [
'[🤖 AI生成内容] 皇马 vs 巴萨数据分析 ⚠️ 仅供娱乐参考,不构成投注建议',
'[🤖 AI分析] 今天为大家带来比赛数据洞察 📊 分析显示双方实力接近 ⚠️ 仅供参考,请理性观赛',
'🤖 本内容由Winner12 AI算法自动生成 比赛分析来了!数据显示有趣的趋势 ⚠️ 免责声明:本分析仅供参考'
]
};
/**
* 运行所有合规测试
*/
export function runComplianceTests() {
const results = [];
console.log('🧪 开始运行合规性测试...\n');
// 1. 测试赌博语言检测
console.log('1. 测试赌博语言检测');
for (const content of testCases.violations.gambling_language) {
const result = ContentComplianceValidator.validateContent(content, 'tiktok');
const hasGamblingViolation = result.violations.some(v => v.type === 'gambling_language');
const passed = hasGamblingViolation;
results.push({
test: `赌博语言检测: "${content.substring(0, 30)}..."`,
passed,
details: passed ? '✅ 正确检测到赌博用词' : '❌ 未检测到赌博用词'
});
}
// 2. 测试AI标识检测
console.log('2. 测试AI标识检测');
for (const content of testCases.violations.missing_ai_label) {
const result = ContentComplianceValidator.validateContent(content, 'instagram');
const missingLabel = result.violations.some(v => v.type === 'missing_ai_label');
const passed = missingLabel;
results.push({
test: `AI标识检测: "${content.substring(0, 30)}..."`,
passed,
details: passed ? '✅ 正确检测到缺少AI标识' : '❌ 未检测到缺少AI标识'
});
}
// 3. 测试免责声明检测
console.log('3. 测试免责声明检测');
for (const content of testCases.violations.missing_disclaimer) {
const result = ContentComplianceValidator.validateContent(content, 'facebook');
const missingDisclaimer = result.violations.some(v => v.type === 'missing_disclaimer');
const passed = missingDisclaimer;
results.push({
test: `免责声明检测: "${content.substring(0, 30)}..."`,
passed,
details: passed ? '✅ 正确检测到缺少免责声明' : '❌ 未检测到缺少免责声明'
});
}
// 4. 测试互动诱导检测
console.log('4. 测试互动诱导检测');
for (const content of testCases.violations.engagement_bait) {
const result = ContentComplianceValidator.validateContent(content, 'instagram');
const hasEngagementBait = result.violations.some(v => v.type === 'engagement_bait');
const passed = hasEngagementBait;
results.push({
test: `互动诱导检测: "${content.substring(0, 30)}..."`,
passed,
details: passed ? '✅ 正确检测到互动诱导' : '❌ 未检测到互动诱导'
});
}
// 5. 测试合规内容
console.log('5. 测试合规内容');
for (const content of testCases.compliant) {
const result = ContentComplianceValidator.validateContent(content, 'youtube');
const passed = result.isCompliant;
results.push({
test: `合规内容测试: "${content.substring(0, 30)}..."`,
passed,
details: passed ? '✅ 正确识别为合规内容' : `❌ 误判为违规: ${result.violations[0]?.description || '未知原因'}`
});
}
// 6. 测试平台特定规则
console.log('6. 测试平台特定规则');
const tiktokViolation = '预测:皇马胜 置信度:90%';
const tiktokResult = ContentComplianceValidator.validateContent(tiktokViolation, 'tiktok');
const hasCriticalViolation = tiktokResult.violations.some(v => v.severity === 'critical');
results.push({
test: 'TikTok平台特定规则',
passed: hasCriticalViolation,
details: hasCriticalViolation ? '✅ TikTok严格模式正常工作' : '❌ TikTok严格模式未生效'
});
// 7. 测试内容处理器
console.log('7. 测试内容处理器');
testContentProcessor(results);
// 8. 测试评分系统
console.log('8. 测试评分系统');
testScoringSystem(results);
// 统计结果
const passed = results.filter(r => r.passed).length;
const failed = results.length - passed;
console.log('\n📊 测试结果统计:');
console.log(`✅ 通过: ${passed}`);
console.log(`❌ 失败: ${failed}`);
console.log(`📈 通过率: ${((passed / results.length) * 100).toFixed(1)}%`);
// 显示失败的测试
const failedTests = results.filter(r => !r.passed);
if (failedTests.length > 0) {
console.log('\n❌ 失败的测试:');
failedTests.forEach(test => {
console.log(` - ${test.test}: ${test.details}`);
});
}
return { passed, failed, results };
}
/**
* 测试内容处理器
*/
async function testContentProcessor(results) {
try {
const rawContent = '今天的比赛分析';
const processed = await ContentProcessor.processContent(rawContent, 'instagram');
const hasAILabel = processed.processed.includes('🤖');
const hasDisclaimer = processed.processed.includes('⚠️');
const hasCompliance = processed.compliance !== undefined;
results.push({
test: '内容处理器基本功能',
passed: hasAILabel && hasDisclaimer && hasCompliance,
details: hasAILabel && hasDisclaimer && hasCompliance
? '✅ 正确添加AI标识、免责声明和合规验证'
: '❌ 内容处理不完整'
});
// 测试批量处理
const batchContents = [
{ content: '比赛1分析', platform: 'tiktok' },
{ content: '比赛2分析', platform: 'twitter' }
];
const batchResults = await ContentProcessor.batchProcess(batchContents);
results.push({
test: '批量内容处理',
passed: batchResults.length === 2,
details: batchResults.length === 2 ? '✅ 批量处理正常' : '❌ 批量处理失败'
});
}
catch (error) {
results.push({
test: '内容处理器测试',
passed: false,
details: `❌ 处理器测试失败: ${error instanceof Error ? error.message : '未知错误'}`
});
}
}
/**
* 测试评分系统
*/
function testScoringSystem(results) {
// 测试完全合规内容
const perfectContent = '[🤖 AI生成内容] 比赛数据分析 ⚠️ 仅供娱乐参考,不构成投注建议';
const perfectResult = ContentComplianceValidator.validateContent(perfectContent, 'facebook');
results.push({
test: '完美内容评分',
passed: perfectResult.score === 100,
details: `评分: ${perfectResult.score}/100 ${perfectResult.score === 100 ? '✅' : '❌'}`
});
// 测试严重违规内容
const severeContent = '预测皇马必胜!投注稳赚不赔!';
const severeResult = ContentComplianceValidator.validateContent(severeContent, 'tiktok');
results.push({
test: '严重违规内容评分',
passed: severeResult.score < 50,
details: `评分: ${severeResult.score}/100 ${severeResult.score < 50 ? '✅ 正确识别为高风险' : '❌ 评分过高'}`
});
// 测试风险等级
results.push({
test: '风险等级评估',
passed: severeResult.riskLevel === 'critical' || severeResult.riskLevel === 'high',
details: `风险等级: ${severeResult.riskLevel} ${severeResult.riskLevel === 'critical' || severeResult.riskLevel === 'high' ? '✅' : '❌'}`
});
}
/**
* 运行特定平台的合规测试
*/
export function runPlatformSpecificTests(platform) {
const testContent = '预测:主队胜 置信度:85% 在评论区分享你的预测!';
const result = ContentComplianceValidator.validateContent(testContent, platform);
return {
platform,
score: result.score,
issues: result.violations.map(v => `${v.severity}: ${v.description}`)
};
}
// 如果直接运行此文件,执行测试
if (import.meta.url === `file://${process.argv[1]}`) {
runComplianceTests();
}
//# sourceMappingURL=compliance.test.js.map