generated from john/python-template
This commit is contained in:
@@ -121,3 +121,105 @@ async def test_retranscription_job_locks_source_and_frozen_model(default_session
|
||||
assert loaded.model == "vendor/alternate"
|
||||
assert loaded.user_prompt == "Transcribe verbatim."
|
||||
assert [link.source_id for link in loaded.job_sources] == [source.id]
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@pytest.mark.asyncio
|
||||
async def test_promoting_candidate_does_not_mutate_execution_attempt_history(default_session_factory):
|
||||
settings = Settings(openrouter_api_key="test-key", provider_models=None)
|
||||
services = _services(default_session_factory, settings)
|
||||
source = await _seed_source(services)
|
||||
|
||||
first_job = await services.jobs.create_job(Job(document_id=source.document_id))
|
||||
second_job = await services.jobs.create_job(Job(document_id=source.document_id))
|
||||
await services.sources.create_job_source(JobSource(job_id=first_job.id, source_id=source.id))
|
||||
await services.sources.create_job_source(JobSource(job_id=second_job.id, source_id=source.id))
|
||||
|
||||
await services.sources.update_job_source_transcription(
|
||||
job_id=first_job.id,
|
||||
source_id=source.id,
|
||||
text="baseline",
|
||||
provider="fixture",
|
||||
model="model-a",
|
||||
)
|
||||
await services.sources.update_job_source_transcription(
|
||||
job_id=second_job.id,
|
||||
source_id=source.id,
|
||||
text="candidate",
|
||||
provider="fixture",
|
||||
model="model-b",
|
||||
)
|
||||
|
||||
before = [
|
||||
(
|
||||
attempt.id,
|
||||
attempt.job_id,
|
||||
attempt.source_id,
|
||||
attempt.attempt_number,
|
||||
attempt.status.value,
|
||||
attempt.raw_transcription,
|
||||
attempt.error_category,
|
||||
attempt.error_detail,
|
||||
attempt.failure_phase,
|
||||
)
|
||||
for attempt in await services.evidence.list_execution_attempts(source_id=source.id)
|
||||
]
|
||||
|
||||
candidate = next(
|
||||
attempt
|
||||
for attempt in await services.evidence.list_execution_attempts(source_id=source.id)
|
||||
if attempt.raw_transcription == "candidate"
|
||||
)
|
||||
await services.evidence.promote_machine_attempt(source_id=source.id, execution_attempt_id=candidate.id)
|
||||
|
||||
after = [
|
||||
(
|
||||
attempt.id,
|
||||
attempt.job_id,
|
||||
attempt.source_id,
|
||||
attempt.attempt_number,
|
||||
attempt.status.value,
|
||||
attempt.raw_transcription,
|
||||
attempt.error_category,
|
||||
attempt.error_detail,
|
||||
attempt.failure_phase,
|
||||
)
|
||||
for attempt in await services.evidence.list_execution_attempts(source_id=source.id)
|
||||
]
|
||||
|
||||
assert after == before
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@pytest.mark.asyncio
|
||||
async def test_retry_appends_new_attempt_instead_of_rewriting_history(default_session_factory):
|
||||
settings = Settings(openrouter_api_key="test-key", provider_models=None)
|
||||
services = _services(default_session_factory, settings)
|
||||
source = await _seed_source(services)
|
||||
|
||||
job = await services.jobs.create_job(Job(document_id=source.document_id))
|
||||
await services.sources.create_job_source(JobSource(job_id=job.id, source_id=source.id))
|
||||
|
||||
await services.sources.update_job_source_transcription(
|
||||
job_id=job.id,
|
||||
source_id=source.id,
|
||||
text=None,
|
||||
error_detail="timeout",
|
||||
error_category="timeout",
|
||||
provider="fixture",
|
||||
model="model-a",
|
||||
failure_phase="provider_call",
|
||||
)
|
||||
await services.sources.update_job_source_transcription(
|
||||
job_id=job.id,
|
||||
source_id=source.id,
|
||||
text="retry-success",
|
||||
provider="fixture",
|
||||
model="model-a",
|
||||
)
|
||||
|
||||
attempts = list(await services.evidence.list_execution_attempts(source_id=source.id))
|
||||
assert len(attempts) == 2
|
||||
assert [attempt.attempt_number for attempt in attempts] == [1, 2]
|
||||
assert attempts[0].raw_transcription is None
|
||||
assert attempts[1].raw_transcription == "retry-success"
|
||||
|
||||
Reference in New Issue
Block a user