FastAPI + Celery + Next.js + Postgres/Redis app with company monitoring, source collection, LLM-based change analysis, enrichment, and account security (Turnstile, escalating lockout, email verification).
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from app.change_detection.text_diff import bounded_text_diff
|
|
|
|
|
|
def test_identical_text_has_zero_diff_ratio():
|
|
text = "Acme Corp builds electric trucks.\nWe are hiring engineers."
|
|
result = bounded_text_diff(text, text)
|
|
assert result.diff_ratio == 0.0
|
|
assert result.is_identical is True
|
|
|
|
|
|
def test_changed_text_has_nonzero_diff_ratio_and_captures_lines():
|
|
previous = "Acme Corp builds gasoline trucks.\nContact us for a quote."
|
|
current = "Acme Corp builds electric trucks.\nContact us for a quote."
|
|
result = bounded_text_diff(previous, current)
|
|
assert result.diff_ratio > 0.0
|
|
assert any("electric" in line for line in result.added_lines)
|
|
assert any("gasoline" in line for line in result.removed_lines)
|
|
|
|
|
|
def test_noise_only_changes_do_not_register_as_a_diff():
|
|
previous = "About us.\nUpdated: 2026-01-01 10:00\nWe build trucks."
|
|
current = "About us.\nUpdated: 2026-06-15 14:30\nWe build trucks."
|
|
result = bounded_text_diff(previous, current)
|
|
assert result.diff_ratio == 0.0
|
|
|
|
|
|
def test_diff_is_bounded_in_size():
|
|
previous = "\n".join(f"line {i} original" for i in range(200))
|
|
current = "\n".join(f"line {i} changed" for i in range(200))
|
|
result = bounded_text_diff(previous, current)
|
|
assert len(result.added_lines) <= 40
|
|
assert len(result.removed_lines) <= 40
|