feat: bind native CRUD to prepared engine identity transactions

This commit is contained in:
阿白叔 committed 2026-11-03 11:54:56 +08:00
1 parent 89500cbb5f
commit 55a82fdc5f
8 files changed
+492 -13

No files matched your search

+14 -1
View File
@@ -29,6 +29,7 @@ class ManagementRequest:
timeout_seconds: float = 180
mapped_drive: str = ''
mapped_remote_root: str = ''
transaction_token: str = ''
@dataclass(frozen=True)
@@ -53,6 +54,7 @@ class NativeOutcome:
detail: str
identity_matches: bool | None = None
evidence_path: Path | None = None
identity_proof: dict | None = None
@dataclass(frozen=True)
@@ -268,6 +270,14 @@ def run_management(request, *, adapter=None, verifier=None, idle_check=None, pro
identity = engineering_identity(staged.source)
if build_manifest(source.parent) != source_manifest:
raise OSError('来源工程在暂存期间变化。')
if source and hasattr(adapter, 'prepare_add_transaction'):
checkpoint('prepare_identity')
owner_safe = False
staged, proof = adapter.prepare_add_transaction(staged, root, original_source=source)
owner_safe = proof.safe_to_continue
if not owner_safe or proof.identity is None:
return finish('UPLOAD_FAILED', proof.detail, owner_safe)
identity = proof.identity
if build_manifest(library_root, scope=scope) != original:
raise OSError('备份后中心库内容变化,停止写入。')
if request.operation in ('remove', 'update'):
@@ -302,8 +312,11 @@ def run_management(request, *, adapter=None, verifier=None, idle_check=None, pro
owner_safe = after.safe_to_continue
matches = [entry for entry in after.entries if entry.name == request.name
and entry.partition == request.partition]
proof_matches = (native.identity_matches is True and native.identity_proof == identity
if hasattr(adapter, 'prepare_add_transaction') else
len(matches) == 1 and matches[0].engineering_identity == identity)
if (not owner_safe or Path(after.library).resolve() != canonical_library or after.flow != 1
or len(matches) != 1 or matches[0].engineering_identity != identity):
or len(matches) != 1 or not proof_matches):
return finish('RECOVERY_REQUIRED', '原生新增后名称、分区或来源工程内容未确认一致。', False)
uploaded = True
checkpoint('uploaded')