Commit Graph

27 Commits

Author SHA1 Message Date
Vladimir Bryzgalov f415f429ed refactor(classifier): single-pass hard-drop trigger; cleaner drop reason rendering
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 16:20:28 +05:00
Vladimir Bryzgalov a70785beca feat(classifier): label 'drop' via hard-rule + score threshold (-5 default)
- Add DEFAULT_THRESHOLDS['drop'] = -5 and DEFAULT_HARD_DROP_RULES const
- Add evaluate_hard_drop(): fires when no positive signals + short latin name OR ≥3 placeholder fields
- Wire into classify(): drop overrides all other labels; synthetic reason explains trigger
- Add drop_reason_label() and 'drop' => ' авто-дроп' to MessageFormatter::LABEL_MAP
- Update ClassifierTest/MessageFormatterTest to extend Cf7stgTestCase (filter isolation)
- Adjust pre-existing assertions that now correctly yield 'drop' instead of 'spam'
2026-04-21 16:14:49 +05:00
Vladimir Bryzgalov 18a07c9b1b test(classifier): exact-count assertions for placeholder fixture; document SERVICE_FIELD_KEYS prefix semantics
Fixes issues from code review in commit 249f195:

1. Tighten fixture assertions to exact counts (assertSame instead of assertGreaterThanOrEqual):
   - test_count_placeholder_fields_screenshot_1_exact_count: expect 5 placeholders
   - test_count_placeholder_fields_screenshot_2_exact_count: expect 5 placeholders
   - test_count_placeholder_fields_screenshot_3_exact_count: expect 1 placeholder

2. Document SERVICE_FIELD_KEYS prefix-matching semantics in comment:
   clarify that keys starting with _wpcf7 are skipped via strpos prefix match,
   so explicit enumeration of every _wpcf7_* variant is unnecessary.

Test results: 75/75 green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 16:08:57 +05:00
Vladimir Bryzgalov 249f195257 feat(classifier): count_placeholder_fields() helper for drop-logic
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 16:06:32 +05:00
Vladimir Bryzgalov 1168a733a4 test(classifier): boundary + array-value tests for has_short_latin_name; @return tags
- Add @return bool to has_valid_email_anywhere docblock
- Add @return bool to has_short_latin_name docblock
- Add Cyrillic note to has_short_latin_name docblock
- Add test_has_short_latin_name_true_for_single_letter_boundary (lower bound)
- Add test_has_short_latin_name_false_for_four_letters_boundary (upper bound)
- Add test_has_short_latin_name_false_for_array_value_with_space_join (regression)

Addresses code review feedback from commit 660a0d2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 16:04:18 +05:00
Vladimir Bryzgalov 660a0d2b7c feat(classifier): has_short_latin_name() helper for drop-logic 2026-04-21 16:01:58 +05:00
Vladimir Bryzgalov b5c939e9e4 fix(classifier): iterate all email candidates per field; document method contract
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 15:59:12 +05:00
Vladimir Bryzgalov eae8fafb32 feat(classifier): has_valid_email_anywhere() helper for drop-logic 2026-04-21 15:56:14 +05:00
Vladimir Bryzgalov 8efb82ca43 fix: phone leak, field-by-value detection, strict Flamingo email fallback
Three pilot-surfaced issues in one pass:

1. PhoneParser regex used '\s' in the candidate character class, so a
   digit on a following flattened line bled into the phone. '+7977
   6277470\n1' (phone + trailing checkbox value) parsed as 12 digits,
   producing '+797762774701'. Replaced '\s' with a literal space so
   newlines/tabs stop the candidate.

2. Custom-themed forms don't use 'your-name' / 'your-email' keys
   (washanyanya.ru has text-211 / text-212 / name_user). Added
   FieldDetector::find_name + find_email as fallbacks. Classifier
   and MessageFormatter now call them if no standard key matches,
   so 'Александр' in text-211 is recognised as a cyrillic name and
   scored / displayed accordingly.

3. FlamingoHelper copied '_from_email' into 'your-email' without
   validating it. Flamingo derives that meta from whatever field it
   considers "first"; on phone-first forms it ends up holding the
   phone number. Now we only copy _from_email if it contains '@',
   and dropped the _from_name shortcut entirely — FieldDetector
   handles the name via the actual field values.

Tests: +1 FieldDetectorTest (13 cases); +2 PhoneParserTest cases for
newline/tab bleeds; +1 ClassifierTest case; +1 MessageFormatterTest
case for custom field keys. Full suite 53/53 green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 00:22:39 +05:00
Vladimir Bryzgalov 2de8f0be57 fix(formatter+telegram): drop tel: inline button, mark all 4xx as permanent
Pilot on washanyanya.ru exposed that Telegram Bot API rejects tel:
URLs in inline_keyboard with HTTP 400 "Wrong port number specified
in the URL". Queue was stuck on 5 items retrying the same failure
4 times each.

