SurfSense/surfsense_backend/tests/unit/services
DESKTOP-RTLN3BA\$punk bdacea8b6e feat(crawler): captcha solving + per-attempt billing (Phase 3d)
Wire captchatools as the StealthyFetcher-tier page_action to detect, harvest
(egressing from the crawl's own proxy IP), inject, and submit reCAPTCHA v2/v3
and hCaptcha tokens. Opt-in and off by default (zero attempts, zero cost).

Licensing split:
- Apache-2 app/utils/captcha/ holds the generic, vendor-agnostic config
  (CaptchaConfig + captcha_enabled() = flag AND key present).
- Proprietary app/proprietary/web_crawler/captcha.py holds the bypass logic
  (detect/harvest/inject) plus a process-wide solver latch that halts solving
  on unrecoverable errors (no balance / bad key).

Crawler: CrawlOutcome gains captcha_attempts/captcha_solved, surfaced via a
per-call captcha_state dict threaded crawl_url -> _crawl_with_stealthy(_sync)
and stamped onto every stealth terminal outcome. The stealth tier captures the
proxy once and reuses it for both the fetch and the solver (IP-coherence).

Billing: WebCrawlCreditService gains captcha_billing_enabled,
captcha_solves_to_micros, charge_captcha, and a generic check_balance, sharing
a single _apply_debit path. The indexer accumulates attempts (even on failed
crawls), runs a combined crawl+captcha pre-flight, and posts a per-attempt
owner charge as usage_type="web_crawl_captcha". The captcha worst-case is only
reserved when solving is actually enabled, so a solving-off deployment is never
blocked for captcha that can never run. Both chat scrape tools fold attempts
into the current turn before the success/fail branch.

Fully config-driven prices; no migration. New unit tests cover the config,
factory (detection/latch/timeout/cap), credit service, indexer wiring, and the
chat fold.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 22:58:21 -07:00
..
streaming feat: improved document, folder mentions rendering 2026-05-09 22:15:51 -07:00
__init__.py test: add unit tests for Dropbox integration, covering delta sync methods, file type filtering, and re-authentication behavior 2026-04-06 18:36:48 +05:30
test_agent_billing_resolver.py test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F) 2026-06-26 18:36:46 +02:00
test_ai_file_sort_service.py feat: added ai file sorting 2026-04-14 01:43:30 -07:00
test_ai_sort_task_dedupe.py test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F) 2026-06-26 18:36:46 +02:00
test_auto_model_pin_service.py test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F) 2026-06-26 18:36:46 +02:00
test_auto_pin_image_aware.py test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F) 2026-06-26 18:36:46 +02:00
test_billable_call.py test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F) 2026-06-26 18:36:46 +02:00
test_docling_image_support.py chore: ran linting 2026-04-07 05:55:39 +05:30
test_folder_hierarchy.py feat: added ai file sorting 2026-04-14 01:43:30 -07:00
test_image_gen_api_base_defense.py test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F) 2026-06-26 18:36:46 +02:00
test_llm_router_pool_filter.py refactor(provider-configuration): standardize provider parameter naming across various modules and improve quota error handling in tests 2026-06-13 14:23:32 +05:30
test_memory_service.py feat: add no-update sentinel handling to save_memory function and corresponding unit tests 2026-05-20 15:03:35 +05:30
test_model_connections.py feat: antropic model added fix & kb tooling fixes 2026-06-25 20:19:44 -07:00
test_openrouter_integration_service.py chore: ran linting 2026-06-13 21:59:35 +05:30
test_openrouter_legacy_config.py chore: ran linting 2026-05-02 03:36:13 +05:30
test_or_health_enrichment.py refactor(provider-configuration): standardize provider parameter naming across various modules and improve quota error handling in tests 2026-06-13 14:23:32 +05:30
test_pricing_registration.py chore: ran linting 2026-06-13 21:59:35 +05:30
test_provider_capabilities.py refactor(provider-configuration): standardize provider parameter naming across various modules and improve quota error handling in tests 2026-06-13 14:23:32 +05:30
test_quality_score.py feat(database-migrations): add migration to remove legacy model config tables and remove stale model connection code 2026-06-13 12:45:43 +05:30
test_quota_checked_vision_llm.py test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F) 2026-06-26 18:36:46 +02:00
test_revert_filesystem_tools.py test: rename SearchSpace -> Workspace across tests + fixtures (Phase 2 Wave F) 2026-06-26 18:36:46 +02:00
test_revert_service.py chore: cleaned comments slop 2026-04-28 23:52:37 -07:00
test_supports_image_input.py refactor(agents): consolidate chat runtime infra under chat/runtime 2026-06-05 13:19:24 +02:00
test_token_quota_service_cost.py feat(token-tracking): enhance model metadata reconciliation by adding bare model name handling 2026-06-14 12:18:22 +05:30
test_web_crawl_credit_service.py feat(crawler): captcha solving + per-attempt billing (Phase 3d) 2026-06-29 22:58:21 -07:00