All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 3m5s
L0 quality detection layer to catch translation failures BEFORE they
reach users. Pure Python/TypeScript, zero new dependencies, no API calls.
Backend (Python — services/quality/):
- Script detection: 145 langs mapped to 23 scripts (Latin, Cyrillic,
Greek, Arabic, Hebrew, CJK, Hangul, Kana, Devanagari, Bengali, etc.)
- Language confusion detection (e.g. Arabic text for French target)
- Arabic-script variant discrimination (Persian/Urdu/Pashto/Kurdish
confusion — e.g. Persian text returned when Arabic was requested)
- Length sanity check (with numeric/short-source exemptions)
- Prompt leak detection (Translation: / Voici la traduction: / 翻译:)
- Repetition hallucination detection (token + character level)
- File text extraction for .docx/.xlsx/.pptx/.pdf (no translator
changes needed)
- Defensive pipeline that never raises (L0 must NEVER break a job)
Frontend (TypeScript — wordly.art---traduction-de-documents/src/utils/):
- Exact 1:1 mirror of the Python module
- Zero dependencies, works in browser AND Node.js
- Native Unicode regex (\\p{L}/u) and codePoint iteration
- 63 tests using Node's built-in test runner
Integration:
- Feature-flagged: QUALITY_L0_ENABLED=false (default)
- Observation only: logs structured events, never modifies files
- try/except wrapped: impossible to break a translation job
- Lazy imports: only loaded when flag is on
- Zero impact on existing tests / behavior
Tests:
- 111 Python tests covering all paths (config, script, length, leak,
pipeline, file_extractor) — 100% pass
- 63 TypeScript tests (Node --test) — 100% pass
- 174/174 total tests for the L0 layer
Bug fixes in script mapping:
- yi (Yiddish) -> hebrew (was incorrectly mapped to arabic)
- dv (Maldivian) -> thaana (was incorrectly mapped to arabic)
- ja (Japanese) -> hiragana_katakana (distinguishes from Chinese CJK)
Phase 1 (backend) + Phase 2 (frontend) of Track A complete.
Next: Track B1 (Word/Excel format preservation quick wins).
Closes Track A phase 1+2 of the dev plan.
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
"""
|
|
Tests for services/quality/pipeline.py
|
|
"""
|
|
import pytest
|
|
|
|
from services.quality import run_l0_check
|
|
from services.quality.script_detector import DocumentQualityResult
|
|
|
|
|
|
class TestRunL0Check:
|
|
def test_returns_result_on_success(self):
|
|
result = run_l0_check(
|
|
["Hello", "World"],
|
|
["Bonjour", "Monde"],
|
|
"fr",
|
|
job_id="test_job_1",
|
|
)
|
|
assert isinstance(result, DocumentQualityResult)
|
|
assert result.passed is True
|
|
assert result.chunk_count == 2
|
|
|
|
def test_returns_neutral_on_empty_lists(self):
|
|
result = run_l0_check([], [], "fr", job_id="test_job_2")
|
|
assert result.passed is True
|
|
assert result.chunk_count == 0
|
|
|
|
def test_detects_failures(self):
|
|
result = run_l0_check(
|
|
["Hello", "World"],
|
|
["Bonjour", "مرحبا"],
|
|
"fr",
|
|
job_id="test_job_3",
|
|
)
|
|
assert result.passed is False
|
|
assert "wrong_script" in result.issues
|
|
|
|
def test_never_raises_on_bad_input(self):
|
|
# Even with weird input, it shouldn't raise
|
|
result = run_l0_check(
|
|
["Hello"],
|
|
[None], # None translation
|
|
"fr",
|
|
job_id="test_job_4",
|
|
)
|
|
assert result is not None
|
|
|
|
def test_optional_job_id(self):
|
|
# job_id is optional
|
|
result = run_l0_check(["hi"], ["salut"], "fr")
|
|
assert result is not None
|
|
|
|
def test_optional_file_extension(self):
|
|
result = run_l0_check(
|
|
["hi"], ["salut"], "fr", file_extension=".docx"
|
|
)
|
|
assert result is not None
|
|
|
|
def test_target_lang_none(self):
|
|
# Should not crash with no target lang
|
|
result = run_l0_check(["hi"], ["salut"], None)
|
|
assert result is not None
|