"""Homepage storage resolves its root from settings rather than from `__file__`. 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 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 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 test_homepage_dir_follows_the_configured_setting(tmp_path): settings = _settings(tmp_path) assert homepage_dir(settings) == tmp_path / "homepage" def test_markdown_round_trips_through_the_configured_directory(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 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") save_homepage_markdown("first", first) assert read_homepage_markdown(second) == ""