refactor: move services to a unit of work over repository ports

Services depend only on src/core/ports: async with self.uow is one
transaction, commit is explicit, leaving without it rolls back. A
connection is held per step, the JSON routers keep a shared request
deadline, and rollback runs under the block deadline. Adds
service-tests with fakes, a repo contract run on both the fake and SQL,
and make service_test / service_test_db. API, schema and settings are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-31 23:14:16 +03:00
co-authored by Claude Opus 5.5
parent b2fb88f25a
commit 6ba74b18f3
90 changed files with 10882 additions and 2030 deletions
+14
View File
@@ -487,6 +487,20 @@ bench_ab:
student_test:
BASE_URL=$(BASE_URL) EXPECT_REPLICAS=$(EXPECT_REPLICAS) uv run pytest
# быстрые тесты сервисов на фейках: без PostgreSQL, Valkey, S3, брокера, docker
# и сети (design change unit-of-work, решение 13). Каталог вне student-tests:
# правило black-box там прежнее
.PHONY: service_test
service_test:
uv run pytest -c service-tests/pytest.ini service-tests/unit
# настоящая единица работы, тот же набор условий repo на SQL и общий срок запроса
# на временной базе test_uow_<db> в PostgreSQL стенда; база создаётся и мигрирует
# в начале, удаляется при любом исходе, рабочая база не затрагивается
.PHONY: service_test_db
service_test_db: start_db
uv run pytest -c service-tests/pytest.ini service-tests/db
# образ на временной базе test_<POSTGRES_DB>: сборка, миграции, отдельный
# контейнер api на 127.0.0.1:TEST_APP_PORT, make test и make student_test,
# затем уборка при любом исходе. KEEP_TEST_DB=1 оставляет базу и объекты