# Implementation Report — 031-agreement-export-import ### Status DONE ### Покрытые сценарии 1. **Полный цикл Export → Reset → Import** с тремя ДС: - project-wide **draft** (increase); - project-wide **approved** (decrease); - scoped на ведомость **approved** (new_position + increase). 2. **Scope ДС:** `boq_document_id = NULL` и `!= NULL` — восстановление scope на сущности нового проекта. 3. **Lifecycle:** draft остаётся `draft`, approved остаётся `approved`, approved immutable (`_require_draft`). 4. **Типы изменений:** `increase` / `decrease` / `new_position` — все три в архиве и после импорта. 5. **new_position:** AgreementItem + WorkItem (qty 0, `boq_document_id=None`), `source_boq_document_id` remapped, связь AgreementItem → WorkItem восстановлена. 6. **Effective plan до/после:** quantities и amounts идентичны (A=80, B=65, new=5/35). 7. **Export ID:** `export_id` как архивные ключи (`agreement:…`, `work_item:…`), `source_id` только диагностика; внутренние ссылки строковые. 8. **Полный reset:** agreements/items/work_items удалены; импорт создаёт новый проект с полным графом. 9. **Обратная совместимость 025:** архив без `work_journal_entries.json` импортируется (с count 0). ### Тесты Файл: `tests/test_task031_agreement_export_import.py` — **7 тестов**: - `test_export_reset_import_agreements_full_cycle` - `test_export_ids_are_archive_local` - `test_scoped_and_project_wide_both_apply` - `test_draft_stays_draft_and_does_not_affect_plan_after_import` - `test_approved_remains_immutable_after_import` - `test_old_archive_without_work_journal_still_imports` - `test_reset_clears_agreements_and_items` Результат `pytest -q`: ``` 322 passed, 284 warnings in 26.91s ``` (315 существующих + 7 новых.) Результат `git diff --check`: ``` (без ошибок) ``` ### Export → Reset → Import | Шаг | Результат | |---|---| | Export: 3 agreements, 4 items (increase/decrease/new_position) | ✓ | | Scope: project-wide NULL, scoped → boq_document_export_id | ✓ | | Statuses draft/approved в архиве | ✓ | | Reset: 0 agreements/items/work_items/projects | ✓ | | Import: 3 agreements с верными status/scope | ✓ | | Remapping WorkItem / BoqDocument / source_boq | ✓ | | Effective plan: A 80 / B 65 / new 5 (amount 35) | ✓ | | Backward compat без work_journal_entries | ✓ | ### Обнаруженные дефекты Не обнаружено. Замечание (не дефект): после Reset SQLite может переиспользовать числовые ID (1, 2, 3…). Тесты корректно проверяют принадлежность сущностей импортированному проекту и разрешение ссылок внутри проекта, а не неравенство старых/новых ID. ### Production-код **Не изменялся.** Только тесты + отчёт. ### Deviations None.