Github Copilot service realignment & cleanup

This commit is contained in:
Jim Lancaster
2026-08-11 16:02:19 -05:00
parent 0ace10269f
commit 8d5aec4301
22 changed files with 1641 additions and 1344 deletions
+24 -17
View File
@@ -2,23 +2,24 @@ from __future__ import annotations
from datetime import UTC
from datetime import datetime
from pathlib import Path
from uuid import uuid4
import pytest
from sqlmodel import select
from transcription.db.models import Document
from transcription.db.models import Job
from transcription.db.models import DocumentPerson
from transcription.db.models import DocumentPersonRole
from transcription.db.models import DocumentType
from transcription.db.models import Job
from transcription.db.models import Person
from transcription.db.models import PersonRole
from transcription.db.models import Source
from transcription.services.documents import DocumentDeleteBlockedError
from transcription.services.documents import DocumentError
from transcription.services.documents import DocumentService
from transcription.services.people import PeopleError
from transcription.services.people import PeopleService
@pytest.mark.asyncio
@@ -123,6 +124,7 @@ async def test_delete_document_succeeds_when_unlinked(default_session_factory, t
@pytest.mark.asyncio
async def test_delete_document_removes_person_links(default_session_factory, tmp_path):
service = DocumentService(session_factory=default_session_factory)
people_service = PeopleService(session_factory=default_session_factory)
service.settings.upload_dir = tmp_path
document = await service.create_document(
@@ -132,8 +134,8 @@ async def test_delete_document_removes_person_links(default_session_factory, tmp
document_type="memo",
)
)
person = await service.create_person(Person(full_name="Linked Person"))
await service.create_document_person(
person = await people_service.create_person(Person(full_name="Linked Person"))
await people_service.create_document_person(
DocumentPerson(
document_id=document.id,
person_id=person.id,
@@ -141,7 +143,7 @@ async def test_delete_document_removes_person_links(default_session_factory, tmp
)
)
links_before_delete = await service.list_document_people(document_id=document.id)
links_before_delete = await people_service.list_document_people(document_id=document.id)
assert len(links_before_delete) == 1
assert links_before_delete[0].role_id is not None
assert links_before_delete[0].role_ref is not None
@@ -153,7 +155,7 @@ async def test_delete_document_removes_person_links(default_session_factory, tmp
await service.delete_document(document)
assert not document_dir.exists()
assert await service.list_document_people(document_id=document.id) == []
assert await people_service.list_document_people(document_id=document.id) == []
with pytest.raises(DocumentError):
await service.read_document_detail(document.id)
@@ -189,6 +191,7 @@ async def test_delete_document_removes_populated_storage_tree(default_session_fa
@pytest.mark.asyncio
async def test_read_person_detail_loads_document_links(default_session_factory):
service = DocumentService(session_factory=default_session_factory)
people_service = PeopleService(session_factory=default_session_factory)
document = await service.create_document(
Document(
@@ -197,8 +200,8 @@ async def test_read_person_detail_loads_document_links(default_session_factory):
document_type="letter",
)
)
person = await service.create_person(Person(full_name="Linked Person"))
await service.create_document_person(
person = await people_service.create_person(Person(full_name="Linked Person"))
await people_service.create_document_person(
DocumentPerson(
document_id=document.id,
person_id=person.id,
@@ -206,7 +209,7 @@ async def test_read_person_detail_loads_document_links(default_session_factory):
)
)
detail = await service.read_person_detail(person.id)
detail = await people_service.read_person_detail(person.id)
assert detail.id == person.id
assert len(detail.document_people) == 1
@@ -216,7 +219,7 @@ async def test_read_person_detail_loads_document_links(default_session_factory):
@pytest.mark.asyncio
async def test_update_person_refreshes_updated_timestamp(default_session_factory):
service = DocumentService(session_factory=default_session_factory)
service = PeopleService(session_factory=default_session_factory)
created = await service.create_person(
Person(
@@ -235,9 +238,10 @@ async def test_update_person_refreshes_updated_timestamp(default_session_factory
@pytest.mark.asyncio
async def test_delete_person_removes_links_when_linked_documents_exist(default_session_factory):
service = DocumentService(session_factory=default_session_factory)
documents_service = DocumentService(session_factory=default_session_factory)
service = PeopleService(session_factory=default_session_factory)
document = await service.create_document(
document = await documents_service.create_document(
Document(
id=uuid4(),
name="block-person-delete-doc",
@@ -258,19 +262,19 @@ async def test_delete_person_removes_links_when_linked_documents_exist(default_s
links = await service.list_document_people(person_id=person.id)
assert links == []
with pytest.raises(DocumentError):
with pytest.raises(PeopleError):
await service.read_person_detail(person.id)
@pytest.mark.asyncio
async def test_delete_person_succeeds_when_unlinked(default_session_factory):
service = DocumentService(session_factory=default_session_factory)
service = PeopleService(session_factory=default_session_factory)
person = await service.create_person(Person(full_name="Free Person"))
await service.delete_person(person)
with pytest.raises(DocumentError):
with pytest.raises(PeopleError):
await service.read_person_detail(person.id)
@@ -292,9 +296,12 @@ async def test_create_document_reuses_existing_document_type_registry(default_se
@pytest.mark.asyncio
async def test_update_document_person_sets_role_id_from_legacy_role(default_session_factory):
service = DocumentService(session_factory=default_session_factory)
documents_service = DocumentService(session_factory=default_session_factory)
service = PeopleService(session_factory=default_session_factory)
document = await service.create_document(Document(id=uuid4(), name="role-sync-doc", document_type="letter"))
document = await documents_service.create_document(
Document(id=uuid4(), name="role-sync-doc", document_type="letter")
)
person = await service.create_person(Person(full_name="Role Sync Person"))
link = await service.create_document_person(
DocumentPerson(