Phase 1 - minor fix to Sources page
Quality Gate / gate (push) Failing after 11s

This commit is contained in:
Jim Lancaster
2026-08-20 15:14:34 -05:00
parent 7daa0b9808
commit afd1dba4d4
8 changed files with 165 additions and 28 deletions
+60
View File
@@ -5,6 +5,7 @@ import warnings
import pytest
import sqlalchemy as sa
from sqlalchemy import inspect
from sqlalchemy import text
from sqlalchemy.dialects import postgresql
from sqlalchemy.exc import SAWarning
from sqlmodel import SQLModel
@@ -16,8 +17,13 @@ from transcription.config import SqliteSettings
from transcription.db import create_all
from transcription.db import dispose_database_runtime
from transcription.db import initialize_database_runtime
from transcription.db import normalize_legacy_status_spellings
from transcription.db import session_scope
from transcription.db.models import Document
from transcription.db.models import DocumentType
from transcription.db.models import Job
from transcription.db.models import JobSource
from transcription.db.models import JobSourceStatus
from transcription.db.models import PersonRole
from transcription.db.models import Source
@@ -151,6 +157,60 @@ async def test_create_all_declares_hot_path_indexes(tmp_path):
await dispose_database_runtime()
@pytest.mark.asyncio
async def test_normalize_legacy_status_spellings_repairs_job_source_status_rows(tmp_path):
settings = Settings(
openrouter_api_key="test-key",
database=SqliteSettings(path=str(tmp_path / "legacy-status.db")),
environment="test",
)
runtime = initialize_database_runtime(settings=settings)
try:
await create_all(engine=runtime.engine)
async with AsyncSession(runtime.engine, expire_on_commit=False) as session:
document = Document(name="legacy-status-doc")
session.add(document)
await session.flush()
job = Job(document_id=document.id)
session.add(job)
await session.flush()
source = Source(
document_id=document.id,
page_number=1,
upload_name="legacy.jpg",
filename="legacy.jpg",
file_path="uploads/legacy.jpg",
file_hash="a" * 64,
file_size_bytes=1,
)
session.add(source)
await session.flush()
job_source = JobSource(job_id=job.id, source_id=source.id, status=JobSourceStatus.PENDING)
session.add(job_source)
await session.commit()
await session.refresh(job_source)
async with runtime.engine.begin() as connection:
await connection.execute(
text('update "job_source" set status = :status where status = :expected'),
{"status": "TRANSCRIBED", "expected": JobSourceStatus.PENDING.value},
)
fixed_rows = await normalize_legacy_status_spellings(engine=runtime.engine)
assert fixed_rows == 1
async with runtime.engine.connect() as connection:
status = (
await connection.execute(
text('select status from "job_source"'),
)
).scalar_one()
assert status == "transcribed"
finally:
await dispose_database_runtime()
def test_metadata_has_no_unresolvable_table_cycle():
"""create_all must be able to order every table, including on PostgreSQL."""
with warnings.catch_warnings():