v4: 7643 tests passing, 83% raw / 96.9% real coverage (excl __tests__).

12 known failures — all from Agent 3 new unverified tests (mock setup issues):
- 3 dataset_review_routes_extended (DTO field mismatches)
- 1 settings_consolidated (dict key access)
- 1 llm_analysis_service_coverage (rate_limit mock)
- 1 migration_plugin (SessionLocal side_effect exhaustion)
- 1 preview (DB query vs dict key)
- 5 scheduler (datetime timezone + async mock mismatches)

NEW TEST FILES THIS SESSION:
- test_batch_insert_coverage.py — 3 tests
- test_storage_plugin.py — +3 tests
- test_search.py — +2 tests
- test_mapper.py — already 100%
- test_llm_analysis_migration_v1_to_v2.py — 14 tests
- test_llm_async_http.py — +1 test
- test_prompt_builder.py — +1 test
- test_service_datasource.py — +1 test
- test_lang_detect.py — +1 test
- test_scheduler.py — +6 tests
- test_llm_analysis_service_coverage.py — +15 tests
- test_dataset_review_routes_extended.py — +14 tests
- test_settings_consolidated.py — +13 tests

Modules pushed to 100%: _batch_insert, dictionary_entries, service_datasource,
_llm_async_http, prompt_builder, dictionary_crud, _batch_sizer, storage/plugin,
mapper.py

Session: 7194→7643 tests (+449), 80%→83% raw (+3pp), 93.4%→96.9% real (+3.5pp).
Remaining: 12 failures to fix + ~300 statements to reach 98% real coverage.
This commit is contained in:
2026-06-16 09:34:10 +03:00
parent 005ef0f5c7
commit 8a4310169b
28 changed files with 8511 additions and 1 deletions

View File

@@ -32,6 +32,8 @@ def _make_job(session, target_langs=None):
if target_langs:
job.target_languages = target_langs
job.target_dialect = target_langs[0]
# Ensure provider_id is always set so _process_llm enters the try/except block
job.provider_id = "test-provider"
session.commit()
return job
@@ -382,4 +384,56 @@ class TestProcessBatch:
)
assert result["successful"] == 2
assert result.get("cache_hits", 0) == 2
class TestProcessLlmProviderEdgeCases:
"""Cover provider_id edge cases in _process_llm."""
@pytest.mark.asyncio
async def test_process_llm_no_provider_id(self, db_with_run):
"""Edge: job has no provider_id, uses default token config."""
session, run_id = db_with_run
config = MagicMock()
svc = BatchProcessingService(session, config)
job = _make_job(session)
job.provider_id = None # Override to test the no-provider path
rows = _batch_rows(1)
with patch('src.plugins.translate._batch_proc.estimate_token_budget',
return_value={
"max_output_needed": 1000, "max_rows_by_output": 10,
"estimated_input_tokens": 500, "warning": None,
}):
with patch.object(svc._llm_service, 'call_llm_for_batch',
new=AsyncMock(return_value={"successful": 1, "failed": 0,
"skipped": 0, "retries": 0})):
result = await svc._process_llm(
job, run_id, rows, [], "batch-1", ["fr"],
)
assert result["successful"] == 1
@pytest.mark.asyncio
async def test_process_llm_provider_exception(self, db_with_run):
"""Edge: LLMProviderService raises in provider resolution."""
session, run_id = db_with_run
config = MagicMock()
svc = BatchProcessingService(session, config)
job = _make_job(session)
rows = _batch_rows(1)
with patch('src.plugins.translate._batch_proc.LLMProviderService') as MockProv:
mock_instance = MockProv.return_value
mock_instance.get_provider_token_config.side_effect = RuntimeError("API error")
with patch('src.plugins.translate._batch_proc.estimate_token_budget',
return_value={
"max_output_needed": 1000, "max_rows_by_output": 10,
"estimated_input_tokens": 500, "warning": None,
}):
with patch.object(svc._llm_service, 'call_llm_for_batch',
new=AsyncMock(return_value={"successful": 1, "failed": 0,
"skipped": 0, "retries": 0})):
result = await svc._process_llm(
job, run_id, rows, [], "batch-1", ["fr"],
)
assert result["successful"] == 1
# #endregion Test.BatchProcessingService