97 lines
2.6 KiB
Python
97 lines
2.6 KiB
Python
import json
|
|
|
|
from audita.config import AuditaConfig
|
|
from audita.pipeline import process_transcript
|
|
from audita.schemas import CorrectionCandidate, CorrectionSet, parse_glossary_yaml, parse_transcript_json
|
|
|
|
|
|
class FakeLLMClient:
|
|
def __init__(self, responses):
|
|
self.responses = list(responses)
|
|
self.calls = 0
|
|
|
|
def create_corrections(self, messages, config):
|
|
self.calls += 1
|
|
return self.responses.pop(0)
|
|
|
|
|
|
def _config(tmp_path):
|
|
return AuditaConfig(
|
|
api_key="key",
|
|
max_section_tokens=16000,
|
|
confidence_threshold=0.8,
|
|
max_retries=3,
|
|
work_dir=tmp_path / "work",
|
|
)
|
|
|
|
|
|
def _glossary():
|
|
return parse_glossary_yaml(
|
|
"""
|
|
glossary:
|
|
- name: "Chauntea"
|
|
category: deity
|
|
summary: "Chauntea is a deity."
|
|
"""
|
|
)
|
|
|
|
|
|
def _transcript():
|
|
return parse_transcript_json(
|
|
"""
|
|
[
|
|
{"speaker": "Eric", "start": 0.0, "end": 1.0, "text": "I ask Chontia."}
|
|
]
|
|
"""
|
|
)
|
|
|
|
|
|
def test_pipeline_processes_with_fake_llm_and_cleans_work_dir(tmp_path):
|
|
correction = CorrectionCandidate(
|
|
segment_id=0,
|
|
original_text="Chontia",
|
|
corrected_text="Chauntea",
|
|
confidence=0.95,
|
|
)
|
|
fake_client = FakeLLMClient([CorrectionSet(corrections=[correction])])
|
|
|
|
revised = process_transcript(
|
|
_transcript(),
|
|
_glossary(),
|
|
_config(tmp_path),
|
|
llm_client=fake_client,
|
|
)
|
|
|
|
assert revised[0].text == "I ask Chauntea."
|
|
assert fake_client.calls == 1
|
|
assert list((tmp_path / "work").iterdir()) == []
|
|
|
|
|
|
def test_pipeline_skips_bad_correction_and_preserves_diagnostics(tmp_path):
|
|
correction = CorrectionCandidate(
|
|
segment_id=0,
|
|
original_text="Different text.",
|
|
corrected_text="Chauntea",
|
|
confidence=0.95,
|
|
)
|
|
fake_client = FakeLLMClient([CorrectionSet(corrections=[correction])])
|
|
progress = []
|
|
|
|
revised = process_transcript(
|
|
_transcript(),
|
|
_glossary(),
|
|
_config(tmp_path),
|
|
llm_client=fake_client,
|
|
progress=progress.append,
|
|
)
|
|
|
|
assert revised[0].text == "I ask Chontia."
|
|
assert any("Skipping correction for segment 0" in message for message in progress)
|
|
preserved = list((tmp_path / "work").iterdir())
|
|
assert len(preserved) == 1
|
|
skipped_path = preserved[0] / "skipped-corrections.json"
|
|
assert skipped_path.exists()
|
|
diagnostics = json.loads(skipped_path.read_text(encoding="utf-8"))
|
|
assert diagnostics["skipped_corrections"][0]["segment_id"] == 0
|
|
assert "does not match any substring" in diagnostics["skipped_corrections"][0]["reason"]
|