v4.10 revision to remove "legacy compatibility" code
Quality Gate / gate (push) Failing after 11s

This commit is contained in:
Jim Lancaster
2026-08-22 11:21:18 -05:00
parent cf49c3c127
commit 63c21d4a14
25 changed files with 840 additions and 301 deletions
+59 -59
View File
@@ -17,14 +17,10 @@ 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 reconcile_canonical_media_paths
from transcription.db import reconcile_legacy_job_source_columns
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
@@ -158,60 +154,6 @@ 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()
@pytest.mark.asyncio
async def test_reconcile_legacy_job_source_columns_drops_executed_at(tmp_path):
settings = Settings(
@@ -253,6 +195,64 @@ async def test_reconcile_legacy_job_source_columns_drops_executed_at(tmp_path):
await dispose_database_runtime()
@pytest.mark.asyncio
async def test_reconcile_canonical_media_paths_normalizes_source_and_person_paths(tmp_path):
settings = Settings(
openrouter_api_key="test-key",
database=SqliteSettings(path=str(tmp_path / "canonical-paths.db")),
environment="test",
)
runtime = initialize_database_runtime(settings=settings)
try:
await create_all(engine=runtime.engine)
async with runtime.engine.begin() as connection:
await connection.execute(
text(
'insert into "person" (id, full_name, portrait_path, created_at, updated_at) '
'values (:id, :full_name, :portrait_path, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)'
),
{"id": "11" * 16, "full_name": "Portrait", "portrait_path": "portraits/person/seeded.png"},
)
await connection.execute(
text(
'insert into "document" (id, name, created_at, updated_at) '
'values (:id, :name, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)'
),
{"id": "22" * 16, "name": "Doc"},
)
await connection.execute(
text(
'insert into "source" (id, document_id, page_number, upload_name, filename, file_path, file_hash, file_size_bytes, date_uploaded) '
'values (:id, :document_id, 1, :upload_name, :filename, :file_path, :file_hash, :file_size_bytes, CURRENT_TIMESTAMP)'
),
{
"id": "33" * 16,
"document_id": "22" * 16,
"upload_name": "page.png",
"filename": "page.png",
"file_path": "data\\documents\\doc-1\\page.png",
"file_hash": "a" * 64,
"file_size_bytes": 1,
},
)
changed = await reconcile_canonical_media_paths(engine=runtime.engine)
assert changed == 2
async with runtime.engine.connect() as connection:
source_path = (
await connection.execute(text('select file_path from "source" where id = :id'), {"id": "33" * 16})
).scalar_one()
portrait_path = (
await connection.execute(text('select portrait_path from "person" where id = :id'), {"id": "11" * 16})
).scalar_one()
assert source_path == "documents/doc-1/page.png"
assert portrait_path == "persons/person/seeded.png"
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():