107 lines
9.0 KiB
Markdown
107 lines
9.0 KiB
Markdown
---
|
||
title: 'Исправить drift canonical migration contract после добавления V13'
|
||
type: 'bugfix'
|
||
created: '2026-08-29'
|
||
status: 'done'
|
||
baseline_commit: 'c2556ec236b6b14306c6f2d8674c3c5ada8b704e'
|
||
review_loop_iteration: 0
|
||
context: []
|
||
---
|
||
|
||
<frozen-after-approval reason="human-owned intent — do not modify unless human renegotiates">
|
||
|
||
## Intent
|
||
|
||
**Problem:** CI и release блокируются на `crank-migrate plan --check`: Rust migration authority уже содержит append-only V13, но committed machine contract и связанные CLI-ожидания остались на V12. Из-за точного сравнения планов команда закономерно возвращает `contract_drift` на `plan.compare`.
|
||
|
||
**Approach:** Добавить фактический V13 descriptor в canonical JSON без изменения записей V1–V12, синхронизировать точечные CLI-тесты и operator documentation с current version 13, затем проверить детерминированность и полный migration contract.
|
||
|
||
## Boundaries & Constraints
|
||
|
||
**Always:** Rust `MigrationAuthority::sequence()` остаётся единственным источником истины; committed JSON должен byte-semantically соответствовать сгенерированному plan; V1–V12 неизменяемы; V13 использует уже закреплённые name/checksum/source digest/readability fields; исправление одинаково валидно для CI и release workflow.
|
||
|
||
**Ask First:** Любое изменение SQL V13, descriptor authority, checksum/source digest, migration ordering, compatibility window либо поведения CLI сравнения.
|
||
|
||
**Never:** Удалять V13, ослаблять или пропускать `plan --check`, редактировать исторические descriptors, игнорировать drift, менять PostgreSQL state либо регенерировать contract из недоверенного/непроверенного источника.
|
||
|
||
## I/O & Edge-Case Matrix
|
||
|
||
| Scenario | Input / State | Expected Output / Behavior | Error Handling |
|
||
|----------|---------------|---------------------------|----------------|
|
||
| Canonical check | Authority V1–V13 и committed JSON | `plan --check` возвращает `contract_current` и exit 0 | Любое semantic отличие остаётся `contract_drift` |
|
||
| Deterministic plan | Два последовательных запуска `plan` | JSON plans идентичны и содержат ровно V1–V13 | Нестабильность блокирует исправление |
|
||
| Fresh schema | `apply`, затем `preflight` | Ledger и CLI сообщают current version 13 | Ошибка миграции не маскируется обновлением contract |
|
||
| Historical immutability | Canonical V1–V12 до/после исправления | Старые entries не меняются; добавляется только V13 | Любое изменение истории отклоняется |
|
||
|
||
</frozen-after-approval>
|
||
|
||
## Code Map
|
||
|
||
- `apps/admin-api/src/bin/crank-migrate.rs:154-208` — строит plan из authority и semantic-сравнивает его с committed JSON; менять проверку не требуется.
|
||
- `crates/crank-registry/src/migrations/authority.rs:24-26,258-263` — действующий source of truth: current version 13 и descriptor `artifact-cleanup-indexes-v13` с readable window 12..13.
|
||
- `crates/crank-registry/src/migrations/artifact_cleanup_indexes_v13.rs:5-7` — закрепляет SHA-256 `abe822…ab05`; SQL и digest read-only в этом исправлении.
|
||
- `docs/schemas/migration-sequence.json:1-204` — canonical machine contract сейчас заканчивается V12; добавить только сгенерированный V13 object.
|
||
- `apps/admin-api/tests/migration_command.rs:30-49,68-86` — deterministic plan и fresh-schema preflight имеют устаревшие ожидания `12`.
|
||
- `crates/crank-registry/src/migrations/authority_tests.rs:4-18` — append-only sequence test также имеет устаревший список V1–V12.
|
||
- `crates/crank-registry/tests/integration/migrations.rs:32-55` — уже подтверждает ledger V1–V13; использовать как широкую проверку, не переписывать.
|
||
- `docs/migrations.md:9-20,62-98` — operator flow всё ещё называет current version 12 и не описывает V13.
|
||
- `.gitea/workflows/{ci.yml:70-71,release.yml:66-67}` — оба pipeline уже вызывают правильный gate; workflow read-only.
|
||
|
||
## Tasks & Acceptance
|
||
|
||
**Execution:**
|
||
- [x] `docs/schemas/migration-sequence.json` — добавить точный V13 descriptor из `crank-migrate plan`, сохранив V1–V12 без изменений.
|
||
- [x] `apps/admin-api/tests/migration_command.rs` — синхронизировать sequence length/current version с 13 и сохранить проверку `plan --check`.
|
||
- [x] `crates/crank-registry/src/migrations/authority_tests.rs` — включить V13 в точный append-only sequence test.
|
||
- [x] `docs/migrations.md` — обновить operator current-version пример и добавить назначение V13.
|
||
- [x] Verification — доказать canonical equality, историческую append-only дельту и прохождение CLI/integration migration tests.
|
||
|
||
**Acceptance Criteria:**
|
||
- Given checkout с V13 authority, when CI или release выполняет canonical migration gate, then команда завершается exit 0 и сообщает `contract_current`.
|
||
- Given canonical JSON до исправления, when рассматривается итоговый diff, then V1–V12 semantic entries идентичны, а единственное изменение sequence — новый V13 descriptor.
|
||
- Given fresh PostgreSQL schema, when migrations применяются и выполняется preflight, then canonical ledger и CLI согласованно сообщают current version 13.
|
||
|
||
## Spec Change Log
|
||
|
||
## Design Notes
|
||
|
||
Это восстановление ранее нарушенной append-only публикации V13, а не новая миграция. Canonical object берётся только из текущего executable `plan`; checksum равен проверяемому SHA-256 уже committed SQL artifact.
|
||
|
||
## Verification
|
||
|
||
**Commands:**
|
||
- `cargo run -p admin-api --bin crank-migrate -- plan --check` — expected: exit 0 и `contract_current`.
|
||
- `cargo test -p admin-api --test migration_command` — expected: deterministic contract и fresh-schema current version 13 проходят.
|
||
- `cargo test -p crank-registry --lib migrations::authority::tests::sequence_is_deterministic_and_append_only -- --exact` — expected: deterministic append-only sequence V1–V13 проходит.
|
||
- `cargo test -p crank-registry --test integration integration::migrations::controlled_authority_is_versioned_and_safe_under_concurrent_apply -- --exact --test-threads=1` — expected: ledger V1–V13 проходит.
|
||
- `git diff c2556ec236b6b14306c6f2d8674c3c5ada8b704e -- docs/schemas/migration-sequence.json` — expected: добавлен только V13 object.
|
||
- `cargo fmt --all -- --check && git diff --check` — expected: clean.
|
||
|
||
**Фактические результаты:**
|
||
- Canonical check прошёл с `{"status":"contract_current"}`.
|
||
- `migration_command`: 7 passed; deterministic plan и fresh-schema preflight подтвердили V13.
|
||
- Authority unit test: 1 passed; точная последовательность V1–V13 подтверждена.
|
||
- Registry PostgreSQL integration: 1 passed; ledger после concurrent apply содержит V1–V13.
|
||
- Historical immutability проверена semantic diff первых 12 entries против baseline; отличий нет, sequence содержит ровно один новый V13 entry.
|
||
- `cargo fmt --all -- --check` и `git diff --check` прошли.
|
||
|
||
## Suggested Review Order
|
||
|
||
**Canonical contract**
|
||
|
||
- Append-only V13 descriptor восстанавливает равенство committed plan и Rust authority.
|
||
[`migration-sequence.json:195`](../../docs/schemas/migration-sequence.json#L195)
|
||
|
||
**Regression protection**
|
||
|
||
- CLI contract проверяет детерминированный план и fresh-schema current version 13.
|
||
[`migration_command.rs:43`](../../apps/admin-api/tests/migration_command.rs#L43)
|
||
|
||
- Authority test закрепляет непрерывную последовательность V1–V13.
|
||
[`authority_tests.rs:11`](../../crates/crank-registry/src/migrations/authority_tests.rs#L11)
|
||
|
||
**Operator contract**
|
||
|
||
- Upgrade flow и назначение expand-only V13 синхронизированы с executable plan.
|
||
[`migrations.md:19`](../../docs/migrations.md#L19)
|