fix: decouple CBB imports from optional export diagnostics

This commit is contained in:
阿白叔 committed 2026-11-13 15:29:00 +08:00
1 parent cbc5723849
commit 1572e2d8ca
12 files changed
+601 -65

No files matched your search

+12 -4
View File
@@ -389,16 +389,24 @@ 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
expected_proof, registered_proof = identity, native.identity_proof
if isinstance(identity, dict) and identity.get('policy') == 'mentor795-import-assets-v1':
expected_proof = {key: value for key, value in identity.items() if key != 'assets'}
registered_proof = ({key: value for key, value in registered_proof.items() if key != 'assets'}
if isinstance(registered_proof, dict) else None)
# Library Manager may name the imported top block after the CBB.
if registered_proof is not None and registered_proof.get('top_level_block') == request.name:
expected_proof['top_level_block'] = request.name
proof_matches = (native.identity_matches is True and registered_proof == expected_proof
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 not proof_matches):
return finish('RECOVERY_REQUIRED', '原生新增后名称、分区或来源工程内容未确认一致。', owner_safe)
return finish('RECOVERY_REQUIRED', '原生新增后名称、分区或工程关联未确认一致。\n'+native.detail, owner_safe)
uploaded = True
checkpoint('uploaded')
if not request.auto_verify:
return finish('UPLOADED', '上传已确认;本批次未启用自动校验。')
return finish('UPLOADED', '上传已确认;本批次未启用自动校验。\n'+native.detail)
# Adapter catalog cannot return until its exact native owner exits.
checkpoint('verify')
owner_safe = False
@@ -410,7 +418,7 @@ def run_management(request, *, adapter=None, verifier=None, idle_check=None, pro
checkpoint('verified', verification=asdict(verified))
good = verified.status == 'PASS' and verified.library_flag == 'GREEN' and owner_safe
return finish('UPLOADED_VERIFIED' if good else 'UPLOADED_VERIFY_FAILED',
verified.stderr or verified.library_flag_detail, owner_safe)
'\n'.join(filter(None, (native.detail, verified.stderr or verified.library_flag_detail))), owner_safe)
except Exception as error:
if uploaded:
return finish('UPLOADED_VERIFY_FAILED', str(error), owner_safe)
@@ -191,17 +191,21 @@ def _normalized_project(path, expected_library):
data = path.read_bytes(); encoding = _project_encoding(data)
text = data.decode(encoding)
refs = re.findall(r'^KEY CentralLibrary "([^"\r\n]*)"', text, re.M)
if not refs or any((path.parent/value).resolve() != expected_library.resolve() for value in refs):
if (not refs or any(not value.strip() for value in refs)
or expected_library is not None and any(
(path.parent/value).resolve() != expected_library.resolve() for value in refs)):
raise ValueError(f'CentralLibrary reference does not resolve to the approved library: {path}')
return re.sub(r'(?m)^(KEY CentralLibrary ")[^"\r\n]*(")',
r'\1<CENTRAL_LIBRARY>\2', text).encode(encoding)
def asset_identity(source, expected_library):
"""Normalize old library paths when None; imported projects require the exact target."""
from .backup_recovery import _project_text
source, pcb, top = source_project(source)
expected_library = Path(expected_library)
if not expected_library.is_file(): raise ValueError('Approved CentralLibrary is missing.')
expected_library = Path(expected_library) if expected_library is not None else None
if expected_library is not None and not expected_library.is_file():
raise ValueError('Approved CentralLibrary is missing.')
root = source.parent
from .maintenance_entry import maintenance_project_files
projects = maintenance_project_files(source, pcb)
@@ -236,6 +240,21 @@ def asset_identity(source, expected_library):
'layout_sha256': hash_file(pcb.parent/'Layout/LayoutDB.lyt'), 'assets': assets}
def capture_registration_identity(source, evidence_root, *, expected_library):
"""File-only import evidence; native database normalization is not semantic proof."""
root = Path(evidence_root)
try:
root.mkdir(parents=True, exist_ok=False)
identity = {**asset_identity(source, expected_library),
'policy': 'mentor795-import-assets-v1',
'coverage': {'primary_assets_checked': True,
'schematic_semantics_checked': False}}
_write_json(root/'identity.json', {'identity': identity, 'safe_to_continue': True})
return IdentityOutcome(identity, True, 'Engineering files and project references checked; no native export.', root)
except Exception as error:
return IdentityOutcome(None, True, str(error), root)
def check_exporters(mentor_home):
for name, expected in EXPORTER_PROOF.items():
path = Path(mentor_home)/('wv/win32/bin' if name == 'edifExporter.exe' else 'iCDB/win32/bin')/name
+34 -29
View File
@@ -1,7 +1,7 @@
"""Version-pinned native adapter, private desktop transport and strict catalog.
"""Version-pinned native import/removal, private desktop transport and catalog.
The installed Tcl CleanWGLib/F4 contract has isolated removal proof. Discovery
of an Add dialog is deliberately insufficient to enable production Add/Update.
Normal import checks native registration and engineering files without invoking
the independent schematic exporters. Optional Verify determines READY.
"""
from dataclasses import asdict, replace
import ctypes
@@ -131,17 +131,12 @@ class NativeManagementAdapter:
def capabilities(self):
reason = self._binary_capability()
add_reason = reason
if not add_reason:
from .native_engineering_identity import check_exporters
try: check_exporters(self.home)
except (ValueError, OSError, TypeError) as error: add_reason = str(error)
return {
'remove': Capability(not reason, reason or '已验证 CleanWGLib/F4;仅 ASCII 名称、Logical-Physical 和 DxDesigner 库。'),
'add': Capability(not add_reason and _PRODUCTION_ADD_VALIDATED, add_reason or
'已验证 EE7.9.5 原生导入及完整工程复读;仅 ASCII 名称、Logical-Physical 和 DxDesigner 库。'),
'update': Capability(not add_reason and _PRODUCTION_ADD_VALIDATED and _PRODUCTION_UPDATE_VALIDATED,
add_reason or '已验证同名原生替换:移除并重新导入;操作前请手动备份。'),
'add': Capability(not reason and _PRODUCTION_ADD_VALIDATED, reason or
'EE7.9.5 原生导入及工程关联复读;仅 ASCII 名称、Logical-Physical 和 DxDesigner 库。'),
'update': Capability(not reason and _PRODUCTION_ADD_VALIDATED and _PRODUCTION_UPDATE_VALIDATED,
reason or '同名原生替换:移除并重新导入;操作前请手动备份。'),
}
def _worker(self, job, evidence):
@@ -310,7 +305,7 @@ class NativeManagementAdapter:
return self._add_transaction(request, Path(evidence))
def prepare_add_transaction(self, request, root, *, original_source):
from .native_engineering_identity import project_library, asset_identity, capture_identity, IdentityOutcome
from .native_engineering_identity import asset_identity, capture_registration_identity, IdentityOutcome
from .native_add_failures import validate_native_copy_paths
from .management_transaction import current_lease, prepare_transaction
from .management import source_project
@@ -320,7 +315,8 @@ class NativeManagementAdapter:
raise ValueError(self.capabilities()['add'].reason)
validate_native_copy_paths(request.source, request.library, request.name)
current_lease(request.library)
original_assets = asset_identity(original_source, project_library(original_source))
# The selected destination replaces old library paths in the staged copy.
original_assets = asset_identity(original_source, None)
staged, pcb, _ = source_project(request.source, request.top_level_block)
if staged.parent != Path(root).resolve()/'source':
raise ValueError('Only the engine staged source can be aligned for native Add.')
@@ -329,8 +325,7 @@ class NativeManagementAdapter:
raise ValueError('Staged engineering assets differ from the original source.')
except Exception as error:
return request, IdentityOutcome(None, True, str(error), Path(root))
proof = capture_identity(staged, Path(root)/'source-identity', expected_library=request.library,
owner_library=request.library, mentor_home=self.home, timeout_seconds=request.timeout_seconds)
proof = capture_registration_identity(staged, Path(root)/'source-identity', expected_library=request.library)
if proof.identity is None or not proof.safe_to_continue:
return request, proof
try:
@@ -344,7 +339,7 @@ class NativeManagementAdapter:
from contextlib import contextmanager
from .management_transaction import validate_transaction
from .library_lock import LibraryLock
from .native_engineering_identity import capture_identity, project_library
from .native_engineering_identity import capture_registration_identity, project_library
from .management import source_project
from .backup_recovery import _align_library, _idle_check
try:
@@ -383,7 +378,7 @@ class NativeManagementAdapter:
if len(projects) != 1:
return NativeOutcome(True, owner_safe, 'Registered engineering project is not unique.',
identity_matches=False, evidence_path=evidence)
target, pcb, _ = source_project(projects[0], request.top_level_block)
target, pcb, _ = source_project(projects[0])
_idle_check(request.library, target, pcb)
from .maintenance_entry import maintenance_project_files
project_files = maintenance_project_files(target, pcb)
@@ -401,18 +396,31 @@ class NativeManagementAdapter:
or catalog.flow != 1 or len(entries) != 1):
return NativeOutcome(True, owner_safe, 'Aligned target did not reopen with the exact catalog identity.',
identity_matches=False, evidence_path=evidence)
owner_safe = False
proof = capture_identity(target, evidence/'registered-identity', expected_library=request.library,
owner_library=request.library, mentor_home=self.home, timeout_seconds=request.timeout_seconds)
proof = capture_registration_identity(target, evidence/'registered-identity', expected_library=request.library)
owner_safe = proof.safe_to_continue
matched = proof.identity is not None and proof.identity == prepared['expected_identity']
expected, registered = prepared['expected_identity'], proof.identity
# Native Add rewrites PRJ metadata and runtime history. Registration
# identity uses the top block and Layout; other file diffs are evidence.
allowed_tops = (expected['top_level_block'], request.name)
matched = (registered is not None and registered['top_level_block'] in allowed_tops
and registered['layout_sha256'] == expected['layout_sha256'])
before_assets, after_assets = expected['assets'], (registered or {}).get('assets', {})
differences = {'added': sorted(after_assets.keys()-before_assets.keys()),
'deleted': sorted(before_assets.keys()-after_assets.keys()),
'modified': sorted(key for key in before_assets.keys() & after_assets.keys()
if before_assets[key] != after_assets[key])}
assets_match = registered is not None and not any(differences.values())
_write_json(evidence/'identity-comparison.json', {'identity_matches': matched,
'expected': prepared['expected_identity'], 'registered': proof.identity,
'assets_match': assets_match, 'asset_differences': differences,
'top_level_block_mapping': {'source': expected['top_level_block'],
'registered': (registered or {}).get('top_level_block'), 'allowed': list(allowed_tops)},
'expected': expected, 'registered': registered,
'safe_to_continue': owner_safe, 'detail': proof.detail})
return NativeOutcome(True, owner_safe,
'Native ASCII/CSV/EDIF, physical assets and library references match.' if matched else
'Native registration succeeded but complete engineering identity proof did not match: '+proof.detail,
identity_matches=matched, evidence_path=evidence, identity_proof=proof.identity)
('原生注册、工程关联、顶层块和 Layout 已确认;未核验原理图语义。'
+ ('其他工程文件有差异,已记录供核对。' if not assets_match else '')) if matched else
'原生注册成功,但工程关联、顶层块或 Layout 未确认一致:'+proof.detail,
identity_matches=matched, evidence_path=evidence, identity_proof=registered)
def add_owned_fixture(self, request, evidence, *, probe_token):
"""Research only: stage and back up a token-bound, actively leased fixture."""
@@ -463,13 +471,10 @@ class _OwnedFixtureManagementAdapter(NativeManagementAdapter):
def capabilities(self):
from .management_transaction import fixture_authority
from .native_engineering_identity import check_exporters
fixture = self._fixture_authority
fixture_authority(fixture['root'], Path(fixture['root'])/'native-add/fixture/mentor_lib.lmc', fixture['token'])
caps = super().capabilities()
reason = self._binary_capability()
try: check_exporters(self.home)
except (ValueError, OSError) as error: reason = str(error)
for operation in ('add', 'update'):
caps[operation] = Capability(not reason, reason or 'Owned fixture engine validation only; production capability unchanged.')
return caps
@@ -9,7 +9,7 @@ from PySide6.QtWidgets import (QCheckBox, QDialog, QFileDialog, QHBoxLayout, QLa
from .workers import ServiceWorker
from .backup_notice import MANUAL_BACKUP_NOTICE
from ..management import run_management_batch, validate_name
from ..management import run_management_batch
RESULT_LABELS = {
'REMOVED': '已移除', 'UPLOADED': '已上传 / 未自动校验',
@@ -18,7 +18,7 @@ RESULT_LABELS = {
'BLOCKED': '操作被阻止', 'UNSUPPORTED': '当前环境不支持',
}
STAGE_LABELS = {
'prepare_identity': '正在核对来源工程内容',
'prepare_identity': '正在检查来源工程文件',
'catalog_before': '正在核对原生目录', 'baseline': '正在记录中心库内容基线',
'stage_source': '正在复制并检查来源工程', 'native_remove': '正在移除',
'removed': '原条目已移除', 'native_add': '正在上传', 'uploaded': '上传已确认',
@@ -150,10 +150,7 @@ class ManagementDialog(QDialog):
try:
if not requests:
raise ValueError('请先选择来源工程。')
for request in requests:
validate_name(request.name)
if request.operation != 'remove' and (request.source is None or not request.source.is_file()):
raise ValueError(f'{request.name}:请选择完整来源 PRJ。')
# Per-item input errors belong in batch results, so valid rows still run.
if len({(r.partition.casefold(), r.name.casefold()) for r in requests}) != len(requests):
raise ValueError('批次包含重复目标名称。')
except ValueError as error: