feat(platform): 增加履约分类映射管理并锁定迁移

This commit is contained in:
yml
2026-11-21 14:41:36 +08:00
parent 8580f9738d
commit 7396126c73
20 changed files with 3093 additions and 115 deletions
+36
View File
@@ -0,0 +1,36 @@
"""已发布 Alembic 迁移不可被静默修改。"""
from __future__ import annotations
from pathlib import Path
import pytest
from web.backend.migrations import immutability
def test_committed_migration_manifest_matches_files():
immutability.verify_manifest()
def test_manifest_rejects_modified_released_migration(tmp_path: Path):
versions = tmp_path / "versions"
versions.mkdir()
migration = versions / "20260101_0001_example.py"
migration.write_text('revision = "20260101_0001"\n', encoding="utf-8")
manifest = tmp_path / "migration_manifest.json"
immutability.write_manifest(versions_dir=versions, manifest_path=manifest)
migration.write_text(
'revision = "20260101_0001"\n# accidental released change\n',
encoding="utf-8",
)
with pytest.raises(immutability.MigrationManifestError, match="内容被修改"):
immutability.verify_manifest(
versions_dir=versions,
manifest_path=manifest,
)
with pytest.raises(immutability.MigrationManifestError, match="拒绝更新"):
immutability.write_manifest(versions_dir=versions, manifest_path=manifest)