test-infra: add real-DB integration test gate for site_finder services #197

Closed
opened 2026-05-16 09:01:37 +00:00 by lekss361 · 1 comment
Owner

Эшелон: 🟢 Test infrastructure / Schema-drift prevention
Triggered by: review-bot verdict на PR #196 (#113 PR C) — 🔴 critical bug domrf_kn_objects.geom_3857 (column не существует) прошёл все 10 mock tests т.к. SQL не выполнялся.

Контекст / pattern

Это второй случай того же класса bug'а:

  • 2026-05-26 — fixes/Fix_Competitors_Schema_Mismatch_May26.md — PR #112 competitors.py — 4 critical schema mismatch'а, пойманы reviewer'ом
  • 2026-05-16 — PR #196 best_layouts.py — geom_3857 phantom column, пойман reviewer'ом

Root cause repeating pattern: worker пишет mock-tests которые db.execute.side_effect = [MagicMock, ...] — это не trigger'ит SQL parsing на DB → schema drift / typo / wrong column names не ловятся unit tests. Reviewer ловит вручную через mcp__postgres-gendesign__list_objects + grep.

Что сделать

Phase 1: pytest fixture для real DB integration tests (0.5-1 день)

backend/tests/conftest.py (NEW):

  • pytest_addoption для --db-live flag
  • db_live fixture connecting к local prod-snapshot Postgres (через DATABASE_URL или dedicated TEST_DATABASE_URL)
  • Auto-skip integration tests если --db-live не передан → CI/dev workflow не сломан

Phase 2: smoke integration tests для site_finder services (1 день)

Минимум:

  • tests/integration/test_best_layouts_integration.py — 2-3 теста: high-density EKB cad → non-empty response, low-density → empty graceful, confidence field reasonable
  • tests/integration/test_competitors_integration.py — same pattern для #112
  • tests/integration/test_connection_points_integration.py — для #115

Подход: test fixture creates httpx.AsyncClient(app=app) → real db session → endpoint вызывается с real test cad'ом → assertions на shape, не точные values (т.к. data меняется).

Phase 3: CI gate (опционально, 0.5 дня)

.github/workflows/ci.yml — добавить job integration-tests который:

  • Setup postgres service (уже есть)
  • Применяет migrations
  • Загружает small EKB dataset (анонимизированный snapshot, ~10MB)
  • Run pytest --db-live -m integration

ИЛИ — оставить integration tests opt-in через manual --db-live (devs runs locally before push), CI gate отложить до Phase 2 validation.

Acceptance

  • conftest.py с --db-live + db_live fixture
  • 3 integration test файла (best_layouts, competitors, connection_points) — minimum 2 теста каждый
  • Tests passing локально через cd backend && uv run pytest --db-live tests/integration -v
  • README обновлён с инструкциями how to run integration tests
  • (Optional Phase 3) CI gate

Owner

backend-engineer + devops-engineer (Phase 3)

Effort

~1.5-2 дня (Phase 1+2). Phase 3 опционально.

Why important

  • Repeating bug class — без integration gate третий PR в site_finder поймает ту же ловушку
  • Cheap fixpytest fixture + 6 integration tests = критически малая investment vs cost от prod 500 errors
  • MV / view schema drift — после migration N будут breaking changes которые mock не поймают
  • Triggered by: #196 (#113 PR C re-review)
  • Similar prior: vault fixes/Fix_Competitors_Schema_Mismatch_May26.md
  • Plan agent для #113 уже flagged: "после deploy — qa-tester post-deploy smoke" — это manual proxy, нужен automated.
**Эшелон:** 🟢 Test infrastructure / Schema-drift prevention **Triggered by:** review-bot verdict на PR #196 (#113 PR C) — 🔴 critical bug `domrf_kn_objects.geom_3857` (column не существует) прошёл все 10 mock tests т.к. SQL не выполнялся. ## Контекст / pattern Это **второй случай** того же класса bug'а: - 2026-05-26 — `fixes/Fix_Competitors_Schema_Mismatch_May26.md` — PR #112 competitors.py — 4 critical schema mismatch'а, пойманы reviewer'ом - 2026-05-16 — PR #196 best_layouts.py — `geom_3857` phantom column, пойман reviewer'ом **Root cause repeating pattern:** worker пишет mock-tests которые `db.execute.side_effect = [MagicMock, ...]` — это **не trigger'ит SQL parsing на DB** → schema drift / typo / wrong column names не ловятся unit tests. Reviewer ловит вручную через `mcp__postgres-gendesign__list_objects` + grep. ## Что сделать ### Phase 1: pytest fixture для real DB integration tests (0.5-1 день) **`backend/tests/conftest.py`** (NEW): - `pytest_addoption` для `--db-live` flag - `db_live` fixture connecting к local prod-snapshot Postgres (через `DATABASE_URL` или dedicated `TEST_DATABASE_URL`) - Auto-skip integration tests если `--db-live` не передан → CI/dev workflow не сломан ### Phase 2: smoke integration tests для site_finder services (1 день) Минимум: - `tests/integration/test_best_layouts_integration.py` — 2-3 теста: high-density EKB cad → non-empty response, low-density → empty graceful, `confidence` field reasonable - `tests/integration/test_competitors_integration.py` — same pattern для #112 - `tests/integration/test_connection_points_integration.py` — для #115 **Подход:** test fixture creates `httpx.AsyncClient(app=app)` → real `db` session → endpoint вызывается с real test cad'ом → assertions на shape, не точные values (т.к. data меняется). ### Phase 3: CI gate (опционально, 0.5 дня) `.github/workflows/ci.yml` — добавить job `integration-tests` который: - Setup postgres service (уже есть) - Применяет migrations - Загружает small EKB dataset (анонимизированный snapshot, ~10MB) - Run `pytest --db-live -m integration` ИЛИ — оставить integration tests opt-in через manual `--db-live` (devs runs locally before push), CI gate отложить до Phase 2 validation. ## Acceptance - [ ] `conftest.py` с `--db-live` + `db_live` fixture - [ ] 3 integration test файла (best_layouts, competitors, connection_points) — minimum 2 теста каждый - [ ] Tests passing локально через `cd backend && uv run pytest --db-live tests/integration -v` - [ ] README обновлён с инструкциями how to run integration tests - [ ] (Optional Phase 3) CI gate ## Owner `backend-engineer` + `devops-engineer` (Phase 3) ## Effort ~1.5-2 дня (Phase 1+2). Phase 3 опционально. ## Why important - **Repeating bug class** — без integration gate третий PR в site_finder поймает ту же ловушку - **Cheap fix** — `pytest fixture` + 6 integration tests = критически малая investment vs cost от prod 500 errors - **MV / view schema drift** — после migration N будут breaking changes которые mock не поймают ## Links - Triggered by: https://git.gendsgn.ru/lekss361/gendesign/pulls/196 (#113 PR C re-review) - Similar prior: vault `fixes/Fix_Competitors_Schema_Mismatch_May26.md` - Plan agent для #113 уже flagged: "после deploy — `qa-tester` post-deploy smoke" — это manual proxy, нужен automated.
Author
Owner

Working on this in PR #216.

Working on this in PR #216.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lekss361/gendesign#197
No description provided.