Files
ShieldAI/test-classifier.ts
Michael Freno 3663e5b80a FRE-4517, FRE-4499: Complete SpamShield implementation and billing updates
- SpamFeedback table migration with timestamp index
- Real-time interception engine completion
- Billing service enhancements
- Classifier and rule engine updates

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-01 19:53:19 -04:00

61 lines
2.0 KiB
TypeScript

import { BertSmsClassifier } from './services/spamshield/src/classifier/sms-classifier';
// Mock SpamShieldService for testing
class MockSpamShield {
async checkReputation(phoneNumber: string) {
return {
score: 0,
isSpam: false,
source: 'fallback',
};
}
}
async function testClassifier(): Promise<void> {
console.log('=== SMS Classifier Feature Flag Test ===\n');
// Test 1: Classifier with enabled feature flag
console.log('Test 1: Classifier with enabled feature flag');
const mockShield = new MockSpamShield();
const classifier = new BertSmsClassifier(mockShield as any);
const result = await classifier.classify(
'Congratulations! You have won $1,000,000! Click here: http://bit.ly/12345 to claim your prize now! Call 555-1234 immediately!'
);
console.log('Input:', result.body);
console.log('Classification:', result.isSpam ? 'SPAM' : 'NOT SPAM');
console.log('Score:', result.score);
console.log('Features:', result.features);
console.log('');
// Test 2: Classifier with benign message
console.log('Test 2: Classifier with benign message');
const benignResult = await classifier.classify(
'Hello! Just checking in to see how you are doing. Hope you have a great day!'
);
console.log('Input:', benignResult.body);
console.log('Classification:', benignResult.isSpam ? 'SPAM' : 'NOT SPAM');
console.log('Score:', benignResult.score);
console.log('');
// Test 3: Classifier metrics
console.log('Test 3: Classifier metrics');
const metrics = classifier.getMetrics();
console.log('Total classified:', metrics.totalClassified);
console.log('Spam detected:', metrics.spamDetected);
console.log('Accuracy:', metrics.totalClassified > 0
? ((metrics.spamDetected / metrics.totalClassified) * 100).toFixed(1) + '%'
: '0%');
console.log('');
console.log('=== All tests completed successfully ===');
}
export { testClassifier };
if (import.meta.env?.MODE !== 'test') {
testClassifier().catch(console.error);
}