- MessageFormatter: always returns reply_markup = null. The phone
  number is already rendered in the '📱 ...' line, and mobile
  Telegram clients linkify it automatically.
- TelegramClient::is_permanent: treat all 4xx except 429 as permanent
  client-side errors, so future payload-shape bugs surface in the
  dashboard widget immediately instead of burning five retry cycles.
- MessageFormatterTest updated: the old test asserting tel: in
  reply_markup is replaced with one asserting reply_markup is null
  and the phone still appears in the text body.
- Spec §9 + §19 updated, §19's open question closed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 23:55:06 +05:00
Vladimir Bryzgalov 1f89052f72 fix(flamingo-helper): extract field values from _field_* meta, not _fields
Flamingo's '_fields' meta stores only the list of field NAMES with
null values; the actual values live in separate per-field meta keys
prefixed with '_field_'. The old extract_fields() returned the
null-valued '_fields' array on the first branch and never fell
through to the '_field_*' collector, so every retro Telegram message
showed '(не указан)' / '(пусто)' for every slot.

Also collect '_from_name' / '_from_email' (set by Akismet) as
convenience mappings to 'your-name' / 'your-email' so the formatter's
standard slots are populated for most submissions even when the form
uses custom field names like text-211 / name_user.

Pilot on washanyanya.ru caught this (retro delivered empty skeletons).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 23:46:52 +05:00
Vladimir Bryzgalov 22239321d0 fix(activator): register cron_schedules filter during activation
Dispatcher::register_hooks() runs on plugins_loaded, which is AFTER
register_activation_hook fires. The custom recurrence 'cf7stg_every_minute'
was therefore unknown to wp_schedule_event during activation, and the
'cf7stg_dispatch' event silently failed to schedule — queue items never
got dispatched.

Pilot caught this on washanyanya.ru (23 items queued, 0 sent, 0 failed —
no cron hook firing at all).

Adding the filter directly inside Activator::schedule_events() makes the
custom schedule available in the same request as the wp_schedule_event
call, regardless of bootstrap order.

After updating the plugin, deactivate + reactivate is required to
re-trigger Activator::activate() so events get (re)scheduled.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 23:26:06 +05:00
Vladimir Bryzgalov 0c1be5b4cd feat: plugin bootstrap, autoloader, activation/deactivation hooks 2026-04-17 23:02:20 +05:00
Vladimir Bryzgalov fef22c1ff8 feat(activator): create queue table, schedule cron, guard PHP/WP versions 2026-04-17 22:49:25 +05:00
Vladimir Bryzgalov aa66d15eb5 feat(retro-importer): queue last-N Flamingo spam posts with dedup 2026-04-17 22:48:21 +05:00
Vladimir Bryzgalov eb199c6d40 feat(cf7-source): capture spam submissions via wpcf7_spam and submission status 2026-04-17 22:47:13 +05:00
Vladimir Bryzgalov 4ce2fac42d feat(dispatcher): WP-Cron tick with backoff and retention cleanup 2026-04-17 22:45:38 +05:00
Vladimir Bryzgalov 786a306f29 feat(telegram-client): sendMessage wrapper classifying permanent/transient errors 2026-04-17 22:44:41 +05:00
Vladimir Bryzgalov 1f85d009c4 feat(settings): options wrapper with wp-config constant override 2026-04-17 22:43:36 +05:00
Vladimir Bryzgalov f24cadc799 feat(flamingo-helper): locate flamingo_inbound posts and extract fields/reason 2026-04-17 22:42:38 +05:00
Vladimir Bryzgalov 09f2638066 feat(queue): CRUD, dedup, retention, status counters 2026-04-17 22:41:30 +05:00
Vladimir Bryzgalov cc37aa2647 feat(crypto): AES-256-CBC token encryption via AUTH_KEY 2026-04-17 22:40:08 +05:00
Vladimir Bryzgalov 6961bb1b72 feat(telegram): exception carrying permanent/retry_after flags 2026-04-17 22:39:04 +05:00
Vladimir Bryzgalov d3bd360357 feat(message-formatter): build Telegram HTML payload with inline tel button 2026-04-17 22:37:10 +05:00
Vladimir Bryzgalov 90940dd928 feat(classifier): weighted heuristic for client/unclear/spam scoring 2026-04-17 22:21:10 +05:00
Vladimir Bryzgalov 3dd0f41446 feat(phone-parser): normalize RU phones and extract first candidate 2026-04-17 22:08:57 +05:00
Vladimir Bryzgalov 6068a6a54f feat(domain-formatter): decode punycode hosts to Cyrillic with fallbacks 2026-04-17 22:03:33 +05:00