feat(formatter): [БЫЛО БЫ DROPPED] header + triggered-rule line in dry-run mode

This commit is contained in:
Vladimir Bryzgalov
2026-04-21 17:12:16 +05:00
parent 42e311c05a
commit 2fcebcc756
2 changed files with 98 additions and 3 deletions
+21 -3
View File
@@ -43,9 +43,15 @@ final class MessageFormatter
$lines = [];
$label_info = self::LABEL_MAP[$class['label']] ?? self::LABEL_MAP['unclear'];
$header = ($ctx['is_retro'] ? '📂 Ретроспектива · ' : '')
. $label_info['emoji'] . ' ' . $label_info['text'];
$is_dry_run_drop = !empty($ctx['dry_run_drop']);
if ($is_dry_run_drop) {
$header = '[БЫЛО БЫ DROPPED]';
} else {
$label_info = self::LABEL_MAP[$class['label']] ?? self::LABEL_MAP['unclear'];
$header = ($ctx['is_retro'] ? '📂 Ретроспектива · ' : '')
. $label_info['emoji'] . ' ' . $label_info['text'];
}
$lines[] = $header;
$lines[] = '🌐 ' . esc_html($ctx['site_title']) . ' · форма «' . esc_html($ctx['form_title']) . '»';
@@ -60,6 +66,18 @@ final class MessageFormatter
$lines[] = '⚙️ Попало в спам: ' . esc_html($ctx['reason']);
$lines[] = '📊 Классификация: ' . self::format_reasons($class['reasons']);
if ($is_dry_run_drop) {
$rule = '';
foreach ($class['reasons'] as $r) {
$text = (string)($r['text'] ?? '');
if (strpos($text, 'hard-rule:') === 0 || strpos($text, 'score ≤') === 0) {
$rule = $text;
break;
}
}
if ($rule !== '') $lines[] = '🚫 Сработавшее правило: ' . esc_html($rule);
}
$meta_bits = [];
if ($ctx['ip'] !== '') $meta_bits[] = 'IP ' . esc_html($ctx['ip']);
if ($ctx['user_agent'] !== '') $meta_bits[] = 'UA ' . esc_html(self::shorten_ua($ctx['user_agent']));