v5.0 Introduce centralized homepage & portrait photo management
Quality Gate / gate (push) Failing after 11s

This commit is contained in:
Jim Lancaster
2026-08-23 09:11:36 -05:00
parent efe7785392
commit 86b8e83ff4
26 changed files with 835 additions and 343 deletions
+2
View File
@@ -30,6 +30,7 @@ from transcription.db.models import JobSource
from transcription.db.models import JobSourceStatus
from transcription.db.models import JobStatus
from transcription.db.models import Person
from transcription.db.models import Photo
from transcription.db.models import Source
from transcription.db.models import Tag
@@ -80,6 +81,7 @@ async def clear_ui_database(
await session.exec(delete(Source))
await session.exec(delete(Job))
await session.exec(delete(Document))
await session.exec(delete(Photo))
await session.exec(delete(Person))
await session.exec(delete(Tag))
await session.commit()
+12 -40
View File
@@ -1,64 +1,36 @@
"""Homepage storage resolves its root from settings rather than from `__file__`.
"""Homepage markdown storage tests."""
The previous module derived its directory from ``Path(__file__).parents[3]``,
which could not be configured and resolved into the installed package directory
outside a source checkout.
"""
import pytest
from pathlib import Path
from transcription.config import Settings
from transcription.ui.homepage_store import homepage_dir
from transcription.ui.homepage_store import latest_homepage_image
from transcription.ui.homepage_store import list_homepage_images
from transcription.ui.homepage_store import homepage_markdown_path
from transcription.ui.homepage_store import read_homepage_markdown
from transcription.ui.homepage_store import save_homepage_markdown
from transcription.ui.homepage_store import store_homepage_image
PNG_BYTES = bytes.fromhex(
"89504e470d0a1a0a0000000d49484452000000010000000108060000001f15c4890000000a49444154789c6360000002000100"
"05fe02fea7b1b8000000004945"
) + b"NDAE\xae\x42\x60\x82"
def _settings(tmp_path) -> Settings:
return Settings(openrouter_api_key="test-key-abc123", homepage_dir=tmp_path / "homepage")
def _settings(tmp_path: Path) -> Settings:
return Settings(openrouter_api_key="test-key-abc123", upload_dir=tmp_path / "uploads")
def test_homepage_dir_follows_the_configured_setting(tmp_path):
def test_markdown_path_uses_upload_dir_root(tmp_path):
settings = _settings(tmp_path)
assert homepage_dir(settings) == tmp_path / "homepage"
assert homepage_markdown_path(settings) == tmp_path / "uploads" / "homepage.md"
def test_markdown_round_trips_through_the_configured_directory(tmp_path):
def test_markdown_round_trip_uses_upload_dir_root(tmp_path):
settings = _settings(tmp_path)
assert read_homepage_markdown(settings) == ""
save_homepage_markdown("# Archive", settings)
assert (tmp_path / "homepage" / "homepage.md").read_text(encoding="utf-8") == "# Archive"
assert (tmp_path / "uploads" / "homepage.md").read_text(encoding="utf-8") == "# Archive"
assert read_homepage_markdown(settings) == "# Archive"
@pytest.mark.asyncio
async def test_images_are_stored_and_listed_from_the_configured_directory(tmp_path):
settings = _settings(tmp_path)
assert list_homepage_images(settings) == []
assert latest_homepage_image(settings) is None
stored = await store_homepage_image(filename="banner.png", file_bytes=PNG_BYTES, settings=settings)
assert stored.parent == tmp_path / "homepage"
assert list_homepage_images(settings) == [stored]
assert latest_homepage_image(settings) == stored
def test_two_configurations_do_not_share_storage(tmp_path):
first = Settings(openrouter_api_key="test-key-abc123", homepage_dir=tmp_path / "a")
second = Settings(openrouter_api_key="test-key-abc123", homepage_dir=tmp_path / "b")
def test_two_configurations_do_not_share_markdown_storage(tmp_path):
first = Settings(openrouter_api_key="test-key-abc123", upload_dir=tmp_path / "a")
second = Settings(openrouter_api_key="test-key-abc123", upload_dir=tmp_path / "b")
save_homepage_markdown("first", first)
+14 -9
View File
@@ -12,6 +12,7 @@ from transcription.db.models import Document
from transcription.db.models import DocumentPerson
from transcription.db.models import Person
from transcription.db.models import PersonRole
from transcription.db.models import Photo
from transcription.db.models import Source
@@ -99,7 +100,6 @@ class TestPeoplePageRendering:
death_date_raw="1992",
death_place="Arlington",
biography="Computer pioneer",
portrait_path="/images/grace.jpg",
family_search_id="G8T4-MDQ",
)
session.add(person)
@@ -132,20 +132,25 @@ class TestPeoplePageRendering:
assert "No linked documents yet." in response.text
@pytest.mark.asyncio
async def test_person_detail_page_resolves_relative_portrait_path(self, app_client):
async def test_person_detail_page_resolves_relative_photo_path(self, app_client):
app, client = app_client
upload_dirs = {app.state.settings.upload_dir, get_settings().upload_dir}
for upload_dir in upload_dirs:
portrait_file = upload_dir / "persons" / "person" / "seeded.png"
portrait_file.parent.mkdir(parents=True, exist_ok=True)
portrait_file.write_bytes(b"portrait")
photo_file = upload_dir / "photos" / "seeded.png"
photo_file.parent.mkdir(parents=True, exist_ok=True)
photo_file.write_bytes(b"portrait")
async with session_scope() as session:
person = Person(
full_name="Portrait Person",
portrait_path="persons/person/seeded.png",
)
person = Person(full_name="Portrait Person")
session.add(person)
await session.flush()
session.add(
Photo(
person_id=person.id,
path="photos/seeded.png",
is_primary=True,
)
)
await session.commit()
person_id = str(person.id)